[Erik Max Francis] > > > Searching for straights and flushes is much better done by masks.
Interesting. I've been thinking about playing with this stuff too, but hadn't considered masks. So each card has a representation: n bits for rank, then m bits for suit. 00000000000010 0001 = 2 clubs 01000000000000 1000 = K spades ... [flupke] > > As for straights, if i understand correctly, you make all possible > > straights of the cards in the hand and then see if one matches? Yeah, I originally thought that's what you meant, too. But if you take the scheme above, and sort the cards before you merge them into the hand-bits aggregate, then you can just have *one* mask for straights, and shift it down by a bit each time you check. So the best straight mask (A high) would be (ignoring suit bits): 10000000000000 01000000000000 00100000000000 00010000000000 00001000000000 Then this could be shifted right for a K-high straight: 01000000000000 00100000000000 00010000000000 00001000000000 00000100000000 I guess that means that an Ace has to have the following representation, since it can be both at the high and low end of a straight: 10000000000001 0100 = A hearts But this may mess with bit-counting shortcuts for other calculations... This is interesting to think about. Thanks for the pointer. I'm also going to look at pokersource, though I may put that off until I at least partially re-invent the wheel for learning purposes. -John -- http://mail.python.org/mailman/listinfo/python-list