示例#1
0
文件: Players.py 项目: LEXJeoen/Chess
 def select_move(self, game_state):
     """Choose a random valid move that preserves our own eyes."""
     candidates = []
     for r in range(1, game_state.board.num_rows + 1):
         for c in range(1, game_state.board.num_cols + 1):
             candidate = Point(row=r, col=c)
             if game_state.is_valid_move(Move.play(candidate)) and \
                     not is_point_an_eye(game_state.board,
                                         candidate,
                                         game_state.next_player):
                 candidates.append(candidate)
     if not candidates:
         return Move.pass_turn()
     return Move.play(random.choice(candidates))
示例#2
0
文件: goGame.py 项目: LEXJeoen/Chess
    def legal_moves(self):  # 所有合法的操作
        moves = []
        for row in range(1, self.board.num_rows + 1):
            for col in range(1, self.board.num_cols + 1):
                move = Move.play(Point(row, col))
                if self.is_valid_move(move):
                    moves.append(move)

        moves.append(Move.pass_turn())
        moves.append(Move.resign())
        moves.append(Move.restart())
        moves.append(Move.turn_back())

        return moves
示例#3
0
文件: Players.py 项目: LEXJeoen/Chess
    def select_move(self, game_state):
        """Choose a random valid move that preserves our own eyes."""
        dim = (game_state.board.num_rows, game_state.board.num_cols)
        if dim != self.dim:
            self._update_cache(dim)

        idx = np.arange(len(self.point_cache))
        np.random.shuffle(idx)
        for i in idx:
            p = self.point_cache[i]
            if game_state.is_valid_move(Move.play(p)) and \
                    not is_point_an_eye(game_state.board,
                                        p,
                                        game_state.next_player):
                return Move.play(p)
        return Move.pass_turn()