glassfrog.handevaluator
Class HandEvaluator

java.lang.Object
  extended by glassfrog.handevaluator.HandEvaluator

public class HandEvaluator
extends java.lang.Object

Class for identifying / comparing / ranking Hands.

Author:
Aaron Davidson, Darse Billings, Denis Papp

Field Summary
static int FIVEKIND
           
private static int flush
           
static int FLUSH
           
static int FOURKIND
           
private static int fullhouse
           
static int FULLHOUSE
           
private static java.lang.String[] hand_name
           
static int HIGH
           
private static int highcard
           
private static int ID_GROUP_SIZE
           
private static int nopair
           
static int NUM_HANDS
           
private static int NUM_RANKS
           
private static int pair
           
static int PAIR
           
private static int POKER_HAND
           
private static int quads
           
private static java.lang.String[] rank_name
           
private static int straight
           
static int STRAIGHT
           
static int STRAIGHTFLUSH
           
private static int strflush
           
static int THREEKIND
           
private static int trips
           
private static int twopair
           
static int TWOPAIR
           
private static int unknown
           
 
Constructor Summary
HandEvaluator()
           
 
Method Summary
private  int Best_Hand(int[] hand1, int[] hand2)
           
private static boolean Check_StrFlush(int[] hand, int[] dist, int[] best)
           
 int compareHands(EvaluateHand h1, EvaluateHand h2)
          Compares two hands against each other.
 int compareHands(int rank1, EvaluateHand h2)
          Compares two 5-7 card hands against each other.
private  java.lang.String drb_Name_Hand(int handtype)
          Get a string from a hand type.
private  void Find_Flush(int[] hand, int[] dist, int[] best)
           
private  void Find_FullHouse(int[] hand, int[] dist, int[] best)
           
private  int Find_Hand(int[] hand, int[] best)
           
private  void Find_NoPair(int[] hand, int[] dist, int[] best)
           
private  void Find_Pair(int[] hand, int[] dist, int[] best)
           
private  void Find_Quads(int[] hand, int[] dist, int[] best)
           
private  void Find_Straight(int[] hand, int[] dist, int[] best)
           
private  void Find_Trips(int[] hand, int[] dist, int[] best)
           
private  void Find_TwoPair(int[] hand, int[] dist, int[] best)
           
 EvaluateHand getBest5CardHand(EvaluateHand h)
          Get the best 5 card poker hand from a 7 card hand
 int[][] getRanks(EvaluateHand board)
          Given a board, cache all possible two card combinations of hand ranks, so that lightenting fast hand comparisons may be done later.
private static byte ID_ExistsStraightFlush(EvaluateHand h, byte major_suit)
           
private static int ID_KickerValue(byte[] paired, int kickers, byte[] not_allowed)
           
private static int ID_KickerValueSuited(EvaluateHand h, int kickers, byte suit)
           
static void main(java.lang.String[] args)
           
private static java.lang.String name_hand(int rank)
          Return a string naming the hand
static java.lang.String nameHand(EvaluateHand h)
          Given a hand, return a string naming the hand ('Ace High Flush', etc..)
private static int pow(int n, int p)
           
 int rankHand(EvaluateCard c1, EvaluateCard c2, EvaluateHand h)
          Get a numerical ranking of this hand.
static int rankHand(EvaluateHand h)
          Get a numerical ranking of this hand.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unknown

private static final int unknown
See Also:
Constant Field Values

strflush

private static final int strflush
See Also:
Constant Field Values

quads

private static final int quads
See Also:
Constant Field Values

fullhouse

private static final int fullhouse
See Also:
Constant Field Values

flush

private static final int flush
See Also:
Constant Field Values

straight

private static final int straight
See Also:
Constant Field Values

trips

private static final int trips
See Also:
Constant Field Values

twopair

private static final int twopair
See Also:
Constant Field Values

pair

private static final int pair
See Also:
Constant Field Values

nopair

private static final int nopair
See Also:
Constant Field Values

highcard

private static final int highcard
See Also:
Constant Field Values

POKER_HAND

private static final int POKER_HAND
See Also:
Constant Field Values

HIGH

public static final int HIGH
See Also:
Constant Field Values

PAIR

public static final int PAIR
See Also:
Constant Field Values

TWOPAIR

public static final int TWOPAIR
See Also:
Constant Field Values

THREEKIND

public static final int THREEKIND
See Also:
Constant Field Values

STRAIGHT

public static final int STRAIGHT
See Also:
Constant Field Values

FLUSH

public static final int FLUSH
See Also:
Constant Field Values

FULLHOUSE

public static final int FULLHOUSE
See Also:
Constant Field Values

FOURKIND

public static final int FOURKIND
See Also:
Constant Field Values

STRAIGHTFLUSH

public static final int STRAIGHTFLUSH
See Also:
Constant Field Values

FIVEKIND

public static final int FIVEKIND
See Also:
Constant Field Values

NUM_HANDS

public static final int NUM_HANDS
See Also:
Constant Field Values

NUM_RANKS

private static final int NUM_RANKS
See Also:
Constant Field Values

ID_GROUP_SIZE

private static final int ID_GROUP_SIZE
See Also:
Constant Field Values

hand_name

private static final java.lang.String[] hand_name

rank_name

private static final java.lang.String[] rank_name
Constructor Detail

HandEvaluator

public HandEvaluator()
Method Detail

main

public static void main(java.lang.String[] args)

rankHand

public int rankHand(EvaluateCard c1,
                    EvaluateCard c2,
                    EvaluateHand 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(EvaluateHand h)
Given a hand, return a string naming the hand ('Ace High Flush', etc..)


compareHands

public int compareHands(EvaluateHand h1,
                        EvaluateHand 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,
                        EvaluateHand 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(EvaluateHand 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 EvaluateHand getBest5CardHand(EvaluateHand 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.

drb_Name_Hand

private java.lang.String drb_Name_Hand(int handtype)
Get a string from a hand type.

Parameters:
handtype - number coding a hand type
Returns:
name of hand type

Check_StrFlush

private static boolean Check_StrFlush(int[] hand,
                                      int[] dist,
                                      int[] best)

Find_Quads

private void Find_Quads(int[] hand,
                        int[] dist,
                        int[] best)

Find_FullHouse

private void Find_FullHouse(int[] hand,
                            int[] dist,
                            int[] best)

Find_Flush

private void Find_Flush(int[] hand,
                        int[] dist,
                        int[] best)

Find_Straight

private void Find_Straight(int[] hand,
                           int[] dist,
                           int[] best)

Find_Trips

private void Find_Trips(int[] hand,
                        int[] dist,
                        int[] best)

Find_TwoPair

private void Find_TwoPair(int[] hand,
                          int[] dist,
                          int[] best)

Find_Pair

private void Find_Pair(int[] hand,
                       int[] dist,
                       int[] best)

Find_NoPair

private void Find_NoPair(int[] hand,
                         int[] dist,
                         int[] best)

Best_Hand

private int Best_Hand(int[] hand1,
                      int[] hand2)

Find_Hand

private int Find_Hand(int[] hand,
                      int[] best)

ID_ExistsStraightFlush

private static final byte ID_ExistsStraightFlush(EvaluateHand h,
                                                 byte major_suit)

ID_KickerValue

private static final int ID_KickerValue(byte[] paired,
                                        int kickers,
                                        byte[] not_allowed)

ID_KickerValueSuited

private static final int ID_KickerValueSuited(EvaluateHand h,
                                              int kickers,
                                              byte suit)

rankHand

public static final int rankHand(EvaluateHand 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.

pow

private static int pow(int n,
                       int p)

name_hand

private static java.lang.String name_hand(int rank)
Return a string naming the hand

Parameters:
rank - calculated by rankHand_java()