This activity belongs to the GeoGebra book Attractive projects. 2D project: create robots that adapt to the environment. In this last example, the robot (green point) does not have any information about the shape of the labyrinth. It only detects if there is free space to its right (in which case it turns to the right to stick to the right wall) or if there is an obstacle in front (in which case it turns to the left). This simple rule is enough to not detach from its right wall and get out of the labyrinth (although not in the shortest possible way). To do this, two instructions are enough in the script of the robot:
  • SetValue(v, If(dPD> 8, vn, If(dPA <2, -vn, v)))
  • SetValue(P, P + v)
A second robot (yellow point) does the same changing the right for the left. Between the two, they go through the entire labyrinth, but the green point goes less path to get to the exit. Note that the walls of the labyrinth actually make up two polygons with many sides, separated by a path. The green point circles one of the polygons in a clockwise direction, while the yellow point circles the other polygon in a counterclockwise direction. Both travel (in opposite directions) the path that separates both polygons (bicolor trace), which is the shortest route to go from the entrance to the exit of the labyrinth.