Inteligentna_smieciarka/bfs.py

23 lines
775 B
Python
Raw Normal View History

2023-04-19 22:12:02 +02:00
from succ import succ as successors
2023-05-03 12:07:13 +02:00
def bfs(istate, goalx, goaly, passedFields):
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-05-03 12:07:13 +02:00
element = successors(state, passedFields)
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)
2023-04-21 14:31:17 +02:00
if val not in explored and value not in fringe:
2023-04-19 22:12:02 +02:00
fringe.append(value)
return False