Robot Wars

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"}

As soon as opponents are informed about the battle identity, they can join. A robot configuration is returned.

curl -s -d '{"type":"enter", "id":787352956}' -H "Content-Type: application/json" -X POST
# => {"id":328610546,"battle":787352956,"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 run from a single computer or from different computers.

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]}

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

When game master is ready to start the battle e.g. based on number of entrants or time the battle is started.

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

Robots also need to wait until the battle has been started. This can also be checked via 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.

Robots can then send commands with a maximum timeout of 1000 ms. Failing to send a command within 1000 ms is the same as sending a nop (no operation) command.

The following commands can be sent:

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

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

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},"aim":10}

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

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

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

Commands can be sent until only one robot has energy higher than 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"},"robots":[{"id":795767293,"battle":753756259,"x":18,"y":82,"angle":108,"aim":60,"energy":0},{"id":475298804,"battle":753756259,"x":30,"y":99,"angle":82,"aim":12,"energy":0},{"id":93040013,"battle":753756259,"x":26,"y":79,"angle":335,"aim":251,"energy":52}]}

During or after a running game simulation data can be retrieved allow a client to visualize the battle. But this yet to do.

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.

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.