# jackserafini/briscolarl architecture

> Architecture diagram of the GitHub repository jackserafini/briscolarl, 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/jackserafini/briscolarl
- Repository: https://github.com/jackserafini/briscolarl

## Overview

BriscolaRL is a PyTorch reinforcement-learning project for training and comparing DQN and PPO agents on the Briscola card game. The principal workflow is to run training episodes against the game environment, update an agent, save weights, then evaluate win rates and score breakdowns. The environment implements game state, legal actions, trick resolution, rewards, and opponent turns; the agent modules implement their respective learning methods. README documents training, evaluation, saved models, and result outputs. Notebook internals were not sampled, so notebook relationships are based on README documentation.

Main entry points: [`briscola.py`](https://github.com/jackserafini/briscolarl/blob/main/briscola.py) (Briscola environment), [`train.ipynb`](https://github.com/jackserafini/briscolarl/blob/main/train.ipynb) (Training workflow), [`evaluate.ipynb`](https://github.com/jackserafini/briscolarl/blob/main/evaluate.ipynb) (Evaluation workflow), [`agents/dqn_agent.py`](https://github.com/jackserafini/briscolarl/blob/main/agents/dqn_agent.py) (DQN agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game environment"]
  node_environment["Briscola environment<br/>[briscola.py]"]
end

subgraph group_agents["Learning agents"]
  node_dqn["DQN agent<br/>[dqn_agent.py]"]
  node_ppo["PPO agent<br/>[ppo_agent.py]"]
  node_random["Random agent<br/>[random_agent.py]"]
end

subgraph group_experiments["Experiment workflow"]
  node_training["Training workflow<br/>[train.ipynb]"]
  node_evaluation["Evaluation workflow<br/>[evaluate.ipynb]"]
  node_plots["Result plots<br/>[plots.ipynb]"]
end

subgraph group_artifacts["Results and artifacts"]
  node_weights[("Saved weights")]
  node_outputs["Run outputs"]
end

node_player(("Player"))

node_player -->|"plays actions"| node_environment
node_environment -->|"returns observations"| node_player
node_environment -.->|"requests opponent action"| node_dqn
node_environment -.->|"requests opponent action"| node_ppo
node_training -->|"runs episodes"| node_environment
node_training -->|"trains"| node_dqn
node_training -->|"trains"| node_ppo
node_training -->|"saves models"| node_weights
node_evaluation -->|"evaluates models"| node_weights
node_evaluation -->|"runs episodes"| node_environment
node_evaluation -.->|"records results"| node_outputs
node_plots -.->|"plots results"| node_outputs
node_dqn -->|"uses environment spaces"| node_environment
node_ppo -->|"uses environment spaces"| node_environment

click node_environment "https://github.com/jackserafini/briscolarl/blob/main/briscola.py"
click node_dqn "https://github.com/jackserafini/briscolarl/blob/main/agents/dqn_agent.py"
click node_ppo "https://github.com/jackserafini/briscolarl/blob/main/agents/ppo_agent.py"
click node_random "https://github.com/jackserafini/briscolarl/blob/main/agents/random_agent.py"
click node_training "https://github.com/jackserafini/briscolarl/blob/main/train.ipynb"
click node_evaluation "https://github.com/jackserafini/briscolarl/blob/main/evaluate.ipynb"
click node_plots "https://github.com/jackserafini/briscolarl/blob/main/plots.ipynb"
click node_weights "https://github.com/jackserafini/briscolarl/tree/main/models"
click node_outputs "https://github.com/jackserafini/briscolarl/tree/main/outputs"

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_dqn,node_ppo,node_random toneAmber
class node_training,node_evaluation,node_plots toneMint
class node_weights,node_outputs toneRose
class node_player toneIndigo
```

## Components

### Game environment

- [Briscola environment](https://github.com/jackserafini/briscolarl/blob/main/briscola.py): `briscola.py`

### Learning agents

- [DQN agent](https://github.com/jackserafini/briscolarl/blob/main/agents/dqn_agent.py): `agents/dqn_agent.py`
- [PPO agent](https://github.com/jackserafini/briscolarl/blob/main/agents/ppo_agent.py): `agents/ppo_agent.py`
- [Random agent](https://github.com/jackserafini/briscolarl/blob/main/agents/random_agent.py): `agents/random_agent.py`

### Experiment workflow

- [Training workflow](https://github.com/jackserafini/briscolarl/blob/main/train.ipynb): `train.ipynb`
- [Evaluation workflow](https://github.com/jackserafini/briscolarl/blob/main/evaluate.ipynb): `evaluate.ipynb`
- [Result plots](https://github.com/jackserafini/briscolarl/blob/main/plots.ipynb): `plots.ipynb`

### Results and artifacts

- [Saved weights](https://github.com/jackserafini/briscolarl/tree/main/models): `models`
- [Run outputs](https://github.com/jackserafini/briscolarl/tree/main/outputs): `outputs`

### Other components

- **Player**

## Connections

- Player → Briscola environment: plays actions (evidence: `briscola.py`)
- Briscola environment → Player: returns observations (evidence: `briscola.py`)
- Briscola environment → DQN agent: requests opponent action (evidence: `briscola.py`)
- Briscola environment → PPO agent: requests opponent action (evidence: `briscola.py`)
- Training workflow → Briscola environment: runs episodes (evidence: `README.md`)
- Training workflow → DQN agent: trains (evidence: `README.md`)
- Training workflow → PPO agent: trains (evidence: `README.md`)
- Training workflow → Saved weights: saves models (evidence: `README.md`)
- Evaluation workflow → Saved weights: evaluates models (evidence: `README.md`)
- Evaluation workflow → Briscola environment: runs episodes (evidence: `README.md`)
- Evaluation workflow → Run outputs: records results
- Result plots → Run outputs: plots results
- DQN agent → Briscola environment: uses environment spaces (evidence: `agents/dqn_agent.py`)
- PPO agent → Briscola environment: uses environment spaces (evidence: `agents/ppo_agent.py`)
