I wrote a poker hand evaluator
Hey everyone,
I’ve been tinkering with poker hand evaluators and wanted to share my finished Python implementation. It’s not meant to compete with the fastest LUT-based evaluators, but I think it’s neat because:
It avoids large lookup tables (only 22 bytes total, just for straights, and you could even avoid those, I believe).
Evaluates the best 5-card hand from arbitrary 5–9 card inputs in constant time (no subset enumeration). In theory any number of cards should be possible, but I was too lazy to fix it snapping to the first flush it finds and with 10+ cards more than 1 flush is possible.
Uses pure bitmask logic with Numba JIT, so it’s both compact and surprisingly fast (13M+ hands/sec on my machine, 60M+ hands/sec if you allow for parallelization).
Supports full lexicographic scoring for tie-breaking, wheel straights, flush detection, etc.
This was mostly a personal project to see if I could:
Avoid LUTs entirely,
Skip the C(n,5) subset enumeration,
Still be reasonably fast and correct.
And I believe it is somewhat of a success.
You can find the code here: https://github.com/felixubl/bb-poker-eva...