Beispiel #1
0
def test_when_hand_test_and_bad_hand_type_then_raise_error():
    with raises(
            ValueError,
            match=
            "Hand type provided 'WINNING_HAND_TYPE' is not an acceptable value"
    ):
        hand_test("Texas Holdem", "WINNING_HAND_TYPE")
Beispiel #2
0
def test_when_hand_test_and_too_many_kwargs_passed_then_raise_error(
        game_type, hand_type, kwargs):
    with raises(
            ValueError,
            match=
            f"Kwargs object '{kwargs}' contains additional keys from what is expected"
    ):
        hand_test(game_type, hand_type, **kwargs)
Beispiel #3
0
def test_when_hand_test_and_incorrect_kwargs_passed_then_raise_error(
        game_type, hand_type, kwargs):
    with raises(
            ValueError,
            match=
            f"Kwargs object '{kwargs}' does not contain all keys required for "
            f"this method"):
        hand_test(game_type, hand_type, **kwargs)
Beispiel #4
0
    def find_best_hand(self, hole_cards: List[Card], board_cards: List[Card]):
        """
        Abstract method to implement to find a players best hand.

        :param hole_cards: List of card objects, representing the players hole cards
        :param board_cards: List of card objects, representing the board cards available to use.
        :return: dictionary of player hand information. including at least the following keys:
        {
            "best_hand": List of card objects representing the players best hand
            "hand_title": Str the english title of the best hand type the player has (Straight, Flush, Two Pair, etc)
            "hand_rank": Int ranking of the hand type, with 1 signifying the best type of hand (e.g. straight flush
                         would have a ranking of 1 in texas holdem)
        }
        child classes implementing this abstract method can choose to expand the dictionary where
        appropriate but must at minimum have the above keys
        """

        hand_size = (
            5
            if len(hole_cards) + len(board_cards) >= 5
            else len(hole_cards) + len(board_cards)
        )
        all_hands = get_all_combinations(hole_cards, board_cards, hand_size)
        for hand_ranking in self._hand_rankings:
            matched_hands = [
                hand
                for hand in all_hands
                if hand_test(
                    GAME_TYPE_TEXAS_HOLDEM, hand_ranking[HAND_TITLE], hand=hand
                )
            ]

            if matched_hands:
                best_hand = rank_hand_type(
                    GAME_TYPE_TEXAS_HOLDEM,
                    hand_ranking[HAND_TITLE],
                    hands=matched_hands,
                )[1][0]
                return {
                    BEST_HAND: best_hand,
                    HAND_TITLE: hand_ranking[HAND_TITLE],
                    HAND_RANK: hand_ranking[HAND_RANK],
                    HAND_DESCRIPTION: describe_hand(
                        GAME_TYPE_TEXAS_HOLDEM, hand_ranking[HAND_TITLE], hand=best_hand
                    ),
                }
Beispiel #5
0
    def _group_player_hands_by_rank(self, players_hands):
        """
        Helper method that will group player hands together by their hand ranks.

        :param players_hands: Dict in format of {PLAYER_NAME: [LIST_OF_CARDS]}
        :return: dictionary in format of {RANK: {PLAYER: [LIST_OF_CARDS]}}
        """

        player_hands_by_rank = dict()
        for player, hand in players_hands.items():
            for hand_type in self._hand_rankings:
                if hand_test(GAME_TYPE_TEXAS_HOLDEM, hand_type[HAND_TITLE], hand=hand):
                    if hand_type[HAND_RANK] not in player_hands_by_rank.keys():
                        player_hands_by_rank[hand_type[HAND_RANK]] = {player: hand}
                    else:
                        player_hands_by_rank[hand_type[HAND_RANK]][player] = hand
                    break
        return player_hands_by_rank
Beispiel #6
0
def test_when_hand_test_and_bad_game_type_then_raise_error():
    with raises(
            ValueError,
            match=
            "Game type provided 'BAD_GAME_TYPE' is not an acceptable value"):
        hand_test("BAD_GAME_TYPE", "Straight Flush")
Beispiel #7
0
def test_when_hand_test_and_texas_holdem_and_high_card_then_correct_response_returned(
        hand_name, expected):
    actual = hand_test("Texas Holdem", "High Card", hand=get_hand(hand_name))
    assert actual == expected
Beispiel #8
0
def test_when_hand_test_then_correct_response_returned(hand_name, expected):
    actual = hand_test("Texas Holdem", "Two Pair", hand=get_hand(hand_name))
    assert actual == expected
Beispiel #9
0
def test_when_hand_test_and_texas_holdem_and_straight_then_correct_response_returned(
        hand_name, expected):
    actual = hand_test("Texas Holdem", "Straight", hand=get_hand(hand_name))
    assert actual == expected
Beispiel #10
0
def test_when_hand_test_and_texas_holdem_and_full_house_then_correct_response_returned(
        hand_name, expected):
    actual = hand_test("Texas Holdem", "Full House", hand=get_hand(hand_name))
    assert actual == expected
Beispiel #11
0
def test_when_hand_test_then_correct_response_returned(game_type, hand_type,
                                                       hand_name, expected):
    actual = hand_test(game_type, hand_type, hand=get_hand(hand_name))
    assert actual == expected