Skip to content

gaems12/connect-four

Repository files navigation

Connect Four

Python version Code style Status of passing 'lint' job Status of passing 'test' job

📜 License

This project is licensed under the Personal Use License. See the LICENSE file for details.

📚 Table of Contents

📦 Dependencies

Ensure the following services are installed and running:

  • Redis
  • NATS
  • Centrifugo

🚀 Installation

Using uv

  1. Create and activate a virtual environment:

    uv venv --python 3.13
    source ./.venv/bin/activate
  2. Install dependencies:

    For development

    uv sync --all-extras --frozen

    For production

    uv sync --frozen

Using pip

  1. Create and activate a virtual environment:

    python3 -m venv .venv
    source ./.venv/bin/activate
  2. Install dependencies:

    For development:

    pip install -e ".[dev]"

    For production:

    pip install -e .

Using Docker

  1. Build Docker image:

    docker build -t connect_four:latest .

⚙️ Environment Variables

Configure the following environment variables before running the application:

Variable Required Description Default
LOGGING_LEVEL No Logging level DEBUG
REDIS_URL No URL for the Redis instance. redis://localhost:6379
NATS_URL No URL for the NATS server. nats://localhost:4222
CENTRIFUGO_URL Yes URL for the Centrifugo server. -
CENTRIFUGO_API_KEY Yes API key for Centrifugo. -
GAME_MAPPER_GAME_EXPIRES_IN No Game expiration time in seconds. 3600
LOCK_EXPIRES_IN No Lock expiration time in seconds. 5
TEST_REDIS_URL Yes (for tests) URL for the test Redis instance. -
TEST_NATS_URL Yes (for tests) URL for the test NATS server. -

🛠️ Commands

Create NATS Streams

Create NATS streams with all subjects used by application to test it:

connect-four create-nats-streams <nats_url>

Run Message Consumer

Run the message consumer to process game-related events from NATS:

connect-four run-message-consumer

Run Task Scheduler

Run the task scheduler:

connect-four run-task-scheduler

Run Task Executor

Run the task executor for scheduled tasks:

connect-four run-task-executor

Create a New Game

connect-four create-game --id <UUID> --lobby-id <UUID> --first-player-id <UUID> --first-player-time <number_of_seconds> --first-player-communication <"centrifugo" | "other"> --second-player-id <UUID> --second-player-time <number_of_seconds> --second-player-communication <"centrifugo" | "other">

End a Game

connect-four end-game --id <UUID>

About

Backend for the connect four game.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •