Tic Tac Toe - API
This Tic Tac Toe game has a grid of 3x3, the playerIds are "X" and "O". At the moment, it doesn't validate the player turns, i.e. any player can take more than one turn at a time.
This API exposes three endpoints:
- GET /state
- GET /players
- POST /turn
$ ./gradlew build && java -jar build/libs/tictactoe-0.0.1-SNAPSHOT.jar
Returns the current state of the board as a Map of String key and values. key is the position and value is the playerId.
Sample response
Initial state is:
{
"0": null,
"1": null,
"2": null,
"3": null,
"4": null,
"5": null,
"6": null,
"7": null,
"8": null,
"9": null
}
Returns a list of the available players.
Sample response
[
{
"id": "X",
"description": "Player 1"
},
{
"id": "O",
"description": "Player 2"
}
]
Called every time a player takes a turn on the board.
There are validations on both fields used in the POST payload.
{
"playerId" : "X",
"position" : 5
}
gameOver
field will be false as long as the game is ongoing.
{
"gameOver": false,
"winner": null,
"state": {
"0": null,
"1": null,
"2": null,
"3": null,
"4": null,
"5": "X",
"6": null,
"7": null,
"8": null,
"9": null
}
}
Once there is a winner POST requests will still be 200 and return the winner, but they will not affect the state of the board.
gameOver
- true once there is a winner in the game.winner
- contains the winner.
{
"gameOver": true,
"winner": {
"id": "X",
"description": "Player 1"
},
"state": {
"0": "X",
"1": "X",
"2": "X",
"3": "O",
"4": "O",
"5": null,
"6": null,
"7": null,
"8": null,
"9": null
}
}
- Validate that players take alternate turns.
- Endpoint to reset the game