def test_player_with_table(): player = Player(10) table = Table() player.sit(table, 0) assert player.table == table assert player.position == 0 assert repr(player) == '<Player Pos: 0 Hole Cards: Chips: 10>'
def test_player_with_table(): player = Player(10) table = Table() player.sit(table, 0) assert player.table == table assert player.position == 0 assert repr(player) == '<Player Pos: 0 Hole Cards: Chips: 10>'
def test_pot_starting_chips(): players = [] for i in xrange(1): player = Player(1000) player.position = i players.append(player) pot = Pot(range(1), 10) assert pot.round_bets == {0: None} assert pot.chips == 10
def test_pot_initial_round_bets(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3), initial_round_bets={0: 5, 2: 5}) assert pot.chips == 0 assert pot.round_bets == {0: 5, 2: 5}
def test_pot_initial_round_bets(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3), initial_round_bets={0: 5, 2: 5}) assert pot.chips == 0 assert pot.round_bets == {0: 5, 2: 5}
def test_pot_starting_chips(): players = [] for i in xrange(1): player = Player(1000) player.position = i players.append(player) pot = Pot(range(1), 10) assert pot.round_bets == {0: None} assert pot.chips == 10
def test_foldwithnopostfloppairorbetter_call_preflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'FoldWithNoPostFlopPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('D', 2)) table.players[0].hole_cards.append(Card('H', 9)) assert table.players[0].decide() == Decision.CALL
def test_foldwithnopostfloppairorbetter_call_preflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'FoldWithNoPostFlopPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('D', 2)) table.players[0].hole_cards.append(Card('H', 9)) assert table.players[0].decide() == Decision.CALL
def test_callpairorbetter_fold_preflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'CallPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('H', 10)) table.players[0].hole_cards.append(Card('H', 9)) assert table.players[0].decide() == Decision.FOLD
def test_callpairorbetter_fold_preflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'CallPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('H', 10)) table.players[0].hole_cards.append(Card('H', 9)) assert table.players[0].decide() == Decision.FOLD
def test_table_take_bet_two_skim_bets(): table = Table() player = Player(3) player.sit(table, 0) player = Player(4) player.sit(table, 3) for i in (1, 2): player = Player(10) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(5) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: None, 3: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: 6, 3: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 2 assert table.pots[0].round_bets == {1: 4, 0: None, 2: 4, 3: 4} assert table.pots[1].round_bets == {1: 1, 2: 2, 0: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 3 assert table.pots[0].round_bets == {1: 3, 0: 3, 2: 3, 3: 3} assert table.pots[1].round_bets == {1: 1, 2: 1, 3: 1} assert table.pots[2].round_bets == {1: 1, 2: 2}
def test_callpairorbetter_call_postflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'CallPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('D', 9)) table.players[0].hole_cards.append(Card('H', 9)) table.board.append(Card('S', 'A')) assert table.players[0].decide() == Decision.CALL
def test_table_no_initialize(): table = Table() for i in xrange(3): player = Player(10) player.sit(table, i) try: table.deal_one_hole_card_to_all_players() except TableException as e: assert str(e) == 'Hand not initialized' else: assert False
def test_table_no_initialize(): table = Table() for i in xrange(3): player = Player(10) player.sit(table, i) try: table.deal_one_hole_card_to_all_players() except TableException as e: assert str(e) == 'Hand not initialized' else: assert False
def test_callpairorbetter_call_postflop(): table = Table() num_players = 3 for i in xrange(num_players): player = Player(10, 'CallPairOrBetter') player.sit(table, i) table.initialize_hand() table.players[0].hole_cards.append(Card('D', 9)) table.players[0].hole_cards.append(Card('H', 9)) table.board.append(Card('S', 'A')) assert table.players[0].decide() == Decision.CALL
def test_table_community_card(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() remember = table.deck.cards[0] table.deal_one_community_card() assert table.board == [remember]
def test_table_community_card(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() remember = table.deck.cards[0] table.deal_one_community_card() assert table.board == [remember]
def test_pot_receive_bet(): players = [] for i in xrange(num_players): player = Player(1000) player.position = i players.append(player) pot = Pot(range(num_players)) pot.receive_bet(10, players[0]) compare_round_bets = dict(zip(range(1, 10), [None for pos in range(1, 10)])) compare_round_bets[0] = 10 assert pot.round_bets == compare_round_bets assert pot.chips == 0
def test_pot_single_player_end_round(): players = [] for i in xrange(1): player = Player(1000) player.position = i players.append(player) pot = Pot(range(1)) pot.receive_bet(10, players[0]) assert pot.round_bets == {0: 10} assert pot.chips == 0 pot.end_round() assert pot.round_bets == {0: None} assert pot.chips == 10
def test_pot_receive_bet(): players = [] for i in xrange(num_players): player = Player(1000) player.position = i players.append(player) pot = Pot(range(num_players)) pot.receive_bet(10, players[0]) compare_round_bets = dict(zip(range(1, 10), [None for pos in range(1, 10)])) compare_round_bets[0] = 10 assert pot.round_bets == compare_round_bets assert pot.chips == 0
def test_pot_initial_round_bets_chained(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) pot.receive_bet(15, players[0]) pot2 = Pot(range(3), initial_round_bets=pot.skim_for_side_pot(10)[0]) assert pot.chips == 0 assert pot.round_bets == {0: 10, 1: None, 2: None} assert pot2.chips == 0 assert pot2.round_bets == {0: 5, 1: None, 2: None}
def test_table(): table = Table() for i in xrange(3): player = Player(10) player.sit(table, i) table.initialize_hand() assert table.board == [] assert table.button_seat == 0 assert table.action == 0 assert len(table.pots) == 1 assert table.pots[0].chips == 0 assert table.pots[0].round_bets == {0: None, 1: None, 2: None} assert table.rake == [0]
def test_pot_single_player_end_round(): players = [] for i in xrange(1): player = Player(1000) player.position = i players.append(player) pot = Pot(range(1)) pot.receive_bet(10, players[0]) assert pot.round_bets == {0: 10} assert pot.chips == 0 pot.end_round() assert pot.round_bets == {0: None} assert pot.chips == 10
def test_pot_initial_round_bets_chained(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) pot.receive_bet(15, players[0]) pot2 = Pot(range(3), initial_round_bets=pot.skim_for_side_pot(10)[0]) assert pot.chips == 0 assert pot.round_bets == {0: 10, 1: None, 2: None} assert pot2.chips == 0 assert pot2.round_bets == {0: 5, 1: None, 2: None}
def test_table_flop(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] board_cards = table.deck.cards[1:4] table.flop() assert table.board == board_cards
def test_table(): table = Table() for i in xrange(3): player = Player(10) player.sit(table, i) table.initialize_hand() assert table.board == [] assert table.button_seat == 0 assert table.action == 0 assert len(table.pots) == 1 assert table.pots[0].chips == 0 assert table.pots[0].round_bets == {0: None, 1: None, 2: None} assert table.rake == [0]
def test_table_river(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] remember = table.deck.cards[1] table.river() assert table.board == [remember]
def test_table_river(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] remember = table.deck.cards[1] table.river() assert table.board == [remember]
def test_table_flop(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] board_cards = table.deck.cards[1:4] table.flop() assert table.board == board_cards
def test_table_take_blinds(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() # This will have to change when I support more types of games assert table.pots[0].round_bets == {1: 1, 2: 2, 0: None} assert table.action == 2
def test_table_pots_need_action(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() assert table.pots_need_action(0) assert table.pots_need_action(1) assert not table.pots_need_action(2)
def test_table_determine_final_winner(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.deal_one_hole_card_to_all_players() table.deal_one_hole_card_to_all_players() table.flop() table.turn() table.river()
def test_table_determine_final_winner(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.deal_one_hole_card_to_all_players() table.deal_one_hole_card_to_all_players() table.flop() table.turn() table.river()
def test_table_take_blinds(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() # This will have to change when I support more types of games assert table.pots[0].round_bets == {1: 1, 2: 2, 0: None} assert table.action == 2
def test_table_take_bet_skim_bet_after(): table = Table() player = Player(4) player.sit(table, 3) for i in (0, 1, 2): player = Player(10) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(5) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: None, 3: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: 6, 3: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 2 assert table.pots[0].round_bets == {1: 4, 0: None, 2: 4, 3: 4} assert table.pots[1].round_bets == {1: 1, 2: 2, 0: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 2 assert table.pots[0].round_bets == {1: 4, 0: 4, 2: 4, 3: 4} assert table.pots[1].round_bets == {1: 1, 2: 2, 0: 2}
def test_pot_three_players_end_round_2(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(0, players[0]) # Check assert not pot.round_done() pot.receive_bet(0, players[1]) assert not pot.round_done() pot.receive_bet(0, players[2]) assert pot.round_done()
def test_table_pots_need_action(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() assert table.pots_need_action(0) assert table.pots_need_action(1) assert not table.pots_need_action(2)
def test_pot_skim_2(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) pot.receive_bet(5, players[0]) pot.receive_bet(10, players[1]) assert pot.round_bets == {0: 5, 1: 10, 2: None} assert pot.chips == 0 for_next_pot = pot.skim_for_side_pot(7) assert pot.round_bets == {0: 5, 1: 7, 2: None} assert for_next_pot == ({1: 3, 2: None}, {'amt': 7})
def test_table_take_bet_skim(): table = Table() player = Player(4) player.sit(table, 0) for i in (1, 2): player = Player(10) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(5) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: 6} table.incr_action() table.take_bet(6) assert len(table.pots) == 2 assert table.pots[0].round_bets == {1: 4, 0: 4, 2: 4} assert table.pots[1].round_bets == {1: 1, 2: 2} assert table.players[0].chips == 0 assert table.players[1].chips == 5 assert table.players[2].chips == 4
def test_pot_three_players_end_round_2(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(0, players[0]) # Check assert not pot.round_done() pot.receive_bet(0, players[1]) assert not pot.round_done() pot.receive_bet(0, players[2]) assert pot.round_done()
def test_pot_skim_2(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) pot.receive_bet(5, players[0]) pot.receive_bet(10, players[1]) assert pot.round_bets == {0: 5, 1: 10, 2: None} assert pot.chips == 0 for_next_pot = pot.skim_for_side_pot(7) assert pot.round_bets == {0: 5, 1: 7, 2: None} assert for_next_pot == ({1: 3, 2: None}, {'amt': 7})
def test_neverplay(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10, 'NeverPlay') player.sit(table, i) players.append(player) assert table.button_seat == -1 table.deal() assert table.button_seat == 0 assert table.players[2].chips == 11 assert table.players[1].chips == 9 assert table.players[0].chips == 10
def test_neverplay(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10, 'NeverPlay') player.sit(table, i) players.append(player) assert table.button_seat == -1 table.deal() assert table.button_seat == 0 assert table.players[2].chips == 11 assert table.players[1].chips == 9 assert table.players[0].chips == 10
def test_table_deal_hole_card(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] player_cards = [[table.deck.cards[i+1]] for i in xrange(num_players)] assert to_burn == table.burn_one_card() table.deal_one_hole_card_to_all_players() for i in xrange(1, num_players): assert players[i].hole_cards == player_cards[i-1] assert players[0].hole_cards == player_cards[-1]
def test_table_run_betting_round(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() winner = table.run_betting_round() assert winner == 2 assert len(table.pots) == 1 assert table.pots[0].chips == 3 # For a 1/2 limit game
def test_table_run_betting_round(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() table.incr_action() table.take_blinds() winner = table.run_betting_round() assert winner == 2 assert len(table.pots) == 1 assert table.pots[0].chips == 3 # For a 1/2 limit game
def test_table_deal_hole_card(): table = Table() num_players = 3 players = [] for i in xrange(num_players): player = Player(10) player.sit(table, i) players.append(player) table.initialize_hand() to_burn = table.deck.cards[0] player_cards = [[table.deck.cards[i + 1]] for i in xrange(num_players)] assert to_burn == table.burn_one_card() table.deal_one_hole_card_to_all_players() for i in xrange(1, num_players): assert players[i].hole_cards == player_cards[i - 1] assert players[0].hole_cards == player_cards[-1]
def test_pot_three_players_bad_end_round(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(0, players[0]) # Check assert not pot.round_done() pot.receive_bet(0, players[1]) try: pot.end_round() except PotException as e: assert str(e) == 'Betting round cannot be complete' else: assert False
def test_pot_three_players_bad_end_round(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(0, players[0]) # Check assert not pot.round_done() pot.receive_bet(0, players[1]) try: pot.end_round() except PotException as e: assert str(e) == 'Betting round cannot be complete' else: assert False
def test_badbrain(): table = Table() num_players = 3 players = [] for i in xrange(num_players): try: player = Player(10, 'NotARealBrainName') except PlayerException as e: assert str(e) == 'Brain named "NotARealBrainName" cannot be found'
def test_pot_action_needed(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert pot.action_needed(0) assert pot.action_needed(1) assert pot.action_needed(2) assert not pot.action_needed(3) pot.receive_bet(10, players[0]) assert not pot.action_needed(0) assert pot.action_needed(1) assert pot.action_needed(2) pot.receive_bet(20, players[1]) # a raise assert pot.action_needed(0) assert not pot.action_needed(1) assert pot.action_needed(2)
def test_alwayscall(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10, 'AlwaysCall') player.sit(table, i) players.append(player) assert table.button_seat == -1 table.deal() assert table.button_seat == 0 # I don't know who won here chips = [] for player in table.players.values(): chips.append(player.chips) assert (chips.count(8) == 2 and chips.count(14) == 1) or \ (chips.count(8) == 2 and chips.count(14) == 1) or \ (chips.count(10) == 3)
def test_table_take_rake_at_limit(): table = Table() for i in (1, 2, 3, 4): player = Player(100) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) for pot in table.pots: pot.end_round() table.take_rake() assert table.rake == [5]
def test_pot_action_needed(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert pot.action_needed(0) assert pot.action_needed(1) assert pot.action_needed(2) assert not pot.action_needed(3) pot.receive_bet(10, players[0]) assert not pot.action_needed(0) assert pot.action_needed(1) assert pot.action_needed(2) pot.receive_bet(20, players[1]) # a raise assert pot.action_needed(0) assert not pot.action_needed(1) assert pot.action_needed(2)
def test_alwayscall(): table = Table() # Dealer will bet first preflop, so 2 will win as for now all players will fold num_players = 3 players = [] for i in xrange(num_players): player = Player(10, 'AlwaysCall') player.sit(table, i) players.append(player) assert table.button_seat == -1 table.deal() assert table.button_seat == 0 # I don't know who won here chips = [] for player in table.players.values(): chips.append(player.chips) assert (chips.count(8) == 2 and chips.count(14) == 1) or \ (chips.count(8) == 2 and chips.count(14) == 1) or \ (chips.count(10) == 3)
def test_table_take_rake_at_limit(): table = Table() for i in (1, 2, 3, 4): player = Player(100) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) table.incr_action() table.take_bet(100) for pot in table.pots: pot.end_round() table.take_rake() assert table.rake == [5]
def test_pot_three_players_end_round(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(5, players[0]) assert not pot.round_done() pot.receive_bet(10, players[1]) assert not pot.round_done() pot.receive_bet(10, players[2]) assert not pot.round_done() pot.make_ineligible_to_win(0) # Player 0 folds assert pot.round_done() assert pot.round_bets == {1: 10, 2: 10} assert pot.chips == 5 pot.end_round() assert pot.chips == 25 assert pot.round_bets == {1: None, 2: None}
def test_pot_three_players_end_round(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(5, players[0]) assert not pot.round_done() pot.receive_bet(10, players[1]) assert not pot.round_done() pot.receive_bet(10, players[2]) assert not pot.round_done() pot.make_ineligible_to_win(0) # Player 0 folds assert pot.round_done() assert pot.round_bets == {1: 10, 2: 10} assert pot.chips == 5 pot.end_round() assert pot.chips == 25 assert pot.round_bets == {1: None, 2: None}
def test_table_take_bet_skim(): table = Table() player = Player(4) player.sit(table, 0) for i in (1, 2): player = Player(10) player.sit(table, i) table.initialize_hand() table.incr_action() table.take_bet(5) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: None} table.incr_action() table.take_bet(6) assert len(table.pots) == 1 assert table.pots[0].round_bets == {1: 5, 0: None, 2: 6} table.incr_action() table.take_bet(6) assert len(table.pots) == 2 assert table.pots[0].round_bets == {1: 4, 0: 4, 2: 4} assert table.pots[1].round_bets == {1: 1, 2: 2} assert table.players[0].chips == 0 assert table.players[1].chips == 5 assert table.players[2].chips == 4
def test_pot_three_players_bad_fold(): players = [] for i in xrange(3): player = Player(1000) player.position = i players.append(player) pot = Pot(range(3)) assert not pot.round_done() pot.receive_bet(5, players[0]) assert not pot.round_done() pot.make_ineligible_to_win(1) assert not pot.round_done() pot.receive_bet(10, players[2]) assert not pot.round_done() pot.receive_bet(5, players[0]) # Player 0 calls assert pot.round_done() assert pot.round_bets == {0: 10, 2: 10} assert pot.chips == 0 try: pot.make_ineligible_to_win(1) except PotException as e: assert str(e) == 'Position 1 is already not eligible to win' else: assert False