Results 1 to 7 of 7
Thread: Poker Hand Evaluator Help
 04122013, 06:27 AM #1Senior 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; }
 04122013, 06:38 AM #2Member
 Join Date
 Feb 2013
 Location
 San Diego
 Posts
 97
 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; 04122013 at 06:45 AM.
 04122013, 07:07 AM #3Senior 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; }
 04122013, 08:52 AM #4Senior Member
 Join Date
 Mar 2013
 Posts
 123
 Rep Power
 0
Popopopoker 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
 04122013, 08:59 AM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,300
 Blog Entries
 7
 Rep Power
 24
Re: Popopopoker 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,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 04122013, 09:28 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,300
 Blog Entries
 7
 Rep Power
 24
Re: Poker Hand Evaluator Help
@OP: I've merged your two threads; please don'y start multiple threads for the same subject.
kind regards,
JosThe only person who got everything done by Friday was Robinson Crusoe.
 10032013, 06:07 AM #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.
Similar Threads

dice poker
By saina in forum New To JavaReplies: 1Last Post: 04042012, 10:01 AM 
Problem with infix evaluator?
By chris1 in forum New To JavaReplies: 3Last Post: 10122011, 02:33 AM 
Lucene as Conditional Evaluator / Indexer?
By cuebei in forum LuceneReplies: 0Last Post: 01112010, 08:36 PM
Bookmarks