Example #1
0
def test_giveHand_cardAmmount():
    p1 = Player("test1")
    p2 = Player("test2")
    p3 = Player("test3")
    table = Table(TablePlayers([p1, p2, p3]))

    assert len(table.cards) == 11
    table.giveHand()
    assert len(table.cards) == 5

    for p in table.players.List:
        assert len(p.hand) == 2
Example #2
0
def test_nextStage_stageInc():
    p1 = Player("test1")
    p2 = Player("test2")
    p3 = Player("test3")
    table = Table(TablePlayers([p1, p2, p3]))

    assert table.stage == GameStage.preFlop
    table.nextStage()
    assert table.stage == GameStage.Flop
    table.nextStage()
    assert table.stage == GameStage.Turn
    table.nextStage()
    assert table.stage == GameStage.River
    table.nextStage()
    assert table.stage == GameStage.Showdown
Example #3
0
def test_combined_1():
    p1 = Player("test1", STARTING_MONEY)
    p2 = Player("test2", STARTING_MONEY)
    p3 = Player("test3", STARTING_MONEY)
    p4 = Player("test4", STARTING_MONEY)

    table = Table(TablePlayers([p1, p2, p3, p4]), SMALL_BLIND)

    assert table.stage == GameStage.preFlop

    assert table.pots[0].ammount == 3 * SMALL_BLIND
    assert table.pots[0].members == [p2]
    assert table.pots[0].required == 2 * SMALL_BLIND

    assert all_in(table, p3) == ActionEffect.OK
    table.nextTurnPlayer()
    assert p3.status == Status.all_in
    assert table.turnPlayer == p4
    assert len(table.pots) == 1
    assert table.pots[0].required == STARTING_MONEY
    assert table.pots[0].ammount == STARTING_MONEY + 3 * SMALL_BLIND

    assert fold(table, p4) == ActionEffect.OK
    table.nextTurnPlayer()
    assert p4.status == Status.fold
    assert p4.table_money == 0
    assert p4.money == STARTING_MONEY
    assert table.turnPlayer == p1
    assert len(table.pots) == 1
    assert table.pots[0].required == STARTING_MONEY
    assert table.pots[0].ammount == STARTING_MONEY + 3 * SMALL_BLIND

    assert all_in(table, p1) == ActionEffect.OK
    table.nextTurnPlayer()
    assert p1.status == Status.all_in
    assert table.turnPlayer == p2
    assert len(table.pots) == 1
    assert table.pots[0].required == STARTING_MONEY
    assert table.pots[0].ammount == 2 * STARTING_MONEY + 2 * SMALL_BLIND

    assert fold(table, p2) == ActionEffect.OK
    table.nextTurnPlayer()
    assert p2.status == Status.fold
    assert len(table.pots) == 1
    assert table.pots[0].required == STARTING_MONEY
    assert table.pots[0].ammount == 2 * STARTING_MONEY + 2 * SMALL_BLIND

    assert table.stage == GameStage.Showdown
Example #4
0
def test_getWinner_byHeight():
    p1 = Player("test1")
    p1_hand = [Card(SUITES[1], '4'), Card(SUITES[3], '4')]
    p2 = Player("test2")
    p2_hand = [Card(SUITES[3], '8'), Card(SUITES[0], '10')]
    p3 = Player("test3")
    p3_hand = [Card(SUITES[2], '7'), Card(SUITES[0], 'A')]
    p_hands = [p1_hand, p2_hand, p3_hand]
    table = Table(TablePlayers([p1, p2, p3]))
    table_cards = [Card(SUITES[1], '3'), Card(SUITES[0], '3'), Card(SUITES[1], 'K'), Card(SUITES[0], '8'), Card(SUITES[0], '9')]

    for i in range(3):
        table.players.List[i].hand = p_hands[i]
    table.cards = table_cards

    hand_dict = {}
    for x in table.players.List:
        hand_dict[x] = Hand.evaluateHand(x.hand + table.cards)

    result = table.getWinners(hand_dict)
    assert len(result) == 1
    assert result[0].user == p2.user
Example #5
0
    def get(self, tableID, startingMoney, smallBlind):
        if tableID not in not_started_games:
            return '', 404

        table = not_started_games[tableID]
        if len(table) < 2:
            return 'Not enought players', 400
        if smallBlind <= 0:
            return 'Small blind amount has to be intiger greater than 0', 400
        if startingMoney <= 2 * smallBlind:
            return 'Statring money ammount has to be greater than twice the small blind ammount', 400

        players = [Player(user, startingMoney) for user in table]
        started_games[tableID] = Table(TablePlayers(players), smallBlind)
        timeout_dict[tableID] = {}
        for player in players:
            timeout_dict[tableID][player.user.id] = True

        del not_started_games[tableID]
        return '', 200
Example #6
0
def test_call():
    p1 = Player("test1")
    p2 = Player("test2")
    p3 = Player("test3")
    p4 = Player("test4")

    p3.table_money = 150

    table = Table(TablePlayers([p1, p2, p3, p4]))

    pot1 = Pot()
    pot1.members = [p1, p2, p3, p4]
    pot1.ammount = 400
    pot1.required = 100

    pot2 = Pot()
    pot2.members = [p2, p4]
    pot2.ammount = 250
    pot2.required = 200

    pot3 = Pot()
    pot3.members = [p2]
    pot3.ammount = 50
    pot3.required = 250

    table.pots = [pot1, pot2, pot3]

    assert call(table, p3) == ActionEffect.OK

    assert len(table.pots) == 3

    assert table.pots[0].ammount == 400
    assert table.pots[0].members == [p1, p2, p3, p4]
    assert table.pots[0].required == 100

    assert table.pots[1].ammount == 300
    assert table.pots[1].members == [p2, p4, p3]
    assert table.pots[1].required == 200

    assert table.pots[2].ammount == 100
    assert table.pots[2].members == [p2, p3]
    assert table.pots[2].required == 250

    assert table.players[2].table_money == 250
Example #7
0
def test_bet_raise():
    p1 = Player("test1")
    p2 = Player("test2")
    p3 = Player("test3")
    p4 = Player("test4")

    p1.status = Status.all_in
    p4.status = Status.all_in

    p1.table_money = 100
    p2.table_money = 250
    p3.table_money = 150
    p4.table_money = 200

    table = Table(TablePlayers([p1, p2, p3, p4]))

    pot1 = Pot()
    pot1.members = [p1, p2, p3, p4]
    pot1.ammount = 400
    pot1.required = 100

    pot2 = Pot()
    pot2.members = [p2, p4]
    pot2.ammount = 250
    pot2.required = 200

    pot3 = Pot()
    pot3.members = [p2]
    pot3.ammount = 50
    pot3.required = 250

    table.pots = [pot1, pot2, pot3]
    assert bet_raise(table, p3, 100) == ActionEffect.OK

    assert len(table.pots) == 3

    assert p3.table_money == 250

    assert table.pots[0].ammount == 400
    assert table.pots[0].members == [p1, p2, p3, p4]
    assert table.pots[0].required == 100

    assert table.pots[1].ammount == 300
    assert table.pots[1].members == [p2, p4, p3]
    assert table.pots[1].required == 200

    assert table.pots[2].ammount == 200
    assert table.pots[2].members == [p3]
    assert table.pots[2].required == 350
Example #8
0
def test_all_in_create_new_pot_at_end():
    p1 = Player("test1")
    p2 = Player("test2")
    p3 = Player("test3")
    p4 = Player("test4")

    table = Table(TablePlayers([p1, p2, p3, p4]))
    p1.status = Status.all_in
    p3.status = Status.all_in
    p4.status = Status.all_in

    p1.table_money = 100
    p2.table_money = 150
    p3.table_money = 200
    p4.table_money = 300

    p2.money = 250

    while (table.turnPlayer != p2):
        table.nextPlayer()

    pot1 = Pot()
    pot1.members = [p1, p2, p3, p4]
    pot1.ammount = 400
    pot1.required = 100

    pot2 = Pot()
    pot2.members = [p3, p4]
    pot2.ammount = 250
    pot2.required = 200

    pot3 = Pot()
    pot3.members = [p4]
    pot3.ammount = 100
    pot3.required = 300

    table.pots = [pot1, pot2, pot3]

    assert all_in(table, p2) == ActionEffect.OK

    assert len(table.pots) == 4
    assert p2.status == Status.all_in
    assert p2.table_money == 400
    assert p2.money == 0

    assert table.pots[0].ammount == 400
    assert table.pots[0].members == [p1, p2, p3, p4]
    assert table.pots[0].required == 100

    assert table.pots[1].ammount == 300
    assert table.pots[1].members == [p3, p4, p2]
    assert table.pots[1].required == 200

    assert table.pots[2].ammount == 200
    assert table.pots[2].members == [p4, p2]
    assert table.pots[2].required == 300

    assert table.pots[3].ammount == 100
    assert table.pots[3].members == [p2]
    assert table.pots[3].required == 400

    assert table.players.lastIndex == 1
Example #9
0
def all_in(table: Table, player: Player) -> ActionEffect:
    if table.turnPlayer is None or table.turnPlayer != player:
        return ActionEffect.Wrong_player

    count_for_player = player.table_money
    prev_pot_req = 0
    i = 0
    for pot in table.pots:
        if player not in pot.members:
            koszt = pot.required - prev_pot_req
            mozliwosc = player.table_money - prev_pot_req + player.money
            if koszt < mozliwosc:
                if any(player.status == Status.all_in
                       for player in pot.members):
                    give = None
                    if player.table_money - prev_pot_req > 0:
                        give = koszt - (player.table_money - prev_pot_req)
                    else:
                        give = koszt
                    pot.ammount += give
                    player.table_money += give
                    player.money -= give
                    pot.members.append(player)
                else:
                    pot.ammount += player.money
                    player.table_money += player.money
                    player.money = 0
                    pot.members = [player]
                    pot.required = player.table_money
                    table.players.setLastPlayer()
                    break

            elif koszt == mozliwosc:
                pot.ammount += player.money
                player.table_money += player.money
                player.money = 0
                pot.members.append(player)
                break
            else:
                new_pot = Pot()
                new_pot.members = pot.members.copy()
                new_pot.members.append(player)
                new_pot.required = player.table_money + player.money
                new_pot.ammount = (new_pot.required - prev_pot_req) * len(
                    new_pot.members)
                if player.table_money - prev_pot_req > 0:
                    pot.ammount -= (new_pot.required - prev_pot_req) * (
                        len(new_pot.members) - 1) + (player.table_money -
                                                     prev_pot_req)
                else:
                    pot.ammount -= (new_pot.required -
                                    prev_pot_req) * (len(new_pot.members) - 1)
                player.table_money += player.money
                player.money = 0
                table.pots.insert(i, new_pot)
                break

        prev_pot_req = pot.required
        i += 1
    if player.money > 0:
        pot = Pot()
        pot.members = [player]
        pot.ammount = player.money
        player.table_money += player.money
        pot.required = player.table_money
        player.money = 0
        table.pots.append(pot)
        table.players.setLastPlayer()

    table.turnPlayer.status = Status.all_in
    return ActionEffect.OK