🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Around 10 years ago Google DeepMind showed that you could use deep reinforcement learning to play video games. It’s something that I found fascinating at the time and wanted to try but never had the time to really look into it.

With LLMs now being able to do a lot of the heavy lifting for me, I’ve started to work through my backlog of ā€œthis is interesting - I’d like to try it outā€.

I grew up in the 70s and 80s and my childhood computer was the ZX Spectrum, and my ESP32 Rainbow project has given me a nice emulator that I can use to both play games and experiment with.

Manic Miner was one of the first games we purchased and I wasted a lot of time playing it. I have vague memories of progressing reasonably far, but never actually completing the game. So I naively thought - Reinforcement Learning - why not? Some cursory googling would have told me it was not suitable, but I’ve never really been one for doing a lot of up-front research before diving in.

The title screen, and the game starting

The emulator that I have for the ESP32 also compiles into a desktop application (and there’s a WebAssembly version as well). Running it at full speed is about 1000 times faster than the original machine - so in theory we are in a good position to get something working.

There are also some really good resources for Manic Miner - this site is particularly good. Very handy when Claude is being an absolute doofus head.

The idea that Claude and I came up with (and of course Claude was super enthusiastic about…) was to wrap the emulator as a Gym environment, give the agent a reward for doing well, and run PPO until Willy walks out of Central Cavern. How hard can this possibly be…

This failed miserably. The initial attempt was to just use joystick movements to drive Willy around. We then tried creating a set of move ā€œmacrosā€, e.g. jump right, jump left, walk right. And still didn’t get anywhere with the RL approach.

Claude then suggested that what we were lacking was a good reward function, and that what we should do was solve the problem via search and then feed the route into the RL algorithm and use that to help guide the algorithm.

This really should have set off some alarm bells in my head.

We spent a lot of time messing around with searching and then feeding the path into the RL algorithm and started to get some results - but ultimately the question ends up being - ā€œif we can solve this with search, what is RL adding?ā€.

So, eventually, after a lot of wasted time, we pivoted to just doing that - why don’t we just try and find the fastest route through each cavern using search.

Should be simple, shouldn’t it?

There are a couple of things that make it tricky. There isn’t a simple graph that we can search (see later to learn I was wrong). The search space is very large, we have moving guardians, sometimes quite a few of them, this explodes the search space. Every position Willy can end up in gets multiplied by all the possible guardian positions.

The order you collect items in can have a big influence on the length of the path - and you need to collect all the keys - this turns into a bit of a travelling salesman problem. What order should we collect them in?

Some caverns have switches that change the layout - once again the search space gets quite big.

Our first working version was a two pass system. The first pass runs with the guardians set as harmless and ignored. This lets us find the optimum path and item order.

The second pass takes this route and searches along it but waits and jumps to avoid the guardians.

Pass one's path and pass two's route in Central Cavern

Central Cavern side by side: harmless guardians (pass one) vs live guardians (pass two)

The most expensive cavern is Return of the Alien Kong Beast, which has five items and two switches, and so 5,040 possible orders of collecting items. That one cavern took 8 hours to search.

Return of the Alien Kong Beast, with both switches

Some of the caverns are very complicated, there are a lot of guardians, so waiting and jumping at the right time becomes critical.

Attack of the Mutant Telephones

This did get us a complete run through of Manic Miner - every cavern solved. 39,091 frames, which is about 13 minutes of play.

The problem was it took around a day of computer time to find it, and 92% of that time was spent in the emulator. Every move the search tried had to be run through a full Z80 emulation, and even at 1000 times real speed it’s pretty slow.

So we took the emulator out of the search. Willy’s movement is pretty simple - he walks 2 pixels per tick, jumps follow a fixed table, falls speed up and kill you if they’re too long, and crumbling floors and conveyors do what you’d expect. Claude went through the disassembly and wrote a model of all of this, and of the guardians, so the search can step through the game without running the emulator.

Most of the guardians don’t react to Willy at all - where they are just depends on how long you’ve been in the cavern. Eugene, the Kong Beast are the exceptions. So we could drop the harmless guardians pass and do a single A* search with the guardians live. The inner loop is in C++ and does around 690,000 states a second.

Every route the search finds still gets played back through the emulator, and if Willy dies we throw it away - this was added a belt and braces check - just in case Claude had got its model of the game wrong.

All the caverns are searched in order, each one starting from the state the previous one finished in.

There were bugs in the model. Eugene could walk off the bottom of his shaft, so Willy was dying to a guardian the model didn’t know was there. We also found that pressing fire to start the game was making Willy jump at the start of the first cavern.

The full run is now 36,791 frames, about 2,300 fewer than the two pass version, and takes about two hours to find instead of a day. Fifteen of the twenty caverns are faster and the other five are slower by between 2 and 40 frames.

Frames to finish each cavern with each approach

Moral of the story? Forget all this ML and AI nonsense and get back to studying basic algorithms…

Related Posts

Jev Plays Manic Miner - TypeSafe's new decision model, Jev, has been shown playing games, so I tried it on Manic Miner. It works - but there is a big question - is Jev actually doing anything?
Old school tape loading - If you're anything like me, the nostalgic screeches of ZX Spectrum games loading might bring a smile to your face. I've taken a trip down memory lane by working on my own tribute to this iconic machine—introducing the ESP32 Rainbow. It’s on Crowd Supply, where we're closing in on full funding! This blog post walks you through the journey of harnessing audial data to load games directly into my emulator—faster and more reliable than those temperamental cassette decks from our childhood.
Tanks! Mayhem is back: 16 years later, in your browser - I dusted off my 2010 wireframe tank shooter, Tanks! Mayhem—pulled from the US App Store after an Atari complaint—and asked Claude Code to bring it back on the web. About half an hour later I had a faithful browser port: original models and sounds, Box2D physics via planck.js, and my neon line glow rebuilt with quad-expanded edges. A forgotten procedural radar shader finally shipped, multiplayer and the hated attack chopper stayed out, the code’s on GitHub, and it’s free to play at tanks.atomic14.com.
Vibing a PCB - surprisingly good - In my latest adventure, I challenged AI to design a working ESP32-S3 development board from scratch using Atopile and Claude. The idea was as simple as vibe-coding actual hardware without diving into the code. It was a chaotic yet fascinating journey, with some misses like unwired components and a forgotten capacitor. After a few prompts, the AI delivered a surprisingly functional board featuring USB-C, an AMS1117 regulator, and status LEDs. While not yet perfect, vibe-coding feels like a glimpse into the future of hardware design.
Esp32 s3 zx spectrum - In a bid to quench my nostalgia and flex my ESP32 chops, I managed to get a ZX Spectrum emulator running on my ESP32-TV board! Then, spurred on by PCBWay's new full color silk screen service, I pursuit the audacious task of recreating the ZX Spectrum's iconic keyboard. It's been quite the joyride - wrangling touch pins, shrinking screens and creating a thing of beauty on PCB. It's not quite ready for the spotlight, but keep an eye on my newsletter for more eagerly-awaited updates. It's like the Spectrum is reborn!

Related Videos

ESP32-S3 ZX Spectrum - Full Color Silk Screen is really cool! - Super stoked to share this creation – an ESP32 ZX Spectrum emulator! Although it's still very much a proof-of-concept, it's looking pretty rad. I've got the classic games like Manic Miner, and yes, you can program in basic too! In perfect Sinclair fashion, I'm planning on selling this key piece of nostalgia for just Ā£99. Work still needs to be done before the production phase, but rest assured, I'm meticulously working out the kinks, including tweaking the keyboard to ensure even better user experience. And on the technical side - a single ESP32S3 runs the show and we’ve multiplexed the keys exactly like the OG Spectrum. It's been great fun designing this piece of kit with the new full color silk screen printing from PCB way. Stay tuned for further updates!
But does it run DOOM? ESP32 ZX Spectrum update - All right, it's time for an update on my ESP Rainbow, the ZX Spectrum emulator with stunning full-color silk screen printing. I've been testing the latest boards, and PCB Way did a fantastic job. The enhancements include upgraded firmware, a 128k ZX Spectrum emulator, and a new 2-watt speaker replacing the old 7-watt buzzer. You can enjoy great sound with PWM and even play 128k games like The Never Ending Story. I've also added a snapshot feature and ported my video player over. Hardware upgrades include new capacitors and a slick power control chip for seamless battery and USB mode switching. We're gearing up for a commercial release, hopefully by Christmas, so stay tuned. And yes, it does run Doom! [Laughter]
Surprisingly not CR*P - Vibing hardware - Well folks, what an adventure! After vibe coding our vibing button, I took up the challenge to vibe code the actual hardware for an ESP32 S3 dev board. Used a tool called at pile and gave it a whirl with some AI help from Claude. Interestingly, it handled everything from sourcing components with LCSC part numbers to wiring them up. Had a wee hiccup with missing capacitor in the RC circuit, but overall it was a thrilling ride watching the AI process! A bit of tweaking here and there, and we're good to go! Can't wait to see it in action.
Taking KiCad Silk Screen to the Next Level! - Take a peek at how my ESP 32 ZX Spectrum project is coming along! We're funded on Crowd Supply, ordering components, and adding a cool silk screen design to our PCB. Using tools like KiCad and Affinity Designer, I've jazzed up the back of the board with detailed graphics. It's been an exciting journey, making adjustments and ensuring everything works perfectly before ramping up production. If you haven't yet, head over to Crowd Supply and support the ESP 32 Rainbow project!
Crowd Funding Success? I must be rich! - Hey guys! So, I wrapped up my ZX Spectrum crowdfunding project, and boy, it was quite a ride! The campaign went gangbusters with 146% funding, and I shipped everything out. Total revenue was Ā£12,839.57, but after costs, I pocketed a neat Ā£4,273.91—though, spoiler, that's before considering my labor! There was quite a learning curve understanding COGS, pricing strategies, and the hidden costs of hardware projects. It took about 13 months from idea to fulfillment, and I amassed 436 hours of work! I discussed vital strategies like working with distributors and how PCBs' cost plummets with bulk orders. Plus, the unknowns, like tariffs, which almost threw a wrench in the works. Stick around for the deets, and maybe you'll pick up a tip or two for your own crowdfunded adventures!
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts