Exemplo n.º 1
0
    def test_BettingRound_called_to_blind(self):
        """Test of BettingRound with calls around to blind.

        Blind should still have option to act."""
        players = [ Player(stack=500),
                    Player(stack=100),
                    Player(stack=1000),
                    Player(stack=700) ]
        table = Table()
        table.seat_players(players, in_order=True)
        message_handler = MessageHandler(table, self.console)
        pot = Pot(players)
        round = BettingRound(table, pot, message_handler)
        action_is_on = players[0]
        round.set_action(action_is_on)
        # Player 0 50 blind, fold, fold, fold
        round.process_action(Action.new_blind(50))
        round.process_action(Action.new_fold())
        round.process_action(Action.new_call(50))
        round.process_action(Action.new_fold())
        # Back on blind
        self.assertFalse(round.is_pot_good())
        round.process_action(Action.new_check())
        self.assertTrue(round.is_pot_good())
        round.sweep_bets_into_pot()
        # At this point we should have a pot of 50 with only player
        # 0 contending.
        pot = round.pot
        self.assertEqual(pot.amount, 100)
        self.assertListEqual(pot.contending_players, [players[0], players[2]])
        self.assertIsNone(pot.parent)
Exemplo n.º 2
0
 def test_BettingRound_blind_walk(self):
     """Test of BettingRound with a walk for the blind"""
     players = [ Player(stack=500),
                 Player(stack=100),
                 Player(stack=1000),
                 Player(stack=700) ]
     table = Table()
     table.seat_players(players, in_order=True)
     message_handler = MessageHandler(table, self.console)
     pot = Pot(players)
     round = BettingRound(table, pot, message_handler)
     action_is_on = players[0]
     round.set_action(action_is_on)
     # Player 0 50 blind, fold, fold, fold
     round.process_action(Action.new_blind(50))
     round.process_action(Action.new_fold())
     round.process_action(Action.new_fold())
     round.process_action(Action.new_fold())
     self.assertTrue(round.is_pot_good())
     round.sweep_bets_into_pot()
     # At this point we should have a pot of 50 with only player
     # 0 contending.
     pot = round.pot
     self.assertEqual(pot.amount, 50)
     self.assertListEqual(pot.contending_players, [players[0]])
     self.assertIsNone(pot.parent)
Exemplo n.º 3
0
 def test_BettingRound_with_side_pots(self):
     """Test of BettingRound with side pots."""
     players = [ Player(stack=500),
                 Player(stack=100),
                 Player(stack=1000),
                 Player(stack=700) ]
     table = Table()
     table.seat_players(players, in_order=True)
     message_handler = MessageHandler(table, self.console)
     pot = Pot(players)
     round = BettingRound(table, pot, message_handler)
     action_is_on = players[0]
     round.set_action(action_is_on)
     # Player 0 50 blind, player 1 100 blind (allin),
     # player 2 raises to 300, player 4 calls
     round.process_action(Action.new_blind(50))
     round.process_action(Action.new_blind(100, all_in=True))
     round.process_action(Action.new_raise(300))
     round.process_action(Action.new_call(300))
     # Player 0 raises 450 all-in, player 2 raises 700 all-in
     # Player 3 folds
     round.process_action(Action.new_raise(450, all_in=True))
     # Make sure player 1, who is all-in, is skipped
     self.assertEqual(round.get_action_player(), players[2])
     round.process_action(Action.new_raise(700, all_in=True))
     round.process_action(Action.new_fold())
     self.assertTrue(round.is_pot_good())
     round.sweep_bets_into_pot()
     # At this point we should have a main point with 400
     # between 0,1 and 2, a side pot with 1000 between players 0 and 2,
     # and a side pot of 500 with just player 2.
     side_pot1 = round.pot
     self.assertEqual(side_pot1.amount, 500)
     self.assertListEqual(side_pot1.contending_players, [players[2]])
     self.assertIsNotNone(side_pot1.parent)
Exemplo n.º 4
0
 def test_Game(self):
     """Test Game class"""
     players = [
         Player(name="Player One", stack=1000),
         Player(name="Player Two", stack=1000),
         Player(name="Player Three", stack=1000)
         ]
     table = Table(players = players)
     structure = Structure(Structure.LIMIT, ante=5, blinds=[10])
     game = Game(table, structure, console=self.console)
     self.assertIsNotNone(game)
     self.assertEqual(game.table, table)
     self.assertEqual(game.structure, structure)
     # Default MessageHander should be created.
     self.assertIsNotNone(game.message_handler)
     game.message("Test message")
     game.debug("Test debug message")
     # Simulate play_hand()
     hand_state = HandState(table, game.message_handler)
     game.antes(hand_state)
     self.assertEqual(hand_state.pot.amount, 15)
     game.action_to_left_of_dealer(hand_state)
     betting_round = hand_state.get_current_betting_round()
     self.assertIsInstance(betting_round, BettingRound)
     self.assertIsInstance(betting_round.get_action_player(), Player)
     game.blinds(hand_state)
     self.assertEqual(betting_round.total_pot(), 25)  # Antes + 10 blind
     game.deal_hands(hand_state)
     for player in players:
         self.assertEqual(len(player._hand), 5)
     # Simulate betting_round()
     self.assertFalse(betting_round.is_pot_good())
     action_request = game._get_action_request(hand_state)
     self.assertIsInstance(action_request, ActionRequest)
     # Should be call of blind
     self.assertTrue(action_request.is_call_request())
     self.assertEqual(action_request.amount, 10)
     self.assertEqual(action_request.raise_amount, 20)
     # Fold UTG
     betting_round.process_action(Action.new_fold())
     self.assertFalse(betting_round.is_pot_good())
     # Should be same request as before
     action_request2 = game._get_action_request(hand_state)
     self.assertIsInstance(action_request2, ActionRequest)
     self.assertTrue(action_request2.is_call_request())
     self.assertEqual(action_request2.amount, 10)
     self.assertEqual(action_request2.raise_amount, 20)
     # Now raise
     betting_round.process_action(Action.new_raise(20))
     self.assertFalse(betting_round.is_pot_good())
     # Action back on blind
     action_request3 = game._get_action_request(hand_state)
     self.assertIsInstance(action_request3, ActionRequest)
     self.assertTrue(action_request3.is_call_request())
     self.assertEqual(action_request3.amount, 10)
     self.assertEqual(action_request3.raise_amount, 20)
     betting_round.process_action(Action.new_call(10))
     self.assertTrue(betting_round.is_pot_good())
     game.pot_to_high_hand(hand_state)
Exemplo n.º 5
0
 def test_Action_fold(self):
     """Test fold Action"""
     action = Action.new_fold()
     self.assertIsNotNone(action)
     self.assertTrue(action.is_fold())
     self.assertEqual(action.amount, 0)
     self.assertFalse(action.is_all_in())
     self.assertEqual(str(action), "fold")
Exemplo n.º 6
0
 def test_option_ActionRequest(self):
     """Test ActionRequest for option"""
     amount = 50
     request = ActionRequest.new_option_request(amount)
     self.assertIsNotNone(request)
     self.assertTrue(request.is_option_request())
     self.assertEqual(request.raise_amount, amount)
     request.validate_action(Action.new_check())
     request.validate_action(Action.new_raise(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_blind(amount+1))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_call(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_bet(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_fold())
Exemplo n.º 7
0
 def test_ante_ActionRequest(self):
     """Test ActionRequest for ante"""
     amount = 20
     request = ActionRequest.new_ante_request(amount)
     self.assertIsNotNone(request)
     self.assertTrue(request.is_ante_request())
     self.assertEqual(request.amount, amount)
     request.validate_action(Action.new_ante(amount))
     request.validate_action(Action.new_fold())
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_ante(amount+1))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_call(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_bet(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_raise(amount))
Exemplo n.º 8
0
 def test_call_ActionRequest(self):
     """Test ActionRequest for call"""
     amount = 50
     request = ActionRequest.new_call_request(amount, raise_amount=amount*2)
     self.assertIsNotNone(request)
     self.assertTrue(request.is_call_request())
     self.assertEqual(request.amount, amount)
     self.assertEqual(request.raise_amount, amount*2)
     self.assertEqual(str(request), "call request for 50 or raise of 100")
     request.validate_action(Action.new_call(amount))
     request.validate_action(Action.new_raise(amount*2))
     request.validate_action(Action.new_fold())
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_ante(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_blind(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_call(amount+1))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_bet(amount))
     with self.assertRaises(InvalidActionException):
         request.validate_action(Action.new_raise(amount*2-1))
Exemplo n.º 9
0
 def test_BettingRound(self):
     """Test BettingRound class"""
     players = [ Player(stack=1000),
                 Player(stack=1000),
                 Player(stack=1000),
                 Player(stack=1000) ]
     table = Table()
     table.seat_players(players, in_order=True)
     message_handler = MessageHandler(table, self.console)
     pot = Pot(players)
     round = BettingRound(table, pot, message_handler)
     self.assertIsNotNone(round)
     self.assertEqual(round.table, table)
     self.assertEqual(round.pot, pot)
     self.assertRaises(PokerGameStateException, round.get_action_player)
     action_is_on = players[1]
     round.set_action(action_is_on)
     self.assertEqual(round.get_action_player(), action_is_on)
     self.assertIsNone(round.last_to_bet)
     self.assertEqual(len(round.action_record), 0)
     self.assertEqual(round.action_to_next_player(), players[2])
     self.assertEqual(round.action_to_next_player(), players[3])
     self.assertEqual(round.action_to_next_player(), players[0])
     self.assertEqual(round.action_to_next_player(), players[1])
     self.assertEqual(round.required_to_call(players[0]), 0)
     self.assertFalse(round.is_pot_good())
     # Have all players ante
     round.process_action(Action.new_ante(5))
     self.assertEqual(players[1].stack, 995)
     self.assertEqual(round.get_action_player(), players[2])
     self.assertEqual(round.last_to_bet, players[1])
     round.process_action(Action.new_ante(5))
     self.assertEqual(players[2].stack, 995)
     self.assertEqual(round.get_action_player(), players[3])
     self.assertEqual(round.last_to_bet, players[1])
     round.process_action(Action.new_ante(5))
     self.assertEqual(players[3].stack, 995)
     self.assertEqual(round.get_action_player(), players[0])
     self.assertEqual(round.last_to_bet, players[1])
     round.process_action(Action.new_ante(5))
     self.assertEqual(players[0].stack, 995)
     self.assertEqual(round.get_action_player(), players[1])
     self.assertEqual(round.last_to_bet, players[1])
     self.assertTrue(round.is_pot_good())
     self.assertEqual(round.sweep_bets_into_pot(), pot)
     self.assertEqual(pot.amount, 20)
     # New round
     round = BettingRound(table, pot, message_handler)
     self.assertIsNotNone(round)
     round.set_action(action_is_on)
     # Player 1 blinds, 2 blinds, 3 fold, 0 raises to 300
     round.process_action(Action.new_blind(50))
     self.assertEqual(players[1].bet, 50)
     round.process_action(Action.new_blind(100))
     round.process_action(Action.new_fold())
     self.assertTrue(players[3].is_folded())
     round.process_action(Action.new_raise(300))
     self.assertFalse(round.is_pot_good())
     self.assertEqual(round.get_action_player(), players[1])
     self.assertEqual(len(round.action_record), 4)
     self.assertEqual(round.total_pot(), 470)
     # Player 1 calls, 2 raises all in, 3 has folded, 0 folds
     self.assertEqual(round.required_to_call(), 250)
     round.process_action(Action.new_call(250))
     self.assertEqual(round.required_to_call(), 200)
     round.process_action(Action.new_raise(895, all_in=True))
     self.assertTrue(players[2].is_all_in())
     # Make sure we skipped player 3 who folded earlier
     self.assertEqual(round.get_action_player(), players[0])
     self.assertEqual(round.required_to_call(), 695)
     round.process_action(Action.new_fold())
     self.assertFalse(round.is_pot_good())
     self.assertEqual(round.total_pot(), 1615)
     # Plater 1 calls and pot should be good
     self.assertEqual(round.required_to_call(), 695)
     round.process_action(Action.new_call(695, all_in=True))
     self.assertTrue(round.is_pot_good())
     self.assertEqual(round.total_pot(), 2310)
     round.sweep_bets_into_pot()
     # Should only be main pot
     self.assertIsNone(pot.parent)
     # All players bets should have beet swept into pot
     for player in players:
         self.assertEqual(0, player.bet,
                          "Bet for %s == %d != 0" % (player, player.bet))
     self.assertEqual(pot.amount, 2310)