# daz029/balatro-strategy architecture

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

- Interactive diagram: https://gitdiagram.com/daz029/balatro-strategy
- Repository: https://github.com/daz029/balatro-strategy

## Overview

Jackdaw is a Balatro simulator and reinforcement-learning environment. The principal workflow is an agent observing a game state, choosing a legal action through an environment adapter, and receiving the resulting state and reward as the engine advances the run. The repository also supports separate hand-play and shop-agent training, hand-solving and behavior cloning, and decision review via slideshow prototypes. Edges reflect README descriptions or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`jackdaw/engine/game.py`](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/game.py) (Game step engine), [`jackdaw/env/balatro_env.py`](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/balatro_env.py) (Run environment), [`jackdaw/env/hand_play_gym.py`](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/hand_play_gym.py) (Hand-play environment), [`jackdaw/agents/hand_policy_v3.py`](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/hand_policy_v3.py) (Hand policies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_environment["Environments"]
  node_run_env["Run environment<br/>[balatro_env.py]"]
  node_hand_env["Hand-play environment<br/>[hand_play_gym.py]"]
  node_shop_env["Shop environment<br/>[shop_gym.py]"]
  node_observations["State encoding<br/>[observation.py]"]
  node_action_space["Legal actions<br/>[action_space.py]"]
  node_hand_adapter["Hand-play adapter"]
end

subgraph group_agents["Agents"]
  node_hand_agent["Hand policies<br/>[hand_policy_v3.py]"]
  node_pointer_head["Pointer policy head"]
  node_shop_agent["Shop policy<br/>[shop_policy.py]"]
  node_solver["Hand solver<br/>[hand_solver.py]"]
end

subgraph group_engine["Game engine"]
  node_engine_game["Game step engine<br/>[game.py]"]
  node_engine_actions["Actions and phases<br/>[actions.py]"]
  node_scoring["Hand evaluation and scoring<br/>[hand_eval.py]"]
  node_joker_dispatch["Joker effects<br/>[jokers.py]"]
  node_consumables["Consumable effects<br/>[consumables.py]"]
  node_run_init["Run initialization<br/>[run_init.py]"]
  node_shop_logic["Shop operations<br/>[shop.py]"]
end

subgraph group_integration["Bridge and scenarios"]
  node_balatrobot["Balatrobot adapter"]
  node_scenario_defs["Scenario definitions"]
end

subgraph group_review["Decision review"]
  node_hand_slideshow["Hand decision viewer<br/>[app.js]"]
  node_shop_slideshow["Shop decision viewer<br/>[app.js]"]
  node_decision_export["Decision export"]
end

node_player(("Agent or user"))

node_player -.->|"submits actions"| node_run_env
node_run_env -.->|"encodes state"| node_observations
node_run_env -->|"gets legal actions"| node_action_space
node_run_env -.->|"advances game"| node_engine_game
node_hand_env -->|"uses adapter"| node_hand_adapter
node_hand_env -->|"encodes state"| node_observations
node_hand_env -.->|"steps engine"| node_engine_game
node_shop_env -.->|"steps engine"| node_engine_game
node_hand_agent -->|"consumes"| node_observations
node_pointer_head -->|"uses policy"| node_hand_agent
node_hand_agent -.->|"trains in"| node_hand_env
node_shop_agent -.->|"trains in"| node_shop_env
node_solver -.->|"supplies solved data"| node_hand_agent
node_engine_game -->|"validates actions"| node_engine_actions
node_engine_game -->|"scores hands"| node_scoring
node_engine_game -->|"dispatches effects"| node_joker_dispatch
node_engine_game -->|"uses effects"| node_consumables
node_engine_game -->|"initializes runs"| node_run_init
node_engine_game -->|"uses shop logic"| node_shop_logic
node_balatrobot -->|"adapts actions"| node_engine_actions
node_scenario_defs -.->|"configures scenarios"| node_engine_game
node_decision_export -.->|"feeds decisions"| node_hand_slideshow
node_decision_export -.->|"feeds decisions"| node_shop_slideshow

click node_run_env "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/balatro_env.py"
click node_hand_env "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/hand_play_gym.py"
click node_shop_env "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/shop_gym.py"
click node_observations "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/observation.py"
click node_action_space "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/action_space.py"
click node_hand_adapter "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/hand_play_adapter.py"
click node_hand_agent "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/hand_policy_v3.py"
click node_pointer_head "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/hand_pointer_head.py"
click node_shop_agent "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/shop_policy.py"
click node_solver "https://github.com/daz029/balatro-strategy/blob/main/scripts/hand_solver.py"
click node_engine_game "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/game.py"
click node_engine_actions "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/actions.py"
click node_scoring "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/hand_eval.py"
click node_joker_dispatch "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/jokers.py"
click node_consumables "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/consumables.py"
click node_run_init "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/run_init.py"
click node_shop_logic "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/shop.py"
click node_balatrobot "https://github.com/daz029/balatro-strategy/blob/main/jackdaw/bridge/balatrobot_adapter.py"
click node_scenario_defs "https://github.com/daz029/balatro-strategy/tree/main/jackdaw/cli/scenarios"
click node_hand_slideshow "https://github.com/daz029/balatro-strategy/blob/main/prototypes/hand-slideshow/app.js"
click node_shop_slideshow "https://github.com/daz029/balatro-strategy/blob/main/prototypes/shop-slideshow-prototype/app.js"
click node_decision_export "https://github.com/daz029/balatro-strategy/blob/main/scripts/export_shop_decisions_csv.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_run_env,node_hand_env,node_shop_env,node_observations,node_action_space,node_hand_adapter,node_player toneBlue
class node_hand_agent,node_pointer_head,node_shop_agent,node_solver toneAmber
class node_engine_game,node_engine_actions,node_scoring,node_joker_dispatch,node_consumables,node_run_init,node_shop_logic toneMint
class node_balatrobot,node_scenario_defs toneRose
class node_hand_slideshow,node_shop_slideshow,node_decision_export toneIndigo
```

## Components

### Environments

- [Run environment](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/balatro_env.py): `jackdaw/env/balatro_env.py`
- [Hand-play environment](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/hand_play_gym.py): `jackdaw/env/hand_play_gym.py`
- [Shop environment](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/shop_gym.py): `jackdaw/env/shop_gym.py`
- [State encoding](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/observation.py): `jackdaw/env/observation.py`
- [Legal actions](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/action_space.py): `jackdaw/env/action_space.py`
- [Hand-play adapter](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/env/hand_play_adapter.py): `jackdaw/env/hand_play_adapter.py`

### Agents

- [Hand policies](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/hand_policy_v3.py): `jackdaw/agents/hand_policy_v3.py`
- [Pointer policy head](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/hand_pointer_head.py): `jackdaw/agents/hand_pointer_head.py`
- [Shop policy](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/agents/shop_policy.py): `jackdaw/agents/shop_policy.py`
- [Hand solver](https://github.com/daz029/balatro-strategy/blob/main/scripts/hand_solver.py): `scripts/hand_solver.py`

### Game engine

- [Game step engine](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/game.py): `jackdaw/engine/game.py`
- [Actions and phases](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/actions.py): `jackdaw/engine/actions.py`
- [Hand evaluation and scoring](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/hand_eval.py): `jackdaw/engine/hand_eval.py`
- [Joker effects](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/jokers.py): `jackdaw/engine/jokers.py`
- [Consumable effects](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/consumables.py): `jackdaw/engine/consumables.py`
- [Run initialization](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/run_init.py): `jackdaw/engine/run_init.py`
- [Shop operations](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/engine/shop.py): `jackdaw/engine/shop.py`

### Bridge and scenarios

- [Balatrobot adapter](https://github.com/daz029/balatro-strategy/blob/main/jackdaw/bridge/balatrobot_adapter.py): `jackdaw/bridge/balatrobot_adapter.py`
- [Scenario definitions](https://github.com/daz029/balatro-strategy/tree/main/jackdaw/cli/scenarios): `jackdaw/cli/scenarios`

### Decision review

- [Hand decision viewer](https://github.com/daz029/balatro-strategy/blob/main/prototypes/hand-slideshow/app.js): `prototypes/hand-slideshow/app.js`
- [Shop decision viewer](https://github.com/daz029/balatro-strategy/blob/main/prototypes/shop-slideshow-prototype/app.js): `prototypes/shop-slideshow-prototype/app.js`
- [Decision export](https://github.com/daz029/balatro-strategy/blob/main/scripts/export_shop_decisions_csv.py): `scripts/export_shop_decisions_csv.py`

### Other components

- **Agent or user**

## Connections

- Agent or user → Run environment: submits actions
- Run environment → State encoding: encodes state (evidence: `jackdaw/env/observation.py`)
- Run environment → Legal actions: gets legal actions (evidence: `jackdaw/env/action_space.py`)
- Run environment → Game step engine: advances game
- Hand-play environment → Hand-play adapter: uses adapter (evidence: `jackdaw/env/hand_play_gym.py`)
- Hand-play environment → State encoding: encodes state (evidence: `jackdaw/env/hand_play_gym.py`)
- Hand-play environment → Game step engine: steps engine
- Shop environment → Game step engine: steps engine
- Hand policies → State encoding: consumes (evidence: `jackdaw/agents/hand_policy_v3.py`)
- Pointer policy head → Hand policies: uses policy (evidence: `jackdaw/agents/hand_pointer_head.py`)
- Hand policies → Hand-play environment: trains in
- Shop policy → Shop environment: trains in
- Hand solver → Hand policies: supplies solved data
- Game step engine → Actions and phases: validates actions (evidence: `jackdaw/engine/game.py`)
- Game step engine → Hand evaluation and scoring: scores hands (evidence: `jackdaw/engine/game.py`)
- Game step engine → Joker effects: dispatches effects (evidence: `jackdaw/engine/game.py`)
- Game step engine → Consumable effects: uses effects (evidence: `jackdaw/engine/game.py`)
- Game step engine → Run initialization: initializes runs (evidence: `jackdaw/engine/game.py`)
- Game step engine → Shop operations: uses shop logic (evidence: `jackdaw/engine/game.py`)
- Balatrobot adapter → Actions and phases: adapts actions (evidence: `jackdaw/bridge/balatrobot_adapter.py`)
- Scenario definitions → Game step engine: configures scenarios
- Decision export → Hand decision viewer: feeds decisions
- Decision export → Shop decision viewer: feeds decisions
