How to write a bot

Bots are written in Javascript, Lua, Python or Ruby. They'll be executed in a sandbox.

For every turn, our game server will call a function called make_move() in your program.
This function can return six different values (defined as global constants):

  • NORTH
  • EAST
  • SOUTH
  • WEST
  • TAKE
  • PASS

This is a very simple, albeit not very smart, robot (a.k.a. known as "EASTBOT"):

function make_move()
{
  return EAST;
}

A more fully-fledged example implementation is called random bot and comes with source code.

Bots have a number of functions they can call to enquire the state of the board, the position of the enemy player, the number of fruits left etc.

See the API documentation.

Global state

Global state persists from one call of make_move() to the next, so feel free to keep data around or cache previous results.

Time limit

There's a limit of ten seconds "thinking time" per move. After that, the bot execution is aborted and the other player wins.

Memory limit

The maximum amount of memory you can allocate is 128 Mb.

Errors / Exceptions

The bot also loses if it throws an exeception. You can check the replay logs to see the errors and exceptions that happened while your bot was running.

Standalone bot testing framework

The easiest way to hack a bot is to grab the standalone testing framework.
Clone the git repository and then modify mybot.js to start writing your bot. Opening game.html will allow you to watch your bot play on random boards (you can also step through one move at a time.)
It also comes with an easy opponent (if you're not ready to face an opponent yet, uncomment the "return PASS" line in assets/simplebot.js.)

Sandbox

Notice that official matches run on our servers work differently than the ones in the testing framework: On our servers every bot will run in its own sandboxed environment, with no access to anything except its own state and the game state- in particular, it won't have access to the opponents code or variables. So don't try anything sneaky :)