poker-flopsolve 0.1.0 → 0.3.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/worker.js CHANGED
@@ -258,100 +258,104 @@ function buildShowdownTable(runouts, relevant2) {
258
258
  bytes: order.byteLength + liveCount.byteLength + groupStart.byteLength + groupCount.byteLength
259
259
  };
260
260
  }
261
- function showdownValues(reach, table, board, payoff, scratch, out) {
262
- const { weaker, stronger, win } = scratch;
263
- const cards = COMBO_CARDS;
264
- const order = table.order;
265
- const starts = table.groupStart;
266
- const orderBase = board * table.stride;
267
- const groupBase = board * (table.stride + 1);
268
- const groups = table.groupCount[board];
269
- if (table.liveCount[board] === 0) return;
270
- let running = 0;
271
- for (let g = 0; g < groups; g++) {
272
- const from = starts[groupBase + g];
273
- const to = starts[groupBase + g + 1];
274
- if (to - from === 1) {
275
- const combo = order[orderBase + from];
276
- const a = cards[combo * 2];
277
- const b = cards[combo * 2 + 1];
278
- win[combo] = running - (weaker[a] + weaker[b]);
279
- const value = reach[combo];
280
- if (value !== 0) {
281
- running += value;
282
- weaker[a] += value;
283
- weaker[b] += value;
261
+
262
+ // src/hands.ts
263
+ function span(lists, round, board, player) {
264
+ const slot = (lists.roundBase[round] + board) * 2 + player;
265
+ return [lists.start[slot], lists.count[slot]];
266
+ }
267
+ function buildHandSpace(runouts, players, lists) {
268
+ void players;
269
+ const indexOf = new Int32Array(COMBOS).fill(-1);
270
+ const upStart = [new Int32Array(0)];
271
+ const up = [];
272
+ for (let round = 1; round < runouts.rounds; round++) {
273
+ const orbitStart = runouts.orbitStart[round];
274
+ const starts = new Int32Array(runouts.orbitMap[round].length * 2);
275
+ for (let child = 0; child < runouts.counts[round]; child++) {
276
+ const parent = runouts.parent[round][child];
277
+ for (let player = 0; player < 2; player++) {
278
+ const [parentFrom, parentCount] = span(lists, round - 1, parent, player);
279
+ for (let i = 0; i < parentCount; i++) indexOf[lists.list[parentFrom + i]] = i;
280
+ const [childFrom, childCount] = span(lists, round, child, player);
281
+ for (let m = orbitStart[child]; m < orbitStart[child + 1]; m++) {
282
+ const back = runouts.maps.combo[runouts.maps.inverse(runouts.orbitMap[round][m])];
283
+ starts[m * 2 + player] = up.length;
284
+ for (let k = 0; k < childCount; k++) {
285
+ const real = back[lists.list[childFrom + k]];
286
+ const at = indexOf[real];
287
+ if (at < 0) throw new Error("A relabelled hand is not in its range; the relabelling must preserve both ranges");
288
+ up.push(at);
289
+ }
290
+ }
291
+ for (let i = 0; i < parentCount; i++) indexOf[lists.list[parentFrom + i]] = -1;
284
292
  }
285
- continue;
286
- }
287
- for (let i = from; i < to; i++) {
288
- const combo = order[orderBase + i];
289
- win[combo] = running - (weaker[cards[combo * 2]] + weaker[cards[combo * 2 + 1]]);
290
- }
291
- for (let i = from; i < to; i++) {
292
- const combo = order[orderBase + i];
293
- const value = reach[combo];
294
- if (value === 0) continue;
295
- running += value;
296
- weaker[cards[combo * 2]] += value;
297
- weaker[cards[combo * 2 + 1]] += value;
298
293
  }
294
+ upStart.push(starts);
299
295
  }
300
- running = 0;
301
- for (let g = groups - 1; g >= 0; g--) {
302
- const from = starts[groupBase + g];
303
- const to = starts[groupBase + g + 1];
304
- if (to - from === 1) {
305
- const combo = order[orderBase + from];
306
- const a = cards[combo * 2];
307
- const b = cards[combo * 2 + 1];
308
- out[combo] = payoff * (win[combo] - (running - (stronger[a] + stronger[b])));
309
- const value = reach[combo];
310
- if (value !== 0) {
311
- running += value;
312
- stronger[a] += value;
313
- stronger[b] += value;
296
+ const slots = lists.roundBase[runouts.rounds] * 2;
297
+ const sameStart = new Int32Array(slots + 1);
298
+ const same = [];
299
+ for (let round = 0; round < runouts.rounds; round++) {
300
+ for (let board = 0; board < runouts.counts[round]; board++) {
301
+ for (let player = 0; player < 2; player++) {
302
+ const slot = (lists.roundBase[round] + board) * 2 + player;
303
+ const [otherFrom, otherCount] = span(lists, round, board, 1 - player);
304
+ for (let j = 0; j < otherCount; j++) indexOf[lists.list[otherFrom + j]] = j;
305
+ const [from, count] = span(lists, round, board, player);
306
+ sameStart[slot] = same.length;
307
+ for (let i = 0; i < count; i++) same.push(indexOf[lists.list[from + i]]);
308
+ for (let j = 0; j < otherCount; j++) indexOf[lists.list[otherFrom + j]] = -1;
314
309
  }
315
- continue;
316
- }
317
- for (let i = from; i < to; i++) {
318
- const combo = order[orderBase + i];
319
- out[combo] = payoff * (win[combo] - (running - (stronger[cards[combo * 2]] + stronger[cards[combo * 2 + 1]])));
320
- }
321
- for (let i = from; i < to; i++) {
322
- const combo = order[orderBase + i];
323
- const value = reach[combo];
324
- if (value === 0) continue;
325
- running += value;
326
- stronger[cards[combo * 2]] += value;
327
- stronger[cards[combo * 2 + 1]] += value;
328
310
  }
329
311
  }
330
- weaker.fill(0, 0, DECK);
331
- stronger.fill(0, 0, DECK);
312
+ sameStart[slots] = same.length;
313
+ return { upStart, up: Uint16Array.from(up), sameStart, same: Int32Array.from(same) };
332
314
  }
333
- function foldValues(reach, live, liveCount, payoff, scratch, out) {
334
- const sums = scratch.all;
335
- const cards = COMBO_CARDS;
336
- const deck = DECK;
337
- if (liveCount === 0) return;
315
+ function foldValuesHands(oppReach, cardA, cardB, oppFrom, oppCount, myFrom, myCount, same, sameFrom, payoff, sums, out) {
338
316
  let total = 0;
339
- for (let i = 0; i < liveCount; i++) {
340
- const combo = live[i];
341
- const value = reach[combo];
342
- if (value === 0) continue;
317
+ for (let j = 0; j < oppCount; j++) {
318
+ const value = oppReach[j];
343
319
  total += value;
344
- sums[cards[combo * 2]] += value;
345
- sums[cards[combo * 2 + 1]] += value;
346
- sums[deck + combo] += value;
320
+ sums[cardA[oppFrom + j]] += value;
321
+ sums[cardB[oppFrom + j]] += value;
347
322
  }
348
- for (let i = 0; i < liveCount; i++) {
349
- const combo = live[i];
350
- const pair = deck + combo;
351
- out[combo] = payoff * (total - (sums[cards[combo * 2]] + sums[cards[combo * 2 + 1]] - sums[pair]));
352
- sums[pair] = 0;
323
+ for (let i = 0; i < myCount; i++) {
324
+ const twin = same[sameFrom + i];
325
+ const both = twin >= 0 ? oppReach[twin] : 0;
326
+ out[i] = payoff * (total - (sums[cardA[myFrom + i]] + sums[cardB[myFrom + i]] - both));
353
327
  }
354
- sums.fill(0, 0, deck);
328
+ sums.fill(0, 0, DECK);
329
+ }
330
+ function showdownValuesHands(oppReach, cardA, cardB, strength, oppFrom, oppCount, myFrom, myCount, payoff, sums, out) {
331
+ let running = 0;
332
+ let j = 0;
333
+ for (let i = 0; i < myCount; i++) {
334
+ const level = strength[myFrom + i];
335
+ while (j < oppCount && strength[oppFrom + j] < level) {
336
+ const value = oppReach[j];
337
+ running += value;
338
+ sums[cardA[oppFrom + j]] += value;
339
+ sums[cardB[oppFrom + j]] += value;
340
+ j++;
341
+ }
342
+ out[i] = running - (sums[cardA[myFrom + i]] + sums[cardB[myFrom + i]]);
343
+ }
344
+ sums.fill(0, 0, DECK);
345
+ running = 0;
346
+ j = oppCount - 1;
347
+ for (let i = myCount - 1; i >= 0; i--) {
348
+ const level = strength[myFrom + i];
349
+ while (j >= 0 && strength[oppFrom + j] > level) {
350
+ const value = oppReach[j];
351
+ running += value;
352
+ sums[cardA[oppFrom + j]] += value;
353
+ sums[cardB[oppFrom + j]] += value;
354
+ j--;
355
+ }
356
+ out[i] = payoff * (out[i] - (running - (sums[cardA[myFrom + i]] + sums[cardB[myFrom + i]])));
357
+ }
358
+ sums.fill(0, 0, DECK);
355
359
  }
356
360
 
357
361
  // src/tree.ts
@@ -611,7 +615,8 @@ function makeBuffers(ctx2, width) {
611
615
  live: make(() => new Uint16Array(COMBOS)),
612
616
  hands: make(() => new Uint16Array(width)),
613
617
  strategy: make(() => new Float64Array(actions * COMBOS)),
614
- rank: new Int32Array(COMBOS)
618
+ rank: new Int32Array(COMBOS),
619
+ position: new Int32Array(COMBOS)
615
620
  };
616
621
  }
617
622
  function pairValues(ctx2, node, board, traverser, hands, handReach, live, liveCount) {
@@ -754,16 +759,15 @@ function walk(ctx2, buffers, traverser, hands, node, board, colReach, cols, colC
754
759
  const actions = tree.numEdges[node];
755
760
  const edgeBase = tree.firstEdge[node];
756
761
  const owner = tree.player[node];
757
- const index = ctx2.players[owner];
758
- const stride = index.count;
759
- const slotBase = ctx2.layout.offset[node] + board * actions * stride;
760
762
  const lists = ctx2.active;
761
763
  const listSlot = (lists.roundBase[tree.round[node]] + board) * 2 + owner;
762
- const active = lists.list;
764
+ const active2 = lists.list;
763
765
  const activeFrom = lists.start[listSlot];
764
766
  const activeCount = lists.count[listSlot];
767
+ const stride = activeCount;
768
+ const slotBase = ctx2.layout.offset[node] + actions * ctx2.layout.rowStart[listSlot];
765
769
  const strategy = buffers.strategy[depth];
766
- averageStrategy(ctx2.strategySum, slotBase, actions, stride, active, lists.slot, activeFrom, activeCount, strategy, ctx2.regret);
770
+ averageStrategy(ctx2.strategySum, slotBase, actions, stride, strategy, ctx2.regret);
767
771
  if (owner === traverser) {
768
772
  for (let a = 0; a < actions; a++) {
769
773
  const offset = a * COMBOS;
@@ -784,8 +788,8 @@ function walk(ctx2, buffers, traverser, hands, node, board, colReach, cols, colC
784
788
  for (let c = 0; c < colCount; c++) {
785
789
  const row = cols[c] * COMBOS;
786
790
  for (let i = 0; i < activeCount; i++) {
787
- const combo = active[activeFrom + i];
788
- out[row + combo] += strategy[a * stride + lists.slot[activeFrom + i]] * value[row + combo];
791
+ const combo = active2[activeFrom + i];
792
+ out[row + combo] += strategy[a * stride + i] * value[row + combo];
789
793
  }
790
794
  }
791
795
  }
@@ -793,12 +797,14 @@ function walk(ctx2, buffers, traverser, hands, node, board, colReach, cols, colC
793
797
  }
794
798
  const childReach = buffers.colReach[depth + 1];
795
799
  const childCols = buffers.cols[depth + 1];
800
+ const position = buffers.position;
801
+ for (let i = 0; i < activeCount; i++) position[active2[activeFrom + i]] = i;
796
802
  for (let a = 0; a < actions; a++) {
797
803
  const offset = a * COMBOS;
798
804
  let childCount = 0;
799
805
  for (let c = 0; c < colCount; c++) {
800
806
  const k = cols[c];
801
- const r = colReach[k] * strategy[a * stride + index.slot[hands[k]]];
807
+ const r = colReach[k] * strategy[a * stride + position[hands[k]]];
802
808
  childReach[k] = r;
803
809
  if (r !== 0) childCols[childCount++] = k;
804
810
  }
@@ -888,6 +894,29 @@ function buildPlayerIndex(weights2) {
888
894
  return { combos: Uint16Array.from(combos), count: combos.length, slot, weights: weights2 };
889
895
  }
890
896
  function buildLayout(tree, runouts, players, bytesPerElement) {
897
+ const roundBase = new Int32Array(runouts.rounds + 1);
898
+ for (let round = 0; round < runouts.rounds; round++) roundBase[round + 1] = roundBase[round] + runouts.counts[round];
899
+ const rowStart = new Int32Array(roundBase[runouts.rounds] * 2);
900
+ const totals = new Int32Array(runouts.rounds * 2);
901
+ const onBoard = new Uint8Array(DECK);
902
+ for (let round = 0; round < runouts.rounds; round++) {
903
+ const width = runouts.width[round];
904
+ const cards = runouts.cards[round];
905
+ for (let board = 0; board < runouts.counts[round]; board++) {
906
+ onBoard.fill(0);
907
+ for (let i = 0; i < width; i++) onBoard[cards[board * width + i]] = 1;
908
+ for (let player = 0; player < 2; player++) {
909
+ const index = players[player];
910
+ let live = 0;
911
+ for (let i = 0; i < index.count; i++) {
912
+ const combo = index.combos[i];
913
+ if (!onBoard[COMBO_CARDS[combo * 2]] && !onBoard[COMBO_CARDS[combo * 2 + 1]]) live++;
914
+ }
915
+ rowStart[(roundBase[round] + board) * 2 + player] = totals[round * 2 + player];
916
+ totals[round * 2 + player] += live;
917
+ }
918
+ }
919
+ }
891
920
  const offset = new Int32Array(tree.nodeCount).fill(-1);
892
921
  const blockOffset = new Int32Array(tree.nodeCount).fill(-1);
893
922
  let total = 0;
@@ -899,11 +928,20 @@ function buildLayout(tree, runouts, players, bytesPerElement) {
899
928
  if (actions > maxActions) maxActions = actions;
900
929
  offset[node] = total;
901
930
  blockOffset[node] = blocks;
902
- total += runouts.counts[tree.round[node]] * actions * players[tree.player[node]].count;
931
+ total += actions * totals[tree.round[node] * 2 + tree.player[node]];
903
932
  blocks += runouts.counts[tree.round[node]];
904
933
  }
905
934
  const scales = bytesPerElement === 2 ? blocks * 8 * 2 : 0;
906
- return { offset, blockOffset, blocks, totalSlots: total, maxActions, bytes: total * bytesPerElement * 2 + scales };
935
+ return {
936
+ offset,
937
+ blockOffset,
938
+ blocks,
939
+ totalSlots: total,
940
+ maxActions,
941
+ rowStart,
942
+ roundBase,
943
+ bytes: total * bytesPerElement * 2 + scales
944
+ };
907
945
  }
908
946
  var REGRET_STEPS = 32767;
909
947
  var SUM_STEPS = 65535;
@@ -937,7 +975,7 @@ function matchupMass(a, b) {
937
975
  }
938
976
  return mass;
939
977
  }
940
- function buildActiveLists(runouts, players) {
978
+ function buildActiveLists(runouts, players, showdown2 = null) {
941
979
  const roundBase = new Int32Array(runouts.rounds + 1);
942
980
  for (let round = 0; round < runouts.rounds; round++) {
943
981
  roundBase[round + 1] = roundBase[round] + runouts.counts[round];
@@ -958,10 +996,18 @@ function buildActiveLists(runouts, players) {
958
996
  const index = players[player];
959
997
  const slot = (roundBase[round] + board) * 2 + player;
960
998
  start[slot] = entries.length;
999
+ const here = [];
961
1000
  for (let i = 0; i < index.count; i++) {
962
1001
  const combo = index.combos[i];
963
1002
  if (onBoard[COMBO_CARDS[combo * 2]] || onBoard[COMBO_CARDS[combo * 2 + 1]]) continue;
964
- entries.push(combo);
1003
+ here.push(i);
1004
+ }
1005
+ if (showdown2 !== null && round === runouts.rounds - 1) {
1006
+ const group = strengthOn(showdown2, board);
1007
+ here.sort((x, y) => group[index.combos[x]] - group[index.combos[y]] || x - y);
1008
+ }
1009
+ for (const i of here) {
1010
+ entries.push(index.combos[i]);
965
1011
  entrySlots.push(i);
966
1012
  }
967
1013
  count[slot] = entries.length - start[slot];
@@ -978,15 +1024,15 @@ function buildActiveLists(runouts, players) {
978
1024
  const slot = (roundBase[round] + board) * 2 + player;
979
1025
  tieStart[slot] = ties.length;
980
1026
  if (stabStart[board + 1] - stabStart[board] < 2) continue;
981
- const index = players[player];
982
- const seen = new Uint8Array(index.count);
1027
+ const position = /* @__PURE__ */ new Map();
1028
+ for (let e = start[slot]; e < start[slot] + count[slot]; e++) position.set(entries[e], e - start[slot]);
1029
+ const seen = new Uint8Array(count[slot]);
983
1030
  for (let e = start[slot]; e < start[slot] + count[slot]; e++) {
984
- const first = entrySlots[e];
985
- if (seen[first]) continue;
1031
+ if (seen[e - start[slot]]) continue;
986
1032
  const members = [];
987
1033
  for (let k = stabStart[board]; k < stabStart[board + 1]; k++) {
988
- const image = index.slot[runouts.maps.combo[stabMap[k]][entries[e]]];
989
- if (image < 0 || seen[image]) continue;
1034
+ const image = position.get(runouts.maps.combo[stabMap[k]][entries[e]]);
1035
+ if (image === void 0 || seen[image]) continue;
990
1036
  seen[image] = 1;
991
1037
  members.push(image);
992
1038
  }
@@ -996,16 +1042,48 @@ function buildActiveLists(runouts, players) {
996
1042
  }
997
1043
  }
998
1044
  tieStart[slots] = ties.length;
1045
+ const list = Uint16Array.from(entries);
1046
+ const cardA = new Uint8Array(list.length);
1047
+ const cardB = new Uint8Array(list.length);
1048
+ for (let e = 0; e < list.length; e++) {
1049
+ cardA[e] = COMBO_CARDS[list[e] * 2];
1050
+ cardB[e] = COMBO_CARDS[list[e] * 2 + 1];
1051
+ }
1052
+ const strength = new Int32Array(list.length);
1053
+ if (showdown2 !== null) {
1054
+ const last = runouts.rounds - 1;
1055
+ for (let board = 0; board < runouts.counts[last]; board++) {
1056
+ const group = strengthOn(showdown2, board);
1057
+ for (let player = 0; player < 2; player++) {
1058
+ const slot = (roundBase[last] + board) * 2 + player;
1059
+ for (let e = start[slot]; e < start[slot] + count[slot]; e++) strength[e] = group[list[e]];
1060
+ }
1061
+ }
1062
+ }
999
1063
  return {
1000
1064
  start,
1001
1065
  count,
1002
- list: Uint16Array.from(entries),
1066
+ list,
1003
1067
  slot: Uint16Array.from(entrySlots),
1004
1068
  roundBase,
1005
1069
  tieStart,
1006
- ties: Int32Array.from(ties)
1070
+ ties: Int32Array.from(ties),
1071
+ cardA,
1072
+ cardB,
1073
+ strength
1007
1074
  };
1008
1075
  }
1076
+ var strengthScratch = new Int32Array(COMBOS);
1077
+ function strengthOn(table, board) {
1078
+ const orderBase = board * table.stride;
1079
+ const groupBase = board * (table.stride + 1);
1080
+ for (let g = 0; g < table.groupCount[board]; g++) {
1081
+ for (let i = table.groupStart[groupBase + g]; i < table.groupStart[groupBase + g + 1]; i++) {
1082
+ strengthScratch[table.order[orderBase + i]] = g;
1083
+ }
1084
+ }
1085
+ return strengthScratch;
1086
+ }
1009
1087
  function tieMirrors(store, slotBase, actions, stride, ties, from, to, integer) {
1010
1088
  for (let a = 0; a < actions; a++) {
1011
1089
  const row = slotBase + a * stride;
@@ -1026,6 +1104,7 @@ function makeBuffers2(tree, maxActions, simd2) {
1026
1104
  const kernels = simd2 ? loadKernels(depth, maxActions * COMBOS) : null;
1027
1105
  return {
1028
1106
  kernels,
1107
+ cardSums: new Float64Array(DECK),
1029
1108
  value: make(() => new Float64Array(COMBOS)),
1030
1109
  reachFor: [make(() => new Float64Array(COMBOS)), make(() => new Float64Array(COMBOS))],
1031
1110
  strategy: kernels ? Array.from({ length: depth }, (_, d) => kernels.strategy(d)) : make(() => new Float64Array(maxActions * COMBOS)),
@@ -1053,79 +1132,122 @@ function treeDepth2(tree) {
1053
1132
  }
1054
1133
  var DCFR_ALPHA = 1.5;
1055
1134
  var DCFR_BETA = 0;
1056
- var DCFR_GAMMA = 2;
1135
+ var DCFR_GAMMA = 3;
1136
+ function dcfrFactors(t) {
1137
+ const age = t > 2 ? t - 2 : 0;
1138
+ const grown = age ** DCFR_ALPHA;
1139
+ const shrunk = age ** DCFR_BETA;
1140
+ return {
1141
+ keepPositive: grown / (grown + 1),
1142
+ keepNegative: shrunk / (shrunk + 1),
1143
+ keepSum: ((t - 1) / t) ** DCFR_GAMMA
1144
+ };
1145
+ }
1057
1146
  var Mode = { Train: 0, BestResponse: 1, Average: 2 };
1058
- function normalise(source, base, actions, stride, active, slots, from, count, strategy) {
1147
+ function normalise(source, base, actions, count, strategy) {
1059
1148
  const uniform = 1 / actions;
1060
1149
  for (let i = 0; i < count; i++) {
1061
- const slot = slots[from + i];
1062
- const at = base + slot;
1150
+ const at = base + i;
1063
1151
  let total = 0;
1064
1152
  for (let a = 0; a < actions; a++) {
1065
- const value = source[at + a * stride];
1153
+ const value = source[at + a * count];
1066
1154
  const positive = value > 0 ? value : 0;
1067
- strategy[a * stride + slot] = positive;
1155
+ strategy[a * count + i] = positive;
1068
1156
  total += positive;
1069
1157
  }
1070
1158
  if (total > 0) {
1071
- for (let a = 0; a < actions; a++) strategy[a * stride + slot] /= total;
1159
+ for (let a = 0; a < actions; a++) strategy[a * count + i] /= total;
1072
1160
  } else {
1073
- for (let a = 0; a < actions; a++) strategy[a * stride + slot] = uniform;
1161
+ for (let a = 0; a < actions; a++) strategy[a * count + i] = uniform;
1074
1162
  }
1075
1163
  }
1076
1164
  }
1077
- function regretMatch(regret, base, actions, stride, active, slots, from, count, strategy) {
1078
- normalise(regret, base, actions, stride, active, slots, from, count, strategy);
1165
+ function regretMatch(regret, base, actions, count, strategy) {
1166
+ normalise(regret, base, actions, count, strategy);
1079
1167
  }
1080
- function averageStrategy(strategySum, base, actions, stride, active, slots, from, count, strategy, regret) {
1168
+ function averageStrategy(strategySum, base, actions, count, strategy, regret) {
1081
1169
  const fallback = regret !== void 0 && regret.length > 0 ? regret : null;
1082
1170
  const uniform = 1 / actions;
1083
1171
  for (let i = 0; i < count; i++) {
1084
- const slot = slots[from + i];
1085
- const at = base + slot;
1172
+ const at = base + i;
1086
1173
  let total = 0;
1087
1174
  for (let a = 0; a < actions; a++) {
1088
- const value = strategySum[at + a * stride];
1089
- strategy[a * stride + slot] = value;
1175
+ const value = strategySum[at + a * count];
1176
+ strategy[a * count + i] = value;
1090
1177
  total += value;
1091
1178
  }
1092
1179
  if (total > 0) {
1093
- for (let a = 0; a < actions; a++) strategy[a * stride + slot] /= total;
1180
+ for (let a = 0; a < actions; a++) strategy[a * count + i] /= total;
1094
1181
  continue;
1095
1182
  }
1096
1183
  if (fallback !== null) {
1097
1184
  for (let a = 0; a < actions; a++) {
1098
- const value = fallback[at + a * stride];
1185
+ const value = fallback[at + a * count];
1099
1186
  const positive = value > 0 ? value : 0;
1100
- strategy[a * stride + slot] = positive;
1187
+ strategy[a * count + i] = positive;
1101
1188
  total += positive;
1102
1189
  }
1103
1190
  }
1104
1191
  if (total > 0) {
1105
- for (let a = 0; a < actions; a++) strategy[a * stride + slot] /= total;
1192
+ for (let a = 0; a < actions; a++) strategy[a * count + i] /= total;
1106
1193
  } else {
1107
- for (let a = 0; a < actions; a++) strategy[a * stride + slot] = uniform;
1194
+ for (let a = 0; a < actions; a++) strategy[a * count + i] = uniform;
1108
1195
  }
1109
1196
  }
1110
1197
  }
1111
- function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reachMe2, reachOpp2, live, liveCount, depth) {
1198
+ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reachMe2, reachOpp2, depth) {
1112
1199
  const { tree, runouts } = ctx2;
1113
1200
  const out = buffers.value[depth];
1114
1201
  const kind = tree.kind[node];
1202
+ const round = tree.round[node];
1203
+ const lists = ctx2.active;
1204
+ const opponent = 1 - traverser;
1205
+ const mySlot = (lists.roundBase[round] + board) * 2 + traverser;
1206
+ const oppSlot = (lists.roundBase[round] + board) * 2 + opponent;
1207
+ const myFrom = lists.start[mySlot];
1208
+ const myCount = lists.count[mySlot];
1209
+ const oppFrom = lists.start[oppSlot];
1210
+ const oppCount = lists.count[oppSlot];
1115
1211
  if (kind === NodeKind.TerminalFold) {
1116
1212
  const signed = traverser === 0 ? tree.payoff[node] : -tree.payoff[node];
1117
- const weight = ctx2.runoutWeight[tree.round[node]] / ctx2.chipScale;
1118
- foldValues(reachOpp2, live, liveCount, signed * weight, ctx2.scratch, out);
1213
+ const weight = ctx2.runoutWeight[round] / ctx2.chipScale;
1214
+ const hands = ctx2.hands;
1215
+ foldValuesHands(
1216
+ reachOpp2,
1217
+ lists.cardA,
1218
+ lists.cardB,
1219
+ oppFrom,
1220
+ oppCount,
1221
+ myFrom,
1222
+ myCount,
1223
+ hands.same,
1224
+ hands.sameStart[mySlot],
1225
+ signed * weight,
1226
+ buffers.cardSums,
1227
+ out
1228
+ );
1119
1229
  return out;
1120
1230
  }
1121
1231
  if (kind === NodeKind.TerminalShowdown) {
1122
- const weight = ctx2.runoutWeight[tree.round[node]] / ctx2.chipScale;
1123
- showdownValues(reachOpp2, ctx2.showdown, board, tree.payoff[node] * weight, ctx2.scratch, out);
1232
+ const weight = ctx2.runoutWeight[round] / ctx2.chipScale;
1233
+ showdownValuesHands(
1234
+ reachOpp2,
1235
+ lists.cardA,
1236
+ lists.cardB,
1237
+ lists.strength,
1238
+ oppFrom,
1239
+ oppCount,
1240
+ myFrom,
1241
+ myCount,
1242
+ tree.payoff[node] * weight,
1243
+ buffers.cardSums,
1244
+ out
1245
+ );
1124
1246
  return out;
1125
1247
  }
1126
1248
  if (kind === NodeKind.Chance) {
1127
- for (let i = 0; i < liveCount; i++) out[live[i]] = 0;
1128
- const nextRound = tree.round[node] + 1;
1249
+ for (let i = 0; i < myCount; i++) out[i] = 0;
1250
+ const nextRound = round + 1;
1129
1251
  if (ctx2.entryIndexOf !== null && nextRound === ctx2.shardRound) {
1130
1252
  const entry = ctx2.entryIndexOf[node];
1131
1253
  if (entry >= 0) {
@@ -1135,91 +1257,39 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1135
1257
  }
1136
1258
  if (ctx2.chanceOverride !== null) {
1137
1259
  const base = entry * COMBOS;
1138
- for (let i = 0; i < liveCount; i++) out[live[i]] = ctx2.chanceOverride[base + live[i]];
1260
+ for (let i = 0; i < myCount; i++) out[i] = ctx2.chanceOverride[base + i];
1139
1261
  return out;
1140
1262
  }
1141
1263
  }
1142
1264
  }
1143
1265
  const child = tree.edgeChild[tree.firstEdge[node]];
1144
- const width = runouts.width[nextRound];
1145
- const cards = runouts.cards[nextRound];
1146
1266
  const orbitStart = runouts.orbitStart[nextRound];
1147
- const orbitMap = runouts.orbitMap[nextRound];
1148
- const orbitCard = runouts.orbitCard[nextRound];
1149
- const comboMaps = runouts.maps.combo;
1150
- const childLive = buffers.live[depth];
1151
- const comboCards = COMBO_CARDS;
1267
+ const upStart = ctx2.hands.upStart[nextRound];
1268
+ const up = ctx2.hands.up;
1269
+ const childMe = buffers.reachFor[traverser][depth];
1270
+ const childOpp = buffers.reachFor[opponent][depth];
1152
1271
  const sharded = nextRound === ctx2.shardRound;
1153
1272
  const first = runouts.childStart[nextRound][board];
1154
1273
  const last = runouts.childStart[nextRound][board + 1];
1155
1274
  const from = sharded && ctx2.shardStart > first ? ctx2.shardStart : first;
1156
1275
  const to = sharded && ctx2.shardEnd < last ? ctx2.shardEnd : last;
1157
1276
  for (let childBoard = from; childBoard < to; childBoard++) {
1158
- const dealt = cards[childBoard * width + width - 1];
1159
- let childCount = 0;
1160
- for (let i = 0; i < liveCount; i++) {
1161
- const combo = live[i];
1162
- if (comboCards[combo * 2] === dealt || comboCards[combo * 2 + 1] === dealt) continue;
1163
- childLive[childCount++] = combo;
1164
- }
1165
- const value = traverse(
1166
- ctx2,
1167
- buffers,
1168
- mode,
1169
- traverser,
1170
- iterWeight,
1171
- child,
1172
- childBoard,
1173
- reachMe2,
1174
- reachOpp2,
1175
- childLive,
1176
- childCount,
1177
- depth + 1
1178
- );
1179
- for (let i = 0; i < childCount; i++) out[childLive[i]] += value[childLive[i]];
1277
+ const childMySlot = (lists.roundBase[nextRound] + childBoard) * 2 + traverser;
1278
+ const childOppSlot = (lists.roundBase[nextRound] + childBoard) * 2 + opponent;
1279
+ const nMe = lists.count[childMySlot];
1280
+ const nOpp = lists.count[childOppSlot];
1281
+ const firstMember = orbitStart[childBoard];
1180
1282
  const membersEnd = orbitStart[childBoard + 1];
1181
- for (let m = orbitStart[childBoard] + 1; m < membersEnd; m++) {
1182
- const map = comboMaps[orbitMap[m]];
1183
- const real = orbitCard[m];
1184
- if (!ctx2.expandOrbits) {
1185
- for (let i = 0; i < liveCount; i++) {
1186
- const combo = live[i];
1187
- if (comboCards[combo * 2] === real || comboCards[combo * 2 + 1] === real) continue;
1188
- out[combo] += value[map[combo]];
1189
- }
1190
- continue;
1191
- }
1192
- const mappedMe = buffers.mappedMe[depth];
1193
- const mappedOpp = buffers.mappedOpp[depth];
1194
- const mappedLive = buffers.mappedLive[depth];
1195
- let mappedCount = 0;
1196
- for (let i = 0; i < liveCount; i++) {
1197
- const combo = live[i];
1198
- if (comboCards[combo * 2] === real || comboCards[combo * 2 + 1] === real) continue;
1199
- const image = map[combo];
1200
- mappedMe[image] = reachMe2[combo];
1201
- mappedOpp[image] = reachOpp2[combo];
1202
- mappedLive[mappedCount++] = image;
1203
- }
1204
- const mirrored = traverse(
1205
- ctx2,
1206
- buffers,
1207
- mode,
1208
- traverser,
1209
- iterWeight,
1210
- child,
1211
- childBoard,
1212
- mappedMe,
1213
- mappedOpp,
1214
- mappedLive,
1215
- mappedCount,
1216
- depth + 1
1217
- );
1218
- for (let i = 0; i < liveCount; i++) {
1219
- const combo = live[i];
1220
- if (comboCards[combo * 2] === real || comboCards[combo * 2 + 1] === real) continue;
1221
- out[combo] += mirrored[map[combo]];
1283
+ let value = null;
1284
+ for (let m = firstMember; m < membersEnd; m++) {
1285
+ const upMe = upStart[m * 2 + traverser];
1286
+ if (value === null || ctx2.expandOrbits) {
1287
+ const upOpp = upStart[m * 2 + opponent];
1288
+ for (let k = 0; k < nMe; k++) childMe[k] = reachMe2[up[upMe + k]];
1289
+ for (let k = 0; k < nOpp; k++) childOpp[k] = reachOpp2[up[upOpp + k]];
1290
+ value = traverse(ctx2, buffers, mode, traverser, iterWeight, child, childBoard, childMe, childOpp, depth + 1);
1222
1291
  }
1292
+ for (let k = 0; k < nMe; k++) out[up[upMe + k]] += value[k];
1223
1293
  }
1224
1294
  }
1225
1295
  return out;
@@ -1227,36 +1297,29 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1227
1297
  const actions = tree.numEdges[node];
1228
1298
  const edgeBase = tree.firstEdge[node];
1229
1299
  const owner = tree.player[node];
1230
- const index = ctx2.players[owner];
1231
- const stride = index.count;
1232
- const slotBase = ctx2.layout.offset[node] + board * actions * stride;
1233
1300
  const isTraverser = owner === traverser;
1234
- const lists = ctx2.active;
1235
- const listSlot = (lists.roundBase[tree.round[node]] + board) * 2 + owner;
1236
- const active = lists.list;
1237
- const activeSlot = lists.slot;
1238
- const activeFrom = lists.start[listSlot];
1301
+ const listSlot = isTraverser ? mySlot : oppSlot;
1239
1302
  const activeCount = lists.count[listSlot];
1303
+ const stride = activeCount;
1304
+ const slotBase = ctx2.layout.offset[node] + actions * ctx2.layout.rowStart[listSlot];
1240
1305
  const strategy = buffers.strategy[depth];
1306
+ const length = actions * stride;
1241
1307
  if (mode === Mode.Train && buffers.kernels !== null) {
1242
1308
  const kernels = buffers.kernels;
1243
- kernels.input.set(ctx2.regret.subarray(slotBase, slotBase + actions * stride));
1309
+ kernels.input.set(ctx2.regret.subarray(slotBase, slotBase + length));
1244
1310
  kernels.regretMatch(strategy, actions, stride);
1245
1311
  } else if (mode === Mode.Train) {
1246
- regretMatch(ctx2.regret, slotBase, actions, stride, active, activeSlot, activeFrom, activeCount, strategy);
1312
+ regretMatch(ctx2.regret, slotBase, actions, stride, strategy);
1247
1313
  } else if (buffers.kernels !== null) {
1248
1314
  const kernels = buffers.kernels;
1249
- const length = actions * stride;
1250
1315
  kernels.input.set(ctx2.strategySum.subarray(slotBase, slotBase + length));
1251
1316
  const hasRegret = ctx2.regret.length > 0;
1252
1317
  if (hasRegret) kernels.second.set(ctx2.regret.subarray(slotBase, slotBase + length));
1253
1318
  kernels.averageMatch(strategy, actions, stride, hasRegret);
1254
1319
  } else {
1255
- averageStrategy(ctx2.strategySum, slotBase, actions, stride, active, activeSlot, activeFrom, activeCount, strategy, ctx2.regret);
1320
+ averageStrategy(ctx2.strategySum, slotBase, actions, stride, strategy, ctx2.regret);
1256
1321
  }
1257
- for (let i = 0; i < liveCount; i++) out[live[i]] = 0;
1258
1322
  if (isTraverser && mode === Mode.BestResponse) {
1259
- let first = true;
1260
1323
  for (let a = 0; a < actions; a++) {
1261
1324
  const value = traverse(
1262
1325
  ctx2,
@@ -1268,32 +1331,23 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1268
1331
  board,
1269
1332
  reachMe2,
1270
1333
  reachOpp2,
1271
- live,
1272
- liveCount,
1273
1334
  depth + 1
1274
1335
  );
1275
- if (first) {
1276
- for (let i = 0; i < activeCount; i++) out[active[activeFrom + i]] = value[active[activeFrom + i]];
1277
- first = false;
1336
+ if (a === 0) {
1337
+ for (let i = 0; i < myCount; i++) out[i] = value[i];
1278
1338
  } else {
1279
- for (let i = 0; i < activeCount; i++) {
1280
- const combo = active[activeFrom + i];
1281
- if (value[combo] > out[combo]) out[combo] = value[combo];
1282
- }
1339
+ for (let i = 0; i < myCount; i++) if (value[i] > out[i]) out[i] = value[i];
1283
1340
  }
1284
1341
  }
1285
1342
  return out;
1286
1343
  }
1344
+ for (let i = 0; i < myCount; i++) out[i] = 0;
1287
1345
  const childReach = buffers.reachFor[owner][depth];
1288
1346
  const actionValues = buffers.actionValues[depth];
1289
1347
  for (let a = 0; a < actions; a++) {
1290
- const offset = a * COMBOS;
1291
1348
  const row = a * stride;
1292
1349
  const source = isTraverser ? reachMe2 : reachOpp2;
1293
- for (let i = 0; i < activeCount; i++) {
1294
- const combo = active[activeFrom + i];
1295
- childReach[combo] = source[combo] * strategy[row + activeSlot[activeFrom + i]];
1296
- }
1350
+ for (let i = 0; i < activeCount; i++) childReach[i] = source[i] * strategy[row + i];
1297
1351
  const value = traverse(
1298
1352
  ctx2,
1299
1353
  buffers,
@@ -1304,18 +1358,16 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1304
1358
  board,
1305
1359
  isTraverser ? childReach : reachMe2,
1306
1360
  isTraverser ? reachOpp2 : childReach,
1307
- live,
1308
- liveCount,
1309
1361
  depth + 1
1310
1362
  );
1311
1363
  if (isTraverser) {
1312
- for (let i = 0; i < activeCount; i++) {
1313
- const combo = active[activeFrom + i];
1314
- actionValues[offset + combo] = value[combo];
1315
- out[combo] += strategy[row + activeSlot[activeFrom + i]] * value[combo];
1364
+ const offset = a * myCount;
1365
+ for (let i = 0; i < myCount; i++) {
1366
+ actionValues[offset + i] = value[i];
1367
+ out[i] += strategy[row + i] * value[i];
1316
1368
  }
1317
1369
  } else {
1318
- for (let i = 0; i < liveCount; i++) out[live[i]] += value[live[i]];
1370
+ for (let i = 0; i < myCount; i++) out[i] += value[i];
1319
1371
  }
1320
1372
  }
1321
1373
  if (isTraverser && mode === Mode.Train && ctx2.applyUpdates && ctx2.regretScale !== null) {
@@ -1325,10 +1377,6 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1325
1377
  slotBase,
1326
1378
  actions,
1327
1379
  stride,
1328
- active,
1329
- activeSlot,
1330
- activeFrom,
1331
- activeCount,
1332
1380
  iterWeight,
1333
1381
  reachMe2,
1334
1382
  strategy,
@@ -1336,37 +1384,32 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1336
1384
  out
1337
1385
  );
1338
1386
  } else if (isTraverser && mode === Mode.Train && ctx2.applyUpdates && ctx2.dcfr) {
1339
- const previous = iterWeight - 1;
1340
- const grown = previous ** DCFR_ALPHA;
1341
- const shrunk = previous ** DCFR_BETA;
1342
- const keepPositive = grown / (grown + 1);
1343
- const keepNegative = shrunk / (shrunk + 1);
1344
- const keepSum = (previous / iterWeight) ** DCFR_GAMMA;
1387
+ const { keepPositive, keepNegative, keepSum } = dcfrFactors(iterWeight);
1345
1388
  const regret = ctx2.regret;
1346
1389
  const strategySum = ctx2.strategySum;
1347
1390
  for (let a = 0; a < actions; a++) {
1348
- const offset = a * COMBOS;
1391
+ const offset = a * activeCount;
1349
1392
  const slotRow = slotBase + a * stride;
1393
+ const row = a * stride;
1350
1394
  for (let i = 0; i < activeCount; i++) {
1351
- const combo = active[activeFrom + i];
1352
- const at = slotRow + activeSlot[activeFrom + i];
1395
+ const at = slotRow + i;
1353
1396
  const accumulated = regret[at];
1354
- regret[at] = accumulated * (accumulated > 0 ? keepPositive : keepNegative) + actionValues[offset + combo] - out[combo];
1355
- strategySum[at] = strategySum[at] * keepSum + reachMe2[combo] * strategy[a * stride + activeSlot[activeFrom + i]];
1397
+ regret[at] = accumulated * (accumulated > 0 ? keepPositive : keepNegative) + actionValues[offset + i] - out[i];
1398
+ strategySum[at] = strategySum[at] * keepSum + reachMe2[i] * strategy[row + i];
1356
1399
  }
1357
1400
  }
1358
1401
  } else if (isTraverser && mode === Mode.Train && ctx2.applyUpdates) {
1359
1402
  const regret = ctx2.regret;
1360
1403
  const strategySum = ctx2.strategySum;
1361
1404
  for (let a = 0; a < actions; a++) {
1362
- const offset = a * COMBOS;
1405
+ const offset = a * activeCount;
1363
1406
  const slotRow = slotBase + a * stride;
1407
+ const row = a * stride;
1364
1408
  for (let i = 0; i < activeCount; i++) {
1365
- const combo = active[activeFrom + i];
1366
- const at = slotRow + activeSlot[activeFrom + i];
1367
- const updated = regret[at] + actionValues[offset + combo] - out[combo];
1409
+ const at = slotRow + i;
1410
+ const updated = regret[at] + actionValues[offset + i] - out[i];
1368
1411
  regret[at] = updated > 0 ? updated : 0;
1369
- strategySum[at] += iterWeight * reachMe2[combo] * strategy[a * stride + activeSlot[activeFrom + i]];
1412
+ strategySum[at] += iterWeight * reachMe2[i] * strategy[row + i];
1370
1413
  }
1371
1414
  }
1372
1415
  }
@@ -1381,7 +1424,7 @@ function traverse(ctx2, buffers, mode, traverser, iterWeight, node, board, reach
1381
1424
  }
1382
1425
  return out;
1383
1426
  }
1384
- function updateQuantised(ctx2, block, slotBase, actions, stride, active, activeSlot, activeFrom, activeCount, iterWeight, reachMe2, strategy, actionValues, out) {
1427
+ function updateQuantised(ctx2, block, slotBase, actions, count, iterWeight, reachMe2, strategy, actionValues, out) {
1385
1428
  const regret = ctx2.regret;
1386
1429
  const strategySum = ctx2.strategySum;
1387
1430
  const regretScale = ctx2.regretScale;
@@ -1394,44 +1437,37 @@ function updateQuantised(ctx2, block, slotBase, actions, stride, active, activeS
1394
1437
  let weight = iterWeight;
1395
1438
  const clamp = !ctx2.dcfr;
1396
1439
  if (ctx2.dcfr) {
1397
- const previous = iterWeight - 1;
1398
- const grown = previous ** DCFR_ALPHA;
1399
- const shrunk = previous ** DCFR_BETA;
1400
- keepPositive = grown / (grown + 1);
1401
- keepNegative = shrunk / (shrunk + 1);
1402
- keepSum = (previous / iterWeight) ** DCFR_GAMMA;
1440
+ ({ keepPositive, keepNegative, keepSum } = dcfrFactors(iterWeight));
1403
1441
  weight = 1;
1404
1442
  }
1405
1443
  let largestRegret = 0;
1406
1444
  let largestSum = 0;
1407
1445
  for (let a = 0; a < actions; a++) {
1408
- const offset = a * COMBOS;
1409
- const slotRow = slotBase + a * stride;
1410
- for (let i = 0; i < activeCount; i++) {
1411
- const combo = active[activeFrom + i];
1412
- const at = slotRow + activeSlot[activeFrom + i];
1446
+ const offset = a * count;
1447
+ const slotRow = slotBase + a * count;
1448
+ for (let i = 0; i < count; i++) {
1449
+ const at = slotRow + i;
1413
1450
  const accumulated = regret[at] * oldRegret;
1414
- let updated = accumulated * (accumulated > 0 ? keepPositive : keepNegative) + actionValues[offset + combo] - out[combo];
1451
+ let updated = accumulated * (accumulated > 0 ? keepPositive : keepNegative) + actionValues[offset + i] - out[i];
1415
1452
  if (clamp && updated < 0) updated = 0;
1416
1453
  const magnitude = updated < 0 ? -updated : updated;
1417
1454
  if (magnitude > largestRegret) largestRegret = magnitude;
1418
- actionValues[offset + combo] = updated;
1419
- const sum = strategySum[at] * oldSum * keepSum + weight * reachMe2[combo] * strategy[a * stride + activeSlot[activeFrom + i]];
1455
+ actionValues[offset + i] = updated;
1456
+ const sum = strategySum[at] * oldSum * keepSum + weight * reachMe2[i] * strategy[a * count + i];
1420
1457
  if (sum > largestSum) largestSum = sum;
1421
- strategy[a * stride + activeSlot[activeFrom + i]] = sum;
1458
+ strategy[a * count + i] = sum;
1422
1459
  }
1423
1460
  }
1424
1461
  const regretStep = largestRegret > 0 ? REGRET_STEPS / largestRegret : 0;
1425
1462
  const sumStep = largestSum > 0 ? SUM_STEPS / largestSum : 0;
1426
1463
  for (let a = 0; a < actions; a++) {
1427
- const offset = a * COMBOS;
1428
- const slotRow = slotBase + a * stride;
1429
- for (let i = 0; i < activeCount; i++) {
1430
- const combo = active[activeFrom + i];
1431
- const at = slotRow + activeSlot[activeFrom + i];
1432
- const r = actionValues[offset + combo] * regretStep;
1464
+ const offset = a * count;
1465
+ const slotRow = slotBase + a * count;
1466
+ for (let i = 0; i < count; i++) {
1467
+ const at = slotRow + i;
1468
+ const r = actionValues[offset + i] * regretStep;
1433
1469
  regret[at] = r < 0 ? r - 0.5 : r + 0.5;
1434
- const s = strategy[a * stride + activeSlot[activeFrom + i]] * sumStep + dither(at, iterWeight);
1470
+ const s = strategy[a * count + i] * sumStep + dither(at, iterWeight);
1435
1471
  strategySum[at] = s < SUM_STEPS ? s : SUM_STEPS;
1436
1472
  }
1437
1473
  }
@@ -1460,25 +1496,28 @@ function makeSolver(ctx2) {
1460
1496
  rootLive[rootCount++] = combo;
1461
1497
  }
1462
1498
  }
1499
+ const lists = ctx2.active;
1500
+ const listOf = (round, board, player) => {
1501
+ const slot = (lists.roundBase[round] + board) * 2 + player;
1502
+ return [lists.start[slot], lists.count[slot]];
1503
+ };
1504
+ const gather = (source, round, board, player, into) => {
1505
+ const [from, count] = listOf(round, board, player);
1506
+ for (let i = 0; i < count; i++) into[i] = source[lists.list[from + i]];
1507
+ };
1463
1508
  const run = (mode, traverser, iterWeight) => {
1464
- reach0.set(ctx2.players[0].weights);
1465
- reach1.set(ctx2.players[1].weights);
1466
- for (let i = 0; i < COMBOS; i++) {
1467
- if (ctx2.players[0].slot[i] < 0) reach0[i] = 0;
1468
- if (ctx2.players[1].slot[i] < 0) reach1[i] = 0;
1469
- }
1509
+ gather(ctx2.players[0].weights, 0, 0, 0, reach0);
1510
+ gather(ctx2.players[1].weights, 0, 0, 1, reach1);
1470
1511
  const me = traverser === 0 ? reach0 : reach1;
1471
1512
  const opp = traverser === 0 ? reach1 : reach0;
1472
- return traverse(ctx2, buffers, mode, traverser, iterWeight, 0, 0, me, opp, rootLive, rootCount, 0);
1513
+ return traverse(ctx2, buffers, mode, traverser, iterWeight, 0, 0, me, opp, 0);
1473
1514
  };
1474
1515
  let root = run;
1475
1516
  const total = (values, traverser) => {
1476
1517
  const weights2 = ctx2.players[traverser].weights;
1518
+ const [from, count] = listOf(0, 0, traverser);
1477
1519
  let sum = 0;
1478
- for (let i = 0; i < rootCount; i++) {
1479
- const combo = rootLive[i];
1480
- sum += weights2[combo] * values[combo];
1481
- }
1520
+ for (let i = 0; i < count; i++) sum += weights2[lists.list[from + i]] * values[i];
1482
1521
  return sum / ctx2.totalMass;
1483
1522
  };
1484
1523
  return {
@@ -1492,20 +1531,7 @@ function makeSolver(ctx2) {
1492
1531
  root = next ?? run;
1493
1532
  },
1494
1533
  traverseChance(mode, traverser, iterWeight, node, me, opp) {
1495
- return traverse(
1496
- ctx2,
1497
- buffers,
1498
- mode,
1499
- traverser,
1500
- iterWeight,
1501
- node,
1502
- 0,
1503
- me,
1504
- opp,
1505
- rootLive,
1506
- rootCount,
1507
- 0
1508
- );
1534
+ return traverse(ctx2, buffers, mode, traverser, iterWeight, node, 0, me, opp, 0);
1509
1535
  },
1510
1536
  iterate(count, from) {
1511
1537
  for (let i = 0; i < count; i++) {
@@ -1526,21 +1552,19 @@ function makeSolver(ctx2) {
1526
1552
  const expanded = ctx2.expandOrbits;
1527
1553
  ctx2.expandOrbits = true;
1528
1554
  try {
1529
- const value = traverse(
1530
- ctx2,
1531
- buffers,
1532
- Mode.Average,
1533
- traverser,
1534
- 0,
1535
- node,
1536
- board,
1537
- reachMe2,
1538
- reachOpp2,
1539
- live,
1540
- liveCount,
1541
- 0
1542
- );
1543
- return Float64Array.from(value.subarray(0, COMBOS));
1555
+ const round = ctx2.tree.round[node];
1556
+ const opponent = 1 - traverser;
1557
+ const me = new Float64Array(COMBOS);
1558
+ const opp = new Float64Array(COMBOS);
1559
+ gather(reachMe2, round, board, traverser, me);
1560
+ gather(reachOpp2, round, board, opponent, opp);
1561
+ const value = traverse(ctx2, buffers, Mode.Average, traverser, 0, node, board, me, opp, 0);
1562
+ const result = new Float64Array(COMBOS);
1563
+ const [from, count] = listOf(round, board, traverser);
1564
+ for (let i = 0; i < count; i++) result[lists.list[from + i]] = value[i];
1565
+ void live;
1566
+ void liveCount;
1567
+ return result;
1544
1568
  } finally {
1545
1569
  ctx2.expandOrbits = expanded;
1546
1570
  }
@@ -1552,24 +1576,16 @@ function makeSolver(ctx2) {
1552
1576
  const owner = ctx2.tree.player[node];
1553
1577
  const index = ctx2.players[owner];
1554
1578
  const actions = ctx2.tree.numEdges[node];
1555
- const base = ctx2.layout.offset[node] + board * actions * index.count;
1556
- const probs = new Float64Array(index.count * actions);
1557
- const regret = ctx2.regret;
1558
- for (let i = 0; i < index.count; i++) {
1559
- let sum = 0;
1560
- for (let a = 0; a < actions; a++) sum += ctx2.strategySum[base + a * index.count + i];
1561
- let source = ctx2.strategySum;
1562
- if (!(sum > 0) && regret.length > 0) {
1563
- for (let a = 0; a < actions; a++) {
1564
- const value = regret[base + a * index.count + i];
1565
- if (value > 0) sum += value;
1566
- }
1567
- source = regret;
1568
- }
1569
- for (let a = 0; a < actions; a++) {
1570
- const value = source[base + a * index.count + i];
1571
- probs[i * actions + a] = sum > 0 ? value > 0 ? value / sum : 0 : 1 / actions;
1572
- }
1579
+ const slot = (lists.roundBase[ctx2.tree.round[node]] + board) * 2 + owner;
1580
+ const from = lists.start[slot];
1581
+ const count = lists.count[slot];
1582
+ const base = ctx2.layout.offset[node] + actions * ctx2.layout.rowStart[slot];
1583
+ const strategy = new Float64Array(actions * count);
1584
+ averageStrategy(ctx2.strategySum, base, actions, count, strategy, ctx2.regret);
1585
+ const probs = new Float64Array(index.count * actions).fill(1 / actions);
1586
+ for (let i = 0; i < count; i++) {
1587
+ const at = lists.slot[from + i];
1588
+ for (let a = 0; a < actions; a++) probs[at * actions + a] = strategy[a * count + i];
1573
1589
  }
1574
1590
  return { actions, probs };
1575
1591
  }
@@ -1915,9 +1931,9 @@ function expand(segment) {
1915
1931
  if (kind !== "o") suitedCombos(high2, low, out);
1916
1932
  if (kind !== "s") offsuitCombos(high2, low, out);
1917
1933
  };
1918
- const span = /^([AKQJT2-9])([AKQJT2-9])([so])?-([AKQJT2-9])([AKQJT2-9])([so])?$/.exec(text);
1919
- if (span) {
1920
- const [, a1, a2, k1, b1, b2, k2] = span;
1934
+ const span2 = /^([AKQJT2-9])([AKQJT2-9])([so])?-([AKQJT2-9])([AKQJT2-9])([so])?$/.exec(text);
1935
+ if (span2) {
1936
+ const [, a1, a2, k1, b1, b2, k2] = span2;
1921
1937
  const kind = k1 ?? k2;
1922
1938
  if (k1 && k2 && k1 !== k2) throw new Error(`"${text}" mixes suited and offsuit`);
1923
1939
  const from1 = rankOfChar(a1);
@@ -2174,19 +2190,22 @@ for (const combo of spot.players[0].combos) relevant[combo] = 1;
2174
2190
  for (const combo of spot.players[1].combos) relevant[combo] = 1;
2175
2191
  var weights = runoutWeights(spot.runouts);
2176
2192
  var layout = buildLayout(spot.tree, spot.runouts, spot.players, PRECISION_BYTES[precision]);
2193
+ var showdown = buildShowdownTable(spot.runouts, relevant);
2194
+ var active = buildActiveLists(spot.runouts, spot.players, showdown);
2177
2195
  var ctx = {
2178
2196
  tree: spot.tree,
2179
2197
  runouts: spot.runouts,
2180
2198
  players: spot.players,
2181
2199
  layout,
2182
- showdown: buildShowdownTable(spot.runouts, relevant),
2200
+ showdown,
2183
2201
  regret: makeRegretStore(precision, setup.regret),
2184
2202
  strategySum: makeSumStore(precision, setup.strategySum),
2185
2203
  regretScale: setup.regretScale ? new Float64Array(setup.regretScale) : null,
2186
2204
  sumScale: setup.sumScale ? new Float64Array(setup.sumScale) : null,
2187
2205
  scratch: makeTerminalScratch(),
2188
2206
  chipScale: spot.chipScale,
2189
- active: buildActiveLists(spot.runouts, spot.players),
2207
+ active,
2208
+ hands: buildHandSpace(spot.runouts, spot.players, active),
2190
2209
  runoutWeight: weights,
2191
2210
  totalMass: matchupMass(spot.players[0].weights, spot.players[1].weights) * weights[0],
2192
2211
  dcfr,