Snakes on a Chip

Christopher Bolig gave the Snake game an AI upgrade on a custom ATtiny1616-based handheld gaming platform with just 2 KB of memory.

Nick Bild
6 months agoGaming
Great. Now snakes have harnessed AI. (📷: Christopher Bolig)

Snake games, in which an ever-growing digital snake must survive as long as possible without running into either a wall or itself, are still quite popular today, despite the genre being nearly 50 years old. However, it is a very simple game, and before too long the fun inevitably starts to wear off. Christopher Bolig wanted to keep the good times rolling a bit longer, so he updated the classic game with — you guessed it — artificial intelligence (AI).

The plan was to train an AI algorithm to compete against. You play a round and give it your best effort, then see if the AI can top your score.

Snake games are not typically the sort of thing one sits down at a high-end gaming rig to play. Rather, they are usually played on low-power handheld devices when one has a few minutes of downtime. So naturally Bolig wanted to build his game into a portable device. The game itself is very lightweight, but adding an AI algorithm complicated things a bit — especially since he is working with an ATtiny1616 microcontroller with just 2 KB of memory.

Aside from the microcontroller, the device consists of little more than an 8 x 8 bicolor LED matrix, four buttons, and a few resistors. So how did Bolig get this system to run the game and AI algorithm? First, he found an existing implementation of a reinforcement learning algorithm that was designed to play Snake. It was much too large to fit into the microcontroller’s available memory, so he cut it down in size and then tweaked a few hyperparameters. This was not exactly a scientific process, but who knows, maybe it will work?

And work it did. After training the scaled-down model and porting the Python code to C++ for the ATtiny1616, Bolig was racing around the playfield trying to one-up the AI algorithm. Ugh! Those AIs always think they are so smart.

Bolig designed the hardware around an electronic business card that he had previously created, since it already had the necessary components. You can do the same, or if you would rather breadboard it, or develop your own platform, all of the necessary details are available in the project write-up.

Nick Bild
R&D, creativity, and building the next big thing you never knew you wanted are my specialties.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles