Skip to content

At-home challengeGrades 6–12 25 min

Debug the maze algorithm

A pencil-and-paper puzzle for teens: a maze robot's code has three bugs. Trace it, find them and fix them.

By Maple Mind Academy instructors · Updated

Maze solving is the heart of RoboCupJunior Rescue Maze, the league where Maple Mind students won two awards in 2026. Before any robot drives a maze, the algorithm has to survive a pencil trace.

You'll need

  • Paper and pencil
  • The maze and code below

Steps

  1. 1

    Draw a 5 × 5 grid. Mark START bottom-left and EXIT top-right. Add walls anywhere you like.

  2. 2

    Read the robot's code: while not at exit: if wall ahead: turn right; else: move forward.

  3. 3

    Trace it square by square. Where does it get stuck in a loop?

  4. 4

    Bug 1: it never checks the left wall. Bug 2: it can spin forever in a dead end. Bug 3: it has no way to know it already visited a square.

  5. 5

    Fix it with the right-hand rule, then add a 'visited' mark. Trace again.

Level up

  • → Count the moves. Can you make it shorter?
  • → Write it in real Python with a 2D list for the maze.
  • → Research: what is the flood-fill algorithm used in Micromouse and RoboCupJunior Rescue Maze?

Want an instructor to take it from here?

Live online robotics classes for K–12, placed by age and skill.

Find my class