# emirmurat6606/invertedpendulum architecture

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

- Interactive diagram: https://gitdiagram.com/emirmurat6606/invertedpendulum
- Repository: https://github.com/emirmurat6606/invertedpendulum

## Overview

This is a Pygame inverted-pendulum game with an approximate Q-learning controller and a manual keyboard mode. The main loop initializes the simulation, selects an action (or reads manual input), advances the box-and-pendulum physics, updates the learner, and renders the result; on improved survival time it saves learned weights. The graph includes the documented reward/Q-learning and rendering capabilities. Relationships are limited to calls and data flows shown in excerpts or the README; unsampled details are omitted.

Main entry points: [`main.py`](https://github.com/emirmurat6606/invertedpendulum/blob/main/main.py) (Game Loop), [`Logic/movingbox.py`](https://github.com/emirmurat6606/invertedpendulum/blob/main/Logic/movingbox.py) (Box Motion), [`Rl/model.py`](https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model.py) (RL Controller), [`configs.py`](https://github.com/emirmurat6606/invertedpendulum/blob/main/configs.py) (Game Settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game Runtime"]
  node_game_loop["Game Loop<br/>[main.py]"]
end

subgraph group_physics["Simulation Physics"]
  node_box_physics["Box Motion<br/>[movingbox.py]"]
  node_pendulum_physics["Pendulum Dynamics<br/>[pendulum.py]"]
end

subgraph group_learning["Reinforcement Learning"]
  node_rl_controller["RL Controller<br/>[model.py]"]
  node_q_function["Q Function<br/>[model.py]"]
  node_saved_weights["Saved Weights<br/>[model_weights.txt]"]
end

subgraph group_presentation["Display and Configuration"]
  node_box_view["Box View<br/>[movingbox.py]"]
  node_pendulum_view["Pendulum View<br/>[pendulum.py]"]
  node_settings["Game Settings<br/>[configs.py]"]
end

node_player(("Player"))

node_player -->|"starts or controls"| node_game_loop
node_game_loop -->|"selects and updates"| node_rl_controller
node_game_loop -->|"moves box"| node_box_physics
node_box_physics -->|"updates dynamics"| node_pendulum_physics
node_game_loop -->|"passes observed state"| node_rl_controller
node_rl_controller -->|"evaluates and trains"| node_q_function
node_game_loop -->|"writes best weights"| node_saved_weights
node_game_loop -->|"updates and draws"| node_box_view
node_game_loop -->|"draws pendulum"| node_pendulum_view
node_box_view -->|"reads position"| node_box_physics
node_pendulum_view -->|"renders state"| node_pendulum_physics
node_game_loop -->|"reads settings"| node_settings
node_box_physics -->|"reads physics constants"| node_settings
node_pendulum_physics -->|"reads gravity"| node_settings
node_rl_controller -->|"reads screen width"| node_settings

click node_game_loop "https://github.com/emirmurat6606/invertedpendulum/blob/main/main.py"
click node_box_physics "https://github.com/emirmurat6606/invertedpendulum/blob/main/Logic/movingbox.py"
click node_pendulum_physics "https://github.com/emirmurat6606/invertedpendulum/blob/main/Logic/pendulum.py"
click node_rl_controller "https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model.py"
click node_q_function "https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model.py"
click node_saved_weights "https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model_weights.txt"
click node_box_view "https://github.com/emirmurat6606/invertedpendulum/blob/main/Interface/movingbox.py"
click node_pendulum_view "https://github.com/emirmurat6606/invertedpendulum/blob/main/Interface/pendulum.py"
click node_settings "https://github.com/emirmurat6606/invertedpendulum/blob/main/configs.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_game_loop toneBlue
class node_box_physics,node_pendulum_physics toneAmber
class node_rl_controller,node_q_function,node_saved_weights toneMint
class node_box_view,node_pendulum_view,node_settings toneRose
class node_player toneIndigo
```

## Components

### Game Runtime

- [Game Loop](https://github.com/emirmurat6606/invertedpendulum/blob/main/main.py): `main.py`

### Simulation Physics

- [Box Motion](https://github.com/emirmurat6606/invertedpendulum/blob/main/Logic/movingbox.py): `Logic/movingbox.py`
- [Pendulum Dynamics](https://github.com/emirmurat6606/invertedpendulum/blob/main/Logic/pendulum.py): `Logic/pendulum.py`

### Reinforcement Learning

- [RL Controller](https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model.py): `Rl/model.py`
- [Q Function](https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model.py): `Rl/model.py`
- [Saved Weights](https://github.com/emirmurat6606/invertedpendulum/blob/main/Rl/model_weights.txt): `Rl/model_weights.txt`

### Display and Configuration

- [Box View](https://github.com/emirmurat6606/invertedpendulum/blob/main/Interface/movingbox.py): `Interface/movingbox.py`
- [Pendulum View](https://github.com/emirmurat6606/invertedpendulum/blob/main/Interface/pendulum.py): `Interface/pendulum.py`
- [Game Settings](https://github.com/emirmurat6606/invertedpendulum/blob/main/configs.py): `configs.py`

### Other components

- **Player**

## Connections

- Player → Game Loop: starts or controls (evidence: `README.md`)
- Game Loop → RL Controller: selects and updates (evidence: `main.py`)
- Game Loop → Box Motion: moves box (evidence: `main.py`)
- Box Motion → Pendulum Dynamics: updates dynamics (evidence: `Logic/movingbox.py`)
- Game Loop → RL Controller: passes observed state (evidence: `main.py`)
- RL Controller → Q Function: evaluates and trains (evidence: `Rl/model.py`)
- Game Loop → Saved Weights: writes best weights (evidence: `main.py`)
- Game Loop → Box View: updates and draws (evidence: `main.py`)
- Game Loop → Pendulum View: draws pendulum (evidence: `main.py`)
- Box View → Box Motion: reads position (evidence: `Interface/movingbox.py`)
- Pendulum View → Pendulum Dynamics: renders state (evidence: `Interface/pendulum.py`)
- Game Loop → Game Settings: reads settings (evidence: `main.py`)
- Box Motion → Game Settings: reads physics constants (evidence: `Logic/movingbox.py`)
- Pendulum Dynamics → Game Settings: reads gravity (evidence: `Logic/pendulum.py`)
- RL Controller → Game Settings: reads screen width (evidence: `Rl/model.py`)
