Skip to content

Commit 5fca88c

Browse files
committed
docs: simplify docs and add mermaid diagrams
1 parent 249ec7e commit 5fca88c

File tree

8 files changed

+252
-838
lines changed

8 files changed

+252
-838
lines changed

docs/architecture.md

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ Balatrobot consists of two main components working together:
1111

1212
These components communicate via UDP sockets to achieve real-time bot control.
1313

14-
```
15-
┌─────────────────┐ UDP Socket ┌─────────────────┐
16-
│ Balatro Game │ ◄──────────────► │ Python Bot │
17-
│ (Lua Mod) │ Port 12345+ │ (Bot Logic) │
18-
└─────────────────┘ └─────────────────┘
14+
```mermaid
15+
graph LR
16+
A["Balatro Game<br/>(Lua Mod)"] <-->|"UDP Socket<br/>Port 12345+"| B["Python Bot<br/>(Bot Logic)"]
1917
```
2018

2119
## Component Architecture
@@ -24,21 +22,23 @@ These components communicate via UDP sockets to achieve real-time bot control.
2422

2523
The Lua mod consists of several interconnected modules:
2624

27-
```
28-
main.lua
29-
├── config.lua (Configuration)
30-
├── lib/ (External Libraries)
31-
│ ├── hook.lua (Function hooking)
32-
│ ├── sock.lua (UDP networking)
33-
│ ├── json.lua (JSON serialization)
34-
│ ├── list.lua (Data structures)
35-
│ └── bitser.lua (Binary serialization)
36-
└── src/ (Core Modules)
37-
├── api.lua (UDP API server)
38-
├── bot.lua (Action definitions)
39-
├── middleware.lua (Game hooks)
40-
├── botlogger.lua (Logging/replay)
41-
└── utils.lua (Utility functions)
25+
```mermaid
26+
graph TD
27+
A["main.lua"] --> B["config.lua (Configuration)"]
28+
A --> C["lib/ (External Libraries)"]
29+
A --> D["src/ (Core Modules)"]
30+
31+
C --> E["hook.lua (Function hooking)"]
32+
C --> F["sock.lua (UDP networking)"]
33+
C --> G["json.lua (JSON serialization)"]
34+
C --> H["list.lua (Data structures)"]
35+
C --> I["bitser.lua (Binary serialization)"]
36+
37+
D --> J["api.lua (UDP API server)"]
38+
D --> K["bot.lua (Action definitions)"]
39+
D --> L["middleware.lua (Game hooks)"]
40+
D --> M["botlogger.lua (Logging/replay)"]
41+
D --> N["utils.lua (Utility functions)"]
4242
```
4343

4444
#### Key Modules
@@ -53,12 +53,12 @@ main.lua
5353

5454
The Python side provides the bot framework and decision-making logic:
5555

56-
```
57-
Bot Framework
58-
├── bot.py (Base Bot class)
59-
├── gamestates.py (State caching)
60-
├── bot_example.py (Simple example)
61-
└── flush_bot.py (Advanced example)
56+
```mermaid
57+
graph TD
58+
A["Bot Framework"] --> B["bot.py (Base Bot class)"]
59+
A --> C["gamestates.py (State caching)"]
60+
A --> D["bot_example.py (Simple example)"]
61+
A --> E["flush_bot.py (Advanced example)"]
6262
```
6363

6464
#### Base Bot Class
@@ -75,29 +75,30 @@ The communication between components follows this pattern:
7575

7676
### 1. Initialization
7777

78-
```
79-
Python Bot Lua Mod
80-
│ │
81-
├─── HELLO ──────────────► │
82-
│ ├─── Game State ───►
83-
◄─── Game State ───────────┤
84-
│ │
78+
```mermaid
79+
sequenceDiagram
80+
participant PB as Python Bot
81+
participant LM as Lua Mod
82+
83+
PB->>LM: HELLO
84+
LM->>PB: Game State
8585
```
8686

8787
### 2. Decision Loop
8888

89-
```
90-
Python Bot Lua Mod
91-
│ │
92-
│ ├─── Wait for Action
93-
│ ├─── Send Game State ──►
94-
◄─── Game State ───────────┤
95-
├─── Process State │
96-
├─── Make Decision │
97-
├─── Send Action ────────► │
98-
│ ├─── Execute Action
99-
│ ├─── Update Game
100-
│ └─── Loop
89+
```mermaid
90+
sequenceDiagram
91+
participant PB as Python Bot
92+
participant LM as Lua Mod
93+
94+
LM->>LM: Wait for Action
95+
LM->>PB: Send Game State
96+
PB->>PB: Process State
97+
PB->>PB: Make Decision
98+
PB->>LM: Send Action
99+
LM->>LM: Execute Action
100+
LM->>LM: Update Game
101+
LM->>LM: Loop
101102
```
102103

103104
### 3. Game State Structure

docs/configuration.md

Lines changed: 32 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,216 +1,79 @@
11
# Configuration Guide
22

3-
Complete guide to configuring Balatrobot for optimal performance and functionality.
3+
Balatrobot configuration is controlled by `config.lua` in the mod directory.
44

5-
## Configuration File Overview
6-
7-
The main configuration is stored in `config.lua` in the mod directory. This file controls all aspects of the Balatrobot mod behavior.
8-
9-
### Default Configuration
5+
## Configuration File
106

117
```lua
128
BALATRO_BOT_CONFIG = {
13-
enabled = true, -- Master enable/disable switch
14-
port = '12345', -- UDP port for communication
15-
dt = 8.0/60.0, -- Game update speed multiplier
9+
enabled = true, -- Enable/disable mod functionality
10+
port = '12345', -- UDP port for bot communication
11+
dt = 8.0/60.0, -- Game update speed (lower = faster)
1612
uncap_fps = true, -- Remove FPS limitations
1713
instant_move = true, -- Disable movement animations
1814
disable_vsync = true, -- Disable vertical sync
1915
disable_card_eval_status_text = true, -- Hide card scoring text
20-
frame_ratio = 100, -- Render frequency (1 = every frame)
16+
frame_ratio = 100, -- Render every Nth frame (higher = faster)
2117
}
2218
```
2319

24-
## Core Settings
20+
## Configuration Options
2521

2622
### enabled
23+
**Type:** `boolean` | **Default:** `true`
2724

28-
**Type:** `boolean`
29-
**Default:** `true`
30-
**Description:** Master switch for all mod functionality.
31-
32-
```lua
33-
enabled = true -- Mod is active
34-
enabled = false -- Mod is completely disabled
35-
```
36-
37-
**Usage:**
38-
- Set to `false` to temporarily disable the mod without uninstalling
39-
- Useful for playing the game normally without bot interference
25+
Master switch for all mod functionality. Set to `false` to disable the mod without uninstalling.
4026

4127
### port
28+
**Type:** `string` | **Default:** `'12345'`
4229

43-
**Type:** `string`
44-
**Default:** `'12345'`
45-
**Description:** UDP port for bot communication.
46-
47-
```lua
48-
port = '12345' -- Default port
49-
port = '12346' -- Alternative port to avoid conflicts
50-
```
51-
52-
**Important Notes:**
53-
- Must match the port in your Python bot configuration
54-
- Change if multiple bot instances are running simultaneously
55-
- Can be overridden by command line argument when launching Balatro
56-
57-
**Port Selection Guidelines:**
58-
- Use ports 12345-12355 for standard single-bot usage
59-
- For multiple instances, increment by 1 for each instance
60-
- Avoid system ports (1-1024) and common application ports
61-
62-
## Performance Optimization
63-
64-
### dt (Delta Time)
65-
66-
**Type:** `number`
67-
**Default:** `8.0/60.0` (~0.133)
68-
**Description:** Game update interval in seconds. Lower values = faster game.
69-
70-
```lua
71-
dt = 8.0/60.0 -- Default: ~7.5 FPS equivalent
72-
dt = 4.0/60.0 -- Faster: ~15 FPS equivalent
73-
dt = 16.0/60.0 -- Slower: ~3.75 FPS equivalent
74-
dt = 1.0/60.0 -- Maximum speed: ~60 FPS equivalent
75-
```
30+
UDP port for bot communication. Must match the port in your Python bot. Can be overridden by command line argument when launching Balatro.
7631

77-
**Performance Impact:**
78-
- **Lower values**: Faster game execution, higher CPU usage
79-
- **Higher values**: Slower execution, more visible for debugging
80-
- **Recommended range**: 4.0/60.0 to 16.0/60.0 for stability
32+
### dt
33+
**Type:** `number` | **Default:** `8.0/60.0`
8134

82-
**Stability Considerations:**
83-
- Values below 4.0/60.0 may cause game instability
84-
- Very low values can overwhelm the networking stack
85-
- Test thoroughly when using extreme values
35+
Game update interval in seconds. Lower values make the game run faster but use more CPU.
8636

8737
### uncap_fps
38+
**Type:** `boolean` | **Default:** `true`
8839

89-
**Type:** `boolean`
90-
**Default:** `true`
91-
**Description:** Remove FPS limitations for maximum speed.
92-
93-
```lua
94-
uncap_fps = true -- Remove FPS cap (recommended for bots)
95-
uncap_fps = false -- Keep normal FPS limits
96-
```
97-
98-
**Effects:**
99-
- `true`: Game runs as fast as possible, better for bot performance
100-
- `false`: Game respects normal FPS limits, more stable visually
101-
102-
### frame_ratio
103-
104-
**Type:** `integer`
105-
**Default:** `100`
106-
**Description:** Render every Nth frame. Higher values = less rendering.
107-
108-
```lua
109-
frame_ratio = 1 -- Render every frame (full visual)
110-
frame_ratio = 10 -- Render every 10th frame
111-
frame_ratio = 100 -- Render every 100th frame (minimal visual)
112-
frame_ratio = 200 -- Render every 200th frame (fastest)
113-
```
114-
115-
**Performance vs Visual Quality:**
116-
117-
| Value | Rendering | Performance | Use Case |
118-
|-------|-----------|-------------|----------|
119-
| 1 | Full visual | Slowest | Debugging, demonstrations |
120-
| 10 | Reduced visual | Moderate | Development testing |
121-
| 100 | Minimal visual | Fast | Production bots |
122-
| 200+ | Almost no visual | Fastest | Benchmark/batch runs |
123-
124-
## Visual Settings
40+
Remove FPS limitations for maximum game speed. Recommended for bot performance.
12541

12642
### instant_move
43+
**Type:** `boolean` | **Default:** `true`
12744

128-
**Type:** `boolean`
129-
**Default:** `true`
130-
**Description:** Skip movement animations for instant card positioning.
131-
132-
```lua
133-
instant_move = true -- Cards move instantly (faster)
134-
instant_move = false -- Cards use smooth animations (slower)
135-
```
136-
137-
**Impact:**
138-
- `true`: Significant performance improvement, no smooth movements
139-
- `false`: Normal game animations, slower but more visually appealing
45+
Skip movement animations for instant card positioning. Provides significant performance improvement.
14046

14147
### disable_vsync
48+
**Type:** `boolean` | **Default:** `true`
14249

143-
**Type:** `boolean`
144-
**Default:** `true`
145-
**Description:** Disable vertical synchronization.
146-
147-
```lua
148-
disable_vsync = true -- Disable VSync (faster, may cause tearing)
149-
disable_vsync = false -- Enable VSync (smoother, frame-rate limited)
150-
```
151-
152-
**Considerations:**
153-
- `true`: Better performance, possible screen tearing
154-
- `false`: Smoother visuals, frame rate limited to monitor refresh
50+
Disable vertical synchronization for better performance.
15551

15652
### disable_card_eval_status_text
53+
**Type:** `boolean` | **Default:** `true`
15754

158-
**Type:** `boolean`
159-
**Default:** `true`
160-
**Description:** Hide floating text when cards are scored ("+10", etc.).
161-
162-
```lua
163-
disable_card_eval_status_text = true -- Hide score text (faster)
164-
disable_card_eval_status_text = false -- Show score text (slower)
165-
```
166-
167-
**Performance Impact:**
168-
- Disabling this text provides a small but measurable performance improvement
169-
- Recommended to keep `true` for production bots
170-
171-
## Network Configuration
172-
173-
### Command Line Port Override
174-
175-
The port can be overridden when launching Balatro:
55+
Hide floating score text ("+10", etc.) when cards are scored for better performance.
17656

177-
```bash
178-
# Windows
179-
Balatro.exe 12346
57+
### frame_ratio
58+
**Type:** `integer` | **Default:** `100`
18059

181-
# Launch with specific port
182-
steam://rungameid/2379780//12346
183-
```
60+
Render every Nth frame. Higher values provide better performance with less visual output.
18461

185-
### Multi-Instance Setup
62+
## Multi-Instance Setup
18663

187-
For running multiple bot instances:
64+
For multiple bot instances, use different ports:
18865

189-
**Instance 1 (config.lua):**
19066
```lua
67+
-- Instance 1
19168
port = '12345'
192-
```
19369

194-
**Instance 2 (config.lua):**
195-
```lua
70+
-- Instance 2
19671
port = '12346'
19772
```
19873

199-
**Instance 3 (config.lua):**
200-
```lua
201-
port = '12347'
202-
```
203-
204-
**Python Bot Configuration:**
205-
```python
206-
# Bot 1
207-
bot1 = Bot(deck="Red Deck", stake=1, bot_port=12345)
208-
209-
# Bot 2
210-
bot2 = Bot(deck="Blue Deck", stake=1, bot_port=12346)
211-
212-
# Bot 3
213-
bot3 = Bot(deck="Yellow Deck", stake=1, bot_port=12347)
74+
Launch Balatro with specific port:
75+
```bash
76+
Balatro.exe 12346
21477
```
21578

21679
## Bot-Specific Settings

0 commit comments

Comments
 (0)