예제 #1
0
def test_two_pair():
    # The two-pair kicker is also embedded in a pair
    assert find_best_hand("ASAHKSKHQSQHJS") == Hand(Value.TWO_PAIRS,
                                                    "ASAHKSKHQS")

    # There are three pairs, but the kicker is unpaired
    assert find_best_hand("ASAHKSKHJHJSQS") == Hand(Value.TWO_PAIRS,
                                                    "ASAHKSKHQS")
예제 #2
0
def test_flush():
    assert find_best_hand("ADQHJHXH9H7H6H") == Hand(Value.FLUSH, "QHJHXH9H7H")

    # Trips within the flush
    assert find_best_hand("QH5CXH9H5H5DAH") == Hand(Value.FLUSH, "AHQHXH9H5H")

    # Straight and flush, but not straight-flush
    assert find_best_hand("8H9HXDJHQHKHAH") == Hand(Value.FLUSH, "AHKHQHJH9H")
예제 #3
0
def test_full_house():
    assert find_best_hand("AHKHQHQDQC4H4C") == Hand(Value.FULL_HOUSE,
                                                    "QHQDQC4H4C")
    assert find_best_hand("AHASQHQDQC4H4C") == Hand(Value.FULL_HOUSE,
                                                    "QHQDQCAHAS")

    # Two sets on the board
    assert find_best_hand("QDQCQH4CAHASAD") == Hand(Value.FULL_HOUSE,
                                                    "AHASADQDQC")
예제 #4
0
def test_four():
    assert find_best_hand("AHQHQDQSQC3H2C") == Hand(Value.QUAD, "QHQDQSQCAH")

    # Kicker is embedded in a pair
    assert find_best_hand("QHQDQSQC3H3D8C") == Hand(Value.QUAD, "QHQDQSQC8C")

    # Kicker is embedded in a pair
    assert find_best_hand("QHQDQSQC3H3D2C") == Hand(Value.QUAD, "QHQDQSQC3H")

    # Kicker is embedded in a set
    assert find_best_hand("QHQDQSQC3H3D3C") == Hand(Value.QUAD, "QHQDQSQC3H")
예제 #5
0
def test_straight_flush():
    assert find_best_hand("AHKHQHJHXH9H8H") == Hand(Value.STRAIGHT_FLUSH,
                                                    "AHKHQHJHXH")
    assert find_best_hand("ASKHQHJHXH9H8H") == Hand(Value.STRAIGHT_FLUSH,
                                                    "KHQHJHXH9H")
    assert find_best_hand("AHQHJHXH9H8H7H") == Hand(Value.STRAIGHT_FLUSH,
                                                    "QHJHXH9H8H")
    assert find_best_hand("AHQHJHXH9H8H7H") == Hand(Value.STRAIGHT_FLUSH,
                                                    "QHJHXH9H8H")

    # Ace plays low
    assert find_best_hand("KHQH5H4H3H2HAH") == Hand(Value.STRAIGHT_FLUSH,
                                                    "5H4H3H2HAH")
예제 #6
0
def test_straight():
    assert find_best_hand("AHJD6S5S4H3C2D") == Hand(Value.STRAIGHT,
                                                    "6S5S4H3C2D")

    # Embedded pair
    assert find_best_hand("AHKHQHJDXD5C5S") == Hand(Value.STRAIGHT,
                                                    "AHKHQHJDXD")

    # Ace plays low
    assert find_best_hand("KHQH5H4S3H2DAC") == Hand(Value.STRAIGHT,
                                                    "5H4S3H2DAC")

    # Ace plays low, with included values
    assert find_best_hand("5H5S4S4H3H2DAC") == Hand(Value.STRAIGHT,
                                                    "5H4S3H2DAC")
예제 #7
0
def test_comparison():
    board = "ASJSXH8H5H"

    hands = [
        board + "KDQC",
        board + "AHAD",
        board + "KCQD",
        board + "KS6H",
        board + "QS9C",
    ]

    expecteds = [
        Hand(Value.STRAIGHT, "ASKDQCJSXH"),
        Hand(Value.SET, "ASAHADJSXH"),
        Hand(Value.STRAIGHT, "ASKCQDJSXH"),
        Hand(Value.CARD, "ASKSJSXH8H"),
        Hand(Value.STRAIGHT, "QSJSXH9C8H"),
    ]

    for hand, expected in zip(hands, expecteds):
        assert find_best_hand(hand) == expected

    player_hands = zip(count(), expecteds)

    assert get_winners(player_hands) == [
        (0, Hand(Value.STRAIGHT, "ASKDQCJSXH")),
        (2, Hand(Value.STRAIGHT, "ASKCQDJSXH")),
    ]
예제 #8
0
def test_high_card():
    # Near straight
    assert find_best_hand("JDQDXS5C4D9H2S") == Hand(Value.CARD, "QDJDXS9H5C")
예제 #9
0
def test_pair():
    assert find_best_hand("ASADKS9H5H4H3H") == Hand(Value.PAIR, "ASADKS9H5H")
예제 #10
0
def _split_hand(value, cards):
    return Hand(value, [Card(cards[i:i + 2]) for i in range(0, len(cards), 2)])
예제 #11
0
def test_set():
    assert find_best_hand("QDJCXH4CAHASAD") == Hand(Value.SET, "AHASADQDJC")
예제 #12
0
def test_play_hand(monkeypatch):
    monkeypatch.setattr(game, "random", Random(0))

    game.delete_room("test")
    game.register("test", "a", "blah a")
    game.increment_balance("test", "a", name="blah a", amount=100)
    game.register("test", "b", "blah b")
    game.increment_balance("test", "a", name="blah b", amount=100)
    game.register("test", "c", "other")
    game.increment_balance("test", "a", name="other", amount=100)

    view_a = game.get_player_view("test", "a")
    assert view_a.game is None

    game.start("test", "a")
    assert len(_room("test").get()[1].log) == 0
    deck = _get_game("test").deck

    view_a = game.get_player_view("test", "a")
    assert view_a.game.community_cards == ""
    assert view_a.game.hole_cards == deck[0:4]

    view_c = game.get_player_view("test", "c")
    assert view_c.game.hole_cards == deck[4:8]

    view_b = game.get_player_view("test", "b")
    assert view_b.game.hole_cards == deck[8:12]

    # Pre-flop
    game.add_bet("test", "b", 5)
    assert _get_game("test").stage == 0
    game.add_bet("test", "a", 5)
    assert _get_game("test").stage == 0
    game.add_bet("test", "c", 5)

    # Flop
    state = _get_game("test")
    assert state.stage == 1
    assert state.pot == 15

    view_a = game.get_player_view("test", "a")
    assert view_a.game.community_cards == deck[12:18]
    assert view_a.game.hole_cards == deck[0:4]

    game.add_bet("test", "a", 1)
    assert _get_game("test").stage == 1
    game.add_bet("test", "c", 2)
    assert _get_game("test").stage == 1
    game.add_bet("test", "b", 4)
    assert _get_game("test").stage == 1
    game.fold("test", "a")
    assert _get_game("test").stage == 1
    game.add_bet("test", "c", 4)

    # Turn
    view_a = game.get_player_view("test", "a")
    assert view_a.game.community_cards == deck[12:20]
    assert view_a.game.hole_cards == deck[0:4]

    state = _get_game("test")
    assert state.stage == 2
    assert state.pot == 24

    game.add_bet("test", "c", 0)
    game.add_bet("test", "b", 0)

    # River
    state = _get_game("test")
    assert state.stage == 3
    assert state.pot == 24
    view_a = game.get_player_view("test", "a")
    assert view_a.game.community_cards == "6DKD9D9SAH"

    final_hands = dict(state._get_final_hands())
    assert len(final_hands) == 2
    assert final_hands["c"][1] == deck[4:8]
    assert final_hands["b"][1] == deck[8:12]
    assert final_hands["c"][2] == Hand(Value.TWO_PAIRS, "KDKH9D9SAH")
    assert final_hands["b"][2] == Hand(Value.PAIR, "9D9SAHKD6D")

    game.add_bet("test", "c", 1)
    game.add_bet("test", "b", 1)

    # Payout

    state = _get_game("test")
    assert len(_room("test").get()[1].log) == 1
    assert state.stage == 0
    assert state.pot == 3
    assert state.players[0].session_id == "c"
    assert state.players[0].bet == 1
    assert state.players[1].session_id == "b"
    assert state.players[1].bet == 2
    assert state.players[2].session_id == "a"
    assert state.players[2].bet == 0

    players = game.get_player_view("test", "a").players
    assert len(players) == 3
    assert players["other"]["balance"] == 115
    assert players["blah b"]["balance"] == 88
    assert players["blah a"]["balance"] == 94