Pages

Saturday, September 22, 2012

Poker 3: Exhaustive Analysis

There are 169 different possible PreFlop hands:
  • C(13,2) = 78 suited hands
  • C(13,2) = 78 offsuited hands, excluding pairs
  • 13 pairs

For a given such Pre Flop hand, let us generate all possible 5 table cards. There are C(50,5) = 2,118,760 different tables. Assuming each set of table cards is equally likely, i.e. neglecting the other players hole cards, we can compute the distribution of hand ranks associated to a PreFlop hand.

Below are 3 interactive CDFs.
The first one displays the probability distribution of hand ranks for a given PreFlop hand, by hand type (e.g. high card, pair, two pairs, etc), and by hand rank (from 1 to 7468) bucket.
The second one displays the same probability distribution by hand rank without buckets (As it is maybe less easily readable, zooming is possible), as well as a focus of the most frequent best hands  for a given PreFlop hand.
The third one displays, for the same distribution, the number of hands for a given PreFlop hand.

You can view them with the free CDF (computable document format) player.
The CDFs were created with Mathematica 8.0.4 and the CDF player enables you to locally run Mathematica code.
You may have to 'Enable Dynamics' to view the contents.





Now, instead of considering a single PreFlop hand, let us examine how any two PreFlop hands compare. In order to do so, we must first determine all possible pairs of PreFlop hands.
Provisionally there are C(169,2)+169 = 14,365 possible pairs. But on closer inspection, for each such pair, there may be several combinations of suits in both hands. Specifically, the combinations of suits depends on whether each hand is suited/offsuited, a pair/not a pair. The exhaustive range of combinations is in the tables below.



The number of suit combinations ranges from 2 to 7 depending on the pair characteristics (suited/offsuited, pair/no pair) considered. But note that these combinations represent the maximum diversity in terms of suit possibilities for a pair of PreFlop hand pair. In several cases these combinations may collapse to a narrower range of possibilities. For example, 98o vs. 98o are two offsuited hands, and none is a pair. The table mentions 7 suit combinations, but because the faces overlap, 4 of these combinations disappear, or I should say merge into the 3 remaining:
98 vs. 98       98 vs. 98       98 vs. 98

Going though all pairs of PreFlop hands and suit combinations, we can determine the exact number of distinct (in terms of hand strength) pairs of PreFlop hands: 47,008. Which means the average number of suits combination for each pair of PreFlop hands identified as FFS/O (F=face, S/O=suited/offsuited) is ~3.27.

Below is an interactive CDF,  displaying the equity distribution for all one-to-one pair of PreFlop hands confrontation. I call equity the fraction of the money in the pot that a player is likely to win if both players play their hands out all the way to showdown, and assuming the table cards are drawn randomly.

You can view them with the free CDF (computable document format) player.
The CDFs were created with Mathematica 8.0.4 and the CDF player enables you to locally run Mathematica code.
You may have to 'Enable Dynamics' to view the contents.




Now that we have performed an exhaustive comparison of all PreFlop hands, it would be interesting, to make sense of it all, create an overview of the equity distribution for all pairs of PreFlop hands.
So we must somewhat simplify the ranking of PreFlop hands and ignore the combinations of card suits for pair of each PreFlop hands. Can this be done without distorting the real relative strength of two PreFlop hands ?
In order to determine that we have isolated the pairs of PreFlop hands that cannot be ranked for all combinations of suits across both hands, i.e. the pairs for which the choice of the combination of suits changes the relative strength of the PreFlop hands. There are 51 (out of 14,365) such pairs. The table below shows these 51 pairs of PreFlop hands and the equi-weighted arithmetic average across all suits combinations (irrespective of the probability of occurrence of each combination) of their equity.


 We can see that those 'undetermined' pair of PreFlop hands all have a near 50-50% equity distribution. In other words, they are near equal, and it seems reasonable, from now on, to consider the equi-weighted arithmetic average across all suits combinations as a proxy for the equity distribution in a pair of PreFlop hands.

After this simplification, we can represent the one-to-one equity distribution of all 14,365 pairs of PreFlop hands in an array. In fact the array contains 169^2 = 28,561 points but is symmetrical. 

Below is an interactive CDF displaying a bird eye view of the equity distribution for all one-to-one pair of PreFlop hands.

The PreFlop hands are ordered from 1 to 169 as follows:
{22o,32o,32s,33o,42o,42s,43o,43s,44o,52o,52s,53o,53s,54o,54s,55o,62o,62s,63o,63s,64o,64s,65o,65s,66o,72o,72s,73o,73s,74o,74s,75o,75s,76o,76s,77o,82o,82s,83o,83s,84o,84s,85o,85s,86o,86s,87o,87s,88o,92o,92s,93o,93s,94o,94s,95o,95s,96o,96s,97o,97s,98o,98s,99o,T2o,T2s,T3o,T3s,T4o,T4s,T5o,T5s,T6o,T6s,T7o,T7s,T8o,T8s,T9o,T9s,TTo,J2o,J2s,J3o,J3s,J4o,J4s,J5o,J5s,J6o,J6s,J7o,J7s,J8o,J8s,J9o,J9s,JTo,JTs,JJo,Q2o,Q2s,Q3o,Q3s,Q4o,Q4s,Q5o,Q5s,Q6o,Q6s,Q7o,Q7s,Q8o,Q8s,Q9o,Q9s,QTo,QTs,QJo,QJs,QQo,K2o,K2s,K3o,K3s,K4o,K4s,K5o,K5s,K6o,K6s,K7o,K7s,K8o,K8s,K9o,K9s,KTo,KTs,KJo,KJs,KQo,KQs,KKo,A2o,A2s,A3o,A3s,A4o,A4s,A5o,A5s,A6o,A6s,A7o,A7s,A8o,A8s,A9o,A9s,ATo,ATs,AJo,AJs,AQo,AQs,AKo,AKs,AAo}

The color code for the equity is the following: The bluer, the closer to 100%; the redder, the closer to 0%; white is 50%.

The grid-like pattern is due to the pairs, the strength of which is important in a two player game, even for small pairs, and significantly greater than the hands before and after in the lexicographic order described above. 

You can view them with the free CDF (computable document format) player.
The CDFs were created with Mathematica 8.0.4 and the CDF player enables you to locally run Mathematica code.
You may have to 'Enable Dynamics' to view the contents.




Finally, for a finer view, we show a section of the array above for each PreFlop hand, in the CDF below.

You can view them with the free CDF (computable document format) player.
The CDFs were created with Mathematica 8.0.4 and the CDF player enables you to locally run Mathematica code.
You may have to 'Enable Dynamics' to view the contents.




After exploring single and pairs of PreFlop hands, we now turn show a hand equity calculator that determines each player equity at any point in a game. The number of player ranges from 2 to 10. The hand equity calculator goes through all possible table cards and determines, using the hand evaluator described in the previous post 'Poker 2: Hand Evaluator', the equity of each player for each set of possible table cards. This is very tractable as the number of games to go through is smaller than 2,000,000. More precisely the maximum number of games to go though is for 2 players pre Flop: C(48,5) = 1,712,304.

Below is an interactive CDF,  in which you can set the number of players, choose or shuffle the hole cards and the table cards Flop/Turn/River. The result is for each player the equity of this hand, split in (1) the equity contributed by wins (i.e. the player takes the whole pot) and (2) the equity contributed by ties (i.e. at least two players have the best hand and the pot is equally split between the winners). Additionally the number of games gone through by the algorithm is displayed, as well as the hand type and hand rank for each player after all table cards are determined.

You can view them with the free CDF (computable document format) player.
The CDFs were created with Mathematica 8.0.4 and the CDF player enables you to locally run Mathematica code.
You may have to 'Enable Dynamics' to view the contents.

The hand evaluator is coded in C for speed. The resulting executable must be stored in a directory named 'MathLinkExec' under your home directory, for the CDF to know where to look the hand evaluator. Beware: You must give the CDF access to this executable only if you trust that there is nothing harmful in it. Naturally, I guarantee this executable is indeed safe !

More generally, in the github repo containing everything about these poker posts, there is a one to one match between the source files in the MathLink folder and the executable in the Exec folder.



  • Hand evaluator executable - to be stored in <user>/MathLinkExec/ and named equityPreFlopHand. For example under OSX, you must have the executable as follows: ~/MathLinkExec/equityPreFlopHand