def test_expected(self): flush_hand = Hand( [ Two(Suit.Clubs), Three(Suit.Clubs), Four(Suit.Clubs), Jack(Suit.Clubs), King(Suit.Clubs) ] ) is_flush_result = FlushVerifier.verify_hand_ranking(flush_hand) self.assertTrue(is_flush_result) non_flush_hand = Hand( [ Two(Suit.Hearts), Three(Suit.Clubs), Four(Suit.Clubs), Jack(Suit.Clubs), King(Suit.Clubs) ] ) is_not_flush_result = FlushVerifier.verify_hand_ranking(non_flush_hand) self.assertFalse(is_not_flush_result)
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 FlushVerifier.verify_hand_ranking(hand) and not StraightFlushVerifier.verify_hand_ranking(hand): suit = hand.cards[0].suit sorted_card_values = sorted([card.value for card in hand.cards], reverse=True) return Flush( suit, first_kicker=sorted_card_values[0], second_kicker=sorted_card_values[1], third_kicker=sorted_card_values[2], fourth_kicker=sorted_card_values[3], fifth_kicker=sorted_card_values[4] ) else: raise RuntimeError("hand is not flush")