Robot Wars

The API is accessible on host:

Open the root url to see the existing battles that have been run on the server.

Robot Wars API

The API is accessible on host:

Open the root url to see the existing battles that have been run on the server.

API examples using curl

The game master first need to create a battle where opponents can join. A battle configuration is returned.

curl -s -d '{"type":"create"}' -H "Content-Type: application/json" -X POST
# => {"id":787352956,"width":100,"height":100,"timeout":1000,"state":"open","created":"2019-02-10T17:54:05Z"}

A configuration for the battle is returned.

As soon as opponents are informed about the battle identity, they can join by specifying the battle id and a name for the robot. A robot configuration is returned.

curl -s -d '{"type":"enter", "id":787352956, "name":"MrRobot"}' -H "Content-Type: application/json" -X POST
# => {"id":328610546,"battle":787352956,"name":"MrRobot","x":77,"y":66,"angle":136,"aim":106,"energy":100}

Robots get a random location, angle and aim on the battle field and start with power of 100.

Robots can execute from a single computer or from different computers. One way is to create a single program/script that controls the game (a "master" program) which in turn start different client robot programs.

It is the game master that decide when the game starts. The game master can ping the battle to check battle state.

curl -s -d '{"type":"ping", "id":787352956}' -H "Content-Type: application/json" -X POST
# => {"state":"open","robots":[328610546,802403610]}

The robots field contain the identities of robots that have joined the game.

The game master decide when to start the battle based on e.g. number of entrants or time period after opponents was informed about the battle. The battle is started with a start command.

curl -s -d '{"type":"start", "id":787352956}' -H "Content-Type: application/json" -X POST
# => {"robots":[328610546,802403610,656339793]}

After entering the battle, robots also need to wait until the battle is started. Robots can also check battle state through ping command.

curl -s -d '{"type":"ping", "id":787352956}' -H "Content-Type: application/json" -X POST
# => {"id":787352956,"width":100,"height":100,"timeout":1000,"state":"running"}

When battle state change from open to running robots can start to send commands.

Battle can be in the following states:

During a running battle, robots can send a single command with a maximum timeout of 1000 ms each battle round. Failing to send a command within 1000 ms is the same as sending a nop (no operation) command.

One of the following commands (walk, turn, aim, scan, fire and nop) can be sent in a round.

A walk command move the robot in the angle direction of the robot


curl -s -d '{"type":"walk", "id":328610546, "steps":8}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":730700238,"battle":173310470,"name":"MrRobot","x":82,"y":0,"angle":343,"aim":41,"energy":20},"result":{"walk":{"x":8,"y":0}}}

A turn change the direction of the robot a specified angle relative current direction


curl -s -d '{"type":"turn", "id":328610546, "angle":5}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":730700238,"battle":173310470,"name":"MrRobot","x":74,"y":0,"angle":337,"aim":41,"energy":20},"result":{"turn":5}}

An aim change the aim of the cannon/scanner tower relative current aim


curl -s -d '{"type":"aim", "id":328610546, "angle":10}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":231079204,"battle":173310470,"x":57,"y":54,"angle":202,"aim":176,"energy":100},"result":{"aim":10}}

A scan command detect other robots in the direction of the cannon tower


curl -s -d '{"type":"scan", "id":328610546, "angle":15}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":944065924,"battle":173310470,"name":"MrRobot","x":99,"y":4,"angle":37,"aim":188,"energy":38},"result":{"scanned":[{"737167333":23}]}}

A fire command fire hit the first robot in in the direction of the tower


curl -s -d '{"type":"fire", "id":328610546}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":730700238,"battle":173310470,"name":"MrRobot","x":95,"y":0,"angle":1,"aim":77,"energy":20},"result":{"damaged":[{"737167333":-15}]}}

A nop command does nothing. It should be used if you don't want to do an operation in a specific turn because simulation will complete faster when all robots has sent a command.

curl -s -d '{"type":"nop", "id":328610546}' -H "Content-Type: application/json" -X POST
# => {"robot":{"id":730700238,"battle":173310470,"name":"MrRobot","x":95,"y":0,"angle":1,"aim":77,"energy":20},"result":{"nop":"empty"}}

The order of execution of commands is the following:

  1. walk
  2. turn and aim
  3. scan and fire

Commands can be sent until only one robot has energy above zero. At this stage the battle is finished.

The game master can check the battle status via ping.

curl -s -d '{"type":"ping", "id":787352956}' -H "Content-Type: application/json" -X POST
# => {"id":787352956,"width":100,"height":100,"timeout":1000,"state":"finished"}

After that the game master can close the game.

curl -s -d '{"type":"close", "id":328610546}' -H "Content-Type: application/json" -X POST`
# => {"battle":{"id":753756259,"width":100,"height":100,"timeout":1000,"state":"closed",,"created":"2019-02-10T17:54:05Z"},"robots":[{"id":795767293,"battle":753756259,"name":"MrRobot","x":18,"y":82,"angle":108,"aim":60,"energy":0},{"id":475298804,"battle":753756259,"name":"Rand1","x":30,"y":99,"angle":82,"aim":12,"energy":0},{"id":93040013,"battle":753756259,"name":"Rand2","x":26,"y":79,"angle":335,"aim":251,"energy":52}]}

After a game has finished the game simulation data can be retrieved and allow clients to visualise the battle progress.


curl -s -d "{"type":"simdata", "id":787352956, "step":0}" -H "Content-Type: application/json" -X POST $HOST/simdata`
# => [{"meta":{"battle_id":787352956,"step":0,"robot_id":663512003},"command":{"type":"walk","id":663512003,"steps":2},"robot":{"id":663512003,"battle":787352956,"name":"MrRobot","x":68,"y":1,"angle":253,"aim":289,"energy":100},"result":{"walk":{"x":-1,"y":-2}}},{"meta":{"battle_id":787352956,"step":0,"robot_id":212732548},"command":{"type":"fire","id":212732548},"robot":{"id":212732548,"battle":787352956,"name":"Rand1","x":85,"y":60,"angle":0,"aim":14,"energy":100},"result":{"damaged":[]}},{"meta":{"battle_id":787352956,"step":0,"robot_id":737167333},"command":{"type":"fire","id":737167333},"robot":{"id":737167333,"battle":787352956,"name":"Rand1","x":36,"y":84,"angle":336,"aim":158,"energy":100},"result":{"damaged":[]}}]

Random test robots

If you want to test a full battle I have built a naive/random robots that "fight to the power-down".

There is one master script that control the battle and start each robot. The robots also have their own script.

These scripts are dependent on ksh and jq.

There is also an example robot in ruby and python.

It takes a few minutes for these stupid robots to kill each other off. Surely your robot can do better?

Try it!

Battle Visualization

A visualisation engine has been made to show the progress of a battle.

Check it out here:

You can change battle and step and run simulation by the simple input fields.

Press Run to animate the battle.