1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
//! Core type aliases, traits, and constants for robopoker.
//!
//! This crate provides the foundational types and configuration parameters
//! used throughout the robopoker workspace.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// ============================================================================
// TYPE ALIASES
// ============================================================================
/// Stack sizes and bet amounts in big blinds.
pub type Chips = i16;
/// Seat index around the table (0 = button in heads-up).
pub type Position = usize;
/// Training iteration counter for CFR epochs.
pub type Epoch = i16;
/// Distance metrics, convergence thresholds, and smoothing terms.
pub type Energy = f32;
/// Temperature parameters and information-theoretic measures.
pub type Entropy = f32;
/// Expected values, regrets, and payoffs.
pub type Utility = f32;
/// Strategy weights, sampling distributions, and reach probabilities.
pub type Probability = f32;
// ============================================================================
// TRAITS
// ============================================================================
/// Random instance generation for testing and Monte Carlo sampling.
/// Unique identifier trait for domain entities.
// ============================================================================
// GAME TREE PARAMETERS
// ============================================================================
/// Number of players at the table.
pub const N: usize = 2;
/// Starting stack size in chips.
pub const STACK: Chips = 200;
/// Big blind amount.
pub const B_BLIND: Chips = 2;
/// Small blind amount.
pub const S_BLIND: Chips = 1;
/// Maximum re-raises per betting round (limits tree width).
pub const MAX_RAISE_REPEATS: usize = 3;
/// Maximum edges in a packed Path (12 nibbles × 5 bits = 60 bits ≤ 64 bits).
/// Data-representation limit, not a solver depth knob — the subgame tree's
/// effective depth is controlled by where `DepthGame::at_frontier` fires
/// (first chance node past origin), not by this constant.
pub const MAX_PATH_EDGES: usize = 12;
// ============================================================================
// BET SIZING ABSTRACTION
// RAISES is the canonical pool; SIZE_* select subsets via index.
// To change the game tree, edit RAISES or the index arrays below.
// ============================================================================
/// Preflop open sizes in BB units (depth=0 only).
pub const OPENS: = ;
/// Canonical raise pool as pot-relative (numerator, denominator) fractions.
/// Index position = u8 encoding offset from 10. 1:1 with Odds::GRID.
/// 0 1 2 3 4 5 6 7 8 9
/// 25% 33% 50% 67% 75% 100% 125% 150% 200% 300%
pub const RAISES: = ;
const
/// Action grid for the Pluribus regime. Pluribus-faithful (Brown &
/// Sandholm 2019) widths on first-bet rows, shrunk on subsequent raises.
/// No SPR axis on the menu — pot-relative sizing already self-scales
/// with stack depth (1× pot at SPR=1 *is* all-in), so the menu is keyed
/// only on `(street, depth)`. All-in remains available at every node as
/// `Edge::Shove`.
///
/// **Cells are indices into `RAISES`:**
/// `0=1/4 1=1/3 2=1/2 3=2/3 4=3/4 5=1:1 6=5/4 7=3/2 8=2:1 9=3:1`
///
/// **Row layout:** `street * 3 + min(depth, 2)`, so depth ≥ 2 collapses
/// to the "N" row:
///
/// | row | cell | row | cell | row | cell | row | cell |
/// |-----|------|-----|------|-----|------|------|------|
/// | 0 | Pref/0 (opens) | 3 | Flop/0 | 6 | Turn/0 | 9 | Rive/0 |
/// | 1 | Pref/1 (3-bet) | 4 | Flop/1 | 7 | Turn/1 | 10 | Rive/1 |
/// | 2 | Pref/N (4-bet+)| 5 | Flop/N | 8 | Turn/N | 11 | Rive/N |
///
/// `(Pref, 0)` is empty here — preflop opens are BB-relative and use
/// `OPENS` instead.
///
/// **Bit-packing budget:** max cell width is 5 (Flop/0:
/// `[1/4, 1/2, 3/4, 1:1, 2:1]`). Max `choices` is 5 raises +
/// Fold/Check/Call/Shove = 9 edges × 5 bits = 45 bits, under the
/// 60-bit Path capacity.
pub const PLURIBUS_INDICES: = ;
// Slumbot regime: uniform grid (½ pot, full pot) at every street/depth.
// UI also offers Min Bet and All In, handled by Edge::Raise (min coercion)
// and Edge::Shove respectively.
pub const SLUMBOT_INDICES: & = &;
// GAME PACING (milliseconds)
/// Delay after hand start before dealing hole cards.
pub const PACE_DEAL_HOLE: u64 = 0;
/// Delay after dealing community cards.
pub const PACE_DEAL_BOARD: u64 = 0;
/// Simulated think time for bot actions.
pub const PACE_BOT_THINK: u64 = 0;
/// Window for voluntary card reveals at showdown.
pub const PACE_SHOWDOWN: u64 = 0;
/// Pause between hands (after settlement, before next deal).
pub const PACE_RESULTS: u64 = 4000;
/// Timeout for human player decisions.
pub const PACE_DECISION: u64 = 10000;
/// Timeout for room startup (waiting for WebSocket connection).
pub const PACE_ROOM_STARTUP: u64 = 30000;
/// Maximum consecutive all-timeout hands before ending session.
pub const MAX_IDLE_HANDS: usize = 3;
// ============================================================================
// K-MEANS CLUSTERING — STRUCTURAL CONSTANTS
// Cluster counts are const-generic / array-size; can't be runtime config.
// Tuning knobs (iterations, RMS interval, drift threshold) live in
// `KmeansHyperParams` (lloyd); Sinkhorn knobs in
// `SinkhornHyperParams`.
// ============================================================================
const _: = assert!;
const _: = assert!;
const _: = assert!;
/// Maximum clusters per street. Bound by Abstraction's 8-bit index field
/// (0..=255 = 256 distinct values).
pub const KMEANS_MAX_CLUSTER_COUNT: usize = 256;
/// Number of flop buckets (distributions over turn clusters).
pub const KMEANS_FLOP_CLUSTER_COUNT: usize = 256;
/// Number of turn buckets (distributions over river equity).
pub const KMEANS_TURN_CLUSTER_COUNT: usize = 256;
/// Equity histogram resolution (0%, 1%, ..., 100%).
pub const KMEANS_EQTY_CLUSTER_COUNT: usize = 101;
// ============================================================================
// MCCFR SOLVER CONFIGURATIONS
// Batch size = trees per iteration, tree count = total training budget.
// ============================================================================
/// Asymmetric payoff for RPS test game (rock beats scissors by 2x).
pub const ASYMMETRIC_UTILITY: f32 = 2.0;
// ============================================================================
// REGRET MATCHING
// ============================================================================
/// Minimum policy weight to prevent division by zero in normalization.
pub const EPSILON: Probability = MIN_POSITIVE;
// ============================================================================
// SUBGAME SOLVING — STRUCTURAL CONSTANTS
// `N_WORLDS` and `FRONTIER_LEAVES` are const-generic depths in the world /
// depth solvers; they can't be runtime config. Tuning knobs live in
// `SubgameHyperParams` (subgame) and `FrontierHyperParams` (horizon).
// ============================================================================
/// Alternative opponent hand partitions in the subgame (safe subgame solving).
/// Each world represents a partition of the opponent's range conditioned on
/// the observed action sequence. More worlds = finer range partitioning =
/// more robust strategy, but higher memory and slower convergence.
pub const N_WORLDS: usize = 4;
/// Number of biased continuation strategies at depth-limited frontiers.
/// D=4: unmodified blueprint + fold-biased + call-biased + raise-biased (Pluribus).
pub const FRONTIER_LEAVES: usize = 4;
// ============================================================================
// RUNTIME UTILITIES
// ============================================================================
/// Register Ctrl+C handler for immediate (non-graceful) termination.
/// Use when you need hard shutdown without waiting for current batch.
/// Global interrupt flag for graceful shutdown coordination.
static INTERRUPTED: AtomicBool = new;
/// Optional training deadline from TRAIN_DURATION env var.
static DEADLINE: OnceLock = new;
/// Check if graceful shutdown was requested (via stdin "Q") or deadline reached.
/// No-op interrupt check when server feature disabled.
/// Register graceful interrupt handler. Type "Q" + Enter to stop after current batch.
/// Also handles SIGTERM (sent by ECS stop-task) for graceful remote shutdown.
/// Optionally set TRAIN_DURATION env var (e.g., "2h", "30m") for timed runs.
/// Parse duration string like "30s", "5m", "2h", "1d" into Duration.