def test_expected(self): two_pair_hand = Hand( [ Two(Suit.Clubs), Two(Suit.Diamonds), Three(Suit.Clubs), Three(Suit.Diamonds), Five(Suit.Clubs) ] ) self.assertTrue(TwoPairVerifier.verify_hand_ranking(two_pair_hand)) full_house_hand = Hand( [ Two(Suit.Clubs), Two(Suit.Diamonds), Three(Suit.Clubs), Three(Suit.Diamonds), Three(Suit.Clubs) ] ) self.assertFalse(TwoPairVerifier.verify_hand_ranking(full_house_hand)) three_of_a_kind_hand = Hand( [ Ace(Suit.Clubs), Two(Suit.Diamonds), Three(Suit.Clubs), Three(Suit.Diamonds), Three(Suit.Clubs) ] ) self.assertFalse(TwoPairVerifier.verify_hand_ranking(three_of_a_kind_hand)) one_pair_hand = Hand( [ Two(Suit.Clubs), Two(Suit.Diamonds), Three(Suit.Clubs), Four(Suit.Diamonds), Five(Suit.Clubs) ] ) self.assertFalse(TwoPairVerifier.verify_hand_ranking(one_pair_hand))
def calculate_hand_ranking(hand): if StraightFlushVerifier.verify_hand_ranking(hand): return StraightFlushCalculator.calculate_hand_ranking(hand) else: if FourOfAKindVerifier.verify_hand_ranking(hand): return FourOfAKindCalculator.calculate_hand_ranking(hand) else: if FullHouseVerifier.verify_hand_ranking(hand): return FullHouseCalculator.calculate_hand_ranking(hand) else: if FlushVerifier.verify_hand_ranking(hand): return FlushCalculator.calculate_hand_ranking(hand) else: if StraightVerifier.verify_hand_ranking(hand): return StraightCalculator.calculate_hand_ranking(hand) else: if ThreeOfAKindVerifier.verify_hand_ranking(hand): return ThreeOfAKindCalculator.calculate_hand_ranking(hand) else: if TwoPairVerifier.verify_hand_ranking(hand): return TwoPairCalculator.calculate_hand_ranking(hand) else: if OnePairVerifier.verify_hand_ranking(hand): return OnePairCalculator.calculate_hand_ranking(hand) else: if HighCardVerifier.verify_hand_ranking(hand): return HighCardCalculator.calculate_hand_ranking(hand) else: raise RuntimeError("unknown hand ranking")
def calculate_hand_ranking(hand): if TwoPairVerifier.verify_hand_ranking(hand): hand_value_counter = Counter([card.value for card in hand.cards]) hand_most_common_values = hand_value_counter.most_common() hand_highest_pair_value = max(hand_most_common_values[0][0], hand_most_common_values[1][0]) hand_lowest_pair_value = min(hand_most_common_values[0][0], hand_most_common_values[1][0]) hand_kicker_value = hand_most_common_values[2][0] return TwoPair( hand_highest_pair_value, hand_lowest_pair_value, hand_kicker_value ) else: raise RuntimeError("hand is not two pair")