Checking for a full house

flupke flupke at nonexistingdomain.com
Thu May 26 03:08:49 EDT 2005


Paul Rubin wrote:
> "Raymond Hettinger" <python at rcn.com> writes:
> 
>>Your use case for gathering roll statistics probably needs a more
>>general solution:
>>
>>hands = {
>>    (1,1,1,1,1): 'nothing',
>>    (1,1,1,2): 'one pair',
>>    (1,2,2): 'two pair',
>>    (1,1,3): 'three of a kind',
>>    (2,3): 'full house',
>>    (1,4): 'four of a kind',
>>    (5): 'flush (five of a kind)'
>>}
>>
>>def eval_hand(hand):
>>    counts = tuple(sorted(hand.count(card) for card in set(hand)))
>>    return hands.get(counts, 'misdeal')
> 
> 
> 1. "Flush" means 5 cards of the same suit (i.e. all hearts), not 5 of
>    a kind.
> 
> 2. That code doesn't detect flushes or straights.

It would be interesting to see how complicated it would get to write 
code to detect the correct hands in poker with wildcards included.
I tried that a year or 2 ago when i wanted to write a pokergame in java 
but i failed miserably in doing so.

I have a gut feeling that with python this is easier. I might give it 
another go. Is there any of such code available somewhere?
The reason i wanted to do so is that there isn't a game that allows a 
player to specify it's own games. I wanted to make a simple network 
enabled game with simple graphics and scriptable poker games via a wizard.
But as i said, i first wanted to construct my "card" code to deal, 
evaluate a hand and compare 2 or more hands, and to find the highest 
hand in a number of hands. And all this with wildcards, cards in the 
hands varying from 5 to 7 and high low. I toyed with on several 
occasions but never could seem to find an easy way to do it.

Benedict



More information about the Python-list mailing list