com.asdf.plugins.pokergames
Class HandEval

java.lang.Object
  extended by com.asdf.plugins.pokergames.HandEval

public class HandEval
extends java.lang.Object

This class evaluates poker hands with methods eval_5cards and eval_7cards. Returns an integer representing the "strength" of a hand. A hand with greater number wins against lower value hands.


Field Summary
 int FLUSH
           
 int FOUR_OF_A_KIND
           
 int FULL_HOUSE
           
 int HIGH_CARD
           
 int ONE_PAIR
           
 int STRAIGHT
           
 int STRAIGHT_FLUSH
           
 EvalTables tables
           
 int THREE_OF_A_KIND
           
 int TWO_PAIR
           
static java.lang.String[] value_str
           
 
Constructor Summary
HandEval(EvalTables evalTables)
          Constructor.
 
Method Summary
 int eval_5cards(int c1, int c2, int c3, int c4, int c5)
          Calculates the absolute value of a given 5 card poker-hand.
 BestHand eval_6cards(int[] cards)
          Cycles through all 5 card combinations of the 6 cards, and returns the best hand and it's value.
 BestHand eval_7cards(int[] cards)
          Cycles through all 5 card combinations of the 7 cards, and returns the best hand and it's value.
 int find_card(int rank, int suit, java.util.Vector<java.lang.Integer> deck)
          This routine will search a deck for a specific card (specified by rank/suit), and return the INDEX giving the position of the found card.
 int findit(int key)
          This function performs a binary search on a presorted array of integer representasions of hands.
 int hand_rank(int val)
          Obtains the hand type of a hand, given it's value.
 void init_deck(java.util.Vector<java.lang.Integer> deck)
          Describes how a deck should be built if this evaluator is intended to be used with the deck.
 int RANK(int x)
          Getter for card rank for a card in integer representation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tables

public EvalTables tables

STRAIGHT_FLUSH

public final int STRAIGHT_FLUSH
See Also:
Constant Field Values

FOUR_OF_A_KIND

public final int FOUR_OF_A_KIND
See Also:
Constant Field Values

FULL_HOUSE

public final int FULL_HOUSE
See Also:
Constant Field Values

FLUSH

public final int FLUSH
See Also:
Constant Field Values

STRAIGHT

public final int STRAIGHT
See Also:
Constant Field Values

THREE_OF_A_KIND

public final int THREE_OF_A_KIND
See Also:
Constant Field Values

TWO_PAIR

public final int TWO_PAIR
See Also:
Constant Field Values

ONE_PAIR

public final int ONE_PAIR
See Also:
Constant Field Values

HIGH_CARD

public final int HIGH_CARD
See Also:
Constant Field Values

value_str

public static java.lang.String[] value_str
Constructor Detail

HandEval

public HandEval(EvalTables evalTables)
Constructor. Sets the tables to point to the location given as parameter. Enables the possibility of not having an instance of the tables (which are rather large) for every instance of HandEval, and thus, for every poker game instance.

Parameters:
evalTables - Reference to an EvalTables instance.
Method Detail

init_deck

public void init_deck(java.util.Vector<java.lang.Integer> deck)
Describes how a deck should be built if this evaluator is intended to be used with the deck.

Parameters:
deck - A Vector of Integer representations of Cards.

findit

public int findit(int key)
This function performs a binary search on a presorted array of integer representasions of hands. The index gives the absolute value of the hand, and tables.products contains the prime number product representation of the hand.

Parameters:
key - Prime number representation of the given hand.
Returns:
Absolute value of queried hand, or -1 if unable to resolve hand value.

find_card

public int find_card(int rank,
                     int suit,
                     java.util.Vector<java.lang.Integer> deck)
This routine will search a deck for a specific card (specified by rank/suit), and return the INDEX giving the position of the found card. If it is not found, then it returns -1

Parameters:
rank - Rank of queried card.
suit - Suit of queried card. (0x8000 || 0x4000 || 0x2000 || 0x1000)
deck - A deck of cards.
Returns:
The index in the deck where the card is located, or -1 if the card is not in the deck.

eval_6cards

public BestHand eval_6cards(int[] cards)
Cycles through all 5 card combinations of the 6 cards, and returns the best hand and it's value.

Parameters:
cards - A 6 card hand in integer representation. See com.asdf.utils.Card.getInt().
Returns:
The best combination of 5 cards in this hand, and it's value. If there are multiple hands of the same value, the first one encountered is preferred.

eval_7cards

public BestHand eval_7cards(int[] cards)
Cycles through all 5 card combinations of the 7 cards, and returns the best hand and it's value.

Parameters:
cards - A 7 card hand in integer representation. See com.asdf.utils.Card.getInt().
Returns:
The best combination of 5 cards in this hand, and it's value. If there are multiple hands of the same value, the first one encountered is preferred.

eval_5cards

public int eval_5cards(int c1,
                       int c2,
                       int c3,
                       int c4,
                       int c5)
Calculates the absolute value of a given 5 card poker-hand.

Parameters:
c1 - card1
c2 - card2
c3 - card3
c4 - card4
c5 - card5
Returns:
value of the hand

hand_rank

public int hand_rank(int val)
Obtains the hand type of a hand, given it's value.

Parameters:
val - Value of a poker hand.
Returns:
integer representation of the hand type. Use this to index value_str to obtain string representation.

RANK

public int RANK(int x)
Getter for card rank for a card in integer representation.

Parameters:
x - a card.
Returns:
Rank of the given card.