mjai-manue-go is a high-performance Go port of mjai-manue a Japanese Mahjong AI originally developed by Hiroshi Ichikawa. The project implements a sophisticated decision engine that communicates via the Mjai protocol to play Mahjong on automated servers or against other AI clients README.md6-13
The AI logic is ported from the CoffeeScript version of the original project, while the surrounding infrastructure—including the game state machine, protocol handling, and statistical analysis tools—has been reimplemented in Go to ensure type safety and execution efficiency README.md58-60 .agents/design.md3-4
mjsonp://) and standard I/O (stdio) streams for integration with various simulators and match servers README.md37-39 .agents/design.md17-20mjai-manue-go does not rely on the possible_actions field from the server. It maintains its own internal game state and derives legal actions independently using round.State and round.LegalActions README.md41-46 .agents/design.md101go:embed README.md47-49 .agents/design.md108--seed flag to ensure reproducible AI decisions README.md63 .agents/design.md48The project follows a layered architecture inspired by Domain-Driven Design (DDD) and Hexagonal Architecture principles. This separation ensures that the core Mahjong rules and AI logic remain isolated from the specifics of the Mjai JSON protocol.
The following diagram illustrates how external protocol messages flow through the system layers to trigger AI decisions.
Diagram: System Flow and Code Entities
Sources: .agents/design.md66-91 .agents/design.md100-105 AGENTS.md22-26
| Layer | Package Path | Responsibility |
|---|---|---|
| Cmd | cmd/ | Entry points (e.g., cmd/mjai-manue), CLI flag parsing, and runtime initialization .agents/design.md60 |
| Adapter | internal/adapter/ | Translation between the Mjai JSON protocol and internal domain events/actions using an Anti-Corruption Layer (ACL) .agents/design.md59 .agents/design.md64-65 |
| Application | internal/application/ | Orchestrating the game loop, managing the Bot lifecycle, and coordinating state updates with AI queries .agents/design.md58 |
| Domain | internal/domain/ | The "source of truth" for Mahjong rules, including tile types, score calculation, and the ManueAgent decision logic .agents/design.md57 |
For a detailed breakdown of these layers and their dependency rules, see Architecture Overview.
The ManueAgent selects actions by evaluating candidates across several statistical dimensions. It aims to maximize the expected final rank rather than just the immediate score README.md120-123
Diagram: Decision Pipeline
Sources: README.md95-124 .agents/design.md132-133 internal/domain/game/round/service/shanten.go91-140
The evaluation includes:
myHoraProb): Estimated via Monte Carlo simulation of 1000 trials per decision README.md102-106hojuProb): Calculated using a pre-trained decision tree trained from tile-safety features such as honors, suji, and dora README.md110-112avgRank): Combines win/loss probabilities with current scores and statistical distributions to predict the final game outcome README.md120-124To explore the codebase and its documentation further, refer to the following child pages:
round.State machine processes events .agents/design.md51-91estimate_danger, dump_game_stats) for generating the statistical models embedded in the AI .agents/design.md109Sources: README.md1-124 .agents/design.md1-133 AGENTS.md1-54 test/original_vs_port/README.md1-101
Refresh this wiki