Battleship is played in two stages :

At each turn, the arena made HTTP(s) queries containing POST parameters, to your bots.
They must respond to the specifications below.

Descriptif des paramètres envoyés par l'arène

Parameter Description
game String, will always "Battleship".
Can be used if your url is used for several games.
match_id String. Match the following regular expression : ^[0-9]+-(1|2)$
The first number (digits before the hyphen) identified the game.
The number after the hyphen indicates whether you are the first or second bot in the order to play.
It will serve you if your AI makes statistics on games.
act Can take two values :
  • "init" : We start the game, you must place your ships
  • "fight" : You send a shot
opponent String identifying your opponent.
So you can grow up delirium by developping an algorithm that adapts depending on the opponent and the history of fighting with it.
width Integer, between 1 and 100, inclusive, indicates the width of the map.
height Integer, between 1 and 100, inclusive, indicates the height of the map.
ship1 Integer, between 0 and 10, inclusive, indicates the number of boats with length of 1 box to set.
ship2 Integer, between 0 and 10, inclusive, indicates the number of boats with length of 2 box to set.
... ...
ship6 Integer, between 0 and 10, inclusive, indicates the number of boats with length of 6 box to set.
your_strikes

String, representing an array in JSON format.
This parameter is only sent when the game is in shooting phase (act=fight).
It tells you the shots you've already made and their results.
In the first round of play, it is an empty array.

[ ]

In the second round of game, it contains the previous shot and the result :

[{"target":"2,0","result":""}]

In the third round of play, the two previous shots :

[{"target":"2,0","result":"hit"},{"target":"5,1","result":"hit"}]

Each shot is a sub array for which :

  • The index target indicates the coordinates of the target shooting x,y
  • result may be :
    • Empty "" means that the shot did not hit anything
    • "hit" An enemy ship has been hit
    • "hit and sunk" An enemy ship was hit and sunk
his_strikes Same except that this is the shot of the opponent.

What must return your bot

During initialization of the game

Lors de l'initialisation d'une partie StupidIA VS StupidsIA, l'arène a envoyé au bot les parametres POST suivants : During initialization of part StupidIA VS StupidIA, the arena send to your bot the following parameters in POST :

    game=Battleship&match_id=828-1&act=init&opponent=stupidIA&width=10&height=10&ship1=0&ship2=1&ship3=2&ship4=1&ship5=1&ship6=0

Or, more readable :

    [game] => Battleship
    [match_id] => 828-1
    [act] => init
    [opponent] => stupidIA
    [width] => 10
    [height] => 10
    [ship1] => 0
    [ship2] => 1
    [ship3] => 2
    [ship4] => 1
    [ship5] => 1
    [ship6] => 0

The HTTP page that must generate your bot contains the position of ships.

You return a character string that is a JSON array with as many records as ships.
Each ship is defined by the coordinates of its ends.

Placement example of 5 boats with respective sizes 5, 4, 3, 3, 2 boxes :

    ["3,3-3,7","2,1-2,4","0,1-0,3","7,3-7,1","8,8-7,8"]

Of course if your boat overlap, or if their number and length does not match the demand of the arena, you lose the game.

The order of the boats does not matter.
Similarly, for a boat, the order of its points does not matter either.

Seen on the grid, the example above would be :

0 1 2 3 4 5 6 7 8 9
0
1
2
3
4
5
6
7
8
9

During the fight

Examples of parameters sent by the arena.

First round (your_strikes and his_strikes are empty)

    [game] => Battleship
    [match_id] => 834-1
    [act] => fight
    [opponent] => stupidIA
    [width] => 10
    [height] => 10
    [ship1] => 0
    [ship2] => 1
    [ship3] => 2
    [ship4] => 1
    [ship5] => 1
    [ship6] => 0
    [your_strikes] => []
    [his_strikes] => []

Second round

    [game] => Battleship
    [match_id] => 834-1
    [act] => fight
    [opponent] => stupidIA
    [width] => 10
    [height] => 10
    [ship1] => 0
    [ship2] => 1
    [ship3] => 2
    [ship4] => 1
    [ship5] => 1
    [ship6] => 0
    [your_strikes] => [{"target":"4,6","result":""}]
    [his_strikes] => [{"target":"7,8","result":""}]

Third round

    [game] => Battleship
    [match_id] => 834-1
    [act] => fight
    [opponent] => stupidIA
    [width] => 10
    [height] => 10
    [ship1] => 0
    [ship2] => 1
    [ship3] => 2
    [ship4] => 1
    [ship5] => 1
    [ship6] => 0
    [your_strikes] => [{"target":"4,6","result":""},{"target":"3,9","result":"hit"}]
    [his_strikes] => [{"target":"7,8","result":""},{"target":"7,8","result":""}]

You simply need to return the address of the box where you want to shoot in the form of x,y

    6,9

To shoot on the coordinates x=6 y=9