I make a Poker Hand Generator
- By SHLIM --
- Saturday, 12 Nov, 2022
In 2010 i took up playing poker for a hobby, and have pretty much never stopped. Co-incidentally around 1 year later i became a developer, and even though both skills have played a major part in my life, i never thought about mixing the 2 together in order to "better my game". In fact it wasnt until the rise of Poker Solvers that i decided to give it a go.
For those that dont know what a Solver is, its basically a tool that shows a player the best action to make under any circumstance. It has been perfectly optimised to give you the best edge at the table, and although obviously its not fool proof it is something any serious pro player would of studied.
My initial goal was to create something similar to a solver but one which more helped a player to understand their possible outcomes & percentages as opposed to 'the best possible decision'. However, In order to do this id first have to create a poker hand generator which is (and was) a pretty mundane task of its own. Generating a series of cards to deal out is simple enough, but there are 2,598,960 possible poker hands a player can get which is then split up into 10 seperate ways of winning. Each card also has its own hand strength, and then there are also 4 different suits to take into consideration aswel.
Realising this would be the most difficult task of my programming career i dove right in and got to work! As always, my choice of programming language is PHP. Im constantly told there are more efficient languages out there, but for me PHP is the most convenient of all. I started off by turning hands into values from 1-12 which allowed me to build hand strength. From there i started computing small hands like pairs, and then comparing them with a 2nd player to determin which pair was better dependant on its hand strength. Once that was completed it allowed me to easily check further for 3 of a kinds, and 4 of a kind wins. Flushes werent too bad, but straights were a lot harder to figure out as theres a lot more than just hand strength that goes into them, but with a lot of bug testing i finally got there.
All in all it took a few weeks to finalise the script and it performed much better than id expected. It has been limited to save on server power, but its capable of producing 50,000 hands and determin the winner of each in just a few seconds. It definitely was the most difficult task id taken on, but still my most rewarding accomplishment so far.
You can use the hand generator by clicking here