Skip to main content

Pure Texas Hold'em engine with equity calculator. Designed for AI agents.

Project description

PokerTable

Pure Texas Hold'em engine with Monte Carlo equity calculator. Zero dependencies. Designed for AI agents.

from poker_engine import PokerEngine, Action, ActionType

engine = PokerEngine(["Alice", "Bob", "Charlie"], starting_chips=1000, seed=42)
engine.new_hand()

# Get valid actions for current player
player = engine.get_current_player()
actions = engine.get_valid_actions(player.name)

# Apply an action
result = engine.apply_action(player.name, Action(ActionType.CALL, 20))

# Check equity
from poker_engine import calculate_equity
equity = calculate_equity(player.hole_cards, engine.community, num_opponents=2)
print(f"Win probability: {equity.win_probability:.0%}")

Installation

pip install pokertable

Features

  • Complete Texas Hold'em rules (pre-flop through showdown)
  • Proper side pots for multi-player all-ins
  • Correct betting round termination (raise resets action)
  • Dealer button rotation with heads-up special rules
  • Monte Carlo equity calculator (~500 simulations, <100ms)
  • Hand evaluation for all 10 poker hand ranks
  • Human-readable hand descriptions ("Full House, Kings over Tens")
  • Turn-based API designed for AI agent integration
  • Seeded RNG for reproducible games
  • Zero external dependencies

Architecture

src/poker_engine/
├── cards.py      # Card, Suit, HandRank, evaluate_hand, describe_hand
├── engine.py     # PokerEngine state machine (the core)
├── equity.py     # Monte Carlo win probability calculator
└── __init__.py   # Public API exports

The engine is a pure state machine — no I/O, no async, no display logic. You call methods, it returns state. This makes it easy to wrap with any interface: CLI, web, AI agents, etc.

Usage

Basic Game Loop

from poker_engine import PokerEngine, Action, ActionType

engine = PokerEngine(["Alice", "Bob"], starting_chips=1000)

while not engine.is_tournament_over():
    engine.new_hand()
    
    while not engine.is_hand_over():
        if engine.is_betting_round_complete():
            if engine.phase.name == "RIVER":
                summary = engine.resolve_showdown()
                break
            engine.advance_phase()
            continue
        
        player = engine.get_current_player()
        if player is None:
            break
        
        actions = engine.get_valid_actions(player.name)
        # Your logic to choose an action here
        chosen = actions[1]  # e.g., call/check
        engine.apply_action(player.name, chosen)
    
    engine.rotate_dealer()

Equity Calculator

from poker_engine import calculate_equity
from poker_engine.cards import Card, Suit

hole = [Card(14, Suit.SPADES), Card(14, Suit.HEARTS)]  # Pocket aces
community = [Card(10, Suit.DIAMONDS), Card(7, Suit.CLUBS), Card(2, Suit.SPADES)]

equity = calculate_equity(hole, community, num_opponents=3, num_simulations=1000)
print(f"Hand: {equity.current_hand}")           # "Pair of As"
print(f"Win: {equity.win_probability:.0%}")      # "~82%"
print(f"Improvements: {equity.hand_improvement}") # {"Pair": 0.45, "Two Pair": 0.12, ...}

Development

git clone https://github.com/chiruu12/poker-engine.git
cd poker-engine
uv sync --extra dev
uv run pytest
uv run ruff check src tests

License

MIT

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

pokertable-0.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

pokertable-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pokertable-0.1.0.tar.gz.

File metadata

  • Download URL: pokertable-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for pokertable-0.1.0.tar.gz
Algorithm Hash digest
SHA256 331ebc0c08498ea9628eded0205f8cdbbb014a4dfbc53d06823bcf7da4ba369a
MD5 a32f8ed5155ef1a2cc88ab497d7296e9
BLAKE2b-256 4c2faf2eef95facef3fa1dc4eb35324a286c1a9427c5544d2e20ca883075a470

See more details on using hashes here.

File details

Details for the file pokertable-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pokertable-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.3

File hashes

Hashes for pokertable-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0345d0424fb7f7691992b0622a7ed2b0ccdd5061a1bb50b599247d8bd49e82ae
MD5 2b99a02950c9947e39a9b1fd6d835a5c
BLAKE2b-256 e5f46a51c9ddff82a9e3a36e1bfbfe60686d80fe71235d3aaa5c44a21aca7ebb

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