Skip to content

TicTacToe

Mike Leonard edited this page Jul 12, 2016 · 33 revisions

Introduction

Tic-tac-toe (also known as Noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game - Wikipedia, Tic-tac-toe

To implement a Tic-Tac-Toe, your bot must support receiving of RPCs - the current game state will be passed to you each time TicTacToe.NextMove is RPC'd and you need to return the position of your next move.

The RPCs you need to support are:

Game Board

The game board, when passed to you as the current game state will be represent as an array with each position in the array corresponding to the diagram below. You will respond with the position in which you want to make your next move.

       |       |   
   0   |   1   |   2
       |       |   
-----------------------
       |       |   
   3   |   4   |   5
       |       |   
-----------------------
       |       |   
   6   |   7   |   8
       |       |   

Bot Registration

To register your bot with Merknera you will need to call RegistrationService.Register. This must be called each time you bot starts up. Details of this RPC can be found here.

Use TICTACTOE as the value of the game property in the Register request body.

RPCs

Your bot must support the following RPCs on the same URL endpoint. All requests will be of the HTTP method POST and will send the Content-Type: application/json header.

Status.Ping (server)

With this request your bot acts as the server.

Status.Ping will be invoked on your bot to ensure that it is currently online. This RPC is standard across all bots and full documentation can be found here.

TicTacToe.NextMove (server)

With this request your bot acts as the server.

TicTacToe.NextMove will be called to get the position on the board for where you wish to place your next mark. You will be passed the current state of the board. This RPC will be called when it is your turn to play.

Request Body
{
   "jsonrpc": "2.0",
   "method": "TicTacToe.NextMove",
   "params": {
       "gameid": 78,
       "mark": "X",
       "gamestate": ["O", "X", "O", "", "O", "", "", "X", ""]
   },
   "id": 1
}
Parameter Description
gameid The ID of the current game. This will be the same for all calls of TicTacToe.NextMove within the same game.
mark The mark that has been allocated to you either "X" or "O".
gamestate An array indicating where plays have currently been made. Index 0 of the array is the top left most space on the board and the 8th index bottom right most space. See the above game board diagram above for number positions. Empty strings will be passed for spaces that have not yet been played.
Response Body
{
   "jsonrpc": "2.0",
   "result": {
       "position": 7
   },
   "error": null, // Only present if an error occurs
   "id": 1
}
Result Description
position The position of your next move according for the game board diagram above.

TicTacToe.Complete (server)

With this request your bot acts as the server.

TicTacToe.Complete will be called when the game is complete and you will be told if you were the winner or not. You will be passed the final game state.

Request Body
{
   "jsonrpc": "2.0",
   "method": "TicTacToe.Complete",
   "params": {
       "gameid": 21,
       "winner": true,
       "mark": "X",
       "gamestate": ["O", "X", "O", "", "O", "X", "O", "X", ""]
   },
   "id": 1
}
Parameter Description
gameid The ID of the current game. This will be the same for all calls of TicTacToe.Complete within the same game.
winner true or false - true if you won the game, false if you lost the game.
mark The mark that has been allocated to you either "X" or "O".
gamestate An array indicating the final game state of where plays have been made. Index 0 of the array is the top left most space on the board and the 8th index bottom right most space. See the above game board diagram above for number positions. Empty strings will be used for spaces that have not been played.
Response Body
{
   "jsonrpc": "2.0",
   "result": {
       "status": "OK"
   },
   "error": null, // Only present if an error occurs
   "id": 1
}
Result Description
status Return the hardcoded value "OK" to indicate that you received the response.

TicTacToe.Error (server)

With this request your bot acts as the server.

TicTacToe.Error will be called when an error in the game is caused by you. For example, playing an illegal move. If this is invoked then you bot will be marked as error and no games will be played until RegistrationService.Register is called again and your bot is brought back online. You need to simply respond successfully with the JSON found below and it is up to you as to what you do with this information.

Request Body
{
   "jsonrpc": "2.0",
   "method": "TicTacToe.Error",
   "params": {
       "gameid": 21,
       "message": "You played an invalid move, 'X' was already played here.",
       "errorcode": 1548
   },
   "id": 1
}
Parameter Description
gameid The ID of the current game. This will be the same for all calls of TicTacToe.Error within the same game.
message A message detailing the error.
errorcode A code indicating the type of error that occurred.
Response Body
{
   "jsonrpc": "2.0",
   "result": {
       "status": "OK"
   },
   "error": null, // Only present if an error occurs
   "id": 1
}
Result Description
status Return the hardcoded value "OK" to indicate that you received the response.
Clone this wiki locally