Thursday, June 08, 2006

Combinations, Permutations, and Hand Values

You probably remember covering Permutations and Combinations in your High School math class. In case you missed that day of school, here's a quick summary.

Permutations are used when you care about order. For example, As Ks would be considered unique from Ks As. Combinations are used when order doesn't matter.

In Texas Holdem the hole cards As Ks (the ace of spades and the king of spades) are considered equivalent to Ks As. So combinations are used when calculating the number of hands.

The formula for combinations is nCk=n!/(k!*(n-k)!). To calculate the number of unique hole card combinations in Texas Holdem you substitute the following 52C2= 52!/(2!*(52-2)!) which is 1326 total hands.

In the Hand Evaluator library (available in the downloads area on the left), we use 52 bits of a 64 bit int as a hand mask. A hand mask describes a specific hand. Each of the 52 bits in the mask describe a specific card. When the bit is on the card is present. Combinations are used to describe the total number of possible unique hand masks.

The Hand Evaluator library also uses hand values. A hand value is the result of passing a hand mask into the Evaluate() method. What's returned is an integer value that can be used to determine which hands are of higher value than another.

So looking at the number of unique hand value is also an interesting thing to know. The following table shows the number of hand values, permutations and combinations (hand masks) that a hand of a specific number of cards requires.

The first time I saw anyone work through this was Cactus Kev. I found the results for 5 card hands to be, well, shocking. I never expected there to be only 7462 unique hand values for 5 card hands. Cactus Kev uses this fact to create a very fast hand evaluator algorithm.

What I found even more surprising (at least until I spent sometime thinking about it), was that 6 and 7 card hands have even fewer possible hand values.

Though this may seem like trivia, understanding this has been quite helpful to me. I hope it's useful for you.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?