I have a problem concerning a labyrinth pathfinder I'm making. I have got a depth first solution, but i want a breadth first solution. This is the depth first:
def find_path(pathList):
if pathList[-1] == goal:
return pathList
for i in adjacent_passages(labyrinth, pathList[-1]):
if i not in pathList:
found_path = find_path(pathList + [i])
if found_path:
return found_path
And this is how "far" I've come on the breadth first problem:
def find_path_bf(pathL):
num = 0
for i in range(0, len(pathL)):
frontier[i] = adjacent_passages(labyrinth, pathL[i][-1])
for i in range(0, len(pathL)):
if pathL[i][-1] == goal:
return pathL[i]
for i in frontier:
if i not in pathL:
pathL[num].append(i)
num = num + 1
find_path_bf(pathL)
The labyrinth is a matrix of a labyrinth and adjacent_passages finds the adjacent squares :)