Results 1 to 3 of 3
  1. #1
    Incisus is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Talking Texas Hold'em, Who Has the Best Hand?

    Hello!

    I'm making an online Texas Hold'em game for fun, everything is done! Except for one small problem. I cannot figure out a way to find who has the best hand?

    Here is the CardType class:

    Java Code:
    public class CardType
    {
    	public static String[] suit = {"Spades", "Hearts", "Diamonds", "Clubs"};
    	public static String[] rank = {"2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};
    	public static int[] value = {2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1};
    	
    	public static String randomSuit()
    	{
    		return suit[new Random().nextInt(suit.length)];
    	}
    	public static String randomRank()
    	{
    		return rank[new Random().nextInt(rank.length)];
    	}
    	public static int getRankID(String r)
    	{
    		int rid = 0;
    		for (int i = 0; i < rank.length; i++)
    		{
    			if (r.equals(rank[i])) rid = i;
    		}
    		return rid;
    	}
    	public static int getValue(int rid)
    	{
    		return value[rid];
    	}
    }
    And the Card class:
    Java Code:
    public class Card
    {
    	private int rid = -1;
    	private String suit;
    	private String rank;
    	private boolean faceUp;
    	private float angle;
    	
    	public void setRandom()
    	{
    		suit = CardType.randomSuit();
    		rank = CardType.randomRank();
    	}
    	public void setString(String v)
    	{
    		suit = v;
    	}
    	public void setRank(String v)
    	{
    		rank = v;
    	}
    	public void setSuit(String v)
    	{
    		suit = v;
    	}
    	public void setFaceUp(boolean v)
    	{
    		faceUp = v;
    	}
    	public void setAngle(float v)
    	{
    		angle = v;
    	}
    	public int getValue()
    	{
    		if (rid == -1) rid = CardType.getRankID(rank);
    		return CardType.getValue(rid);
    	}
    	public String getRank()
    	{
    		return rank;
    	};
    	public String getSuit()
    	{
    		return suit;
    	}
    	public void parseCard(String cardText)
    	{
    		cardText = cardText.toLowerCase();
    		String[] cValue = cardText.split("_");
    		rank = cValue[0];
    		suit = cValue[1];
    		if (cValue[2].equals("false")) faceUp = false;
    		else if (cValue[2].equals("true"))  faceUp = true;
    	}
    	public String toText()
    	{
    		return rank + "_" + suit + "_" + Boolean.toString(faceUp);
    	}
    }
    So in the Game class, I need to compare 4 players cards to the 5 cards in the flop. All of which use the Card class for an object.

    Any help or insight is greatly appreciated!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,900
    Rep Power
    25

    Default Re: Texas Hold'em, Who Has the Best Hand?

    a way to find who has the best hand
    Can you evaluate a hand to know what it contains? Highcard up to royal straight flush?

    Assign a number in ranking order to each type of hand and pick the hand with the highest number.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: Texas Hold'em, Who Has the Best Hand?

    Assign a number in ranking order to each type of hand and pick the hand with the highest number.
    I think that's a good start, but in Poker hands, you can have three-of-a-kind for example and a different three-of-a-kind would win or lose depending upon who has the highest cards.

    I would keep the constants (or enums) one for each type of hand: ROYAL_FLUSH, STRAIGHT_FLUSH, etc. and have a class called PokerHand. A PokerHand could have three instance variables 1) a ranking, and 2) a high card, and 3) a second highest card (for two pairs for example). Each hand that the players have could be evaluated from the least valuable to the most valuable hand. PokerHand could implement the Comparable interface so that hand can be compared to one another using the compareTo() method. First the type of hand could be compared, if they are equal then the high card could be compared, and if they are equal, the second highest card could be compared. This way, each of the 5 hands could be evaluated and the result would be a PokerHand object and they can be put into an ArrayList, sorted with a call to Collections.sort(), and the winning hand would come out first (or last depending upon how compareTo() is implemented).

    Well, I'm sure that you could do this differently, but I think that this approach would work.

Similar Threads

  1. Texas Hold'em Poker
    By JohnPringle83 in forum Java Gaming
    Replies: 0
    Last Post: 05-05-2011, 06:40 AM
  2. Java Developer needed in Texas
    By borris83 in forum Jobs Offered
    Replies: 0
    Last Post: 12-18-2010, 12:23 AM
  3. Developer III - JAVA; North Texas area
    By ScottSearch in forum Jobs Offered
    Replies: 0
    Last Post: 09-22-2008, 10:06 PM

Posting Permissions

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