@chrischall/warapp-mcp 0.10.0 → 0.12.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.
Files changed (65) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +10 -8
  4. package/dist/analysis/cards-in-effect.js +10 -1
  5. package/dist/analysis/chat-mentions.js +17 -0
  6. package/dist/analysis/commander-fog.js +126 -0
  7. package/dist/analysis/end-game-stats.js +149 -0
  8. package/dist/analysis/local-deploy.js +3 -2
  9. package/dist/analysis/outlook.js +133 -55
  10. package/dist/analysis/picks.js +125 -0
  11. package/dist/analysis/plan/commander.js +3 -2
  12. package/dist/analysis/plan/deploy-estimates.js +11 -7
  13. package/dist/analysis/plan/estimates.js +63 -9
  14. package/dist/analysis/plan/relations.js +29 -14
  15. package/dist/analysis/plan/shared.js +21 -0
  16. package/dist/analysis/plan/threats.js +74 -5
  17. package/dist/analysis/player-record.js +31 -1
  18. package/dist/analysis/player.js +23 -10
  19. package/dist/analysis/relations.js +83 -9
  20. package/dist/analysis/scale.js +71 -0
  21. package/dist/analysis/single-pick.js +356 -0
  22. package/dist/bundle.js +3099 -809
  23. package/dist/chat-links.js +141 -0
  24. package/dist/finished-store.js +30 -0
  25. package/dist/index.js +1 -1
  26. package/dist/known-mods.js +33 -0
  27. package/dist/map-stats.js +24 -2
  28. package/dist/mod-alliances.js +217 -0
  29. package/dist/mod-data.js +160 -0
  30. package/dist/my-games.js +53 -2
  31. package/dist/normalize.js +7 -0
  32. package/dist/outlook-log.js +13 -0
  33. package/dist/player-record-store.js +5 -3
  34. package/dist/protocol/methods.js +14 -2
  35. package/dist/relations-store.js +29 -1
  36. package/dist/tools/card-advice.js +29 -9
  37. package/dist/tools/card-effects.js +3 -1
  38. package/dist/tools/card-support-advice.js +1 -1
  39. package/dist/tools/chat-advice.js +1 -1
  40. package/dist/tools/chat-inbox.js +67 -10
  41. package/dist/tools/chat.js +46 -8
  42. package/dist/tools/check-plan.js +115 -11
  43. package/dist/tools/close-finished-game.js +110 -0
  44. package/dist/tools/commander-check.js +80 -1
  45. package/dist/tools/diplomacy.js +11 -2
  46. package/dist/tools/end-of-game.js +57 -3
  47. package/dist/tools/game.js +7 -3
  48. package/dist/tools/how-lost.js +68 -5
  49. package/dist/tools/index.js +21 -1
  50. package/dist/tools/map.js +50 -1
  51. package/dist/tools/mod-alliances.js +191 -0
  52. package/dist/tools/my-games.js +12 -1
  53. package/dist/tools/pace.js +44 -0
  54. package/dist/tools/picks.js +41 -1
  55. package/dist/tools/relations.js +120 -7
  56. package/dist/tools/session.js +20 -6
  57. package/dist/tools/stress-opponents.js +25 -2
  58. package/dist/tools/turn.js +338 -42
  59. package/dist/tools/write-kit.js +1 -0
  60. package/dist/version.js +1 -1
  61. package/manifest.json +10 -2
  62. package/mint.yaml +3 -4
  63. package/package.json +1 -1
  64. package/server.json +2 -2
  65. package/skills/warapp-mcp/SKILL.md +73 -11
@@ -60,7 +60,9 @@
60
60
  // LIKELY_LOSING_RATIO × the highest likely high (1 / OUTLOOK_RATIO once its LIKELY_INCOME_MARGIN is
61
61
  // taken back out: it counts every army received and none lost, so alone it read 0.05× in a game I
62
62
  // led) AND that is corroborated, by the main front grinding me down or by my income at most
63
- // BEHIND_RATIO × the most an opponent is tracked earning (the profile's "behind"); such a turn carries
63
+ // BEHIND_RATIO × the most an opponent is tracked earning (the profile's "behind"; #522: an opponent whose
64
+ // frontier read is thin counts at its calibrated estimate when that is higher, as `income` reads it, so a thin
65
+ // read cannot hide being out-earned); such a turn carries
64
66
  // `lowLikely`, and so does an uncorroborated one, whose basis says why it is no loss. The front that
65
67
  // corroborates it is always forecast on the incomes read off my boards (below), never the plan's
66
68
  // (#228 review): warapp_plan_turn plans on an outlook read without the plan's front and then reports
@@ -121,6 +123,7 @@ import { FORECAST_TURNS, forecastBorder, mainFront } from './exchange.js';
121
123
  import { specialUnitStrength } from './combat.js';
122
124
  import { coverageText, LOW_COVERAGE } from './plan/shared.js';
123
125
  import { coverageBucket } from './game-lessons.js';
126
+ import { LARGE_GAME_OPPONENTS, NEAR_STEPS, opponentScope } from './scale.js';
124
127
  /** Turns a state must hold before it is reported. */
125
128
  export const OUTLOOK_TURNS = 3;
126
129
  /** Winning at this strength ratio or more, losing at its inverse or less (borrowed, unmeasured). */
@@ -167,6 +170,12 @@ export const INCOME_AHEAD_RATIO = 1.5;
167
170
  export const SURRENDER_TURNS = 3;
168
171
  /** #436: the samples a coverage band needs before its estimate ÷ truth calibrates an estimate (unmeasured). */
169
172
  export const MIN_CALIBRATION_SAMPLES = 5;
173
+ /** #436: one turn's incomes, mine against the strongest opponent side's. */
174
+ /** Scale: why a large game's outlook compares only the opponents near my land. */
175
+ export const OUTLOOK_FAR_NOTE = `A large game (more than ${LARGE_GAME_OPPONENTS} opponents): the outlook compares the opponents in view or holding land ` +
176
+ `within ${NEAR_STEPS} steps of yours; the others are counted only, since none can reach you this turn and their ` +
177
+ 'strength under the fog would be a prior, not a reading. The surrender line still judges the strongest opponent ' +
178
+ "anywhere, every opponent's estimate included (owner decision 2026-11-23), so a runaway leader far away still counts.";
170
179
  const round2 = (n) => Math.round(n * 100) / 100;
171
180
  /** The armies the special units on a territory fight as (commanders), as the planner counts them. */
172
181
  const unitsOn = (b, id) => specialUnitStrength(b.territories.find((t) => t.territoryId === id)?.specialUnits);
@@ -377,10 +386,10 @@ export function gameOutlook(input) {
377
386
  for (const p of players)
378
387
  if (!ally(p.id) && stillPlaying(p.id))
379
388
  ids.add(p.id);
380
- const rows = [...ids]
381
- .filter((p) => stillPlaying(p))
382
- .sort((a, b) => a - b)
383
- .map((playerId) => {
389
+ // Scale: in a large game (more than LARGE_GAME_OPPONENTS opponents) only the opponents near my land on this
390
+ // board are judged one by one; the rest are counted in the evidence (`far`). Every other game: all of them.
391
+ const scope = opponentScope(g, board, me, [...ids].filter((p) => stillPlaying(p)));
392
+ const rowOf = (playerId) => {
384
393
  const a = armies.get(playerId) ?? 0;
385
394
  const income = boardIncome(g, held.get(playerId) ?? new Set(), rules).total;
386
395
  const low = a + k * income;
@@ -428,7 +437,8 @@ export function gameOutlook(input) {
428
437
  // #436: the most it likely earns a turn, as the likely high counts it.
429
438
  const paceIncome = Math.max(income, last?.income ?? 0, Math.min(cap, pace));
430
439
  return { playerId, low, high, seen, paceIncome, capIncome: cap, likely: Math.min(high, Math.max(low, likely)), source, why };
431
- });
440
+ };
441
+ const rows = [...scope.near].sort((a, b) => a - b).map(rowOf);
432
442
  // PLAN-TEAMS C3: an enemy team is one side, its figures summed; elsewhere a side is a player.
433
443
  const teamOf = (p) => {
434
444
  const t = players.find((x) => x.id === p)?.team;
@@ -567,20 +577,44 @@ export function gameOutlook(input) {
567
577
  // tracked earning (the profile's "behind").
568
578
  // PLAN-TEAMS C3: in a team game my team's income, against the most an enemy team is tracked earning.
569
579
  const myNow = mates.reduce((n, p) => n + boardIncome(g, held.get(p) ?? new Set(), rules).total, boardIncome(g, mineNow, rules).total);
570
- const mostTracked = () => {
580
+ // #436: past games' estimate ÷ truth in a coverage band, when the band has enough samples.
581
+ const calibrationFor = (share) => {
582
+ const c = input.calibration?.[coverageBucket(share)];
583
+ return c && c.n >= MIN_CALIBRATION_SAMPLES && c.geoMean > 0 ? c.geoMean : undefined;
584
+ };
585
+ // #522 (owner decision of 2026-11-23): an opponent whose frontier read is thin counts at its calibrated
586
+ // estimate (as `income` reads it: the tracked figure ÷ its band's estimate ÷ truth, capped at what it could
587
+ // earn), never below its tracked figure; a solid read, or no calibrated band, keeps the tracked figure.
588
+ let mostMemo;
589
+ const mostEarning = () => (mostMemo ??= (() => {
571
590
  const by = new Map();
572
591
  for (const [p, tr] of trackedAll()) {
573
592
  if (ally(p) || tr.income === null)
574
593
  continue;
594
+ let v = tr.income;
595
+ let calibrated = false;
596
+ const thin = !open && (tr.coverage === null || tr.coverage.share < LOW_COVERAGE);
597
+ const factor = thin ? calibrationFor(tr.coverage?.share ?? null) : undefined;
598
+ if (factor !== undefined) {
599
+ const r = rowOf(p);
600
+ const estimate = Math.min(Math.max(r.capIncome, v), Math.max(r.seen.income, Math.round(v / factor)));
601
+ if (estimate > v) {
602
+ v = estimate;
603
+ calibrated = true;
604
+ }
605
+ }
575
606
  const t = teamOf(p);
576
607
  const key = t === undefined ? `p${p}` : `t${t}`;
577
- by.set(key, (by.get(key) ?? 0) + tr.income);
608
+ const side = by.get(key) ?? { n: 0, calibrated: false };
609
+ by.set(key, { n: side.n + v, calibrated: side.calibrated || calibrated });
578
610
  }
579
- let most = 0;
611
+ let most = { most: 0, calibrated: false };
580
612
  for (const v of by.values())
581
- most = Math.max(most, v);
613
+ if (v.n > most.most)
614
+ most = { most: v.n, calibrated: v.calibrated };
582
615
  return most;
583
- };
616
+ })());
617
+ const mostTracked = () => mostEarning().most;
584
618
  const lowLikely = !bound && !estimated && !lostOnBound && likely !== undefined && likely.high > 0 && likely.ratio <= LIKELY_LOSING_RATIO;
585
619
  // #228 review: on my boards' incomes, whatever the plan gave the reported front.
586
620
  const groundDown = ownOutcome === 'ground-down';
@@ -588,7 +622,7 @@ export function gameOutlook(input) {
588
622
  const lostOnEstimate = lowLikely && (groundDown || incomeBehind);
589
623
  // #304: what the state rests on — the two incomes compared and each opponent's frontier read.
590
624
  // Reporting only: nothing above reads it.
591
- const evidenceRows = rows.map((r) => {
625
+ const evidenceRowOf = (r) => {
592
626
  const tr = trackedOf(r.playerId);
593
627
  const tracked = tr?.income ?? null;
594
628
  const cov = tr?.coverage ?? null;
@@ -600,7 +634,8 @@ export function gameOutlook(input) {
600
634
  thin: !open && (cov === null || cov.share < LOW_COVERAGE),
601
635
  ...(cov ? { read: coverageText(cov) } : {}),
602
636
  };
603
- });
637
+ };
638
+ const evidenceRows = rows.map(evidenceRowOf);
604
639
  const compared = likely ? sides.find((x) => x.playerId === likely.playerId) : top;
605
640
  const comparedRows = compared ? evidenceRows.filter((r) => (compared.players ?? [compared.playerId]).includes(r.playerId)) : [];
606
641
  const evidence = {
@@ -615,44 +650,60 @@ export function gameOutlook(input) {
615
650
  : null,
616
651
  opponents: evidenceRows,
617
652
  thin: evidenceRows.some((r) => r.thin),
653
+ ...(scope.large ? { far: { count: scope.far.length, note: OUTLOOK_FAR_NOTE } } : {}),
618
654
  };
619
- // #436: each opponent's income range and estimate, summed per side; the strongest side by estimate.
620
- const calibrationFor = (share) => {
621
- const c = input.calibration?.[coverageBucket(share)];
622
- return c && c.n >= MIN_CALIBRATION_SAMPLES && c.geoMean > 0 ? c.geoMean : undefined;
623
- };
624
- const incomeSides = new Map();
625
- for (const r of rows) {
626
- const tr = trackedOf(r.playerId);
627
- const row = evidenceRows.find((x) => x.playerId === r.playerId);
628
- const low = row.income;
629
- const factor = tr?.income != null ? calibrationFor(tr.coverage?.share ?? null) : undefined;
630
- // The calibrated estimate and the top of the range never pass what it could earn this turn (`capIncome`, the
631
- // bound `paceIncome` keeps to): dividing a low-coverage reading by ~0.3 must not read an income it cannot reach.
632
- const capped = (n) => Math.min(Math.max(r.capIncome, low), n);
633
- const estimate = open ? low : factor !== undefined ? capped(Math.max(r.seen.income, Math.round(tr.income / factor))) : low;
634
- const high = open ? low : capped(Math.max(estimate, low, row.thin ? r.paceIncome : low));
635
- const t = teamOf(r.playerId);
636
- const key = t === undefined ? `p${r.playerId}` : `t${t}`;
637
- const side = incomeSides.get(key);
638
- if (!side)
639
- incomeSides.set(key, {
640
- playerId: r.playerId,
641
- ...(t !== undefined ? { team: t, players: [r.playerId] } : {}),
642
- low: Math.min(low, estimate),
643
- high,
644
- estimate,
645
- calibrated: factor !== undefined,
646
- });
647
- else {
648
- side.low += Math.min(low, estimate);
649
- side.high += high;
650
- side.estimate += estimate;
651
- side.calibrated ||= factor !== undefined;
652
- side.players.push(r.playerId);
655
+ const strongestIncome = (from, evRows) => {
656
+ const incomeSides = new Map();
657
+ for (const r of from) {
658
+ const tr = trackedOf(r.playerId);
659
+ const row = evRows.find((x) => x.playerId === r.playerId);
660
+ const low = row.income;
661
+ const factor = tr?.income != null ? calibrationFor(tr.coverage?.share ?? null) : undefined;
662
+ // The calibrated estimate and the top of the range never pass what it could earn this turn (`capIncome`, the
663
+ // bound `paceIncome` keeps to): dividing a low-coverage reading by ~0.3 must not read an income it cannot reach.
664
+ const capped = (n) => Math.min(Math.max(r.capIncome, low), n);
665
+ const estimate = open ? low : factor !== undefined ? capped(Math.max(r.seen.income, Math.round(tr.income / factor))) : low;
666
+ const high = open ? low : capped(Math.max(estimate, low, row.thin ? r.paceIncome : low));
667
+ const t = teamOf(r.playerId);
668
+ const key = t === undefined ? `p${r.playerId}` : `t${t}`;
669
+ const side = incomeSides.get(key);
670
+ if (!side)
671
+ incomeSides.set(key, {
672
+ playerId: r.playerId,
673
+ ...(t !== undefined ? { team: t, players: [r.playerId] } : {}),
674
+ low: Math.min(low, estimate),
675
+ high,
676
+ estimate,
677
+ calibrated: factor !== undefined,
678
+ });
679
+ else {
680
+ side.low += Math.min(low, estimate);
681
+ side.high += high;
682
+ side.estimate += estimate;
683
+ side.calibrated ||= factor !== undefined;
684
+ side.players.push(r.playerId);
685
+ }
653
686
  }
687
+ return [...incomeSides.values()].sort((a, b) => b.estimate - a.estimate || b.high - a.high || a.playerId - b.playerId)[0];
688
+ };
689
+ const theirs = strongestIncome(rows, evidenceRows);
690
+ // Owner decision (2026-11-23, #530): the surrender line keeps judging the strongest opponent ANYWHERE, every
691
+ // opponent's estimate included, so a runaway leader far from my land still counts. Only in a large game does
692
+ // that differ from the outlook's own (nearby) comparison.
693
+ let surrenderSide;
694
+ if (scope.large && scope.far.length) {
695
+ const allRows = [...rows, ...scope.far.map(rowOf)];
696
+ const all = strongestIncome(allRows, allRows.map(evidenceRowOf));
697
+ if (all)
698
+ surrenderSide = {
699
+ playerId: all.playerId,
700
+ ...(all.team !== undefined ? { team: all.team, players: all.players } : {}),
701
+ low: all.low,
702
+ estimate: all.estimate,
703
+ calibrated: all.calibrated,
704
+ near: scope.near.includes(all.playerId),
705
+ };
654
706
  }
655
- const theirs = [...incomeSides.values()].sort((a, b) => b.estimate - a.estimate || b.high - a.high || a.playerId - b.playerId)[0];
656
707
  const income = theirs
657
708
  ? {
658
709
  mine: myNow,
@@ -753,10 +804,21 @@ export function gameOutlook(input) {
753
804
  ...(forecast ? { front: forecast } : {}),
754
805
  state,
755
806
  ...(claimWin || lostOnEstimate ? { estimated: true } : {}),
756
- ...(lowLikely ? { lowLikely: { myIncome: myNow, mostTracked: mostTracked(), groundDown, losing: lostOnEstimate } } : {}),
807
+ ...(lowLikely
808
+ ? {
809
+ lowLikely: {
810
+ myIncome: myNow,
811
+ mostTracked: mostTracked(),
812
+ ...(mostEarning().calibrated ? { calibrated: true } : {}),
813
+ groundDown,
814
+ losing: lostOnEstimate,
815
+ },
816
+ }
817
+ : {}),
757
818
  evidence,
758
819
  ...(bonusesLost.length ? { bonusesLost } : {}),
759
820
  ...(income ? { income } : {}),
821
+ ...(surrenderSide ? { surrenderSide } : {}),
760
822
  ...(bonusesInReach.length ? { bonusesInReach } : {}),
761
823
  };
762
824
  });
@@ -875,17 +937,28 @@ export function gameOutlook(input) {
875
937
  }
876
938
  : undefined;
877
939
  // #436: the surrender line (advice only): my income under the line for SURRENDER_TURNS turns running.
878
- const below = (t) => !!t.income && t.income.mine < INCOME_BEHIND_RATIO * t.income.theirs.estimate && trackedBehind(t.income);
940
+ // The side the line judges against: in a large game the strongest anywhere (`surrenderSide`), else the outlook's own.
941
+ const lineSide = (t) => t.income
942
+ ? t.surrenderSide
943
+ ? { mine: t.income.mine, theirs: t.surrenderSide, calibrated: t.surrenderSide.calibrated, anywhere: true }
944
+ : { mine: t.income.mine, theirs: t.income.theirs, calibrated: t.income.calibrated, anywhere: false }
945
+ : undefined;
946
+ const below = (t) => {
947
+ const x = lineSide(t);
948
+ return !!x && x.mine < INCOME_BEHIND_RATIO * x.theirs.estimate && x.mine < x.theirs.low;
949
+ };
879
950
  let turnsBelow = 0;
880
951
  for (let i = turns.length - 1; i >= 0 && below(turns[i]) && (i === turns.length - 1 || turns[i + 1].turn === turns[i].turn + 1); i--)
881
952
  turnsBelow++;
882
953
  let surrenderLine;
883
- if (last && lastIncome && turnsBelow > 0) {
954
+ const lastSide = last ? lineSide(last) : undefined;
955
+ if (last && lastSide && turnsBelow > 0) {
956
+ const lastIncome = lastSide;
884
957
  const line = round2(INCOME_BEHIND_RATIO * lastIncome.theirs.estimate);
885
958
  const closer = (last.bonusesInReach ?? []).find((b) => lastIncome.mine + b.value >= line);
886
959
  const crossed = turnsBelow >= SURRENDER_TURNS && !closer;
887
960
  const who = lastIncome.theirs.team !== undefined ? `team ${lastIncome.theirs.team}` : `player ${lastIncome.theirs.playerId}`;
888
- const est = `${who}'s ~${lastIncome.theirs.estimate} (${lastIncome.calibrated ? "calibrated on past games' estimate ÷ truth" : 'the tracked figure, uncalibrated'})`;
961
+ const est = `${who}'s ~${lastIncome.theirs.estimate} (${lastIncome.calibrated ? "calibrated on past games' estimate ÷ truth" : 'the tracked figure, uncalibrated'}${lastIncome.anywhere ? `; the strongest of every opponent, near or not${'near' in lastIncome.theirs && !lastIncome.theirs.near ? ' — this one is not near your land' : ''}` : ''})`;
889
962
  const mineText = `my ${teamGame ? "team's " : ''}income ${lastIncome.mine}`;
890
963
  const advice = crossed
891
964
  ? `Surrender line crossed (advice only; the server never acts on it): ${mineText} has stayed below two-thirds of ${est} for ${turnsBelow} turns running (the line is ${line}), and no bonus in reach closes the gap.`
@@ -955,6 +1028,8 @@ export function gameOutlook(input) {
955
1028
  }
956
1029
  if (ev && !fullyVisible(g, byTurn.get(last.turn).board) && ev.opponents.length)
957
1030
  reading += ` Frontier read: ${ev.opponents.map((r) => `player ${r.playerId} ${r.read ?? 'not measured'}`).join('; ')}.`;
1031
+ if (ev?.far?.count)
1032
+ reading += ` ${ev.far.count} more opponent${ev.far.count === 1 ? ' is' : 's are'} not near your land and not compared (a large game); the surrender line still judges the strongest opponent anywhere, every opponent's estimate included.`;
958
1033
  if (ev?.thin) {
959
1034
  const pct = Math.round(LOW_COVERAGE * 100);
960
1035
  const which = ev.opponents
@@ -992,15 +1067,18 @@ export function gameOutlook(input) {
992
1067
  const low = last.lowLikely;
993
1068
  if (low) {
994
1069
  const share = `mine is at most 1/${round2(1 / LIKELY_LOSING_RATIO)} (${round2(LIKELY_LOSING_RATIO)}×) of the likely high`;
1070
+ // #522: the figure is a calibrated estimate when a thin frontier read raised it.
1071
+ const earning = low.calibrated ? 'estimated earning' : 'tracked earning';
1072
+ const why = low.calibrated ? ", calibrated on past games' estimate ÷ truth: its frontier read is thin" : '';
995
1073
  const incomeText = low.mostTracked > 0
996
1074
  ? teamGame
997
- ? `my team's income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an enemy team is tracked earning (${low.mostTracked})`
998
- : `my income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an opponent is tracked earning (${low.mostTracked})`
1075
+ ? `my team's income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an enemy team is ${earning} (${low.mostTracked}${why})`
1076
+ : `my income (${low.myIncome}) at most ${BEHIND_RATIO}× the most an opponent is ${earning} (${low.mostTracked}${why})`
999
1077
  : '';
1000
1078
  const behind = low.mostTracked > 0 && low.myIncome <= BEHIND_RATIO * low.mostTracked;
1001
1079
  reading += low.losing
1002
1080
  ? ` Losing on the estimate: ${share}, corroborated by ${[low.groundDown ? 'the main front grinding me down on the incomes read off my boards' : '', behind ? incomeText : ''].filter(Boolean).join(' and ')}.`
1003
- : ` ${share[0].toUpperCase()}${share.slice(1)}, but that alone is no loss: the likely high counts every army an opponent could have received at ${LIKELY_INCOME_MARGIN}× its pace and none it lost, so it reads every fogged opponent strong. Losing on it needs the main front grinding me down on the incomes read off my boards (not the plan's, so the plan acts on the state shown) or my income at most ${BEHIND_RATIO}× the most an opponent is tracked earning${low.mostTracked > 0 ? ` (mine ${low.myIncome}, the most tracked ${low.mostTracked})` : ' (none is tracked)'}.`;
1081
+ : ` ${share[0].toUpperCase()}${share.slice(1)}, but that alone is no loss: the likely high counts every army an opponent could have received at ${LIKELY_INCOME_MARGIN}× its pace and none it lost, so it reads every fogged opponent strong. Losing on it needs the main front grinding me down on the incomes read off my boards (not the plan's, so the plan acts on the state shown) or my income at most ${BEHIND_RATIO}× the most an opponent is tracked earning (its calibrated estimate when its frontier read is thin)${low.mostTracked > 0 ? ` (mine ${low.myIncome}, the most ${low.calibrated ? 'estimated' : 'tracked'} ${low.mostTracked})` : ' (none is tracked)'}.`;
1004
1082
  }
1005
1083
  if (leaning)
1006
1084
  reading += ` Leaning behind: even for ${leaning.turns} turns running while I lost bonuses on each (${leaning.lost.map((x) => `turn ${x.turn} +${x.value}`).join(', ')}): the strength ratio lags a slide the board already shows, so read "even" as falling behind.`;
@@ -162,6 +162,7 @@ import { armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE,
162
162
  import { bfsDistances, neighborsOf } from './graph.js';
163
163
  import { captureCost } from './planner.js';
164
164
  import { boardIncome, DEFAULT_BASE_INCOME } from './player.js';
165
+ import { HUGE_MAP_TERRITORIES, rankSingleStarts, SINGLE_HORIZON, SINGLE_PICK_SHOWN, singleStartReasons } from './single-pick.js';
165
166
  /** Turns the opening simulation runs (income by turn 3). */
166
167
  export const PICK_HORIZON = 3;
167
168
  /** Share of a still-incomplete bonus's value credited per share of it held at the horizon. */
@@ -1843,6 +1844,8 @@ function planCore(input, friendlyIds = []) {
1843
1844
  * not credited to me — with a {@link TeamPicksReport}; with none, or only empty ones, exactly as before.
1844
1845
  */
1845
1846
  export function planPicks(input) {
1847
+ if (singlePickMode(input))
1848
+ return singlePickPlan(input);
1846
1849
  const lists = input.team?.lists ?? [];
1847
1850
  if (!input.team || !lists.some((l) => l.length))
1848
1851
  return planCore(input).plan;
@@ -2189,3 +2192,125 @@ function coverageModel(input) {
2189
2192
  export function coverage(input, picks) {
2190
2193
  return coverageModel(input)(picks);
2191
2194
  }
2195
+ /**
2196
+ * Single-pick distribution on a huge map (mega-game spec part 2): a game that overrides bonus values,
2197
+ * a territory limit of 1, not a team game, not a full deal, three or more players, a map of at least
2198
+ * {@link HUGE_MAP_TERRITORIES} territories and more pickable territories than one page shows. Every
2199
+ * other plan is the group search, byte-identical (the owner: games without overrides or with a limit
2200
+ * above 1 must not change).
2201
+ */
2202
+ export function singlePickMode(input) {
2203
+ const g = input.graph;
2204
+ return (input.overridden === true &&
2205
+ Math.floor(input.territoryLimit) === 1 &&
2206
+ input.team === undefined &&
2207
+ !input.fullDeal &&
2208
+ Math.floor(input.players) >= 3 &&
2209
+ g.map.territories.length >= HUGE_MAP_TERRITORIES &&
2210
+ new Set(input.pickable.filter((t) => g.territoryById.has(t))).size > SINGLE_PICK_SHOWN);
2211
+ }
2212
+ /**
2213
+ * The single-pick plan: the ranking of every pickable start (`rankSingleStarts`), the best first as the
2214
+ * primary, the next as the fallback in rank order, cut at `maxPicks` (the client's players × 1), so the
2215
+ * submit list stays within the client's max; one page of SINGLE_PICK_SHOWN starts carries reasons.
2216
+ */
2217
+ function singlePickPlan(input) {
2218
+ const g = input.graph;
2219
+ const s = input.settings ?? {};
2220
+ const r = rankSingleStarts({
2221
+ graph: g,
2222
+ pickable: input.pickable,
2223
+ settings: s,
2224
+ players: input.players,
2225
+ ...(input.neutralArmies ? { neutralArmies: input.neutralArmies } : {}),
2226
+ ...(input.budgetMs !== undefined ? { budgetMs: input.budgetMs } : {}),
2227
+ ...(input.clock ? { clock: input.clock } : {}),
2228
+ });
2229
+ const pages = Math.max(1, Math.ceil(r.ranked.length / SINGLE_PICK_SHOWN));
2230
+ const page = Math.min(pages, Math.max(1, Math.floor(input.singlePage ?? 1)));
2231
+ const from = (page - 1) * SINGLE_PICK_SHOWN;
2232
+ const starts = r.ranked.slice(from, from + SINGLE_PICK_SHOWN).map((x) => ({ ...x, reasons: singleStartReasons(g, x, r.base, s.commanders === true) }));
2233
+ const reasonsOf = new Map(starts.map((x) => [x.territoryId, x.reasons]));
2234
+ const maxPicks = Math.max(1, Math.floor(input.maxPicks));
2235
+ const list = r.ranked.slice(0, maxPicks);
2236
+ const picks = list.map((x, i) => ({
2237
+ territoryId: x.territoryId,
2238
+ group: i === 0 ? 'primary' : 'fallback',
2239
+ score: x.score,
2240
+ reasons: reasonsOf.get(x.territoryId) ?? [],
2241
+ }));
2242
+ const top = list[0];
2243
+ const pickSet = new Set(r.ranked.map((x) => x.territoryId));
2244
+ const threatsOf = (bonusId, turn) => {
2245
+ const near = new Set();
2246
+ for (const m of bonusTerritories(g, bonusId))
2247
+ for (const [t] of boundedDistances(g, m, turn + 1))
2248
+ if (t !== top.territoryId && pickSet.has(t))
2249
+ near.add(t);
2250
+ return [...near].sort(byNum);
2251
+ };
2252
+ const rest = list.slice(1).map((x) => x.territoryId);
2253
+ let far = 0;
2254
+ for (const a of rest) {
2255
+ const d = bfsDistances(g, [a]);
2256
+ for (const b of rest)
2257
+ far = Math.max(far, d.get(b) ?? Number.POSITIVE_INFINITY);
2258
+ }
2259
+ const groups = {
2260
+ primary: {
2261
+ territoryIds: [top.territoryId],
2262
+ score: top.score,
2263
+ bonuses: top.bonuses.map((b) => ({ bonusId: b.bonusId, name: b.name, value: b.value, turn: b.turn, threats: threatsOf(b.bonusId, b.turn) })),
2264
+ twoOrderCaptures: [],
2265
+ maxHops: 0,
2266
+ },
2267
+ fallback: {
2268
+ territoryIds: rest,
2269
+ score: list[1]?.score ?? 0,
2270
+ bonuses: [],
2271
+ twoOrderCaptures: [],
2272
+ maxHops: rest.length ? (Number.isFinite(far) ? far : null) : 0,
2273
+ },
2274
+ };
2275
+ const warnings = [];
2276
+ const luck = luckPercent(s.luckModifier);
2277
+ if (luck > 0)
2278
+ warnings.push(`Luck is ${luck}%: capture costs carry a margin and can still fail.`);
2279
+ if (s.localDeployments)
2280
+ warnings.push('Local deployments are on: the flood opening pools every army, so bonus income it deploys anywhere is an upper bound.');
2281
+ if (s.minimumArmyBonus === undefined)
2282
+ warnings.push(`Base income missing from settings; assumed ${DEFAULT_BASE_INCOME}.`);
2283
+ if (r.partial)
2284
+ warnings.push(`The ${input.budgetMs} ms time budget ran out: ${r.simulated} of ${r.pickable} starts were simulated; the rest are ranked by their quick score (nearest paying bonus).`);
2285
+ const rationale = [
2286
+ `Single pick on a huge map (${g.map.territories.length} territories, ${r.pickable} pickable, ${Math.floor(input.players)} players, territory limit 1): ` +
2287
+ 'each pickable territory is ranked as a lone start instead of searching groups.',
2288
+ `Score: the income above the ${r.base} base over ${SINGLE_HORIZON + 1} turns of a flood opening at the game's bonus values (${r.paying} bonuses pay; ` +
2289
+ 'a bonus worth 0 is crossed, never counted), each completed bonus discounted by the chance a rival starts within reach of it, ' +
2290
+ 'less a safety charge in starting armies: rival starts within 3 hops, open approaches and entries into the 2-hop pocket' +
2291
+ `${s.commanders ? ' (doubled: Commanders are on)' : ''}, wastelands shielding an approach credited.`,
2292
+ `The submit list is the ranking in priority order, cut at ${maxPicks} (the client's max: players × 1); ` +
2293
+ `starts ${from + 1}–${from + starts.length} carry reasons (page ${page} of ${pages}; ask for another page to see the next ${SINGLE_PICK_SHOWN}).`,
2294
+ ];
2295
+ if (r.simulated < r.pickable && !r.partial)
2296
+ rationale.push(`Only the ${r.simulated} starts with the best quick score were simulated (the pool cap); the rest follow by quick score.`);
2297
+ return {
2298
+ picks,
2299
+ groups,
2300
+ side: mapSides(g, [top.territoryId], []),
2301
+ coverage: coverage({ graph: g, pickable: input.pickable, settings: s, ...(input.neutralArmies ? { neutralArmies: input.neutralArmies } : {}) }, [top.territoryId]),
2302
+ warnings,
2303
+ rationale,
2304
+ ...(r.partial ? { partial: true } : {}),
2305
+ candidates: { ranked: r.simulated, pickable: r.pickable, bonuses: r.paying },
2306
+ single: {
2307
+ shown: { from: from + 1, to: from + starts.length, of: r.pickable },
2308
+ page,
2309
+ pages,
2310
+ simulated: r.simulated,
2311
+ paying: r.paying,
2312
+ starts,
2313
+ ...(r.cached ? { cached: true } : {}),
2314
+ },
2315
+ };
2316
+ }
@@ -192,8 +192,9 @@ export function commanderTransit(pc, ps, book, threats, gone = () => false) {
192
192
  const left = d - soft.reduce((a, n) => a + kills(n), 0);
193
193
  return left > 0 && (pc.toTake(left) ?? Infinity) > threats.bombSized(r.from, last);
194
194
  });
195
- // Where it walks to holds it for the rest of the turn (rule 1k there): its hold comes first.
196
- const dest = threats.borderAt(r.to, gone);
195
+ // Where it walks to holds it for the rest of the turn (rule 1k there): its hold against what is in view comes
196
+ // first; a hold against the fog's attackers there (part 5) is rule 1k's, after this transit hold.
197
+ const dest = threats.visibleBorderAt(r.to, gone);
197
198
  let reserve = 0;
198
199
  if (dest) {
199
200
  const there = ps.avail.get(r.to) + book.guardAt(r.to) + pc.unitsAt(r.to);
@@ -4,7 +4,7 @@ import { bonusTerritories } from '../bonuses.js';
4
4
  import { neighborsOf } from '../graph.js';
5
5
  import { armyCapIncome, boardIncome, DEFAULT_BASE_INCOME, incomeRules, territoryIncome } from '../player.js';
6
6
  import { byNum } from './util.js';
7
- import { LOW_COVERAGE, MIN_ENEMY_DEPLOY, OWNERS_SHOWN_FOG, PRIOR_EVIDENCE_TURNS, TRACKED_MIN_TURNS, bombPossibleOn, fogPaceIncome, localFreeOn } from './shared.js';
7
+ import { LOW_COVERAGE, MIN_ENEMY_DEPLOY, OWNERS_SHOWN_FOG, PRIOR_EVIDENCE_TURNS, TRACKED_MIN_TURNS, bombPossibleOn, fogPaceIncome, localFreeOn, reinforcementArmiesFor } from './shared.js';
8
8
  import { observeDeploy, ownerShown, trackCoverage, visibleState } from './observe.js';
9
9
  /**
10
10
  * The army count every visible player territory holds, when they all hold the same one (the
@@ -124,6 +124,10 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
124
124
  myArmies += armies.get(t) ?? 0;
125
125
  }
126
126
  const myBoardIncome = boardIncome(g, myLand, { base: minimum, per }).total;
127
+ // A Reinforcement card: a flat card's armies, or a progressive one by the client's formula — the same for every
128
+ // opponent: 10% (say) of the territories every player holds (here those in view, a floor under fog), or the turn.
129
+ const cardValue = when.reinforcement ? reinforcementArmiesFor(when.reinforcement, { territories: owner.size, turn: when.turn ?? 0 }) : undefined;
130
+ const cardArmies = cardValue?.armies ?? 0;
127
131
  return players.map((playerId) => {
128
132
  // Its visible territories are a lower bound on what it holds, so on its
129
133
  // per-territory income too.
@@ -211,22 +215,22 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
211
215
  // #164: a Reinforcement card play is seen as a deploy (its low reading) above the income that turn:
212
216
  // exactly, when every owner shows; under fog only a jump of the card's armies over its visible income
213
217
  // counts (a smaller excess may be a bonus the fog hides — and the tracked income then carries the jump).
214
- const above = (low, income) => (exact !== null ? low > income : low >= income + when.reinforcement.armies);
218
+ const above = (low, income) => (exact !== null ? low > income : low >= income + cardArmies);
215
219
  let tracked = usable ? usable.income : null;
216
220
  // #427: the tracker reads every deploy as income, so a card play it saw set its figure (the most it was
217
221
  // seen to deploy) and was then carried, while the clock adds the next card on top: one card counted
218
222
  // twice, every turn. When the turns that set the figure are all plays counted as cards, it is read
219
223
  // again with each play's card armies out (never below its visible income, never above the figure).
220
224
  let cardInTrack = null;
221
- if (usable && tracked !== null && when.reinforcement && when.reinforcement.armies > 0 && when.turn !== null && when.turn !== undefined) {
225
+ if (usable && tracked !== null && when.reinforcement && cardArmies > 0 && when.turn !== null && when.turn !== undefined) {
222
226
  const r = when.reinforcement;
223
227
  const read = playsOf(usable.turns.filter((x) => above(x.low, x.visibleIncome)).map((x) => x.from), playerId, when.plays);
224
228
  const plays = new Set(cardsCounted(read.turns, r, when.turn, read.seen).counted);
225
229
  const top = usable.turns.filter((x) => x.observed >= tracked);
226
230
  if (top.length && top.every((x) => plays.has(x.from))) {
227
- const without = Math.max(usable.visibleIncome, ...usable.turns.map((x) => (plays.has(x.from) ? Math.min(x.cap, Math.max(0, x.raw - r.armies)) : x.observed)));
231
+ const without = Math.max(usable.visibleIncome, ...usable.turns.map((x) => (plays.has(x.from) ? Math.min(x.cap, Math.max(0, x.raw - cardArmies)) : x.observed)));
228
232
  if (without < tracked) {
229
- cardInTrack = { was: tracked, income: without, armies: r.armies, turns: top.map((x) => x.from).sort(byNum) };
233
+ cardInTrack = { was: tracked, income: without, armies: cardArmies, turns: top.map((x) => x.from).sort(byNum) };
230
234
  tracked = without;
231
235
  }
232
236
  }
@@ -418,8 +422,8 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
418
422
  const { counted, due } = cardsCounted(read.turns, r, when.turn, read.seen);
419
423
  cardPlayed = counted.at(-1) ?? null;
420
424
  cardSeen = cardPlayed !== null && read.seen.has(cardPlayed);
421
- if (when.turn >= due && r.armies > 0)
422
- card = { armies: r.armies, due };
425
+ if (when.turn >= due && cardArmies > 0)
426
+ card = { armies: cardArmies, due, ...(cardValue?.basis ? { basis: cardValue.basis } : {}) };
423
427
  }
424
428
  const estimate = income + (card?.armies ?? 0);
425
429
  return {
@@ -99,7 +99,7 @@ export function planEnemyEstimates(input) {
99
99
  ...(ctx.reinforcementPlays ? { plays: ctx.reinforcementPlays } : {}),
100
100
  ...(previousBoard && input.previousOrders ? { previousOrders: input.previousOrders } : {}),
101
101
  });
102
- const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? []), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
102
+ const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? [], turn), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
103
103
  return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
104
104
  }
105
105
  /**
@@ -152,12 +152,16 @@ export function applyArmyPrice(estimates, m) {
152
152
  });
153
153
  }
154
154
  /**
155
- * G2 (PLAN-TEAMS D3): each estimate under the Sanctions on its player. A figure read off the board
156
- * (`visible`, `exact`) is income before any cut, so its income (the Reinforcement card left out) is
157
- * cut by the client's rule ({@link sanctionedIncome}); an observed, tracked or prior figure is left
158
- * whole — an observed deploy may already carry the cut — and marked not applied. Unchanged without.
155
+ * G2 (PLAN-TEAMS D3; owner spec 2026-11-23): each estimate under the Sanctions on its player. Every income
156
+ * figure used for it is cut by the client's rule ({@link sanctionedIncome}): the estimate's income (its
157
+ * Reinforcement card left out, kept on top), whatever its source — read off the board, observed, tracked or
158
+ * the fog prior — and thin evidence's range (tracked, prior, trend, lower, upper, midpoint, toward, figure).
159
+ * The card bites from the turn after it is played (`fromTurn`) through its last turn: a figure read only from
160
+ * deploys made on or after `fromTurn` (an observed deploy of last turn, every turn behind a tracked figure)
161
+ * already carries the cut and is left whole (`carried`); a card with no `fromTurn` cuts every figure. A
162
+ * negative percentage raises them. Unchanged without.
159
163
  */
160
- export function applySanctions(estimates, sanctions) {
164
+ export function applySanctions(estimates, sanctions, turn) {
161
165
  if (!sanctions.length)
162
166
  return estimates;
163
167
  return estimates.map((e) => {
@@ -167,12 +171,62 @@ export function applySanctions(estimates, sanctions) {
167
171
  const percentages = on.map((x) => x.percentage);
168
172
  const card = e.card?.armies ?? 0;
169
173
  const before = e.estimate - card;
170
- const applied = e.source === 'visible' || e.source === 'exact';
171
174
  const untilTurn = Math.max(...on.map((x) => x.untilTurn));
175
+ const starts = on.map((x) => x.fromTurn).filter((t) => t !== undefined);
176
+ const fromTurn = starts.length === on.length ? Math.min(...starts) : undefined;
177
+ // The turns of deploys behind the figure: last turn's for an observed one, the track's for a tracked one.
178
+ const behind = e.source === 'observed'
179
+ ? turn !== null && turn !== undefined
180
+ ? [turn - 1]
181
+ : []
182
+ : e.source === 'tracked' || (e.thinEvidence && e.source !== 'prior')
183
+ ? (e.trackedTurns ?? [])
184
+ : [];
185
+ const trackTurns = e.trackedTurns ?? [];
186
+ const carried = fromTurn !== undefined && behind.length > 0 && behind.every((t) => t >= fromTurn);
187
+ const trackCarried = fromTurn !== undefined && trackTurns.length > 0 && trackTurns.every((t) => t >= fromTurn);
188
+ const cut = (x) => sanctionedIncome(x, percentages);
189
+ const z = e.thinEvidence;
190
+ let thinEvidence = z;
191
+ let after;
192
+ if (z) {
193
+ // The track's figures stay whole when every turn behind them was under the card; the prior is always cut.
194
+ const track = (x) => (trackCarried ? x : cut(x));
195
+ const lower = track(z.lower);
196
+ const upper = Math.max(lower, cut(z.upper));
197
+ const midpoint = lower + Math.ceil((upper - lower) / 2 - 1e-9);
198
+ const toward = Math.min(upper, Math.max(lower, trackCarried && z.toward === z.tracked ? z.toward : cut(z.toward)));
199
+ const figure = toward + Math.ceil(z.weight * (midpoint - toward) - 1e-9);
200
+ thinEvidence = {
201
+ ...z,
202
+ tracked: track(z.tracked),
203
+ prior: z.prior === null ? null : cut(z.prior),
204
+ trend: z.trend === null ? null : track(z.trend),
205
+ lower,
206
+ upper,
207
+ midpoint,
208
+ toward,
209
+ figure,
210
+ ...(z.pace ? { pace: { ...z.pace, figure: cut(z.pace.figure) } } : {}),
211
+ };
212
+ // The estimate is the figure when thin evidence set it, else the figure it chose, cut alike.
213
+ after = before === z.figure ? figure : carried ? before : cut(before);
214
+ }
215
+ else
216
+ after = carried ? before : cut(before);
172
217
  return {
173
218
  ...e,
174
- ...(applied ? { estimate: sanctionedIncome(before, percentages) + card } : {}),
175
- sanctioned: { percentages, untilTurn, before, applied },
219
+ estimate: after + card,
220
+ ...(thinEvidence !== z ? { thinEvidence } : {}),
221
+ sanctioned: {
222
+ percentages,
223
+ untilTurn,
224
+ ...(fromTurn !== undefined ? { fromTurn } : {}),
225
+ before,
226
+ after,
227
+ applied: !carried,
228
+ ...(carried ? { carried: true } : {}),
229
+ },
176
230
  };
177
231
  });
178
232
  }