Giving Instructions: Algorithms

Primary schoolComputer ScienceA deterministic grid robot executing forward and quarter-turn instructions, with fixed start and goal cells and editable obstacles

Build a program, then step the robot toward G. Drag a board tile upward to build a wall or downward to remove it.

3D

Drag the apparatus to adjust it. Drag the background to rotate. Scroll to zoom.

Measurement notebook

Change the setup, test a prediction and save the result. Up to 12 snapshots are kept.

About this experiment

Build a small program and test it on a three-dimensional board. The robot follows each instruction literally, making a blocked move or an incorrect turn visible. Compare an intended route with the actual execution trace, then edit the program and try again.

Learning goals

  • Translate a route into an ordered sequence of precise instructions.
  • Debug a program by inspecting position and direction after each step.
  • Explain how changing an obstacle changes a program outcome without changing its instructions.

How to use it

  1. 1Run the initial program and identify the first instruction that does not match your intended route.
  2. 2Rewind and use Step and Back to inspect the position after each instruction.
  3. 3Load Example route, predict its endpoint, then run to the goal.
  4. 4Drag a board tile upward to create an obstacle. Repair the route using the command buttons, then record the program and its result.

The model

Direction after a left turn
Direction after a right turn

Assumptions

  • The board has six rows and six columns. The robot begins at the lower left facing right; its goal is the upper right.
  • A forward instruction moves one cell. Left and right turn 90 degrees without moving. A collision or arrival at the goal ends execution.
  • The robot is an instruction interpreter, not a rigid-body physics simulation. Visual interpolation does not change discrete cell positions.

Try this in class

  1. Q1Why can the same instructions work on one board and fail after a wall is moved?
  2. Q2How could you write a shorter program if repetition commands were available?

Frequently asked questions

Does the robot find its own way?

No. It executes the supplied sequence exactly. Finding and correcting a route is the experiment.

What happens at a wall?

The robot stays in its last valid cell, marks the move blocked and stops the program.