Skip to main content

A 4-player terminal card game

Project description

Belote – 4-Player Terminal Card Game

Complete implementation of the French card game Belote for the terminal, with a full-screen green felt table and full card graphics at compass positions (N/W/E/S).

Showcase

Main Menu

      ⢠⣴⣶⣶⣶⣄
      ⣿⣿⣿⣿⣿⣿⣦
     ⢰⣿⣿⣿⣿⡿⠟⠁⣠⣴⣶⣦⠄
     ⢸⣿⣿⠟⠉⣠⣴⣿⣿⣿⠟⠁⣠⣾⣿⣦⡀
      ⠉⣀⣴⣾⣿⣿⣿⠟⢁⣤⣾⣿⣿⣿⣿⣿⡆
    ⢀⣤⣾⣿⣿⣿⡿⠛⢁⣴⣿⣿⣿⣿⣿⣿⣿⠟⠁⡀
    ⢼⣿⣿⣿⡿⠋⣀⣴⣿⣿⣿⣿⣿⣿⣿⡿⠉⣠⣾⣿⡆
    ⠘⢿⡿⠋⣠⣾⣿⣿⣿⠟⠁⣿⣿⣿⣿⣿⠟⢁⣀
      ⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣴⣿⣿⣿⠋⢠⣾⣿⣷⣦⡀
      ⢻⣿⣿⣿⣿⣿⣿⣿⠟⢁⣴⣿⣿⣿⡿⠁⣰⣿⣿⣿⣿⣿⣿
       ⠹⢿⣿⣿⣿⡿⠋⣠⣾⣿⣿⣿⠟⢀⣼⣿⣿⣿⣿⣿⣿⡟
         ⠉⠉⠉⠀⢾⣿⣿⣿⣿⠋⠀⠚⠛⠛⠛⠛⠛⠛⠁

                       (
                        )     (
                 ___...(-------)-....___
             .-''       )    (          ''-.
       .-'``'|-._             )         _.-|
      /  .--.|   `''---...........---''`   |
     /  /    |       > Start Game <        |
     |  |    |     Difficulty: Medium      |
      \  \   |    Target Score: 1000       |
       `\ `\ |       Speed: Normal         |
         `\ `|      Rules & History        |
         _/ /\           Quit              /
        (__/  \                           /
     _..---''` \                         /`''---.._
  .-'           \                       /          '-.
 :               `-.__             __.-'              :
 :                  ) ''---...---'' (                 :
  '._               `''...___...--''`              _.'
 jgs \''--..__                              __..--''/
     '._     '''----.....______.....----'''     _.'
        `''--..,,_____            _____,,..--''`
                      `'''----'''`

Card Graphics

┌────┐  ┌────┐  ┌────┐  ┌────┐
│J ♠ │  │Q ♦ │  │K ♥ │  │A ♣ │
│ ⚔  │  │ ♕  │  │ ♔  │  │ ★  │
│ J ♠│  │ Q ♦│  │ K ♥│  │ A ♣│
└────┘  └────┘  └────┘  └────┘

Requirements

  • Python >= 3.10
  • No third-party dependencies (stdlib only)
  • Terminal with >= 100 columns x 40 rows
  • UTF-8 support (for card symbols: ♠♥♦♣)

Quick Start

# Install in editable mode (recommended for development)
pip install -e .

# Or install from PyPI (once uploaded)
pip install belote-cli

# Play using the belote command
belote

# Custom settings
belote --difficulty hard --target 500 --seed 123 --speed fast

Controls

General:

  • ? or H: Show keyboard shortcut help
  • M: Toggle sound effects on/off
  • Q: Quit to main menu or exit
  • T: View Game History (Round-by-round)

Main Menu:

  • : Navigate options
  • : Quick-change settings (Difficulty, Target, Speed, Mode)
  • Enter: Select option / Enter submenu

Gameplay:

  • or : Move selection
  • Enter: Confirm card/bid
  • 1-8: Direct card selection (or 1-4 for bids)
  • O: Sort hand by suit and rank
  • Z: Undo last move
  • Space or Esc: Skip animations

Features

  • Rich Terminal UI: Full-screen green felt table with detailed card graphics, face card art, and distinct color palettes. Graceful fallback to text-only mode for non-UTF-8 terminals.
  • Incremental Rendering: High-performance cursor-based updates for zero-flicker gameplay even at high speeds.
  • Hand Sorting: One-touch organization of your hand by suit and rank for better strategic overview.
  • Main Menu: Configure Mode, Difficulty, Target Score, and Game Speed, and access Rules & History (EN/FR) without restarting the app.
  • Undo/Redo: Press Z to undo your last move during bidding or play.
  • Statistics: Global tracking of games played/won, win rate (per difficulty), capots, best/worst rounds, and longest games. Includes a Session Stats dashboard.
  • Sound Effects: Enhanced auditory feedback for trick wins, Belote, and Capot, with a built-in mute toggle.
  • Declarations: Automatic detection and announcement of sequences (Tierce, Quarte, etc.) and Carrés after the first trick.
  • Live HUD: Real-time round scoring displays points won during the current round, with a smooth "rolling" numerical animation for total scores.
  • High Fidelity: Full implementation of French Belote rules including a two-round bidding system, "Dix de Der", and "Capot" (250 pts).
  • Rules & History Viewer: A scrollable, bilingual (English/French) in-game reference for the game's heritage and mechanics.

AI

Three difficulty levels:

  • Easy: Random legal moves, bids on 2+ honors.
  • Medium: Heuristic suit scoring, strategic lead (longest suit), and smart covering/ducking.
  • Hard: Void inference, 2-ply lookahead for critical tricks, and randomized "personality" bidding thresholds.

Project Structure

belote/
├── src/belote/
│   ├── main.py        # Entry point, CLI parsing, terminal setup
│   ├── gameflow.py    # Main game loop and phase transitions
│   ├── deck.py        # Card, Suit, Rank, deck operations, points
│   ├── game.py        # GameState, phases, pure transitions, legal moves
│   ├── bidding.py     # Bidding phase state machine
│   ├── scoring.py     # Declarations, round scoring, capot
│   ├── ai.py          # Three-tier AI (easy/medium/hard)
│   ├── ui/            # Modular UI package
│   │   ├── render.py  # ANSI table and card rendering
│   │   ├── prompts.py # Keyboard input and menu navigation
│   │   ├── menu.py    # Main menu and settings
│   │   └── announce.py# Sound and score animations
│   ├── ansi.py        # ANSI escape helpers (colors, cursor)
│   ├── input.py       # Platform-dispatched key reader
│   ├── stats.py       # Global and session statistics tracking
│   └── rules.py       # Game rules content
├── tests/             # Comprehensive test suite (50+ tests)
├── pyproject.toml      # Build system and dev dependencies (ruff/mypy)
├── LICENSE             # MIT License
└── DEVELOPMENT.md      # Detailed setup and dev guide

Running Tests

PYTHONPATH=src pytest

Terminal Hygiene

Signal handlers (SIGINT, SIGTERM) and atexit hooks ensure the terminal is always restored — cursor visible, colors reset, alt-screen off — even after Ctrl+C or crashes.

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

belote_cli-0.9.6.tar.gz (5.5 MB view details)

Uploaded Source

Built Distribution

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

belote_cli-0.9.6-py3-none-any.whl (49.2 kB view details)

Uploaded Python 3

File details

Details for the file belote_cli-0.9.6.tar.gz.

File metadata

  • Download URL: belote_cli-0.9.6.tar.gz
  • Upload date:
  • Size: 5.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for belote_cli-0.9.6.tar.gz
Algorithm Hash digest
SHA256 2e2105075ca4267140b80e823c81e6200862510d5b6addd2935ab72474ade440
MD5 c933fcf59565c6d754949b91dd74aa8b
BLAKE2b-256 587af2692f1a9274ef705226d45270611b9683cefc713e13c74307b05ef66b69

See more details on using hashes here.

File details

Details for the file belote_cli-0.9.6-py3-none-any.whl.

File metadata

  • Download URL: belote_cli-0.9.6-py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for belote_cli-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1a6fbca412baa2974e49cd4b83773793747e247d8b0182fab27085fbe4316c94
MD5 465dcf4e4e207e661090f2c0943870b8
BLAKE2b-256 592a1aa1255b25654007c293809d363db3b2cc75a53cb14d9f2465f01c0d510e

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