Inteligentna_smieciarka/bfs.py

23 lines
723 B
Python
Raw Normal View History

2023-04-19 22:12:02 +02:00
from succ import succ as successors
2023-04-19 23:51:24 +02:00
def bfs(istate, goalx, goaly):
2023-04-19 22:12:02 +02:00
fringe = [istate]
explored = []
2023-04-19 23:51:24 +02:00
steps = []
2023-04-19 22:12:02 +02:00
while(fringe):
state = fringe.pop(0)
2023-04-19 23:51:24 +02:00
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
2023-04-19 22:12:02 +02:00
element = successors(state)
2023-04-20 10:01:48 +02:00
explored.append((state.xpos, state.ypos, state.orientation))
2023-04-19 22:12:02 +02:00
for value in element :
2023-04-20 10:01:48 +02:00
val = (value.xpos, value.ypos, value.orientation)
if val not in explored:
2023-04-19 22:12:02 +02:00
fringe.append(value)
return False