Esempio n. 1
0
    def stateless_act(self, action):
        '''
        Executes an action for the current player on a copy of the state
        Returns:
            a new GoState with the new board and the player switched
        '''
        try:
            new_board = self.board.play(_action_to_coord(self.board, action),
                                        self.color)
        except pachi_py.IllegalMove:
            # Will do pass turn on invalid move
            action = _pass_action(self.board_size)
            new_board = self.board.play(_action_to_coord(self.board, action),
                                        self.color)

        new_state = GoState(board_size=self.board_size,
                            color=pachi_py.stone_other(self.color),
                            board=new_board)

        new_state.last_action_2 = new_state.last_action
        new_state.last_action = action

        new_state._new_state_checks()

        return new_state
Esempio n. 2
0
def make_random_board(size):
    b = pachi_py.CreateBoard(size)
    c = pachi_py.BLACK
    for _ in range(0, 50):
        b = b.play(np.random.choice(b.get_legal_coords(c)), c)
        c = pachi_py.stone_other(c)
    return b
Esempio n. 3
0
def make_random_board(size):
    b = pachi_py.CreateBoard(size)
    c = pachi_py.BLACK
    for _ in range(0, 50):
        b = b.play(np.random.choice(b.get_legal_coords(c)), c)
        c = pachi_py.stone_other(c)
    return b
Esempio n. 4
0
    def _act(self, action, history):
        """ Executes an action for the current player """

        self.board = self.board.play(_action_to_coord(self.board, action), self.player_color)
        board = self.board.encode()
        for color in [0,1]:
            history[color] = np.roll(history[color], 1, axis=0)
            history[color][0] = np.array(board[color])
        self.player_color = pachi_py.stone_other(self.player_color)
Esempio n. 5
0
    def act(self, action):
        '''
        Executes an action for the current player

        Returns:
            a new GoState with the new board and the player switched
        '''
        return GoState(
            self.board.play(_action_to_coord(self.board, action), self.color),
            pachi_py.stone_other(self.color))
Esempio n. 6
0
File: go.py Progetto: AniChikage/gym
    def act(self, action):
        '''
        Executes an action for the current player

        Returns:
            a new GoState with the new board and the player switched
        '''
        return GoState(
            self.board.play(_action_to_coord(self.board, action), self.color),
            pachi_py.stone_other(self.color))
Esempio n. 7
0
    def _act(self, action, history):
        """ Executes an action for the current player """

        self.board = self.board.play(_action_to_coord(self.board, action), self.player_color)
        self.steps.append(action)
        board = self.board.encode()
        color = self.player_color - 1
        a = int(HISTORY/2-1)
        for i in range(a):
            self.history[(a-i)*2+color] = self.history[(a-1-i)*2+color]  
#         self.history = np.roll(history, 1, axis=0)
        self.history[color] = np.array(board[color])
        self.player_color = pachi_py.stone_other(self.player_color)
Esempio n. 8
0
    def act(self, action):
        '''
        Executes an action for the current player

        Returns:
            1) a new CustomGoState with the new board and the player switched
            2) a move log item of {action taken, by who}
        '''
        #        print(action, self.color, _action_to_coord(self.board, action))
        coord = _action_to_coord(self.board, action)
        #            self.moves_log.append({'action':action, 'board':self.state.board,
        #                'color':self.state.color})
        return CustomGoState(self.board.play(coord, self.color),\
                        pachi_py.stone_other(self.color)), coord
Esempio n. 9
0
    def act(self, action):
        '''
        Executes an action for the current player
        '''

        try:
            self.board = self.board.play(_action_to_coord(self.board, action),
                                         self.color)
        except pachi_py.IllegalMove:
            # Will do pass turn on disallowed move
            action = _pass_action(self.board_size)
            self.board = self.board.play(_action_to_coord(self.board, action),
                                         self.color)

        self.color = pachi_py.stone_other(self.color)
        self.current_player = -self.current_player

        self.last_action_2 = self.last_action
        self.last_action = action

        self._new_state_checks()  # Updates self.game_over and self.winner