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

Controls

Main Menu:

  • : Navigate options
  • Enter: Select option
  • Q: Quit application

Gameplay:

  • or : Move selection
  • Enter: Confirm action
  • 1-8: Direct card/bid selection
  • Q: Return to main menu during gameplay

Features

  • Rich Terminal UI: Full-screen green felt table with detailed card graphics, face card art (Roi ♔, Dame ♕, Valet ⚔), and distinct color palettes.
  • Main Menu: Configure Difficulty, Target Score, and Game Speed, and access Rules & History (EN/FR) without restarting the app.
  • Live HUD: Real-time round scoring displays points won during the current round, with a smooth "rolling" numerical animation for total scores.
  • Trick History: Visual "Last Trick" panel helps track the flow of the game.
  • High Fidelity: Full implementation of French Belote rules including a two-round bidding system, "Dix de Der", and "Capot" (250 pts) announcements.
  • Rules & History Viewer: A scrollable, bilingual (English/French) in-game reference for the game's heritage and mechanics.
  • Robust Input: High-performance unbuffered key reading for responsive navigation and 'q' to quit functionality.

AI

Three difficulty levels:

  • Easy: Random legal moves, bids on 2+ honors
  • Medium: Heuristic suit scoring, strategic play (cover/duck/duck)
  • Hard: Void inference, 1-ply lookahead, Monte-Carlo bidding

Project Structure

belote/
├── src/belote/
│   ├── main.py        # Entry point, game loop, CLI args
│   ├── 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)
│   ├── ansi.py        # ANSI escape helpers (colors, cursor)
│   ├── input.py       # Platform-dispatched key reader
│   ├── ui.py          # Render, prompts, full-screen layout
│   └── rules.py       # Game rules content
├── tests/
│   └── test_belote.py  # 36 pytest tests
├── pyproject.toml      # Build system configuration
├── 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.2.tar.gz (38.2 kB 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.2-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: belote_cli-0.9.2.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • 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.2.tar.gz
Algorithm Hash digest
SHA256 7cf148b5cc3dab46d9afa4fd5b3a6993c133e51e6e7ec60489a3e08ef27e2747
MD5 6a241a5d90bd20eae2a2bf100e6f3433
BLAKE2b-256 7762f24d3fa0fad462f80863a0a9fb004211c47b69dfe2ab40be6da335f69ef7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: belote_cli-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 36.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d61627d69651f0cf68e19dc74ac114dd800da79127e6bebb8a6372d3b2b46592
MD5 fb66bfd5da7382bffe626fd6982ccd98
BLAKE2b-256 b69315e91100945e78af338c21817dba39b265dd0eecc678fe611b19b7c2edf7

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