【发布时间】:2018-06-16 22:45:54
【问题描述】:
我一直致力于伯克利的 Pacman 项目,用于他们的人工智能。课程。我遇到了一个问题,要弄清楚如何找到一条路径,以便 pacman 触及 pacman 板的所有四个角。它使用一般的广度优先搜索算法。它只在有一个目标状态时返回一条路径,而不是四个。
这个特定问题的项目说明:
在角落迷宫中,有四个点,每个角落一个。我们新的搜索问题是找到穿过迷宫的最短路径,触及所有四个角(迷宫是否真的有食物)。请注意,对于一些像 tinyCorners 这样的迷宫,最短路径并不总是首先到达最近的食物!提示:通过 tinyCorners 的最短路径需要 28 步。
在 searchAgents.py 中实现 CornersProblem 搜索问题。您将需要选择一个状态表示来编码检测是否已到达所有四个角所需的所有信息。
BFS:
fringe = util.Queue()
fringe.push( (problem.getStartState(), [], 0) )
visited = set()
while not fringe.isEmpty():
curState, curAction, curCost = fringe.pop()
if curState in visited:
continue
visited.add(curState)
if problem.isGoalState(curState):
return curAction
for state, action, cost in problem.getSuccessors(curState):
fringe.push( (state, curAction + [action], cost ) )
return []
util.raiseNotDefined()
搜索代理开始状态:
def getStartState(self):
"""
Returns the start state (in your state space, not the full Pacman state
space)
"""
"*** YOUR CODE HERE ***"
return self.startingPosition
util.raiseNotDefined()
SearchAgent 目标状态
"""
Returns whether this search state is a goal state of the problem.
"""
"*** YOUR CODE HERE ***"
// TODO
util.raiseNotDefined()
我坚持返回目标状态,以便测试通过。目前,该函数返回:
*** FAIL: test_cases/q5/corner_tiny_corner.test
*** Corners missed: [(1, 1), (1, 6), (6, 1), (6, 6)]
*** Tests failed.
或者我只返回 4 个角中的 1 个。
【问题讨论】:
-
...这是什么编程语言?
-
python v 2.7.12