What's going on
1. Learning from rewards
Nobody shows Little Q the right way to go. This is reinforcement learning: the agent acts, the world responds, and a number called the reward says how that went. Here it is small and simple:
- +2 for reaching the exit
- −2 for getting caught by a mob
- +0.1 for a step that gets closer to the exit, −0.15 for one that doesn't
The small per-step rewards are reward shaping. Without them the only feedback would come at the very end of a run, and early on, when it's moving at random, it would almost never get there. The shaping tells it it's warm or cold on every step.
2. What it senses
It never sees the map. It gets 28 numbers about the four tiles around it, shown as the little four-node crosses on the left of the 3D view. There are seven questions, each asked once for up, right, down and left:
- open: can it step there?
- closer to exit: would that step shorten the shortest remaining route? Think of it as a sense of smell for the exit. The network still has to learn to trust it.
- mob on it, mob next to it, mob 2 away: how close the nearest danger is to that tile
- been there: has it already walked on that tile this run?
- last move: which way it just went
Because these features describe the world relative to where it's standing, the same small network works on every new map.
3. Q-values: how good is each move?
The network's four outputs are Q-values: its estimate of the total future reward it will collect after making that move. That isn't just the next step, it's everything after, with later rewards counting a little less (each step ahead is discounted by 0.95). It simply takes the move with the highest Q. You can see the live values under the network, and the arrows on the map show which move it would choose from every tile right now.
Learning comes from the Bellman equation. After a move, the network compares its prediction with what it actually got plus its own estimate for where it ended up:
Q(here, move) ← reward + 0.95 × max Q(next tile, any move)
The gap between the two is the error. Backpropagation nudges every weight to shrink it: the gold sparks in the 3D view run backwards along the weights that changed most. Do this thousands of times and the value of reaching the exit slowly flows backwards through the map, one step at a time, until the arrows point the right way from everywhere.
4. The tricks that make it work
- Exploration (ε-greedy). At first it moves completely at random, then less and less, bottoming out at 3%. If it always took the move it currently thinks is best, it would never discover anything better. The "random move" badge shows when it's exploring.
- Experience replay. Every step goes into a memory of up to 30,000 moments, and each update trains on 32 picked at random. Consecutive steps are almost identical, and learning only from them makes the network lurch around.
- A target network. The "estimate for where it ended up" comes from a second copy of the network that is only refreshed every 300 steps. Otherwise the network is chasing its own moving tail.
- Double DQN. The live network picks the next move but the frozen copy scores it. Using the same network for both makes it systematically over-optimistic.
5. Things to try
- Hit Turbo for twenty seconds, then drop back to 1× and watch how differently it moves.
- Drag the Mobs slider to 10. Success rate drops and route efficiency falls, because the shortest route is no longer the safest one and it has to learn to go around.
- Set mobs to 0 and reset the brain: with nothing to dodge, it finds near-perfect routes (about 97% efficient) as soon as it stops exploring, after a few thousand steps.
- Watch the arrows near a slime. They bend away from it, and that's the network trading a longer route against the risk of losing everything.
The size of it
28 → 16 → 12 → 4 with ReLU: 688 weights plus 32 biases. That's the whole brain. Every connection in the 3D view is a real weight, drawn brighter the bigger it is. It's plain JavaScript with no ML library. It's a pocket-sized version of DQN, the algorithm DeepMind used in 2015 to learn Atari games straight from the screen.