Programming a Robot to get Through Through a Maze
activity
computational-thinking
instruction coding
debugging
Overview
This activity is to use instructions to guide a robot through a maze. Because the robot follows instructions literally, it’s a great way to teach the importance of precision in programming!
- The programmer builds a list of instructions using only the
UP,DOWN,LEFT, andRIGHTbuttons below. - Clicking on Run Robot allows you to see whether the instructions actually get the robot to the end of the maze. Remember, robots interpret things literally and they only follow instructions that are given to them. If the robot hits a wall, it will stop and report which instruction failed and where.
How to use this tool
- Choose a grid size and a seed, then click Generate Maze. The same seed + size always produces the same maze — great for giving every group an identical challenge, or for having students trade seeds with each other.
- Click
UP,DOWN,LEFT,RIGHTto build up the instruction list for the green robot (top-left) to reach the red goal (bottom-right). - Use Undo Last or Clear All to edit the instruction list.
- Click Save Instructions to download the list as a
.txtfile — this is the “program” the tester will run. - Click Load Instructions to load a saved
.txtfile (handy for swapping programs between groups). - Click ▶ Run Robot to test the instructions. Watch the robot move step-by-step. If it hits a wall, the wall is highlighted in red and a message explains exactly which instruction caused the problem.
- Click 🧭 Solve Maze to have the tool automatically compute a shortest instruction set and fill in the list — handy for showing an answer key or checking whether a shorter solution exists.
Start
Goal
Robot
Blocked wall
Instructions
Discussion questions for after the activity
- Which types of instructions (UP/DOWN/LEFT/RIGHT) were most often used in your group’s solution? Why do you think that is?
- What types of mazes required the most instructions to solve? Why do you think that is?
- Could you tell before running the program that an instruction would fail, just by looking at the maze?
- How did your group’s debugging process change once you could see exactly which step failed?
- What is the minimum number of instructions needed to solve your maze? How do you know you cannot do better than this minimum?
- How is this activity similar to, or different from, writing a program for a real robot? What are some of the challenges of programming a real robot that you did not encounter in this activity?