Inteligentna_smieciarka/bfs.py
2023-04-19 23:51:24 +02:00

22 lines
649 B
Python

from succ import succ as successors
def bfs(istate, goalx, goaly):
fringe = [istate]
explored = []
steps = []
while(fringe):
state = fringe.pop(0)
if state.xpos == goalx and state.ypos == goaly:
steps.insert(0, state)
while(state.parent != None):
state = state.parent
steps.insert(0, state)
return steps
element = successors(state)
explored.append(state)
for value in element :
if value not in explored and value not in fringe:
fringe.append(value)
return False