@chrischall/warapp-mcp 0.5.0 → 0.7.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 (125) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +133 -8
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +177 -17
  7. package/dist/analysis/card-threats.js +126 -14
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/decision-replay.js +279 -0
  13. package/dist/analysis/decision-truth.js +146 -0
  14. package/dist/analysis/finished-game.js +62 -3
  15. package/dist/analysis/game-lessons.js +15 -10
  16. package/dist/analysis/hold-diff.js +3 -1
  17. package/dist/analysis/income-trend.js +38 -0
  18. package/dist/analysis/intel.js +75 -0
  19. package/dist/analysis/opens.js +64 -0
  20. package/dist/analysis/opponent-profile.js +121 -10
  21. package/dist/analysis/opponents.js +246 -20
  22. package/dist/analysis/outlook.js +360 -15
  23. package/dist/analysis/picks.js +91 -12
  24. package/dist/analysis/plan/after-leftover.js +4 -1
  25. package/dist/analysis/plan/bonus-attempts.js +105 -0
  26. package/dist/analysis/plan/capture-instead.js +116 -0
  27. package/dist/analysis/plan/captures.js +49 -7
  28. package/dist/analysis/plan/conceded-out.js +13 -2
  29. package/dist/analysis/plan/estimates.js +203 -30
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +110 -9
  32. package/dist/analysis/plan/jabs.js +113 -0
  33. package/dist/analysis/plan/leftover.js +393 -8
  34. package/dist/analysis/plan/orders.js +76 -4
  35. package/dist/analysis/plan/relations.js +135 -2
  36. package/dist/analysis/plan/report.js +69 -3
  37. package/dist/analysis/plan/second-sizing.js +133 -0
  38. package/dist/analysis/plan/shared.js +279 -27
  39. package/dist/analysis/plan/siege.js +303 -0
  40. package/dist/analysis/plan/stand-still.js +9 -5
  41. package/dist/analysis/plan/state.js +8 -0
  42. package/dist/analysis/plan/stockpile.js +104 -0
  43. package/dist/analysis/plan/strike.js +39 -7
  44. package/dist/analysis/plan/targets.js +256 -110
  45. package/dist/analysis/plan/threats.js +148 -10
  46. package/dist/analysis/plan/transfers.js +57 -6
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/planner.js +527 -49
  50. package/dist/analysis/profile.js +13 -2
  51. package/dist/analysis/since-last.js +18 -5
  52. package/dist/analysis/stress.js +8 -2
  53. package/dist/board.js +36 -2
  54. package/dist/bonus-attempt-store.js +55 -0
  55. package/dist/build-id.js +106 -0
  56. package/dist/bundle.js +54138 -41059
  57. package/dist/cards.js +7 -5
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/chat.js +35 -1
  60. package/dist/client.js +14 -0
  61. package/dist/commerce.js +111 -0
  62. package/dist/decision-log.js +1093 -0
  63. package/dist/finished-store.js +5 -1
  64. package/dist/index.js +9 -1
  65. package/dist/lessons-store.js +322 -21
  66. package/dist/live.js +43 -0
  67. package/dist/move-order.js +64 -3
  68. package/dist/normalize.js +17 -0
  69. package/dist/open-games.js +36 -16
  70. package/dist/outlook-log.js +42 -1
  71. package/dist/profile-store.js +12 -2
  72. package/dist/protocol/methods.js +62 -5
  73. package/dist/protocol/rpc.js +8 -0
  74. package/dist/relations-store.js +38 -4
  75. package/dist/review-export.js +198 -0
  76. package/dist/siege-store.js +49 -0
  77. package/dist/state-bundle.js +584 -0
  78. package/dist/state-cli.js +71 -0
  79. package/dist/strategy/notes.js +56 -0
  80. package/dist/team-cards.js +25 -0
  81. package/dist/tools/accept-surrender.js +23 -9
  82. package/dist/tools/award.js +20 -2
  83. package/dist/tools/card-advice.js +93 -28
  84. package/dist/tools/card-plays.js +2 -2
  85. package/dist/tools/card-support-advice.js +37 -7
  86. package/dist/tools/chat-advice.js +330 -0
  87. package/dist/tools/chat-inbox.js +19 -4
  88. package/dist/tools/chat.js +106 -17
  89. package/dist/tools/check-plan.js +68 -12
  90. package/dist/tools/commerce-deploy.js +33 -0
  91. package/dist/tools/common.js +31 -0
  92. package/dist/tools/decision-capture.js +459 -0
  93. package/dist/tools/end-of-game.js +151 -21
  94. package/dist/tools/game-kind.js +92 -0
  95. package/dist/tools/how-lost.js +7 -2
  96. package/dist/tools/index.js +10 -0
  97. package/dist/tools/join-game.js +10 -4
  98. package/dist/tools/live-context.js +6 -0
  99. package/dist/tools/live.js +10 -1
  100. package/dist/tools/map-curves.js +73 -0
  101. package/dist/tools/notifications.js +4 -3
  102. package/dist/tools/opponents.js +2 -0
  103. package/dist/tools/past-games.js +74 -8
  104. package/dist/tools/picks.js +61 -10
  105. package/dist/tools/profile-hook.js +62 -3
  106. package/dist/tools/profile-opponents.js +4 -0
  107. package/dist/tools/push.js +2 -2
  108. package/dist/tools/relations.js +139 -0
  109. package/dist/tools/scout.js +16 -2
  110. package/dist/tools/state.js +232 -0
  111. package/dist/tools/strategy.js +3 -3
  112. package/dist/tools/stress-opponents.js +7 -2
  113. package/dist/tools/surrender-pending.js +10 -1
  114. package/dist/tools/surrender.js +18 -3
  115. package/dist/tools/survival.js +11 -3
  116. package/dist/tools/team-brief.js +2 -2
  117. package/dist/tools/team.js +12 -3
  118. package/dist/tools/turn.js +643 -76
  119. package/dist/tools/where.js +3 -1
  120. package/dist/version.js +1 -1
  121. package/manifest.json +32 -3
  122. package/mint.yaml +37 -4
  123. package/package.json +4 -4
  124. package/server.json +20 -2
  125. package/skills/warapp-mcp/SKILL.md +73 -17
@@ -1,5 +1,7 @@
1
+ import { commerceRules } from '../../commerce.js';
2
+ import { LEAD_ARMIES } from '../opponents.js';
1
3
  import { bonusTerritories } from '../bonuses.js';
2
- import { armiesForChance, armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, fewestAttackersToKill, fewestAttackersToTake, luckFraction, specialUnitStrength, straightKills, } from '../combat.js';
4
+ import { armiesForChance, armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, fewestAttackersToKill, fewestAttackersToTake, guaranteedKills, luckFraction, specialUnitStrength, straightKills, } from '../combat.js';
3
5
  import { neighborsOf } from '../graph.js';
4
6
  import { armyCapIncome, boardIncome, DEFAULT_BASE_INCOME, incomeRules, territoryIncome } from '../player.js';
5
7
  import { byNum } from './util.js';
@@ -11,6 +13,11 @@ export const PAYBACK_TURNS = 10;
11
13
  * next turn, and a border may still be retaken or the stack turned elsewhere.
12
14
  */
13
15
  export const BREACH_WEIGHT = 0.5;
16
+ /**
17
+ * #291: the share of what a gate's loss opens (`opensBehind`: held bonuses every route from an enemy or the fog
18
+ * reaches only through it) that its protected value counts — the enemy still has to walk in, as with a breach.
19
+ */
20
+ export const OPENS_WEIGHT = 0.5;
14
21
  /** #201: the shortest payback horizon once the game is decided. */
15
22
  export const DECIDED_PAYBACK_MIN = 3;
16
23
  /** …or when one remaining territory alone costs more than this many times its value (a wasteland). */
@@ -42,16 +49,12 @@ export const TRACKED_MIN_TURNS = 2;
42
49
  export const PRIOR_EVIDENCE_TURNS = 4;
43
50
  /**
44
51
  * #294: an opponent's tracked income was read from less than this share of its frontier
45
- * ({@link frontierCoverage}, over its income window): it is read as low, and the estimate never
46
- * falls below the tracked figure × {@link LOW_COVERAGE_FACTOR}. Unmeasured.
52
+ * ({@link frontierCoverage}, over its income window): the evidence is thin. #368 (owner decision of
53
+ * 2026-11-19): the estimate is then the midpoint of its range, moved toward the tracked figure as the
54
+ * coverage nears this share ({@link EnemyDeployEstimate.thinEvidence}); it replaced #294's floor of the
55
+ * tracked figure × 1.5. Unmeasured.
47
56
  */
48
57
  export const LOW_COVERAGE = 0.5;
49
- /**
50
- * #294: while coverage is under {@link LOW_COVERAGE}, the estimate is at least the tracked figure ×
51
- * this (at most what it could earn). Unmeasured: the play session's long fogged games tracked a half
52
- * to a quarter of the income later seen, so 1.5 is a cautious floor, not a correction.
53
- */
54
- export const LOW_COVERAGE_FACTOR = 1.5;
55
58
  /** Fog reveals named in the observed-deploy rationale before "and N more". */
56
59
  export const MAX_NAMED_REVEALS = 6;
57
60
  /**
@@ -277,6 +280,10 @@ export function guaranteedFallsReaching(saveCosts, reaches, deploy) {
277
280
  const savable = saveCosts.filter((c, i) => c <= (reaches[i] ?? deploy));
278
281
  return saveCosts.length - savable.length + guaranteedFalls(savable, deploy);
279
282
  }
283
+ /** #419: the income a pace stands for, given my income. */
284
+ export function fogPaceIncome(p, myIncome) {
285
+ return p.basis === 'map' ? Math.max(0, Math.floor(p.income ?? 0)) : Math.ceil(Math.max(0, myIncome) * (p.ratio ?? 0) - 1e-9);
286
+ }
280
287
  /**
281
288
  * Fog levels that hide a territory's armies. The live board names war.app's StandingFogLevel
282
289
  * (1 You, 2 Visible, 3 OwnerOnly, 4 Fogged; the client refuses a deploy on 3 or 4 as "fogged");
@@ -580,6 +587,123 @@ export function repelledFloor(g, before, after, me, playerId, orders, settings =
580
587
  }
581
588
  return best;
582
589
  }
590
+ /**
591
+ * #418 (the owner's decision of 2026-11-20: proof may always raise an estimate): the fewest armies that
592
+ * can kill `defenders` however the attack is split into orders. One attack of `a` kills at most
593
+ * round(a × the best kill rate luck allows) (straight; weighted rounding rounds up a fraction); a split
594
+ * gains most per army at the smallest attack, so the most kills per army is the best over small attacks.
595
+ */
596
+ function fewestAttackersAnySplit(defenders, settings) {
597
+ if (defenders <= 0)
598
+ return 0;
599
+ let perArmy = 0;
600
+ for (let a = 1; a <= 20; a++) {
601
+ // The most kills `a` attackers can make: the largest k with fewestAttackersToKill(k) ≤ a.
602
+ let k = 0;
603
+ for (;;) {
604
+ const need = fewestAttackersToKill(k + 1, settings, settings.luckModifier, settings.roundingMode);
605
+ if (need === null || need > a)
606
+ break;
607
+ k++;
608
+ }
609
+ perArmy = Math.max(perArmy, k / a);
610
+ }
611
+ return perArmy > 0 ? Math.ceil(defenders / perArmy - 1e-9) : null;
612
+ }
613
+ /**
614
+ * #418: a capture with every source army in view proves a minimum deploy. Without Multi-Attack each army
615
+ * moves once, so every attacker on a territory it took — and every army that then moved in — came from
616
+ * its territories beside the target at the start of the turn: their armies then (less the guard, a
617
+ * commander as 7) plus what it deployed on them. What arrived is at least what stands there now plus the
618
+ * attacker the last defender surely killed ({@link guaranteedKills} of one), and at least the fewest
619
+ * armies that kill every defender however the attack was split ({@link fewestAttackersAnySplit}); what
620
+ * that leaves beyond the supply was deployed.
621
+ * A capture reads only when: the target was a neutral or mine, shown with its armies, and its now, shown
622
+ * with its armies, no special unit on it; every neighbour of the target showed its owner on the earlier
623
+ * board and each of its showed its armies (a hidden one may have sent a stack); no other player borders
624
+ * the target on either board (it may have worn the defenders down first); and, when the target was mine
625
+ * or borders mine, my orders are known in full (`sent` and `cards`) and none of them leaves the target,
626
+ * enters it or plays a card on it (a move of mine out of it leaves fewer defenders; an attack of mine in
627
+ * kills some first). A Bomb it may have played (`bomb`) halves the defenders first. Over every such
628
+ * capture the floor is the larger of the best single capture and all of them together (their attackers
629
+ * summed against the stacks beside any of them, each counted once), as {@link repelledFloor} does.
630
+ */
631
+ export function captureFloor(g, before, after, playerId, settings = {}, guard = (settings.oneArmyStandsGuard ?? true) ? 1 : 0, opts = {}) {
632
+ const none = { territories: [], attackers: 0, supply: 0, floor: 0 };
633
+ if (settings.multiAttack)
634
+ return none;
635
+ const was = new Map(before.territories.map((t) => [t.territoryId, t]));
636
+ const now = new Map(after.territories.map((t) => [t.territoryId, t]));
637
+ const { me, orders } = opts;
638
+ const ordersKnown = !!orders?.sent && !!orders.cards;
639
+ const touchedByMe = (id) => !ordersKnown ||
640
+ orders.sent.some((m) => m.from === id || m.to === id) ||
641
+ orders.moves.some((m) => m.from === id || m.to === id) ||
642
+ orders.cards.some((c) => c.from === id || c.to === id || c.target === id);
643
+ const its = (t) => t?.owner.kind === 'player' && t.owner.playerId === playerId;
644
+ const sendable = (id) => {
645
+ const st = visibleState(was.get(id));
646
+ return Math.max(0, st.armies - guard) + specialUnitStrength(st.specialUnits?.filter((u) => u.playerId === playerId));
647
+ };
648
+ const lastKill = guaranteedKills(1, settings.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE, settings.luckModifier, settings.roundingMode);
649
+ const caps = [];
650
+ for (const t of [...after.territories].sort((a, b) => a.territoryId - b.territoryId)) {
651
+ const id = t.territoryId;
652
+ if (!g.territoryById.has(id))
653
+ continue;
654
+ const a = visibleState(t);
655
+ const b = visibleState(was.get(id));
656
+ if (!its(a) || !b || its(b) || a.specialUnits?.length || b.specialUnits?.length)
657
+ continue;
658
+ const mineBefore = me !== undefined && b.owner.kind === 'player' && b.owner.playerId === me;
659
+ if (b.owner.kind !== 'neutral' && !mineBefore)
660
+ continue;
661
+ const ns = neighborsOf(g, id);
662
+ let ok = true;
663
+ let bordersMe = false;
664
+ const beside = [];
665
+ for (const n of ns) {
666
+ const o = ownerShown(was.get(n));
667
+ if (!o) {
668
+ ok = false;
669
+ break;
670
+ }
671
+ for (const side of [o, ownerShown(now.get(n))]) {
672
+ if (side?.owner.kind !== 'player' || side.owner.playerId === playerId)
673
+ continue;
674
+ if (side.owner.playerId === me)
675
+ bordersMe = true;
676
+ else
677
+ ok = false;
678
+ }
679
+ if (its(o)) {
680
+ if (!visibleState(o))
681
+ ok = false;
682
+ else
683
+ beside.push(n);
684
+ }
685
+ }
686
+ if (!ok || ((mineBefore || bordersMe) && touchedByMe(id)))
687
+ continue;
688
+ const defenders = opts.bomb ? Math.floor(b.armies / 2) : b.armies;
689
+ const kill = fewestAttackersAnySplit(defenders, settings);
690
+ if (kill === null)
691
+ continue;
692
+ const attackers = Math.max(kill, a.armies + (defenders > 0 ? lastKill : 0));
693
+ caps.push({ id, attackers, beside });
694
+ }
695
+ if (!caps.length)
696
+ return none;
697
+ const supplyOf = (ids) => [...new Set(ids)].reduce((n, id) => n + sendable(id), 0);
698
+ const all = { attackers: caps.reduce((n, c) => n + c.attackers, 0), supply: supplyOf(caps.flatMap((c) => c.beside)) };
699
+ let best = { territories: caps.map((c) => c.id), ...all, floor: Math.max(0, all.attackers - all.supply) };
700
+ for (const c of caps) {
701
+ const supply = supplyOf(c.beside);
702
+ if (c.attackers - supply > best.floor)
703
+ best = { ...best, attackers: c.attackers, supply, floor: c.attackers - supply };
704
+ }
705
+ return best;
706
+ }
583
707
  /** #240: the turns {@link repulsedAttacks} looks back over, ending on the board being planned. */
584
708
  export const REPULSE_WINDOW = 3;
585
709
  /** #240: failed, reinforced attacks on one territory within the window that make it repulsed. */
@@ -625,6 +749,9 @@ export function repulsedAttacks(g, boards, me, rates = {}) {
625
749
  const armies = failedAttackMoves(g, was.board, now.board, me, p, orders)
626
750
  .filter((m) => m.to === t)
627
751
  .reduce((n, m) => n + Math.max(0, m.armies), 0);
752
+ // #361: a single-army jab never tries to take it (one army takes no defended territory): no evidence.
753
+ if (armies <= 1)
754
+ continue;
628
755
  const attack = { turn: was.turn, armies, before: b, after: a, kills };
629
756
  const key = `${t}:${p}`;
630
757
  const entry = found.get(key);
@@ -679,7 +806,8 @@ export function repulsedAttacks(g, boards, me, rates = {}) {
679
806
  * before + deploy + transfers in − kills, so deploy ≥ after + kills − before — beside the fog an
680
807
  * ambiguous growth like any other, read as deploy up to the turn's bound. #271: given those orders,
681
808
  * a failed attack on a hold of mine bounds the deploy from below ({@link repelledFloor}: `deploy`,
682
- * `low` and `high` never below it). A capture also claims, after the visible sources, what its stacks
809
+ * `low` and `high` never below it), and so does a capture with every source army in view (#418,
810
+ * {@link captureFloor}: proof may always raise an estimate). A capture also claims, after the visible sources, what its stacks
683
811
  * in view last turn and hidden now could have sent (`arrivals`: no figure counts them but `high`); a
684
812
  * capture of a neutral beside the fog that no visible source sent into reads the attackers it needed
685
813
  * beyond its cost ({@link fewestAttackersToTake}) as ambiguous, deploy up to the bound
@@ -988,7 +1116,13 @@ export function observeSigned(g, board, previous, playerId, rates = {}, context
988
1116
  const repelled = context.me !== undefined && context.myOrders
989
1117
  ? repelledFloor(g, previous, board, context.me, playerId, context.myOrders, rates, guard, context.bomb === true)
990
1118
  : { territories: [], floor: 0 };
991
- const floor = repelled.floor;
1119
+ // #418: a capture with every source army in view proves a minimum deploy, fog or not.
1120
+ const proof = captureFloor(g, previous, board, playerId, rates, guard, {
1121
+ ...(context.me !== undefined ? { me: context.me } : {}),
1122
+ orders: context.myOrders,
1123
+ bomb: context.bomb === true,
1124
+ });
1125
+ const floor = Math.max(repelled.floor, proof.floor);
992
1126
  return {
993
1127
  stacks,
994
1128
  deploy: Math.max(0, total, floor),
@@ -1011,7 +1145,9 @@ export function observeSigned(g, board, previous, playerId, rates = {}, context
1011
1145
  unseenAttackers,
1012
1146
  unseenAttackerArmies,
1013
1147
  repelled: repelled.territories,
1014
- repelledFloor: floor,
1148
+ repelledFloor: repelled.floor,
1149
+ proven: proof.territories,
1150
+ captureFloor: proof.floor,
1015
1151
  low: Math.max(0, total + lowExtra, floor),
1016
1152
  high: Math.max(0, total + highExtra, floor),
1017
1153
  };
@@ -1056,6 +1192,22 @@ export function openingArmies(g, board, when = {}) {
1056
1192
  counts.add(t.armies);
1057
1193
  return counts.size === 1 ? [...counts][0] : null;
1058
1194
  }
1195
+ /**
1196
+ * #368: an opponent's tracked figure as of each of its last three consecutive observed turns — the most
1197
+ * it was seen to earn (`earned`) over that turn and the two before it, the tracker's max-observed window —
1198
+ * when it rose on both steps; else `null` (fewer than three consecutive turns, or a step not a rise).
1199
+ */
1200
+ export function risingTracked(turns) {
1201
+ const n = turns.length;
1202
+ if (n < 3)
1203
+ return null;
1204
+ for (let i = n - 2; i < n; i++)
1205
+ if (turns[i].from !== turns[i - 1].from + 1)
1206
+ return null;
1207
+ const asOf = (i) => Math.max(...turns.slice(Math.max(0, i - 2), i + 1).map((x) => x.earned));
1208
+ const series = [asOf(n - 3), asOf(n - 2), asOf(n - 1)];
1209
+ return series[0] < series[1] && series[1] < series[2] ? series : null;
1210
+ }
1059
1211
  /**
1060
1212
  * Per-opponent enemy deploy estimates, one per visible enemy player (sorted by
1061
1213
  * id): base income plus the bonuses that player visibly holds in full, never
@@ -1091,6 +1243,15 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
1091
1243
  g.map.territories.every((t) => ownerShown(seenNow.get(t.id)) !== undefined);
1092
1244
  const minimum = Math.max(0, Math.floor(settings.baseIncome ?? DEFAULT_BASE_INCOME));
1093
1245
  const per = settings.bonusArmyPer ?? 0;
1246
+ // #418: my income on the board (cards aside) and my armies in view, against which a rising track is weighed.
1247
+ const myLand = new Set();
1248
+ let myArmies = 0;
1249
+ for (const [t, p] of owner)
1250
+ if (p === me) {
1251
+ myLand.add(t);
1252
+ myArmies += armies.get(t) ?? 0;
1253
+ }
1254
+ const myBoardIncome = boardIncome(g, myLand, { base: minimum, per }).total;
1094
1255
  return players.map((playerId) => {
1095
1256
  // Its visible territories are a lower bound on what it holds, so on its
1096
1257
  // per-territory income too.
@@ -1160,7 +1321,15 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
1160
1321
  const priorCap = prior && k > 0
1161
1322
  ? Math.min(couldEarn, territoryIncome(held + Math.ceil((couldHold - held) / k), minimum, per) + possibleOwn + Math.ceil((possible - possibleOwn) / k))
1162
1323
  : null;
1163
- const priorFigure = prior && fogBeside ? Math.min(Math.max(0, Math.floor(priorBase)), priorCap ?? couldEarn) : null;
1324
+ const priorFull = prior && fogBeside ? Math.min(Math.max(0, Math.floor(priorBase)), priorCap ?? couldEarn) : null;
1325
+ // #444: incomes other players stated scale this one's prior down by their ratio to mine (never up).
1326
+ const statedRatio = prior?.stated && !prior.stated.players.some((x) => x.id === playerId) ? prior.stated.ratio : null;
1327
+ const priorFigure = priorFull !== null && statedRatio !== null ? Math.min(priorFull, Math.ceil(priorFull * statedRatio - 1e-9)) : priorFull;
1328
+ // #419: the past winners' pace, as the prior is figured (capped, scaled, only beside the fog), when above it.
1329
+ const paceIncome = prior?.winnerPace ? fogPaceIncome(prior.winnerPace, prior.myIncome) : null;
1330
+ const paceFull = paceIncome !== null && fogBeside && paceIncome > priorBase ? Math.min(paceIncome, priorCap ?? couldEarn) : null;
1331
+ const paceFigure = paceFull !== null && statedRatio !== null ? Math.min(paceFull, Math.ceil(paceFull * statedRatio - 1e-9)) : paceFull;
1332
+ const paceTop = paceFigure !== null && priorFigure !== null && paceFigure > priorFigure ? paceFigure : null;
1164
1333
  // A track over enough turns replaces the single-turn observed figure (S3).
1165
1334
  const track = tracks?.find((t) => t.playerId === playerId);
1166
1335
  const usable = track && track.income !== null && track.turns.length >= TRACKED_MIN_TURNS ? track : undefined;
@@ -1182,7 +1351,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
1182
1351
  ? observeDeploy(g, board, previous, playerId, settings, {
1183
1352
  me,
1184
1353
  guard: (settings.oneArmyStandsGuard ?? true) ? 1 : 0,
1185
- expected: Math.max(visible, trackBound ?? tracked ?? priorFigure ?? 0),
1354
+ expected: Math.max(visible, trackBound ?? tracked ?? priorFull ?? 0),
1186
1355
  most: couldEarn,
1187
1356
  // #293: under Local Deployment, growth beside the fog outside every bonus it could hold is
1188
1357
  // deploy only up to its free income.
@@ -1249,15 +1418,84 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
1249
1418
  // a card (or armies the board misread), never income.
1250
1419
  const exact = ownersAll && !opening ? Math.max(0, base + bonusIncome) : null;
1251
1420
  const source = exact !== null ? 'exact' : priorUsed !== null && priorUsed > seen ? 'prior' : seenSource;
1252
- // #294: what its tracked figure was read from; while that is little, the estimate never falls below
1253
- // the tracked figure × LOW_COVERAGE_FACTOR (the fog hid most of where it deploys).
1421
+ // #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
1254
1422
  const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
1255
- const chosen = source === 'exact' ? exact : source === 'prior' ? priorUsed : seen;
1256
- const lowFloor = source !== 'exact' && tracked !== null && tracked > visible && coverage !== null && coverage.share < LOW_COVERAGE
1257
- ? Math.min(couldEarn, Math.ceil(tracked * LOW_COVERAGE_FACTOR - 1e-9))
1258
- : null;
1259
- const coverageFloor = lowFloor !== null && lowFloor > chosen ? { tracked: tracked, share: coverage.share, factor: LOW_COVERAGE_FACTOR, figure: lowFloor } : null;
1260
- const income = coverageFloor ? coverageFloor.figure : chosen;
1423
+ // #444: an untracked opponent whose prior a stated income scaled: #368's midpoint between what is in
1424
+ // view (or observed) and that prior.
1425
+ const statedMid = statedRatio !== null && source === 'prior' && !usable ? seen + Math.ceil((priorUsed - seen) / 2 - 1e-9) : null;
1426
+ const chosen = source === 'exact' ? exact : source === 'prior' ? (statedMid ?? priorUsed) : seen;
1427
+ // #368 (owner decision of 2026-11-19: on a hidden opponent, choose the middle until we learn
1428
+ // otherwise): thin evidence — its tracked figure read from under LOW_COVERAGE of its frontier —
1429
+ // sizes it for the midpoint between the lower bound (what is in view or tracked, raised to the
1430
+ // trend's next step when its tracked figure rose two turns running, #418: unless I lead it on armies
1431
+ // in view and on income — above its tracked figure, or with LEAD_ARMIES × its armies above what it
1432
+ // earned before the newest rise) and the upper bound (the fog
1433
+ // prior whole, else the most it could earn), moved toward what the evidence gives as the coverage
1434
+ // nears LOW_COVERAGE. A rising track read from more of its frontier only raises the estimate to that
1435
+ // lower bound. Never the maximum.
1436
+ let thinEvidence = null;
1437
+ if (source !== 'exact' && usable && tracked !== null) {
1438
+ // #418: no trend step on an opponent I lead on income (its tracked figure) and on armies in view.
1439
+ // #418 review: with LEAD_ARMIES × its armies in view, the income lead is judged against what it
1440
+ // earned before the newest rise (or its visible income) instead: an over-read tracked figure must
1441
+ // not switch off the gate meant to stop it. (On that judgement alone, with a bare army lead, the
1442
+ // calibration lost 3 of 4 changed samples further below truth.)
1443
+ let theirArmies = 0;
1444
+ for (const t of theirs)
1445
+ theirArmies += armies.get(t) ?? 0;
1446
+ const risen = risingTracked(usable.turns);
1447
+ const leadIt = risen !== null &&
1448
+ myArmies > theirArmies &&
1449
+ (myBoardIncome > Math.max(visible, tracked) || (myArmies >= LEAD_ARMIES * theirArmies && myBoardIncome > Math.max(visible, risen[1])));
1450
+ const rising = leadIt ? null : risen;
1451
+ const thinCoverage = coverage !== null && coverage.share < LOW_COVERAGE;
1452
+ if (thinCoverage || rising) {
1453
+ const trend = rising ? Math.min(couldEarn, rising[2] + Math.ceil((rising[2] - rising[0]) / 2 - 1e-9)) : null;
1454
+ const lower = Math.min(couldEarn, Math.max(visible, tracked, trend ?? 0));
1455
+ // #419: the top of its range is the larger of the prior and the past winners' pace.
1456
+ const upper = Math.max(lower, Math.min(couldEarn, paceTop ?? priorFigure ?? couldEarn));
1457
+ const midpoint = lower + Math.ceil((upper - lower) / 2 - 1e-9);
1458
+ // What the evidence gives without thin evidence (the track, or #235's prior shrunk toward it),
1459
+ // never below the lower bound: the figure meets it at LOW_COVERAGE, so it does not jump there.
1460
+ const toward = Math.min(couldEarn, Math.max(lower, chosen));
1461
+ const weight = thinCoverage ? Math.max(0, 1 - coverage.share / LOW_COVERAGE) : 0;
1462
+ const figure = toward + Math.ceil(weight * (midpoint - toward) - 1e-9);
1463
+ // Thin coverage: the figure replaces the estimate, up or down. A rising track alone: a raise only.
1464
+ if (thinCoverage || figure > chosen)
1465
+ thinEvidence = {
1466
+ coverage: coverage ? coverage.share : null,
1467
+ rising,
1468
+ tracked,
1469
+ prior: priorFigure,
1470
+ trend,
1471
+ lower,
1472
+ upper,
1473
+ midpoint,
1474
+ toward,
1475
+ weight,
1476
+ figure,
1477
+ ...(paceTop !== null && prior?.winnerPace
1478
+ ? {
1479
+ pace: {
1480
+ figure: paceTop,
1481
+ basis: prior.winnerPace.basis,
1482
+ afterTurn: prior.winnerPace.afterTurn,
1483
+ games: prior.winnerPace.games,
1484
+ ...(prior.winnerPace.ratio !== undefined ? { ratio: prior.winnerPace.ratio } : {}),
1485
+ },
1486
+ }
1487
+ : {}),
1488
+ };
1489
+ }
1490
+ }
1491
+ const income = thinEvidence ? thinEvidence.figure : chosen;
1492
+ // #368: the figure thin evidence chose names its source: the prior when there is one and the figure
1493
+ // lies above the lower bound, else the track.
1494
+ const finalSource = thinEvidence
1495
+ ? thinEvidence.prior !== null && thinEvidence.figure > thinEvidence.lower
1496
+ ? 'prior'
1497
+ : 'tracked'
1498
+ : source;
1261
1499
  // #164: a Reinforcement card, from the turn the clock says one can be in hand, until a deployment
1262
1500
  // above its income is seen; the next card is due a card's capturing turns after the last one
1263
1501
  // (pieces carry over while a card is held), never before the turn after the play.
@@ -1319,13 +1557,14 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
1319
1557
  prior: priorFigure,
1320
1558
  priorBlend,
1321
1559
  coverage,
1322
- coverageFloor,
1323
1560
  priorCap,
1324
1561
  fogBeside,
1325
- source,
1562
+ source: finalSource,
1563
+ thinEvidence,
1326
1564
  exact,
1327
1565
  card,
1328
1566
  cardPlayed,
1567
+ ...(priorFull !== null && priorFigure < priorFull ? { stated: { full: priorFull, scaled: priorFigure, lower: seen, midpoint: statedMid } } : {}),
1329
1568
  };
1330
1569
  });
1331
1570
  }
@@ -1370,10 +1609,21 @@ export function incomeFor(g, board, me, settings) {
1370
1609
  */
1371
1610
  export function visibleIncomeFor(g, board, player, settings) {
1372
1611
  const held = new Set();
1612
+ let cities = 0;
1373
1613
  for (const t of board.territories)
1374
- if (g.territoryById.has(t.territoryId) && t.owner.kind === 'player' && t.owner.playerId === player)
1614
+ if (g.territoryById.has(t.territoryId) && t.owner.kind === 'player' && t.owner.playerId === player) {
1375
1615
  held.add(t.territoryId);
1376
- return boardIncome(g, held, incomeRules(settings)).total;
1616
+ cities += t.cities ?? 0;
1617
+ }
1618
+ return boardIncome(g, held, incomeRules(settings)).total + cityGold(cities, settings);
1619
+ }
1620
+ /**
1621
+ * #332: the gold a commerce game's cities pay each turn (CityIncome each), part of the income like a bonus (the client's
1622
+ * income function adds it after base and bonuses, before the army cap). 0 outside a commerce game with city income.
1623
+ */
1624
+ export function cityGold(cities, settings) {
1625
+ const per = commerceRules(settings)?.cityIncome ?? 0;
1626
+ return cities > 0 && per > 0 ? cities * per : 0;
1377
1627
  }
1378
1628
  /**
1379
1629
  * {@link incomeFor} with the army cap's arithmetic: `cap` when the game has one and every territory
@@ -1386,16 +1636,18 @@ export function incomeDetail(g, board, me, settings) {
1386
1636
  const held = new Set();
1387
1637
  let armies = 0;
1388
1638
  let unread = false;
1639
+ let cities = 0;
1389
1640
  for (const t of board.territories) {
1390
1641
  if (!g.territoryById.has(t.territoryId) || t.owner.kind !== 'player' || t.owner.playerId !== me)
1391
1642
  continue;
1392
1643
  held.add(t.territoryId);
1644
+ cities += t.cities ?? 0;
1393
1645
  if (t.armies === null)
1394
1646
  unread = true;
1395
1647
  else
1396
1648
  armies += t.armies;
1397
1649
  }
1398
- const income = boardIncome(g, held, incomeRules(settings)).total;
1650
+ const income = boardIncome(g, held, incomeRules(settings)).total + cityGold(cities, settings);
1399
1651
  if (settings?.armyCap === undefined || settings.armyCap === null || !(settings.armyCap > 0))
1400
1652
  return { income };
1401
1653
  if (unread)