# Thread: Poker Hand Evaluator Help

1. Senior Member
Join Date
Mar 2013
Posts
123
Rep Power
0

## 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:
Java 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

2. Member
Join Date
Feb 2013
Location
San Diego
Posts
98
Rep Power
0

## 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.
Last edited by Prime624; 04-12-2013 at 06:45 AM.

3. Senior Member
Join Date
Mar 2013
Posts
123
Rep Power
0

## Re: Poker Hand Evaluator Help

here's what i got for 4 of a kind. What do you think?

Java 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;
}```

4. Senior Member
Join Date
Mar 2013
Posts
123
Rep Power
0

## 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
Java 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
Java 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

Java 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

5. ## 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

6. ## Re: Poker Hand Evaluator Help

kind regards,

Jos

7. ## Re: Poker Hand Evaluator Help

You can expand your hasFourOfAKind method to handle all combinations. By that I mean the value stored in count will be unique for pair (1), two pair (2), three of a kind (3) etc. Just use one method to do all the counting then use a switch on the result to determine the hand. No need to have multiple methods duplicating the work. Straights and flushes need to handled separately.