Esempio n. 1
0
 def test_proceed_game(self):
     game = Game()
     game.init_game()
     while not game.is_over():
         action = np.random.choice(['hit', 'action'])
         state, _ = game.step(action)
     self.assertEqual(len(state['state'][1]), len(game.dealer.hand))
Esempio n. 2
0
 def test_get_state(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     game.init_game()
     self.assertEqual(len(game.get_state(0)['state'][1]), 1)
     game.step('stand')
     self.assertGreater(len(game.get_state(0)['state'][1]), 1)
Esempio n. 3
0
 def test_init_game(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     state, current_player = game.init_game()
     self.assertEqual(len(game.history), 0)
     self.assertEqual(current_player, 0)
     self.assertEqual(game.winner['dealer'], 0)
     self.assertEqual(len(state['state'][0]), len(state['state'][1]) + 1)
Esempio n. 4
0
 def test_init_game(self):
     game = Game()
     state, current_player = game.init_game()
     self.assertEqual(len(game.history), 0)
     self.assertEqual(current_player, 0)
     self.assertEqual(game.winner['dealer'], 0)
     self.assertEqual(game.winner['player'], 0)
     self.assertEqual(len(state['state'][0]), len(state['state'][1]) + 1)
Esempio n. 5
0
 def test_step_back(self):
     game = Game()
     state, _ = game.init_game()
     init_hand = state['state'][0]
     game.step('hit')
     game.step_back()
     test_hand = game.get_state(0)['state'][0]
     self.assertEqual(init_hand, test_hand)
     self.assertEqual(len(game.history), 0)
Esempio n. 6
0
 def test_step_back(self):
     game = Game(allow_step_back=True)
     game.configure(DEFAULT_GAME_CONFIG)
     state, _ = game.init_game()
     init_hand = state['state'][0]
     game.step('hit')
     game.step_back()
     test_hand = game.get_state(0)['state'][0]
     self.assertEqual(init_hand, test_hand)
     self.assertEqual(len(game.history), 0)
     success = game.step_back()
     self.assertEqual(success, False)
Esempio n. 7
0
 def test_step(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     game.init_game()
     next_state, next_player = game.step('hit')
     self.assertEqual(next_player, 0)
     if game.players[0].status != 'bust':
         self.assertEqual(len(game.dealer.hand), len(next_state['state'][1])+1)
     else:
         self.assertEqual(len(game.dealer.hand), len(next_state['state'][1]))
     next_state, _ = game.step('stand')
     self.assertEqual(len(next_state['state'][0]), len(game.players[0].hand))
Esempio n. 8
0
 def __init__(self, allow_step_back=False):
     ''' Initialize the Blackjack environment
     '''
     super().__init__(Game(allow_step_back), allow_step_back)
     self.rank2score = {
         "A": 11,
         "2": 2,
         "3": 3,
         "4": 4,
         "5": 5,
         "6": 6,
         "7": 7,
         "8": 8,
         "9": 9,
         "T": 10,
         "J": 10,
         "Q": 10,
         "K": 10
     }
     self.actions = ['hit', 'stand']
     self.state_shape = [2]
Esempio n. 9
0
 def __init__(self, config):
     ''' Initialize the Blackjack environment
     '''
     self.game = Game()
     super().__init__(config)
     self.rank2score = {
         "A": 11,
         "2": 2,
         "3": 3,
         "4": 4,
         "5": 5,
         "6": 6,
         "7": 7,
         "8": 8,
         "9": 9,
         "T": 10,
         "J": 10,
         "Q": 10,
         "K": 10
     }
     self.actions = ['hit', 'stand']
     self.state_shape = [2]
Esempio n. 10
0
 def test_get_num_players(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     num_players = game.get_num_players()
     self.assertEqual(num_players, 1)
Esempio n. 11
0
 def test_get_num_actions(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     num_actions = game.get_num_actions()
     self.assertEqual(num_actions, 2)
Esempio n. 12
0
 def test_get_player_num(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     player_num = game.get_player_num()
     self.assertEqual(player_num, 1)
Esempio n. 13
0
 def test_get_action_num(self):
     game = Game()
     game.configure(DEFAULT_GAME_CONFIG)
     action_num = game.get_action_num()
     self.assertEqual(action_num, 2)
Esempio n. 14
0
 def test_get_player_num(self):
     game = Game()
     player_num = game.get_player_num()
     self.assertEqual(player_num, 1)
Esempio n. 15
0
 def test_get_state(self):
     game = Game()
     game.init_game()
     self.assertEqual(len(game.get_state(0)['state'][1]), 1)
     game.step('stand')
     self.assertGreater(len(game.get_state(0)['state'][1]), 1)
Esempio n. 16
0
 def test_get_action_num(self):
     game = Game()
     action_num = game.get_action_num()
     self.assertEqual(action_num, 2)