Poker Playground
An interactive website to learn how to play poker, and play against different poker playstyles. Developed as part of the Capstone project at Marianopolis College.
Playing against computers
Exploring the backend architecture
The app has a backend built entirely in Python. It holds the game state, the players, as well as the game logic, such as dealing cards or determining which hand is the strongest. I will dive a bit more into detail on how the bots’ algorithms are constructed, since there are many different implementations of the game logic of poker on the Internet.
A big part of the singleplayer experience is the existence of a computer algorithm (“bots”) that mimicks the habits and playstyles of real poker players. The computers in this project were developed according to the playstyles defined in the paper Dealing with Imperfect Information in Poker.
Playstyle variability
Playing against bots that use the same predictable strategy gets boring. The paper suggests adding a tightness factor to each bot, from which strategies can evolve. For example, a bot with a loose tightness would have a higher chance of bluffing than one with a tight strategy.
1 | bluff_percentage = { |
Other strategies will be determined based on this tightness value.
In poker, from my understanding, there are two main betting strategies: pre-flop and post-flop.
Pre-flop
Income rates are used for pre-flop betting strategy. Since the income rate of a given starting hand is always known, the calculated values for the income rates are stored in an IR (income rate) table. Suited hands are calculated with the order row->column while unsuited hands’ IR are calculated column->row.
1 | # The IR table used for our bots |
Pre-flop strategies are simple to implement since they do not rely on external information. Only the 2 cards in the starting hand influence a pre-flop strategy.
Post-flop
Post-flop is where it gets interesting. Three cards are revealed on the table, and the bots must decide what to do.
The four main actions on a turn are folding, checking, calling and betting. Bots can do either of these actions in different flavors. Here are some of the coded actions.
Actions
make0: Fold if it costs more than zero to play.call1: Fold if it costs more than 1 bet to continue playing AND the bot hasn’t put money into the pot this round yet, otherwise it will check/call.make1: If no bets have been made this round, then bet. Fold if two or more bets are required to continue. Otherwise check/call. This strategy should not be called if the bot is the big blind (it should be impossible).call2: Always check/call, no matter the bet is on the table, even if it forces an all-in.make2: Bet/raise if less than two bets/raises have been made this round, otherwise call.make4: Bet/raise until betting is capped, or another player goes all-in.
How do the bots know what action to do? We use effective hand strength , pre-flop strategy values, PPOT (potential of winning) and PNOT (potential of losing) to guide their decisions.
Each of these actions have a threshold in regards to the bot’s effective hand strength. If the bot’s EHS surpasses the strategy’s threshold, then that strategy is played. The thresholds vary per bot according to their tightness value.
1 | # The values for the thresholds of effective hand strength |
The strategy values are also different pre-flop. Here they are:
1 | # Expert-defined values to calculate strategy thresholds. There are technically different thresholds, but we'll use the ones for 3-4 players for the sake of simplicity. |
Finalized Effective Hand Strength (FEHS)
The finalized effective hand strength is calculated based on the current hand strength (a hard value), the effective hand strength (EHS), the PPOT (potential of winning) and the PNOT (potential of losing). There are two versions of the FEHS: a “happy” and “sad” version, depending on the EHS and the usage of PPOT or PNOT.
There is a way to calculate the hand strength of a given hand based on what is shown in the river. To start, we take a deck of 52 cards, and remove from it the cards that are already shown (river + the bot’s hand). Then, the bot will bruteforce calculate every other possible hand that the opponent can have, check the number of times it wins, ties or loses in these imaginary scenarios. From this, it will get it’s hand strength value: the higher it is, the stronger its hand is since it has won many more games in those imaginary scenarios.
1 | def hand_strength(self): |
Evaluating if a hand is winning or not in each of these scenarios is a beast on its own, but it is an issue that I will not discuss here. You can check our function implementation in our source code. The same goes for retrieving the PPOT and PNOT values: you can find the function here.
Thus, on every turn, the bot can calculate its finalized effective hand strength, without information of other players’ hands.
Finally, to add a “surprise” factor, bots can also bluff.
Bluffing
We have two types of bluffing. One is totally based on randomness and not logic. The other, which we will call semi-bluffing, is based on a combination of the implied pot odds and the bot’s PPOT (potential of winning).
For pure bluffing, the bot gaslights itself into thinking that it has a very high IR (income rate) and FEHS (finalized effective hand strength). Then, according to a pseudorandom value, it will check if it surpasses its bluffing threshold, which is set differently based on each bot’s tightness value.
For a more logical type of bluffing, semi-bluffing, the bot first checks if there are already bets on the table, in which case it will not proceed with the semi-bluff strategy. Then, it will calculate the implied pot odds as well as its PPOT, which will decide whether it will semi-bluff or not.
1 | # Yes, that is the name of our function... could be better. |
On every turn, the bot will check if it should bluff or not. We have tweaked the threshold values so that bluffing behaviour is more consistent with humans who play very conservatively, or very loosely.
Comments
That sums it up. I was very excited to build this with my friends; we got it done very early, and our prof kept our project as an example for future classes. Nice!
The codebase is messy and could definitely use some refactoring and abstractions. However, for a CEGEP project, I am quite happy with it.
Poker Playground
