I have a homework in python, where i am supposed to make a "robot" get from the start to the finish, and return the path to the goal. I have the robot searching, but i want the list to just show the path from start to finish. Right now the pathList returns all visited squares.. and also, when it comes to the goal it doesn't stop, just continue with the other nodes. What am i missing?
def find(labyrinth, robotPos, pathList = []):
frontier = adjacent_passages(labyrinth, robotPos)
pathList.append(robotPos)
if len(frontier) == 1:
print("Corner")
return []
for i in range(0, len(frontier)):
if frontier[i] == goal:
pathList.append(frontier[i])
return pathList
for i in range(0, len(frontier)):
if frontier[i] not in pathList:
pathList.append(frontier[i])
if (find(labyrinth, frontier[i], pathList) == []):
pathList.pop()
return pathList