Instructions

Communication between the game and the bots is established using JSON data exchanges over HTTP. For every turn, the two bots are given the current game state as JSON. Your bot must accept a POST method at /. The game state will be POSTed to your bot. Your bot is expected to return your set of moves in the appropriate JSON format in the POST response. Each bot is expected to respond with moves within five seconds. If a bot doesn't respond within five seconds, it is disqualified.

This is an example of the game state that will be POSTed to each bot:

"state": {
  "gameId":"9LAoswlJU21Osy9N51Z9",
  "turnId":0,
  "apiKey":null,
  "secretKey":null,
  "rows": 4,
  "cols": 4,
  "p1": {
    "energy": 0,
    "spawn": 5
  },
  "p2": {
    "energy": 0,
    "spawn": 10
  },
  "grid": ".....1....2.....",
    "maxTurns": 20,
    "turnsElapsed": 0
  },
  "player": "p1"

Where "player" represents which side the bot is playing as, and is either "1" or "2". p1.spawn and p2.spawn represent the indices of their respective bots' spawn points on the grid string. p1.energy and p2.energy represent the amount of energy each bot currently has.

The Grid

The grid is a string where each character represents a space on the grid.

Note that the grid can be visualized by formatting it according to the number of rows and columns. In the above example, we know the grid is 4 rows long and 4 columns wide, so the grid of ".....1....2....." can be visualized as follows:

....
.1..
..2.
....

And so we see that the two bots are actually diagonal to each other!

Bots are expected to respond in from the POST with the following format:

[
  {
    "from": 12,
    "to": 11
  },
  {
    "from": 21,
    "to": 20
  }
]

Where each item in the array represents a move. "from" must be the index of one of the bot's botlets, and "to" must be the index of a coordinate adjacent to that botlet. Otherwise, the move is ignored.

Bots can be written in any language you wish as long as you meet the HTTP JSON specification defined here and they are publically accessible at the time of the tournament. After any given tournament, you must leave your bot API accessible for play until the next tournament, so players can practice against yours.

Testing your bot

You can use any language or tools to program a bot that you want!

All you have to do is create an API that can accept a POST request contianing the MoveRequest object and return a list of moves for it's bot. Even if you're not an expert programmer, we're here to help.

If you like the C-like languages, someone has made a "starter kit" using the C# language. You can check the repo out on Github. It includes a sample bot, and already does all the heavy lifting of serializing and deserializing the objects.

If you hate Microsoft, that's OK! Being the awesome counterculture Python/Javascript/whatever guy you are, I know you won't have any problems. But, as you develop your own project, maybe think about creating your own starter kit in the language of your choice. We're trying to help people hone their programming chops in a fun way, and you can help!

You'll also probably want the Netbots Debug Assitant. When you're developing your own bot, you're probably going to have it running on localhost. Obviously, this site can't connect to your localhost so we've made a handy bridge for you. You can check out the source reop here, but mainly you'll want to use it by just downloading this zip.Just extract the files, lauch the exe and following the instructions.

Step By Step Guide For Using the Starter Kit

If you wish to use the C# Starter Kit, here is a detailed step-by-step guide.

First, you'll need to download a few things.

Open the NetBots Starter Kit in Visual Studio (double-click on the .sln file). In the menus, select "DEBUG -> Start Debugging." If you get an error that the solution cannot be started, find the NetbotsClient.Host project on the Solution Explorer, right-click it, and choose "Set as Start Up Project." Then try again. A web browser window should open. The address should be something like http://localhost:59345/ We will refer to this as the "client root address" in the rest of these instructions.

Now install the NetBots Debug Assistnat. A shortcut shoudl be created both in your Start Menu and on your Desktop. Launch it, and a console app should open telling you what address to put into your web browser (currently, it is http://localhost:9001, but if htis address doesn't work, check the Console screen to make sure it hasn't changed since this writing).

Go to that address in your web browser. You should see a page similar to the NetBots Skirmish page. In the "Your Bot" field, type "[client root address]/berserkerbot". For instance, if your client root address was http://localhost:59345/, you should type http://localhost:59345/berserkerbot. Check the "Enable CORS box," and then select your opponent from the drop down menu. Then hit the "Fight" button. You now have a fight going on between the starter kit demo bot and a bot on aibattleground.com!

Now go back to Visual Studio. In the Solution Explorer (normally your right-most pane) you should see a list of projects. If it is not already, expand the NetBotsClient.Ai project. Inside that project, you should see a folder called "DemoBots." If you expand this folder, you should see "BerserkerBot" and "Randombot" classes. Set a breakpoint at the top of BerserkerBot's GetMoves() method. Do this by positioning your cursor at the first line and hitting F9. A red ball should appear on the left. Start a new fight, and the breakpoint should be hit.

You should familiarize yourself with this code a bit to get a feel for some basic bot logic. Once you're ready, you can write your own. If you create a new class, you have to implement the IRobot interface. Otherwise, if you want, just rename the BerserkerBot or RandomBot class and get started. When you hit "Debug -> Start Debugging" again your new bot will be at an address such as "[client root address]/className". For instance, if your new bot's class was called FooBot, and your root address was http://localhost:59345/, then when using the Debug Assistant, you'd type in http://localhost:59345/foobot as the address of your bot.