poker
Class HandEvaluator

java.lang.Object
  extended by poker.HandEvaluator

public class HandEvaluator
extends java.lang.Object

Class for identifying / comparing / ranking Hands.

Source Code: HandEvaluator.java

JNI Poker Evaluation Library Code

Version:
2.2
Author:
Aaron Davidson, Darse Billings, Denis Papp

Constructor Summary
HandEvaluator()
          Construct a new Hand Evaluator.
 
Method Summary
static double CGetRanks(int[] board, int[] ranks)
           
static double CHandRank(int c1, int c2, int[] board)
          Calculates the probability of having the best hand against one opponent.
static int compareHands(Hand h1, Hand h2)
          Compares two 7 card hands against each other.
static int compareHands(int rank1, Hand h2)
          Compares two 5-7 card hands against each other.
static int CRankHandFast(int[] cards)
          Get a numerical ranking of this hand.
static int CRankHandFast7(int[] cards)
          Get a numerical ranking of this hand.
static int Find_Hand(int[] hand, int[] best)
           
static Hand getBest5CardHand(Hand h)
          Get the best 5 card poker hand from a 7 card hand
 int getNumBetter()
          Get the number of hands better than the last hand ranked.
 int getNumTied()
          Get the number of hands tied with the last hand ranked.
 int getNumWorse()
          Get the number of hands worse than the last hand ranked.
static 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 int[][] getRanksNative(Hand board)
           
 double handRank(Card c1, Card c2, Hand h)
          Calculates the probability of having the best hand against one opponent.
 double handRank(Card c1, Card c2, Hand h, int np)
          Calculates the probability of having the best hand against several opponents.
static double handRank(Card c1, Card c2, int[][] rankCache, Deck dk)
          Calculate the strength of the given hand.
static double handRankNative(Card c1, Card c2, Hand h)
           
 boolean isNative()
          Returns true if the native evaluation library is loaded.
static boolean isTheNuts(Card c1, Card c2, Hand board, int[][] rankCache)
          Determine if the hand is the nuts (no hands beat it)
static java.lang.String nameHand(Card c1, Card c2, Hand b)
          Given a hand, return a string naming the hand ('Ace High Flush', etc..)
static java.lang.String nameHand(Hand h)
          Given a hand, return a string naming the hand ('Ace High Flush', etc..)
static double[] potential(Card c1, Card c2, Hand bd, poker.ai.model.WeightTable wt)
           
static double ppot1(Card c1, Card c2, Hand bd, poker.ai.model.WeightTable wt)
           
static double ppot1(int c1, int c2, int[] bd, double[] weights, double[] result)
           
static int rankHand_Java(Hand h)
          Get a numerical ranking of this hand.
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 rankHand7(Hand h)
          Get a numerical ranking of this hand.
static void test()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HandEvaluator

public HandEvaluator()
Construct a new Hand Evaluator. If the libeval.so library is present, the native methods will be used, otherwise the slower java methods will be used instead.

Method Detail

isNative

public boolean isNative()
Returns true if the native evaluation library is loaded.


rankHand

public static final int rankHand(Hand h)
Get a numerical ranking of this hand. Uses a Native Method. (Make sure the feval library is installed!) Uses GNU Poker Lib: eval.h

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

rankHand

public static int rankHand(Card c1,
                           Card c2,
                           Hand h)
Get a numerical ranking of this hand. Uses a Native Method. (Make sure the feval library is installed!) Uses GNU Poker Lib: eval.h

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(Card c1,
                                        Card c2,
                                        Hand b)
Given a hand, return a string naming the hand ('Ace High Flush', etc..)


nameHand

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


compareHands

public static int compareHands(Hand h1,
                               Hand h2)
Compares two 7 card 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

CRankHandFast

public static int CRankHandFast(int[] cards)
Get a numerical ranking of this hand. Native Method. (Make sure the feval library is installed!) Uses GNU Poker Lib: eval.h

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

CRankHandFast7

public static int CRankHandFast7(int[] cards)
Get a numerical ranking of this hand. Native Method. (Make sure the feval library is installed!) Uses GNU Poker Lib: eval7.h

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

CHandRank

public static double CHandRank(int c1,
                               int c2,
                               int[] board)
Calculates the probability of having the best hand against one opponent.

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

handRankNative

public static double handRankNative(Card c1,
                                    Card c2,
                                    Hand h)

rankHand7

public static final int rankHand7(Hand h)
Get a numerical ranking of this hand. Uses a Native Method. (Make sure the feval library is installed!) Uses GNU Poker Lib: eval7.h

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

CGetRanks

public static double CGetRanks(int[] board,
                               int[] ranks)

getRanksNative

public static int[][] getRanksNative(Hand board)

getRanks

public static 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.


handRank

public double handRank(Card c1,
                       Card c2,
                       Hand h,
                       int np)
Calculates the probability of having the best hand against several 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 double handRank(Card c1,
                       Card c2,
                       Hand h)
Calculates the probability of having the best hand against one 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,
                              int[][] 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

getNumWorse

public int getNumWorse()
Get the number of hands worse than the last hand ranked.


getNumBetter

public int getNumBetter()
Get the number of hands better than the last hand ranked.


getNumTied

public int getNumTied()
Get the number of hands tied with the last hand ranked.


isTheNuts

public static final boolean isTheNuts(Card c1,
                                      Card c2,
                                      Hand board,
                                      int[][] rankCache)
Determine if the hand is the nuts (no hands beat it)

Returns:
true if no other hands beat this hand.

getBest5CardHand

public static 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.

Find_Hand

public static int Find_Hand(int[] hand,
                            int[] best)

rankHand_Java

public static final int rankHand_Java(Hand h)
Get a numerical ranking of this hand. Uses java based code, so may be slower than using the native methods, but is more compatible this way. Based on Denis Papp's Loki Hand ID code (id.cpp) Given a 1-9 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 1-9 card hand
Returns:
a unique number representing the hand strength of the best 5-card poker hand in the given 7 cards. The higher the number, the better the hand is.

ppot1

public static double ppot1(int c1,
                           int c2,
                           int[] bd,
                           double[] weights,
                           double[] result)

ppot1

public static double ppot1(Card c1,
                           Card c2,
                           Hand bd,
                           poker.ai.model.WeightTable wt)

potential

public static double[] potential(Card c1,
                                 Card c2,
                                 Hand bd,
                                 poker.ai.model.WeightTable wt)

test

public static void test()