# zaferavci1/chessagent architecture

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

- Interactive diagram: https://gitdiagram.com/zaferavci1/chessagent
- Repository: https://github.com/zaferavci1/chessagent

## Overview

This repository combines a Python DQN chess agent with a bundled Stockfish engine. The main user journey is to train the agent using chess positions and Stockfish guidance, then load the trained model to attempt predefined mate puzzles. The README documents these capabilities; the source index confirms Python modules and major Stockfish subsystems, but Python implementation excerpts were not provided. Accordingly, the Stockfish training link is shown as unverified, and the engine’s internal links reflect only relationships supported by the excerpts or source index.

Main entry points: [`stockfish/src/search.cpp`](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/search.cpp) (Move search), [`stockfish/src/engine.cpp`](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/engine.cpp) (Engine control), [`chess_agent_training.py`](https://github.com/zaferavci1/chessagent/blob/main/chess_agent_training.py) (Agent training), [`stockfish/src/position.cpp`](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/position.cpp) (Board position)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Python chess agent"]
  node_training["Agent training"]
  node_model["DQN model<br/>[chess_model.py]"]
  node_puzzles["Mate puzzles<br/>[main.py]"]
end

subgraph group_engine["Stockfish engine"]
  node_uci["UCI interface<br/>[uci.cpp]"]
  node_engine_main["Engine control<br/>[engine.cpp]"]
end

subgraph group_engine_core["Board and search"]
  node_position["Board position<br/>[position.cpp]"]
  node_bitboards["Bitboard attacks<br/>[bitboard.cpp]"]
  node_movegen["Move generation<br/>[movegen.cpp]"]
  node_search["Move search<br/>[search.cpp]"]
  node_movepick["Move ordering<br/>[movepick.cpp]"]
  node_threads["Search threads<br/>[thread.cpp]"]
  node_transposition[("Transposition table<br/>[tt.cpp]")]
end

subgraph group_engine_eval["Position evaluation"]
  node_evaluation["Evaluation<br/>[evaluate.cpp]"]
  node_nnue["NNUE network<br/>[network.cpp]"]
  node_features["NNUE features<br/>[half_ka_v2_hm.cpp]"]
  node_tablebases[("Syzygy tablebases<br/>[tbprobe.cpp]")]
end

node_user(("User"))
node_sf_teacher["Stockfish teacher"]

node_user -->|"starts training"| node_training
node_training -->|"trains"| node_model
node_training -.->|"uses guidance"| node_sf_teacher
node_user -->|"runs puzzles"| node_puzzles
node_puzzles -->|"loads model"| node_model
node_user -.->|"sends commands"| node_uci
node_uci -.->|"routes commands"| node_engine_main
node_engine_main -->|"starts search"| node_threads
node_engine_main -->|"sets position"| node_position
node_engine_main -->|"configures"| node_tablebases
node_search -->|"searches positions"| node_position
node_search -->|"generates moves"| node_movegen
node_search -->|"orders moves"| node_movepick
node_search -->|"evaluates positions"| node_evaluation
node_search -->|"queries network"| node_nnue
node_search -->|"probes endgames"| node_tablebases
node_position -->|"uses attacks"| node_bitboards
node_nnue -->|"uses features"| node_features
node_threads -.->|"runs search"| node_search
node_search -.->|"uses cache"| node_transposition

click node_training "https://github.com/zaferavci1/chessagent/blob/main/chess_agent_training.py"
click node_model "https://github.com/zaferavci1/chessagent/blob/main/chess_model.py"
click node_puzzles "https://github.com/zaferavci1/chessagent/blob/main/main.py"
click node_uci "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/uci.cpp"
click node_engine_main "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/engine.cpp"
click node_position "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/position.cpp"
click node_bitboards "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/bitboard.cpp"
click node_movegen "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/movegen.cpp"
click node_search "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/search.cpp"
click node_movepick "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/movepick.cpp"
click node_threads "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/thread.cpp"
click node_transposition "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/tt.cpp"
click node_evaluation "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/evaluate.cpp"
click node_nnue "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/nnue/network.cpp"
click node_features "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/nnue/features/half_ka_v2_hm.cpp"
click node_tablebases "https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/syzygy/tbprobe.cpp"

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_training,node_model,node_puzzles,node_user toneBlue
class node_uci,node_engine_main toneAmber
class node_position,node_bitboards,node_movegen,node_search,node_movepick,node_threads,node_transposition toneMint
class node_evaluation,node_nnue,node_features,node_tablebases toneRose
class node_sf_teacher toneIndigo
```

## Components

### Python chess agent

- [Agent training](https://github.com/zaferavci1/chessagent/blob/main/chess_agent_training.py): `chess_agent_training.py`
- [DQN model](https://github.com/zaferavci1/chessagent/blob/main/chess_model.py): `chess_model.py`
- [Mate puzzles](https://github.com/zaferavci1/chessagent/blob/main/main.py): `main.py`

### Stockfish engine

- [UCI interface](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/uci.cpp): `stockfish/src/uci.cpp`
- [Engine control](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/engine.cpp): `stockfish/src/engine.cpp`

### Board and search

- [Board position](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/position.cpp): `stockfish/src/position.cpp`
- [Bitboard attacks](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/bitboard.cpp): `stockfish/src/bitboard.cpp`
- [Move generation](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/movegen.cpp): `stockfish/src/movegen.cpp`
- [Move search](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/search.cpp): `stockfish/src/search.cpp`
- [Move ordering](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/movepick.cpp): `stockfish/src/movepick.cpp`
- [Search threads](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/thread.cpp): `stockfish/src/thread.cpp`
- [Transposition table](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/tt.cpp): `stockfish/src/tt.cpp`

### Position evaluation

- [Evaluation](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/evaluate.cpp): `stockfish/src/evaluate.cpp`
- [NNUE network](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/nnue/network.cpp): `stockfish/src/nnue/network.cpp`
- [NNUE features](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/nnue/features/half_ka_v2_hm.cpp): `stockfish/src/nnue/features/half_ka_v2_hm.cpp`
- [Syzygy tablebases](https://github.com/zaferavci1/chessagent/blob/main/stockfish/src/syzygy/tbprobe.cpp): `stockfish/src/syzygy/tbprobe.cpp`

### Other components

- **User**
- **Stockfish teacher**

## Connections

- User → Agent training: starts training
- Agent training → DQN model: trains (evidence: `chess_agent_training.py`)
- Agent training → Stockfish teacher: uses guidance
- User → Mate puzzles: runs puzzles
- Mate puzzles → DQN model: loads model (evidence: `main.py`)
- User → UCI interface: sends commands
- UCI interface → Engine control: routes commands
- Engine control → Search threads: starts search (evidence: `stockfish/src/engine.cpp`)
- Engine control → Board position: sets position (evidence: `stockfish/src/engine.cpp`)
- Engine control → Syzygy tablebases: configures (evidence: `stockfish/src/engine.cpp`)
- Move search → Board position: searches positions (evidence: `stockfish/src/search.cpp`)
- Move search → Move generation: generates moves (evidence: `stockfish/src/search.cpp`)
- Move search → Move ordering: orders moves (evidence: `stockfish/src/search.cpp`)
- Move search → Evaluation: evaluates positions (evidence: `stockfish/src/search.cpp`)
- Move search → NNUE network: queries network (evidence: `stockfish/src/search.cpp`)
- Move search → Syzygy tablebases: probes endgames (evidence: `stockfish/src/search.cpp`)
- Board position → Bitboard attacks: uses attacks
- NNUE network → NNUE features: uses features
- Search threads → Move search: runs search
- Move search → Transposition table: uses cache
