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)
|
|
|
|
explored.append(state)
|
|
|
|
for value in element :
|
2023-04-19 23:51:24 +02:00
|
|
|
if value not in explored and value not in fringe:
|
2023-04-19 22:12:02 +02:00
|
|
|
fringe.append(value)
|
|
|
|
return False
|