# narayan-bhattarai/baghchal architecture

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

- Interactive diagram: https://gitdiagram.com/narayan-bhattarai/baghchal
- Repository: https://github.com/narayan-bhattarai/baghchal

## Overview

This repository is a single-script BaghChal reinforcement-learning application. Its main workflow trains role-specific agents in self-play against the custom game environment, saves learned models or Q-tables, and evaluates results through reward and win-rate visualizations; a separate terminal mode lets a person play against trained agents. The README documents Q-Learning, SARSA, Expected SARSA, and DQN, though the supplied excerpts show only parts of their implementations. Components share DQN.py because the tree contains no separate source modules; edges reflect README statements or visible training code.

Main entry points: [`DQN.py`](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py) (Self-Play Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game"]
  node_environment["BaghChal Environment<br/>[DQN.py]"]
end

subgraph group_learning["RL Training"]
  node_selfplay["Self-Play Training<br/>[DQN.py]"]
  node_qlearning["Q-Learning<br/>[DQN.py]"]
  node_sarsa["SARSA<br/>[DQN.py]"]
  node_esarsa["Expected SARSA<br/>[DQN.py]"]
  node_dqn["Deep Q-Network<br/>[DQN.py]"]
  node_artifacts[("Saved Models &amp; Tables<br/>[DQN.py]")]
end

subgraph group_use["Play &amp; Evaluation"]
  node_terminal["Terminal Game<br/>[DQN.py]"]
  node_evaluation["Performance Evaluation<br/>[DQN.py]"]
  node_visualizations["Training Plots<br/>[DQN.py]"]
end

node_human(("Human Player"))

node_selfplay -->|"uses game"| node_environment
node_selfplay -->|"trains"| node_qlearning
node_selfplay -->|"trains"| node_sarsa
node_selfplay -->|"trains"| node_esarsa
node_selfplay -->|"trains"| node_dqn
node_selfplay -->|"saves learned state"| node_artifacts
node_evaluation -->|"evaluates performance"| node_selfplay
node_evaluation -->|"plots results"| node_visualizations
node_human -->|"plays against"| node_terminal
node_terminal -->|"uses trained agents"| node_artifacts

click node_environment "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_selfplay "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_qlearning "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_sarsa "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_esarsa "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_dqn "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_artifacts "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_terminal "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_evaluation "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"
click node_visualizations "https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py"

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_environment toneBlue
class node_selfplay,node_qlearning,node_sarsa,node_esarsa,node_dqn,node_artifacts toneAmber
class node_terminal,node_evaluation,node_visualizations toneMint
class node_human toneIndigo
```

## Components

### Game

- [BaghChal Environment](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`

### RL Training

- [Self-Play Training](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Q-Learning](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [SARSA](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Expected SARSA](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Deep Q-Network](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Saved Models & Tables](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`

### Play & Evaluation

- [Terminal Game](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Performance Evaluation](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`
- [Training Plots](https://github.com/narayan-bhattarai/baghchal/blob/main/DQN.py): `DQN.py`

### Other components

- **Human Player**

## Connections

- Self-Play Training → BaghChal Environment: uses game (evidence: `README.md`)
- Self-Play Training → Q-Learning: trains (evidence: `README.md`)
- Self-Play Training → SARSA: trains (evidence: `README.md`)
- Self-Play Training → Expected SARSA: trains (evidence: `README.md`)
- Self-Play Training → Deep Q-Network: trains (evidence: `README.md`)
- Self-Play Training → Saved Models & Tables: saves learned state (evidence: `README.md`)
- Performance Evaluation → Self-Play Training: evaluates performance (evidence: `README.md`)
- Performance Evaluation → Training Plots: plots results (evidence: `README.md`)
- Human Player → Terminal Game: plays against (evidence: `README.md`)
- Terminal Game → Saved Models & Tables: uses trained agents (evidence: `README.md`)
