# jayanad/rl_flappy_bird architecture

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

- Interactive diagram: https://gitdiagram.com/jayanad/rl_flappy_bird
- Repository: https://github.com/jayanad/rl_flappy_bird

## Overview

This repository implements a Deep Q-Network agent for Flappy Bird, plus a separate keyboard-controlled game runner. In training, the agent loads a hyperparameter set, interacts with the Gymnasium environment, stores transitions in replay memory, and uses sampled batches to update its policy and target networks. It saves the best policy and a reward log; evaluation loads the saved policy and plays with rendering enabled. The sampled source establishes these connections; no README content was provided.

Main entry points: [`agent.py`](https://github.com/jayanad/rl_flappy_bird/blob/master/agent.py) (DQN agent), [`game.py`](https://github.com/jayanad/rl_flappy_bird/blob/master/game.py) (Keyboard game runner), [`dqn.py`](https://github.com/jayanad/rl_flappy_bird/blob/master/dqn.py) (Q-network), [`experience_replay.py`](https://github.com/jayanad/rl_flappy_bird/blob/master/experience_replay.py) (Replay memory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_learning["Agent learning"]
  node_agent["DQN agent<br/>[agent.py]"]
  node_network["Q-network<br/>[dqn.py]"]
  node_replay[("Replay memory")]
  node_optimizer["PyTorch optimizer"]
end

subgraph group_environment["Game interaction"]
  node_game_runner["Keyboard game runner<br/>[game.py]"]
  node_bird_env["Flappy Bird environment"]
  node_pygame["Pygame input/render"]
end

subgraph group_settings["Settings and artifacts"]
  node_params["Hyperparameters<br/>[parameters.yaml]"]
  node_model_file["Saved policy"]
  node_reward_log["Training log"]
end

node_user(("User"))

node_user -->|"selects mode"| node_agent
node_agent -->|"reads settings"| node_params
node_agent -->|"resets and steps"| node_bird_env
node_bird_env -->|"returns observations"| node_agent
node_agent -->|"evaluates policy"| node_network
node_agent -->|"stores transitions"| node_replay
node_agent -->|"samples batches"| node_replay
node_agent -->|"updates networks"| node_network
node_agent -->|"optimizes policy"| node_optimizer
node_agent -->|"loads or saves policy"| node_model_file
node_agent -->|"writes best reward"| node_reward_log
node_user -->|"starts and controls"| node_game_runner
node_game_runner -->|"reads input and renders"| node_pygame
node_game_runner -->|"resets and steps"| node_bird_env

click node_agent "https://github.com/jayanad/rl_flappy_bird/blob/master/agent.py"
click node_network "https://github.com/jayanad/rl_flappy_bird/blob/master/dqn.py"
click node_replay "https://github.com/jayanad/rl_flappy_bird/blob/master/experience_replay.py"
click node_game_runner "https://github.com/jayanad/rl_flappy_bird/blob/master/game.py"
click node_params "https://github.com/jayanad/rl_flappy_bird/blob/master/parameters.yaml"

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_agent,node_network,node_replay,node_optimizer,node_user toneBlue
class node_game_runner,node_bird_env,node_pygame toneAmber
class node_params,node_model_file,node_reward_log toneMint
```

## Components

### Agent learning

- [DQN agent](https://github.com/jayanad/rl_flappy_bird/blob/master/agent.py): `agent.py`
- [Q-network](https://github.com/jayanad/rl_flappy_bird/blob/master/dqn.py): `dqn.py`
- [Replay memory](https://github.com/jayanad/rl_flappy_bird/blob/master/experience_replay.py): `experience_replay.py`
- **PyTorch optimizer**

### Game interaction

- [Keyboard game runner](https://github.com/jayanad/rl_flappy_bird/blob/master/game.py): `game.py`
- **Flappy Bird environment**
- **Pygame input/render**

### Settings and artifacts

- [Hyperparameters](https://github.com/jayanad/rl_flappy_bird/blob/master/parameters.yaml): `parameters.yaml`
- **Saved policy**
- **Training log**

### Other components

- **User**

## Connections

- User → DQN agent: selects mode
- DQN agent → Hyperparameters: reads settings
- DQN agent → Flappy Bird environment: resets and steps
- Flappy Bird environment → DQN agent: returns observations
- DQN agent → Q-network: evaluates policy
- DQN agent → Replay memory: stores transitions
- DQN agent → Replay memory: samples batches
- DQN agent → Q-network: updates networks
- DQN agent → PyTorch optimizer: optimizes policy
- DQN agent → Saved policy: loads or saves policy
- DQN agent → Training log: writes best reward
- User → Keyboard game runner: starts and controls
- Keyboard game runner → Pygame input/render: reads input and renders
- Keyboard game runner → Flappy Bird environment: resets and steps
