def test_python_tic_tac_toe(self): # run this test to a Python-only game game = tic_tac_toe.TicTacToeGame() for _ in range(0, 100): # cannot use pyspiel's serialization since the python-only games don't # implement them self.sim_game(game, False)
def test_create(self): """Checks we can create the game and clone states.""" game = tic_tac_toe.TicTacToeGame() print(game.num_distinct_actions()) state = game.new_initial_state() clone = state.clone() print(state) print(clone)
def test_create(self): game = tic_tac_toe.TicTacToeGame() print(game.num_distinct_actions()) clone = game.clone() print(clone.num_distinct_actions()) state = game.new_initial_state() clone = state.clone() print(state) print(clone)
def test_random_game(self): # This is here mostly to show the API by example. # More serious simulation tests are done in python/tests/game_sim_test.py. # Those test the conformance to the API thoroughly. game = tic_tac_toe.TicTacToeGame() state = game.new_initial_state() while not state.is_terminal(): print(state) cur_player = state.current_player() legal_actions = state.legal_actions() action = np.random.choice(legal_actions) print("Player {} chooses action {}".format(cur_player, action)) state.apply_action(action) print(state) print("Returns: {}".format(state.returns()))
def test_cloned_state_matches_original_state(self): """Check we can clone states successfully.""" game = tic_tac_toe.TicTacToeGame() state = game.new_initial_state() state.apply_action(1) state.apply_action(2) clone = state.clone() self.assertEqual(state.history(), clone.history()) self.assertEqual(state.num_players(), clone.num_players()) self.assertEqual(state.move_number(), clone.move_number()) self.assertEqual(state.num_distinct_actions(), clone.num_distinct_actions()) self.assertEqual(state._cur_player, clone._cur_player) self.assertEqual(state._player0_score, clone._player0_score) self.assertEqual(state._is_terminal, clone._is_terminal) np.testing.assert_array_equal(state.board, clone.board)
def test_can_create_game_and_state(self): """Checks we can create the game and a state.""" game = tic_tac_toe.TicTacToeGame() state = game.new_initial_state() self.assertEqual(str(state), "...\n...\n...")
def _load_game(game_string): """Loads a game, including special-cases for Python-implemented games.""" if game_string == "python_tic_tac_toe": return tic_tac_toe.TicTacToeGame() else: return pyspiel.load_game(game_string)