Poker Hand Evaluator Help

• 04-12-2013, 06:27 AM
NoobieCode
Poker Hand Evaluator Help
How do I make boolean methods to check for if 5 cards have: pair, two pair, 3 of a kind, straight, flush, full house, 4 of kind,
straight flush.

This is what I have for flush and it worked. I need help on the others.

ex:
Code:

```                 int suit = cards[0].getSuit();  //Find 1 suit of 1 card                 for (int i = 1; i <= 4; i++){                         if (suit != (cards[i].getSuit())){ //If suit of first card does not equal suit of other cards, there is no flush                                 return false;                                        }                 }                 return true;         }```
Hints would be awesome
• 04-12-2013, 06:38 AM
Prime624
Re: Poker Hand Evaluator Help
Pair: Check each card against every other card. If any two are same, it's a pair.
Two Pair: Same as pair but once you find one pair, take out those cards and recheck.
Three of a Kind: Same as pair except check against two other cards instead of one.
Straight: Find lowest card and search remaining cards for next number and next etc. Ex: 3 is lowest. Search for 4. If found, search for 5...
Flush: Done.
Full House: Check for three of a kind, then check if remaining two cards equal each other.
Four of a Kind: Same as three of a kind except check against three other cards instead of two.
Straight Flush: If it is a straight, and it is a flush, it is also a straight flush.

Good luck.
• 04-12-2013, 07:07 AM
NoobieCode
Re: Poker Hand Evaluator Help
here's what i got for 4 of a kind. What do you think?

Code:

```public static boolean hasFourOfAKind(Card[] cards){                 int count = 0;                 for (int i = 0; i <= 4 ;i++){                         count = 0;                         for (int j = i+1 ; j <= 4 ; j++){                                 if (cards[i] == (cards[j])){                                         count++;                                 }                                 if (count == 4){                                         return true;                                 }                         }                 }                 return false;         }```
• 04-12-2013, 08:52 AM
NoobieCode
Po-po-po-poker face... Poker Hand Evaluator Help
Hi. How do I make boolean methods to check for if 5 cards have: pair, two pair, 3 of a kind, straight, flush, full house?

This is what I have so Far:

PAIR
Code:

```public static boolean hasPair(Card[] cards){ int count = 0;                 for (int i = 0; i <= 4 ;i++){                         count = 0;                         for (int j = i + 1 ; j <= 4 ; j++){                                 if (cards[i] == (cards[j])){                                         count++;                                 }                                 if (count >= 1){                                         return true;                                 }                         }                 }                 return false;         }```

TWO PAIR
no idea how to find another pair not equals the first pair foound

THREE OF A KIND
Code:

```public static boolean hasThreeOfAKind(Card[] cards){ int count = 0;                 for (int i = 0; i <= 4 ;i++){                         count = 0;                         for (int j = i + 1 ; j <= 4 ; j++){                                 if (cards[i] == (cards[j])){                                         count++;                                 }                                 if (count >= 2){                                         return true;                                 }                         }                 }                 return false;         }```

STRAIGHT
no Idea how to begin sorting

FLUSH

Code:

```public static boolean hasFlush(Card[] cards) int suit = cards[0].getSuit();  //Find 1 suit of 1 card                 for (int i = 1; i <= 4; i++){                         if (suit != (cards[i].getSuit())){ //If suit of first card does not equal suit of other cards, there is no flush                                 return false;                                        }                 }                 return true;         }```

FULLHOUSE
no idea how to call my methods
• 04-12-2013, 08:59 AM
JosAH
Re: Po-po-po-poker face... Poker Hand Evaluator Help
Inroduce a temporary array 'count' that (after your loop(s) have finished) contains the number of cards of a certain rank; e.g. coun[7]= 2 means that the hand contains two sevens. If the array contains two number 2s, you have two pairs, if the array contains a 2 and a 3, you have a full house. etc.

kind regards,

Jos
• 04-12-2013, 09:28 AM
JosAH
Re: Poker Hand Evaluator Help