poker-flopsolve 0.3.0 → 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 +237 -204
- package/dist/browser.js.map +1 -1
- package/dist/engine-worker.js.map +1 -1
- package/dist/index.d.ts +25 -8
- package/dist/index.js +260 -224
- 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/dist/worker.js
CHANGED
|
@@ -359,6 +359,12 @@ function showdownValuesHands(oppReach, cardA, cardB, strength, oppFrom, oppCount
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
// src/tree.ts
|
|
362
|
+
function isPerPlayer(value) {
|
|
363
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && "oop" in value && "ip" in value;
|
|
364
|
+
}
|
|
365
|
+
function forPlayer(value, player) {
|
|
366
|
+
return isPerPlayer(value) ? player === 0 ? value.oop : value.ip : value;
|
|
367
|
+
}
|
|
362
368
|
function raisesPerRound(sizes) {
|
|
363
369
|
return sizes.length > 0 && Array.isArray(sizes[0]);
|
|
364
370
|
}
|
|
@@ -418,14 +424,25 @@ function buildTree(config2, runouts) {
|
|
|
418
424
|
const edgeChild = [];
|
|
419
425
|
const { potUnits, stackUnits, chipScale, minRaiseUnits } = config2;
|
|
420
426
|
const rounds = runouts.rounds;
|
|
421
|
-
const
|
|
422
|
-
const
|
|
427
|
+
const players = [0, 1];
|
|
428
|
+
const maxRaises = players.map((p) => {
|
|
429
|
+
const value = forPlayer(config2.maxRaises, p);
|
|
430
|
+
return perRound(value, Array.isArray(value), rounds, "maxRaises");
|
|
431
|
+
});
|
|
432
|
+
const allowAllIn = players.map((p) => {
|
|
433
|
+
const value = forPlayer(config2.allowAllIn, p);
|
|
434
|
+
return perRound(value, Array.isArray(value), rounds, "allowAllIn");
|
|
435
|
+
});
|
|
423
436
|
const merge = config2.mergeSizes ?? 0;
|
|
424
|
-
const raiseSizes =
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
437
|
+
const raiseSizes = players.map((p) => {
|
|
438
|
+
const value = forPlayer(config2.raiseSizes, p);
|
|
439
|
+
return value ? perRound(value, raisesPerRound(value), rounds, "raiseSizes").map((row) => mergeBetSizes(row, merge)) : null;
|
|
440
|
+
});
|
|
441
|
+
const betSizes = players.map((p) => forPlayer(config2.betSizes, p).map((row) => mergeBetSizes(row, merge)));
|
|
442
|
+
const threshold = players.map((p) => {
|
|
443
|
+
const value = forPlayer(config2.allInThreshold, p) ?? 0;
|
|
444
|
+
return perRound(value, Array.isArray(value), rounds, "allInThreshold");
|
|
445
|
+
});
|
|
429
446
|
const noDonk = perRound(config2.noDonk ?? false, Array.isArray(config2.noDonk), rounds, "noDonk");
|
|
430
447
|
const half = Math.round(potUnits / 2);
|
|
431
448
|
const addNode = (nodeKind, nodePlayer, nodeRound, nodePot, nodePayoff) => {
|
|
@@ -504,13 +521,14 @@ function buildTree(config2, runouts) {
|
|
|
504
521
|
});
|
|
505
522
|
const cap = Math.min(stackUnits, theirs + (stackUnits - theirs));
|
|
506
523
|
const donk = noDonk[state.round] && me === 0 && owed === 0 && state.aggressions === 0 && state.previousAggressor === 1;
|
|
507
|
-
if (state.aggressions < maxRaises[state.round] && myRemaining > owed && !donk) {
|
|
524
|
+
if (state.aggressions < maxRaises[me][state.round] && myRemaining > owed && !donk) {
|
|
508
525
|
const seen = /* @__PURE__ */ new Set();
|
|
509
|
-
const
|
|
510
|
-
|
|
526
|
+
const myRaises = raiseSizes[me];
|
|
527
|
+
const sizes = owed > 0 && myRaises ? [...myRaises[state.round]] : [...betSizes[me][state.round] ?? []].filter((size) => !(typeof size === "object" && "times" in size));
|
|
528
|
+
if (allowAllIn[me][state.round]) sizes.push("allin");
|
|
511
529
|
for (const size of sizes) {
|
|
512
530
|
let target = resolveTarget(size, state, cap);
|
|
513
|
-
if (target !== null && threshold[state.round] > 0 && target - mine >= threshold[state.round] * myRemaining) {
|
|
531
|
+
if (target !== null && threshold[me][state.round] > 0 && target - mine >= threshold[me][state.round] * myRemaining) {
|
|
514
532
|
target = cap;
|
|
515
533
|
}
|
|
516
534
|
if (target === null || seen.has(target)) continue;
|
|
@@ -2055,12 +2073,16 @@ function defineSpot(config2) {
|
|
|
2055
2073
|
const rounds = 6 - board.length;
|
|
2056
2074
|
if (config2.pot <= 0) throw new Error("pot must be positive");
|
|
2057
2075
|
if (config2.stack <= 0) throw new Error("stack must be positive");
|
|
2058
|
-
const
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2076
|
+
const rowsFor = (sizes, who) => {
|
|
2077
|
+
const expanded = sizes.length === 1 ? Array.from({ length: rounds }, () => sizes[0]) : sizes;
|
|
2078
|
+
if (expanded.length !== rounds) {
|
|
2079
|
+
throw new Error(
|
|
2080
|
+
`${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`
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
return expanded;
|
|
2084
|
+
};
|
|
2085
|
+
const rows = isPerPlayer(config2.betSizes) ? { oop: rowsFor(config2.betSizes.oop, "oop "), ip: rowsFor(config2.betSizes.ip, "ip ") } : rowsFor(config2.betSizes, "");
|
|
2064
2086
|
const onBoard = new Set(board);
|
|
2065
2087
|
const trim = (range, who) => {
|
|
2066
2088
|
const weights2 = typeof range === "string" ? parseRange(range) : Float64Array.from(range);
|
|
@@ -2118,9 +2140,10 @@ function defineSpot(config2) {
|
|
|
2118
2140
|
const compressedBytes = buildLayout(tree, runouts, players, 2).bytes + showdownBytes;
|
|
2119
2141
|
const suggestions = [];
|
|
2120
2142
|
if (compressedBytes > maxBytes) {
|
|
2121
|
-
const widest = Math.max(...rows.map((r) => r.length));
|
|
2143
|
+
const widest = Math.max(...[0, 1].flatMap((p) => forPlayer(rows, p).map((r) => r.length)));
|
|
2122
2144
|
if (widest > 1) suggestions.push(`use fewer bet sizes (currently up to ${widest} per round)`);
|
|
2123
|
-
|
|
2145
|
+
const raises = [0, 1].flatMap((p) => [forPlayer(config2.maxRaises ?? 1, p)].flat());
|
|
2146
|
+
if (Math.max(...raises) > 1) suggestions.push(`lower maxRaises to 1`);
|
|
2124
2147
|
suggestions.push(`narrow the ranges (currently ${players[0].count} and ${players[1].count} combos)`);
|
|
2125
2148
|
if (runouts.rounds === 3) suggestions.push("solve from the turn instead of the flop");
|
|
2126
2149
|
}
|