A game of snake that's less than ~2.8 KB, which is the maximum amount of binary data a QR code can hold.
The answer is yes, and Matt KC goes through the process in this great video: https://www.youtube.com/watch?v=ExwqNreocpg. You can also read his post on this.
The code or the exact steps used in the video weren't linked, so I wanted to challenge myself to see if I could do it. I've taken a slightly different approach than what's shown in the video. This project is essentially a guide for anyone else who wants to try this out. This is by no means perfect, and suggestions are welcome.
I've created a game of snake that's played in the terminal using C and it runs on Windows. Unfortunately the smallest I could get the exe was 3 KB, so I resorted to compressing it in a zip file. This doesn't affect the experience too much in my opinion as the game can be played without extracting from the folder, but it does feel like cheating so I'm looking for ways to make it even smaller.
These are the tools I used to minimize my file size.
- TCC- The tiny C compiler
- UPX- For executable packing
- qrencode- To generate a QR code
- zbarcam- To read the QR code
-
Create an executable: This creates a
.exefile that's ~4 KB in size.tcc -m32/64 snek.c
-
Pack with UPX: This creates a smaller
exefile that's ~3 KB large.upx --ultra-brute snek.exe
-
Zip the
exe: Put theexein a compressed zipped folder and name itsnek.zip. This zipped file is less than 2KB and can fit in a QR code. -
Create the QR code: You'll need to run this in a linux environment, I used WSL for this purpose.
qrencode -r snek.zip -8 code.png
-
Read the QR code: Print the code out on a sheet of paper or use your phone. Download the zip file containing
zbarcamfor windows from here: https://itsmattkc.com/etc/snakeqr/zbarcam.zip and unzip the files.cd zbarcam zbarcam --raw --oneshot -Sbinary > snake.zip
Open the zipped folder and run the application to play snake!
Credits for this idea and the modified version of zbarcam go to @itsmattkc