我把它实现到项目中(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
答案 0 :(得分:0)
您总是将1
限制为depthLimitedSearch
:
for depth in xrange(sys.maxint):
result = depthLimitedSearch(problem, 1)
未使用depth
。如果使用限制1的搜索导致截止,这将迭代很长时间而不会产生结果。