Giter Site home page Giter Site logo

mastermind's Introduction

Mastermind game

Mastermind game via REST API done with Django and Django REST Framework.

Build Status

Coverage Status

Prerequisites

  • Python 3.6 with a new virtual environment (for local testing and development)
  • Docker (optional)
  • Travis CLI (optional)

Environment variables setup

VARIABLE NAME DEFAULT VALUE NEEDED IN PRODUCTION NEEDED IN LOCAL ACCEPTED VALUES
DJANGO_SECRET_KEY (in config file) YES YES string
DJANGO_CONFIGURATION Local YES YES Local, Production, Test
DJANGO_SETTINGS_MODULE mastermind.config YES YES n/a
DATABASE_NAME postgres YES YES string
DATABASE_USER postgres YES YES string
DATABASE_PASSWORD YES YES string
DATABASE_HOST db YES YES string
DJANGO_AWS_ACCESS_KEY_ID YES NO string
DJANGO_AWS_SECRET_ACCESS_KEY YES NO string
DJANGO_AWS_STORAGE_BUCKET_NAME YES NO string

Local Development

Using python and python virtualenv

Install project dependencies:

pip install -r requirements

Migrate database:

python manage.py migrate

Create a test admin user:

python manage.py createsuperuser --username my_user_name

Start the development server:

python manage.py runserver

Using docker and docker-compose

Start the dev server for local development:

docker-compose up -d

To run a command inside the docker container:

docker-compose run --rm web [command]

Therefore, to create the first admin user in Djanjo console:

docker-compose run --rm web bash

$ python manage.py createsuperuser --username my_user_name

Continuous Deployment

Deployment can be automated via Travis, CircleCI, Jenkins, etc.

Note that production servers (or service provider) must have all the required ENV_VARS configured for a successful deployment and DJANGO_CONFIGURATION should be Production

Testing

To run code tests, simply use pytest command

Usage

Main models

This app includes two main models: Game and Guess.

First, a remote user requests the creation of a game, by providing a name via a POST message to /api/v1/games/ :

{
    "name": "Your Game Name"
}

The user can also retrieve the list of created games via a GET request to /api/v1/games/

After a game is created, it will contain a randomly generated code of four colours, being the possible choices one of:

  • RED
  • BLUE
  • GREEN
  • YELLOW

Next step is try to solve the game with a POST message to /api/v1/guess/:

{
    "guess_code": ["RED","BLUE","GREEN","YELLOW"],
    "game": 1
}

Being the game number, the game ID

After successfully posting a new guess, the response will return the created guess as well as the obtained score for it.

The score is returned in a format of a list of individual scores, being 1 a full match of both color and position and 0 a partial match of color but not position.

You can request the complete list of guesses and its score for a given game using the endpoint /api/v1/games/{gameID}

Documentation

API documentation can be found in /docs

TODO:

  • Add user attribute to each game and guess and provide private game views

mastermind's People

Contributors

carlosescura avatar

Watchers

James Cloos 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.