Reputation: 69
I have a question more about style rather than implementation. I'm working on poker application. It has a class storing all required data, like five cards. There is also second structure, which models the FigureAnalyzer - piece of code to determine, whever the hand contains flush, two pairs or full. In general, everything is working fine. But it's more ugly then my ex-girlfriend.
This is a sample, which determine hand combination:
@Override
public int getFigureStrength(IHand hand) {
/*
* analyze all possible pairs, triples, etc.
*/
MultipleCardAnalyzer.anayzeMultipleCards(hand, figureList);
hand.setFigureAnalyzer(this);
if (isPoker()) {
if (isRoyalPoker())
return 10;
return 9;
}
else if (isFourOfAKind())
return 8;
else if (isFull())
return 7;
else if (isFlush())
return 6;
else if (isStraight())
return 5;
else if (areThreeOfAKind())
return 4;
else if (areTwoPairs())
return 3;
else if (isPair())
return 2;
else
return 1;
}
Numbers are useful when it comes to comparing two hands. But... it's just awful. Can any one point me or just suggest, how can I make it more pretty?
Upvotes: 0
Views: 90
Reputation: 49920
Define constants w/ meaningful names for these values; an enum
might be useful here.
Upvotes: 2