Skip to main content

Play connect 4 in your terminal or online with your friends

Project description

py-connect-4

This is a simple Python script to play connect 4.

Uses rich to represent the board!

Play locally OR online with your friends.

Installation

  • With uv (recommended)
 uv tool install py-connect-4
❯ py-connect-4 --help

Or simply run it via uvx

 uvx py-connect-4 --help
  • With pip
 pip install py-connect-4
❯ py-connect-4 --help

Usage

Locally

 uvx py-connect-4 local # or after installation via pip py-connect-4 local

Then play in turns in 1 shell prompt.

Online

One of you needs to spawn 2 processes to HOST and also JOIN the game:

Host:

 uvx py-connect-4 online host
❯ # or after installation via pip py-connect-4 online host

Client:

 uvx connect-4 online join
❯ # or after installation via pip py-connect-4 online join

You'll be prompted to enter the HOST IP or fall back to "0.0.0.0"

Game example

This is an example for a local game
 uvx py-connect-4 local
┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━┓
┃ 0  1  2  3  4  5  6 ┃
┡━━━╇━━━╇━━━╇━━━╇━━━╇━━━╇━━━┩
│                     │
├───┼───┼───┼───┼───┼───┼───┤
│                     │
├───┼───┼───┼───┼───┼───┼───┤
│                     │
├───┼───┼───┼───┼───┼───┼───┤
│                     │
├───┼───┼───┼───┼───┼───┼───┤
│                     │
├───┼───┼───┼───┼───┼───┼───┤
│                     │
└───┴───┴───┴───┴───┴───┴───┘
Player 🟠. Col: 6
┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━━┓
┃ 0  1  2  3  4  5  6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━╇━━━╇━━━━┩
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                   🟠 │
└───┴───┴───┴───┴───┴───┴────┘
Player 🔵. Col: 6
┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━━┓
┃ 0  1  2  3  4  5  6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━╇━━━╇━━━━┩
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                      │
├───┼───┼───┼───┼───┼───┼────┤
│                   🔵 │
├───┼───┼───┼───┼───┼───┼────┤
│                   🟠 │
└───┴───┴───┴───┴───┴───┴────┘
Player 🟠. Col: 5
┏━━━┳━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4  5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━┩
│                       │
├───┼───┼───┼───┼───┼────┼────┤
│                       │
├───┼───┼───┼───┼───┼────┼────┤
│                       │
├───┼───┼───┼───┼───┼────┼────┤
│                       │
├───┼───┼───┼───┼───┼────┼────┤
│                    🔵 │
├───┼───┼───┼───┼───┼────┼────┤
│                🟠  🟠 │
└───┴───┴───┴───┴───┴────┴────┘
Player 🔵. Col: 4
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                     🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🟠. Col: 5
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                 🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🔵. Col: 5
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                 🔵     │
├───┼───┼───┼───┼────┼────┼────┤
│                 🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🟠. Col: 4
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                 🔵     │
├───┼───┼───┼───┼────┼────┼────┤
│             🟠  🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🔵. Col: 6
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                 🔵  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🟠  🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🟠. Col: 6
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                     🟠 │
├───┼───┼───┼───┼────┼────┼────┤
│                 🔵  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🟠  🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🔵. Col: 4
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                     🟠 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🔵  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🟠  🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🟠. Col: 5
┏━━━┳━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3  4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━┩
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                        │
├───┼───┼───┼───┼────┼────┼────┤
│                 🟠  🟠 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🔵  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🟠  🟠  🔵 │
├───┼───┼───┼───┼────┼────┼────┤
│             🔵  🟠  🟠 │
└───┴───┴───┴───┴────┴────┴────┘
Player 🔵. Col: 3
┏━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3   4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                         │
├───┼───┼───┼────┼────┼────┼────┤
│                         │
├───┼───┼───┼────┼────┼────┼────┤
│                  🟠  🟠 │
├───┼───┼───┼────┼────┼────┼────┤
│              🔵  🔵  🔵 │
├───┼───┼───┼────┼────┼────┼────┤
│              🟠  🟠  🔵 │
├───┼───┼───┼────┼────┼────┼────┤
│          🔵  🔵  🟠  🟠 │
└───┴───┴───┴────┴────┴────┴────┘
Player 🟠. Col: 4
┏━━━┳━━━┳━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2  3   4   5   6  ┃
┡━━━╇━━━╇━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                         │
├───┼───┼───┼────┼────┼────┼────┤
│                         │
├───┼───┼───┼────┼────┼────┼────┤
│              🟠  🟠  🟠 │
├───┼───┼───┼────┼────┼────┼────┤
│              🔵  🔵  🔵 │
├───┼───┼───┼────┼────┼────┼────┤
│              🟠  🟠  🔵 │
├───┼───┼───┼────┼────┼────┼────┤
│          🔵  🔵  🟠  🟠 │
└───┴───┴───┴────┴────┴────┴────┘
Player 🔵. Col: 2
┏━━━┳━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1  2   3   4   5   6  ┃
┡━━━╇━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                          │
├───┼───┼────┼────┼────┼────┼────┤
│                          │
├───┼───┼────┼────┼────┼────┼────┤
│               🟠  🟠  🟠 │
├───┼───┼────┼────┼────┼────┼────┤
│               🔵  🔵  🔵 │
├───┼───┼────┼────┼────┼────┼────┤
│               🟠  🟠  🔵 │
├───┼───┼────┼────┼────┼────┼────┤
│       🔵  🔵  🔵  🟠  🟠 │
└───┴───┴────┴────┴────┴────┴────┘
Player 🟠. Col: 1
┏━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1   2   3   4   5   6  ┃
┡━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                🟠  🟠  🟠 │
├───┼────┼────┼────┼────┼────┼────┤
│                🔵  🔵  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│                🟠  🟠  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│    🟠  🔵  🔵  🔵  🟠  🟠 │
└───┴────┴────┴────┴────┴────┴────┘
Player 🔵. Col: 2
┏━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1   2   3   4   5   6  ┃
┡━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                🟠  🟠  🟠 │
├───┼────┼────┼────┼────┼────┼────┤
│                🔵  🔵  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│        🔵      🟠  🟠  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│    🟠  🔵  🔵  🔵  🟠  🟠 │
└───┴────┴────┴────┴────┴────┴────┘
Player 🟠. Col: 2
┏━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0  1   2   3   4   5   6  ┃
┡━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                           │
├───┼────┼────┼────┼────┼────┼────┤
│                🟠  🟠  🟠 │
├───┼────┼────┼────┼────┼────┼────┤
│        🟠      🔵  🔵  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│        🔵      🟠  🟠  🔵 │
├───┼────┼────┼────┼────┼────┼────┤
│    🟠  🔵  🔵  🔵  🟠  🟠 │
└───┴────┴────┴────┴────┴────┴────┘
Player 🔵. Col: 0
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0   1   2   3   4   5   6  ┃
┡━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                 🟠  🟠  🟠 │
├────┼────┼────┼────┼────┼────┼────┤
│         🟠      🔵  🔵  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│         🔵      🟠  🟠  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│ 🔵  🟠  🔵  🔵  🔵  🟠  🟠 │
└────┴────┴────┴────┴────┴────┴────┘
Player 🟠. Col: 3
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0   1   2   3   4   5   6  ┃
┡━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                 🟠  🟠  🟠 │
├────┼────┼────┼────┼────┼────┼────┤
│         🟠      🔵  🔵  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│         🔵  🟠  🟠  🟠  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│ 🔵  🟠  🔵  🔵  🔵  🟠  🟠 │
└────┴────┴────┴────┴────┴────┴────┘
Player 🔵. Col: 3 
┏━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓
┃ 0   1   2   3   4   5   6  ┃
┡━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━╇━━━━┩
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                            │
├────┼────┼────┼────┼────┼────┼────┤
│                 🟠  🟠  🟠 │
├────┼────┼────┼────┼────┼────┼────┤
│         🟠  🔵  🔵  🔵  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│         🔵  🟠  🟠  🟠  🔵 │
├────┼────┼────┼────┼────┼────┼────┤
│ 🔵  🟠  🔵  🔵  🔵  🟠  🟠 │
└────┴────┴────┴────┴────┴────┴────┘
WINNER IS PLAYER 🔵
❯ 

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

py_connect_4-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

py_connect_4-0.1.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file py_connect_4-0.1.2.tar.gz.

File metadata

  • Download URL: py_connect_4-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.16

File hashes

Hashes for py_connect_4-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3c6cc2ecae044b7a702a791d2e5e8aef5b373a02a2f85da7e4748d62c32ccf67
MD5 a50eaba904567ae1d3dbba94881b8f57
BLAKE2b-256 7a6a0fa58e96391f9dd080d86291d52e549ea7100acaffab9ccd111de7b93b32

See more details on using hashes here.

File details

Details for the file py_connect_4-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for py_connect_4-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a83234fb3df505cba24df79d80cca08e6766b072ab690babe4fdd927fb77895
MD5 a9fd105f64d49e55bca811fa25324efe
BLAKE2b-256 b9449df27468cfc999978f4e699038813622ad678212bd683742d9c102c460ea

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