# sam230230/balatro-auto-game-play-data-acquisition architecture

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

- Interactive diagram: https://gitdiagram.com/sam230230/balatro-auto-game-play-data-acquisition
- Repository: https://github.com/sam230230/balatro-auto-game-play-data-acquisition

## Overview

Balatro gameplay automation is driven by BLTR_controller.py: it observes the game screen, chooses hand/discard actions, executes clicks, tracks scores and endings, and records sessions. Hand-card detection and game-stat OCR provide observations; card selection and Markov-parameter optimization support decisions and learning. The README also describes gameplay-data generation and optimization. Evidence is strongest for the controller’s integrations; the templates directory is present, but its runtime path is hard-coded elsewhere, so that link is not inferred.

Main entry points: [`BLTR_controller.py`](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py) (Gameplay controller), [`cards_detect_fn.py`](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/cards_detect_fn.py) (Hand-card detection), [`game_end_info_detect.py`](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/game_end_info_detect.py) (Game-stat OCR), [`auto_card_selector.py`](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/auto_card_selector.py) (Card selector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_automation["Gameplay automation"]
  node_controller["Gameplay controller<br/>[BLTR_controller.py]"]
  node_selector["Card selector"]
end

subgraph group_perception["Screen perception"]
  node_card_detect["Hand-card detection<br/>[cards_detect_fn.py]"]
  node_end_ocr["Game-stat OCR"]
end

subgraph group_learning["Decision learning"]
  node_optimizer["Markov optimizer"]
end

subgraph group_state["Session state"]
  node_session_log[("Gameplay session log<br/>[BLTR_controller.py]")]
  node_learned_params[("Learned parameters<br/>[BLTR_controller.py]")]
end

node_operator(("Operator"))
node_game["Balatro game"]

node_operator -->|"starts"| node_controller
node_controller -->|"detects cards"| node_card_detect
node_controller -->|"reads game stats"| node_end_ocr
node_controller -->|"selects cards"| node_selector
node_controller -->|"clicks controls"| node_game
node_card_detect -->|"captures hand"| node_game
node_end_ocr -->|"captures stats"| node_game
node_controller -->|"fits parameters"| node_optimizer
node_controller -->|"appends sessions"| node_session_log
node_controller -->|"loads parameters"| node_learned_params
node_controller -->|"saves parameters"| node_learned_params

click node_controller "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py"
click node_selector "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/auto_card_selector.py"
click node_card_detect "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/cards_detect_fn.py"
click node_end_ocr "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/game_end_info_detect.py"
click node_optimizer "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/play_balatro_par_optim.py"
click node_session_log "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py"
click node_learned_params "https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.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_controller,node_selector toneBlue
class node_card_detect,node_end_ocr toneAmber
class node_optimizer toneMint
class node_session_log,node_learned_params toneRose
class node_operator,node_game toneIndigo
```

## Components

### Gameplay automation

- [Gameplay controller](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py): `BLTR_controller.py`
- [Card selector](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/auto_card_selector.py): `auto_card_selector.py`

### Screen perception

- [Hand-card detection](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/cards_detect_fn.py): `cards_detect_fn.py`
- [Game-stat OCR](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/game_end_info_detect.py): `game_end_info_detect.py`

### Decision learning

- [Markov optimizer](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/play_balatro_par_optim.py): `play_balatro_par_optim.py`

### Session state

- [Gameplay session log](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py): `BLTR_controller.py`
- [Learned parameters](https://github.com/sam230230/balatro-auto-game-play-data-acquisition/blob/main/BLTR_controller.py): `BLTR_controller.py`

### Other components

- **Operator**
- **Balatro game**

## Connections

- Operator → Gameplay controller: starts (evidence: `README.md`)
- Gameplay controller → Hand-card detection: detects cards (evidence: `BLTR_controller.py`)
- Gameplay controller → Game-stat OCR: reads game stats (evidence: `BLTR_controller.py`)
- Gameplay controller → Card selector: selects cards (evidence: `BLTR_controller.py`)
- Gameplay controller → Balatro game: clicks controls (evidence: `BLTR_controller.py`)
- Hand-card detection → Balatro game: captures hand (evidence: `cards_detect_fn.py`)
- Game-stat OCR → Balatro game: captures stats (evidence: `game_end_info_detect.py`)
- Gameplay controller → Markov optimizer: fits parameters (evidence: `BLTR_controller.py`)
- Gameplay controller → Gameplay session log: appends sessions (evidence: `BLTR_controller.py`)
- Gameplay controller → Learned parameters: loads parameters (evidence: `BLTR_controller.py`)
- Gameplay controller → Learned parameters: saves parameters (evidence: `BLTR_controller.py`)
