poker-flopsolve 0.5.0-beta.1 → 0.5.0-beta.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,77 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0-beta.2
4
+
5
+ The third beta of 0.5.0 (`npm install poker-flopsolve@beta`): everything since 0.5.0-beta.1.
6
+
7
+ ### `openLite` takes any range, with every Lite option
8
+
9
+ - A session no longer refuses a range. One that adds a hand the blueprint does not store, or
10
+ breaks a suit symmetry it folds, gets a new run started from the old one's regrets, so
11
+ `oopReserve` and `ipReserve` are optional: five moves with no reserve took 83 s against 143
12
+ for `solveLite` on As Kh 7d, 66 against 91 on Ts 9s 4h and 27 against 51 on Ks 9s 4s.
13
+ - `compressRanges` works in a session, compressing both ranges again at every move: 161 s
14
+ against 193 on As Kh 7d, 110 against 178 on Ts 9s 4h and 50 against 90 on Ks 9s 4s, on wide
15
+ ranges, less exploitable in 14 moves of 15.
16
+ - `algorithm: 'cfr+'` works in a session and in `run.setRange`, which clears its average and
17
+ keeps its count: 105 s against 147, 70 against 103 and 20 against 58, less exploitable in 8
18
+ moves of 15 and 0.2–1.4% of pot more on the monotone flop.
19
+ - `run.setRange` throws `RangeNotInPlaceError` for a range that needs a new run, apart from a
20
+ range that is no range.
21
+ - `defineSpot` refuses two ranges of which no pair of hands can be held together, which
22
+ solved to NaN before.
23
+ - A warm start into a new run copies about nine times faster (4.7 s to 0.5 on a 265 MiB
24
+ blueprint), the same values bit for bit.
25
+
26
+ ### Startup
27
+
28
+ - Less stands between a call and solving. Defining the spot, creating the run and the first
29
+ iteration's extra cost took 727 ms on the bench flop on 4 threads and take 244, or 65 for a
30
+ later solve of the same board and hands; 582 and 233 (75) on one thread; 1456 and 584 (436)
31
+ for the Lite blueprint on As Kh 7d. Results are the same, bit for bit.
32
+ - The per-hand tables are built about five times faster, and the last set is kept for a spot
33
+ defined again on the same board with the same hands. `releaseSetupCache()` lets it go.
34
+ - In Node a run's threads start beside its setup, and when it closes replacements start and
35
+ wait 30 seconds for the next run; `enableThreads(n)` starts them ahead and keeps that many.
36
+ - The engine's storage is written once before the first iteration, a share a thread, instead
37
+ of being mapped by every thread at once during it.
38
+
39
+ ### Lite for a range slider: `openLite`
40
+
41
+ - `openLite(spot, options)` solves the Lite blueprint as `solveLite` does and keeps it live.
42
+ `session.setRange(player, range)` changes a range in place and settles the blueprint again
43
+ from where it stands; `session.refine(n)` runs more iterations while the slider is at rest;
44
+ `session.current` is the `LiteSolution`, `resolve` included.
45
+ - On issue #47's betting, 4 threads, five moves of out of position's range settled in 95 s
46
+ against 163 for five `solveLite` calls on As Kh 7d, 69 against 103 on Ts 9s 4h and 27 against
47
+ 52 on Ks 9s 4s: 0.31–0.61× the time for two hand classes added or dropped, 0.66–0.92× for a
48
+ third of the range dropped. It ended less exploitable than `solveLite` in 11 moves of 15, and
49
+ 0.6–1.8% of pot more on the monotone flop's three moves that dropped hands.
50
+ - `oopReserve` and `ipReserve` on a spot keep storage for hands a range does not hold yet, so
51
+ they can be added. With nine classes in reserve an iteration cost 27–42% more and the first
52
+ solve took 20–52% longer.
53
+ - `run.setRange(player, range, { resume })` is the same change on any run, exact solves
54
+ included: about 0.02 ms a call, nothing built or copied, where a `warmStart` into a new run
55
+ costs about two iterations of the spot. It keeps the regrets and resumes the iteration count
56
+ (from 10, `RANGE_RESUME`; `openLite` resumes from 30, as chance sampling was unstable at 10).
57
+ The range must keep the suit symmetries the spot folds runouts by; runout buckets stand.
58
+ A CFR+ run is refused.
59
+ - `runToStop(run, options)` runs a live run as `solve` runs its own: to the iteration cap, the
60
+ target or the settle stop.
61
+
62
+ ### `compressRanges` on a spot that starts on the turn or the river (issue #158)
63
+
64
+ - `compressRanges(spot)`, and Lite's option of the same name, take a board of four or five cards
65
+ with the ranges the players hold there; before, any board but a flop was refused. A turn is
66
+ matched on its board and each river that can follow. A river is also matched on what the other
67
+ player's hands face: how much of the range beats each, ties it and loses to it.
68
+ - The default tolerance past the flop is 0.005. Under Lite on four turns (270–497 combinations a
69
+ side, 4 threads) that settled in 0.6–0.8 s against 1.3–2.4, in 3–4 MiB against 6–11, the root
70
+ play 1.2–1.9 points from Lite's on the full ranges, where two Lite solves were 0.6–2.6 apart.
71
+ At 0.01 it was 1.1–7.8 points off.
72
+ - On a river there is nothing to save: Lite took 0.1 s on the full ranges.
73
+ - The vendored compressor is poker-rangecompress 0.2.0. A flop compresses as before.
74
+
3
75
  ## 0.5.0-beta.1
4
76
 
5
77
  The second beta of 0.5.0 (`npm install poker-flopsolve@beta`): everything since 0.5.0-beta.0.
package/README.md CHANGED
@@ -284,6 +284,46 @@ const seven = solve(defineSpot({ ...config, board: 'As Kh 7d' }), {
284
284
  On the bench flop that reaches 0.5% of pot in 8 iterations instead of 52 (from AsQh7d,
285
285
  20). It needs the whole old solve: seeding only the flop's decisions saved at most 15%.
286
286
 
287
+ ### Changing a range in place
288
+
289
+ A warm start builds a new run, which costs about two iterations of the spot before the first
290
+ one runs: around a second on the bench flop. A range slider, which changes nothing but one
291
+ player's weights, needs none of that. `run.setRange` reweights the live run where it stands:
292
+
293
+ ```ts
294
+ const run = createRun(defineSpot({ ...config, oopReserve: widest })); // every hand the slider can reach
295
+ run.step(50);
296
+ run.setRange(0, weights); // a Float64Array of 1326 weights, or a range string
297
+ run.step(20); // keeps solving, from the regrets it had
298
+ ```
299
+
300
+ Nothing is built or copied, so a call takes about 0.02 ms on any of the bench spots (0.04 ms
301
+ given a string to parse), against 3–110 ms on river and turn and about 1.1 s on the flop for a
302
+ warm start into a new run. It then solves as that warm start does, or faster:
303
+
304
+ | To 0.3% of pot (flop: 0.5%) | From scratch | `warmStart` | `setRange` |
305
+ |---|---|---|---|
306
+ | River, hands added | 60 iterations | 40 | 40 |
307
+ | River, hands dropped | 70 | 45 | 45 |
308
+ | Turn, hands added | 85 | 60 | 50 |
309
+ | Turn, hands dropped | 85 | 60 | 50 |
310
+ | Flop, hands added | 44 | 16 | 16 |
311
+ | Flop, hands dropped | 44 | 24 | 24 |
312
+
313
+ Hands can be reweighted or dropped freely. A hand can be added only where the spot kept
314
+ storage for it: `oopReserve` and `ipReserve` name the hands a range may gain, and each costs
315
+ what a held hand does, in memory and per iteration. The new range must keep the suit symmetries
316
+ the spot folds runouts by (define the spot with `isomorphism: false` to be free of that).
317
+ `runoutBuckets` stand as they are, since they were chosen by the hands the spot stores. The
318
+ average strategy is not cleared, which would cost a pass over the storage; the iteration count
319
+ resumes from 10 instead (`{ resume }` to choose), where DCFR's discounting shrinks the old
320
+ range's share within a few iterations. A run with `algorithm: 'cfr+'`, which discounts nothing,
321
+ keeps its count and has its average cleared: 25–100 iterations to 0.3% of pot against 105–185
322
+ from cold on the bench river and turn. A range that adds a hand without storage, or breaks a
323
+ symmetry, throws `RangeNotInPlaceError`: start a new run on it with `warmStart`. Every run built
324
+ on the same spot object is reweighted with it. For Lite, [`openLite`](#a-range-slider-on-lite-openlite) wraps this with the
325
+ settle rule.
326
+
287
327
  ## Re-solving from a node
288
328
 
289
329
  Solve the whole spot with a coarse tree, then re-solve the street you are looking at
@@ -554,7 +594,7 @@ against the exact solve at equal iterations, root loss OOP / IP in % of pot (the
554
594
  | `solveLite` / `litePreset` | preset | both | — | settled at 2.6× the iterations: 0.22× storage, 0.30× time, root 0.052 / 0.068, turn nodes 0.127, 1.89% exploitable ([Lite mode](#lite-mode-solvelite)) |
555
595
  | `largeTree` | preset | WebAssembly | — | at 4× the iterations: 0.38× storage, 0.58× time, root 0.057 / 0.289 (IP's cut 0.33 bet), 0.39% exploitable in its own tree ([Fitting a large tree](#fitting-a-large-tree-largetree)) |
556
596
  | `shareHistories` | preset-internal (lite) | both | — | 0.40× storage, 1.00× time, root 0.061 / 0.068, 1.89% exploitable |
557
- | `compressRanges` (`solveLite`, or on its own) | advanced (a lite option) | both | a board that is not a flop | edits the ranges. Wide weighted ranges: 0.42–0.72× storage, 0.46–0.60× time, root play 1.2–2.7 points off where two Lite solves were 1.8–3.0 apart. Narrow ranges: little, and slower on a monotone flop ([Lite mode](#lite-mode-solvelite)) |
597
+ | `compressRanges` (`solveLite`, or on its own) | advanced (a lite option) | both | — | edits the ranges. Wide weighted ranges on a flop: 0.42–0.72× storage, 0.46–0.60× time, root play 1.2–2.7 points off where two Lite solves were 1.8–3.0 apart. Narrow ranges: little, and slower on a monotone flop. A spot that starts on the turn: 0.29–0.54× time, 1.2–1.9 points off (0.6–2.6); on the river, nothing to save ([Lite mode](#lite-mode-solvelite)) |
558
598
  | `keepBudget` (`solveLite`), `shareHistories.keepLines`, `linesWithin` | advanced (a lite option) | both | — | turn re-solve gain within 0.1–0.8% of the subgame pot of an unshared blueprint's, against 3.0–4.2% from plain sharing ([History sharing](#history-sharing)) |
559
599
  | `runoutBuckets` | preset-internal (lite) | both | — | folds nothing on napkinpoker's weighted ranges. Bench ranges, gap 3: 0.61× time, true exploitability 0.302 against 0.271 ([Runout buckets](#runout-buckets-and-coarse-start)) |
560
600
  | `approximations.chanceSampling` | preset-internal (both) | both, threaded | — | at 4× the iterations: 0.69× time, root 0.057 / 0.056, 0.60% exploitable |
@@ -567,6 +607,8 @@ against the exact solve at equal iterations, root loss OOP / IP in % of pot (the
567
607
  | `approximations.currentProfileEv` | advanced | both | `analysisOnly` | no more than reading EVs; per-hand EVs often 2–4× closer at equal iterations |
568
608
  | `analysisOnly` | advanced | both, at 32 bits | `compactStorage`, `currentProfileEv` | loads a saved strategy; keeps no regrets |
569
609
  | `warmStart`, `warmCards` | advanced | both | — | see [Warm starts](#warm-starts) |
610
+ | `oopReserve`, `ipReserve` | advanced | both | — | storage for hands `run.setRange` may add; see [Changing a range in place](#changing-a-range-in-place) |
611
+ | `openLite` | preset | both | — | `solveLite` kept live for a range slider: a changed range settled again in 0.52–0.68× the time of a new `solveLite` over five moves, 0.31–0.61× for a two-class move, about as exploitable; any range and every Lite option taken, with or without a reserve ([A range slider on Lite](#a-range-slider-on-lite-openlite)) |
570
612
  | `minWeight` | advanced | both | — | edits the ranges: 2–5% less storage, up to 15% less time on napkinpoker's spots |
571
613
  | `engine: 'js'` | advanced | JavaScript | — | the reference engine, about 2.4× slower; `precision: 'f64'` runs on it |
572
614
  | `isomorphism: false`, `simd: false`, `algorithm: 'cfr+'` | advanced | both | — | exact; off switches for comparison |
@@ -576,6 +618,46 @@ against the exact solve at equal iterations, root loss OOP / IP in % of pot (the
576
618
  `litePreset` and `largeTree` (45 pairs); none is refused. Every approximation
577
619
  tried and left out, with its numbers and issue, is in [docs/APPROXIMATIONS.md](docs/APPROXIMATIONS.md).
578
620
 
621
+ ### Startup
622
+
623
+ What stands between a call and solving: defining the spot, creating the run, and whatever the
624
+ first iteration costs over an ordinary one. Measured in new Node processes on the bench spots
625
+ (`bench/startup/measure.ts`; milliseconds, medians; "before" is the same build without this work):
626
+
627
+ | spot | cold, before | cold | hot, before | hot |
628
+ |---|---|---|---|---|
629
+ | River | 12 | 11 | 2.5 | 1.7 |
630
+ | Turn | 53 | 42 | 43 | 13 |
631
+ | Flop | 582 | 233 | 412 | 75 |
632
+ | Flop, 4 threads | 727 | 244 | 646 | 65 |
633
+ | Lite, As Kh 7d, 4 threads | 1456 | 584 | 1445 | 436 |
634
+ | Lite, Ts 9s 4h, 4 threads | 1124 | 474 | 1108 | 339 |
635
+ | Lite, Ks 9s 4s, 4 threads | 562 | 292 | 492 | 183 |
636
+
637
+ Cold is the first solve in a process. Hot is a later one of the same board and hands with
638
+ another pot, as a page solving its next spot has. Importing the package takes 13–16 ms more.
639
+ Where it went:
640
+
641
+ - **The per-hand tables** (showdown ranking, hand lists, the maps between boards) were most of
642
+ `createRun`: 280 ms of a flop's. They are built about five times faster, and the last set is
643
+ kept: a spot defined again on the same board with the same hands stored and the same
644
+ symmetries, whatever its pot, betting or weights, takes them as they are. They hold a few MiB
645
+ on narrow ranges and tens on wide ones; `releaseSetupCache()` lets them go.
646
+ - **Threads** took 100–190 ms to start, every run. A run now starts them before it builds its
647
+ tables, so they are up when it needs them, and when a run closes its threads end and
648
+ replacements start, off the calling thread, to wait 30 seconds for the next run.
649
+ `enableThreads(n)` from `poker-flopsolve/threads` starts them ahead of the first run and
650
+ keeps that many waiting for good; `enableThreads(1)` stops them.
651
+ - **Fresh memory** is mapped page by page as it is first written, and the first iteration did
652
+ that with every thread writing at once: 380 ms on the flop on 4 threads where later ones take
653
+ 75, and 1.3 s against 70 ms on the Lite blueprint. The storage is now written once up front, a
654
+ share a thread, which takes 50–100 ms.
655
+ - **Laying out the storage** counted every hand on every board up to three times in `defineSpot`
656
+ and once more in `createRun`; it is counted once.
657
+
658
+ What is left on Lite is its first iteration, which under chance sampling walks every deal to
659
+ have a first value for each: 340 ms of the rainbow blueprint's 436 hot.
660
+
579
661
  ### Exact speed
580
662
 
581
663
  Measured on an Apple M2, single threaded:
@@ -878,6 +960,97 @@ weight of those dropped, and `exploitabilityInExact` covers only those: a combin
878
960
  keeps `exact`'s play. `compressRanges(spot)` gives the two compressed ranges on their own.
879
961
  `minWeight` is applied to the ranges as given, before compressing.
880
962
 
963
+ #### A range slider on Lite (`openLite`)
964
+
965
+ `solveLite` solves one pair of ranges and lets go of the run, so a page with a range slider
966
+ solves the blueprint again from nothing on every move. `openLite` keeps the blueprint live:
967
+
968
+ ```ts
969
+ import { openLite } from 'poker-flopsolve';
970
+
971
+ const session = openLite({ ...spot, oopReserve: widest }, { workers: 4 }); // solves as solveLite does
972
+ session.current; // a LiteSolution: .solution, .resolve(...)
973
+ const next = session.setRange(0, range); // settles again from where it stands
974
+ session.refine(40); // more iterations while the slider is at rest
975
+ session.close();
976
+ ```
977
+
978
+ `setRange` changes the range in place (`run.setRange`, above), resumes the iteration count
979
+ from 30 and runs the same settle rule, with the play before the move as its first reading.
980
+ Measured on issue #47's betting and the bench ranges, 4 threads in Node, with out of position's
981
+ range moved five times: two hand classes added, nine added, back to the start, two dropped, and a
982
+ third of the range dropped (`bench/lite/slider.ts`):
983
+
984
+ | flop | five moves, `setRange` | five `solveLite` | a move | iterations a move | less exploitable than `solveLite` | first solve |
985
+ |---|---|---|---|---|---|---|
986
+ | As Kh 7d | 95 s | 163 s | 12–27 s against 28–44 | 120–260 against 400–420 | 4 moves of 5 | 46 s against 30 |
987
+ | Ts 9s 4h | 69 s | 103 s | 11–20 s against 19–25 | 140–280 against 320 | 5 of 5 | 24 s against 18 |
988
+ | Ks 9s 4s | 27 s | 52 s | 3–8 s against 9–14 | 80–240 against 340–380 | 2 of 5 | 12 s against 10 |
989
+
990
+ So a slider move settles in 0.52–0.68× the time of a new solve over the five, the two-class
991
+ moves in 0.31–0.61× and the largest, a third of the range dropped, in 0.66–0.92×. What it
992
+ settles on is about as good. Its exploitability in the blueprint's own game was 2.97–4.66% of
993
+ pot against `solveLite`'s 3.16–5.45 on As Kh 7d and Ts 9s 4h, lower in 9 moves of 10, and
994
+ 3.64–6.38 against 3.63–4.63 on the monotone flop, where the three moves that dropped hands
995
+ ended 0.6–1.8 higher. Against the new range's blueprint run to 1000 iterations, how often the
996
+ range takes each root action was closer than `solveLite`'s in 11 moves of 15 (1.6–6.9 points off
997
+ against 2.6–8.2). Hand by hand it was further off in 10 of 15, by 0.5–8 points. Part of that is
998
+ the reserve, which changes the hands stored and so the runouts bucketed together: `solveLite`
999
+ given the same reserve was itself further off than without it, by 0.1–6.6 points, in all 12
1000
+ moves where the reserve held more than the range.
1001
+
1002
+ Any range is taken, and every Lite option works with it. The same five moves in three other
1003
+ ways, each against `solveLite` with the same options (seconds for the five; then in how many
1004
+ moves the session ended less exploitable):
1005
+
1006
+ | | As Kh 7d | Ts 9s 4h | Ks 9s 4s | less exploitable |
1007
+ |---|---|---|---|---|
1008
+ | No reserve | 83 against 143 | 66 against 91 | 27 against 51 | 12 moves of 15 |
1009
+ | `compressRanges`, wide ranges | 161 against 193 | 110 against 178 | 50 against 90 | 14 of 15 |
1010
+ | `algorithm: 'cfr+'`, with the reserve | 105 against 147 | 70 against 103 | 20 against 58 | 8 of 15 |
1011
+
1012
+ - **The reserve is optional.** `oopReserve` and `ipReserve` name hands to store ahead: with the
1013
+ widest ranges the slider can reach in them, every move changes in place, at 27–42% more an
1014
+ iteration and a first solve 20–52% longer for the nine classes above. Without them the first
1015
+ solve costs what `solveLite`'s does, and a move that adds a hand the blueprint does not store,
1016
+ or breaks a suit symmetry it folds runouts by, gets a new run on the new ranges, started from
1017
+ the old one's regrets. The new run stores that hand and every hand stored before it, so the
1018
+ way back is in place; after a range that broke a symmetry the session stays without it. A new
1019
+ run costs a run's setup and the copy, about 0.5 s on a 265 MiB blueprint, and holds both
1020
+ blueprints for that moment.
1021
+ - **`compressRanges`** compresses both ranges again at every move, so every move gets a new run.
1022
+ Measured on a big blind's call against a button's open (458 and 426 combinations), where it
1023
+ matters; on As Kh 7d the gain is small, 0.83× the time, and one move of five was slower.
1024
+ - **`algorithm: 'cfr+'`** keeps its iteration count at a move and clears its average, and
1025
+ settles to half the tolerance unless `resettle` gives one, since its fresh average stops
1026
+ moving sooner than it is good. It is the fastest of the three and the least even: on the
1027
+ monotone flop every move ended 0.2–1.4% of pot more exploitable than `solveLite`.
1028
+
1029
+ The runout buckets are chosen by the hands stored, so they hold for every range that changes in
1030
+ place. Under the blueprint's shared river histories a reserved hand's river play is not trained
1031
+ until it has weight, so a move that adds hands has that to settle too. Each `setRange` or
1032
+ `refine` makes the `LiteSolution` before it stale: it reads the session's live storage.
1033
+
1034
+ A spot that starts on the turn or the river compresses too (issue #158): give the board's four or
1035
+ five cards and the ranges the players hold there. A turn is matched on its board and each river
1036
+ that can follow. A river has no board to follow, so there each range also keeps what the other
1037
+ player's hands face: how much of it beats each, ties it and loses to it. The default tolerance
1038
+ is 0.005 past the flop. On four turns, with the ranges a flop solve arrives with after check, bet
1039
+ a third, call (270–497 combinations a side, issue #47's betting, 4 threads in Node):
1040
+
1041
+ | board | Lite | tolerance 0.005 | tolerance 0.01 | two Lite solves apart |
1042
+ |---|---|---|---|---|
1043
+ | Td 9d 6h 2c | 1.6 s, 11 MiB | 0.6 s, 4 MiB, 127 / 119 combinations, root play 1.2 points off | 0.5 s, 98 / 93, 3.6 | 0.6 |
1044
+ | As 7d 2c 7h | 2.4 s, 10 MiB | 0.7 s, 3 MiB, 87 / 123, 1.4 | 0.5 s, 70 / 95, 7.8 | 2.6 |
1045
+ | Qs 8s 4s 2h | 1.3 s, 6 MiB | 0.7 s, 3 MiB, 158 / 190, 1.7 | 0.6 s, 128 / 153, 1.1 | 0.6 |
1046
+ | 8h 8d 3c Kc | 1.6 s, 7 MiB | 0.8 s, 3 MiB, 147 / 194, 1.9 | 0.6 s, 124 / 149, 3.7 | 1.7 |
1047
+
1048
+ On the four rivers that follow (149–431 combinations) Lite took 0.1 s with the full ranges, so
1049
+ there is nothing to save; the root play was 0.5–2.6 points off at 0.005, where two Lite solves
1050
+ were 0.5–1.5 apart, and 1.6–4.6 at 0.01. The compressor's own comparison, on another solver with
1051
+ one bet size and averaged over every decision, put the range 0.5–0.8 points off on turns and
1052
+ 0.1–0.5 on rivers at 0.005.
1053
+
881
1054
  Measured on that spot's betting, in headless Chromium. The time counts solving and the settle
882
1055
  checks. Root play loss is what OOP's root mix and IP's mix after a check lose at the
883
1056
  unshared blueprint's per-action values (solved to 0.05% of pot), with that blueprint's
@@ -46,6 +46,12 @@ function serveEngine(setup) {
46
46
  const into = setup.boardValues >>> 2;
47
47
  const profile = new Float64Array(setup.profile[0]);
48
48
  const busy = setup.profile[1];
49
+ const pages = new Uint8Array(memory.buffer);
50
+ if (Atomics.load(control, COMMAND) !== EXIT) {
51
+ for (let r = 0; r < setup.touch.length; r += 2) {
52
+ for (let at = setup.touch[r]; at < setup.touch[r + 1]; at += 4096) pages[at] = 0;
53
+ }
54
+ }
49
55
  let generation = Atomics.load(control, GENERATION);
50
56
  Atomics.add(control, READY, 1);
51
57
  Atomics.notify(control, READY);