I'm following this: Optimizing hand-evaluation algorithm for Poker-Monte-Carlo-Simulation
My setup is similar -- an unsigned long to represent the board and the player's holding. All cards are bit flags, starting at 1 and ending at 2^51.
For example, 2c is 1, 3c is 16, 4c is 256, and As is 2^51. So, the hand
1010 0000 1001 0000 0000 0100 0000 0001 0000 0000 0010 is
Qs Qd 7h 5c 2d (the board) + Ts Tc (the player's holding).
The link I referred to explains well how to find a straight flush / four of a kind, and it works. However, I seem to have hit a brick wall trying to identify three of a kind. I've tried:
hand & (hand >> 1) & (hand >> 2) & 0x1111111111111111 -- the naive case, following the example from the link;
hand & (hand >> 2) & 0x3333333333333333 -- this seems to catch all three of a kind, but it misclassifies pairs (e.g. the example above) as trips;
- and variations thereof.
How do I dismiss all nibbles with fewer than three set bits?