Skip to main content

Connect 4 game with pygame UI

Project description

Connect 4 (Python + pygame)

Summary

A desktop Connect 4 game with a pygame UI. Game rules, sessions, bots, and the engine live under src/game/; shared types are in src/base_models.py; the public API surface is src/api.py so the UI can depend on stable contracts without importing game/ directly. The pygame front end is under src/ux/. Unit tests cover backend logic under tests/unit/; end-to-end grid scenarios are under tests/e2e/.

Features:

  • two players (human or bot)
  • bot difficulties (easy / medium / hard)
  • player session stats across games
  • win-line highlighting

Requirements

  • Python 3.13.x (3.14+ is not supported yet: pygame 2.6.x hits a font-module circular import on 3.14; see pygame#4795.)
  • uv (recommended) or another virtualenv + pip workflow
  • SDL2 (usually bundled with pygame wheels; on some Linux setups you may need system SDL packages)

Build and run from this repository

From the project root (the directory that contains pyproject.toml):

git clone <repository-url> connect4
cd connect4
uv sync

Run the game using either the installed console script or the module:

uv run connect4

or:

uv run python -m main

Tests and formatting (optional)

uv run pytest
uv run black src tests

5. Run without cloning the code (install from PyPI)

After the package is published to PyPI under the name defined in pyproject.toml (connect4-game), anyone can install and run it without a checkout:

pip install connect4-game
connect4

Use pipx install connect4-game if you prefer an isolated CLI install.

Note: The exact PyPI package name must match what you publish; adjust pip install … if you choose a different name on PyPI.

If connect4 fails with No module named 'main'

PyPI 0.1.2+ ships a fixed launcher; the error almost always means the connect4 script on your PATH was not updated (often pip installs to a different Python than the one that runs connect4).

  1. Run with the same interpreter you use to install (replace python with your python3.14 / pyenv shim if needed):

    python -m pip install --upgrade --force-reinstall connect4-game
    python -m pip show connect4-game   # expect Version: 0.1.2 or newer
    head -n 5 "$(which connect4)"
    

    The last line should show from ux.view import run_cli, not from main import main.

  2. Workaround (no console script): after install, run:

    python -m ux
    
  3. Still stuck: uninstall and reinstall with the same python -m pip:

    python -m pip uninstall -y connect4-game
    python -m pip install connect4-game
    

Or reinstall from this repo: uv pip install -e ..

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

connect4_game-0.1.4.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

connect4_game-0.1.4-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file connect4_game-0.1.4.tar.gz.

File metadata

  • Download URL: connect4_game-0.1.4.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for connect4_game-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3989d4477288e5977a2a1238efcb0d9e4514b0592cfcda198032db1eb9d1306e
MD5 78eaa7a14eae0387be6a212bfe3aef08
BLAKE2b-256 611b6a17670491301579d8822ba9fae5f7336318b2c6367d61161589e3355deb

See more details on using hashes here.

File details

Details for the file connect4_game-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: connect4_game-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for connect4_game-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1f2cc422123868033a2f691b06e65afca1bbe2eed9c98c381ab38abebb0f1132
MD5 b2a83e1c06b764b46895a6dbf3d5f27c
BLAKE2b-256 eed42bb731ae378951cf99681740fd1e15e0285f472c46b86da7ba374f6a8bb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page