From ad80b41e06cddff6c276e0ab6249cfbdafae8bb5 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 23 Apr 2010 03:48:36 +0000 Subject: [PATCH] Corrected high card error for hands < 5 cards. Added discard to Player. git-svn-id: file:///srv/svn/euler@51 e5f4c3ec-3c0c-11df-b522-21efaa4426b5 --- p054/poker.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/p054/poker.py b/p054/poker.py index 73c2bd6..6b7d6af 100644 --- a/p054/poker.py +++ b/p054/poker.py @@ -176,6 +176,8 @@ class Hand: self.__rank = Hand.ONE_PAIR mvalues = [m[0] for m in multiples] self.__values = mvalues + [c.value for c in self.__cards if c.value not in mvalues] + if not self.__rank: + self.__rank = Hand.HIGH_CARD return self.__rank def values(self): @@ -349,6 +351,9 @@ class Player: # Rebuild and re-evaluate hand self.__hand = Hand.create_best_hand([str(c) for c in self.__community_cards + self.__cards]) + def discard(self, index): + self.__cards.pop(index) + self.__hand = Hand.create_best_hand([str(c) for c in self.__community_cards + self.__cards]) def hand(self): return self.__hand def __repr__(self): @@ -376,4 +381,4 @@ if __name__ == '__main__': players = sorted(players, reverse=True) print 'Community', community_cards for player in players: - print player \ No newline at end of file + print player