示例#1
0
 def test_is_terminal_returns_false_for_non_terminal_states(
         self, size, actions_to_binary, win_bitmasks, state, mocker):
     rows, columns = size
     mock_game = mocker.MagicMock(rows=rows,
                                  columns=columns,
                                  _actions_to_binary=actions_to_binary,
                                  _win_bitmasks=win_bitmasks)
     assert NoughtsAndCrosses.is_terminal(mock_game, state) is False
示例#2
0
from alphago.player import MCTSPlayer
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)