25 lines
778 B
Python
25 lines
778 B
Python
from succ import succ as successors
|
|
from queue import PriorityQueue
|
|
|
|
|
|
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
|