Your challenge is to write a bot to play the Hexagon dots game. Your bot will play the game using HTTP requests with JSON-encoded payloads. The bot who beats the most opponents wins.
A game is played on a hexagonal board between two players (bots). On a player's turn, they draw a new line between two dots on the board. If the new line completes a hexagon, the player captures the hexagon and has another turn. The player with the most captured hexagons at the end of the game wins.
The game ends when all possible lines have been drawn.
An fresh 3 row x 5 column board:
o o o o o o o o o o o o o
Note that rows alternate between short and long rows. The top row is always short and the bottom row is always short -- all boards have an odd number of rows.
Points on the board are indexed using a hexagonal coordinate system. The top row is row 0, the next row down is row 1 and so on. The left-most point in each row is column 0. Given this 3 row x 3 column board:
A B C D E F G
The points would be addressed as follows:
Point | Row | Col |
---|---|---|
A | 0 | 0 |
B | 0 | 1 |
C | 1 | 0 |
D | 1 | 1 |
E | 1 | 2 |
F | 2 | 0 |
G | 2 | 1 |
If a player (bot) attempts a disqualifying move, they lose the game immediately. Following are disqualifying moves:
It is illegal to draw a line on a line that has already been drawn.
If the board is currently in this state:
A B---C D / \ E F G H I \ / J K---L M
It would be illegal to draw a line using G as an endpoint.
Once notified that it is your turn, you have 5 seconds to submit your move. Failing to do so results in immediate loss.
It is illegal to draw a line outside the board.
The game server uses HTTP with JSON payloads for both responses and request. Following is a typical game request/response example and the list of available commands and their responses.
Client Server POST / {rows: 5, cols: 3} -> 201 Created <- Location: /foobar POST /foobar/players {name: "Bot1"} -> 200 OK X-Turn-Token: gorilla {rows: 5, cols: 3, lines: [], hexagons: [], players: [...], <- state: 'in play'} POST /foobar/moves X-Turn-Token: gorilla [{row: 0, col: 0}, {row:0, col:1}] ->
Payload:
{rows: <integer>, cols: <integer>}
Creates a new game of the given dimensions.
Response Headers:
Location: The <game_url> for the create game
If the game is succesfully created. The created game will be in the
initiating
state. The Location
HTTP header is the url for the created
game.
If there is an error creating the game.
Payload:
{name: <string>}
Tells the server you'd like to join the game at <game_url>
with the player
name given.
Response Headers:
X-Turn-Token: A token you need to pass back on your next move
Payload:
<Game> object
This indicates that it's your turn to play. The game is now in the in play
state. You must use the received X-Turn-Token
when submitting the next
move.
Indicates that the game is full. Find another game.
Headers:
X-Turn-Token: <Previous-X-Turn-Token>
Payload:
[<Coordinate>, <Coordinate>]
The payload indicates the line you'd like to draw.
Response Headers:
X-Turn-Token: A token you need to pass back on your next move
Payload:
<Game Delta>
This indicates that it's your turn to play again. You must use this new
X-Turn-Token
in your next <game_url>/moves
request.
``403 Forbidden` (response)
Payload:
An error describing your violation.
You lose.
{name: <string>, score: <integer> or 'disqualified'}
{rows: <integer>, cols: <integer>, lines: [<Line>*], hexagons: [<Hexagon>*], players: [<Player>*], state: <Game State>}
'initiating', 'in play', or 'completed'
{endpoints: [<Coordinate>, <Coordinate>] owner: <Player>}
Coordinates in responses will always be sorted in row-major order (Coordinates are sorted by row, then Coordinates with the same row are sorted by col).
owner
is the player that placed the line.
{row: <integer>, col: <integer>}
{center: <Coordinate>, owner: <Player>}
Represents a claimed Hexagon on the board. The six triangles surrounding the
center Coordinate
are assigned to the owner.