def test_current_player_returns_correct_player(self, player, state, mocker): mock_game = mocker.MagicMock() assert NoughtsAndCrosses.current_player(mock_game, state) == player
if __name__ == "__main__": nac = NoughtsAndCrosses() evaluator = create_trivial_estimator(nac.legal_actions) state = nac.INITIAL_STATE computer_player_no = np.random.choice([1, 2]) computer_player = MCTSPlayer(nac, evaluator, mcts_iters=2000, c_puct=0.5, tau=0.01) human_player_no = 1 if computer_player_no == 2 else 2 print("You are player: {}".format(human_player_no)) while not nac.is_terminal(state): player_no = nac.current_player(state) next_states = nac.legal_actions(state) if player_no == computer_player_no: action = computer_player.choose_action(state) computer_player.update(action) print("Taking action: {}".format(action)) else: action = None while action not in next_states: action_ix = int( input("Your move (0-8 reading " "across the board): ")) if 0 <= action_ix <= 8: action = nac.ACTION_SPACE[action_ix] computer_player.update(action) state = next_states[action]