def __init__(self, allow_step_back=False): super().__init__(Game(allow_step_back), allow_step_back) self.action_id = card_encoding_dict self.de_action_id = { self.action_id[key]: key for key in self.action_id.keys() } self.state_shape = [6, 34, 4]
def test_step(self): game = Game() state, _ = game.init_game() action = np.random.choice(game.get_legal_actions(state)) state, next_player_id = game.step(action) current = game.round.current_player self.assertLessEqual(len(state['current_hand']), 14) self.assertEqual(next_player_id, current)
def __init__(self, config): self.game = Game() super().__init__(config) self.action_id = card_encoding_dict self.de_action_id = { self.action_id[key]: key for key in self.action_id.keys() } self.state_shape = [6, 34, 4]
def test_step_back(self): game = Game(allow_step_back=True) state, player_id = game.init_game() action = np.random.choice(game.get_legal_actions(state)) game.step(action) game.step_back() self.assertEqual(game.round.current_player, player_id) self.assertEqual(len(game.history), 0) success = game.step_back() self.assertEqual(success, False)
def test_get_payoffs(self): game = Game() state, _ = game.init_game() while not game.is_over(): actions = game.get_legal_actions(state) action = np.random.choice(actions) state, _ = game.step(action) total_cards = len(state['current_hand']) self.assertLessEqual(total_cards, 14) win = game.is_over() self.assertEqual(win, True)
def test_get_player_num(self): game = Game() num_player = game.get_player_num() self.assertEqual(num_player, 4)
def test_get_legal_actions(self): game = Game() state, _ = game.init_game() actions = game.get_legal_actions(state) for action in actions: self.assertIn(action, state['current_hand'])
def test_get_player_id(self): game = Game() _, player_id = game.init_game() current = game.get_player_id() self.assertEqual(player_id, current)
def test_init_game(self): game = Game() state, _ = game.init_game() total_cards = list(state['current_hand']) self.assertGreaterEqual(len(total_cards), 14)
def test_get_action_num(self): game = Game() action_num = game.get_action_num() self.assertEqual(action_num, 38)
def test_get_num_players(self): game = Game() num_players = game.get_num_players() self.assertEqual(num_players, 4)
def test_get_num_actions(self): game = Game() num_actions = game.get_num_actions() self.assertEqual(num_actions, 38)