Results 1 to 7 of 7
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default 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. #2
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default 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. #3
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default 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. #4
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default 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. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default Re: Poker Hand Evaluator Help

    @OP: I've merged your two threads; please don'y start multiple threads for the same subject.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default 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

  1. dice poker
    By saina in forum New To Java
    Replies: 1
    Last Post: 04-04-2012, 10:01 AM
  2. Problem with infix evaluator?
    By chris1 in forum New To Java
    Replies: 3
    Last Post: 10-12-2011, 02:33 AM
  3. Lucene as Conditional Evaluator / Indexer?
    By cuebei in forum Lucene
    Replies: 0
    Last Post: 01-11-2010, 07:36 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •