Inteligentna_smieciarka/bfs.py
Mateusz Szlachetka fc588a4ad5 fixed search
2023-04-20 10:01:48 +02:00

23 lines
723 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.xpos, state.ypos, state.orientation))
for value in element :
val = (value.xpos, value.ypos, value.orientation)
if val not in explored:
fringe.append(value)
return False