Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
/ mastermind Public archive

Implementation of the mastermind game 🕹️through a REST API.

Notifications You must be signed in to change notification settings

adriancarayol/mastermind

Repository files navigation

Mastermind

Implementation of an API REST with Django + PostgreSQL for the game mastermind.

forthebadge made-with-python

Introduction

Mastermind is a code-breaking game for two players. One player becomes the codemaker , the other the codebreaker . The codemaker chooses a pattern of four color code pegs (duplicates allowed) and the codebreaker tries to guess it, in both order and color. Each guess is made by placing a row of color code pegs on the decoding board. Once placed, the codemaker provides feedback by placing from zero to four key pegs in the small holes of the row with the guess. A black key peg (small red in the image) is placed for each code peg from the guess which is correct in both color and position. A white key peg indicates the existence of a correct color code peg placed in the wrong position.

Getting started

With these instructions you can run the API REST locally, or run it for a pre-production/production environment.

Prerequisites

You will need dockers and dockers compose to be able to run the project easily.

You can find out how to install both at the following links: Docker and Docker compose

Abstract structure

This project was created under nginx, gunicorn and postgresql: structure

Deployment

After that, you'll be able to run the API REST with the following commands:

  • For development environment:

    make dev

    or

    docker-compose -f docker-compose.dev.yml build
    docker-compose -f docker-compose.dev.yml up -d
  • For pre-production environment:

      make preprod

    or

    docker-compose -f docker-compose.preprod.yml build
    docker-compose -f docker-compose.preprod.yml up -d
  • For production environment:

      make prod

    or

    docker-compose -f docker-compose.prod.yml build
    docker-compose -f docker-compose.prod.yml up -d

Checking logs

To check the application logs, the following commands are useful:

docker ps
...
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
cf81984103dc        mastermind_api                     sh -c '/wait && ..."     3 days ago          Up 20 seconds       80/tcp
...
docker logs cf81984103dc

Running the tests (Coverage included)

$ .../mastermind/: pytest

Running pylint

$ .../mastermind/: pylint api/ code_peg/ game/

Running black

$ .../mastermind/: black api/ code_peg/ game/

Principal endpoints

Examples

Creating a new game

On /api/users, creates a new user (you'll need two): create-user On /auth/login/ Authenticate with the created user: auth-user Create the new game on /api/games: new-game Submit the game solution on /api/pegs peg With the other user, submit the another code peg.

Checking the historic game.

On /api/games get the ID of the game. On /api/games/<ID>/historic, you'll will see all the code pegs submitted.

Built with

  • Django
  • PostgreSQL
  • DjangoRestFramework

Code style

  • Black
  • Pylint

Authors

About

Implementation of the mastermind game 🕹️through a REST API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published