Skip to main content

Pubnix-local turn-based multiplayer TUI for tic-tac-toe, chess, checkers, Reversi, Battleship, Connect 4, Crazy Eights, Royal Game of Ur, and peg solitaire.

Project description

tuimanji

PyPI Python License: LGPL v3 CI

A pubnix-local turn-based multiplayer TUI. No server. No accounts. Just log in to the same box as your friend and play something.

Tuimanji bundles nine turn-based games — Tic-Tac-Toe, Connect 4, Reversi, Chess, Checkers, Battleship, Crazy Eights, Peg Solitaire, and the Royal Game of Ur — behind a single Textual terminal UI. Matches live in a shared SQLite database; clients coordinate via file locks and append-only writes. It's designed for pubnix boxes, shared servers, and old-school SSH shenanigans.

Why no server?

Because everything you need to synchronize turn-based games is already on the box: a filesystem, a SQLite binary, and flock(2). Running a daemon to marshal moves would be more infrastructure to break. Instead:

  • State lives in tuimanji.db — one file under $TUIMANJI_DB, WAL mode, PRAGMA busy_timeout=5000.
  • Writes are append-only. Each turn is a new row; nothing is ever updated. Replay, spectating, and crash-resume fall out for free.
  • Concurrency is layered. The app checks "is it your turn?"; SQLite's BEGIN IMMEDIATE serializes writers; a (match_id, turn) unique constraint catches anything that slips through.
  • Identity is a session slot. flocking $TUIMANJI_DB/.sessions/<user>/N.lock lets two terminals for the same unix user claim distinct player ids (user, user#2, …) — great for local testing, still sane for shared hosts.

Install

# one-shot run
uv tool run tuimanji

# persistent install
uv tool install tuimanji
# or
pipx install tuimanji
# or
pip install --user tuimanji

Requires Python 3.13+ and a terminal that speaks 256 colors.

Run

tuimanji                # open the lobby
tuimanji new chess      # create a new match + jump to its waiting room
tuimanji join a1b2c3d4  # join (or rejoin) an existing match
tuimanji resume         # open your most recent unfinished match
tuimanji games          # list available games
tuimanji where          # print the resolved database directory
tuimanji --version

The shared database defaults to /var/games/tuimanji/. On a machine where you don't own that path, override it:

export TUIMANJI_DB=~/.local/share/tuimanji
# or per-command
tuimanji --db ~/.local/share/tuimanji

Everyone playing against each other has to point at the same directory.

Games

id players name
tic-tac-toe 2 Tic-Tac-Toe
connect-4 2 Connect 4
battleship 2 Battleship
reversi 2 Reversi
chess 2 Chess
checkers 2 Checkers
peg-solitaire 1 Peg Solitaire
crazy-eights 2–4 Crazy Eights
royal-ur 2 Royal Game of Ur

Controls

key action
↑ ↓ ← → move cursor
enter space commit cursor action
r rotate ship (Battleship placement phase)
tab cycle stage / suit / piece (multi-phase games)
q quit to lobby

Per-game quirks are surfaced in the status strip at the bottom of each match.

Adding a game

A game is one module under src/tuimanji/games/ implementing the tuimanji.engine.Game protocol — pure functions over state dicts. No I/O, no database access. See docs/adding-a-game.md for a walkthrough, or read src/tuimanji/games/peg_solitaire.py for the minimal single-player shape.

from tuimanji import Game, REGISTRY, IllegalAction

class MyGame:  # satisfies the Game protocol structurally
    id = "my-game"
    name = "My Game"
    min_players = 2
    max_players = 2
    # ... initial_state, apply_action, current_player, winner, is_terminal,
    # ... render, initial_cursor, move_cursor, cursor_action, animation_for

Development

git clone https://github.com/alanbato/tuimanji
cd tuimanji
uv sync
uv run pytest -q
prek install    # pre-commit hooks (ruff, ty)
uv run tuimanji

See CONTRIBUTING.md for the full contributor guide.

License

LGPL-3.0-or-later. See COPYING.LESSER (which extends the GPLv3 in COPYING).

Modifications to Tuimanji itself must be released under the LGPL, but larger works that merely use the library (e.g. a game module wired into the REGISTRY) are not required to adopt the same license.

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

tuimanji-0.1.1.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

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

tuimanji-0.1.1-py3-none-any.whl (85.1 kB view details)

Uploaded Python 3

File details

Details for the file tuimanji-0.1.1.tar.gz.

File metadata

  • Download URL: tuimanji-0.1.1.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuimanji-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e4e4de5b7ac1e9bb66a4cdd1ea20d397d928db9624697ea39e924c76e338d95a
MD5 82bcc910f0e04a09ad2282f29451afce
BLAKE2b-256 08a6072e4940cd3b337cac540b672298c8ef98026a43d1a352b19058a4442253

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuimanji-0.1.1.tar.gz:

Publisher: publish.yml on alanbato/tuimanji

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tuimanji-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tuimanji-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 85.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tuimanji-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08951e5b7920a7d22fe54ca208f87685eaa397cd71658ff2825c63a85d67502a
MD5 077c92926442280871d7fb7e17c7d2a0
BLAKE2b-256 5da535511c4c3502bb30054eab47784d970f03b9853f95a39617783c8afbfbbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuimanji-0.1.1-py3-none-any.whl:

Publisher: publish.yml on alanbato/tuimanji

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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