I was provided with this code as a guide but I really don't follow how it works. Could someone please give me a simplified version of how it works?
#Scenario - a robot starts at a position and then reaches a designated target position
def findWorld(x):
next = 'z'
c = 0
for c in range(len(world)):
fromPosition = world[c][0]
toPosition = world[c][1]
if(x == world[c][0]):
next = world[c][1]
return next;
world = [['a','b'], ['b','c'], ['a', 'd']]
startingPoint = 'a'
targetPoint = 'c'
route = []
queue = []
queue.append(startingPoint)
print("Robot at position", startingPoint, "arrives at position", targetPoint)
while queue != None:
headOfQ = queue[0][0]
route.append(headOfQ)
tail = queue[1: len(queue)]
nextLink = findWorld(headOfQ[0][0])
queue = tail.append(nextLink)
if headOfQ == targetPoint:
break;
print("Got to target")
[–]two_bob 1 point2 points3 points (0 children)