DSA Master · Algorithms on a grid

Rover Protocol

You are mission control for Vega, a survey rover on Mars. Write the JavaScript that drives it. Every mission is tested on several maps it has never seen, so only a real algorithm gets it home.

Mission 01 · First Driveeasy

Touchdown. A sample is waiting south-east of the base.

Drive to the sample and collect() it. The rover faces east, and each move() is one cell.

  • Collect every sample
  • Battery: plenty
  • 1 test map
Rover API⌄
  • rover.move()Drive one cell forward. Costs 1 energy (3 on sand). Hitting a rock or the edge ends the mission.
  • rover.turnLeft() / rover.turnRight()Turn 90° in place. Free.
  • rover.collect() → mineralPick up the sample under the rover. Returns its mineral, like 'ice' or 'iron'. Throws if there is none.
vega/mission.jsctrl + enter to run
012345601234BASE
pos (1, 1) · facing E