python代码游戏反恐精英和报告_敲代码学Python:CS188之吃完所有角落的豆豆

先上视频:吃完所有角落的豆豆视频演示https://www.zhihu.com/video/1177971208993325056

简单说一下我的思路:

搜索状态的表达是搜索算法中的重要部分,在本题中,为了记录下吃豆人的吃豆过程,我把吃豆人所经过的包含豆豆的坐标放在搜索状态中,这样就可以从搜索状态中判定它是否完成了当前地图的任务目标。

贴代码吧:

class CornersProblem(search.SearchProblem):

"""This search problem finds paths through all four corners of a layout.You must select a suitable state space and successor function"""

def __init__(self, startingGameState):

"""Stores the walls, pacman's starting position and corners."""

self.walls = startingGameState.getWalls()

self.startingPosition = startingGameState.getPacmanPosition()

top, right = self.walls.height-2, self.walls.width-2

self.corners = ((1,1), (1,top), (right, 1), (right, top))

for corner in self.corners:

你可能感兴趣的:(python代码游戏反恐精英和报告_敲代码学Python:CS188之吃完所有角落的豆豆)