C# Class PsHandler.PokerMath.Evaluator.Hand

Represents a Texas Holdem Hand
Inheritance: IComparable
Exibir arquivo Open project: kampiuceris/PsHandler

Public Properties

Property Type Description
CLUB_OFFSET int
CardJoker int
CardMasksTable ulong[]
CardTable string[]
Clubs int
DIAMOND_OFFSET int
Diamonds int
HEART_OFFSET int
Hearts int
NCardsWJoker int
NumberOfCards int
Rank2 int
Rank3 int
Rank4 int
Rank5 int
Rank6 int
Rank7 int
Rank8 int
Rank9 int
RankAce int
RankJack int
RankKing int
RankQueen int
RankTen int
SPADE_OFFSET int
Spades int

Public Methods

Method Description
BitCount ( ulong bitField ) : int

Fast Bitcounting method (adapted from snippets.org)

CardRank ( int card ) : int

Given a card value, returns it's rank

CardSuit ( int card ) : int

Given a card value, returns it's suit

CompareTo ( object obj ) : int

Used to compare one hand to another. This method allows normal compare functions to work as expected with a hand.

DescriptionFromHand ( string hand ) : string

Takes an string describing a hand and returns the description.

DescriptionFromHandValueInternal ( uint handValue ) : string
DescriptionFromMask ( ulong cards ) : string

Equals ( object obj ) : bool

Test for equality

Eval ( string hand ) : uint

Evaluates a hand (passed as a string) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.

Eval ( ulong cards ) : uint

Evaluates a hand (passed as a hand mask) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.

Eval ( ulong cards, int numberOfCards ) : uint

Evaluates a hand (passed as a hand mask) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.

Evaluate ( string pocketCardsStr, string boardStr, string deadStr ) : EvaluationPocket
EvaluateType ( ulong mask ) : HandTypes

Evaluates the card mask and returns the type of hand it is. This function is faster (but provides less information) than Evaluate or Evaluate.

EvaluateType ( ulong mask, int cards ) : HandTypes

This function is faster (but provides less information) than Evaluate or Evaluate.

GapCount ( ulong mask ) : int

Counts the number of empty space between adjacent cards. 0 means connected, 1 means a gap of one, 2 means a gap of two and 3 means a gap of three.

GetHashCode ( ) : int

Returns hash code

Hand ( ) : System

Default constructor

Hand ( string pocket, string board ) : System

Constructor

HandOdds ( string pockets, string board, string dead, long wins, long ties, long losses, long &totalHands ) : void

Used to calculate the wining information about each players hand. This function enumerates all possible remaining hands and tallies win, tie and losses for each player. This function typically takes well less than a second regardless of the number of players.

HandPlayerOpponentOdds ( string pocketcards, string boardcards, double &player, double &opponent ) : void

Given a set of pocket cards and a set of board cards this function returns the odds of winning or tying for a player and a random opponent.

HandPlayerOpponentOdds ( ulong ourcards, ulong board, double &player, double &opponent ) : void

Given a set of pocket cards and a set of board cards this function returns the odds of winning or tying for a player and a random opponent.

HandPotential ( ulong pocket, ulong board, double &ppot, double &npot ) : void

Returns the positive and negative potential of the current hand. This funciton is described in Aaron Davidson's masters thesis (davidson.msc.pdf).

HandType ( uint handValue ) : uint
Hands ( int numberOfCards ) : IEnumerable

Enables a foreach command to enumerate all possible ncard hands.

Hands ( ulong shared, ulong dead, int numberOfCards ) : IEnumerable

Enables a foreach command to enumerate all possible ncard hands.

IsConnected ( ulong mask ) : bool

Returns true if the cards in the two card hand are connected.

IsSuited ( ulong mask ) : bool

This function returns true if the cards in the hand are all one suit

Mask ( int index ) : ulong

This is a fast way to look up the index mask.

MaskToString ( ulong mask ) : string

Turns a card mask into the equivalent human readable string.

NextCard ( string cards, int &index ) : int

Parses Card strings (internal)

Outs ( ulong player, ulong board ) : int

Returns the number of outs possible with the next card.

OutsMask ( ulong player, ulong board ) : ulong

Creates a Hand mask with the cards that will improve the specified players hand against a list of opponents or if no opponents are list just the cards that improve the players current had. Please note that this only looks at single cards that improve the hand and will not specifically look at runner-runner possiblities.

ParseCard ( string card ) : int

Reads an string definition of a card and returns the Card value.

ParseHand ( string hand ) : ulong

Parses an string description of a hand and returns a hand mask.

ParseHand ( string hand, int &cards ) : ulong

ParseHand ( string pocket, string board, int &cards ) : ulong

This static method parses the passed pocket cards and board and produces a card mask.

PocketHand169Type ( ulong mask ) : PocketHand169Enum

Given a pocket pair mask, the PocketPairType cooresponding to this mask will be returned.

RandomHands ( int ncards, double duration ) : IEnumerable

Iterates through random hands that meets the specified requirements until the specified time duration has elapse. Please note that this iterator requires interop. If you need and interop free hand evaluator you should remove this function along with the other interop functions in this file.

RandomHands ( int ncards, int trials ) : IEnumerable

Iterates through random hands with ncards number of cards. This iterator will return the number of masks specifed in trials. Masks can be repeated.

RandomHands ( ulong shared, ulong dead, int ncards, double duration ) : IEnumerable

Iterates through random hands that meets the specified requirements until the specified time duration has elapse. Please note that this iterator requires interop. If you need and interop free hand evaluator you should remove this function along with the other interop functions in this file.

RandomHands ( ulong shared, ulong dead, int ncards, int trials ) : IEnumerable

This function iterates through random hands returning the number of random hands specified in trials. Please note that a mask can be repeated.

ToString ( ) : string

Returns the string representing the hand.

TopCard ( System hv ) : uint
ValidateHand ( string hand ) : bool

This function takes a string representing a full or partial holdem hand and validates that the text represents valid cards and that no card is duplicated.

ValidateHand ( string pocket, string board ) : bool

This function takes a string representing pocket cards and a board and then validates that the text represents a valid hand.

operator ( ) : bool

Test for inequality.

Private Methods

Method Description
CardMask ( ulong cards, int suit ) : uint
DescriptionFromHandValue ( uint handValue ) : string
Eval ( string pocketCardsStr, IEnumerable boardStr, IEnumerable deadStr ) : int
FIFTH_CARD ( System hv ) : uint
FOURTH_CARD ( System hv ) : uint
GetRandomHand ( ulong dead, int ncards, Random rand ) : ulong

Returns a rand hand with the specified number of cards and constrained to not contain any of the passed dead cards.

HANDTYPE_VALUE ( HandTypes ht ) : uint
HandPotentialOpp ( ulong ourcards, ulong board, ulong oppcards, int index, int &HP ) : void

Internal function used by HandPotential.

MaskToDescription ( ulong mask ) : string
QueryPerformanceCounter ( long &lpPerformanceCount ) : bool
QueryPerformanceFrequency ( long &lpFrequency ) : bool
SECOND_CARD ( System hv ) : uint
SECOND_CARD_VALUE ( System c ) : uint
THIRD_CARD ( System hv ) : uint
THIRD_CARD_VALUE ( System c ) : uint
TOP_CARD_VALUE ( System c ) : uint
UpdateHandMask ( ) : void

Updates handmask and handval, called when card strings change

Method Details

BitCount() public static method

Fast Bitcounting method (adapted from snippets.org)
public static BitCount ( ulong bitField ) : int
bitField ulong ulong to count
return int

CardRank() public static method

Given a card value, returns it's rank
public static CardRank ( int card ) : int
card int card value
return int

CardSuit() public static method

Given a card value, returns it's suit
public static CardSuit ( int card ) : int
card int Card value
return int

CompareTo() public method

Used to compare one hand to another. This method allows normal compare functions to work as expected with a hand.
public CompareTo ( object obj ) : int
obj object object to compare against
return int

DescriptionFromHand() public static method

Takes an string describing a hand and returns the description.
public static DescriptionFromHand ( string hand ) : string
hand string the string describing the hand
return string

DescriptionFromHandValueInternal() public static method

public static DescriptionFromHandValueInternal ( uint handValue ) : string
handValue uint
return string

DescriptionFromMask() public static method

public static DescriptionFromMask ( ulong cards ) : string
cards ulong
return string

Equals() public method

Test for equality
public Equals ( object obj ) : bool
obj object
return bool

Eval() public static method

Evaluates a hand (passed as a string) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.
public static Eval ( string hand ) : uint
hand string hand string
return uint

Eval() public static method

Evaluates a hand (passed as a hand mask) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.
public static Eval ( ulong cards ) : uint
cards ulong hand mask
return uint

Eval() public static method

Evaluates a hand (passed as a hand mask) and returns a hand value. A hand value can be compared against another hand value to determine which has the higher value.
public static Eval ( ulong cards, int numberOfCards ) : uint
cards ulong hand mask
numberOfCards int number of cards in the hand
return uint

Evaluate() public static method

public static Evaluate ( string pocketCardsStr, string boardStr, string deadStr ) : EvaluationPocket
pocketCardsStr string
boardStr string
deadStr string
return EvaluationPocket

EvaluateType() public static method

Evaluates the card mask and returns the type of hand it is. This function is faster (but provides less information) than Evaluate or Evaluate.
public static EvaluateType ( ulong mask ) : HandTypes
mask ulong card mask
return HandTypes

EvaluateType() public static method

This function is faster (but provides less information) than Evaluate or Evaluate.
public static EvaluateType ( ulong mask, int cards ) : HandTypes
mask ulong card mask
cards int number of cards in mask
return HandTypes

GapCount() public static method

Counts the number of empty space between adjacent cards. 0 means connected, 1 means a gap of one, 2 means a gap of two and 3 means a gap of three.
public static GapCount ( ulong mask ) : int
mask ulong two card hand mask
return int

GetHashCode() public method

Returns hash code
public GetHashCode ( ) : int
return int

Hand() public method

Default constructor
public Hand ( ) : System
return System

Hand() public method

Constructor
public Hand ( string pocket, string board ) : System
pocket string Pocket Cards
board string Board
return System

HandOdds() public static method

Used to calculate the wining information about each players hand. This function enumerates all possible remaining hands and tallies win, tie and losses for each player. This function typically takes well less than a second regardless of the number of players.
public static HandOdds ( string pockets, string board, string dead, long wins, long ties, long losses, long &totalHands ) : void
pockets string Array of pocket hand string, one for each player
board string the board cards
dead string the dead cards
wins long An array of win tallies, one for each player
ties long An array of tie tallies, one for each player
losses long An array of losses tallies, one for each player
totalHands long The total number of hands enumarated.
return void

HandPlayerOpponentOdds() public static method

Given a set of pocket cards and a set of board cards this function returns the odds of winning or tying for a player and a random opponent.
public static HandPlayerOpponentOdds ( string pocketcards, string boardcards, double &player, double &opponent ) : void
pocketcards string Pocket cards in ASCII
boardcards string Board cards in ASCII
player double Player odds as doubles
opponent double Opponent odds as doubles
return void

HandPlayerOpponentOdds() public static method

Given a set of pocket cards and a set of board cards this function returns the odds of winning or tying for a player and a random opponent.
public static HandPlayerOpponentOdds ( ulong ourcards, ulong board, double &player, double &opponent ) : void
ourcards ulong Pocket mask for the hand.
board ulong Board mask for hand
player double Player odds as doubles
opponent double Opponent odds as doubles
return void

HandPotential() public static method

Returns the positive and negative potential of the current hand. This funciton is described in Aaron Davidson's masters thesis (davidson.msc.pdf).
public static HandPotential ( ulong pocket, ulong board, double &ppot, double &npot ) : void
pocket ulong Hold Cards
board ulong Community cards
ppot double Positive Potential
npot double Negative Potential
return void

HandType() public static method

public static HandType ( uint handValue ) : uint
handValue uint
return uint

Hands() public static method

Enables a foreach command to enumerate all possible ncard hands.
public static Hands ( int numberOfCards ) : IEnumerable
numberOfCards int the number of cards in the hand (must be between 1 and 7)
return IEnumerable

Hands() public static method

Enables a foreach command to enumerate all possible ncard hands.
public static Hands ( ulong shared, ulong dead, int numberOfCards ) : IEnumerable
shared ulong A bitfield containing the cards that must be in the enumerated hands
dead ulong A bitfield containing the cards that must not be in the enumerated hands
numberOfCards int the number of cards in the hand (must be between 1 and 7)
return IEnumerable

IsConnected() public static method

Returns true if the cards in the two card hand are connected.
public static IsConnected ( ulong mask ) : bool
mask ulong the hand to check
return bool

IsSuited() public static method

This function returns true if the cards in the hand are all one suit
public static IsSuited ( ulong mask ) : bool
mask ulong hand to check for "suited-ness"
return bool

Mask() public static method

This is a fast way to look up the index mask.
public static Mask ( int index ) : ulong
index int index of mask
return ulong

MaskToString() public static method

Turns a card mask into the equivalent human readable string.
public static MaskToString ( ulong mask ) : string
mask ulong mask to convert
return string

NextCard() public static method

Parses Card strings (internal)
public static NextCard ( string cards, int &index ) : int
cards string string containing hand definition
index int iterator into card string
return int

Outs() public static method

Returns the number of outs possible with the next card.
public static Outs ( ulong player, ulong board ) : int
player ulong Players pocket cards
board ulong THe board (must contain either 3 or 4 cards)
return int

OutsMask() public static method

Creates a Hand mask with the cards that will improve the specified players hand against a list of opponents or if no opponents are list just the cards that improve the players current had. Please note that this only looks at single cards that improve the hand and will not specifically look at runner-runner possiblities.
public static OutsMask ( ulong player, ulong board ) : ulong
player ulong Players pocket cards
board ulong The board (must contain either 3 or 4 cards)
return ulong

ParseCard() public static method

Reads an string definition of a card and returns the Card value.
public static ParseCard ( string card ) : int
card string card string
return int

ParseHand() public static method

Parses an string description of a hand and returns a hand mask.
public static ParseHand ( string hand ) : ulong
hand string string descripton of a hand
return ulong

ParseHand() public static method

public static ParseHand ( string hand, int &cards ) : ulong
hand string
cards int
return ulong

ParseHand() public static method

This static method parses the passed pocket cards and board and produces a card mask.
public static ParseHand ( string pocket, string board, int &cards ) : ulong
pocket string ASCII string representing pocket cards
board string ASCII string representing board
cards int Number of cards represented in mask
return ulong

PocketHand169Type() public static method

Given a pocket pair mask, the PocketPairType cooresponding to this mask will be returned.
public static PocketHand169Type ( ulong mask ) : PocketHand169Enum
mask ulong
return PocketHand169Enum

RandomHands() public static method

Iterates through random hands that meets the specified requirements until the specified time duration has elapse. Please note that this iterator requires interop. If you need and interop free hand evaluator you should remove this function along with the other interop functions in this file.
public static RandomHands ( int ncards, double duration ) : IEnumerable
ncards int The number of cards in the returned hand.
duration double The amount of time to allow the generation of hands to occur. When elapsed, the iterator will terminate.
return IEnumerable

RandomHands() public static method

Iterates through random hands with ncards number of cards. This iterator will return the number of masks specifed in trials. Masks can be repeated.
public static RandomHands ( int ncards, int trials ) : IEnumerable
ncards int Number of cards required to be in the hand.
trials int Number of total mask to return.
return IEnumerable

RandomHands() public static method

Iterates through random hands that meets the specified requirements until the specified time duration has elapse. Please note that this iterator requires interop. If you need and interop free hand evaluator you should remove this function along with the other interop functions in this file.
public static RandomHands ( ulong shared, ulong dead, int ncards, double duration ) : IEnumerable
shared ulong These cards must be included in the returned hand
dead ulong These cards must not be included in the returned hand
ncards int The number of cards in the returned random hand.
duration double The amount of time to allow the generation of hands to occur. When elapsed, the iterator will terminate.
return IEnumerable

RandomHands() public static method

This function iterates through random hands returning the number of random hands specified in trials. Please note that a mask can be repeated.
public static RandomHands ( ulong shared, ulong dead, int ncards, int trials ) : IEnumerable
shared ulong Cards that must be in the hand.
dead ulong Cards that must not be in the hand.
ncards int The total number of cards in the hand.
trials int The total number of random hands to return.
return IEnumerable

ToString() public method

Returns the string representing the hand.
public ToString ( ) : string
return string

TopCard() public static method

public static TopCard ( System hv ) : uint
hv System
return uint

ValidateHand() public static method

This function takes a string representing a full or partial holdem hand and validates that the text represents valid cards and that no card is duplicated.
public static ValidateHand ( string hand ) : bool
hand string hand to validate
return bool

ValidateHand() public static method

This function takes a string representing pocket cards and a board and then validates that the text represents a valid hand.
public static ValidateHand ( string pocket, string board ) : bool
pocket string Pocket cards as a string
board string Board cards as a string
return bool

operator() public static method

Test for inequality.
public static operator ( ) : bool
return bool

Property Details

CLUB_OFFSET public_oe static_oe property

public static int CLUB_OFFSET
return int

CardJoker public_oe static_oe property

public static int CardJoker
return int

CardMasksTable public_oe static_oe property

This table is equivalent to 1UL left shifted by the index. The lookup is faster than the left shift operator.
public static ulong[] CardMasksTable
return ulong[]

CardTable public_oe static_oe property

public static string[] CardTable
return string[]

Clubs public_oe static_oe property

Represents the suit - Clubs
public static int Clubs
return int

DIAMOND_OFFSET public_oe static_oe property

public static int DIAMOND_OFFSET
return int

Diamonds public_oe static_oe property

Represents the suit - Diamonds
public static int Diamonds
return int

HEART_OFFSET public_oe static_oe property

public static int HEART_OFFSET
return int

Hearts public_oe static_oe property

Represents the suit - Hearts
public static int Hearts
return int

NCardsWJoker public_oe static_oe property

public static int NCardsWJoker
return int

NumberOfCards public_oe static_oe property

The total number of cards in a deck
public static int NumberOfCards
return int

Rank2 public_oe static_oe property

Rank of a card with a value of two.
public static int Rank2
return int

Rank3 public_oe static_oe property

Rank of a card with a value of three.
public static int Rank3
return int

Rank4 public_oe static_oe property

Rank of a card with a value of four.
public static int Rank4
return int

Rank5 public_oe static_oe property

Rank of a card with a value of five.
public static int Rank5
return int

Rank6 public_oe static_oe property

Rank of a card with a value of six.
public static int Rank6
return int

Rank7 public_oe static_oe property

Rank of a card with a value of seven.
public static int Rank7
return int

Rank8 public_oe static_oe property

Rank of a card with a value of eight.
public static int Rank8
return int

Rank9 public_oe static_oe property

Rank of a card with a value of nine.
public static int Rank9
return int

RankAce public_oe static_oe property

Rank of a card showing an Ace.
public static int RankAce
return int

RankJack public_oe static_oe property

Rank of a card showing a Jack.
public static int RankJack
return int

RankKing public_oe static_oe property

Rank of a card showing a King.
public static int RankKing
return int

RankQueen public_oe static_oe property

Rank of a card showing a Queen.
public static int RankQueen
return int

RankTen public_oe static_oe property

Rank of a card with a value of ten.
public static int RankTen
return int

SPADE_OFFSET public_oe static_oe property

public static int SPADE_OFFSET
return int

Spades public_oe static_oe property

Represents the suit - Spades
public static int Spades
return int