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/README.md +18 -0
- package/dist/browser.js +51 -24
- package/dist/browser.js.map +1 -1
- package/dist/index.d.ts +25 -8
- package/dist/index.js +51 -24
- package/dist/index.js.map +1 -1
- package/dist/worker.js +42 -19
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,6 +107,24 @@ defineSpot({ ..., board: 'Qs Jh 4d',
|
|
|
107
107
|
|
|
108
108
|
A subgame keeps the rounds from its own onwards.
|
|
109
109
|
|
|
110
|
+
### Betting per player
|
|
111
|
+
|
|
112
|
+
Every betting setting — `betSizes`, `raiseSizes`, `maxRaises`, `allowAllIn`,
|
|
113
|
+
`allInThreshold` — can also be given apart for each player, each side in its usual form:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
defineSpot({ ...,
|
|
117
|
+
betSizes: { oop: [[0.33]], ip: [[0.5, 1.25]] }, // OOP bets small, IP bets half or overbets
|
|
118
|
+
maxRaises: { oop: 2, ip: 1 }, // only OOP may raise a bet
|
|
119
|
+
allowAllIn: { oop: false, ip: true },
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Settings only shape the betting tree, which is built once before solving, so this costs
|
|
124
|
+
nothing per iteration: the same game given plainly or per player solves at the same
|
|
125
|
+
speed, and asymmetric sizes cost exactly what their tree does. With `maxRaises` apart, a
|
|
126
|
+
player may bet or raise only while the round's aggressions are under their own limit.
|
|
127
|
+
|
|
110
128
|
### Trimming the tree
|
|
111
129
|
|
|
112
130
|
Tree size multiplies everything else, so three switches cut the lines that cost the most
|
package/dist/browser.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
|
|
143
|
-
const
|
|
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 =
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
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
|
|
231
|
-
|
|
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;
|
|
@@ -2686,12 +2707,16 @@ function defineSpot(config) {
|
|
|
2686
2707
|
const rounds = 6 - board.length;
|
|
2687
2708
|
if (config.pot <= 0) throw new Error("pot must be positive");
|
|
2688
2709
|
if (config.stack <= 0) throw new Error("stack must be positive");
|
|
2689
|
-
const
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2710
|
+
const rowsFor = (sizes, who) => {
|
|
2711
|
+
const expanded = sizes.length === 1 ? Array.from({ length: rounds }, () => sizes[0]) : sizes;
|
|
2712
|
+
if (expanded.length !== rounds) {
|
|
2713
|
+
throw new Error(
|
|
2714
|
+
`${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`
|
|
2715
|
+
);
|
|
2716
|
+
}
|
|
2717
|
+
return expanded;
|
|
2718
|
+
};
|
|
2719
|
+
const rows = isPerPlayer(config.betSizes) ? { oop: rowsFor(config.betSizes.oop, "oop "), ip: rowsFor(config.betSizes.ip, "ip ") } : rowsFor(config.betSizes, "");
|
|
2695
2720
|
const onBoard = new Set(board);
|
|
2696
2721
|
const trim = (range, who) => {
|
|
2697
2722
|
const weights = typeof range === "string" ? parseRange(range) : Float64Array.from(range);
|
|
@@ -2749,9 +2774,10 @@ function defineSpot(config) {
|
|
|
2749
2774
|
const compressedBytes = buildLayout(tree, runouts, players, 2).bytes + showdownBytes;
|
|
2750
2775
|
const suggestions = [];
|
|
2751
2776
|
if (compressedBytes > maxBytes) {
|
|
2752
|
-
const widest = Math.max(...rows.map((r) => r.length));
|
|
2777
|
+
const widest = Math.max(...[0, 1].flatMap((p) => forPlayer(rows, p).map((r) => r.length)));
|
|
2753
2778
|
if (widest > 1) suggestions.push(`use fewer bet sizes (currently up to ${widest} per round)`);
|
|
2754
|
-
|
|
2779
|
+
const raises = [0, 1].flatMap((p) => [forPlayer(config.maxRaises ?? 1, p)].flat());
|
|
2780
|
+
if (Math.max(...raises) > 1) suggestions.push(`lower maxRaises to 1`);
|
|
2755
2781
|
suggestions.push(`narrow the ranges (currently ${players[0].count} and ${players[1].count} combos)`);
|
|
2756
2782
|
if (runouts.rounds === 3) suggestions.push("solve from the turn instead of the flop");
|
|
2757
2783
|
}
|
|
@@ -3099,8 +3125,9 @@ function makeSolution(spot, ctx, solver, iterations, totalIterations, history, s
|
|
|
3099
3125
|
const invested = (tree.pot[node] - spot.potUnits) / 2;
|
|
3100
3126
|
const { source } = spot;
|
|
3101
3127
|
const later = (value, listed) => listed && value.length > 1 ? value.slice(round) : value;
|
|
3102
|
-
const
|
|
3103
|
-
const
|
|
3128
|
+
const laterEach = (value, listed) => value === void 0 ? void 0 : mapPlayers(value, (side) => later(side, listed(side)));
|
|
3129
|
+
const rows = laterEach(source.betSizes, () => true);
|
|
3130
|
+
const raiseRows = laterEach(source.raiseSizes, (side) => side !== void 0 && raisesPerRound(side));
|
|
3104
3131
|
return {
|
|
3105
3132
|
board: formatCards(cards),
|
|
3106
3133
|
pot: tree.pot[node] / spot.chipScale,
|
|
@@ -3109,9 +3136,9 @@ function makeSolution(spot, ctx, solver, iterations, totalIterations, history, s
|
|
|
3109
3136
|
ip: reachAt(node, board, 1),
|
|
3110
3137
|
betSizes: betting.betSizes ?? rows,
|
|
3111
3138
|
raiseSizes: "raiseSizes" in betting ? betting.raiseSizes : raiseRows,
|
|
3112
|
-
maxRaises: betting.maxRaises ?? (source.maxRaises
|
|
3113
|
-
allowAllIn: betting.allowAllIn ?? (source.allowAllIn
|
|
3114
|
-
allInThreshold: "allInThreshold" in betting ? betting.allInThreshold :
|
|
3139
|
+
maxRaises: betting.maxRaises ?? laterEach(source.maxRaises, Array.isArray),
|
|
3140
|
+
allowAllIn: betting.allowAllIn ?? laterEach(source.allowAllIn, Array.isArray),
|
|
3141
|
+
allInThreshold: "allInThreshold" in betting ? betting.allInThreshold : laterEach(source.allInThreshold, Array.isArray),
|
|
3115
3142
|
noDonk: "noDonk" in betting ? betting.noDonk : source.noDonk === void 0 ? void 0 : later(source.noDonk, Array.isArray(source.noDonk)),
|
|
3116
3143
|
mergeSizes: "mergeSizes" in betting ? betting.mergeSizes : source.mergeSizes,
|
|
3117
3144
|
minWeight: source.minWeight,
|