with multiple decks of cards, regardless of what wildcards are used.
It all started with what seemed like a simple question. In a poker game with eight players, using two decks of cards, with five card hands and fives wild, what are the odds for each type of hand? What about seven card hands with sevens wild? What hands should you play and what should you fold?
There are a number of ways to calculate the odds in poker games. For most traditional games, they have been computed manually long ago. You can also enumerate all possible hands. But adding in wildcards and multiple decks makes the calculation harder. The most practical approach is just to simulate the game and play a number of hands, the odds are easily determined if you play a few million hands.
If you allow for multiple decks and wildcards, there are 380,204,032 permutations possible with 5 cards. There are 12,051 distiguishable hands. With a single deck there are only 7,462 distinct 5-card hands. Here are similar lists for 5-card single deck deuces wild, 7-card single deck and 7-card single deck deuces wild.
The core of any poker simulation program is the poker hand evaluator function. Given a hand, it produces a number representing the evaluation of the hand, with higher numbers denoting better hands. There are a number of poker hand evaluators out there, see The Great Poker Hand Evaluator Roundup, Moritz Hammer's evaluator, PokerAI's 7-card evaluator contest, Cactus Kev’s 5-Card Evaluator, and SpecialK's 7-card evaluator. I decided to see if I could write a poker hand evaluator that could handle multiple decks and wildcards. The current version of the simulator can shuffle, deal and evaluate more than 22 million seven card hands per second on my six-year-old PC, this was measured by testing the seven card game below for a billion hands. The evaluator can evaluate hands of any size, the interface supports up to twenty cards in a hand.
Most poker hand evaluators use large lookup tables. The layered cache architecture of modern CPUs means that doing any lookup in a big table will thrash your cache and with wildcards or multiple decks, the lookup tables quickly become too large. I wrote a poker hand evaluator that does not sort the hand or use large tables. Maintaining code and data locality produced amazing speed gains. My goal was to write an evaluator that could run without requiring the enormous memory footprint that some of the really fast lookup methods have. More importantly, the evaluator supports arbitrary wild cards, multiple decks of cards, jokers, the addition or removal of arbitrary cards, and hands of any size. This means you can simulate games that single-deck no-wilds evaluators cannot handle. The resulting simulator runs so fast that it can be used in real time while using less than a megabyte of memory.
Hand size now 5 cards.
Poker with 2 decks, 0 jokers, 8 players, hand size 5 cards.
This test was run on a Windows XP machine with an Intel Q6600 @ 2.4GHz. Note that it shuffled, dealt and evaluated hands for eight players playing 5 million hands each, which was overkill. Simulation of all 40 million hands required 1.234 seconds – more than 32 million hands per second. The output shows the probability of victory for each type of hand and each specific high card variant of that hand. The "break" hand for this game, where you have more than a 50% chance of winning, is three queens, which wins 54% of the time if everybody stays in.
What about the seven card question?
Hand size now 7 cards.
Poker with 2 decks, 0 jokers, 8 players, hand size 7 cards.
This time we shuffled, dealt, and evaluated 40 million seven card hands in 1.796 seconds – more than 22 million hands per second. Now we see that the odds have shifted, so three queens now has 2% chance. The break hand for this game is four twos, which has a 54% shot.
The evaluator used by the simulator can evaluate any size poker hand. Just for fun, let's ask it something harder. Four of you sit down and deal out an entire deck of cards, so each person has 13 cards in their hand. Assuming you can even figure out what you have, what the heck is a good hand?
Hand size now 13 cards.
Poker with 1 deck, 0 jokers, 4 players, hand size 13 cards.
This time we shuffled, dealt, and evaluated 20 million thirteen card hands in 1.766 seconds – more than 11 million hands per second, even with thirteen cards to consider! If you play this game, don't go in with less than a jacks-over full house (wins 53% of the time) unless you are bluffing.
If you find this tool useful, please consider making a donation of what you think it is worth.
If you have questions or are interested in licensing the source code for commercial use, please contact me at henry.berg@codethrowdown.com.
P.S. This site is called Code Throwdown because the very early versions of the simulator came from a programming duel with a friend.