Giter Club home page Giter Club logo

mancala's Introduction

About

Mancala (a.k.a Kalah) is a turn-based board game played by two player. The main goal is capturing opponent's stones. This project is a java implementation of six-stone mancala game.

Architecture

  • Project structure is built upon hexagonal architecture.
  • There are three main package in abstract way:
    • Application package: Real world contact of the project with rest controllers, requests and responses
    • Domain package: Main business logic holder with some set of layers
    • Infrastructure package: Base configurations and interceptors
  • All objects in the project are strictly immutable to avoid any concurrency inconveniences.
  • Exception handling is solved by Spring's global handling interceptor @RestControllerAdvice.
  • Localization in english and dutch is provided to get error messages in requested locale. ?locale=en or ?locale=nl query parameters give the ability.
  • There are 85 tests in project to be sure everything is working. Four main testing type is used:
    • Rest Integration Tests: To initialize spring application context and to hit the endpoint
    • Functional Tests: To initialize spring application context and to test the service and its deeper layers
    • Concurrent Functional Tests: To initialize spring application context and to test the service and its deeper layers with concurrent requests
    • Unit Tests: To test if component under-test is working

How to run

  • Run command: git clone https://github.com/kahramani/mancala.git
  • Go to project's path
  • Run command: ./mvnw clean install
  • Run command: java -jar target/mancala-1.0.0.jar
  • Project will listen requests from port 8080

How to play

  • Be sure project is up and running.

  • Then you can run curl --header "Content-Type: application/json" \ --request POST \ http://localhost:8080/v1/games to create a game. Creation endpoint will return HTTP code: 201, ResponseBody: {"id": {GAME_ID},"uri": "http://localhost:8080/games/{GAME_ID","playerId": {STARTER_PLAYER_ID}

  • Save returned {GAME_ID} and {STARTER_PLAYER_ID} which will be required parameter to make a move. Share {GAME_ID} with your friend.

  • To be a participant, your friend can run curl --header "Content-Type: application/json" \ --request PUT \ http://localhost:8080/v1/games/{GAME_ID} and then will get HTTP code: 200, ResponseBody: {"uri": "http://localhost:8080/games/{GAME_ID","playerId": {PARTICIPANT_PLAYER_ID}

  • Then you can make a move with curl --header "Content-Type: application/json" \ --request PUT \ http://localhost:8080/v1/games/{GAME_ID}/players/{PLAYER_ID_TO_MAKE_MOVE}/pits/{PIT_ID}. Make a move endpoint will return HTTP code: 200, ResponseBody:{"id": "DVLYFVIHY845V406","uri": "http://localhost:8080/games/DVLYFVIHY845V406","status": {"1": "0","2": "7","3": "7","4": "7","5": "7","6": "7","7": "1","8": "6","9": "6","10": "6","11": "6","12": "6","13": "6","14": "0"},"turnRepeat": false}

  • Predefined Rules:

    • Starter player will be the first move maker.
    • {PIT_ID} from 1 to 7 will be game starter player's pits with kalah (id: 7).
    • {PIT_ID} from 8 to 14 will be game participant player's pits with kalah (id: 14).
    • status gives you current status of the mancala board (where keys are {PIT_ID}s, values are stone count).
    • turnRepeat in response tells you if you get another turn to make a move.
    • In case of error, api will return errorCode and errorMessage with proper Http status code.

Tech Stack

Tech Version
JDK 1.8
Spring Boot 2.0.0.RELEASE

mancala's People

Watchers

James Cloos avatar Ibrahim Kahraman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.