# forrestzhu/doudizhu architecture

> Architecture diagram of the GitHub repository forrestzhu/doudizhu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/forrestzhu/doudizhu
- Repository: https://github.com/forrestzhu/doudizhu

## Overview

This repository is a Doudizhu card-game engine with a desktop interface and strategy-evaluation tooling. The main runtime path is a player or policy making a move, the engine validating and applying it, and the game exposing updated state; rule classification, decision policies, and visibility data support that loop. Arena simulation, strategy tuning, and turn diagnosis are additional product capabilities. The README is only a short project title, so desktop wiring and unsampled CLI behavior are not asserted; dependency edges reflect source-index references or shown calls.

Main entry points: [`src/engine.rs`](https://github.com/forrestzhu/doudizhu/blob/main/src/engine.rs) (Game state and turns), [`src/decision.rs`](https://github.com/forrestzhu/doudizhu/blob/main/src/decision.rs) (Policy decisions), [`src/mcts.rs`](https://github.com/forrestzhu/doudizhu/blob/main/src/mcts.rs) (MCTS policy), [`src/arena.rs`](https://github.com/forrestzhu/doudizhu/blob/main/src/arena.rs) (Game arena)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game runtime"]
  node_game["Game state and turns<br/>[engine.rs]"]
  node_cards["Cards and deck<br/>[cards.rs]"]
  node_rules["Hand rules<br/>[rules.rs]"]
  node_views["Player views<br/>[visibility.rs]"]
end

subgraph group_strategy["Decision strategies"]
  node_decisions["Policy decisions<br/>[decision.rs]"]
  node_mcts["MCTS policy<br/>[mcts.rs]"]
end

subgraph group_evaluation["Strategy evaluation"]
  node_arena["Game arena<br/>[arena.rs]"]
  node_tuning["Strategy tuning<br/>[auto_tune.rs]"]
  node_diagnosis["Turn diagnosis<br/>[diagnosis.rs]"]
  node_arena_cli["Arena command line<br/>[arena.rs]"]
end

subgraph group_desktop["Desktop interface"]
  node_renderer["Desktop renderer<br/>[app.js]"]
  node_electron_main["Electron main process<br/>[main.js]"]
  node_preload["Preload bridge<br/>[preload.js]"]
end

node_player(("Player"))

node_player -.->|"submits moves"| node_game
node_game -->|"uses cards"| node_cards
node_game -->|"accepts decisions"| node_decisions
node_game -->|"validates plays"| node_rules
node_game -->|"builds views"| node_views
node_decisions -->|"uses cards"| node_cards
node_decisions -->|"classifies candidates"| node_rules
node_decisions -->|"reads player state"| node_views
node_mcts -->|"scores candidates"| node_decisions
node_mcts -->|"uses cards"| node_cards
node_mcts -->|"checks plays"| node_rules
node_mcts -->|"reads player state"| node_views
node_arena -->|"runs games"| node_game
node_arena -->|"builds policies"| node_decisions
node_arena -->|"builds MCTS policies"| node_mcts
node_tuning -->|"evaluates placements"| node_arena
node_tuning -->|"tunes settings"| node_mcts
node_diagnosis -->|"runs a game"| node_game
node_diagnosis -->|"evaluates candidates"| node_decisions
node_arena_cli -.->|"invokes arena"| node_arena
node_renderer -->|"presents game"| node_player
node_renderer -.->|"requests game steps"| node_preload

click node_game "https://github.com/forrestzhu/doudizhu/blob/main/src/engine.rs"
click node_cards "https://github.com/forrestzhu/doudizhu/blob/main/src/cards.rs"
click node_rules "https://github.com/forrestzhu/doudizhu/blob/main/src/rules.rs"
click node_views "https://github.com/forrestzhu/doudizhu/blob/main/src/visibility.rs"
click node_decisions "https://github.com/forrestzhu/doudizhu/blob/main/src/decision.rs"
click node_mcts "https://github.com/forrestzhu/doudizhu/blob/main/src/mcts.rs"
click node_arena "https://github.com/forrestzhu/doudizhu/blob/main/src/arena.rs"
click node_tuning "https://github.com/forrestzhu/doudizhu/blob/main/src/auto_tune.rs"
click node_diagnosis "https://github.com/forrestzhu/doudizhu/blob/main/src/diagnosis.rs"
click node_arena_cli "https://github.com/forrestzhu/doudizhu/blob/main/src/bin/arena.rs"
click node_renderer "https://github.com/forrestzhu/doudizhu/blob/main/renderer/app.js"
click node_electron_main "https://github.com/forrestzhu/doudizhu/blob/main/electron/main.js"
click node_preload "https://github.com/forrestzhu/doudizhu/blob/main/electron/preload.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_game,node_cards,node_rules,node_views toneBlue
class node_decisions,node_mcts toneAmber
class node_arena,node_tuning,node_diagnosis,node_arena_cli toneMint
class node_renderer,node_electron_main,node_preload toneRose
class node_player toneIndigo
```

## Components

### Game runtime

- [Game state and turns](https://github.com/forrestzhu/doudizhu/blob/main/src/engine.rs): `src/engine.rs`
- [Cards and deck](https://github.com/forrestzhu/doudizhu/blob/main/src/cards.rs): `src/cards.rs`
- [Hand rules](https://github.com/forrestzhu/doudizhu/blob/main/src/rules.rs): `src/rules.rs`
- [Player views](https://github.com/forrestzhu/doudizhu/blob/main/src/visibility.rs): `src/visibility.rs`

### Decision strategies

- [Policy decisions](https://github.com/forrestzhu/doudizhu/blob/main/src/decision.rs): `src/decision.rs`
- [MCTS policy](https://github.com/forrestzhu/doudizhu/blob/main/src/mcts.rs): `src/mcts.rs`

### Strategy evaluation

- [Game arena](https://github.com/forrestzhu/doudizhu/blob/main/src/arena.rs): `src/arena.rs`
- [Strategy tuning](https://github.com/forrestzhu/doudizhu/blob/main/src/auto_tune.rs): `src/auto_tune.rs`
- [Turn diagnosis](https://github.com/forrestzhu/doudizhu/blob/main/src/diagnosis.rs): `src/diagnosis.rs`
- [Arena command line](https://github.com/forrestzhu/doudizhu/blob/main/src/bin/arena.rs): `src/bin/arena.rs`

### Desktop interface

- [Desktop renderer](https://github.com/forrestzhu/doudizhu/blob/main/renderer/app.js): `renderer/app.js`
- [Electron main process](https://github.com/forrestzhu/doudizhu/blob/main/electron/main.js): `electron/main.js`
- [Preload bridge](https://github.com/forrestzhu/doudizhu/blob/main/electron/preload.js): `electron/preload.js`

### Other components

- **Player**

## Connections

- Player → Game state and turns: submits moves
- Game state and turns → Cards and deck: uses cards (evidence: `src/engine.rs`)
- Game state and turns → Policy decisions: accepts decisions (evidence: `src/engine.rs`)
- Game state and turns → Hand rules: validates plays (evidence: `src/engine.rs`)
- Game state and turns → Player views: builds views (evidence: `src/visibility.rs`)
- Policy decisions → Cards and deck: uses cards (evidence: `src/decision.rs`)
- Policy decisions → Hand rules: classifies candidates (evidence: `src/decision.rs`)
- Policy decisions → Player views: reads player state (evidence: `src/decision.rs`)
- MCTS policy → Policy decisions: scores candidates (evidence: `src/mcts.rs`)
- MCTS policy → Cards and deck: uses cards (evidence: `src/mcts.rs`)
- MCTS policy → Hand rules: checks plays (evidence: `src/mcts.rs`)
- MCTS policy → Player views: reads player state (evidence: `src/mcts.rs`)
- Game arena → Game state and turns: runs games (evidence: `src/arena.rs`)
- Game arena → Policy decisions: builds policies (evidence: `src/arena.rs`)
- Game arena → MCTS policy: builds MCTS policies (evidence: `src/arena.rs`)
- Strategy tuning → Game arena: evaluates placements (evidence: `src/auto_tune.rs`)
- Strategy tuning → MCTS policy: tunes settings (evidence: `src/auto_tune.rs`)
- Turn diagnosis → Game state and turns: runs a game (evidence: `src/diagnosis.rs`)
- Turn diagnosis → Policy decisions: evaluates candidates (evidence: `src/diagnosis.rs`)
- Arena command line → Game arena: invokes arena
- Desktop renderer → Player: presents game (evidence: `renderer/app.js`)
- Desktop renderer → Preload bridge: requests game steps
