# abhishek21112000/reinforcement-learning architecture

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

- Interactive diagram: https://gitdiagram.com/abhishek21112000/reinforcement-learning
- Repository: https://github.com/abhishek21112000/reinforcement-learning

## Overview

This repository implements Snake in two modes: a human-controlled Pygame game and an AI training loop that learns to play using Q-learning. In the AI workflow, the training loop reads game state, selects and executes actions, trains from transitions, and plots scores; the game engine handles movement, rewards, collisions, and rendering. The model module supplies the neural network and trainer. Source excerpts support these calls; the README is empty, and the existing checkpoint’s use is not shown.

Main entry points: [`agent2.py`](https://github.com/abhishek21112000/reinforcement-learning/blob/main/agent2.py) (Training Loop), [`model.py`](https://github.com/abhishek21112000/reinforcement-learning/blob/main/model.py) (Q Trainer), [`game2.py`](https://github.com/abhishek21112000/reinforcement-learning/blob/main/game2.py) (AI Snake Engine), [`snake_game_human.py`](https://github.com/abhishek21112000/reinforcement-learning/blob/main/snake_game_human.py) (Human Snake Game)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gameplay["Snake Gameplay"]
  node_human_game["Human Snake Game"]
  node_ai_game["AI Snake Engine<br/>[game2.py]"]
end

subgraph group_learning["AI Training"]
  node_training_loop["Training Loop<br/>[agent2.py]"]
  node_agent["Learning Agent<br/>[agent2.py]"]
end

subgraph group_support["Model and Feedback"]
  node_q_network["Q Network<br/>[model.py]"]
  node_q_trainer["Q Trainer<br/>[model.py]"]
  node_score_plot["Score Plotter<br/>[helper.py]"]
end

node_human(("Human Player"))
node_trainer_operator(("Training Operator"))

node_human -->|"controls"| node_human_game
node_trainer_operator -->|"starts training"| node_training_loop
node_training_loop -->|"requests actions"| node_agent
node_training_loop -->|"executes moves"| node_ai_game
node_training_loop -->|"trains transitions"| node_agent
node_training_loop -->|"plots scores"| node_score_plot
node_agent -->|"reads game state"| node_ai_game
node_agent -->|"predicts actions"| node_q_network
node_agent -->|"trains Q values"| node_q_trainer
node_q_trainer -->|"updates weights"| node_q_network

click node_human_game "https://github.com/abhishek21112000/reinforcement-learning/blob/main/snake_game_human.py"
click node_ai_game "https://github.com/abhishek21112000/reinforcement-learning/blob/main/game2.py"
click node_training_loop "https://github.com/abhishek21112000/reinforcement-learning/blob/main/agent2.py"
click node_agent "https://github.com/abhishek21112000/reinforcement-learning/blob/main/agent2.py"
click node_q_network "https://github.com/abhishek21112000/reinforcement-learning/blob/main/model.py"
click node_q_trainer "https://github.com/abhishek21112000/reinforcement-learning/blob/main/model.py"
click node_score_plot "https://github.com/abhishek21112000/reinforcement-learning/blob/main/helper.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_human_game,node_ai_game toneBlue
class node_training_loop,node_agent toneAmber
class node_q_network,node_q_trainer,node_score_plot toneMint
class node_human,node_trainer_operator toneIndigo
```

## Components

### Snake Gameplay

- [Human Snake Game](https://github.com/abhishek21112000/reinforcement-learning/blob/main/snake_game_human.py): `snake_game_human.py`
- [AI Snake Engine](https://github.com/abhishek21112000/reinforcement-learning/blob/main/game2.py): `game2.py`

### AI Training

- [Training Loop](https://github.com/abhishek21112000/reinforcement-learning/blob/main/agent2.py): `agent2.py`
- [Learning Agent](https://github.com/abhishek21112000/reinforcement-learning/blob/main/agent2.py): `agent2.py`

### Model and Feedback

- [Q Network](https://github.com/abhishek21112000/reinforcement-learning/blob/main/model.py): `model.py`
- [Q Trainer](https://github.com/abhishek21112000/reinforcement-learning/blob/main/model.py): `model.py`
- [Score Plotter](https://github.com/abhishek21112000/reinforcement-learning/blob/main/helper.py): `helper.py`

### Other components

- **Human Player**
- **Training Operator**

## Connections

- Human Player → Human Snake Game: controls (evidence: `snake_game_human.py`)
- Training Operator → Training Loop: starts training (evidence: `agent2.py`)
- Training Loop → Learning Agent: requests actions (evidence: `agent2.py`)
- Training Loop → AI Snake Engine: executes moves (evidence: `agent2.py`)
- Training Loop → Learning Agent: trains transitions (evidence: `agent2.py`)
- Training Loop → Score Plotter: plots scores (evidence: `agent2.py`)
- Learning Agent → AI Snake Engine: reads game state (evidence: `agent2.py`)
- Learning Agent → Q Network: predicts actions (evidence: `agent2.py`)
- Learning Agent → Q Trainer: trains Q values (evidence: `agent2.py`)
- Q Trainer → Q Network: updates weights (evidence: `model.py`)
