/chess-python

A chess board backend for python/Django

Primary LanguagePython

A Chess Game backend made with Django

For Documentation and reference to the Game design, see docs here

This project uses pre-commit and black for formatting.

Quick Start

Clone the repo:

with https

git clone https://github.com/wawanjohi/chess-python.git

or SSH

git clone git@github.com:wawanjohi/chess-python.git

or with Git CLI

gh repo clone wawanjohi/chess-python

Setup virtual env:

Linux or Mac:

virtualenv venv && source venv/bin/activate

Windows: Create the environment venv and run this on powershell:

.\venv\Scripts\Activate.ps1

While at it, copy .env.example to .env and prepopulate the values as you need to.

Setup Channel Layers:

You can use in-memory channel layers, but be sure to move to a production-ready channel layer such as Redis.

Setting up InMemoryChannelLayer:

Add this to your Setting at config/settings.py

    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels.layers.InMemoryChannelLayer"
        }
    }

Setup channel layers to use Redis

Make sure Redis is installed and working on your machine. This works out of the box on Mac or Linux.

Ubuntu/Debian

sudo apt install redis

Arch/Manjaro

sudo pacman -S redis

Fedora

sudo dnf -y install redis

Install with Snap (Compatible with most linux Distros)

sudo snap install redis

For Windows, you will either have to use Docker or other third-party ways for connecting to a linux environment as Redis doesn't work out of the box.

Docker

docker run -it --name chess-python-redis -d redis

I'd highly recommend that you use Memurai if you don't intend to use Docker

Add this to your settings at config/settings.py:

    CHANNEL_LAYERS = {
        "default": {
            "BACKEND": "channels_redis.core.RedisChannelLayer",
            "CONFIG": {
                "hosts": [("127.0.0.1", 6379)],
            },
        },
    }

Setup pre commit:

Adjust the python version on .pre-commit-config.yaml to match yours (3.9.x recommended) on this line:
language_version: python3.x.x

Run Project

Migrate and create superuser:

python manage.py migrate
python manage.py createsuperuser

Run the project:

python manage.py runserver

Go to http://localhost:8000 to ping a move!