How to Solve Any Maze: The Wall-Follower Rule and Beyond

Maze
Maze - fresh randomly generated mazes, one screen, no time limit.

Every maze you have ever solved has a guaranteed solution built into its structure. You do not need luck, spatial genius or a good memory - you need one rule, and then one upgrade for the cases where that rule breaks.

The wall-follower rule

Pick a wall - your left or your right - and keep one hand on it. Walk forward whenever you can, turn to keep contact with that wall at every junction, and never let go. That is the entire method.

  1. Place your left hand on the wall as you enter.
  2. Walk forward until you hit a junction or a dead end.
  3. At every opening, turn left if you can; otherwise go straight; otherwise turn right.
  4. Never lift your hand from the wall. Repeat until you reach the exit.

When wall-following fails

The rule breaks the moment the maze contains a loop that is not connected to the wall you are following, or when the goal sits in the middle of an open area rather than on the outer boundary. Follow the left wall around a detached island and you will simply circle that island forever, arriving back where you started without ever seeing the exit.

The upgrade: the Pledge algorithm

Named after the mathematician who described it, this handles the looping mazes that defeat plain wall-following. It adds a single idea: keep track of how far you have turned.

  1. Choose a direction and walk straight toward the goal, ignoring side passages.
  2. When you hit a wall, start wall-following and keep a running count of your turns: count +1 for each right turn and -1 for each left turn.
  3. Keep following the wall until your turn count returns to zero AND you are facing your original direction.
  4. At that point you are guaranteed to be past the obstacle. Stop wall-following and resume walking straight toward the goal.

Reading a maze before you move

  • Dead ends are cheap to spot: any corridor that branches from a junction and immediately narrows is almost always short.
  • In mazes drawn on a grid, the exit is very often on the outer boundary. Walking the perimeter first is a legitimate opening move.
  • Long straight corridors that span most of the maze usually connect to something important - shortcuts rarely meander.
  • Do not backtrack randomly. If you must retreat, retreat all the way to the last junction where you had an untried option.

Pick the left-hand rule for your next run and use it deliberately, even when you can see a shortcut. Once the habit is automatic you will start noticing the structure of mazes rather than guessing at them, and that is when they stop being hard.