Skip to content

jeancedron/mancala-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mancala Game

This is an implementation of the Mancala game for a challenge in some-random-company.com. In this game, there are two players with 6 small and 1 big pit each one. Each of the small pits are filled with six stones. Every turn, each player choose one of their small pits to sow its stones into the next sow sequentially. The game finishes when a player doesn't have any move available. The winner is the player with the most quantity of stones into its big pit.

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Installation

  1. Clone the repo
    git clone https://gitlab.com/bolcom/jean-pierre-cedron.git
  2. Start with Maven spring-boot plugin
    ./mvnw spring-boot:run

Architecture

This project has been developed using an Hexagonal Architecture with ports and adapters to inverse the dependencies around the domain. This architecture avoids having anemic domain models and allows scalability as the core business logic doesn't care anything about the infrastructure used. We can easily change framework, database, REST API, etc. without touching the domain.

For more reference, please refer to this Netflix blog post

Usage

This application exposes 4 endpoints to create and play a Mancala game. You can: create game, get a game, list movements available and execute a movement for a player.

Create game

To create a game, the API requests for two players to begin. The response is a Game entity.

POST /games

Request

{
    "player_a": "Jean",
    "player_b": "some-random-company.com"
}

Response

{
    "id": "613e9feed346aa32900cf81c",
    "players": [
        {
            "name": "Jean",
            "position": 1
        },
        {
            "name": "some-random-company.com",
            "position": 2
        }
    ],
    "state": "STARTED",
    "pits": [
        7, 7, 7, 7, 7, 0, 1, 7, 7, 7, 7, 7, 0, 1
    ],
    "next_player": {
        "name": "Jean",
        "position": 1
    },
   "winner": null
}

Get a game

To get a game, the API requests the id of the game as path variable. The response is a Game entity.

POST /games/:id

Response

{
    "id": "613e9feed346aa32900cf81c",
    "players": [
        {
            "name": "Jean",
            "position": 1
        },
        {
            "name": "some-random-company.com",
            "position": 2
        }
    ],
    "state": "STARTED",
    "pits": [
        7, 7, 7, 7, 7, 0, 1, 7, 7, 7, 7, 7, 0, 1
    ],
    "next_player": {
        "name": "Jean",
        "position": 1
    },
   "winner": null
}

List available moves

This endpoint returns the available moves for the current player. The response is a list of Move entity.

GET /games/:id/moves

Response

{
   "moves": [
      {
         "pit": 7,
         "stones_available": 7
      },
      {
         "pit": 8,
         "stones_available": 7
      },
      {
         "pit": 9,
         "stones_available": 7
      },
      {
         "pit": 10,
         "stones_available": 7
      },
      {
         "pit": 11,
         "stones_available": 7
      },
      {
         "pit": 12,
         "stones_available": 6
      }
   ],
   "player": {
      "name": "some-random-company.com",
      "position": 2
   }
}

Execute movement

Executing a movement only requires the pit index to begin sowing the stones into the next pits. The response is a MoveResult entity.

POST /games/:id/moves

Request

{
   "pit": 12
}

Response

{
   "winner": null,
   "play_again": false,
   "next_player": {
      "name": "some-random-company.com",
      "position": 2
   }
}

Contact

Jean Cedron - jean.cedrons@gmail.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages