Call, Raise or Fold - Python for Simulating Poker Games
Abhijit Gadgil (~gabhijit) |
In this talk, we start with a solution to the problem of ranking poker hands and then build up on it to simulate poker games. Eventually, we will look at simulating a large number of such games and see if there are any interesting strategies that can be developed, looking at the results of the simulations or it's just that it's random. We'll look at one such solution that uses Python standard library alone, with no external dependencies.
Poker is a family of card games that combines gambling, strategy, and skill. All poker variants involve betting as an intrinsic part of play, and determine the winner of each hand according to the combinations of players' cards, at least some of which remain hidden until the end of the hand. Poker games vary in the number of cards dealt, the number of shared or "community" cards, the number of cards that remain hidden, and the betting procedures.
Thus, poker is a very candidate for understanding how one can run a large number of random simulations.
Those interested in a game of Poker and Python - for the fun part of solving a problem in Python.
This talk should be a good introduction to using some features from standard library to Python programmers who are new to Python. There might be something for more experienced Python programmers as well.
People who are interested in understanding how to simulate certain real world scenarios, might also find the talk useful.
The talk will cover following main topics. Most of the talk will walk through the code.
A quick overview of poker hands and how they are ranked. This section should demonstrates the power of Python's built-ins like
sortedwhich makes solution to the problem of ranking Poker hands a very compact one, deriving inspiration from Peter Norvig's solution. (approx 10-15 mins).
Next we look at what one Poker Game looks like and model it. Here we model a Poker Table with
'n'players and different stages of a poker game. This demonstrates modules from Python's standard library
collections. (approx: 5-7 mins)
Finally we look at How can we answer questions by running simulations of such Poker games. List comprehensions etc. (approx: 5-7 mins)
- What percentage 'flop' winners end up being final game winners?
- Is Ace High during initial deal - really a good hand that can win?
- What about starting with a Pair?
- What about starting with same suit?
Although there are no prerequisites for this specific talk. Having an interest in game of Poker and some idea about the game would certainly help.
Following links should help one understand this -
Below are links for the code and slides for the presentation.
I run a software consultancy firm called hyphenOs Software Labs.
Have been programming in Python for more than 10 years now. Professionally, have been involved in using Python for developing Desktop applications, Web applications and way back a HPC cluster orchestration using Python (This was well before Openstack).
Mostly use Python for all my personal projects. I am always looking at solving problems using Python's standard library and built-ins alone, as I believe, this is something that is not appreciated enough. Partly because excellent ecosystem of Python packages for solving a large number of problems.
Did I mention - I hate trailing white spaces in a file? :-)