This project is an API for handling games of tic-tac-five. Normal tic-tac-toe, but with 5 in a row and a much larger board! A frontend which uses the api can be found here.
The games are stored in the database with the Game model. A game contains a board of 21*21 squares, and starts with an X in the center. Every game contains these data fields:
_id
: The ID of the game.name
: The name of the game (Chosen when the game was created).boardState
: The state of the board. An array consisting of 21*21 values which can be "O", "X" or "-" (nothing).nextToMove
: Can be either "O", "X".null
if the game is over.history
: The games history (all moves played) as a list of elements of the form[xPos, yPos, player]
.xPos
andyPos
are values between 0 and 20, whileplayer
can be either "O" or "X".winner
: "O" or "X" if the game is over, elsenull
.winningLine
: An array of the 5 squares included in the winning line. If the game is not won, it will benull
.timeStarted
: The time the game was created.lastMoveMade
: The time recorded last time the game state was updated.
To interact with the game, these endpoints should be used
Returns a list of all games which are not finished. The games returned will have all information except the history.
Requires the parameter name
. Creates a game and returns it to the user.
Returns all information about the game with the given game_id
. Returns 404 if the game does not exist.
Requires the parameters xPos
, yPos
and player
. xPos
and yPos
should be integers between 0 and 20 (including both 0 and 20). player
should be either "O" or "X". The API will return the next state of the game and will contain a field "error"
if the move is illegal.
For the project to run you need to have a local mongoDB database running. On a mac, this can be done by following the steps here.
You can then clone this repository to your machine and run:
npm install
Before running
npm start
To run the tests, make sure a local mongoDB database is running and run the command npm test
. The test are written with jest
and supertest
.