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:
movement = stack.pop()
fatherNode = fatherStack.pop()
else:
fatherNode = fatherStack.pop()
movement = stack.pop