示例#1
0
 def test_Game_play_hand(self):
     """Test Game.play_hand() method"""
     players = [ Player(name="Player One", stack=1000) ]
     table = Table(players = players)
     self.assertEqual(len(table.get_active_players()), 1)
     structure = Structure(Structure.LIMIT, ante=5, blinds=[10])
     game = Game(table, structure, console=self.console)
     # Trying to play a hand with only one player should be an exception
     with self.assertRaises(PokerGameStateException):
         game.play_hand()
     table.seat_players([
         Player(name="Player Two", stack=1000),
         Player(name="Player Three", stack=1000)
         ])
     self.assertEqual(len(table.get_active_players()), 3)
     hand_state = game.play_hand()
     self.assertIsInstance(hand_state, HandState)
     # Make sure all players states have been reset
     for player in table.get_seated_players():
         if player.stack > 0:
             self.assertTrue(player.is_active())
         else:
             self.assertTrue(player.is_sitting_out())
示例#2
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)