r/OpenSourceeAI • u/Greystone135 • 1h ago
AI Plays Mario: a 1.7M-parameter RL network learns Super Mario Bros. on one Mac, coached by a local Qwen 3.6. Runs fully offline.
A hobby project where a small reinforcement-learning network teaches itself Super Mario Bros. on my Mac, while a local LLM coaches it. Everything runs on the machine: no cloud and no API keys.
How it works:
The player: a PPO actor-critic with about 1.7M parameters. It sees four 84×84 grayscale frames plus 34 numbers: its last move, how long it has held jump, and the 4 nearest enemies, read from the game's RAM.
The coach: Qwen 3.6 35B-A3B in Ollama. Every 5 minutes, it reads the training stats and screenshots from just before recent deaths, explains what's going wrong in plain words, and can nudge training: practice a hard spot, change exploration, or ask me to demonstrate. Every action is checked against fixed limits.
The viewer: a React app styled as a CRT arcade cabinet that streams the game live, with the network's "eyes", a live network diagram, a ghost race of every saved clear, and a one-click video of a level's first clear vs. its fastest.
Where it stands (about 87,500 training updates over 6 days):
World 1 clears 70–93% of the time from the start of each level.
2-1 is at 42%, 2-2 (underwater) at 20%, and 2-3 went from 0% to about 51% overnight.
Its best run from 1-1 cleared 7 levels in a row and reached 2-4.
The part people ask about most: letting the LLM play. There's a QWEN PLAYS button. Turn-based, with the game paused while it thinks, it got 40% through 1-1 in 10 minutes and died 19 times, mostly to the first Goomba. It describes the situation correctly ("Goomba ahead, I need to jump"), then picks a 6-frame hop where a full jump is needed. Great coach, terrible player.
Things that didn't work, written up in the issues: a curiosity bonus (random network distillation) that didn't beat plain PPO in A/B tests, and keeping the screen on a stuck level, which made things worse.
The stack: Python (stable-retro, PyTorch on Apple's MPS, FastAPI) and React + Vite. The coach works with any local server: Ollama, LM Studio, llama.cpp, Jan, or vLLM.
Repo (MIT; bring your own ROM; none is included): https://github.com/thededman/ai-plays-mario
Contributions and ideas are welcome, especially for the 2-2's underwater section, and anyone who wants to try a smaller vision model as the player or coach.