How aaaaha0/ai-mahjong-table works
Mahjong Web Table combines a deterministic four-seat rules engine with a browser debug table and configurable human, random, debug, and LLM seats. The primary workflow is to configure a rule, seed, and seats in the browser; create a session; submit actions or ask a controller to choose among legal actions; then inspect snapshots, events, replay, or a FullLog. The graph preserves rule-driven play, tile/wall handling, controller integration, and inspection paths. Some runtime wiring is inferred only from module names and README capabilities because source excerpts are partial.
Main entry points: table.py Table Engine · session.py Session Manager · app.py Web API · physical_table.py Physical Operations
Components 25
Web Table
- Table UI
src/mahjong_ai/web/static/app.js - Web API
src/mahjong_ai/web/app.py - Session Manager
src/mahjong_ai/web/session.py - API Schemas
src/mahjong_ai/web/schemas.py
Table Engine
- Table Engine
src/mahjong_ai/game/table.py - Physical Operations
src/mahjong_ai/game/physical_table.py - Table State
src/mahjong_ai/game/state.py - Response Windows
src/mahjong_ai/game/response_window.py - Match Controller
src/mahjong_ai/game/match.py
Rules and Tiles
- Rule Contract
src/mahjong_ai/rules/base.py - Rule Loader
src/mahjong_ai/rules/loader.py - Tuidaohe Rules
src/mahjong_ai/rules/tuidaohe/ruleset.py - Wall Provider
src/mahjong_ai/walls/duplicate.py - Tile Model
src/mahjong_ai/common/tile.py - Actions and Scores
src/mahjong_ai/common/action.py
Player Controllers
- Agent Contract
src/mahjong_ai/agents/base.py - Agent Executor
src/mahjong_ai/agents/executor.py - Random Agent
src/mahjong_ai/agents/random.py - LLM Adapter
src/mahjong_ai/agents/llm.py
Game Inspection
- Observation Builder
src/mahjong_ai/observation/builder.py - Replay
src/mahjong_ai/game/replay.py - Snapshot
src/mahjong_ai/game/snapshot.py - Game Events
src/mahjong_ai/common/event.py
Other components
- Debug Browser
- LLM Endpoint
Connections 27
- Debug Browser → Table UI: uses
- Table UI → Web API: calls API
- Web API → API Schemas: validates payloads
- Web API → Session Manager: dispatches requests
- Session Manager → Rule Loader: loads rules
- Session Manager → Table Engine: creates and drives
- Session Manager → LLM Adapter: requests decisions
- Table Engine → Rule Contract: queries rule contract
- Table Engine → Physical Operations: executes operations
- Table Engine → Table State: updates and reads
- Table Engine → Response Windows: resolves responses
- Rule Loader → Tuidaohe Rules: loads plugin
- Tuidaohe Rules → Rule Contract: implements
- Physical Operations → Wall Provider: deals and draws
- Physical Operations → Tile Model: moves tiles
- Tuidaohe Rules → Actions and Scores: produces legal actions
- Table Engine → Actions and Scores: accepts submitted actions
- Match Controller → Table Engine: controls matches
- Agent Executor → Agent Contract: runs agents
- Random Agent → Agent Contract: implements
- LLM Adapter → LLM Endpoint: requests action choice
- Session Manager → Observation Builder: builds observations
- Table Engine → Replay: provides replay
- Session Manager → Replay: serializes replay
- Session Manager → Snapshot: serializes snapshot
- Session Manager → Game Events: serializes events
- Table Engine → Game Events: records events