def test_proceed_game(self): game = Game() game.init_game() while not game.is_over(): legal_actions = game.judge.get_legal_actions() action = np.random.choice(legal_actions) _, _ = game.step(action) self.assertEqual(game.actions[-1].action_id, score_player_1_action_id)
def test_step(self): game = Game() _, current_player = game.init_game() opponent_player = (current_player + 1) % 2 action = np.random.choice(game.judge.get_legal_actions()) self.assertIn(action.action_id, put_action_ids) # should be a put action _, next_player = game.step(action) if not game.is_over(): self.assertEqual(next_player, opponent_player) if not game.is_over(): action = np.random.choice(game.judge.get_legal_actions()) self.assertIn(action.action_id, get_action_ids) # should be a get action _, next_player = game.step(action) self.assertEqual(next_player, opponent_player) # keep turn to put card
def test_init_game(self): game = Game() state, current_player = game.init_game() opponent_player = (current_player + 1) % 2 self.assertEqual(len(game.round.move_sheet), 1) self.assertIn(current_player, [0, 1]) self.assertIn(game.round.dealer_id, [0, 1]) self.assertEqual(len(game.actions), 0) self.assertEqual(opponent_player, game.round.dealer_id) # opponent_player is dealer self.assertEqual(len(game.round.players[opponent_player].hand), 10) # dealer has 10 cards self.assertEqual(len(game.round.players[current_player].hand), 11) # current_player has 11 cards self.assertEqual(len(game.round.dealer.shuffled_deck), 52) self.assertEqual(len(game.round.dealer.stock_pile), 31) self.assertEqual(state['player_id'], current_player) self.assertEqual(len(state['hand']), 11)
def __init__(self, config): self.game = Game() super().__init__(config=config) self.state_shape = [5, 52] self.judge = GinRummyJudge(game=self.game) self.scorer = scorers.GinRummyScorer()
def test_get_state(self): game = Game() state, _ = game.init_game() self.assertEqual(len(state), 6)
def test_get_action_num(self): game = Game() action_num = game.get_action_num() self.assertEqual(action_num, 110)
def test_get_player_num(self): game = Game() player_num = game.get_player_num() self.assertEqual(player_num, 2)
def test_get_state(self): game = Game() state, current_player = game.init_game() self.assertEqual(len(state), 6)
def test_get_num_actions(self): game = Game() num_actions = game.get_num_actions() self.assertEqual(num_actions, 110)
def test_get_num_players(self): game = Game() num_players = game.get_num_players() self.assertEqual(num_players, 2)
def __init__(self, config): self.game = Game() super().__init__(config=config) self.state_shape = [5, 52]