poker card game revisited (code included)

flupke flupke at nonexistingdomain.com
Wed Jun 8 05:03:48 EDT 2005


Erik Max Francis wrote:
> flupke wrote:
> 
>> Which projects are you talking about? I only found a library in c to 
>> evaluat ranks but i didn't find the code to be very understandable.
> 
> 
> pokersource is the main was I was thinking about, yes.
> 
>> With histogram do you mean something like this:
>> Card hand: 2 clubs, 3 diamonds, 10 of diamonds, 4 of hearts,  3 of hearts
>>
>> Histogram 1: list [2,3,4,10]
>>                     2 --------------------- 14   
>> Histogram 2: list [1,2,1,0,0,0,0,0,1,0,0,0,0]
>> or
>> list [1,2,1,1]
>> so index 0 is count of rank at index 0 of Histogram 1
>> index 1 is count of rank at index 1 of Histogram 1
> 
> 
> Histograms usually involve putting things in bins and counting the 
> number by bin.  Here the bins are just the ranks of the cards, and so 
> you're counting the frequency of the ranks.  Once that's done, you want 
> to arrange the frequencies into a mapping of its own, which points to 
> the list of ranks that have that frequency.  That way you can easily 
> pick things off:  If there is a hit in the four bin, you have quads.  If 
> there's a hit in the three bin and either another in the three or one in 
> the two bin, you have a boat.  If there's a hit in the three bin but 
> _not_ another in three or two, then it's trips.  And so on.
> 
>> As for straights, if i understand correctly, you make all possible 
>> straights of the cards in the hand and then see if one matches?
> 
> 
> Not quite.  You break down the cards by what matters -- ranks and suits 
> -- and then make sets based on these.  Then, standing by, you have the 
> sets of valid straights (by rank), and then to test for straights, you 
> iterate through the straight sets and make intersections with the rank 
> set for the hand in question.  If the intersection is the same as the 
> straight set, then it's a straight.  (Do this by reverse order of the 
> relative values of the straights, and stop when you find the first one, 
> to get the highest straight.)  The most efficient way to do this is with 
> a bitmask, so that's how it's usually done.
> 

Thanks for the info. I succeeded in doing a straight flush check 
yesterday but not using the method described. My code works now but 
using bitmasks might actually be faster to use for hand detection and 
comparison. I'm not sure that it will be easier to read and understand 
the code though.
I'll play a bit with bitmasks and see what gives.

Thanks,
Benedict



More information about the Python-list mailing list