我在项目中实现了这一点(Pacman),但它根本就不动,似乎进入了一个无限循环或其他东西……有人能告诉我它有什么问题吗???我被困在这里好几天了。。。。。在
def depthLimitedSearch(problem, limit ):
explored = set()
node = problem.getStartState()
path = []
def recursive_DLS(node, problem, limit, path):
if node not in explored :
explored.add(node)
if problem.goalTest(node):
return path
elif limit == 0 :
return 'cutoff'
else:
cutoff_occurred = False
for successor in problem.getActions(node):
child = problem.getResult(node,successor) #next state
result = recursive_DLS(child ,problem, limit - 1, path)
if result == 'cutoff':
cutoff_occurred = True
elif result != None:
path.append(successor)
if cutoff_occurred:
return 'cutoff'
else:
return None
return recursive_DLS(node, problem, limit, path)
def iterativeDeepeningSearch(problem):
for depth in xrange(sys.maxint):
result = depthLimitedSearch(problem, 1)
if result is not 'cutoff':
return result
您总是将
1
的限制传递给depthLimitedSearch
:未使用
depth
。如果限制为1的搜索导致一个截止,这将迭代很长时间而不产生结果。在相关问题 更多 >
编程相关推荐