How a maze-solving AI learns

No coding or maths needed. Nobody tells the agent where to go. It tries things, gets rewards and penalties, and slowly works out the best route. This is called reinforcement learning.

1 · The cast

2 · Rewards: how it knows what's good

The agent's only aim is to collect as many points as it can.

3 · Explore or exploit?

At every step the agent flips a weighted coin:

The trail behind the agent uses these colours, so you can see which kind of decision made each part of the path. The chance of exploring is epsilon (ε). It starts high and shrinks every episode: curious at first, confident later.

4 · The memory: the Q-table

For every cell, the agent keeps four numbers: how good is up, right, down, left from here? That table is the Q-table. After each move it nudges one number toward what it just learned:

new Q = old Q + α × ( reward + γ × best next Q − old Q )

5 · Try it: step through learning yourself

This is a tiny 5×5 maze. Press step and read what happens. Turn on the heatmap and arrows to see the memory fill in.

Press step to take the agent's first move.

6 · Reading the lab

Heatmap — purple cells have low value, yellow-green cells have high value. Watch a bright glow spread backwards from the goal.

Fog — dotted cells have never been visited. The agent knows nothing about them.

Policy arrows — the move the agent would pick in each cell, if it never explored.

Learned route — the marching white line is the greedy route from the start. If it ends with a red ✕ the agent is stuck or looping.

Policy score — shortest possible length ÷ the learned route's length. 100% means a perfect route. While the route still dead-ends or loops, you only get a little partial credit (up to 25%) for how far along it got.

Cell inspector — hover or tap a cell to see its four Q-values.

7 · Graphs

8 · Experiments to run

Open the lab → Watch four personalities race →