com.biotools.meerkat
Class HandEvaluator

java.lang.Object
  extended by com.biotools.meerkat.HandEvaluator

public class HandEvaluator
extends java.lang.Object

Class for identifying / comparing / ranking Hands.


Constructor Summary
HandEvaluator()
           
 
Method Summary
static int compareHands(Hand h1, Hand h2)
          Compares two 5-to-7 hands against each other.
static int compareHands(int rank1, Hand h2)
          Compares two 5-7 card hands against each other.
static HandEval getHandEval()
          Get the HandEval engine being used by the HandEvaluator
static NChoose2IntTable getRanks(Hand board)
          Given a board, cache all possible two card combinations of hand ranks, so that fast hand comparisons may be done later.
static double handRank(Card c1, Card c2, Hand h)
          Calculates the probability of currently having the best hand against one random opponent.
static double handRank(Card c1, Card c2, Hand h, int np)
          Calculates the probability of having the best hand against several random opponents.
static double handRank(Card c1, Card c2, NChoose2IntTable rankCache, Deck dk)
          Calculate the strength of the given hand.
static boolean isTheNuts(Card c1, Card c2, Hand board, NChoose2IntTable rankCache)
          Determine if the hand is the nuts (no hands beat it) Does not consider draws, only the immediate conditions.
static 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.
static int rankHand(int c1, int c2, Hand h)
          Get a numerical ranking of this hand.
static int rankHand5(Hand h)
          Get a numerical ranking of this hand.
static int rankHand6(Hand h)
          Get a numerical ranking of this hand.
static int rankHand7(Hand h)
          Get a numerical ranking of this hand.
static void setHandEval(HandEval he)
          Set the HandEval engine to be used by the HandEvaluator param an engine to compute hand evaluations
 
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 static final int rankHand(Hand h)
Get a numerical ranking of this hand.

Parameters:
h - a 5-7 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

rankHand7

public static final int rankHand7(Hand h)
Get a numerical ranking of this hand.

Parameters:
h - a 7 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

rankHand6

public static final int rankHand6(Hand h)
Get a numerical ranking of this hand.

Parameters:
h - a 6 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

rankHand5

public static final int rankHand5(Hand h)
Get a numerical ranking of this hand.

Parameters:
h - a 5 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

rankHand

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

Parameters:
h - a 5-7 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

rankHand

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

Parameters:
h - a 5-7 card hand
Returns:
a unique number representing the hand strength equivalence class of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is, and tied hands map to identical integers.

compareHands

public static int compareHands(Hand h1,
                               Hand h2)
Compares two 5-to-7 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 static 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 static NChoose2IntTable getRanks(Hand board)
Given a board, cache all possible two card combinations of hand ranks, so that fast hand comparisons may be done later.


handRank

public static double handRank(Card c1,
                              Card c2,
                              Hand h,
                              int np)
Calculates the probability of having the best hand against several random opponents.

Parameters:
c1 - hole card 1
c2 - hole card 2
h - the board
np - the number of active opponents in the hand
Returns:
probability of having the best hand.

handRank

public static double handRank(Card c1,
                              Card c2,
                              Hand h)
Calculates the probability of currently having the best hand against one random opponent.

Parameters:
c1 - hole card 1
c2 - hole card 2
h - the board
Returns:
probability of having the best hand.

handRank

public static double handRank(Card c1,
                              Card c2,
                              NChoose2IntTable rankCache,
                              Deck dk)
Calculate the strength of the given hand. Use the rank cache to speed the calculations up.

Parameters:
c1 - the first hole card
c2 - the second hole card
rankCache - the ranks for all hands against a board where rankCache[i][j] = the rank of Card(i) and Card(j) the array stores the same values both in [i][j] and [j][i] for faster access times. (this cache can be obtained from HandEvaluator.getRanks(Hand))
dk - the deck with all known cards removed
Returns:
the hand strength

isTheNuts

public static final boolean isTheNuts(Card c1,
                                      Card c2,
                                      Hand board,
                                      NChoose2IntTable rankCache)
Determine if the hand is the nuts (no hands beat it) Does not consider draws, only the immediate conditions.

Returns:
true if no other hands beat this hand.

getHandEval

public static HandEval getHandEval()
Get the HandEval engine being used by the HandEvaluator

Returns:
the HandEval engine being used by the HandEvaluator

setHandEval

public static void setHandEval(HandEval he)
Set the HandEval engine to be used by the HandEvaluator param an engine to compute hand evaluations