Example #1
0
def test_game_stops(monkeypatch):
    monkeypatch.setattr(game, "random", Random(0))

    game.delete_room("test")
    game.register("test", "a", "blah a")
    game.register("test", "b", "blah b")

    game.start("test", "a")

    # Pre-flop
    game.add_bet("test", "b", 100)
    game.add_bet("test", "a", 100)

    room_state = _room("test").get()[1]
    assert len(room_state.log) == 1
    assert room_state.game is None
Example #2
0
def test_play_hand(monkeypatch):
    monkeypatch.setattr(game, "random", Random(0))

    game.delete_room("test")
    game.register("test", "a", "blah a")
    game.register("test", "b", "blah b")
    game.register("test", "c", "other")

    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

    final_hands = dict(state._get_final_hands())
    assert len(final_hands) == 2
    assert final_hands["c"][1] == deck[12:22]
    assert final_hands["c"][2] == deck[4:8]
    assert final_hands["b"][1] == deck[12:22]
    assert final_hands["b"][2] == deck[8:12]

    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
Example #3
0
File: http.py Project: ievans/poker
def route_bet(request, room_name) -> Response:
    data = json.load(request.stream)
    game.add_bet(room_name, request.session_id, data["amount"])