LinkedIn github Codecademy Facebook Twitter

← back to full list


To evaluate the exact winning percentage between two Texas Hold'em starting hands, it is necessary to iterate through all 1,712,304 permutations of board cards. My version, working on a 2.67 Ghz laptop, evaluates 23 million 7-card hands per second, which is in line with the fastest versions described on the internet.

The entire project is available as a Github repository.

To get this speed, I use lookup tables and bitwise operations wherever possible. Most of all, I avoid loops and data transfer within the innermost loop. The diagram below illustrates how bitwise operators detect a straight, using a bitfield to represent the card ranks.

Is this a straight?

Your browser does not support the HTML5 canvas tag.
& (r << 1)AKQJT9876543
& (r << 2)AKQJT987654
& (r << 3)AKQJT98765
& (r << 4)AKQJT9876
9 - high straight


For selecting a range of starting hands, poker programs typically use a grid like the one below. As a first foray into Windows GUI programming, I enjoyed using resource editors, message handlers, etc. To build this window, though, I went a step further and used a custom-drawn list box, to get centered text (list boxes usually left-align text) and the 3-color scheme.

I also have an online version using jQuery.