RESTful Web API for managing multiple concurrent TicTacToe games.
The project is split into 3 parts:
- TicTacToe library: Defines the logic for a single game.
- Game Manager: Manages multiple games at a time.
- Web API: Defines the API and launches the web server, handling all HTTP requests and responses.
- API testing.
- Authentication: Anyone can make a request to play as either nought or cross on any game. Play nice (for now)!
- Persistent storage: There is no database to store the game data if the server goes down. All is within memory, and resets when server does. Careful!
- GUI: No flashy frontend yet. Please play using your favourite API tool.
- Install Go.
- Clone and run:
git clone https://github.com/Frezzle/noxes
go run noxes/server.go
- Play using the API. The web server listens on http://localhost:9876 by default.
Unit tests can be run with go test noxes/...
All endpoints, upon some failure, return an error response:
{
"error": "some error message"
}
Creates a new game instance.
Response:
{
"id": "0"
}
id
- Uniquely identifies the new game instance.
Gets the state of an existing game, given a game id
. Unfortunately, the /game
endpoint currently requires a GET method with a body, so you must use tools which allow providing a body in a GET request (i.e. not Swagger Inspector).
Request:
{
"id": "0"
}
id
- Uniquely identifies an existing game instance.
Response:
{
"id": "0",
"board": "---------",
"nextTurn": "X",
"gameOver": "false",
"winner": "-"
}
id
- Uniquely identifies the game instance.board
- 9-character string representing the cells of the board, withX
,O
, and-
being Cross, Nought and empty respectively. Each string index is mapped to a position on the board:0 | 1 | 2 ----------- 3 | 4 | 5 ----------- 6 | 7 | 8
nextTurn
- who is next to play;X
orO
.X
always starts.gameOver
-true
orfalse
, signifying if a game is over. The game ends when a player achieves 3-in-a-row or a draw occurs.winner
- who won the game. Starts with noone as the winner (-
), becomingX
orO
if someone wins; stays as-
if game ends as a draw.
Gets the state of all existing games.
Response is an array of zero or more games:
[
{
"id": "0",
"board": "---------",
"nextTurn": "X",
"gameOver": "false",
"winner": "-"
},
{
"id": "1",
"board": "---X-----",
"nextTurn": "O",
"gameOver": "false",
"winner": "-"
}
]
See GET /game for the meaning of each game's attributes shown above.
Play a move on an existing game.
Request:
{
"gameId": "0",
"player": "X",
"location": "4"
}
gameId
- Identifies the game instance where you'd like to play the move.player
- The side you are playing as; eitherX
orO
.location
- The cell which you'd like to place your move. The board cells are mapped from 0 to 8:0 | 1 | 2 ----------- 3 | 4 | 5 ----------- 6 | 7 | 8
If your move was successful then the response is a 200 OK
status with no body.
How many valid board permutations are there for a TicTacToe game?
go run noxes/permutations/permutations.go