python 小程序,实现简单的dfs算法
from game import Directions
from util import Stack
stack = Stack()
fatherStack = Stack()
moveDir = [] # record the pacman move direction
result = [] # the correct lines
temp = {}
startState = problem.getStartState() # start the position
moveStart = [startState, Directions.STOP, 0]
stack.push(moveStart)
fatherStack.push(moveStart)
flag = False
while True:
if stack.isEmpty():
print "can not find food"
if flag==False:
mo
Python实现深度优先搜索算法

本文介绍了一个使用Python编写的小程序,实现了深度优先搜索(DFS)算法。通过game模块获取方向,util模块的Stack类进行辅助,遍历并查找目标状态。在搜索过程中,记录 Pacman 的移动方向,并在找到目标状态时返回正确路径。
最低0.47元/天 解锁文章
2476

被折叠的 条评论
为什么被折叠?



