poker-flopsolve 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -207,6 +207,14 @@ type BetSize = number | {
207
207
  } | 'allin';
208
208
  /** Sizes offered when facing a bet: one row for every round, or a row per round. */
209
209
  type RaiseSizes = readonly BetSize[] | readonly (readonly BetSize[])[];
210
+ /**
211
+ * A setting given once for both players, or apart: `{ oop: …, ip: … }`, each
212
+ * side in the setting's own form.
213
+ */
214
+ type PerPlayer<T> = T | {
215
+ readonly oop: T;
216
+ readonly ip: T;
217
+ };
210
218
  declare const NodeKind: {
211
219
  readonly Decision: 0;
212
220
  readonly Chance: 1;
@@ -715,20 +723,29 @@ interface SpotConfig {
715
723
  readonly oop: string | Float64Array;
716
724
  /** The in-position player's range, in either form. */
717
725
  readonly ip: string | Float64Array;
718
- /** Bet sizes per betting round; a single row applies to every round. */
719
- readonly betSizes: readonly (readonly BetSize[])[];
726
+ /**
727
+ * Bet sizes per betting round; a single row applies to every round.
728
+ *
729
+ * This and every other betting setting below (`raiseSizes`, `maxRaises`,
730
+ * `allowAllIn`, `allInThreshold`) can be given apart for each player as
731
+ * `{ oop: …, ip: … }`, each side in the setting's usual form:
732
+ * `betSizes: { oop: [[0.33]], ip: [[0.5, 1]] }`. They only shape the
733
+ * tree, so a solve costs the same either way.
734
+ */
735
+ readonly betSizes: PerPlayer<readonly (readonly BetSize[])[]>;
720
736
  /**
721
737
  * Sizes offered when facing a bet; unset, raises use the bet sizes. One
722
738
  * row for every round, or a row per round like `betSizes`.
723
739
  */
724
- readonly raiseSizes?: RaiseSizes;
740
+ readonly raiseSizes?: PerPlayer<RaiseSizes | undefined>;
725
741
  /**
726
742
  * Maximum aggressive actions per round; the opening bet is the first.
727
- * One number, or one per round. Default 1.
743
+ * One number, or one per round. Default 1. Given apart, a player may bet
744
+ * or raise only while the round's aggressions are under their own limit.
728
745
  */
729
- readonly maxRaises?: number | readonly number[];
746
+ readonly maxRaises?: PerPlayer<number | readonly number[]>;
730
747
  /** Offer a shove alongside the configured sizes; once, or per round. Default false. */
731
- readonly allowAllIn?: boolean | readonly boolean[];
748
+ readonly allowAllIn?: PerPlayer<boolean | readonly boolean[]>;
732
749
  /**
733
750
  * Turn a bet or raise into a shove when it would commit at least this
734
751
  * fraction of the actor's remaining stack — 0.67 makes any bet of two
@@ -736,7 +753,7 @@ interface SpotConfig {
736
753
  * multiply a tree for little strategic difference. Once, or per round.
737
754
  * Unset, never.
738
755
  */
739
- readonly allInThreshold?: number | readonly number[];
756
+ readonly allInThreshold?: PerPlayer<number | readonly number[] | undefined>;
740
757
  /**
741
758
  * Forbid donk bets: out of position may only check when opening a round
742
759
  * into the player who made the last bet or raise of the round before.
@@ -1118,4 +1135,4 @@ declare function solve(spot: Spot, options?: SolveOptions): Solution;
1118
1135
  */
1119
1136
  declare function predictCrossing(t1: number, e1: number, t2: number, e2: number, target: number): number;
1120
1137
 
1121
- export { ACTION_LABELS, ActionKind, type Algorithm, type Approximations, type BetSize, CATEGORY, CATEGORY_NAMES, COMBOS, COMBO_CARDS, COMBO_LANES, DECK, type Estimate, NodeKind, PLATFORM, PRECISION_BYTES, type Precision, type Progress, RANKS, type ResolvedBoard, SUITS, type Solution, type SolveOptions, type SolveRun, type Solver, type Spot, type SpotConfig, SpotTooLargeError, type StrategyView, type SubgameBetting, type WarmStartReport, activeCombos, cardOf, categoryOf, comboIndex, createRun, defineSpot, evaluate, evaluateCards, formatCard, formatCards, formatCombo, makeRegretStore, makeSumStore, parseCard, parseCards, parseRange, predictCrossing, rangeWeight, rankOf, simdAvailable, solve, suitLanes, suitOf };
1138
+ export { ACTION_LABELS, ActionKind, type Algorithm, type Approximations, type BetSize, CATEGORY, CATEGORY_NAMES, COMBOS, COMBO_CARDS, COMBO_LANES, DECK, type Estimate, NodeKind, PLATFORM, PRECISION_BYTES, type PerPlayer, type Precision, type Progress, RANKS, type RaiseSizes, type ResolvedBoard, SUITS, type Solution, type SolveOptions, type SolveRun, type Solver, type Spot, type SpotConfig, SpotTooLargeError, type StrategyView, type SubgameBetting, type WarmStartReport, activeCombos, cardOf, categoryOf, comboIndex, createRun, defineSpot, evaluate, evaluateCards, formatCard, formatCards, formatCombo, makeRegretStore, makeSumStore, parseCard, parseCards, parseRange, predictCrossing, rangeWeight, rankOf, simdAvailable, solve, suitLanes, suitOf };
package/dist/index.js CHANGED
@@ -79,6 +79,15 @@ function formatCombo(combo) {
79
79
  }
80
80
 
81
81
  // src/tree.ts
82
+ function isPerPlayer(value) {
83
+ return typeof value === "object" && value !== null && !Array.isArray(value) && "oop" in value && "ip" in value;
84
+ }
85
+ function forPlayer(value, player) {
86
+ return isPerPlayer(value) ? player === 0 ? value.oop : value.ip : value;
87
+ }
88
+ function mapPlayers(value, f) {
89
+ return isPerPlayer(value) ? { oop: f(value.oop), ip: f(value.ip) } : f(value);
90
+ }
82
91
  function raisesPerRound(sizes) {
83
92
  return sizes.length > 0 && Array.isArray(sizes[0]);
84
93
  }
@@ -139,14 +148,25 @@ function buildTree(config, runouts) {
139
148
  const edgeChild = [];
140
149
  const { potUnits, stackUnits, chipScale, minRaiseUnits } = config;
141
150
  const rounds = runouts.rounds;
142
- const maxRaises = perRound(config.maxRaises, Array.isArray(config.maxRaises), rounds, "maxRaises");
143
- const allowAllIn = perRound(config.allowAllIn, Array.isArray(config.allowAllIn), rounds, "allowAllIn");
151
+ const players = [0, 1];
152
+ const maxRaises = players.map((p) => {
153
+ const value = forPlayer(config.maxRaises, p);
154
+ return perRound(value, Array.isArray(value), rounds, "maxRaises");
155
+ });
156
+ const allowAllIn = players.map((p) => {
157
+ const value = forPlayer(config.allowAllIn, p);
158
+ return perRound(value, Array.isArray(value), rounds, "allowAllIn");
159
+ });
144
160
  const merge = config.mergeSizes ?? 0;
145
- const raiseSizes = config.raiseSizes ? perRound(config.raiseSizes, raisesPerRound(config.raiseSizes), rounds, "raiseSizes").map(
146
- (row) => mergeBetSizes(row, merge)
147
- ) : null;
148
- const betSizes = config.betSizes.map((row) => mergeBetSizes(row, merge));
149
- const threshold = perRound(config.allInThreshold ?? 0, Array.isArray(config.allInThreshold), rounds, "allInThreshold");
161
+ const raiseSizes = players.map((p) => {
162
+ const value = forPlayer(config.raiseSizes, p);
163
+ return value ? perRound(value, raisesPerRound(value), rounds, "raiseSizes").map((row) => mergeBetSizes(row, merge)) : null;
164
+ });
165
+ const betSizes = players.map((p) => forPlayer(config.betSizes, p).map((row) => mergeBetSizes(row, merge)));
166
+ const threshold = players.map((p) => {
167
+ const value = forPlayer(config.allInThreshold, p) ?? 0;
168
+ return perRound(value, Array.isArray(value), rounds, "allInThreshold");
169
+ });
150
170
  const noDonk = perRound(config.noDonk ?? false, Array.isArray(config.noDonk), rounds, "noDonk");
151
171
  const half = Math.round(potUnits / 2);
152
172
  const addNode = (nodeKind, nodePlayer, nodeRound, nodePot, nodePayoff) => {
@@ -225,13 +245,14 @@ function buildTree(config, runouts) {
225
245
  });
226
246
  const cap = Math.min(stackUnits, theirs + (stackUnits - theirs));
227
247
  const donk = noDonk[state.round] && me === 0 && owed === 0 && state.aggressions === 0 && state.previousAggressor === 1;
228
- if (state.aggressions < maxRaises[state.round] && myRemaining > owed && !donk) {
248
+ if (state.aggressions < maxRaises[me][state.round] && myRemaining > owed && !donk) {
229
249
  const seen = /* @__PURE__ */ new Set();
230
- const sizes = owed > 0 && raiseSizes ? [...raiseSizes[state.round]] : [...betSizes[state.round] ?? []].filter((size) => !(typeof size === "object" && "times" in size));
231
- if (allowAllIn[state.round]) sizes.push("allin");
250
+ const myRaises = raiseSizes[me];
251
+ const sizes = owed > 0 && myRaises ? [...myRaises[state.round]] : [...betSizes[me][state.round] ?? []].filter((size) => !(typeof size === "object" && "times" in size));
252
+ if (allowAllIn[me][state.round]) sizes.push("allin");
232
253
  for (const size of sizes) {
233
254
  let target = resolveTarget(size, state, cap);
234
- if (target !== null && threshold[state.round] > 0 && target - mine >= threshold[state.round] * myRemaining) {
255
+ if (target !== null && threshold[me][state.round] > 0 && target - mine >= threshold[me][state.round] * myRemaining) {
235
256
  target = cap;
236
257
  }
237
258
  if (target === null || seen.has(target)) continue;
@@ -2709,12 +2730,16 @@ function defineSpot(config) {
2709
2730
  const rounds = 6 - board.length;
2710
2731
  if (config.pot <= 0) throw new Error("pot must be positive");
2711
2732
  if (config.stack <= 0) throw new Error("stack must be positive");
2712
- const rows = config.betSizes.length === 1 ? Array.from({ length: rounds }, () => config.betSizes[0]) : config.betSizes;
2713
- if (rows.length !== rounds) {
2714
- throw new Error(
2715
- `betSizes has ${config.betSizes.length} rows but this board has ${rounds} betting rounds; give one row per round, or a single row for all of them`
2716
- );
2717
- }
2733
+ const rowsFor = (sizes, who) => {
2734
+ const expanded = sizes.length === 1 ? Array.from({ length: rounds }, () => sizes[0]) : sizes;
2735
+ if (expanded.length !== rounds) {
2736
+ throw new Error(
2737
+ `${who}betSizes has ${sizes.length} rows but this board has ${rounds} betting rounds; give one row per round, or a single row for all of them`
2738
+ );
2739
+ }
2740
+ return expanded;
2741
+ };
2742
+ const rows = isPerPlayer(config.betSizes) ? { oop: rowsFor(config.betSizes.oop, "oop "), ip: rowsFor(config.betSizes.ip, "ip ") } : rowsFor(config.betSizes, "");
2718
2743
  const onBoard = new Set(board);
2719
2744
  const trim = (range, who) => {
2720
2745
  const weights = typeof range === "string" ? parseRange(range) : Float64Array.from(range);
@@ -2772,9 +2797,10 @@ function defineSpot(config) {
2772
2797
  const compressedBytes = buildLayout(tree, runouts, players, 2).bytes + showdownBytes;
2773
2798
  const suggestions = [];
2774
2799
  if (compressedBytes > maxBytes) {
2775
- const widest = Math.max(...rows.map((r) => r.length));
2800
+ const widest = Math.max(...[0, 1].flatMap((p) => forPlayer(rows, p).map((r) => r.length)));
2776
2801
  if (widest > 1) suggestions.push(`use fewer bet sizes (currently up to ${widest} per round)`);
2777
- if (Math.max(...[config.maxRaises ?? 1].flat()) > 1) suggestions.push(`lower maxRaises to 1`);
2802
+ const raises = [0, 1].flatMap((p) => [forPlayer(config.maxRaises ?? 1, p)].flat());
2803
+ if (Math.max(...raises) > 1) suggestions.push(`lower maxRaises to 1`);
2778
2804
  suggestions.push(`narrow the ranges (currently ${players[0].count} and ${players[1].count} combos)`);
2779
2805
  if (runouts.rounds === 3) suggestions.push("solve from the turn instead of the flop");
2780
2806
  }
@@ -3122,8 +3148,9 @@ function makeSolution(spot, ctx, solver, iterations, totalIterations, history, s
3122
3148
  const invested = (tree.pot[node] - spot.potUnits) / 2;
3123
3149
  const { source } = spot;
3124
3150
  const later = (value, listed) => listed && value.length > 1 ? value.slice(round) : value;
3125
- const rows = later(source.betSizes, true);
3126
- const raiseRows = source.raiseSizes && later(source.raiseSizes, raisesPerRound(source.raiseSizes));
3151
+ const laterEach = (value, listed) => value === void 0 ? void 0 : mapPlayers(value, (side) => later(side, listed(side)));
3152
+ const rows = laterEach(source.betSizes, () => true);
3153
+ const raiseRows = laterEach(source.raiseSizes, (side) => side !== void 0 && raisesPerRound(side));
3127
3154
  return {
3128
3155
  board: formatCards(cards),
3129
3156
  pot: tree.pot[node] / spot.chipScale,
@@ -3132,9 +3159,9 @@ function makeSolution(spot, ctx, solver, iterations, totalIterations, history, s
3132
3159
  ip: reachAt(node, board, 1),
3133
3160
  betSizes: betting.betSizes ?? rows,
3134
3161
  raiseSizes: "raiseSizes" in betting ? betting.raiseSizes : raiseRows,
3135
- maxRaises: betting.maxRaises ?? (source.maxRaises === void 0 ? void 0 : later(source.maxRaises, Array.isArray(source.maxRaises))),
3136
- allowAllIn: betting.allowAllIn ?? (source.allowAllIn === void 0 ? void 0 : later(source.allowAllIn, Array.isArray(source.allowAllIn))),
3137
- allInThreshold: "allInThreshold" in betting ? betting.allInThreshold : source.allInThreshold === void 0 ? void 0 : later(source.allInThreshold, Array.isArray(source.allInThreshold)),
3162
+ maxRaises: betting.maxRaises ?? laterEach(source.maxRaises, Array.isArray),
3163
+ allowAllIn: betting.allowAllIn ?? laterEach(source.allowAllIn, Array.isArray),
3164
+ allInThreshold: "allInThreshold" in betting ? betting.allInThreshold : laterEach(source.allInThreshold, Array.isArray),
3138
3165
  noDonk: "noDonk" in betting ? betting.noDonk : source.noDonk === void 0 ? void 0 : later(source.noDonk, Array.isArray(source.noDonk)),
3139
3166
  mergeSizes: "mergeSizes" in betting ? betting.mergeSizes : source.mergeSizes,
3140
3167
  minWeight: source.minWeight,