Ejemplo n.º 1
0
 def test_collect_blinds(self):
     initial_stack = 1000
     small_blind_size = 5
     big_blind_size = small_blind_size * 2
     button_player = self.setup_new_player("Button", initial_stack)
     player2 = self.setup_new_player("SmallBlind", initial_stack)
     player3 = self.setup_new_player("BigBlind", initial_stack)
     seating = Seating([button_player, player2, player3])
     deck = Deck()
     dealer = Dealer(deck, seating)
     dealer.pot = Pot()
     dealer.collect_blinds(small_blind_size)
     self.assertEqual(initial_stack, button_player.stack)
     self.assertEqual(initial_stack - small_blind_size, player2.stack)
     self.assertEqual(initial_stack - big_blind_size, player3.stack)
     self.assertEqual(big_blind_size + small_blind_size,
                      dealer.pot.total_count())
     dealer.move_button()
     dealer.pot = Pot()
     dealer.collect_blinds(small_blind_size)
     self.assertEqual(initial_stack - big_blind_size, button_player.stack)
     self.assertEqual(initial_stack - small_blind_size, player2.stack)
     self.assertEqual(initial_stack - big_blind_size - small_blind_size,
                      player3.stack)
     self.assertEqual(big_blind_size + small_blind_size,
                      dealer.pot.total_count())
     self.assertTrue(button_player in dealer.pot.chips_per_player)
     self.assertTrue(player3 in dealer.pot.chips_per_player)
Ejemplo n.º 2
0
 def setup_dealer_and_play_preflop_where_everybody_calls(
         self, players, small_blind_size):
     for player in players:
         player.act = self.action_check_call()
     seating = Seating(players)
     dealer = Dealer(None, seating)
     dealer.setup_deck()
     winner = dealer.play_preflop(small_blind_size)
     print("# Preflop concluded")
     self.assertEqual(False, winner)
     return dealer
Ejemplo n.º 3
0
 def setup_3_player_preflop_where_everybody_folds(self, initial_stack):
     button_player = self.setup_new_player("Button", initial_stack)
     sb_player = self.setup_new_player("SmallBlind", initial_stack)
     bb_player = self.setup_new_player("BigBlind", initial_stack)
     button_player.act = self.action_fold()
     sb_player.act = self.action_fold()
     bb_player.act = self.action_fold()
     seating = Seating([button_player, sb_player, bb_player])
     dealer = Dealer(None, seating)
     dealer.setup_deck()
     return dealer
Ejemplo n.º 4
0
 def test_deal(self):
     player1 = Player("player1", 1000)
     player2 = Player("player2", 1000)
     seating = Seating([player1, player2])
     deck = Deck()
     deck.initialize()
     dealer = Dealer(deck, seating)
     dealer.deal_cards_to_players()
     hand_size = 2
     cards_dealt = len(seating.players) * hand_size
     self.assertEqual(cards_dealt, len(set(player1.cards + player2.cards)))
     expected_remaining_card_count = TestDeck.deck_size - cards_dealt
     self.assertEqual(expected_remaining_card_count, len(deck.cards))
Ejemplo n.º 5
0
 def test_play_round__when_round_concludes___button_is_moved(self):
     stack_player1 = 100
     stack_player2 = 100
     player1 = self.setup_new_player("Player1", stack_player1)
     player2 = self.setup_new_player("Player2", stack_player2)
     player1.act = TestDealer.action_fold()
     player2.act = TestDealer.action_fold()
     seating = Seating([player1, player2])
     dealer = Dealer(None, seating)
     dealer.move_button = MagicMock()
     # draw for Button and SmallBlind, both have 2 pairs with same kicker
     round = Round(dealer)
     round.play_round(5)
     self.assertTrue(dealer.move_button.called)
Ejemplo n.º 6
0
 def test_play_round__when_players_allin_with_unequal_stacks__side_pots_are_formed(
         self):
     stack_player1 = 1000
     stack_player2 = 3300
     stack_player3 = 7500
     stack_player4 = 30000
     player1 = self.setup_new_player("Button", stack_player1)
     player2 = self.setup_new_player("SmallBlind", stack_player2)
     player3 = self.setup_new_player("BigBlind", stack_player3)
     player4 = self.setup_new_player("UTG", stack_player4)
     player1.act = TestDealer.action_raise(stack_player1)
     player2.act = TestDealer.action_raise(stack_player2)
     player3.act = TestDealer.action_raise(stack_player3)
     player4.act = TestDealer.action_raise(stack_player4)
     seating = Seating([player1, player2, player3, player4])
     dealer = Dealer(None, seating, 1)
     # with seed 1 SmallBlind wins with pair of 6s
     # side pot goes to UTG with pair of 4s
     round = Round(dealer)
     round.play_round(5)
     self.assertEqual(0, player1.stack)
     self.assertEqual(stack_player2 * 3 + stack_player1, player2.stack)
     self.assertEqual(0, player3.stack)
     self.assertEqual(stack_player4 - stack_player2 * 2 + stack_player3,
                      player4.stack)
Ejemplo n.º 7
0
    def test_preflop_round__when_player_raises__all_calls(self):
        initial_stack = 100
        bet_size = 50
        raise_size = bet_size + 10
        small_blind_size = 5
        button_player = self.setup_new_player("Button", initial_stack)
        sb_player = self.setup_new_player("SmallBlind", initial_stack)
        bb_player = self.setup_new_player("BigBlind", initial_stack)

        def call_raise(player_name):
            def call_raise_action(amount):
                if amount == small_blind_size * 2:
                    print(player_name + " calls " + str(amount))
                    return Action.ACTION_CALL, amount
                print(player_name + " raises to " + str(raise_size))
                return Action.ACTION_RAISE, raise_size

            return call_raise_action

        button_player.act = call_raise("Button")

        def raise_call(player_name):
            def raise_call_action(amount):
                if amount == small_blind_size * 2:
                    print(player_name + " raises to " + str(bet_size))
                    return Action.ACTION_RAISE, bet_size
                print(player_name + " calls " + str(amount))
                return Action.ACTION_CALL, amount

            return raise_call_action

        sb_player.act = raise_call("SmallBlind")
        bb_player.act = self.action_check_call()
        seating = Seating([button_player, sb_player, bb_player])
        dealer = Dealer(None, seating)
        dealer.setup_deck()
        winner = dealer.play_preflop(small_blind_size)
        self.assertEqual(False, winner)
        self.assertTrue(button_player in dealer.pot.chips_per_player)
        self.assertTrue(sb_player in dealer.pot.chips_per_player)
        self.assertTrue(bb_player in dealer.pot.chips_per_player)
        self.assertEqual(initial_stack - raise_size, button_player.stack)
        self.assertEqual(initial_stack - raise_size, sb_player.stack)
        self.assertEqual(initial_stack - raise_size, bb_player.stack)
        self.assertEqual(raise_size * 3, dealer.pot.total_count())
Ejemplo n.º 8
0
 def test_collect_blinds__when_player_dont_have_enough_chips(self):
     initial_stack = 100
     small_blind_size = 5
     big_blind_size = small_blind_size * 2
     button_player = self.setup_new_player("Button", 100)
     player2 = self.setup_new_player("SmallBlind", small_blind_size - 1)
     player3 = self.setup_new_player("BigBlind", big_blind_size - 1)
     seating = Seating([button_player, player2, player3])
     deck = Deck()
     dealer = Dealer(deck, seating)
     dealer.pot = Pot()
     dealer.collect_blinds(small_blind_size)
     self.assertEqual(initial_stack, button_player.stack)
     self.assertEqual(0, player2.stack)
     self.assertEqual(0, player3.stack)
     self.assertEqual(13, dealer.pot.total_count())
     self.assertTrue(player2 in dealer.pot.chips_per_player)
     self.assertTrue(player3 in dealer.pot.chips_per_player)
Ejemplo n.º 9
0
 def test_is_winner_determined__when_one_player_left_with_chips__returns_true(
         self):
     stack_player1 = 200
     stack_player2 = 0
     player1 = self.setup_new_player("Player1", stack_player1)
     player2 = self.setup_new_player("Player2", stack_player2)
     seating = Seating([player1, player2])
     dealer = Dealer(None, seating)
     round = Round(dealer)
     self.assertTrue(round.is_winner_determined())
Ejemplo n.º 10
0
 def test_move_button__when2players(self):
     initial_button_player = self.setup_new_player("Button", 100)
     initial_bb_player = self.setup_new_player("BigBlind", 100)
     seating = Seating([initial_button_player, initial_bb_player])
     deck = Deck()
     dealer = Dealer(deck, seating)
     dealer.move_button()
     seating.button_position = 0
     dealer.move_button()
     seating.button_position = 1
     dealer.move_button()
     seating.button_position = 0
Ejemplo n.º 11
0
 def test_preflop_round__when_first_player_bets__all_calls(self):
     initial_stack = 100
     bet_size = 50
     small_blind_size = 5
     button_player = self.setup_new_player("Button", initial_stack)
     sb_player = self.setup_new_player("SmallBlind", initial_stack)
     bb_player = self.setup_new_player("BigBlind", initial_stack)
     button_player.act = self.action_raise(bet_size)
     sb_player.act = self.action_check_call()
     bb_player.act = self.action_check_call()
     seating = Seating([button_player, sb_player, bb_player])
     dealer = Dealer(None, seating)
     dealer.setup_deck()
     winner = dealer.play_preflop(small_blind_size)
     self.assertEqual(False, winner)
     self.assertTrue(button_player in dealer.pot.chips_per_player)
     self.assertTrue(sb_player in dealer.pot.chips_per_player)
     self.assertTrue(bb_player in dealer.pot.chips_per_player)
     self.assertEqual(initial_stack - bet_size, button_player.stack)
     self.assertEqual(initial_stack - bet_size, sb_player.stack)
     self.assertEqual(initial_stack - bet_size, bb_player.stack)
     self.assertEqual(bet_size * 3, dealer.pot.total_count())
Ejemplo n.º 12
0
 def test_play_round__when_player_wins_in_turn__round_concludes(self):
     initial_stack = 1000
     button_player = self.setup_new_player("Button", initial_stack)
     sb_player = self.setup_new_player("SmallBlind", initial_stack)
     bb_player = self.setup_new_player("BigBlind", initial_stack)
     utg_player = self.setup_new_player("UTG", initial_stack)
     button_player.act = TestDealer.action_call_fold(2)
     sb_player.act = TestDealer.action_call_fold(2)
     bb_player.act = TestDealer.action_call_fold(2)
     utg_player.act = TestDealer.action_call_fold(2)
     seating = Seating([button_player, sb_player, bb_player, utg_player])
     dealer = Dealer(None, seating)
     round = Round(dealer)
     round.play_round(5)
     self.assertEqual(40, len(dealer.deck.cards))
Ejemplo n.º 13
0
 def test_play_round__when_played_with_fixed_deck_and_player_keeps_raising__expected_player_wins(
         self):
     initial_stack = 1000
     button_player = self.setup_new_player("Button", initial_stack)
     sb_player = self.setup_new_player("SmallBlind", initial_stack)
     bb_player = self.setup_new_player("BigBlind", initial_stack)
     utg_player = self.setup_new_player("UTG", initial_stack)
     button_player.act = TestDealer.action_check_call()
     sb_player.act = TestDealer.action_check_call()
     bb_player.act = self.action_raise(10)
     utg_player.act = TestDealer.action_check_call()
     seating = Seating([button_player, sb_player, bb_player, utg_player])
     # seed value 2 results in shuffling where SmallBlind has best hand (Pair)
     seed = 2
     dealer = Dealer(None, seating, seed)
     round = Round(dealer)
     round.play_round(5)
     self.assertEqual(1150, sb_player.stack)
Ejemplo n.º 14
0
 def test_play_round__when_draw__pot_is_shared(self):
     stack_player1 = 10000
     stack_player2 = 3000
     stack_player3 = 1001  # 1 chip will be dropped when splitting pot
     player1 = self.setup_new_player("Button", stack_player1)
     player2 = self.setup_new_player("SmallBlind", stack_player2)
     player3 = self.setup_new_player("BigBlind", stack_player3)
     player1.act = TestDealer.action_raise(stack_player3)
     player2.act = TestDealer.action_raise(stack_player2)
     player3.act = TestDealer.action_raise(stack_player3)
     seating = Seating([player1, player2, player3])
     dealer = Dealer(None, seating, 27)
     # draw for Button and SmallBlind, both have 2 pairs with same kicker
     round = Round(dealer)
     round.play_round(5)
     self.assertEqual(stack_player1 + 500, player1.stack)
     self.assertEqual(stack_player2 + 500, player2.stack)
     self.assertEqual(0, player3.stack)
Ejemplo n.º 15
0
 def test_play_round__when_round_ends__cards_are_collected(self):
     stack_player1 = 100
     stack_player2 = 100
     stack_player3 = 100
     player1 = self.setup_new_player("Player1", stack_player1)
     player2 = self.setup_new_player("Player2", stack_player2)
     player3 = self.setup_new_player("Player3", stack_player3)
     player1.act = TestDealer.action_raise(100)
     player2.act = TestDealer.action_raise(100)
     player3.act = TestDealer.action_raise(100)
     seating = Seating([player1, player2, player3])
     dealer = Dealer(None, seating, 27)
     # draw for Button and SmallBlind, both have 2 pairs with same kicker
     round = Round(dealer)
     round.play_round(5)
     self.assertEqual(0, len(dealer.community_cards))
     self.assertEqual(0, len(player1.cards))
     self.assertEqual(0, len(player2.cards))
     self.assertEqual(0, len(player3.cards))
Ejemplo n.º 16
0
#imports
from bots.pseudo_bot import PseudoBot
from bots.easy_bot import EasyBot
from bots.trainer import Trainer
from engine.dealer import Dealer
from engine.player import Player
    
#constants
#n/a

#functions
#n/a

#
valerie = Dealer()
#print("valerie will be our dealer.")

matt_damon = Player("Matt")
ed_norton = Player("Ed")
trainer = Trainer()

matt_damon.bot = EasyBot("MattBot")
ed_norton.bot = PseudoBot("EdBot")

# each iteration took about 1 min, default is 100 iters
# trainer = Trainer()
# trainer.train(matt_damon)

valerie.start_game(matt_damon, ed_norton)
#c = "To play a hand, run ``valerie.play_hand()``\n"
Ejemplo n.º 17
0
from engine.dealer import Dealer
from engine.game_settings import DefaultGameSettings
from engine.round import Round

game_settings = DefaultGameSettings()
dealer = Dealer(None, game_settings.seating)
round = Round(dealer)
while not round.is_winner_determined():
    round.play_round(game_settings.small_blind_size)
Ejemplo n.º 18
0
 def test_move_button__when5players(self):
     player1 = self.setup_new_player("Player1", 100)
     player2 = self.setup_new_player("Player2", 100)
     initial_button_player = self.setup_new_player("Button", 100)
     initial_sb_player = self.setup_new_player("SmallBlind", 100)
     initial_bb_player = self.setup_new_player("BigBlind", 100)
     seating = Seating([
         player1, player2, initial_button_player, initial_sb_player,
         initial_bb_player
     ])
     deck = Deck()
     dealer = Dealer(deck, seating)
     dealer.move_button()
     seating.button_position = 0
     dealer.move_button()
     seating.button_position = 1
     dealer.move_button()
     seating.button_position = 2
     dealer.move_button()
     seating.button_position = 3
     dealer.move_button()
     seating.button_position = 4
     dealer.move_button()
     seating.button_position = 5
     dealer.move_button()
     seating.button_position = 0