# lackio-el-14/proyecto-inteligencia-artifical---juego-snake architecture

> Architecture diagram of the GitHub repository lackio-el-14/proyecto-inteligencia-artifical---juego-snake, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake
- Repository: https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake

## Overview

This is a Snake-game reinforcement-learning project: users train a Double DQN agent across four level definitions, evaluate saved weights, and inspect play in a pygame viewer. The game environment owns movement, collisions, rewards, and episode outcomes; state construction supplies BFS-based sensors to learned and baseline policies. Training also records metrics and periodically evaluates the learner. Separate capabilities include baseline comparisons and plotting training, evaluation, and ablation results. Edges reflect the shown imports and calls or README documentation; unsampled level and plotting details are represented cautiously.

Main entry points: [`train.py`](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/train.py) (Training workflow), [`viewer.py`](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/viewer.py) (Interactive viewer), [`evaluate.py`](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/evaluate.py) (Greedy evaluation), [`snake_env.py`](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/snake_env.py) (Snake environment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game and state"]
  node_config["Configuration<br/>[config.py]"]
  node_levels["Level definitions<br/>[level_1.json]"]
  node_environment["Snake environment<br/>[snake_env.py]"]
  node_state["BFS state sensors<br/>[state.py]"]
end

subgraph group_learning["Policies and learning"]
  node_dqn["Double DQN agent<br/>[agent.py]"]
  node_replay["Replay memory<br/>[agent.py]"]
  node_baselines["Baseline policies<br/>[baselines.py]"]
end

subgraph group_workflows["Training and evaluation"]
  node_trainer["Training workflow<br/>[train.py]"]
  node_evaluator["Greedy evaluation<br/>[evaluate.py]"]
end

subgraph group_analysis["Analysis and viewing"]
  node_plots["Result plots<br/>[plots.py]"]
  node_viewer["Interactive viewer<br/>[viewer.py]"]
end

node_player(("Project user"))
node_metrics["Run metrics"]
node_weights["Model weights"]

node_player -->|"starts training"| node_trainer
node_player -->|"requests evaluation"| node_evaluator
node_player -->|"starts viewer"| node_viewer
node_trainer -->|"reads settings"| node_config
node_trainer -->|"selects levels"| node_levels
node_trainer -->|"runs episodes"| node_environment
node_trainer -->|"builds states"| node_state
node_trainer -->|"selects and trains"| node_dqn
node_trainer -->|"stores and samples"| node_replay
node_trainer -->|"periodically evaluates"| node_evaluator
node_trainer -->|"writes metrics"| node_metrics
node_trainer -->|"saves weights"| node_weights
node_environment -->|"reads rewards"| node_config
node_environment -->|"loads level data"| node_levels
node_state -->|"reads game state"| node_environment
node_dqn -->|"reads hyperparameters"| node_config
node_baselines -->|"runs episodes"| node_environment
node_baselines -->|"builds policy inputs"| node_state
node_evaluator -->|"loads and queries"| node_dqn
node_evaluator -->|"runs episodes"| node_environment
node_evaluator -->|"builds states"| node_state
node_evaluator -->|"writes results"| node_metrics
node_plots -->|"reads run results"| node_metrics
node_plots -->|"reads baseline results"| node_baselines
node_viewer -->|"advances game"| node_environment
node_viewer -->|"builds sensor view"| node_state
node_viewer -->|"queries agent"| node_dqn
node_viewer -->|"uses baseline policies"| node_baselines
node_viewer -->|"reads failure results"| node_evaluator
node_viewer -->|"loads saved model"| node_weights

click node_config "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/config.py"
click node_levels "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/levels/level_1.json"
click node_environment "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/snake_env.py"
click node_state "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/state.py"
click node_dqn "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/agent.py"
click node_replay "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/agent.py"
click node_baselines "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/baselines.py"
click node_trainer "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/train.py"
click node_evaluator "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/evaluate.py"
click node_plots "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/plots.py"
click node_viewer "https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/viewer.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_config,node_levels,node_environment,node_state,node_player toneBlue
class node_dqn,node_replay,node_baselines toneAmber
class node_trainer,node_evaluator toneMint
class node_plots,node_viewer toneRose
class node_metrics,node_weights toneIndigo
```

## Components

### Game and state

- [Configuration](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/config.py): `config.py`
- [Level definitions](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/levels/level_1.json): `levels/level_1.json`
- [Snake environment](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/snake_env.py): `snake_env.py`
- [BFS state sensors](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/state.py): `state.py`

### Policies and learning

- [Double DQN agent](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/agent.py): `agent.py`
- [Replay memory](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/agent.py): `agent.py`
- [Baseline policies](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/baselines.py): `baselines.py`

### Training and evaluation

- [Training workflow](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/train.py): `train.py`
- [Greedy evaluation](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/evaluate.py): `evaluate.py`

### Analysis and viewing

- [Result plots](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/plots.py): `plots.py`
- [Interactive viewer](https://github.com/lackio-el-14/proyecto-inteligencia-artifical---juego-snake/blob/main/viewer.py): `viewer.py`

### Other components

- **Project user**
- **Run metrics**
- **Model weights**

## Connections

- Project user → Training workflow: starts training (evidence: `README.md`)
- Project user → Greedy evaluation: requests evaluation (evidence: `README.md`)
- Project user → Interactive viewer: starts viewer (evidence: `README.md`)
- Training workflow → Configuration: reads settings (evidence: `train.py`)
- Training workflow → Level definitions: selects levels (evidence: `README.md`)
- Training workflow → Snake environment: runs episodes (evidence: `train.py`)
- Training workflow → BFS state sensors: builds states (evidence: `train.py`)
- Training workflow → Double DQN agent: selects and trains (evidence: `train.py`)
- Training workflow → Replay memory: stores and samples (evidence: `train.py`)
- Training workflow → Greedy evaluation: periodically evaluates (evidence: `train.py`)
- Training workflow → Run metrics: writes metrics (evidence: `train.py`)
- Training workflow → Model weights: saves weights (evidence: `train.py`)
- Snake environment → Configuration: reads rewards (evidence: `snake_env.py`)
- Snake environment → Level definitions: loads level data (evidence: `README.md`)
- BFS state sensors → Snake environment: reads game state (evidence: `state.py`)
- Double DQN agent → Configuration: reads hyperparameters (evidence: `agent.py`)
- Baseline policies → Snake environment: runs episodes (evidence: `baselines.py`)
- Baseline policies → BFS state sensors: builds policy inputs (evidence: `baselines.py`)
- Greedy evaluation → Double DQN agent: loads and queries (evidence: `evaluate.py`)
- Greedy evaluation → Snake environment: runs episodes (evidence: `evaluate.py`)
- Greedy evaluation → BFS state sensors: builds states (evidence: `evaluate.py`)
- Greedy evaluation → Run metrics: writes results (evidence: `README.md`)
- Result plots → Run metrics: reads run results (evidence: `plots.py`)
- Result plots → Baseline policies: reads baseline results (evidence: `plots.py`)
- Interactive viewer → Snake environment: advances game (evidence: `viewer.py`)
- Interactive viewer → BFS state sensors: builds sensor view (evidence: `viewer.py`)
- Interactive viewer → Double DQN agent: queries agent (evidence: `viewer.py`)
- Interactive viewer → Baseline policies: uses baseline policies (evidence: `viewer.py`)
- Interactive viewer → Greedy evaluation: reads failure results (evidence: `viewer.py`)
- Interactive viewer → Model weights: loads saved model (evidence: `README.md`)
