snake is a procedural fable that uses judeo-christian imagery to show the dangers of unchecked growth, i.e., capitalism [@aparrish]
In this blog post, we present a port of the Snake game to Twitter. We detail some of the (twisted) game design choices we made, along with code (please follow the links) and explanations. The whole project is available on GitHub (100% R) and here is the Twitter account.
Last move by @XavCompany
— Let's play Snake (@letsplaysnake) February 26, 2016
Rules are short: a snake must eat in order to grow up. Touching elements of its body or walls ends the game. There are variants for this game, an interesting one being that the longer the snake, the faster the game. We implemented this in our Snake game. Furthermore, there are also multiplayer variants of the game. That, we did not even try to implement it.
For the sake of readability, the game relies on three scripts. The first one,
start.R, determines if this is the right time to launch the game. If that is the case, it launches
run.R. The last file,
snake.R, contains the functions behind the game mechanics.
The board is composed of 100 emojis (“white large square”, “up/left/down/right-wards black arrow”, “mouse face”, “snake”), and 9(+1) line breaks. “Last move by @” is 14 characters long, and since a Twitter username cannot be more than 15 characters long, all tweets we send are valid, in principle. The function
tweet from package
Get the users’s directions
The game inputs are Twitter mentions. In Twitter mechanics, every tweet gets an ID attributed according to a chronological order. Thus, when we query tweets, we save the most recent tweet’s ID, and next time, the query will be launched from ID + 1. If you want to have a look at that, watch out, it’s gross (and wrong once every 100’000 tweets).
When the script attempts to read the received tweets, it makes a few choices. The accepted commands are indicated in the bio of @letsplaysnake. The script will look for them, and keep only tweets where they appear. Then, if a user has sent more than one tweet (never happened except me during beta-testing), it keeps only the last one, and only the first cited direction. All users are treated equally, and this also allows one to correct a direction previously given.
All in all, the bot is up only during the day, since for the moment the audience is composed quasi exclusively of European (for the moment?). That feature is implemented in the cron job, the app that deals with the automatic launch of the script.
Will we finish the game, one day, knowing that there's a gift in the end ?
— Let's play Snake (@letsplaysnake) January 26, 2016
Twitter as a game designer
We have had to bring two new features to the Snake game, because of the Twitter platform. At first, we realised that the game would be very boring if the snake were to die every time it touches the border. Like the news, this game should flow through a user’s timeline, you leave, you come, and you join the game later whatever what the situation looks like. If the game restarts too often, challenging runs will be rare and the Twitter account will look dull. Thus, we turned the board into a torus, which then turned itself into our most reliable source of bugs. With a torus, when you leave the board on the left, you’ll reappear on the right, etc. No more wall eating.
A funnier bug appeared when Twitter suddenly refused to post tweets after no one had mentioned the account for a while. In fact, after ten steps, the snake was back to its previous position, thus engaging Twitter’s anti spambot protection, which would simply prevent the account from posting. We needed a more dynamic board, able to evolve without an exterior output. That’s why we modified the mice capabilities by sometimes letting them move by one square in a random direction. This bypassed Twitter’s defences, but also lead to another funny bug (bugs can be funny, once they are solved).
The mouse moves to one adjacent square randomly every 5 steps on average. Is it…
— Let's play Snake (@letsplaysnake) January 16, 2016
The Snake original design
One feature we are proud of is the inclusion of speed. We implemented it by launching the script every minute and choosing to go on depending on the size of the snake. This is dealt by the
start.R file: if this is not the right time, the rest is not executed. So, hem yes, in a sense, the snake accelerates.
Whaddya think? Should it refresh once every…
— Let's play Snake (@letsplaysnake) January 13, 2016
This has been a funny experiment: making the adaptation for Twitter of a well-known game, having to deal with design choices, but also with feedbacks from the audience (in particular, thank you to Sarah, Mathieu and Xavier for really good insights, and Eric, Adrien, Alberto, Xavier (same one), Marco, Ori and ST for having been super active).
Here are some stats we are very proud of:
The most interesting and thrilling part has been the observation of people playing. Given a set of rules, and an environment not known (yet) for gaming, how would they react and adapt? Here are two anecdotes.
One day, a player had been the only one sending instructions for a good hour. The snake had become huge, the refreshment rate had gotten much faster, and the player, that could not play anymore for whatever reason, was already feeling frustrated, thinking of the death of the snake which would happen in the coming minutes after his leave… What did that player do? He grabbed the Twitter handles of some other players, and asked them to take over. And they did! It worked! He was not willing to lose the time invested, and needed real life collaboration in order to keep that weird Twitter account «alive»! The Tinder of video games!
The other story, somewhat similar, was caused by a player whose train passed through a zone with no mobile web access. A tweet containing his command got sent soon after he left the zone, but in between he had missed a few updates. The result: he simply caused the snake to go backwards and eat itself. In the following minutes, the other participants saw the “New Game!” mention, found the person responsible for the «Game Over» and sent him mocking (non-violent) messages. That was a friendly moment for this cute lively community. Just for that, the time invested in the project was worth it.
This is not the first game of Snake programmed with R. See: https://github.com/cocinerox/retro
The Swiss local radio Couleur 3 talked about the project! [MP3 starting at 4min50].