Lesson 11: Escape the cave
Lost in the cave
- The robot is deep in a cave. It cannot see the whole cave, only the wall in front of it.
- There is a green exit somewhere. The tunnels are different on every map, so a fixed route never works.
- The robot has to look, then decide, one square at a time. Each square is 250 mm.
Words for this lesson
| Word | Meaning |
|---|---|
| tunnel | a long, narrow way through rock |
| maze | tunnels that split, with dead ends |
| dead end | a tunnel that is closed at the end |
| open / closed | there is room ahead / a wall is close in front |
| rule | a short plan the robot follows again and again |
Is the way open?
from vexcode_vr import *
def main():
for i in range(4):
if front_distance.get_distance(MM) > 200:
brain.print("open")
else:
brain.print("closed")
brain.new_line()
drivetrain.turn_for(RIGHT, 90, DEGREES)
vr_thread(main)
- The robot looks in all four directions. In a square of the cave, a wall in front is only about 35 mm away.
- When the next square is free, the distance is more than 280 mm. So 200 mm is a good line between open and closed.
The right-hand rule
- Put your right hand on the wall of a maze and never take it off. Walk, and you will reach the exit.
- For the robot this is three steps in every square:
- Turn right.
- While the way ahead is closed, turn left.
- Drive one square.
- It is not the shortest way. But it never goes round in a circle, and it comes back out of every dead end.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
The robot is in a dark tunnel. Drive to the green exit. The tunnel bends, and it is different on each map. In a loop: if the way ahead is open (more than 200 mm), drive one square (250 mm). If not, turn right and look again. If that way is closed too, turn left 180°.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 4/5 · 280 monedas + un pequeño bono en el primer intento de hoy
Now the tunnels split, and some end in a dead end. The tunnel program can go round in circles here. Use the right-hand rule: in every square, first turn right. While the way ahead is closed, turn left. Then drive one square. Stop on the green exit.
Haz clic en Ejecutar para ver la salida aquí.