@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
@@ -76,6 +76,10 @@
76
76
  // more than CONCEDE_FACTOR × its worth, so the captures go first) is held whole before the
77
77
  // first advance when what is left covers it (best worth per army first, never weighed
78
78
  // against spreading: `settleContested(true)`); the rest stays contested as before.
79
+ // #417, the race for vacated land: while a static seat's land is untaken, its captures
80
+ // costing at most VACATED_MAX_COST (`raceTargets`, the 2-defender price of its fogged land
81
+ // included) rank ahead of that rule — after the held-bonus units and my commander's hold,
82
+ // before every other candidate (`raceTier`); the contested units are settled before the first.
79
83
  // 2. FFA with two or more opponents left: no second front — a break (also from a held
80
84
  // border, rule 4a) against a player that can take no member of a bonus I hold next
81
85
  // turn and loses nothing to this turn's strike / finishing off is skipped when a
@@ -199,6 +203,20 @@
199
203
  // income every turn, breaks the opponent's biggest stack beside it soonest (its owner
200
204
  // deploying there every turn), when that is not the border holding the most armies and
201
205
  // breaks sooner than it ("Strike stack on … (#201): no border can strike this turn; …").
206
+ // #421: outside a 1v1 (not a siege, not No-Split, not `defend`), a stockpile on a flat income —
207
+ // my armies in view at least STOCKPILE_TURNS turns of my income while `incomeTrend` is flat —
208
+ // builds the same stack facing the opponent beside me whose visible armies mine outnumber
209
+ // STOCKPILE_LEAD× (fewest first, then id; never an income estimate), never on my commander's
210
+ // territory, and spends it as above ("Stockpile (#421): …").
211
+ // #421, the strike share: in contact on a flat income (a stack built as above), STRIKE_SHARE
212
+ // of the income is held out of captures for the stack (holds keep their exact need first),
213
+ // unless that lowers next income (`planShare`) ("Strike share (#421): …").
214
+ // #421, the break spend: on the pile (`pc.pile`), rule 4a runs the break of the strongest
215
+ // opponent's cheapest visible bonus before every other capture, never skipped as a second
216
+ // front ("Stockpile spend (#421): …").
217
+ // #421, the all-in completion: on the pile, each contested bonus is planned all-in through
218
+ // #298's push (`planPushed`, `PlanInput.stockpileAllIn`), kept only when taken whole
219
+ // ("Stockpile all-in (#421): …").
202
220
  // 3d. Decided (#201): given `options.outlook` (#178) reporting winning or losing, the game is
203
221
  // decided, and every payback test (PAYBACK_TURNS everywhere it appears in these rules)
204
222
  // counts the turns it has left instead: the loser's strength over the winner's income a
@@ -243,6 +261,16 @@
243
261
  // per-territory income, plus what the estimate holds beyond every such pool, with a
244
262
  // warning). An enemy commander counts in
245
263
  // the expected attack too (rule 1h's near miss, kept garrisons).
264
+ // #420 (owner decision of 2026-11-20, "One opponent's deploy"): an opponent deploys its income in
265
+ // one place, so its full deploy sizes only its single most valuable border of mine (by protected
266
+ // value, then its movable armies beside it, then id); its other borders of mine are sized at its
267
+ // stacks beside them plus its largest top-up seen (`OpponentTrack.topUp`: the most one of its
268
+ // stacks beside my land grew in one turn on the tracker's live boards), never above the full deploy
269
+ // (`oneBorder` in plan/threats.ts, read by `forceAt`), with a "deploys its ~D in one place (#420)"
270
+ // line. Not with no top-up seen (no track), under `enemyDeploy`, on my commander's territory, for an
271
+ // untrusted estimate (#275) there, or for an opponent facing a single border of mine.
272
+ // A quiet neighbour (`PlanInput.quiet`, #420's P1 amendment: 10+ contact turns at an attack rate of
273
+ // 0.1 or less, no attack on me since) has every border so sized, its most valuable included.
246
274
  // enemyDeploy is estimated per opponent (`enemyDeployEstimates`): base
247
275
  // income (the larger of MinimumArmyBonus and, with BonusArmyPer on, its
248
276
  // visible territories / BonusArmyPer) plus the bonuses that player
@@ -292,7 +320,14 @@
292
320
  // guard or beside no other player), never a hold an order `moves` does not carry touched (a
293
321
  // Transfer Only, Attack Only or percentage order in `sent`, a card play in `cards`; orders cached
294
322
  // before those were kept read nothing), and on a turn an opponent may have played a Bomb
295
- // (`bombPossibleOn`, `PlannerSettings.bombFrom`) after taking out half the hold, rounded up. A
323
+ // (`bombPossibleOn`, `PlannerSettings.bombFrom`) after taking out half the hold, rounded up. #418
324
+ // (owner decision of 2026-11-20: proof may always raise an estimate): a capture with every source
325
+ // army in view (`captureFloor`) bounds it from below too — what stands on the target plus the
326
+ // attacker its last defender surely killed, and at least the fewest armies that kill every defender
327
+ // however the attack was split, beyond what its stacks beside the target could send (less the
328
+ // guard) — counted when the target was a neutral or mine, every neighbour showed its owner and its
329
+ // own their armies, no other player borders it, Multi-Attack is off, and (beside or out of my land)
330
+ // my orders are known in full and none touches it; a Bomb it may have played halves the defenders. A
296
331
  // capture of a neutral in view beside the fog that needed more attackers (`fewestAttackersToTake`)
297
332
  // than its stacks in view sent (`unseenAttackers`) reads what stands there beyond those as deploy
298
333
  // within #123's bound, the rest a move out of the fog. Its stacks in view beside a capture, hidden
@@ -343,6 +378,10 @@
343
378
  // its lower bound (visible, tracked, a rising trend's next step) and its upper bound (the fog prior,
344
379
  // else what it could earn), moved toward the lower bound as the coverage nears LOW_COVERAGE
345
380
  // (`thinEvidence`); the warning names both bounds. Unmeasured.
381
+ // #419 (owner decision of 2026-11-20): with the fog prior on, that upper bound is the larger of the
382
+ // prior and the pace past winners set at this turn (`PlanGameContext.mapPace`, `FogPace`: this map's
383
+ // median winner over 3+ games of the format and settings, else my income × the format's median winner ÷
384
+ // mine), capped and scaled as the prior; the warning names the basis (`thinEvidence.pace`).
346
385
  // In a 1v1 too, so it trades #119's prior back toward tracked figures #119 found 2-3x low:
347
386
  // PRIOR_EVIDENCE_TURNS (4) is unmeasured against a finished 1v1.
348
387
  // #164, exact income: under a fog setting that shows every owner (`OWNERS_SHOWN_FOG`: No, Light
@@ -465,10 +504,20 @@
465
504
  // (fully visible, fewer territories than mine, deploy below my income) that
466
505
  // threatens it now is never conceded economically (the rationale says so once its
467
506
  // hold is deployed); under `balanced` its hold goes first.
507
+ // #420 (owner decision of 2026-11-20, "Total hold cap", `holdCapOf` in plan/holds.ts): plain holds
508
+ // take at most HOLD_CAP_EVEN (50%) of my income when even or ahead and HOLD_CAP_BEHIND (70%) when
509
+ // the profile reads me behind (rounded down). A held bonus's own gate (rule 1h's units) and my
510
+ // commander's hold (rule 1k) are funded first, outside it, and count nothing toward it. A plain hold
511
+ // past it — rule 1a's `defend` triage, rule 4a's greedy hold, a unit member judged alone, a deferred
512
+ // hold — is conceded with a "cannot be held within the hold cap (#420 …)" line (its armies may still
513
+ // attack out); a hold that breaks its one threat (rule 4a's hold-and-break) runs first, as a capture,
514
+ // and counts. The leftover's revival may still hold a capped border after all. Off under a `defend`
515
+ // goal the caller gave, and with `options.holdCap: false` (tests of earlier hold rules use it).
468
516
  // 1a. Triage (every goal). Each threatened border's protected value is the sum
469
- // of my complete bonuses containing it, plus incomplete bonuses containing it
470
- // that I would lose all access to without it, plus (#122) its share of every other
471
- // incomplete bonus containing it that I am building — value × the members I hold ÷ its
517
+ // of my complete bonuses containing it, plus (#122) its share of every
518
+ // incomplete bonus containing it that I am building (#425: one it is my only way into
519
+ // included — it used to count whole, whatever stood on the rest; now its share, and nothing
520
+ // when an enemy holds or roams a member; a fogged member keeps it, owner decision 2026-11-22) — value × the members I hold ÷ its
472
521
  // size, one decimal, when every missing member is a visible neutral and finishing it passes
473
522
  // rule 4's economy tests (PAYBACK_TURNS, WASTELAND_FACTOR); #298: or when the missing members
474
523
  // are visible neutrals and visible foe territories, one of them a foe's movable stack beside the
@@ -780,6 +829,11 @@
780
829
  // absorbed by its own neighbours' growth) and is now cheaper to take than it
781
830
  // was; never under `expand`/`defend`). Fogged or unknown neighbours are never attacked — they
782
831
  // produce a warning.
832
+ // #430 (owner decision of 2026-11-22): under `balanced`, the opponents' territories that retake
833
+ // a bonus I held in full on `previousBoard` are bonus targets too, in every format, when the retake
834
+ // completes it this turn (every missing member in view, beside mine), costs at most RETAKE_VALUE_TURNS
835
+ // (5) × its value, and the profile does not read me behind; it ranks as any completion, so a stronger hold
836
+ // funds first (plan/targets.ts, `retakeMembers`).
783
837
  // 3. Capture cost (#126): the fewest armies whose exact `winChance` reaches the capture's
784
838
  // chance — certain (chance 1) means every roll and rounding takes it: `armiesToTake` at 0%
785
839
  // luck under straight rounding, one army more where weighted-random rounding could round a
@@ -894,7 +948,10 @@
894
948
  // scored by its net worth (rule 4c), not its value, in every test above.
895
949
  // One owner per bonus (PLAN-TEAMS C3.3): a positive bonus with a member my teammate visibly
896
950
  // holds is not scored at all (a bonus pays only the player holding every member), focused or
897
- // not (a focus on it is ignored with a warning); its other members are plain expansion. The
951
+ // not (a focus on it is ignored with a warning); its other members are plain expansion — unless
952
+ // (#435) the Gift card is in play (`game.cardsInPlay`) and I alone hold the most members: then it is mine to work, its other members scored and
953
+ // advanced, the teammate's left for them to hand over (a Gift), never completable while they
954
+ // stand; an uneconomic one is still skipped as before. The
898
955
  // plan's `team.sharedBonuses` (plan/team.ts) lists each such bonus I hold members of too, and
899
956
  // who holds the most (`nearer`), from the start-of-turn board. No-team plans are unchanged.
900
957
  // Team focus (PLAN-TEAMS C3.4): with my teammates' entered orders read (V5, unverified), a
@@ -970,7 +1027,13 @@
970
1027
  // bonuses this turn's earlier captures completed share the same next income (their added
971
1028
  // needs count too). Then: under `balanced`/`defend` the capture is
972
1029
  // refused (warning "… indefensible …: not completed"); under `expand` and
973
- // `complete-bonus` it is made with a warning. Under `balanced`/`defend` a bonus's
1030
+ // `complete-bonus` it is made with a warning. #422, the payback exemption: a completion whose
1031
+ // losses — the attackers its captures into the bonus lose this turn plus the armies left on the
1032
+ // members that would fall — are at most the bonus's value is made anyway (a "Complete bonus …
1033
+ // (#422)" line): held at the end of this turn, the bonus pays that value next turn even if it
1034
+ // falls after. Such a bonus keeps no conceded border (rule 1c), gets no #122 garrison or #265
1035
+ // weak-member call, and the leftover never rides an attack onto a member it may lose (#288).
1036
+ // Under `balanced`/`defend` a bonus's
974
1037
  // score is value / (capture cost + DEFENSE_DISCOUNT × that defence cost).
975
1038
  // 4d. Frontier cost (#71). Every capture pays for the frontier it adds, in armies: for each
976
1039
  // territory it touches (the capture and its held neighbours), its border cost after minus
@@ -989,7 +1052,7 @@
989
1052
  // would then exceed the next income and the start-of-turn hold cost (in rule 4e's
990
1053
  // contact/late fallback it is a cost instead, #114); a warning ("Frontier grows faster than
991
1054
  // income") names it, and also fires when the plan's frontier ends so. #281: never a territory a
992
- // static seat left (rule 0s) that costs at most VACATED_MAX_COST and borders a live opponent's
1055
+ // static seat left (rule 0s) that costs at most VACATED_MAX_COST (3, #417: what 2 defenders cost) and borders a live opponent's
993
1056
  // stack able to take it with what stands there (`denialOf`): that border comes either way, so
994
1057
  // it is let through, a line ("Take … though it faces player …") says so, and pass 3 ranks it by
995
1058
  // capture cost plus the frontier without its own hold need, less the denial (1 + PAYBACK_TURNS ×
@@ -998,6 +1061,10 @@
998
1061
  // may fall to 0 or below; a plain capture's never goes below one army), and a member of an
999
1062
  // uneconomic bonus of mine is still eligible for it. Each denial is judged once per plan
1000
1063
  // (`denialsOf`, `Targets.denials`). It spends only what stands above its source's hold (#121).
1064
+ // #417, the breach force: land a static seat left whose armies the fog hides is a target at
1065
+ // VACATED_FOG_ARMIES defenders (`fogVacated`, read by `defenceAt`), pass 3 takes vacated land outside
1066
+ // a negative bonus even in an uneconomic bonus, and rule 6 keeps the idle armies beside such land still
1067
+ // untaken and cheap (`breachOf`) until it is taken.
1001
1068
  // #281, the owner's extension (2026-11-16; guard off, not under No-Split, `balanced`/`defend`):
1002
1069
  // a live opponent's own territory beside mine in view at 0 (no special unit) whose owner holds
1003
1070
  // no positive bonus it is in (#165 breaks those) and that was not mine on `previousBoard` (#276
@@ -1024,6 +1091,10 @@
1024
1091
  // rule 4e's contact fallback, where 4d is only a cost (#114), runs it too. The plan reports `gates` (each gate's
1025
1092
  // need and armies, conceded ones marked, the summed need, what stands on them, the per-gate deficit, the next
1026
1093
  // income and the shortfall) and warns when its own captures open a gate the income cannot hold.
1094
+ // #426 (draft): a no-loss neutral (its defenders kill none of my attackers, `noLossNeutral`) is taken
1095
+ // by pass 3 even in an uneconomic bonus, and rule 4d lets one through when only the fog faces its new
1096
+ // border and the hold it adds is at most 1× the next income (`outgrows`, not in a 1v1); a stack idle two
1097
+ // turns beside one is warned of (plan/free-capture.ts).
1027
1098
  // 4e. Never stand still (#104, #107; every goal but `complete-bonus`, after pass 3). A plan that
1028
1099
  // makes no capture at all (no expansion, break, finishing off or strike) in the opening or
1029
1100
  // expansion phase takes one neutral capture toward a positive bonus (net > 0, never a negative
@@ -1142,12 +1213,20 @@
1142
1213
  // this income (armies to finish, counting the members I hold, over the income — and never
1143
1214
  // fewer than its depth, #125: the farthest missing member's distance from what I hold, since
1144
1215
  // a capture's armies attack no further this turn; "N turns (N layers deep)"), so a farther
1145
- // bonus gets only armies the closer ones cannot use; bonuses as close as each other keep the
1146
- // score order. Given `previousBoard`, a bonus advanced last turn (a member captured since) keeps
1147
- // priority unless another is strictly closer; the rationale lists the order and says which
1148
- // kept or gave way. Armies to finish count every missing member: a fogged one at its bonus's
1149
- // costliest visible missing member (counted as free before, the figure jumped when it came into
1150
- // view), named in every "N armies to finish".
1216
+ // bonus gets only armies the closer ones cannot use; bonuses as close as each other go by the
1217
+ // income per army of every bonus their capture completes (#438: each bonus whose missing members
1218
+ // are all among its own, net values summed, over the score's cost; a "complete together" line
1219
+ // names it when another as close competes), then — given `previousBoard` — a bonus advanced last
1220
+ // turn (a member captured since), then the score order; the rationale lists the order and says
1221
+ // which advanced bonus kept or gave way. Armies to finish count every missing member: a fogged one
1222
+ // a static seat left at its #417 price (below); else (#428) at its last sighting on my boards
1223
+ // (`options.lastSeen`, unless the fog shows another owner now), else its picking-board size
1224
+ // (#201), else — its owner hidden too — the game's neutral size (`settings.neutralArmies`), else at
1225
+ // its bonus's costliest visible missing member (counted as free before, the figure jumped when it
1226
+ // came into view), named in every "N armies to finish". #439 (plan/two-move.ts): a single-territory bonus of
1227
+ // at least TWO_MOVE_MIN_VALUE two moves away through a visible neutral is a two-turn completion
1228
+ // (cost: that neutral plus the territory); the neutral in between is a `stage` candidate under
1229
+ // `balanced` (net over both costs, ranked as an advance), else taken before the advances.
1151
1230
  // 3b. One surplus per territory (#121). A border that holds at the start of the turn (its armies
1152
1231
  // beat its visible threat, rule 1) and is not conceded keeps what holds it, as my commander's
1153
1232
  // territory does (rule 1k): a capture from it spends only its armies above that, plus deploys
@@ -1185,7 +1264,10 @@
1185
1264
  // first, only that one lands before the opponent's first; when I am known to move first, the
1186
1265
  // warning is "holds only if my first order is …"). The warning names why the leftover made no
1187
1266
  // deploy there (too little left, Local Deployment, No-Split sending the stack with its order)
1188
- // only when that was the reason. Then it goes to the held
1267
+ // only when that was the reason. #440: before the margins below, the territory with the most
1268
+ // protected value that carries a single-territory bonus of at least DETERRENT_MIN_VALUE
1269
+ // (DETERRENT_VALUE_RATIO × the borders' most, an opponent within two steps) gets a deterrent guard: taking it needs more than
1270
+ // COMFORT_MARGIN × that opponent's deploy (plan/leftover.ts `deterrentGuard`). Then it goes to the held
1189
1271
  // border with the highest protected value still short of COMFORT_MARGIN × its threat (counting
1190
1272
  // armies withdrawn into it) — but first (#121), when it would go to such margins (no strike stack;
1191
1273
  // #215 review: judged and run before the worse-order deploys above), a conceded border the leftover can make hold is held after all, from what is left once
@@ -1262,6 +1344,10 @@
1262
1344
  // S …, the C sent leave L, above the H that hold it …"); a capture removes rule 4e's
1263
1345
  // stand-still warning, and a refused try leaves no line.
1264
1346
  // 6. Idle armies on interior territories transfer one step toward the front,
1347
+ // When no front and no territory not mine is reachable without crossing a border the plan concedes (the
1348
+ // last neutral taken, the enemy past those borders; owner 2026-11-22, golden s246), an idle interior stack
1349
+ // walks up behind the conceded borders on the way to the enemy — never into one, never into a territory an
1350
+ // attack leaves from this turn or one beside a rival at the start of the turn — and waits beside them (#367).
1265
1351
  // only into territories held at the start of the turn and never into, or
1266
1352
  // measured through, a conceded border
1267
1353
  // (unless `idleTransfers` is off: the planner's own switch, not war.app's AllowTransferOnly,
@@ -1368,13 +1454,17 @@
1368
1454
  // warning ("Breaking player … without eliminating it invites retaliation"): what it has left is
1369
1455
  // likeliest aimed at whoever broke it. In a 1v1 it attacks me anyway, so no warning there.
1370
1456
  // Wastelands (#167, `settings.wastelands`): a fogged missing member of a bonus is costed at the
1371
- // costliest visible missing member plus the expected surcharge of being a wasteland
1457
+ // neutral size or costliest visible missing member (#428) plus the expected surcharge of being a wasteland
1372
1458
  // (ceil(count ÷ the map's territories × (a wasteland's capture cost − that))), with a rationale line.
1373
1459
  // #201: given `options.rememberedNeutrals` (the picking board's neutrals, which warapp_plan_picks
1374
1460
  // and warapp_submit_picks' preview keep per game), a fogged missing member the picking board showed
1375
1461
  // as a neutral (and whose owner the fog does not show as a player now) is costed at that size
1376
1462
  // instead, never attacked, with a rationale line ("… fogged now, was a neutral of N on the picking
1377
- // board (#201)").
1463
+ // board (#201)"). #417: a fogged member a static seat left (`BoardCtx.vacated`: shown owner-only as
1464
+ // its, or fogged now and the seat's when last seen — `foggedLastSeen`, the newest earlier board that
1465
+ // showed it, else `previousBoard`) is costed at VACATED_FOG_ARMIES (2) defenders, never above the costliest member in view (its border stack says nothing about the
1466
+ // land behind it), with a "… was player N's (out, no AI) … (#417)" line; it raises no other fogged
1467
+ // member's figure and gets no wasteland surcharge.
1378
1468
  // 7. Move order (#127; every goal, last). Orders zigzag — the first mover's 1st, the other's
1379
1469
  // 1st and 2nd, the first mover's 2nd and 3rd, … — so `moves` is scheduled
1380
1470
  // (`scheduleMoves`, src/analysis/schedule.ts), earliest first: the one order Order Priority
@@ -1577,20 +1667,25 @@ import { BREAK_WEIGHT, MIN_EXPANSION_SHARE, PLAIN_EXPANSION_LOSS, SECOND_FRONT_L
1577
1667
  import { emptyPlan, noteEstimates, planContext } from './plan/estimates.js';
1578
1668
  import { neutralizeSeats, seatTerritories, staticSeats } from './static-seats.js';
1579
1669
  import { deployBook } from './plan/orders.js';
1580
- import { holdsPhase } from './plan/holds.js';
1670
+ import { holdsPhase, priorOnlyHold } from './plan/holds.js';
1581
1671
  import { threatsPhase } from './plan/threats.js';
1672
+ import { applyShortGates } from './plan/horizon.js';
1582
1673
  import { targetsPhase } from './plan/targets.js';
1583
1674
  import { capturesPhase } from './plan/captures.js';
1584
1675
  import { completedMembers } from './plan/completed.js';
1585
1676
  import { chooseStrikeStack, leadStrikes, spendStrikeStack, strikesPhase } from './plan/strike.js';
1586
- import { afterLeftoverCaptures, plainEconomy, plainEligible } from './plan/after-leftover.js';
1677
+ import { contestedBonuses } from './plan/stockpile.js';
1678
+ import { warnIdleBesideFree } from './plan/free-capture.js';
1679
+ import { afterLeftoverCaptures, onlyNoLoss, plainEconomy, plainEligible } from './plan/after-leftover.js';
1587
1680
  import { fundFromSecondSizing } from './plan/second-sizing.js';
1588
1681
  import { leftoverDeploy } from './plan/leftover.js';
1589
1682
  import { fillSecondLine, guardOffRaids } from './plan/guard-off.js';
1590
1683
  import { neverStandStill } from './plan/stand-still.js';
1591
- import { addEmptyEnemyTargets, dropEmptyEnemyTargets, plainOrderCosts, tryEmptyEnemy, withoutTransit } from './plan/vacated.js';
1684
+ import { stageTwoMove, twoMoveStages } from './plan/two-move.js';
1685
+ import { addEmptyEnemyTargets, dropEmptyEnemyTargets, foggedLastSeen, plainOrderCosts, raceLine, raceTargets, tryEmptyEnemy, withoutTransit } from './plan/vacated.js';
1592
1686
  import { spendUnderCap } from './plan/cap-spend.js';
1593
1687
  import { attackOutOfConceded } from './plan/conceded-out.js';
1688
+ import { doomedConcededOut } from './plan/doomed-out.js';
1594
1689
  import { captureInsteadOfHold } from './plan/capture-instead.js';
1595
1690
  import { transfers } from './plan/transfers.js';
1596
1691
  import { scheduleOrders, strikeOrderPriority } from './plan/move-order.js';
@@ -1598,11 +1693,13 @@ import { commanderMoveWarning, placeCommanderMove, reserveCommanderMove } from '
1598
1693
  import { finishPlan, reportExpected, reportOffence } from './plan/report.js';
1599
1694
  import { newPlanState } from './plan/state.js';
1600
1695
  import { teamFocusLine, teamReport } from './plan/team.js';
1601
- import { applyBorderCaps, armiesFreed, partnerFronts, reportBreakLosses, reportTruce, trucePass } from './plan/relations.js';
1696
+ import { applyBorderCaps, armiesFreed, partnerFronts, reportBreakLosses, reportTruce, trucePass, warnTruceNeutrals } from './plan/relations.js';
1602
1697
  export * from './plan/shared.js';
1698
+ export * from './plan/observe.js';
1699
+ export * from './plan/deploy-estimates.js';
1603
1700
  export { alliesOf, planEnemyEstimates } from './plan/estimates.js';
1604
1701
  export { TRUCE_RELAX_VALUE } from './plan/relations.js';
1605
- export { SPREAD_INCOME_SLACK, SPREAD_LAST_TURN, SPREAD_TERRITORIES } from './plan/targets.js';
1702
+ export { HOLDS_BONUS_MIN_VALUE, SPREAD_INCOME_SLACK, SPREAD_LAST_TURN, SPREAD_TERRITORIES } from './plan/targets.js';
1606
1703
  /** Passes that refine the cut set (#172) before falling back to the plan that cuts nothing. */
1607
1704
  const TWO_STEP_PASSES = 3;
1608
1705
  /** Passes that learn which territories in between end held (#172) before none is counted held. */
@@ -1662,6 +1759,12 @@ function withoutStaticSeats(input, seats) {
1662
1759
  for (const t of input.board.territories)
1663
1760
  if (t.owner.kind === 'player' && seats.has(t.owner.playerId))
1664
1761
  vacated.set(t.territoryId, t.owner.playerId);
1762
+ // #417: and the fogged ones last seen held by a seat — on the newest earlier board that showed them
1763
+ // (`foggedLastSeen`), not only the previous board, so the pricing outlasts the turn vision was lost.
1764
+ const lastSeen = input.foggedLastSeen ?? foggedLastSeen(input.board, input.previousBoard ? [{ turn: 0, board: input.previousBoard }] : []);
1765
+ for (const [t, p] of lastSeen)
1766
+ if (seats.has(p))
1767
+ vacated.set(t, p);
1665
1768
  return {
1666
1769
  ...input,
1667
1770
  ...(vacated.size ? { vacated } : {}),
@@ -1675,6 +1778,60 @@ function withoutStaticSeats(input, seats) {
1675
1778
  }
1676
1779
  /** #298: per plan, the all-in pushes its pass sized (plan/targets.ts), by bonus id. */
1677
1780
  const allInOutcome = new WeakMap();
1781
+ /**
1782
+ * #298's attempt memory ({@link planAttempts}), then #421's stockpile all-in completions: on a pile, the
1783
+ * contested bonuses a push could complete are planned all-in, those it does not take whole left out.
1784
+ */
1785
+ function planPushed(input) {
1786
+ const plan = planAttempts(input);
1787
+ const candidates = pileAllInOutcome.get(plan);
1788
+ if (!candidates?.length)
1789
+ return plan;
1790
+ // #421 (owner decision, 2026-11-20): on a stockpile, every contested bonus whose missing members can all be
1791
+ // taken this turn — each an opponent holds sized for its owner's deploy, the push within the payback horizon ×
1792
+ // its value — is completed all-in. One the plan does not take whole is left out (no drop: it is no failed
1793
+ // attempt), and a push that would cost a #298 verdict its plan is not made.
1794
+ const missingOf = (id) => {
1795
+ const at = new Map(input.board.territories.map((t) => [t.territoryId, t.owner]));
1796
+ return bonusTerritories(input.graph, id).filter((t) => {
1797
+ const o = at.get(t);
1798
+ return !(o?.kind === 'player' && o.playerId === input.me);
1799
+ });
1800
+ };
1801
+ const pushed = new Set(candidates);
1802
+ for (;;) {
1803
+ const next = planAttempts({ ...input, stockpileAllIn: new Set(pushed) });
1804
+ const tries = allInOutcome.get(next);
1805
+ const taken = new Set(next.expected.captures);
1806
+ const failing = [...pushed].filter((id) => !tries?.get(id)?.feasible || missingOf(id).some((t) => !taken.has(t)));
1807
+ if (!failing.length) {
1808
+ if (JSON.stringify(next.bonusPush ?? []) !== JSON.stringify(plan.bonusPush ?? []))
1809
+ return plan;
1810
+ const name = (id) => `${input.graph.bonusById.get(id).name} (#${id})`;
1811
+ for (const id of [...pushed].sort((a, b) => a - b)) {
1812
+ const t = tries.get(id);
1813
+ next.rationale.push(`Stockpile all-in (#421): bonus ${name(id)} is contested and my armies stand idle on a flat income, so every missing member is taken this turn, each one another player holds sized for its owner's deploy: ${t.cost} armies, within the cap of ${t.cap} (the payback horizon × its value).`);
1814
+ }
1815
+ return next;
1816
+ }
1817
+ for (const id of failing)
1818
+ pushed.delete(id);
1819
+ if (!pushed.size)
1820
+ return plan;
1821
+ }
1822
+ }
1823
+ /** #421: per plan, the contested bonuses a stockpile could push all-in (only on a plan made without such a push). */
1824
+ const pileAllInOutcome = new WeakMap();
1825
+ /** Merge the #421 stockpile pushes (`input.stockpileAllIn`) into #298's push and focus. */
1826
+ function withPush(input, allIn, dropped) {
1827
+ const ids = new Set([...allIn, ...(input.stockpileAllIn ?? [])]);
1828
+ const focus = [...new Set([...(input.options?.focusBonusIds ?? []), ...ids])];
1829
+ return {
1830
+ ...input,
1831
+ bonusPush: { allIn: ids, dropped },
1832
+ options: { ...input.options, ...(ids.size ? { focusBonusIds: focus } : {}) },
1833
+ };
1834
+ }
1678
1835
  /**
1679
1836
  * #298: the plan with the attempt memory's verdicts (plan/bonus-attempts.ts). A bonus whose completion
1680
1837
  * failed on two consecutive turns is pushed all-in (focused, every missing member sized for its owner's
@@ -1682,14 +1839,15 @@ const allInOutcome = new WeakMap();
1682
1839
  * member, it is planned again with that bonus dropped for DROP_TURNS turns. With no verdict, the plan
1683
1840
  * is exactly what it was without the memory.
1684
1841
  */
1685
- function planPushed(input) {
1842
+ function planAttempts(input) {
1686
1843
  const turn = input.turn;
1844
+ const none = new Set();
1687
1845
  if (!input.bonusAttempts || turn === undefined)
1688
- return planSettled(input);
1846
+ return planShare(input.stockpileAllIn?.size ? withPush(input, none, none) : input);
1689
1847
  const judged = judgeAttempts(input.bonusAttempts, turn, input.graph, input.board, input.me);
1690
1848
  const verdicts = bonusVerdicts(judged, turn).filter((v) => input.graph.bonusById.has(v.bonusId));
1691
1849
  if (!verdicts.length)
1692
- return planSettled(input);
1850
+ return planShare(input.stockpileAllIn?.size ? withPush(input, none, none) : input);
1693
1851
  const entries = new Map();
1694
1852
  for (const v of verdicts)
1695
1853
  if (v.kind === 'dropped')
@@ -1714,12 +1872,7 @@ function planPushed(input) {
1714
1872
  let plan;
1715
1873
  for (;;) {
1716
1874
  const ids = new Set(allIn.map((v) => v.bonusId));
1717
- const focus = [...new Set([...(input.options?.focusBonusIds ?? []), ...ids])];
1718
- plan = planSettled({
1719
- ...input,
1720
- bonusPush: { allIn: ids, dropped: new Set([...entries.keys()]) },
1721
- options: { ...input.options, ...(ids.size ? { focusBonusIds: focus } : {}) },
1722
- });
1875
+ plan = planShare(withPush(input, ids, new Set([...entries.keys()])));
1723
1876
  const tries = allInOutcome.get(plan);
1724
1877
  const taken = new Set(plan.expected.captures);
1725
1878
  const failing = allIn.flatMap((v) => {
@@ -1769,6 +1922,24 @@ function planPushed(input) {
1769
1922
  plan.bonusPush = push;
1770
1923
  return plan;
1771
1924
  }
1925
+ /** #421: per plan, the strike share its pass held out of captures (absent when none). */
1926
+ const shareOutcome = new WeakMap();
1927
+ /**
1928
+ * #421 (owner decision, 2026-11-20): the strike share is held out of captures, ahead of comfort margins,
1929
+ * but never at the cost of next income — when the plan without it earns more next turn (a completion the
1930
+ * share starves), that plan stands and says why.
1931
+ */
1932
+ function planShare(input) {
1933
+ const plan = planSettled(input);
1934
+ const share = shareOutcome.get(plan);
1935
+ if (!share)
1936
+ return plan;
1937
+ const without = planSettled({ ...input, options: { ...input.options, strikeShare: false } });
1938
+ if (without.expected.nextIncome <= plan.expected.nextIncome)
1939
+ return plan;
1940
+ without.rationale.push(`Strike share (#421) not held this turn: holding ${share} of the income out of captures for the strike stack would lower next income from ${without.expected.nextIncome} to ${plan.expected.nextIncome} (a capture it starves completes a bonus).`);
1941
+ return without;
1942
+ }
1772
1943
  function planSettled(input) {
1773
1944
  const plan = planRun(input, false);
1774
1945
  const bare = runOutcome.get(plan);
@@ -1846,11 +2017,14 @@ function planPass(input, pass) {
1846
2017
  // As the deploy book reads it, restated here so TypeScript narrows `pools` wherever it is tested.
1847
2018
  const local = pools !== null && pools.bonuses.length > 0;
1848
2019
  // ---- 1t. threat trend, 1. defence (plan/threats.ts) ----
1849
- const threats = threatsPhase(pc, ps, input);
2020
+ const threats = threatsPhase(pc, ps, input, book.valueOf);
2021
+ // #432: a 1v1 whose gates are short at the start judges its captures on a shorter payback horizon from here on
2022
+ // (every capture test after this reads `pc.capturePaybackTurns`; holds keep `paybackTurns`).
2023
+ applyShortGates(pc, ps, threats);
1850
2024
  const { growthOf, reinforcementAt, borders, facing, borderAt } = threats;
1851
2025
  // ---- 1. holds, #172, 1h, 1b, 1c, #122 garrisons (plan/holds.ts) ----
1852
2026
  const hd = holdsPhase(pc, ps, book, threats, pass);
1853
- const { acting, conceded, concedeUnaffordable, floorOrConcede, fundNearMiss, fundUnit, garrisonCompleted, heldBorders, heldStack, hold, holds, keepFor, kept, keptShort, leftFor, mayComplete, mayHold, noteRecent, pendingLocks, reconsider, settleContested, twoStepBound, twoStepKeep, uneconomic, units, withdraw, } = hd;
2027
+ const { acting, conceded, concedeUnaffordable, floorOrConcede, fundNearMiss, fundUnit, garrisonCompleted, heldBorders, heldStack, hold, holds, keepFor, kept, keptShort, leftFor, mayComplete, mayHold, noteRecent, pendingLocks, reconsider, settleContested, twoStepBound, twoStepKeep, uneconomic, units, withdraw, overCap, chargeCap, concedeCapped, } = hd;
1854
2028
  // ---- 2. targets, 4d. frontier cost, bonus scoring, #101 (plan/targets.ts) ----
1855
2029
  const tgt = targetsPhase(pc, ps, input, threats, hd);
1856
2030
  const { breakable, counterAt, targets, leadSteps, landScoreCost, offence, skipOffence, plans, ratio, committing, byCloseness, retakeChecks, retakeWarning, } = tgt;
@@ -1862,6 +2036,8 @@ function planPass(input, pass) {
1862
2036
  // ---- R3, No-Split, capture helper, 3a. combined, passes 1 and 2 (plan/captures.ts) ----
1863
2037
  const caps = capturesPhase(pc, ps, pass, book, threats, hd, tgt);
1864
2038
  const { strikes, worstCase, defendersAt, tryCapture, snapshot, complete, tryExpand, advance } = caps;
2039
+ /** #439: single-territory bonuses two moves away, each with its neutral in between. */
2040
+ const stages = twoMoveStages(pc, tgt);
1865
2041
  // ---- 1e. finish off an opponent, 1s. strike an enemy commander, #165 guard-off breaks (plan/strike.ts) ----
1866
2042
  const { struck } = strikesPhase(pc, ps, book, threats, hd, tgt, caps);
1867
2043
  // ---- #276: guard off — free retakes and raids one step deeper (plan/guard-off.ts) ----
@@ -1948,7 +2124,9 @@ function planPass(input, pass) {
1948
2124
  return enemyDeploy;
1949
2125
  return Math.max(...[...byPlayer].map(([p, movable]) => movable + deployOf(p)));
1950
2126
  };
1951
- const rank = { unit: 0, hold: 0, complete: 1, advance: 2, break: 3, counter: 3 };
2127
+ const rank = { unit: 0, hold: 0, complete: 1, advance: 2, stage: 2, race: 2, break: 3, counter: 3 };
2128
+ /** A capture that completes no bonus this turn: an advance, a two-move stage (#439), a 1v1 race (#417), a break or a counter. */
2129
+ const completesNothing = (c) => c.kind === 'advance' || c.kind === 'stage' || c.kind === 'race' || c.kind === 'break' || c.kind === 'counter';
1952
2130
  const candidates = [];
1953
2131
  const deferred = [];
1954
2132
  /** #215: pending holds this step conceded and unlocked, whose armies may still attack out. */
@@ -1968,8 +2146,12 @@ function planPass(input, pass) {
1968
2146
  * this turn's captures may complete stays locked until they are known: rule 1c keeps it for a
1969
2147
  * completed bonus, and an attack out would have emptied it first.
1970
2148
  */
1971
- const concedePending = (t, room) => {
1972
- concedeUnaffordable(t, room);
2149
+ const concedePending = (t, room, capped = false) => {
2150
+ // #420: past the hold cap, said as such.
2151
+ if (capped)
2152
+ concedeCapped(t);
2153
+ else
2154
+ concedeUnaffordable(t, room);
1973
2155
  if (heldBorders.has(t.id))
1974
2156
  return;
1975
2157
  if (mayComplete(t.id))
@@ -1997,6 +2179,31 @@ function planPass(input, pass) {
1997
2179
  candidates.push({ kind: 'complete', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => complete(p)) });
1998
2180
  candidates.push({ kind: 'advance', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => advance(p)) });
1999
2181
  }
2182
+ // #439: a single-territory bonus two moves away is a two-turn completion: its neutral in between
2183
+ // competes as an advance does, on the income per army of both captures.
2184
+ for (const st of stages)
2185
+ candidates.push({ kind: 'stage', score: st.net / st.cost, cost: st.cost, id: st.bonusId, value: st.net, focus: false, borders: 0, target: st.via, run: spend(() => stageTwoMove(pc, ps, st, gainWith, tryExpand)) });
2186
+ // #417, the 1v1 race: while a static seat's land is still untaken, its cheap captures rank ahead of
2187
+ // rule 0p.1's "expansion last" (`ahead` below); held-bonus gates and my commander's hold go first.
2188
+ const races = oneVsOne ? raceTargets(pc, targets, captured) : [];
2189
+ if (races.length)
2190
+ rationale.push(raceLine(pc, races));
2191
+ for (const r of races)
2192
+ candidates.push({
2193
+ kind: 'race',
2194
+ score: 0,
2195
+ cost: r.cost,
2196
+ id: r.t,
2197
+ value: 0,
2198
+ focus: false,
2199
+ borders: 0,
2200
+ target: r.t,
2201
+ run: spend(() => {
2202
+ if (captured.has(r.t))
2203
+ return;
2204
+ withoutTransit(pc, tgt, r.t, () => tryExpand(r.t, `races for land player ${pc.vacated.get(r.t)} left (out, no AI), ahead of the 1v1 "expansion last" rule (#417)`));
2205
+ }),
2206
+ });
2000
2207
  // Capturing a member of a breakable bonus: what survives it, and whether that holds next turn.
2001
2208
  // A break is sized to land (#72): its score leaves out what holding it would need.
2002
2209
  const breakOption = (t) => {
@@ -2065,6 +2272,7 @@ function planPass(input, pass) {
2065
2272
  const before = ps.budget;
2066
2273
  noteRecent(t);
2067
2274
  deploy(t.id, t.holdCost);
2275
+ chargeCap(t.holdCost);
2068
2276
  if (!tryCapture(n, breakReason(b), { from: t.id, keep: avail.get(t.id) })) {
2069
2277
  // Refused (R3: it would complete a bonus I cannot hold next turn): just hold.
2070
2278
  rationale.push(`Deploy ${t.holdCost} to ${label(t.id)} so it holds (protects +${t.value}): ${heldStack(t)} need ${toTake(t.have + t.units + t.holdCost)} to take, above the ~${t.threat} threat.`);
@@ -2088,6 +2296,32 @@ function planPass(input, pass) {
2088
2296
  });
2089
2297
  return true;
2090
2298
  };
2299
+ /** The member a break of `b` takes: its cheapest visible member (#72: a break only has to land), then the least frontier, then id. */
2300
+ const breakOptionOf = (b) => bonusTerritories(g, b.bonusId)
2301
+ .filter((t) => targets.has(t))
2302
+ .map(breakOption)
2303
+ .sort((a, b) => a.cost - b.cost || a.scoreCost - b.scoreCost || a.t - b.t)[0];
2304
+ // #421 (owner decision, 2026-11-20): on a stockpile (`pc.pile`) the turn spends by breaking the strongest
2305
+ // opponent's cheapest visible bonus (every member in view: never a probable one) — ahead of every other
2306
+ // capture, never skipped as a second front. The strongest is the highest income estimate, then id.
2307
+ const pileBreak = (() => {
2308
+ if (!pc.pile)
2309
+ return undefined;
2310
+ const strongest = pc.estimateList
2311
+ .filter((e) => foe(e.playerId))
2312
+ .sort((a, b) => incomeOfPlayer(b.playerId) - incomeOfPlayer(a.playerId) || a.playerId - b.playerId)[0]?.playerId;
2313
+ if (strongest === undefined)
2314
+ return undefined;
2315
+ return breakable
2316
+ .filter((b) => b.player === strongest && !b.probable)
2317
+ .flatMap((b) => {
2318
+ const o = breakOptionOf(b);
2319
+ return o ? [{ b, o }] : [];
2320
+ })
2321
+ .sort((x, y) => x.o.cost - y.o.cost || y.b.value - x.b.value || x.b.bonusId - y.b.bonusId)[0];
2322
+ })();
2323
+ if (pileBreak)
2324
+ rationale.push(`Stockpile spend (#421): ${pc.pile.my} armies of mine stand on the board, ${pc.pile.turns} turns of my flat ${income} income, so the turn tries first to break the strongest opponent's cheapest visible bonus, player ${pileBreak.b.player}'s ${bonusName(pileBreak.b.bonusId)} (+${pileBreak.b.value}) through ${label(pileBreak.o.t)} (${pileBreak.o.cost} armies), before any other capture.`);
2091
2325
  for (const b of breakable) {
2092
2326
  // Its cheapest visible member (#72: a break only has to land), then the least frontier, then id.
2093
2327
  const options = bonusTerritories(g, b.bonusId)
@@ -2108,18 +2342,24 @@ function planPass(input, pass) {
2108
2342
  taken: false,
2109
2343
  why: breakReason(b),
2110
2344
  });
2345
+ const spendIt = pileBreak?.b === b;
2111
2346
  // An FFA skips a second-front break, but only one the plan could pay for is named as
2112
- // skipped: an unaffordable one is dropped quietly (it could not run either way).
2113
- if (opensSecondFront(b, score) && !affordable(o.t)) {
2347
+ // skipped: an unaffordable one is dropped quietly (it could not run either way). #421: never the stockpile's.
2348
+ if (spendIt) {
2349
+ // #421: the stockpile's break runs whatever its front.
2350
+ }
2351
+ else if (opensSecondFront(b, score) && !affordable(o.t)) {
2114
2352
  skipOffence(o.t, 'not affordable this turn');
2115
2353
  continue;
2116
2354
  }
2117
- if (secondFront(b, score)) {
2355
+ if (!spendIt && secondFront(b, score)) {
2118
2356
  skipOffence(o.t, `no second front in an FFA: player ${b.player} threatens no bonus of mine`);
2119
2357
  continue;
2120
2358
  }
2359
+ const reasonOf = (r) => (spendIt ? `${r} — the stockpile's spend on the strongest opponent (#421)` : r);
2121
2360
  candidates.push({
2122
2361
  kind: 'break',
2362
+ ...(spendIt ? { spend: true } : {}),
2123
2363
  score,
2124
2364
  cost: o.cost,
2125
2365
  id: b.bonusId,
@@ -2137,7 +2377,7 @@ function planPass(input, pass) {
2137
2377
  const was = worstCase.get(o.t);
2138
2378
  targets.set(o.t, { ...tg, cost: o.cost });
2139
2379
  worstCase.set(o.t, defenceAt(o.t) + reinforcementAt(o.t));
2140
- if (!tryCapture(o.t, `${breakReason(b)}, sized to land against player ${b.player}'s ~${reinforcementAt(o.t)} deploy (#201: I lead this free-for-all)`)) {
2380
+ if (!tryCapture(o.t, reasonOf(`${breakReason(b)}, sized to land against player ${b.player}'s ~${reinforcementAt(o.t)} deploy (#201: I lead this free-for-all)`))) {
2141
2381
  targets.set(o.t, tg);
2142
2382
  if (was === undefined)
2143
2383
  worstCase.delete(o.t);
@@ -2146,7 +2386,7 @@ function planPass(input, pass) {
2146
2386
  return;
2147
2387
  }
2148
2388
  }
2149
- else if (!tryCapture(o.t, breakReason(b)))
2389
+ else if (!tryCapture(o.t, reasonOf(breakReason(b))))
2150
2390
  return;
2151
2391
  ps.anchor ??= moves[moves.length - 1].from;
2152
2392
  warnRetake(b, o);
@@ -2184,7 +2424,7 @@ function planPass(input, pass) {
2184
2424
  }
2185
2425
  expansionLeft = candidates.length;
2186
2426
  // Under rule 0p.1 an advance never outranks a hold, so it never defers one either.
2187
- topValue = Math.max(0, ...candidates.filter((c) => !(oneVsOne && c.kind === 'advance')).map((c) => c.value));
2427
+ topValue = Math.max(0, ...candidates.filter((c) => c.kind !== 'stage' && !(oneVsOne && c.kind === 'advance')).map((c) => c.value));
2188
2428
  let floor = expansionLeft ? Math.ceil(MIN_EXPANSION_SHARE * income) : 0;
2189
2429
  // #167: a multi-turn view of the main front. Adapting in contact, the expansion share stands only
2190
2430
  // when the front is no worse than a stand-off without those armies: my biggest stack facing the
@@ -2240,9 +2480,13 @@ function planPass(input, pass) {
2240
2480
  rationale.push(`Front outlook (#167): ${pair}, ${f.outcome === 'breaks' ? `my stack breaks it on turn ${f.turn}` : 'it is a stand-off'} even with ${share} of income going to expansion (${f.pinnedHolds ? `the border pins ${f.pinned}` : `not even my whole ${every} keeps the border`}): the expansion share stands.${wholeText}`);
2241
2481
  }
2242
2482
  }
2243
- for (const t of holds)
2483
+ for (const t of holds) {
2484
+ const b = borders.get(t.id);
2485
+ const prior = t.recentFrom === undefined && !t.critical && b ? priorOnlyHold(pc, b, t) : null;
2244
2486
  candidates.push({
2245
2487
  kind: 'hold',
2488
+ ...(prior !== null ? { prior } : {}),
2489
+ ...(t.critical ? { critical: true } : {}),
2246
2490
  // A border just taken from a weak opponent is held first: conceding it hands it back.
2247
2491
  score: t.recentFrom !== undefined ? Infinity : t.worth / t.holdCost,
2248
2492
  cost: t.holdCost,
@@ -2254,8 +2498,12 @@ function planPass(input, pass) {
2254
2498
  // Already garrisoned for a bonus this turn completed (#122).
2255
2499
  if (heldBorders.has(t.id))
2256
2500
  return;
2501
+ // #420: a hold that breaks its one threat is a capture first (its hold still counts toward the cap);
2502
+ // any other plain hold past the total hold cap is conceded (its armies may still attack out).
2257
2503
  if (holdAndBreak(t))
2258
2504
  return;
2505
+ if (overCap(t))
2506
+ return concedePending(t, roomAt(t.id), true);
2259
2507
  const pending = expansionLeft > 0 && t.worth < topValue && t.recentFrom === undefined ? Math.max(0, floor - expansionSpent) : 0;
2260
2508
  const room = roomAt(t.id);
2261
2509
  // #215: conceded, its armies may attack out (rule 1a) in the passes still to run.
@@ -2269,6 +2517,7 @@ function planPass(input, pass) {
2269
2517
  hold(t);
2270
2518
  },
2271
2519
  });
2520
+ }
2272
2521
  // A conceded unit's members, judged on their own now (rule 1a, against what is left).
2273
2522
  const singleNow = (t, quiet) => {
2274
2523
  if (t.critical)
@@ -2287,6 +2536,8 @@ function planPass(input, pass) {
2287
2536
  concedeUnaffordable(t, room);
2288
2537
  return;
2289
2538
  }
2539
+ if (overCap(t))
2540
+ return concedeCapped(t, quiet);
2290
2541
  hold(t);
2291
2542
  heldBorders.add(t.id);
2292
2543
  };
@@ -2332,13 +2583,28 @@ function planPass(input, pass) {
2332
2583
  }
2333
2584
  // PLAN-TEAMS C3.4: a capture of a player my teammate attacks this turn ranks above an equal one.
2334
2585
  const teamFocused = (c) => Number(c.owner !== undefined && pc.teamFocus.has(c.owner));
2586
+ /** #417: the 1v1 race's tier: 0 a held bonus's gate or my commander's hold, 1 a race, 2 any other. */
2587
+ const raceTier = (c) => (c.kind === 'unit' || (c.kind === 'hold' && c.critical) ? 0 : c.kind === 'race' ? 1 : 2);
2335
2588
  const ahead = (a, b) => Number(b.focus) - Number(a.focus) ||
2589
+ // #420: a hold sized only on the fog prior ranks after every capture.
2590
+ Number(a.prior !== undefined) - Number(b.prior !== undefined) ||
2591
+ // #417, the 1v1 race: held-bonus gates and my commander's hold, then the races, then everything else.
2592
+ (races.length ? raceTier(a) - raceTier(b) : 0) ||
2336
2593
  // #201: ahead, every held bonus is held for the worst case before any capture (said below).
2337
2594
  (holdPasses === 'worst' ? Number(b.kind === 'unit') - Number(a.kind === 'unit') : 0) ||
2338
- (oneVsOne ? Number(a.kind === 'advance') - Number(b.kind === 'advance') : 0) ||
2595
+ (oneVsOne ? Number(a.kind === 'advance' || a.kind === 'stage') - Number(b.kind === 'advance' || b.kind === 'stage') : 0) ||
2339
2596
  b.score - a.score;
2340
2597
  const after = (a, b) => a.cost - b.cost || a.borders - b.borders || rank[a.kind] - rank[b.kind] || a.id - b.id;
2341
2598
  candidates.sort((a, b) => ahead(a, b) || teamFocused(b) - teamFocused(a) || after(a, b));
2599
+ for (const c of candidates) {
2600
+ if (c.prior === undefined)
2601
+ continue;
2602
+ const passed = candidates.filter((d) => d.kind !== 'hold' && d.kind !== 'unit' && d.score < c.score);
2603
+ if (!passed.length)
2604
+ continue;
2605
+ const b = borders.get(c.id);
2606
+ rationale.push(`Hold ${label(c.id)} after the captures (#420): it needs ${c.cost} only against player ${b.player}'s ~${b.deploy}, the fog prior; against the stacks beside it plus the ~${c.prior} the evidence gives, it holds as it stands.`);
2607
+ }
2342
2608
  if (pc.teamFocus.size)
2343
2609
  for (const [i, c] of candidates.entries()) {
2344
2610
  if (!teamFocused(c))
@@ -2359,6 +2625,13 @@ function planPass(input, pass) {
2359
2625
  slots.forEach((i, k) => (candidates[i] = sorted[k]));
2360
2626
  }
2361
2627
  }
2628
+ // #421: a stockpile spend runs before every other capture; the holds keep their places.
2629
+ if (candidates.some((c) => c.spend)) {
2630
+ const spends = candidates.filter((c) => c.spend);
2631
+ const rest = candidates.filter((c) => !c.spend);
2632
+ const at = rest.findIndex((c) => c.kind !== 'hold' && c.kind !== 'unit');
2633
+ candidates.splice(0, candidates.length, ...(at < 0 ? [...rest, ...spends] : [...rest.slice(0, at), ...spends, ...rest.slice(at)]));
2634
+ }
2362
2635
  // A held-bonus unit that pays for itself is funded before any capture that completes
2363
2636
  // no bonus (an advance or a break, unless focused): at the first such capture, every
2364
2637
  // unit still pending runs first, with the completions that outscore the weakest of them.
@@ -2434,11 +2707,11 @@ function planPass(input, pass) {
2434
2707
  // #215, rule 0p.1: an advance ranks below every hold, a contested held bonus's included
2435
2708
  // (#118 lets the captures go first, but in a 1v1 in contact not one that completes nothing):
2436
2709
  // live, a +4 bonus's one border was left to fall while 15 went to a bonus 47 armies from done.
2437
- if (oneVsOne && c.kind === 'advance' && !c.focus && !contestedDue) {
2710
+ if (oneVsOne && (c.kind === 'advance' || c.kind === 'stage' || c.kind === 'race') && !c.focus && !contestedDue) {
2438
2711
  contestedDue = true;
2439
2712
  settleContested(true);
2440
2713
  }
2441
- if ((c.kind === 'advance' || c.kind === 'break' || c.kind === 'counter') && !c.focus && !unitsDue) {
2714
+ if (completesNothing(c) && !c.focus && !unitsDue) {
2442
2715
  unitsDue = true;
2443
2716
  // Those waiting for the expansion share outscore everything still to run.
2444
2717
  for (const u of waiting.splice(0))
@@ -2457,7 +2730,7 @@ function planPass(input, pass) {
2457
2730
  // completes nothing: when this one leaves too little for a hold still waiting, it is undone,
2458
2731
  // the waiting holds are funded first, and it runs again on what is left (if it still fits).
2459
2732
  const owed = deferred.filter((t) => !heldBorders.has(t.id) && !conceded.has(t.id));
2460
- if ((c.kind === 'advance' || c.kind === 'break' || c.kind === 'counter') && !c.focus && owed.length) {
2733
+ if (completesNothing(c) && !c.focus && owed.length) {
2461
2734
  const restore = snapshot();
2462
2735
  const spent = expansionSpent;
2463
2736
  const left = expansionLeft;
@@ -2470,7 +2743,7 @@ function planPass(input, pass) {
2470
2743
  expansionSpent = spent;
2471
2744
  expansionLeft = left;
2472
2745
  for (const t of owed)
2473
- if (t.holdCost <= roomAt(t.id)) {
2746
+ if (t.holdCost <= roomAt(t.id) && !overCap(t)) {
2474
2747
  rationale.push(`Hold ${label(t.id)} now after all: the capture that would have gone first completes no bonus and would leave too little to hold it later.`);
2475
2748
  hold(t);
2476
2749
  heldBorders.add(t.id);
@@ -2488,8 +2761,8 @@ function planPass(input, pass) {
2488
2761
  if (heldBorders.has(t.id))
2489
2762
  continue;
2490
2763
  const room = roomAt(t.id);
2491
- if (t.holdCost > room)
2492
- concedePending(t, room);
2764
+ if (t.holdCost > room || overCap(t))
2765
+ concedePending(t, room, t.holdCost <= room);
2493
2766
  else
2494
2767
  hold(t);
2495
2768
  }
@@ -2519,6 +2792,8 @@ function planPass(input, pass) {
2519
2792
  // #272: a conceded border attacks out for a free step into a bonus before it withdraws (and
2520
2793
  // before rule 1c re-values the borders, so one whose bonus this completes is kept).
2521
2794
  attackOutOfConceded(pc, ps, book, hd, tgt, caps);
2795
+ // #431: a doomed conceded stack with nowhere to withdraw to attacks out or merges instead of standing.
2796
+ doomedConcededOut(pc, ps, book, hd, tgt, caps, threats);
2522
2797
  reconsider();
2523
2798
  withdraw();
2524
2799
  }
@@ -2529,6 +2804,12 @@ function planPass(input, pass) {
2529
2804
  complete(p);
2530
2805
  garrisonCompleted();
2531
2806
  }
2807
+ // #439: the neutral in between toward a single-territory bonus two moves away, before any advance.
2808
+ if (goal !== 'complete-bonus')
2809
+ for (const st of stages) {
2810
+ stageTwoMove(pc, ps, st, gainWith, tryExpand);
2811
+ garrisonCompleted();
2812
+ }
2532
2813
  for (const p of byCloseness) {
2533
2814
  advance(p);
2534
2815
  garrisonCompleted();
@@ -2540,6 +2821,9 @@ function planPass(input, pass) {
2540
2821
  // before rule 1c re-values the borders, so one whose bonus this completes is kept).
2541
2822
  if (acting)
2542
2823
  attackOutOfConceded(pc, ps, book, hd, tgt, caps);
2824
+ // #431: as under `balanced`.
2825
+ if (acting)
2826
+ doomedConcededOut(pc, ps, book, hd, tgt, caps, threats);
2543
2827
  reconsider();
2544
2828
  if (acting)
2545
2829
  withdraw();
@@ -2582,16 +2866,20 @@ function planPass(input, pass) {
2582
2866
  const reach = Math.max(...neighborsOf(g, t.id).filter((x) => avail.has(x)).map((x) => (avail.get(x) ?? 0) + roomAt(x)));
2583
2867
  if (reach >= t.cost)
2584
2868
  rationale.push(worth > 0
2585
- ? `Do not expand into ${label(t.id)}: it adds +${worth} a turn and loses ~${lost} armies, more than ${paybackTurns} turns of it pay back.`
2869
+ ? `Do not expand into ${label(t.id)}: it adds +${worth} a turn and loses ~${lost} armies, more than ${pc.capturePaybackTurns} turns of it pay back.`
2586
2870
  : `Do not expand into ${label(t.id)}: it adds no income and loses ~${lost} armies (more than ${PLAIN_EXPANSION_LOSS}), in no bonus worth completing.`);
2587
2871
  continue;
2588
2872
  }
2589
2873
  }
2590
2874
  // #281 × #282: a denial is never sourced from the territory my commander walks from (its transit hold).
2875
+ // #426: a no-loss capture in a bonus too costly to finish says why it is taken all the same.
2876
+ const reason = onlyNoLoss(pc, tgt, t.id)
2877
+ ? `expands territory: a no-loss capture (its defenders kill none of the attackers; what lands stays mine), so the cost of finishing its bonus does not stop it (#426)`
2878
+ : 'expands territory';
2591
2879
  if (tgt.denials.has(t.id))
2592
- withoutTransit(pc, tgt, t.id, () => tryExpand(t.id, 'expands territory'));
2880
+ withoutTransit(pc, tgt, t.id, () => tryExpand(t.id, reason));
2593
2881
  else
2594
- tryExpand(t.id, 'expands territory');
2882
+ tryExpand(t.id, reason);
2595
2883
  }
2596
2884
  dropEmptyEnemyTargets(ps, tgt, empties);
2597
2885
  }
@@ -2690,7 +2978,8 @@ function planPass(input, pass) {
2690
2978
  /** Territories locked before the leftover deploy: holds, kept and standing borders, withdrawals. */
2691
2979
  const holdLocked = new Set(locked);
2692
2980
  /** A territory the plan has not given up (or gave up but whose garrison may still hold it). */
2693
- const open = (id) => !conceded.has(id) || mayHold.has(id);
2981
+ // #431: a border a doomed stack left gets no leftover, whatever else it is.
2982
+ const open = (id) => (!conceded.has(id) || mayHold.has(id)) && !ps.doomedOut.has(id);
2694
2983
  /** Armies that stay on a border after its deploys, outgoing moves and incoming withdrawals. */
2695
2984
  const stays = (id) => avail.get(id) + guardAt(id) + (incoming.get(id) ?? 0);
2696
2985
  // ---- #265: a combined capture leaves armies on a weak member of a bonus it completes (plan/captures.ts) ----
@@ -3082,6 +3371,8 @@ function planPass(input, pass) {
3082
3371
  placeCommanderMove(pc, ps);
3083
3372
  // ---- expected, frontier, two-step holds, gambled and shared borders (plan/report.ts) ----
3084
3373
  const expected = reportExpected(pc, ps, book, threats, hd, tgt, caps);
3374
+ // #426: a stack idle two turns beside a no-loss neutral (plan/free-capture.ts), report only.
3375
+ warnIdleBesideFree(pc, ps, tgt, input.previousBoard);
3085
3376
  // ---- offence report (#72), the warnings after the deploys, "Not attacking" (#167) (plan/report.ts) ----
3086
3377
  const { sentAt } = reportOffence(pc, ps, book, threats, hd, tgt, holdLocked, leadSpareFor);
3087
3378
  // ---- 7. schedule the moves (#127), the exits (#179), Order Priority (plan/move-order.ts) ----
@@ -3102,6 +3393,8 @@ function planPass(input, pass) {
3102
3393
  const team = teamReport(pc, { ps, threats, hd, deploys: plan.deploys });
3103
3394
  if (team)
3104
3395
  plan.team = team;
3396
+ // #457: a neutral taken beside a truce partner may read as a breach to it (plan/relations.ts).
3397
+ warnTruceNeutrals(pc, plan);
3105
3398
  if (truceReport) {
3106
3399
  // T6: what a break would cost, against the plan's final orders (plan/relations.ts).
3107
3400
  reportBreakLosses(pc, truceReport.relations, plan);
@@ -3138,6 +3431,16 @@ function planPass(input, pass) {
3138
3431
  runOutcome.set(plan, { bareSteps: [...caps.bareTaken].filter(gone).sort(byNum), held, unheld });
3139
3432
  if (tgt.allInTries.size)
3140
3433
  allInOutcome.set(plan, tgt.allInTries);
3434
+ if (pc.strikeShare > 0)
3435
+ shareOutcome.set(plan, pc.strikeShare);
3436
+ // #421: on a stockpile, the contested bonuses this plan does not complete that an all-in push could (planPushed).
3437
+ if (pc.pile && !input.stockpileAllIn) {
3438
+ const done = new Set(plan.expected.bonusesCompleted);
3439
+ const pushed = new Set([...(input.bonusPush?.allIn ?? []), ...(input.bonusPush?.dropped ?? [])]);
3440
+ const ids = contestedBonuses(g, state, mineSet, foe).filter((id) => !done.has(id) && !pushed.has(id));
3441
+ if (ids.length)
3442
+ pileAllInOutcome.set(plan, ids);
3443
+ }
3141
3444
  // #274: a plan that walks my commander says so first.
3142
3445
  if (pc.commanderAt?.retreat)
3143
3446
  plan.warnings.unshift(commanderMoveWarning(pc.commanderAt.retreat, label));