Fifteen

Fifteen is a 4x4 slide puzzle. Your goal is to arrange the tiles in order (left to right, top to bottom) with 1 in the upper left corner and the blank tile in the bottom right corner. The game sends you a randomized starting state. You send back moves to solve it.

Goal!
| 1| 2| 3| 4|
| 5| 6| 7| 8|
| 9|10|11|12|
|13|14|15|  |

Websocket Endpoint

The endpoint is delivered over SSL (use wss://). It is authenticated and checks that you own the game, so you need to be logged in.

wss://pointatinfinity.com/fifteen/ws

Messages

The server sends and receives JSON. The server will send the game state upon connection. It will also send the game state as a reply to every move your bot makes.

State

The state contains three fields, Score, Board, and Status. An example state is as follows.

{
    "Score": 0,
    "Board": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0],
    "Status": "playing"
}

Score is an integer that is incremented each time you send a move to the server.

Board is an array of integers representing the tiles on the board. Indices 0 through 3 are the first row. Indices 4 through 7 are the second row... you get the idea. The numbers 0 through 15 will be in the array representing the position of the tiles. The zero tile is the blank tile.

Status is a string to let you know the game state. The statuses sent by the server are as follows.

Move

You send moves to the server. This structure contains a single field Move which is a string. Valid moves are up, down, left, and right. These move the blank tile in their respective direction. An example move is as follows.

{
    "Move": "left"
}

The Win

When you win the game (only in Fifteen, not Eight) the game will wait 10 seconds for you to send two unsigned 64 bit integers (State0 and State1) in the following JSON structure. These integers are used as the seed state for the XorShift128+ algorithm.

{
    "State0": 14970488896328355506, 
    "State1": 13029378197679949805,
}

The algorithm is run 5 times using these values as the seed value. The output uint64 is then converted to a string. The valid character class is [A-Za-z0-9]. The string produced by this is placed onto the leaderboard as your username.

If you want to get on the leaderboard but haven't gotten the numbers for your own username yet, you can visit the faucet for a random name.

Caveats

Websocket times out after 2 minutes. Send invalid moves if you need to keep it alive while your solver runs.

Sending invalid messages (e.g. stuff that isn't JSON) will cause a disconnect.

The leaderboard is sorted by score (low to high) and most recent. A lower score and more recent solve will be higher.

User    Score   Time
--------------------
UserD   24     2018-10-31
UserA   24     2018-10-30
UserB   80     2018-10-31

Javascript numbers are 53 bit precision, so you might want to build the leaderboard message as a string so your numbers don't break.