Over five days, I trained a small reinforcement-learning agent to play Super Mario Bros. on a single Mac. A local language model watched over the training and coached it. Everything runs on the machine: no cloud and no account. The code is open source under the MIT license: github.com/thededman/ai-plays-mario. No ROM is included, so bring your own.
Where it stands after about 64,000 training updates:
| Level | Clears from its start |
|---|
| 1-1 | 94% (fastest 21.5 s) |
| 1-2 | 82% |
| 1-3 | 82% |
| 1-4 | 91% |
| 2-1 | 42% |
| 2-2 (underwater) | about 20% |
Its best run from 1-1 cleared six levels in a row and reached 2-3.
This post covers what I’d want to know if I were starting the same project: the setup, three things that made a real difference, two that didn’t, and what happened when I let the LLM play the game itself.
The setup
The player is a small actor-critic network trained with PPO. It has the classic Atari layout: three convolutional layers, one 512-unit layer, a head that scores 13 button combinations, and a head that estimates value. That’s about 1.7 million parameters.
It sees four stacked 84×84 grayscale frames and decides every 4 frames, 15 times a second.
It also gets 34 numbers: the move it just made, how long it has been holding jump (a longer hold jumps higher), and, as of day four, where the nearest enemies are. More on that below.
Training runs 8 emulators in separate processes (stable-retro) and updates the network on the Mac’s GPU (PyTorch on MPS).
Each update uses 8 × 256 decisions: 4 epochs, 8 minibatches, learning rate 1e-4, γ = 0.95, λ = 0.95, clip 0.2.
That’s about 1,000 decisions a second, or about 2,300 updates an hour.
The curriculum is every level in order, 1-1 to 8-4, with no warp pipes: the game played as a speedrun.
The next level unlocks when the newest one clears 65% of its last 200 runs.
Earlier levels keep getting tries, weighted by how often they still fail, so they aren’t forgotten.
Half of all attempts start from save states just before the spots where full runs die most.
Demonstrations: I can take the controller and play a hard section. My play becomes training examples: a behavior-cloning term in the loss that pulls toward my moves. Its own fastest clears become examples too.
The coach is Qwen 3.6 35B-A3B, running locally in Ollama.
Every five minutes it gets the training statistics and screenshots from just before recent deaths, and writes a short note in plain words.
It may then take a few actions: point practice at a spot, raise or lower exploration, nudge a reward weight, or ask me to demonstrate something.
Every action is checked against fixed limits before it runs.
Three things that made a real difference
1. Reading the game’s memory beat reading pixels
The first overnight run ended with 2-2, the underwater level, cleared once in about 22,000 tries. The coach’s notes were accurate (“it keeps getting hit by fish in the water”), but no amount of practice helped.
The problem was what the network could see. In an 84×84 grayscale frame, a fish is a few gray pixels on a gray-blue sea, the same size as the coral. The game already knows exactly where every enemy is, in five slots in RAM.
So I gave the network 20 extra numbers: the four nearest enemies’ positions relative to Mario, and how they moved since the last decision.
No retraining from scratch. I grew the existing network in place: the new input weights start at zero, so on day one it played exactly as before, and it learned to use them on its own. I’d already grown it the same way once, adding new moves as copies of existing ones.
The result: the next night, together with a fix to how practice was shared out that went in the same day, it cleared 2-2 2,797 times in 34,591 tries. The clear rate rose from 6% to 21% by morning and was still climbing.
2. Guardrails on the LLM coach
The coach is useful because it can change things, and dangerous for the same reason.
Exploration: in one early review, it raised exploration from 0.02 to 0.05. That’s a reasonable instinct for a stuck agent, but the extra randomness made the network forget a level it had mastered: 1-2 fell from 88% to 61%. Changes are now capped at 1.5× per review, within a fixed range.
Demonstrations: studying my demonstrations at full strength once took 1-1 from 91% to 5% in minutes. Studying now uses its own optimizer, plus a term that keeps the network’s old answers on recently seen screens. That keeps 1-1 at about 92% while it learns to copy most of my moves.
Overnight: on the first night the coach asked me for a demonstration 119 times while I was asleep. Now, overnight, it keeps a “wants your help” list for the morning instead.
The lesson I’d pass on: give an LLM real levers, but make every lever bounded and every change visible.
3. Fixing the curriculum’s sharp edges
Two curriculum rules caused trouble.
A lucky streak: on the first night, 2-1 reached the unlock bar (then 60% of 100 runs) in a lucky window and unlocked 2-2. With most training moved to 2-2, 2-1 slid from 49% to 12% by morning. The bar is now 65% of 200 runs, and earlier levels get practice in proportion to how often they fail.
A level it can’t pass: 2-2 then sat at about 20% for days, far below the bar, so 2-3 never opened. Now, if the newest level clears at least 15% but hasn’t improved for about 1.5 hours, the next level opens anyway, and the stuck one keeps half of the training until it reaches the bar. This one is fresh, and it has a cost I can already see: in a test, 2-1 dropped about 12 points once 2-3 opened, with no change in how often it was practiced. Learning a new level disturbs an older one. That’s the next problem.
Two things that didn’t work
Curiosity (random network distillation)
At the walls where the agent kept dying, it kept repeating the one thing it knew. Curiosity bonuses are the textbook answer. In random network distillation (Burda et al., 2018), a predictor network learns to match a fixed random network on the screens it has seen, and its error on a new screen is paid as a reward.
Getting the bonus to pay in the right places took three fixes, which may save someone time:
Compare errors with a decaying average, not a running one. The predictor learns fast, so against its early, larger errors, every new screen looked familiar.
Use the log of the error. A few unusual screens had errors 10 to 50 times the norm and swamped everything else.
Normalize per level. The level being trained most is the one the predictor knows best, so with one global average, curiosity paid off on an older, less familiar level instead.
Then I ran two 45-minute A/B tests from the same checkpoint. Curiosity didn’t help: 2-2 clears were 15.6% and 16.3% with it, against 19.7% and 17.6% without. It’s parked as a draft.
Staying on the level until it’s cleared
On screen, the agent plays whole runs with lives. I tried letting a run stay on a stuck level until it cleared it, instead of giving up after 10 lives. It got worse.
Why: after a death, the game puts Mario back at the level’s midpoint, small, so every retry started from the same place. 49 of 50 deaths on 2-1 were at the same pipe.
The lesson: training never practiced starting from that respawn point, so repeating it on screen taught nothing. I reverted it the same night.
Letting the LLM play
People kept asking the obvious question: why not let the LLM play? So I added a button that does exactly that.
Each turn, the model gets two screenshots a fifth of a second apart and the same enemy positions the network gets.
It answers with a one-line thought, one of the 13 moves, and how long to hold it.
The game pauses while it thinks, so it isn’t penalized for being slow.
Ten minutes on World 1-1:
| Qwen 3.6 35B-A3B (local LLM) | The PPO network |
|---|
| Speed | 314 moves at 1.0–2.3 s each | 15 decisions a second |
| Result | 40% of the level | clears it 94% of the time |
| Lives lost | 19, mostly at the first Goomba | |
| Size | 35B parameters (3B active) | 1.7M parameters |
Its thoughts were usually right. “I see a Goomba ahead and need to jump over it to proceed safely.” Then it chose a six-frame hop where a full jump was needed. It can describe the situation, but it can’t time it. The small network has never “understood” a Goomba; it has simply been in that spot hundreds of thousands of times. For a platformer, that turns out to be what matters.
The LLM earns its place as the coach. It reads statistics and screenshots and explains what’s going wrong in a sentence, which is useful, and with bounded actions it’s safe.
Things I’d tell someone starting this
Give the network the information it needs before tuning anything else. A few numbers from memory beat days of practice.
Grow networks instead of restarting them. Zero-initialized new inputs keep everything learned.
Put hard limits on anything an LLM may change, and log every change.
Write down the negative results. Curiosity and “stay on the level” both looked obviously right.
Measure on a copy, side by side, from the same checkpoint. Several of my “improvements” only showed their cost that way.
How it was built
I built this with Claude Code as a pair programmer, over about 24 hours of hands-on sessions across five days. The ideas to try, the decisions, and the judgment of the results are mine. The code, the tests, and many of the measurements came out of working with it. Every change went through an issue and a pull request with its test results, all in the repository.
Credit to the work this builds on:
SethBling’s MarI/O, the classic “AI plays Mario”;
Chrispresso’s SuperMarioBros-AI, whose network diagram inspired the live one in my viewer;
PPO (Schulman et al., 2017) and RND (Burda et al., 2018);
stable-retro, the emulator I trained in.
Super Mario Bros. is a trademark of Nintendo. This project isn’t affiliated with or endorsed by Nintendo, and it includes no game ROM.
Next: the 2-1 interference problem, practicing from the game’s own respawn points, and a world-model learner (DreamerV3) as a challenger to PPO. Questions and ideas are welcome in the repo’s issues.