Inteligentna_smieciarka/bfs.py
Maksymilian Mikołajczak 674393a4d9 added priority for blocks
2023-05-03 12:07:13 +02:00

23 lines
775 B
Python

from succ import succ as successors
def bfs(istate, goalx, goaly, passedFields):
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, passedFields)
explored.append((state.xpos, state.ypos, state.orientation))
for value in element :
val = (value.xpos, value.ypos, value.orientation)
if val not in explored and value not in fringe:
fringe.append(value)
return False