Creativity Task - Multisnake


Nikola Djokic has won the Multisnake contest.


Mouse Stofl and his friends enjoy playing Multisnake. Multisnake is an extended clone of the classic Snake game. Multisnake supports Multiplayer matches for up to 8 players. Unfortunately, Mouse Stofl is the worst Snake player: He loses every game. This is very frustrating.

One day, he came up with the idea to create a computer program which could replace his inputs and win the game. There are whispers that you are a very skilled programmer and therefore Stofl is asking for your assistance.


Multisnake is played on a rectangular tiled map of size WxH and there are 2, 4 or 8 players on a map that compete each other. Each player controls a snake that occupies a number of adjacent tiles. The map is repetitive: Players who leave the map enter it on the opposite side.

A game is played in frames (turns). In each turn, all players move simultaneously following this set of rules:

  1. Snakes move by avancing their head and tail by one tile per turn. If a snake attempts to enter a tile which is occupied it does not move in that turn and dies. If multiple snakes attempt to enter the same tile, they die after performing the move. Dead snakes stay on the map. Note that as all snakes move at the same time, a snake may enter a tile that is left by the tail of another snake (or itself) in the same turn.
  2. Snakes can turn to the opposite direction if and only if their length equals one.
  3. There are tiles that contain + or - signs. When a snake enters such a tile, the sign is consumed by the snake and the snake grows (+) or shrinks (-) by one tile. Growth and shrinking are performed by not moving the tail or moving the tail by two tiles respectively. If a snake shrinks to length zero, it dies.
  4. To enforce termination of the game, all snakes grow by one each T turns, where T is a small positive integer. A snake can grow by at most one tile per turn. Consequently, consumed + signs are ignored and a snake that consumes a - sign does not grow in these turns.
  5. The last player whose snake is still alive wins the game. If all snakes that are left die at the same turn, the game is a tie.

Server Interaction

All interaction will be text-mode based. This is an interactive task, therefore it is crucial that you remember to flush standard output.

At the beginning of the game, the server supplies your program with information about the game. Read five integers W, H, N (number of players), M (your number) and T from standard input.

At the beginning of each move, read the map from standard input. It consists of H lines, each containing W characters. The meaning of each character is explained in the table below:

Character ASCII-Value Meaning
A,B,C… 65, 66, 67… Snakes' heads. Your head's ASCII-Value is given by 64+M.
@ 64 Dead snakes' heads
# 35 An impenetrable tile
v 118 Part of a snake's body, when the snake's head was on this tile, the snake moved down
< 60 Part of a snake's body, when the snake's head was on this tile, the snake moved left
> 62 Part of a snake's body, when the snake's head was on this tile, the snake moved right
^ 94 Part of a snake's body, when the snake's head was on this tile, the snake moved up
. 46 Free tile
+ 43 + sign, increases snake's length by 1
- 45 - sign, decreases snake's length by 1

There are no other characters in the map representation.

After reading the input, you must output exactly one line containing a char ('^', '>', 'v' or '<'), which indicates in which direction the snake should move. Your program is terminated automatically if your snake dies, the game ends or you output an invalid line.


  • 5 ≤ W,H ≤ 150
  • N = 2 OR N = 4 OR N = 8
  • 1 ≤ M ≤ N
  • 1 ≤ T ≤ 25

Example map

This is a map at an arbitrary turn in the format the server will provide it to your program.


The map contains four snakes two of which entered the same tile in the same turn and died. Note how snakes that left the map entered it again on the opposite side.


Download of the Multisnake-Servers: (last change 28.11.10)

System Requirements

The server has been developed using Linux. In order to build the server on your machine, make sure that the build-essentials are installed (sudo apt-get install build-essential on Ubuntu). On Windows you can compile the server and the sample bots using cygwin (


  1. Download the file and extract it into the folder multisnake.
  2. In your terminal change your directory to this folder
cd /path/to/your/folder/multisnake/
  1. Execute the command make. Afterwards the server and all the sample-players in the folder /programs will get compiled. It is important, that the compilation of the server and the players in C/C++ finshes without errors. If there are some additional compilers missing (like javac for Java, gmcs for C# or fpc for Pascal), you might get some errors in the output, because the corresponding sample programs could not get compiled.
  2. You can test, whether the server works properly by executing:
./multisnake map1 random random random random

If everything works fine, you should now be able to see four coloured snakes moving around the console.

Further steps

You can find further information about the usage of the server and possible configuration parameters in README.TXT. Sample implementations of random players in many programming languages (C, C++, C#, Java, Pascal) can be found in the folder /programs. They should help you to start coding your own player in your preferred language. For having some fun during coding breaks, you can also try to steer a snake by yourself by using user as an argument of multisnake.

Have fun while coding and playing!


  • Note that the testing server has not reached final state. Please report bugs, problems and further ideas to us.
  • There is one really simple map included in the server. Feel free to design your own, more complicated ones.