MirrorEngine.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:go-NN 作者: TheDuck314 项目源码 文件源码
def pick_move(self, color):
        if not self.opponent_passed and self.last_opponent_play:
            mirror_x = self.board.N - self.last_opponent_play[0] - 1
            mirror_y = self.board.N - self.last_opponent_play[1] - 1
            if self.board.play_is_legal(mirror_x, mirror_y, color):
                return (mirror_x, mirror_y)

        enemy_stones = (self.board.vertices == flipped_color[color])
        our_stones = (self.board.vertices == color)
        rot_enemy_stones = np.rot90(enemy_stones, 2)

        play_vertices = np.logical_and(rot_enemy_stones, np.logical_not(our_stones))
        play_vertices =  np.logical_and(play_vertices, np.logical_not(enemy_stones))

        for x in xrange(self.board.N):
            for y in xrange(self.board.N):
                if play_vertices[x,y] and self.board.play_is_legal(x, y, color):
                    return (x,y)

        center = (self.board.N/2, self.board.N/2)
        if self.board[center] == Color.Empty and self.board.play_is_legal(center[0], center[1], color):
            return center

        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号