This Game of 'Snake' Takes Place Inside its Own Source Code

The code IS the game.
August 15, 2019, 11:00am
Screen Shot 2019-08-14 at 7
Image: Quinesnake

In this version of Snake, the playing field is the game’s code itself, made with some very creative programming.

That’s why the game, made by a programmer named Taylor Conor, is called Quinesnake. A quine is a program that functionally accepts no input and does nothing but print a copy of its own code; in computer science this is often called a “self-replicating program.” The source code of the program is represented as data within the program itself and printed at execution. Quines, then, are normally not terribly interesting.

You may be asking, then, if a quine is functionally useless and accepts no input, how can quinesnake be a quine? The program does allow you to play a game of snake, after all. The truth is that Conor’s program is using a bit of trickery here. He explains that quinesnake “runs a game loop to accept keyboard control input, and highlights parts of the text as it continuously prints it to render the snake and the food.”

Think of the code generating the snake game as a program within the quine — it’s an event loop that watches for input from your keyboard. So the quine runs to print its code, including that of the embedded snake game, and then stops doing anything. The quine function itself takes no input after execution. Trippy, right?

If you want to play it, the game’s project files are available on Github. The Github page will explain how to run it, and you use the WASD controls to play.