A game-theoretic poker player (written in 2005)
A game-theoretic poker player (written in 2005)
This is a game-theoretic, heads-up limit Texas Hold'em poker player I wrote in 2005, based on the paper Approximating Game-Theoretic Optimal Strategies for Full-scale Poker. It's about 6,000 lines of Java.
Playing the optimal strategy for any game guarantees that you'll achieve at least the expected value of that game. In poker, assuming no rake, the expected value is zero, so if you can compute the optimal strategy then you're guaranteed not to lose on average.
Consider rock-paper-scissors. The optimal strategy for that game is to throw rock 1/3'rd of the time, paper 1/3'rd, and scissors 1/3'rd. If you play by this strategy you are guaranteed not to lose on average, regardless of what strategy your opponent plays by. (Note that even if your opponent throws rock every time, you'll still just tie (not lose) on average. But there are other games where the optimal strategy can dominate some opponents' strategies, and poker is one of them.)
It's just too hard to compute the optimal strategy for poker, even two player limit poker. But we can compute the optimal strategy for an abstract version of poker that, for example, during pre-flop betting treats pairs of aces the same way as pairs of kings.
This code computes the optimal strategy for an abstraction of poker that it builds based on the strength of different hands in different situations.
A more detailed description of this idea is given in the paper Approximating Game-Theoretic Optimal Strategies for Full-scale Poker (Billings, 2003).
Okay, so how good is the resulting player? Well, you can tweak how abstract the game should be at each stage. The less abstract the game, the better the player will be, but you'll hit computation and memory constraints.
The furthest I got was computing five clusters worth of representation for each turn. This took about a month to compute using three machines in my apartment living room. As a median-skilled poker player I could beat the resulting player, but not that easily.
Our abstraction of the game is fairly coarse. We can build a less abstract version of the game by leveraging the dramatic reduction in game size post-flop. The whole game tree has 10^18 nodes, but after you have your two hole cards and after the flop, there are just three rounds of betting and (47 choose 2) more cards that are coming. It's possible to compute the exact optimal strategy for such a narrowed-down game.
So what we should do is: for every (52 choose 2) * (50 choose 3) combination of post-flop states, compute the exact optimal strategy. Each result will also tell you the expected value of that sub-game. Then you compute the starting strategy for each (52 choose 2) initial states substituting the expected value from the sub-games as terminal nodes in the game tree.
This isn't an exact version of the game, but it's far better.
The problem is it'd take about 400,000 CPU-hours to compute.
So I started working on this during MIT's Independent Activities Period in January 2006, but I never finished the code. I stopped because classes started, but also because I didn't have access to 400k cpu-hours. (Coincidentally, I now have access to that kind of compute through Gridspot, but alas working on this is no longer feasible given my opportunity costs.)
_game.Cards to control the parameters of the poker game you're computing for (eg 14 versus 52 card poker) and how many clusters you want at each turn.Compute showdown rankings
Constants.DATA_FILE_REPOSITORY first and create the subdirectory {{ GAME_NAME }}/5, before running.stage1.DoShowdownsCreate files sorted on hole cards, and counts of winCounts (+ tiecount / 2) for hole cards during pre-flop, post-flop, post-turn, plus a new data format
stage1.DoBacktrackingCalculate clustering into abstract game
stage2 directory in {{ GAME_NAME }} subdirstage2.DoClusteringStep1 with command line argument 0stage2.DoClusteringStep2 with command line arguments 0 5Calculate transition probabilities for abstract game
stage2.DoStartClusterPDTstage2.DoTransitionPDTStep1 0 5stage2.DoTransitionPDTStep2 5stage2.DoTerminalClusterValuesStep1stage2.DoTerminalClusterValuesStep2Construct game tree, convert game tree to sequence form (single pass), solve sequence form LP problem
stage3.DoGT rootstage3.DoPreprocessRm mem-heavy rootstage3.DoWriteLP root{{ GAME_NAME }}\stage3\root, run bpmpd game.p1.mps and bpmpd game.p2.mps/net1/poker/poker_data is the Constants.DATA_FILE_REPOSITORY, and 52-5-1.1 is the {{ GAME_NAME }}. bpmpd resides in /net1.…Build your player data files around the resulting mixed strategy
stage4.DoConvertSolsForRndAccess rootstage4.DoConvertSolsForRndAccess all-subtreesUse your player
stage4.MeerkatPlayer classThis code is released under the public domain / no license.
No open issues yet, or sync has not completed.