@chrischall/warapp-mcp 0.6.0 → 0.8.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 (111) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +100 -7
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +187 -20
  7. package/dist/analysis/card-threats.js +68 -3
  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/coalition.js +55 -0
  13. package/dist/analysis/decision-replay.js +279 -0
  14. package/dist/analysis/decision-truth.js +146 -0
  15. package/dist/analysis/finished-game.js +62 -3
  16. package/dist/analysis/game-lessons.js +12 -6
  17. package/dist/analysis/local-deploy.js +14 -0
  18. package/dist/analysis/opponent-profile.js +46 -3
  19. package/dist/analysis/opponents.js +246 -19
  20. package/dist/analysis/outlook.js +323 -17
  21. package/dist/analysis/picks.js +270 -37
  22. package/dist/analysis/plan/after-leftover.js +28 -3
  23. package/dist/analysis/plan/captures.js +80 -16
  24. package/dist/analysis/plan/completed.js +8 -1
  25. package/dist/analysis/plan/conceded-out.js +16 -11
  26. package/dist/analysis/plan/deploy-estimates.js +513 -0
  27. package/dist/analysis/plan/doomed-out.js +135 -0
  28. package/dist/analysis/plan/estimates.js +73 -7
  29. package/dist/analysis/plan/free-capture.js +34 -0
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +85 -313
  32. package/dist/analysis/plan/horizon.js +42 -0
  33. package/dist/analysis/plan/leftover.js +188 -10
  34. package/dist/analysis/plan/observe.js +896 -0
  35. package/dist/analysis/plan/orders.js +35 -1
  36. package/dist/analysis/plan/relations.js +115 -2
  37. package/dist/analysis/plan/report.js +10 -4
  38. package/dist/analysis/plan/shared.js +7 -1189
  39. package/dist/analysis/plan/stand-still.js +7 -5
  40. package/dist/analysis/plan/state.js +12 -0
  41. package/dist/analysis/plan/stockpile.js +104 -0
  42. package/dist/analysis/plan/strike-stack.js +467 -0
  43. package/dist/analysis/plan/strike.js +8 -441
  44. package/dist/analysis/plan/targets.js +374 -72
  45. package/dist/analysis/plan/threats.js +120 -9
  46. package/dist/analysis/plan/transfers.js +35 -1
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/plan/withdraw.js +316 -0
  50. package/dist/analysis/planner.js +356 -53
  51. package/dist/analysis/player.js +4 -0
  52. package/dist/analysis/relations.js +8 -2
  53. package/dist/analysis/since-last.js +18 -5
  54. package/dist/analysis/stress.js +1 -1
  55. package/dist/board.js +36 -2
  56. package/dist/build-id.js +106 -0
  57. package/dist/bundle.js +15863 -10242
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/client.js +14 -0
  60. package/dist/decision-log.js +1093 -0
  61. package/dist/finished-store.js +5 -1
  62. package/dist/lessons-store.js +322 -21
  63. package/dist/my-games.js +2 -0
  64. package/dist/open-games.js +122 -18
  65. package/dist/outlook-log.js +42 -1
  66. package/dist/protocol/methods.js +4 -2
  67. package/dist/review-export.js +198 -0
  68. package/dist/state-bundle.js +62 -3
  69. package/dist/state-cli.js +5 -3
  70. package/dist/strategy/notes.js +56 -0
  71. package/dist/tools/accept-surrender.js +23 -9
  72. package/dist/tools/award.js +5 -1
  73. package/dist/tools/card-advice.js +102 -33
  74. package/dist/tools/card-support-advice.js +53 -8
  75. package/dist/tools/chat-advice.js +330 -0
  76. package/dist/tools/chat-inbox.js +15 -4
  77. package/dist/tools/chat.js +41 -11
  78. package/dist/tools/check-plan.js +16 -3
  79. package/dist/tools/commander-check.js +2 -1
  80. package/dist/tools/decision-capture.js +461 -0
  81. package/dist/tools/end-of-game.js +146 -18
  82. package/dist/tools/game-kind.js +92 -0
  83. package/dist/tools/how-lost.js +7 -2
  84. package/dist/tools/index.js +3 -0
  85. package/dist/tools/join-game.js +51 -9
  86. package/dist/tools/live-context.js +6 -0
  87. package/dist/tools/live.js +43 -6
  88. package/dist/tools/map-curves.js +73 -0
  89. package/dist/tools/notifications.js +4 -3
  90. package/dist/tools/open-games.js +2 -2
  91. package/dist/tools/opponents.js +2 -0
  92. package/dist/tools/past-games.js +74 -8
  93. package/dist/tools/picks.js +169 -57
  94. package/dist/tools/profile-hook.js +62 -3
  95. package/dist/tools/profile-opponents.js +2 -0
  96. package/dist/tools/push.js +2 -2
  97. package/dist/tools/relations.js +2 -0
  98. package/dist/tools/scout.js +16 -2
  99. package/dist/tools/state.js +6 -1
  100. package/dist/tools/strategy.js +3 -3
  101. package/dist/tools/stress-opponents.js +2 -0
  102. package/dist/tools/surrender-pending.js +10 -1
  103. package/dist/tools/surrender.js +18 -3
  104. package/dist/tools/turn.js +353 -19
  105. package/dist/tools/where.js +3 -1
  106. package/dist/version.js +1 -1
  107. package/manifest.json +23 -2
  108. package/mint.yaml +23 -0
  109. package/package.json +1 -1
  110. package/server.json +20 -2
  111. package/skills/warapp-mcp/SKILL.md +42 -8
@@ -10,13 +10,13 @@ import { bfsDistances, neighborsOf } from '../graph.js';
10
10
  import { couldHoldBonusPools, enemyDeployReaching, freeIncome } from '../local-deploy.js';
11
11
  import { incomeBasis, LOST_STACK_TURNS } from '../opponents.js';
12
12
  import { HIDDEN_POOL_INCOMES, MAX_NAMED_REVEALS, coverageText, LOW_COVERAGE, MIN_ENEMY_DEPLOY, openingArmies, ownerShown, visibleState, } from './shared.js';
13
- import { territoryIncome } from '../player.js';
13
+ import { gameBaseIncome, territoryIncome } from '../player.js';
14
14
  import { simTerritories } from '../turn-sim.js';
15
15
  import { byNum } from './util.js';
16
16
  /** Read the threats against my territories, and state them. */
17
- export function threatsPhase(pc, ps, input) {
17
+ export function threatsPhase(pc, ps, input, valueOf) {
18
18
  const src = threatSources(pc, ps, input);
19
- const forces = threatForces(pc, ps, src);
19
+ const forces = threatForces(pc, ps, src, valueOf);
20
20
  const { borders, facing, borderAt, safeAtStart } = borderThreats(pc, ps, input, src, forces);
21
21
  const { growthOf, deployReaching, reinforcementAt, holdArmies, bombSized, hiddenFoe, hiddenMovable, hiddenPool, } = src;
22
22
  const { chainAt, stacksAt, forceAt, threatAt, nextTurnAt, expectedAt, exposure } = forces;
@@ -32,6 +32,8 @@ export function threatsPhase(pc, ps, input) {
32
32
  return {
33
33
  ...seen,
34
34
  growthOf,
35
+ /** #420: each opponent's full-deploy border and the borders its top-up sizes (the leftover's revival reads it). */
36
+ oneBorder: forces.oneBorder,
35
37
  /** #290: the previous board as given (the leftover reads which enemy stacks grew since). */
36
38
  previousBoard: input.previousBoard,
37
39
  deployReaching,
@@ -139,6 +141,8 @@ export function threatSources(pc, ps, input) {
139
141
  // anywhere, so what an estimate holds beyond every bonus it could hold counts as free; without it, a
140
142
  // border faces only the free income and the pools there.
141
143
  const perTerritory = (s.bonusArmyPer ?? 0) > 0;
144
+ /** #433: the free income's floor is the game's own base income (0 and 3 exist), not the 5 of the default. */
145
+ const gameBase = gameBaseIncome(s);
142
146
  if (s.localDeployments && !custom) {
143
147
  const foes = [...new Set([...state.values()].flatMap((t) => (t.owner.kind === 'player' && foe(t.owner.playerId) ? [t.owner.playerId] : [])))].sort(byNum);
144
148
  for (const [p, pools] of couldHoldBonusPools(g, foes, (t) => {
@@ -147,7 +151,7 @@ export function threatSources(pc, ps, input) {
147
151
  })) {
148
152
  enemyPools.set(p, pools);
149
153
  const e = estimates.get(p);
150
- const free = freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0);
154
+ const free = freeIncome(e?.base ?? 0, gameBase, e?.card?.armies ?? 0);
151
155
  const pooled = pools.reduce((n, q) => n + q.value, 0);
152
156
  const figure = deployOf(p);
153
157
  if (perTerritory && figure - pooled > free)
@@ -166,7 +170,7 @@ export function threatSources(pc, ps, input) {
166
170
  if (!pools)
167
171
  return figure;
168
172
  const e = estimates.get(player);
169
- return enemyDeployReaching(figure, freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0), pools, on, perTerritory);
173
+ return enemyDeployReaching(figure, freeIncome(e?.base ?? 0, gameBase, e?.card?.armies ?? 0), pools, on, perTerritory);
170
174
  };
171
175
  /**
172
176
  * #120: what the owner of enemy territory `t` may add there before my attack lands — its deploy
@@ -242,7 +246,8 @@ export function threatSources(pc, ps, input) {
242
246
  const tr = input.tracks?.find((x) => x.playerId === player);
243
247
  // Its income, a Reinforcement card left out: the card is counted once, in the deploy.
244
248
  const e = estimates.get(player);
245
- const income = Math.max(tr?.income ?? 0, (e?.estimate ?? 0) - (e?.card?.armies ?? 0));
249
+ // #427: a tracked figure a card play had set counts without it.
250
+ const income = Math.max(e?.cardInTrack ? e.cardInTrack.income : (tr?.income ?? 0), (e?.estimate ?? 0) - (e?.card?.armies ?? 0));
246
251
  return {
247
252
  unexplained: Math.max(0, Math.floor(tr?.unexplained ?? 0)),
248
253
  cap: income > 0 ? HIDDEN_POOL_INCOMES * income : null,
@@ -326,6 +331,20 @@ export function threatSources(pc, ps, input) {
326
331
  warnings.push(`Player ${l.player}'s stack of ${l.armies} armies last seen on ${label(l.seenOn)} on turn ${l.turn} is out of view and can stand on ${at.slice(0, MAX_NAMED_REVEALS).join('; ')}${more}, by next turn, and attack the turn after with up to ${l.movable} plus its deploy: not counted in this turn's holds${multiNote}.`);
327
332
  }
328
333
  }
334
+ /**
335
+ * #420: each opponent's largest top-up seen (its track's `topUp`: the most one of its stacks beside my
336
+ * land grew in one turn). None under an explicit `enemyDeploy` (the caller's figure stands as given).
337
+ */
338
+ const topUpOf = new Map();
339
+ if (!custom)
340
+ for (const tr of input.tracks ?? [])
341
+ if (foe(tr.playerId) && typeof tr.topUp === 'number')
342
+ topUpOf.set(tr.playerId, tr.topUp);
343
+ /** #420 (P1 amended): the quiet neighbours with a top-up seen, by player. */
344
+ const quietOf = new Map();
345
+ for (const q of input.quiet ?? [])
346
+ if (topUpOf.has(q.player))
347
+ quietOf.set(q.player, { contactTurns: q.contactTurns, attacks: q.attacks });
329
348
  return {
330
349
  growthOf,
331
350
  teamOf,
@@ -339,10 +358,12 @@ export function threatSources(pc, ps, input) {
339
358
  hiddenMovable,
340
359
  hiddenPool,
341
360
  lostAt,
361
+ topUpOf,
362
+ quietOf,
342
363
  };
343
364
  }
344
365
  /** What each opponent can bring against one territory: its stacks, its deploy, its Multi-Attack chains (#199). */
345
- export function threatForces(pc, ps, src) {
366
+ export function threatForces(pc, ps, src, valueOf) {
346
367
  const { g, board, s, foe, territories: state, mineSet, unitsAt, guard, rates, toTake, ffaLeader, untrustedAt } = pc;
347
368
  const { captured } = ps;
348
369
  /**
@@ -503,6 +524,49 @@ export function threatForces(pc, ps, src) {
503
524
  }
504
525
  return byPlayer;
505
526
  };
527
+ /**
528
+ * #420 (owner decision of 2026-11-20, "One opponent's deploy"): an opponent deploys its income in one
529
+ * place, so its full deploy sizes only its single most valuable border of mine (by protected value —
530
+ * `valueOf` —, then its movable armies beside it, then id); each other border of mine its stacks face is
531
+ * sized at those stacks plus its largest top-up seen (`topUpOf`), never above the full deploy. `capAt`:
532
+ * by my territory, the players capped there and the figure; `primary`: each such player's full border.
533
+ * Not on my commander's territory (rule 1k's worst case), nor for an untrusted estimate (#275) at that
534
+ * border, a player with no top-up seen, or one facing a single border of mine. A quiet neighbour
535
+ * (`quietOf`, #420's P1 amendment) has every border capped so, its most valuable one included, and no
536
+ * `primary`. Judged on the board as it stands (no territory gone) and built once.
537
+ */
538
+ let oneBorderMemo;
539
+ const oneBorder = () => {
540
+ if (oneBorderMemo)
541
+ return oneBorderMemo;
542
+ oneBorderMemo = { capAt: new Map(), primary: new Map() };
543
+ if (!src.topUpOf.size)
544
+ return oneBorderMemo;
545
+ const facing = new Map();
546
+ for (const t of [...pc.mine].sort(byNum))
547
+ for (const [player, p] of stacksAt(t, () => false, false)) {
548
+ if (!src.topUpOf.has(player))
549
+ continue;
550
+ facing.set(player, [...(facing.get(player) ?? []), { t, movable: p.stacks.reduce((n, x) => n + x.movable, 0) }]);
551
+ }
552
+ for (const [player, list] of [...facing].sort((a, b) => a[0] - b[0])) {
553
+ // #420 (P1 amended): a quiet neighbour's every border, its most valuable one included.
554
+ const quiet = src.quietOf.has(player);
555
+ if (list.length < 2 && !quiet)
556
+ continue;
557
+ const ranked = [...list].sort((a, b) => valueOf(b.t) - valueOf(a.t) || b.movable - a.movable || a.t - b.t);
558
+ if (!quiet)
559
+ oneBorderMemo.primary.set(player, ranked[0].t);
560
+ for (const { t } of quiet ? ranked : ranked.slice(1)) {
561
+ if (pc.myCommanders.has(t) || untrustedAt(player, t) > 0)
562
+ continue;
563
+ const m = oneBorderMemo.capAt.get(t) ?? new Map();
564
+ m.set(player, src.topUpOf.get(player));
565
+ oneBorderMemo.capAt.set(t, m);
566
+ }
567
+ }
568
+ return oneBorderMemo;
569
+ };
506
570
  /**
507
571
  * #199: the force of a Multi-Attack chain onto my `t`: its player's, its armies all of it (the
508
572
  * deploy that reaches its stack is already inside them), no growth or separate deploy.
@@ -531,9 +595,12 @@ export function threatForces(pc, ps, src) {
531
595
  .map(([player, p]) => {
532
596
  // #275 (b): a held bonus's border is sized for an untrusted estimate's figure, never below the estimate
533
597
  // (#293: under Local Deployment, what of that figure can reach these stacks).
534
- const deploy = truced === player
598
+ const full = truced === player
535
599
  ? 0
536
600
  : deployReaching(player, [...p.stacks.map((x) => x.id), ...(p.behind ?? [])], Math.max(pc.deployOf(player), untrustedAt(player, t)));
601
+ // #420: off its most valuable border, the stack plus its largest top-up seen.
602
+ const cap = oneBorder().capAt.get(t)?.get(player);
603
+ const deploy = cap !== undefined ? Math.min(full, cap) : full;
537
604
  const growth = truced === player ? 0 : p.growth;
538
605
  const movable = p.stacks.reduce((n, x) => n + x.movable, 0);
539
606
  const add = Math.max(deploy, growth);
@@ -643,6 +710,7 @@ export function threatForces(pc, ps, src) {
643
710
  return out;
644
711
  };
645
712
  return {
713
+ oneBorder,
646
714
  chainAt,
647
715
  stacksAt,
648
716
  forceAt,
@@ -775,6 +843,29 @@ export function borderThreats(pc, ps, input, src, forces) {
775
843
  rationale.push(`My commander's territory ${label(t)} is held against the worst case (#274), ~${b.threat}: ${w.players.length > 1 ? `players ${w.players.join(' and ')}` : `player ${w.players[0]}`}'s whole deploy, ~${w.deploy} (never below my own income), plus the ${w.stacks} movable armies ${w.players.length > 1 ? 'they have' : 'it has'} within two moves of it.`);
776
844
  }
777
845
  }
846
+ // #420: say where one opponent's full deploy is sized, and which borders take its top-up instead.
847
+ {
848
+ const { capAt, primary } = forces.oneBorder();
849
+ for (const [player, q] of [...src.quietOf].sort((a, b) => a[0] - b[0])) {
850
+ const sized = [...capAt].filter(([t, m]) => borders.has(t) && m.has(player)).map(([t]) => t).sort(byNum);
851
+ if (!sized.length)
852
+ continue;
853
+ rationale.push(`Player ${player} ${q.attacks ? `has attacked me on ${q.attacks} of ${q.contactTurns} contact turns, and not since it was read quiet` : `has not attacked me in ${q.contactTurns} contact turns`} (#420, P1 amended: a quiet neighbour): ${sized.map(label).join(', ')} ${sized.length === 1 ? 'is' : 'are'} sized at its stack beside ${sized.length === 1 ? 'it' : 'them'} plus its largest top-up seen, +${src.topUpOf.get(player)}, not its ~${pc.deployOf(player)} deploy, until its first attack on me.`);
854
+ }
855
+ for (const [player, top] of [...primary].sort((a, b) => a[0] - b[0])) {
856
+ // The deploy its most valuable border is sized for (under Local Deployment, what reaches it).
857
+ const at = borders.get(top);
858
+ const full = at && at.player === player && !at.chain && !at.commanderWorst ? at.deploy : pc.deployOf(player);
859
+ const rest = [...capAt]
860
+ .filter(([t, m]) => borders.has(t) && m.has(player) && m.get(player) < full)
861
+ .map(([t]) => t)
862
+ .sort(byNum);
863
+ if (!rest.length)
864
+ continue;
865
+ const one = rest.length === 1;
866
+ rationale.push(`Player ${player} deploys its ~${full} in one place (#420): its full deploy is sized only on its most valuable border, ${label(top)}; ${rest.map(label).join(', ')} ${one ? 'is' : 'are'} sized at its stack beside ${one ? 'it' : 'them'} plus its largest top-up seen, +${capAt.get(rest[0]).get(player)} (the most one of its stacks beside my land grew in a turn).`);
867
+ }
868
+ }
778
869
  // #199: say where a Multi-Attack chain sets a border's threat.
779
870
  for (const b of [...borders.values()].filter((x) => x.chain).sort((x, y) => y.chain.armies - x.chain.armies || x.id - y.id).slice(0, MAX_NAMED_REVEALS)) {
780
871
  const c = b.chain;
@@ -904,6 +995,11 @@ export function borderThreats(pc, ps, input, src, forces) {
904
995
  const used = track.turns.filter((x) => e.trackedTurns.includes(x.from));
905
996
  rationale.push(`Tracked income for player ${p}: ~${e.tracked}/turn (${incomeBasis(track)}): ${used.map((x) => `turn ${x.from} +${x.observed}`).join(', ')}, each observed deploy a lower bound under fog${e.coverage ? `, read from ${coverageText(e.coverage)}` : ''}; at least its visible base + bonuses ${track.visibleIncome}; used in place of the single-turn observed figure (warapp_track_opponents has the details).`);
906
997
  }
998
+ // #427: a card play the tracker read as income, taken out of its figure.
999
+ if (e.cardInTrack) {
1000
+ const c = e.cardInTrack;
1001
+ warnings.push(`Player ${p}'s tracked income of ${c.was} counts the Reinforcement card it played on turn ${c.turns.join(', ')}: ${c.income} without it (#427), so the card is counted once, on the clock, not carried as income.`);
1002
+ }
907
1003
  // #164: a Reinforcement card the clock says it may hold, on top of its income.
908
1004
  if (e.card)
909
1005
  warnings.push(`Player ${p} may hold a Reinforcement card from turn ${e.card.due} (the card clock${e.cardPlayed !== null ? `; it last played one on turn ${e.cardPlayed}` : ''}): +${e.card.armies} added to its deploy, ~${e.estimate} in all, until a deployment above its income is seen; one card at most is counted, though more may be in hand after a long time due.`);
@@ -930,6 +1026,13 @@ export function borderThreats(pc, ps, input, src, forces) {
930
1026
  const cut = e.newestCut;
931
1027
  if (cut && e.source !== 'exact' && cut.reading > income)
932
1028
  warnings.push(`Player ${p}'s newest turn (turn ${cut.from} → turn ${cut.to}) reads up to +${cut.reading} if the armies that arrived beside the fog were deploys (+${cut.observed} with those beyond twice the ~${cut.expected ?? '?'} it was expected to deploy read as moves); the estimate keeps ~${income} (${e.source === 'tracked' ? 'tracked' : e.source === 'prior' ? 'the fog prior' : 'its visible base + bonuses'}) because a stack walking in is not income (#123). To test the higher figure, pass enemy_deploy ${cut.reading} to warapp_check_plan.`);
1029
+ // #444: incomes other players stated scaled its fog prior down.
1030
+ if (e.stated && incomePrior?.stated) {
1031
+ const st = incomePrior.stated;
1032
+ const said = st.players.map((x) => `player ${x.id} states ${x.income}`).join(', ');
1033
+ const mid = e.stated.midpoint;
1034
+ warnings.push(`Player ${p}'s fog prior is scaled by the incomes stated in chat (known_income: ${said}), ${Math.round(st.ratio * 100) / 100}× my ${st.mine}: ~${e.stated.scaled} in place of ~${e.stated.full}, never below what is in view or tracked${mid !== null ? `; with no track it is sized at the midpoint ~${mid} between ~${e.stated.lower} and ~${e.stated.scaled} (#368)` : ''}.`);
1035
+ }
933
1036
  // #368: an income the user supplied replaces the estimate.
934
1037
  if (e.known) {
935
1038
  warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (the known income you supplied (known_income), in place of the estimate ~${e.known.was})${withCard}; a figure supplied is taken as it is, not checked against the board.`);
@@ -951,8 +1054,16 @@ export function borderThreats(pc, ps, input, src, forces) {
951
1054
  : t.lower === t.tracked
952
1055
  ? `~${t.lower} (the tracked figure)`
953
1056
  : `~${t.lower} (its visible income; the tracked ~${t.tracked})`;
1057
+ // #419: the upper bound's basis: the past winners' pace (map or format), the prior, or what it could earn.
1058
+ const upperIs = t.pace && t.upper === t.pace.figure
1059
+ ? t.pace.basis === 'map'
1060
+ ? `the median past winner's income after turn ${t.pace.afterTurn} on this map, ${t.pace.games} games of this format and settings (#419)`
1061
+ : `my income × ${t.pace.ratio}, the median past winner's pace against mine after turn ${t.pace.afterTurn} in this format, ${t.pace.games} games (fewer than 3 on this map) (#419)`
1062
+ : t.prior !== null && t.upper === Math.min(e.couldEarn, t.prior)
1063
+ ? 'the fog prior, not shrunk toward the track'
1064
+ : 'the most it could earn';
954
1065
  const sized = thin
955
- ? `it is sized between the lower bound ${lowerIs} and the upper bound ~${t.upper} (${t.prior !== null && t.upper === Math.min(e.couldEarn, t.prior) ? 'the fog prior, not shrunk toward the track' : 'the most it could earn'}): the midpoint ~${t.midpoint}, moved toward what the evidence gives, ~${t.toward}, as more of its frontier is read (${Math.round(t.weight * 100)}% of the way from that to the midpoint)`
1066
+ ? `it is sized between the lower bound ${lowerIs} and the upper bound ~${t.upper} (${upperIs}): the midpoint ~${t.midpoint}, moved toward what the evidence gives, ~${t.toward}, as more of its frontier is read (${Math.round(t.weight * 100)}% of the way from that to the midpoint)`
956
1067
  : `its lower bound is ${lowerIs.startsWith('~') ? lowerIs.slice(1) : lowerIs}, read from enough of its frontier to plan on it`;
957
1068
  warnings.push(`Enemy deploy estimate for player ${p}: ~${income} (thin evidence: ${why.join(' and ')}, so ${sized})${withCard}; it could deploy more.`);
958
1069
  continue;
@@ -19,6 +19,7 @@
19
19
  import { bfsDistances, neighborsOf } from '../graph.js';
20
20
  import { teammateAt } from './state.js';
21
21
  import { capStepRoom, truceKeep } from './relations.js';
22
+ import { breachLine, breachOf } from './vacated.js';
22
23
  /** The transfers (rule 6), with staging toward `staging` (#125) when the leftover saved toward a step. */
23
24
  export function transfers(pc, ps, book, threats, hd, caps, staging) {
24
25
  const { g, me, s, foe, territories: state, label, bonusName, mine, mineSet, unitsAt, toTake, noSplit, myCommanders } = pc;
@@ -187,6 +188,12 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
187
188
  }
188
189
  return border === undefined ? undefined : { border, front: at };
189
190
  };
191
+ // Rule 6's last target (owner, 2026-11-22; golden s246): with no enemy front and no territory not mine
192
+ // reachable without crossing a border the plan concedes — the last neutral taken, the enemy past those
193
+ // borders — a stack had no target and stood deep inside. It walks up behind the conceded borders on the way to
194
+ // the enemy instead: never into one (the plan gives it up), and one already beside one waits there (#367).
195
+ const behind = [...conceded].filter((c) => held.has(c) && distEnemyThrough.has(c));
196
+ const distBehind = bfsDistances(g, behind, { passable });
190
197
  // #125: staging. Idle armies on a territory facing no visible enemy — a border beside neutrals
191
198
  // included — walk one step toward the source of the capture the leftover saved toward, when
192
199
  // it is no farther than the enemy front; once there they help take it.
@@ -197,6 +204,9 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
197
204
  const n = avail.get(t);
198
205
  if (n <= 0 || locked.has(t) || t === st.from || conceded.has(t) || myCommanders.has(t))
199
206
  continue;
207
+ // #417: the breach force stays beside the land a static seat left (said by rule 6 below).
208
+ if (breachOf(pc, captured, t).length)
209
+ continue;
200
210
  if (neighborsOf(g, t).some((x) => isEnemy(x) || x === st.t))
201
211
  continue;
202
212
  if (moves.some((m) => m.from === t && m.kind === 'attack'))
@@ -250,10 +260,18 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
250
260
  distEnemyVia.get(t) < (distEnemy.get(t) ?? Infinity) &&
251
261
  distEnemyVia.get(t) <= (distAny.get(t) ?? Infinity) &&
252
262
  !neighborsOf(g, t).some((x) => isEnemy(x));
253
- const dist = via ? distEnemyVia : distEnemy.has(t) ? distEnemy : distAny;
263
+ const toConceded = !via && !distEnemy.has(t) && !distAny.has(t) && distBehind.has(t);
264
+ const dist = via ? distEnemyVia : distEnemy.has(t) ? distEnemy : toConceded ? distBehind : distAny;
254
265
  const n = avail.get(t);
255
266
  if (n <= 0 || locked.has(t))
256
267
  continue;
268
+ // #417, the breach force: beside land a static seat left, still untaken and cheap at the
269
+ // 2-defender price, the stack stays until it is taken (it attacks into it when a pass funds it).
270
+ const land = breachOf(pc, captured, t);
271
+ if (land.length) {
272
+ rationale.push(breachLine(pc, t, n, land));
273
+ continue;
274
+ }
257
275
  // My commander's territory next to an enemy at the start of the turn keeps its armies,
258
276
  // even when this turn's captures make it interior: a capture can still fail. So does one
259
277
  // next to a border the plan concedes (#121): the enemy takes it next, and then faces it.
@@ -269,6 +287,16 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
269
287
  const steps = neighborsOf(g, t)
270
288
  .filter((x) => mineSet.has(x) &&
271
289
  (via ? viaOk(x) : !conceded.has(x)) &&
290
+ // Behind a conceded border: up to the territory beside it, never into it — nor into a territory an attack
291
+ // leaves from this turn or one beside a rival at the start of the turn (an interior walk, not a strike's
292
+ // reinforcement: golden s1405's would have run before the strike that ends a player, taking its first slot).
293
+ (!toConceded ||
294
+ ((dist.get(x) ?? 0) >= 1 &&
295
+ !moves.some((m) => m.from === x && m.kind === 'attack') &&
296
+ !neighborsOf(g, x).some((y) => {
297
+ const o = state.get(y)?.owner;
298
+ return o?.kind === 'player' && o.playerId !== me && !teammateAt(pc, y);
299
+ }))) &&
272
300
  (dist.get(x) ?? Infinity) < d &&
273
301
  capStepRoom(pc, ps, t, x) > 0)
274
302
  .sort((a, b) => dist.get(a) - dist.get(b) || a - b);
@@ -310,6 +338,12 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
310
338
  arrived.set(step, (arrived.get(step) ?? 0) + k);
311
339
  // #260: say why a step goes toward a front past a conceded border, and what it heads for.
312
340
  let front = '';
341
+ // Rule 6's last target: say which conceded border the stack walks up behind, and why it stops beside it.
342
+ if (toConceded) {
343
+ const past = pastConceded(step);
344
+ if (past)
345
+ front = ` (no front is reachable without crossing a border the plan concedes: they walk up behind ${label(past.border)}, past which lies ${label(past.front)}, and wait beside it — once it falls the front is there)`;
346
+ }
313
347
  if (via) {
314
348
  const targets = attacksFrom(step);
315
349
  const beside = neighborsOf(g, step).filter((x) => !held.has(x) && isEnemy(x)).sort((a, b) => a - b);
@@ -0,0 +1,70 @@
1
+ // #439: a high-value single-territory bonus two moves away through a visible neutral is a two-turn
2
+ // completion. The planner plans one turn ahead, so such a bonus (a city, a capital) was never a bonus
3
+ // plan — its one member is not next to mine, so no capture reaches it — and the neutral in between
4
+ // lost to captures that complete nothing: live, two cities came a turn late (about 17 armies of income).
5
+ import { bonusTerritories } from '../bonuses.js';
6
+ import { neighborsOf } from '../graph.js';
7
+ import { teammateAt } from './state.js';
8
+ /** #439: the least value of a single-territory bonus worth staging toward two moves ahead. */
9
+ export const TWO_MOVE_MIN_VALUE = 5;
10
+ /**
11
+ * The single-territory bonuses of at least {@link TWO_MOVE_MIN_VALUE} two moves from mine through a
12
+ * visible neutral target, each with its cheapest neutral in between, best income per army first (then
13
+ * bonus id). The bonus territory is a visible neutral, or a fogged one the picking board showed as a
14
+ * neutral (`rememberedNeutrals`, costed at that size); never a player's, a teammate's, a truce's or one
15
+ * whose bonus was dropped. Kept only when the two captures repay their armies within the payback turns.
16
+ */
17
+ export function twoMoveStages(pc, tgt) {
18
+ const { g, territories: state, mineSet, costAt, completedOver, capturePaybackTurns: paybackTurns, opts } = pc;
19
+ const out = [];
20
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
21
+ if (b.value < TWO_MOVE_MIN_VALUE || tgt.bonusDropped.has(b.id))
22
+ continue;
23
+ const ts = bonusTerritories(g, b.id);
24
+ if (ts.length !== 1)
25
+ continue;
26
+ const member = ts[0];
27
+ if (mineSet.has(member) || tgt.fromMine.get(member) !== 2 || pc.truce.noTarget(member) || teammateAt(pc, member))
28
+ continue;
29
+ const st = state.get(member);
30
+ let memberCost = null;
31
+ if (st?.owner.kind === 'neutral' && st.armies !== null)
32
+ memberCost = costAt(member);
33
+ else if (!st || st.owner.kind === 'unknown' || st.armies === null) {
34
+ const was = opts.rememberedNeutrals?.get(member);
35
+ if (was !== undefined && st?.owner.kind !== 'player')
36
+ memberCost = costAt(member, was);
37
+ }
38
+ if (memberCost === null)
39
+ continue;
40
+ let best;
41
+ for (const via of [...neighborsOf(g, member)].sort((x, y) => x - y)) {
42
+ const tg = tgt.targets.get(via);
43
+ if (!tg || tg.enemy || state.get(via)?.owner.kind !== 'neutral')
44
+ continue;
45
+ const cost = tg.cost + memberCost;
46
+ const net = completedOver((x) => mineSet.has(x) || x === via || x === member, [via, member]).reduce((n, id) => n + g.bonusById.get(id).value, 0);
47
+ if (net <= 0 || cost > paybackTurns * net)
48
+ continue;
49
+ if (!best || cost < best.cost)
50
+ best = { bonusId: b.id, member, via, cost, net };
51
+ }
52
+ if (best)
53
+ out.push(best);
54
+ }
55
+ return out.sort((a, b) => b.net / b.cost - a.net / a.cost || a.bonusId - b.bonusId);
56
+ }
57
+ /**
58
+ * #439: take `s.via` toward its bonus (pass 3's capture: R3, rule 4d and the usual sizing), unless this
59
+ * turn's captures already took it or stand next to the bonus territory, or it lowers income. Says so.
60
+ */
61
+ export function stageTwoMove(pc, ps, s, gainWith, tryExpand) {
62
+ const { g, label, bonusName } = pc;
63
+ if (ps.captured.has(s.via) || neighborsOf(g, s.member).some((n) => ps.captured.has(n)) || gainWith([s.via]) < 0)
64
+ return;
65
+ const value = g.bonusById.get(s.bonusId).value;
66
+ const worth = s.net === value ? `+${value}` : `+${value}, net +${s.net}`;
67
+ if (!tryExpand(s.via, `stages bonus ${bonusName(s.bonusId)} (${worth}) two moves away (#439)`))
68
+ return;
69
+ ps.rationale.push(`Stage toward ${bonusName(s.bonusId)} (${worth}), two moves away: ${label(s.via)} now, ${label(s.member)} next turn — ${s.cost} armies over two turns (#439).`);
70
+ }
@@ -22,10 +22,132 @@
22
22
  // judged by rule 4d as before. Never a truce's covered territory, one my attacks failed on (#240) or
23
23
  // one lowering income; the capture spends what stands above its source's hold, as any.
24
24
  import { neighborsOf } from '../graph.js';
25
+ import { visibleState } from './shared.js';
25
26
  /** The end of every empty enemy capture's reason (#281, the owner's extension): tests and sweeps match on it. */
26
27
  export const CHEAP_EXPANSION = 'cheap expansion (#281)';
27
- /** A vacated territory costing at most this many armies to take is cheap enough to deny (#281). */
28
- export const VACATED_MAX_COST = 2;
28
+ /**
29
+ * #417 / #428: for each territory fogged on `board`, its sighting on the newest earlier board that showed
30
+ * its owner (`boards` in any order; boards that fog it too are skipped): the owner, and the armies that
31
+ * board showed (`null` when only its owner was shown). The one source of both {@link foggedLastSeen}
32
+ * (#417, who held it) and the planner's last-seen price (#428, `PlanOptions.lastSeen`), so they never
33
+ * read different boards. A GameFeed history board (`source: 'history'`) gives its owner only: no army count.
34
+ */
35
+ export function fogSightings(board, boards) {
36
+ const fogged = new Set(board.territories.filter((t) => t.owner.kind === 'unknown').map((t) => t.territoryId));
37
+ const out = new Map();
38
+ for (const b of [...boards].sort((x, y) => y.turn - x.turn))
39
+ for (const t of b.board.territories) {
40
+ if (!fogged.has(t.territoryId) || out.has(t.territoryId) || t.owner.kind === 'unknown')
41
+ continue;
42
+ // A GameFeed history board (unverified while the game is played) gives the owner, never a count.
43
+ const armies = b.source === 'history' ? null : (visibleState(t)?.armies ?? null);
44
+ out.set(t.territoryId, { owner: t.owner.kind === 'player' ? t.owner.playerId : null, armies });
45
+ }
46
+ return out;
47
+ }
48
+ /**
49
+ * #417: for each territory fogged on `board`, the player who held it on the newest earlier board that
50
+ * showed it (`boards` in any order; boards that fog it too are skipped). None when that sighting was
51
+ * neutral, or no earlier board showed it. A static seat's land stays costed as vacated however many
52
+ * turns it has been out of view, not only on the turn after vision was lost. The owners of {@link fogSightings}.
53
+ */
54
+ export function foggedLastSeen(board, boards) {
55
+ return ownersOf(fogSightings(board, boards));
56
+ }
57
+ /** #417: the players of a {@link fogSightings} map (its neutral sightings left out). */
58
+ export function ownersOf(sightings) {
59
+ const out = new Map();
60
+ for (const [t, s] of sightings)
61
+ if (s.owner !== null)
62
+ out.set(t, s.owner);
63
+ return out;
64
+ }
65
+ /** #428: the counts of a {@link fogSightings} map (a sighting that showed only the owner left out). */
66
+ export function countsOf(sightings) {
67
+ const out = new Map();
68
+ for (const [t, s] of sightings)
69
+ if (s.armies !== null)
70
+ out.set(t, { armies: s.armies, owner: s.owner });
71
+ return out;
72
+ }
73
+ /**
74
+ * A vacated territory costing at most this many armies to take is cheap enough to deny (#281). #417:
75
+ * raised from 2 to 3, what {@link VACATED_FOG_ARMIES} defenders cost at the default settings.
76
+ */
77
+ export const VACATED_MAX_COST = 3;
78
+ /**
79
+ * #417: the defenders a static seat's fogged territory is costed at. A seat deploys on its borders, so
80
+ * its interior stands on 0-2: its border stack in view says nothing about the land behind it.
81
+ */
82
+ export const VACATED_FOG_ARMIES = 2;
83
+ /**
84
+ * #417 (the breach force): `id` is land a static seat left (`vacated`) whose armies the fog hides now —
85
+ * owner hidden, or shown neutral (a seat's own, planned as a neutral) without its armies. It is priced at
86
+ * {@link VACATED_FOG_ARMIES} defenders. Never one the fog shows another player holding: that player got there first.
87
+ */
88
+ export function fogVacated(vacated, st, id) {
89
+ if (!vacated?.has(id))
90
+ return false;
91
+ if (!st || st.owner.kind === 'unknown')
92
+ return true;
93
+ return st.owner.kind === 'neutral' && st.armies === null;
94
+ }
95
+ /**
96
+ * #417 (the breach force): the land a static seat left beside `t` that is still untaken — not captured
97
+ * this turn, still neutral or hidden (never a live player's in view), in no negative bonus
98
+ * — and cheap at the 2-defender price: fogged ({@link fogVacated}), or costing at most {@link VACATED_MAX_COST}. By id.
99
+ */
100
+ export function breachOf(pc, captured, t) {
101
+ if (!pc.vacated.size)
102
+ return [];
103
+ return neighborsOf(pc.g, t)
104
+ .filter((x) => {
105
+ if (!pc.vacated.has(x) || pc.mineSet.has(x) || captured.has(x))
106
+ return false;
107
+ // Never a negative bonus's member (pass 3 never takes one): nothing to race for.
108
+ if ((pc.bonusesWith.get(x) ?? []).some((id) => (pc.g.bonusById.get(id)?.value ?? 0) < 0))
109
+ return false;
110
+ const st = pc.territories.get(x);
111
+ if (fogVacated(pc.vacated, st, x))
112
+ return true;
113
+ if (st?.owner.kind !== 'neutral')
114
+ return false;
115
+ const c = pc.costAt(x);
116
+ return c !== null && c <= VACATED_MAX_COST;
117
+ })
118
+ .sort((a, b) => a - b);
119
+ }
120
+ /**
121
+ * #417, the 1v1 race (owner decision of 2026-11-20): the land a static seat left that this turn's greedy
122
+ * step races for ahead of rule 0p.1's "expansion last" — a capture target next to mine, still untaken
123
+ * (neutral, or hidden: {@link fogVacated}), costing at most {@link VACATED_MAX_COST} (the 2-defender price
124
+ * included), never a negative bonus's member. Cheapest first, then by id. Pure.
125
+ */
126
+ export function raceTargets(pc, targets, captured) {
127
+ const out = [];
128
+ for (const t of [...pc.vacated.keys()].sort((a, b) => a - b)) {
129
+ const tg = targets.get(t);
130
+ if (!tg || tg.enemy || pc.mineSet.has(t) || captured.has(t) || tg.cost > VACATED_MAX_COST)
131
+ continue;
132
+ const st = pc.territories.get(t);
133
+ if (st?.owner.kind !== 'neutral' && !fogVacated(pc.vacated, st, t))
134
+ continue;
135
+ if ((pc.bonusesWith.get(t) ?? []).some((id) => (pc.g.bonusById.get(id)?.value ?? 0) < 0))
136
+ continue;
137
+ out.push({ t, cost: tg.cost });
138
+ }
139
+ return out.sort((a, b) => a.cost - b.cost || a.t - b.t);
140
+ }
141
+ /** #417: the 1v1 race's rationale line, said once when the greedy step has races. */
142
+ export function raceLine(pc, races) {
143
+ const left = [...new Set(races.map((r) => pc.vacated.get(r.t)))].sort((a, b) => a - b).map((p) => `player ${p}`).join(' and ');
144
+ return `1v1 race for vacated land (#417): ${races.map((r) => `${pc.label(r.t)} (${r.cost})`).join(', ')}, land ${left} left (out, no AI), ${races.length === 1 ? 'goes' : 'go'} ahead of the "expansion last" rule while it is up for taking — the opponent takes it otherwise; holds of my held bonuses and my commander still come first.`;
145
+ }
146
+ /** #417: the rationale line for a stack the breach force keeps beside land a static seat left. */
147
+ export function breachLine(pc, t, n, land) {
148
+ const left = [...new Set(land.map((x) => pc.vacated.get(x)))].sort((a, b) => a - b).map((p) => `player ${p}`).join(' and ');
149
+ return `Keep the ${n} idle armies on ${pc.label(t)}: the breach force beside ${land.map(pc.label).join(', ')}, land ${left} left (out, no AI), until it is taken (#417).`;
150
+ }
29
151
  /** The vacated territories that are denials (#281), by territory: {@link denialOf} over them, computed once. */
30
152
  export function denialsOf(pc) {
31
153
  const out = new Map();