def _rank_pair(hands: List[List[Card]]): """ Private tiebreaker method to determine the best pair hand in the list of hands :param hands: List of list of cards. each internal list of cards represents a pair hand :return: Dictionary in the following format of KEY = Rank number (1,2,3,4...) VALUE = List of hands for that rank If there are tied hands, then multiple hands will appear as the value for that rank. """ hands_pair = [(hand, hand_highest_value_tuple(hand, 2)) for hand in hands] pair_values = list(set([tup[1] for tup in hands_pair])) pair_values.sort(reverse=True) ranked_hands = dict() for pair_value in pair_values: pair_value_hands = filter( lambda hand_tuple: hand_tuple[1] == pair_value, hands_pair) pair_value_hands = order_hands_highest_card( [tup[0] for tup in pair_value_hands]) current_rank = 1 if not ranked_hands else max(ranked_hands.keys()) + 1 ranked_hands[current_rank] = [pair_value_hands[0]] for hand in pair_value_hands[1:]: if hands_have_same_card_values(hand, ranked_hands[current_rank][0]): ranked_hands[current_rank].append(hand) else: current_rank += 1 ranked_hands[current_rank] = [hand] return ranked_hands
def test_when_hands_have_same_card_values_then_correct_response_returned( hand_a, hand_b, expected): hand_a = get_hand(hand_a) hand_b = get_hand(hand_b) actual = hands_have_same_card_values(hand_a, hand_b) assert actual == expected
def _rank_high_card(hands: List[List[Card]]): """ Private tiebreaker method to determine the best high card hand in the list of hands :param hands: List of list of cards. each internal list of cards represents a high card hand :return: Dictionary in the following format of KEY = Rank number (1,2,3,4...) VALUE = List of hands for that rank If there are tied hands, then multiple hands will appear as the value for that rank. """ ordered_hands = order_hands_highest_card(hands) ranked_hands = {1: [ordered_hands[0]]} for hand in ordered_hands[1:]: current_rank = max(ranked_hands.keys()) if hands_have_same_card_values(hand, ranked_hands[current_rank][0]): ranked_hands[current_rank].append(hand) else: current_rank += 1 ranked_hands[current_rank] = [hand] return ranked_hands