ca.ualberta.cs.poker
Class HandEvaluator

java.lang.Object
  extended by ca.ualberta.cs.poker.HandEvaluator

public class HandEvaluator
extends java.lang.Object

Class for identifying / comparing / ranking Hands.

Author:
Aaron Davidson, Darse Billings, Denis Papp

Constructor Summary
HandEvaluator()
           
 
Method Summary
 int compareHands(Hand h1, Hand h2)
          Compares two hands against each other.
 int compareHands(int rank1, Hand h2)
          Compares two 5-7 card hands against each other.
 Hand getBest5CardHand(Hand h)
          Get the best 5 card poker hand from a 7 card hand
 int[][] getRanks(Hand board)
          Given a board, cache all possible two card combinations of hand ranks, so that lightenting fast hand comparisons may be done later.
static java.lang.String nameHand(Hand h)
          Given a hand, return a string naming the hand ('Ace High Flush', etc..)
 int rankHand(Card c1, Card c2, Hand h)
          Get a numerical ranking of this hand.
static int rankHand(Hand h)
          Get a numerical ranking of this hand.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HandEvaluator

public HandEvaluator()
Method Detail

rankHand

public int rankHand(Card c1,
                    Card c2,
                    Hand h)
Get a numerical ranking of this hand.

Parameters:
c1 - first hole card
c2 - second hole card
h - a 3-5 card hand
Returns:
a unique number representing the hand strength of the best 5-card poker hand in the given cards and board. The higher the number, the better the hand is.

nameHand

public static java.lang.String nameHand(Hand h)
Given a hand, return a string naming the hand ('Ace High Flush', etc..)


compareHands

public int compareHands(Hand h1,
                        Hand h2)
Compares two hands against each other.

Parameters:
h1 - The first hand
h2 - The second hand
Returns:
1 = first hand is best, 2 = second hand is best, 0 = tie

compareHands

public int compareHands(int rank1,
                        Hand h2)
Compares two 5-7 card hands against each other.

Parameters:
rank1 - The rank of the first hand
h2 - The second hand
Returns:
1 = first hand is best, 2 = second hand is best, 0 = tie

getRanks

public int[][] getRanks(Hand board)
Given a board, cache all possible two card combinations of hand ranks, so that lightenting fast hand comparisons may be done later.


getBest5CardHand

public Hand getBest5CardHand(Hand h)
Get the best 5 card poker hand from a 7 card hand

Parameters:
h - Any 7 card poker hand
Returns:
A Hand containing the highest ranked 5 card hand possible from the input.

rankHand

public static int rankHand(Hand h)
Get a numerical ranking of this hand. Uses java based code Based on Denis Papp's Loki Hand ID code (id.cpp) Given a 5 to 7 card hand, will return a unique rank such that any two hands will be ranked with the better hand having a higher rank.

Parameters:
h - a 5 to 7 card hand
Returns:
a unique number representing the hand strength of the best 5-card poker hand in the given up to 7 cards. The higher the number, the better the hand is.