Playing Around with Snake


Table of Contents

Introduction

The last ten years I’ve been working on a Snake game for the terminal called C-Snake.1 While doing this I found that there are pretty cool ways to spice up the “default” Snake gameplay that most people are used to.

In this post, I want to highlight how we can play around with little gameplay tweaks and game design decisions to make Snake into something much more interesting to play. Each new feature has a demo associated with it, so this post isn’t just theory.

Note for users on mobile

While the demos in this blog post do work with touch controls, the game was really designed to be played with the keyboard.

What Creates Action?

I quickly want to talk about how rather simple games can create exciting gameplay through time pressure. If you don’t care about me waxing on and on about game design you can skip to the demos.

Action Puzzle Games

I love action puzzle games. I love them because they have a simple ruleset that evolves into complex gameplay. A puzzle game just gives you a puzzle. An action puzzle game, forces you to solve the puzzle on a timer. It is this time constraint that makes these games interesting and forces the player to come up with strategies on the fly. Tetris is the most obvious game to mention as an example here, but there are so many more:

All these games have two things in common:

Games like Panel De Pon, Puyo Puyo and Dr. Mario also reward the player for intricate solutions in the form of score bonuses and games like Qix reward the player for taking higher risk, but not all games in this genre do that. It’s important to stress that the fun in these games does not come from overly complex puzzles nor a very stringent time limit, but the combination of fairly straight-forward puzzles with a moderate time limit, that can produce exhilarating, emergent gameplay.

What is a Snake?

What I am wondering is if the beloved game Snake is also part of this genre. Whether it does present the player with a puzzle might be up to interpretation. The gameplay consists of randomly spawning “foods” that the snake needs to touch with its head in order to eat it. This makes the snake grow and adds to the score of the player. The player loses once the snake touches itself. So far so good; I expect everyone reading this to be familiar with the basic gameplay. In my eyes, the Snake gameplay does include puzzle-adjacent elements. When the snake becomes long enough, the game becomes a maze-solving game.

However, can we consider it to be an action puzzle game? If not, can we transform it to be an action puzzle game? In the classic Snake games for Nokia phones, there is no time limit or time-based score bonuses, so the player can take as long as they want. The player has almost full control to set up their snake in a way to comfortably eat the next food, except for snake moving on a timer.

Snake II changes a few rules, but most importantly, every five eaten foods it spawns a bonus food that grants higher points but also disappears after a set time! Additionally, the game added a wrap-around on the boundaries of the game area, so the snake can leave to the right and come back from the left, making the possible moves much more complicated. What else could be done to the game design to make it a bit more engaging?

Game Design Experiments

Let us play around with the Snake game design and see what we can do to make it more engaging. We will add feature after feature in order to show how the gameplay changes. Make sure to try these changes yourself and see how they affect the game.

Colorblind Mode

If you struggle with red-green color contrast the game supports an alternative color palette:2

Simple Beginning

Let’s start with the most simple version of Snake. It is the most basic Snake game you can imagine. You gain points by eating food, and you die instantly when hitting walls or yourself. On Desktop, you change direction with the arrow-keys, and on mobile you tap on the corresponding side of the game area. Go ahead and give it a try!

Adding Speeding Up

This is fine, but I find it boring that the game doesn’t really get harder as the player progresses. Yes, the snake becomes longer, but it would always be possible to “clean up” the game area by wiggling the snake into a compact, looping, space-filling curve and just wait until the next food is hit.3 To make this more interesting, let’s make the snake speed up every time food is eaten.

Now this makes things slightly more difficult, but I have an issue here. When the snake gets fast, it becomes very hard to move towards foods next to the walls. That’s because consecutive directions are not buffered, the game only reacts to your current input based on its own tick, which is roughly how the old Nokia Snake game worked.

Buffering Input

We can improve this by buffering two inputs by the user. These buffered inputs are then applied each game tick. You can test this easily by very quickly changing directions in a diagonal pattern like “up”, “right”, “up”, “right”, and so on.

Trying this on the versions without input buffering will simply ignore your request. Any diagonal movement and quick alignment with the walls is then very hard to do. I would argue that this is not by design. Proper input buffering should be part of any game, that needs a user to react and use complex inputs in rapid succession.

Time-based Score Bonus

Now that we have fixed the issues of stagnant difficulty and the game controls well, we can add a new mechanic that rewards players for their reaction time and effort in planning: A time-based score bonus. Food, after spawning, has a bonus associated with it that starts at 99 and slowly depletes until hitting zero. The bonus is added if the food has been eaten.

This has a few cool effects:

Adding Speed Boost

Now that we have given players an incentive, let’s also give them a more involved control scheme, by adding a way to boost the speed of the snake. By pressing the same direction key twice, the snake will speed up until another direction key is pressed.

This rewards players with good reaction speeds. Also, it makes the start of the game less boring and gets players quicker into action. Now, we have a game that is much more akin to an action puzzle game!

Grace Period

Something which I find unfair at times is how strict the collision detection is. Since we now have added two features that speed up the snake, we should take care of that. We can do so by adding a grace period, in which the snake changes color and gives the player a short time to respond and change direction.

Bonus Foods

Let’s incentivize the player to use the speed boost more actively. We can do this by adding a bonus food that appears regularly, gives a fixed, high score when eaten, moves around quickly and disappears after some time. Now the player is forced, to react quickly if they want to maximize their score.

Less regular Bonus

Currently, the bonus food spawns regularly after a certain amount of normal foods have been eaten. This makes it very predictable for the player, when to look out for the bonus food. To make it a bit harder, we can spawn the bonus food based on time instead.

This decouples the eating of normal foods from the bonus food. Yes, it is still predictable, but it is harder to keep track of the next spawn, since the player now needs to keep track of the current food and the elapsed time.

Going Beyond Boundaries

Since the spawn of foods and bonus foods is randomized, it’s possible for somewhat unfair placements to occur. Let’s say the snake is currently in a corner since that is the position where a regular food spawned. Now a bonus food spawns on the opposite corner. The player will probably be robbed of their bonus just because they got unlucky.

To make things more interesting, why not take something from Snake II’s book and allow the player to pass through the boundaries of the game arena. When the snake moves out of the game arena it will simply come out of the other side.

This is a remedy for unfair food spawns but also has another interesting effect: The quickest path to a food isn’t obvious anymore. The player has to do complex path finding in their head and also plan their movement very carefully. Now, they are thinking with portals

Getting Walled In

This wonderful change makes the game much more interesting, but it funnily makes the game a bit too easy when playing it casually. So why not add back some obstacles?

The added walls make the pathfinding more challenging, even in casual play. I think the combination of open game arena boundaries and static walls makes the gameplay much more fun.

Shrinking back down

A golden rule of Snake is that the length of the snake always increases. I don’t like that rule. It fundamentally limits how long the game can run on for. But why have this limitation? If a player is good enough, they should be allowed to play for as long as they want to. So let’s break that rule! Rules were meant to be broken anyway.

Let’s make the bonus food even more important than it is right now by letting the snake shrink after eating it. This also means that now the player can have different strategies when playing the game. Is it better to wait for bonus foods and remain a short snake or to quickly eat foods and balance them with bonus foods, so the snake stays short while the score is still maximized?

Moving Instantly

The game has become quite complex now. Something that has stayed pretty simple is the input handling. I personally feel held back by the game. When I change a direction I want the game to respond to me. I don’t want it to wait for the next game tick. So, let’s make the game instantly react to direction changes.

Input Filter for Sanity

Now that controlling the snake feels much smoother, let’s address another thing: Currently, invalid movements are still allowed. What I mean by that is that, a player who lets their snake run along a wall can decide to crash their snake into that wall. This behavior is fine. However, I want players to be able to plan ahead when playing. So when a player runs along a wall and decides “once this wall ends, I want to go to the left”, they should be able to input “left” way before the wall ends. Input buffering should handle this.

To test this, let the snake go to the left and let it walk up the outside wall. Then, while still on the wall, let it go to the right. You will see that this does not interrupt gameplay but stores this decision for later.

Why do this? It better reflects what the player wants to do. The player obviously doesn’t want to make the snake commit suicide, but signal where to go next. This makes the gameplay smoother and gives the player a bit more leeway.

Even more Teleportation!

Another golden rule of Snake is that the snake is always contiguous. Since we have already broken a golden rule, why not do it again? Let’s add periodically appearing wormholes that, upon entering, teleport the snake!

This just makes the game so much more fun. Sometimes, a food spawns on or near the exit hole and being near the entry gives a real rush of adrenaline. It also allows breaking up the snake to enable more pathways through a relatively full game arena.

Alternative Game Modes

We have demonstrated how a very simple game can become an engaging experience with a few tweaks and changes to the rules. Something we haven’t touched, is the core gameplay mechanic which consists of:

Why not break up these core tenets to see how the game behaves then?

Time Trial

The simplest idea to break up the first rule is to set a time limit for the game. This results in a time trial mode. Here we set the time to two minutes. With all the additions to the game that make the gameplay faster and more responsive, the player now needs to show that they are able to quickly react.

When playing this for a bit, you might realize how missing game arena boundaries and the wormholes come together nicely to allow for shortcuts. After a while you develop an intuition for pathfinding and it becomes much easier. With this mode, the game now becomes competitive. Now, two players can really go toe to toe and compare what their best scores are after a “best of three” competition.

Time Seeker

Something I don’t like about the “Time Trial” mode is that no matter how well the player is performing, the game still comes to an end. In the beginning I’ve talked about action puzzle games. Many of them can go on almost indefinitely if the player is playing good enough.

So, as a final touch to our game design endeavor, let’s add a way for good players to play the “Time Trial” mode a bit longer. When eating bonus food the timer will gain a few seconds. This way a good player is incentivized to go for the bonus food.

This is my favorite way to play this game. It’s really thrilling to get the bonus food and to race the clock. It’s exciting to navigate around wormholes and walls to get to the bonus food as fast as possible, even when ultimately running into a dead end. This game mode now really feels like an action puzzle game and scratches a certain itch for me.

The Snake Ain’t Hungry?

How do we change Snake so we change the core rule that food is eaten by the snake? One could think of a Tron-style game like Armagetron Advanced where the goal is not to get bigger, but to defeat some adversary.

An idea I’ve been playing around with was called “Constrictor”, where the snake does not eat the food but needs to “enclose” it, by slithering around the food. This was also implemented in the snake demo, but I removed it for a simple reason: It wasn’t fun. It’s not really satisfying to go around food, to eat it. It doesn’t have the same visceral impact that hitting the feed does. The reward is not as immediate.

It also complicates the implementation, since a flood fill algorithm needs to be implemented in order to check if food is “enclosed”. To me, it seems that for a single-player game, making the snake eat the food with its head is a good choice.

Conclusion

I hope I demonstrated in this post how simple tweaks to the gameplay of Snake can lead to massive changes in how the game feels and what its incentives for a player are. The additional features turned a relatively passive game into something more akin to action puzzle games.

Try it for yourself!

You can find the demo game at https://phagenlocher.github.io/SnakeSlop/ where you can toggle the features individually to see how they interact with each other.


  1. When I am saying I’ve been working on the game for ten years I mean that I add about two or three commits each year whenever I feel like it. ↩︎

  2. Wong, B. (2011). Points of view: Color blindness. Nature Methods, 8(6), 441–441. https://doi.org/10.1038/nmeth.1618 ↩︎

  3. What I mean by this is that there is no incentive to go for the food as fast as possible, so the player can just go about a predetermined path that hits every point in the game arena at least once before looping (which is trivial for a 2D grid). ↩︎