Mancala game project
Client: React, TailwindCSS
Server: Java 11, Spring boot, Spring WEB, Lombok, JPA, H2
Clone the project
git clone https://gitlab.com/bolcom/ahmed-aziz.git
Go to the project directory
cd ahmed-aziz
Build the application
mvn clean package
Start the server
mvn spring-boot:run
Application will start on localhost:5000
Rest Method | EndPoint | Description |
---|---|---|
GET |
/mancala/api/v1/create-game |
Start the Game |
DELETE |
/mancala/api/v1/delete-game/{gameId} |
Delete the Game |
POST |
/mancala/api/v1/update-game |
Update the Game |
- The stones can be adjusted in the property file. Currently, it is set to 6.
- The Player opens the web app URL in the browser, localhost:5000. The first player turn will be randomly generated.
- Spring boot will serve the front-end files in the static directory and show them in the browser. It uses a maven front-end plugin that will take care of building the React front-end application and place it in the correct static directory.
- When the front-end be loaded in the browser, it will make an immediate REST call to get a new game by calling the endpoint mancala/api/v1/create-game.
- The game will be loaded and ready to play.
- The Player may reset the game any time he/she wants. Resetting the game means technically:
- Deleting the game from the database in the back-end.
- Refreshing the browser in the front-end and getting a new game.
- If the customer chooses one of his/her pits, a request will be sent to the backend with the selected pit name, and game ID.
- If the player didn't choose one of his/her pits, an error will occur with the message: "Please choose your pits!".
- The player can't choose the Big pits from the front-end. But, if there is a request done via curl, postman, or something else, with the big pit index, an error will occur with the message: "Please use another Pit! The Big one is not allowed to be used".
- The player can't choose outside the game pits size range. But if there is a request done via curl, postman, or something else, without index, an error will occur with the message: "The selected index is not within the game range!".
- If the player chooses the correct pits:
- The game ID will be sent to the backend to retrieve the game from the database.
- The stones will be taken from the selected pit so that the selected pit will be emptied.
- One stone will be added to each next pit till there are no stones left. Big pits will be skipped for the opponent player.
- If the loop end at the last index of the game, and there are still stones left, restart the index to zero.
- The next player will be the opposite of the current player. Only if the last stone end at the own big pit of the player, he/she may have one more turn.
- At the end of the turn and before returning the updated game, the game will check for the winner. It checks the list of the pits of each player if they are empty. If one of the pit lists of one of the players is empty, compare the total amount of each big pit, the one who has the most amount of stones wins. The sum will be counted based on all the stones available. So even if player 1 ends the game and player 2 has in total (big pit + all the stones in the other pits) is more than player 1 big pit, player 2 wins.
- If the count of the stones is equal for both big pits, the one who ends the game wins.
- If there is a winner, that means the game will end, and the application will delete the game from the database. It will return an updated game response with a filled field "PlayerWinner". The front-end will be checking this field for every response, and when it finds that this field is filled, it will show the winning message to the players with the winner player and end the game.
- If there is no winner, the application will save the game in the database and return the list of the updated game to the frontend. The "PlayerWinner" field will remain empty.