Speed
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.
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?







r | A | K | Q | J | T | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
& (r << 1) | A | K | Q | J | T | 9 | 8 | 7 | 6 | 5 | 4 | 3 | |
& (r << 2) | A | K | Q | J | T | 9 | 8 | 7 | 6 | 5 | 4 | ||
& (r << 3) | A | K | Q | J | T | 9 | 8 | 7 | 6 | 5 | |||
& (r << 4) | A | K | Q | J | T | 9 | 8 | 7 | 6 | ||||
= | A | K | Q | J | T | 9 | 8 | 7 | 6 |
GUI
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.
