@chrischall/warapp-mcp 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +133 -8
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +177 -17
  7. package/dist/analysis/card-threats.js +126 -14
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/decision-replay.js +279 -0
  13. package/dist/analysis/decision-truth.js +146 -0
  14. package/dist/analysis/finished-game.js +62 -3
  15. package/dist/analysis/game-lessons.js +15 -10
  16. package/dist/analysis/hold-diff.js +3 -1
  17. package/dist/analysis/income-trend.js +38 -0
  18. package/dist/analysis/intel.js +75 -0
  19. package/dist/analysis/opens.js +64 -0
  20. package/dist/analysis/opponent-profile.js +121 -10
  21. package/dist/analysis/opponents.js +246 -20
  22. package/dist/analysis/outlook.js +360 -15
  23. package/dist/analysis/picks.js +91 -12
  24. package/dist/analysis/plan/after-leftover.js +4 -1
  25. package/dist/analysis/plan/bonus-attempts.js +105 -0
  26. package/dist/analysis/plan/capture-instead.js +116 -0
  27. package/dist/analysis/plan/captures.js +49 -7
  28. package/dist/analysis/plan/conceded-out.js +13 -2
  29. package/dist/analysis/plan/estimates.js +203 -30
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +110 -9
  32. package/dist/analysis/plan/jabs.js +113 -0
  33. package/dist/analysis/plan/leftover.js +393 -8
  34. package/dist/analysis/plan/orders.js +76 -4
  35. package/dist/analysis/plan/relations.js +135 -2
  36. package/dist/analysis/plan/report.js +69 -3
  37. package/dist/analysis/plan/second-sizing.js +133 -0
  38. package/dist/analysis/plan/shared.js +279 -27
  39. package/dist/analysis/plan/siege.js +303 -0
  40. package/dist/analysis/plan/stand-still.js +9 -5
  41. package/dist/analysis/plan/state.js +8 -0
  42. package/dist/analysis/plan/stockpile.js +104 -0
  43. package/dist/analysis/plan/strike.js +39 -7
  44. package/dist/analysis/plan/targets.js +256 -110
  45. package/dist/analysis/plan/threats.js +148 -10
  46. package/dist/analysis/plan/transfers.js +57 -6
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/planner.js +527 -49
  50. package/dist/analysis/profile.js +13 -2
  51. package/dist/analysis/since-last.js +18 -5
  52. package/dist/analysis/stress.js +8 -2
  53. package/dist/board.js +36 -2
  54. package/dist/bonus-attempt-store.js +55 -0
  55. package/dist/build-id.js +106 -0
  56. package/dist/bundle.js +54138 -41059
  57. package/dist/cards.js +7 -5
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/chat.js +35 -1
  60. package/dist/client.js +14 -0
  61. package/dist/commerce.js +111 -0
  62. package/dist/decision-log.js +1093 -0
  63. package/dist/finished-store.js +5 -1
  64. package/dist/index.js +9 -1
  65. package/dist/lessons-store.js +322 -21
  66. package/dist/live.js +43 -0
  67. package/dist/move-order.js +64 -3
  68. package/dist/normalize.js +17 -0
  69. package/dist/open-games.js +36 -16
  70. package/dist/outlook-log.js +42 -1
  71. package/dist/profile-store.js +12 -2
  72. package/dist/protocol/methods.js +62 -5
  73. package/dist/protocol/rpc.js +8 -0
  74. package/dist/relations-store.js +38 -4
  75. package/dist/review-export.js +198 -0
  76. package/dist/siege-store.js +49 -0
  77. package/dist/state-bundle.js +584 -0
  78. package/dist/state-cli.js +71 -0
  79. package/dist/strategy/notes.js +56 -0
  80. package/dist/team-cards.js +25 -0
  81. package/dist/tools/accept-surrender.js +23 -9
  82. package/dist/tools/award.js +20 -2
  83. package/dist/tools/card-advice.js +93 -28
  84. package/dist/tools/card-plays.js +2 -2
  85. package/dist/tools/card-support-advice.js +37 -7
  86. package/dist/tools/chat-advice.js +330 -0
  87. package/dist/tools/chat-inbox.js +19 -4
  88. package/dist/tools/chat.js +106 -17
  89. package/dist/tools/check-plan.js +68 -12
  90. package/dist/tools/commerce-deploy.js +33 -0
  91. package/dist/tools/common.js +31 -0
  92. package/dist/tools/decision-capture.js +459 -0
  93. package/dist/tools/end-of-game.js +151 -21
  94. package/dist/tools/game-kind.js +92 -0
  95. package/dist/tools/how-lost.js +7 -2
  96. package/dist/tools/index.js +10 -0
  97. package/dist/tools/join-game.js +10 -4
  98. package/dist/tools/live-context.js +6 -0
  99. package/dist/tools/live.js +10 -1
  100. package/dist/tools/map-curves.js +73 -0
  101. package/dist/tools/notifications.js +4 -3
  102. package/dist/tools/opponents.js +2 -0
  103. package/dist/tools/past-games.js +74 -8
  104. package/dist/tools/picks.js +61 -10
  105. package/dist/tools/profile-hook.js +62 -3
  106. package/dist/tools/profile-opponents.js +4 -0
  107. package/dist/tools/push.js +2 -2
  108. package/dist/tools/relations.js +139 -0
  109. package/dist/tools/scout.js +16 -2
  110. package/dist/tools/state.js +232 -0
  111. package/dist/tools/strategy.js +3 -3
  112. package/dist/tools/stress-opponents.js +7 -2
  113. package/dist/tools/surrender-pending.js +10 -1
  114. package/dist/tools/surrender.js +18 -3
  115. package/dist/tools/survival.js +11 -3
  116. package/dist/tools/team-brief.js +2 -2
  117. package/dist/tools/team.js +12 -3
  118. package/dist/tools/turn.js +643 -76
  119. package/dist/tools/where.js +3 -1
  120. package/dist/version.js +1 -1
  121. package/manifest.json +32 -3
  122. package/mint.yaml +37 -4
  123. package/package.json +4 -4
  124. package/server.json +20 -2
  125. package/skills/warapp-mcp/SKILL.md +73 -17
@@ -1,29 +1,42 @@
1
+ // The estimates phase of a planning pass (#133): everything planTurn derives from its input before
2
+ // the first order — the opponents' deploy estimates and the fog prior (#119), the game profile and
3
+ // the goal it picks (rule 0p), the combat model and capture costs (S2, #126), what the board's
4
+ // territories are worth (#70, #85, #125), where I stand on armies (#167, #201, rule 0p.3) — and the
5
+ // rationale and warnings that state them. Pure: it reads the input and writes only
6
+ // `state.warnings` / `state.rationale`.
7
+ import { siegeFit, siegeOf } from './siege.js';
8
+ import { pileOf, strikeShareOf } from './stockpile.js';
9
+ import { armiesForGold } from '../../commerce.js';
1
10
  import { holdsSeat } from '../../player-states.js';
2
11
  import { isTeamGame, teammatesOf } from '../../teams.js';
3
12
  import { bonusTerritories } from '../bonuses.js';
4
13
  import { CHAIN_MAX_STEPS } from '../chains.js';
5
14
  import { armiesForChance, armiesToTake, DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, luckFraction, specialUnitStrength, straightKills, winChance, } from '../combat.js';
6
15
  import { neighborsOf } from '../graph.js';
16
+ import { incomeTrend } from '../income-trend.js';
7
17
  import { OUTLOOK_TURNS } from '../outlook.js';
8
18
  import { boardIncome, DEFAULT_BASE_INCOME } from '../player.js';
9
19
  import { AHEAD_PRESSURE_FACTOR, captureCost, combatSettings, DECIDED_PAYBACK_MIN, defaultMinWinChance, enemyDeployEstimates, HOLD_FALL_CHANCE, LUCK_WIN_CHANCE, MIN_ENEMY_DEPLOY, minWinChanceOf, ownerShown, PAYBACK_TURNS, PRESSURE_FACTOR, pressureMargin, SECOND_FRONT_LEAD, visibleState, } from './shared.js';
10
20
  import { AHEAD_RATIO, BEHIND_RATIO, gameProfile } from '../profile.js';
11
21
  import { byNum } from './util.js';
12
22
  import { sanctionedIncome } from '../cards-in-effect.js';
13
- import { truceOf } from './relations.js';
23
+ import { skirtedNeutrals, truceOf } from './relations.js';
14
24
  import { teamFocusOf } from './team.js';
15
25
  import { neutralizeSeats, staticSeats } from '../static-seats.js';
16
26
  import { commanderPlace } from './commander.js';
27
+ import { fogVacated, VACATED_FOG_ARMIES } from './vacated.js';
17
28
  /**
18
29
  * The fog prior to apply (#119, {@link EnemyIncomePrior}): only when the game says the start was
19
- * symmetric (`symmetricStart`), with no teams, and every seated player still playing — a 1v1 (one
20
- * opponent), or (#226) a free-for-all, where every opponent beside the fog gets the same prior. A
21
- * game with a player out (eliminated, booted, surrendered) gets none: a survivor may have absorbed
22
- * its territories, or I may have, so the start no longer says who earns what. Without a player list,
23
- * only one opponent in sight counts (a 1v1 as far as the board tells). #235: in a free-for-all with
24
- * no teams (two or more opponents seated) that gets none, `skipped` says why.
30
+ * symmetric (`symmetricStart`), with no teams — a 1v1 (one opponent), or (#226) a free-for-all, where
31
+ * every opponent beside the fog gets the same prior. #368: a player out (eliminated, booted,
32
+ * surrendered) whose seat no AI plays (`seats`, #270) no longer turns it off: its share of what the
33
+ * board hides goes to the opponents still playing (`opponents` counts them, `out` names it), so the
34
+ * prior is still at least my income, capped at an even share among the survivors. A seat an AI plays
35
+ * is an opponent like any other. Without a player list, only one opponent in sight counts (a 1v1 as
36
+ * far as the board tells). #235: in a free-for-all with no teams (two or more opponents seated) that
37
+ * gets none, `skipped` says why.
25
38
  */
26
- function fogPrior(board, me, ctx, myIncome) {
39
+ function fogPrior(board, me, ctx, myIncome, seats = new Map()) {
27
40
  const players = (ctx.players ?? []).filter((p) => holdsSeat(p.state));
28
41
  if (isTeamGame(players))
29
42
  return { prior: undefined };
@@ -31,19 +44,24 @@ function fogPrior(board, me, ctx, myIncome) {
31
44
  const why = (reason) => ({ prior: undefined, ...(ffa ? { skipped: reason } : {}) });
32
45
  if (ctx.symmetricStart !== true)
33
46
  return why(ctx.unevenStart ?? 'the game does not say every player started even');
34
- const out = players.filter((p) => (p.state ?? 'Playing') !== 'Playing' && p.id !== me).sort((a, b) => a.id - b.id);
35
- if (out.length)
36
- return why(`${out.map((p) => `player ${p.id} is out (${p.state})`).join(', ')}, and a survivor may have absorbed its territories, so the start no longer says who earns what`);
47
+ // #368: the players out whose seats stand still; their share is split among the rest.
48
+ const out = players
49
+ .filter((p) => p.id !== me && seats.has(p.id))
50
+ .sort((a, b) => a.id - b.id)
51
+ .map((p) => ({ id: p.id, state: p.state ?? 'Playing' }));
37
52
  const opponents = players.length
38
- ? players.filter((p) => p.id !== me).length
53
+ ? players.filter((p) => p.id !== me && !seats.has(p.id)).length
39
54
  : new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' && t.owner.playerId !== me ? [t.owner.playerId] : []))).size;
40
55
  if (opponents < 1 || (!players.length && opponents !== 1))
41
56
  return { prior: undefined };
42
57
  return {
43
58
  prior: {
44
59
  myIncome: Math.max(0, myIncome),
45
- ...(opponents > 1 ? { format: 'ffa', opponents } : {}),
60
+ ...(opponents > 1 || out.length ? { format: 'ffa', opponents } : {}),
61
+ ...(out.length ? { out } : {}),
46
62
  ...(ctx.opening ? { opening: ctx.opening } : {}),
63
+ // #419: the past winners' pace, thin evidence's upper bound when above the prior.
64
+ ...(ctx.mapPace ? { winnerPace: ctx.mapPace } : {}),
47
65
  },
48
66
  };
49
67
  }
@@ -70,7 +88,9 @@ export function planEnemyEstimates(input) {
70
88
  const previousBoard = input.previousBoard ? neutralizeSeats(input.previousBoard, seats) : undefined;
71
89
  const tracks = input.tracks?.filter((t) => !seats.has(t.playerId));
72
90
  const capCut = input.incomeCap ? Math.max(0, Math.floor(input.incomeCap.uncapped - input.incomeCap.received)) : 0;
73
- const { prior, skipped } = fogPrior(board, input.me, ctx, input.income + capCut);
91
+ const fog = fogPrior(board, input.me, ctx, input.income + capCut, seats);
92
+ const prior = statedScale(fog.prior, board, input.me, input.known ?? []);
93
+ const skipped = fog.skipped;
74
94
  const turn = input.turn ?? ctx.turn ?? null;
75
95
  const estimates = enemyDeployEstimates(input.graph, board, input.me, input.settings ?? {}, previousBoard, tracks, prior, {
76
96
  turn,
@@ -78,7 +98,57 @@ export function planEnemyEstimates(input) {
78
98
  reinforcement: ctx.reinforcement,
79
99
  ...(previousBoard && input.previousOrders ? { previousOrders: input.previousOrders } : {}),
80
100
  });
81
- return { estimates: applySanctions(estimates, input.sanctions ?? []), prior, ...(skipped ? { priorSkipped: skipped } : {}) };
101
+ const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? []), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
102
+ return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
103
+ }
104
+ /**
105
+ * #444: the incomes stated in chat (`known`) for players in view (not me) scale the prior of every other
106
+ * opponent when their mean is below my income: `EnemyIncomePrior.stated`. The prior unchanged otherwise.
107
+ */
108
+ function statedScale(prior, board, me, known) {
109
+ if (!prior || !known.length || prior.myIncome <= 0)
110
+ return prior;
111
+ const inView = new Set(board.territories.flatMap((t) => (t.owner.kind === 'player' ? [t.owner.playerId] : [])));
112
+ const players = known
113
+ .filter((k) => k.player !== me && inView.has(k.player))
114
+ .map((k) => ({ id: k.player, income: Math.max(0, Math.floor(k.income)) }));
115
+ if (!players.length)
116
+ return prior;
117
+ const ratio = players.reduce((n, x) => n + x.income, 0) / players.length / prior.myIncome;
118
+ return ratio < 1 ? { ...prior, stated: { players, mine: prior.myIncome, ratio } } : prior;
119
+ }
120
+ /**
121
+ * #368: each estimate whose player the user gave a known income for (what it said in chat, say): that
122
+ * income replaces the estimate's, whatever its source; a Reinforcement card the clock adds stays on top.
123
+ * `known` keeps the income given and the one it replaced (`was`, card left out). Unchanged without.
124
+ */
125
+ export function applyKnown(estimates, known) {
126
+ if (!known.length)
127
+ return estimates;
128
+ const by = new Map(known.map((k) => [k.player, Math.max(0, Math.floor(k.income))]));
129
+ return estimates.map((e) => {
130
+ const income = by.get(e.playerId);
131
+ if (income === undefined)
132
+ return e;
133
+ const card = e.card?.armies ?? 0;
134
+ return { ...e, estimate: income + card, known: { income, was: e.estimate - card } };
135
+ });
136
+ }
137
+ /**
138
+ * #332: in a commerce game with a rising army price (multiplier m > 0), what each estimate read off the board
139
+ * (`visible`, `exact`: its base and bonuses, in gold) buys in armies, its Reinforcement card's armies kept on top.
140
+ * An observed, tracked or prior figure is already armies and is left as it is. Unchanged with m = 0.
141
+ */
142
+ export function applyArmyPrice(estimates, m) {
143
+ if (!(m > 0))
144
+ return estimates;
145
+ return estimates.map((e) => {
146
+ if (e.source !== 'visible' && e.source !== 'exact')
147
+ return e;
148
+ const card = e.card?.armies ?? 0;
149
+ const gold = e.estimate - card;
150
+ return { ...e, estimate: armiesForGold(gold, m) + card, armyPrice: { gold, multiplier: m } };
151
+ });
82
152
  }
83
153
  /**
84
154
  * G2 (PLAN-TEAMS D3): each estimate under the Sanctions on its player. A figure read off the board
@@ -135,6 +205,8 @@ function opponentsCtx(input) {
135
205
  game: ctx,
136
206
  turn: turnNow,
137
207
  ...(input.sanctions?.length ? { sanctions: input.sanctions } : {}),
208
+ // #368: a what-if enemyDeploy sizes every opponent itself, so a known income is left out under it.
209
+ ...(input.knownIncome?.length && opts.enemyDeploy === undefined ? { known: input.knownIncome } : {}),
138
210
  });
139
211
  const estimateList = allEstimates.filter((e) => notAlly(e.playerId));
140
212
  /** An opponent's income: its deploy estimate less the Reinforcement card the clock adds (#164). */
@@ -181,16 +253,22 @@ function opponentsCtx(input) {
181
253
  const behind = auto && profile.standing === 'behind';
182
254
  /** Rule 0p.3 (#72): behind on income in a 1v1 — strike (stay balanced, break first), never defend. */
183
255
  const strike = behind && profile.format === '1v1';
184
- const goal = opts.goal ?? (behind && !strike ? 'defend' : 'balanced');
185
- const balanced = goal === 'balanced';
256
+ // #382: a siege plans as balanced; `siege` below carries what differs.
257
+ // (`let`: the profile's siege, below, replaces the goal it picked.)
258
+ let goal = opts.goal === 'siege' ? 'balanced' : (opts.goal ?? (behind && !strike ? 'defend' : 'balanced'));
259
+ let balanced = goal === 'balanced';
186
260
  /** Rule 0p.3: behind — size attacks at the minimum (no pressure margin). */
187
261
  const minimal = behind;
262
+ /** #303: my income over the last turns, this one (what I deploy, card armies out) last. */
263
+ const trendNow = turnNow !== null && input.incomeHistory?.length
264
+ ? incomeTrend(input.incomeHistory, { turn: turnNow, income: Math.max(0, income - Math.max(0, Math.floor(input.cardArmies ?? 0))) })
265
+ : undefined;
188
266
  /** Rule 0p.3: ahead in a 1v1 — pressure allowed at {@link AHEAD_PRESSURE_FACTOR}. */
189
267
  const pressureFactor = auto && profile.format === '1v1' && profile.standing === 'ahead' ? AHEAD_PRESSURE_FACTOR : PRESSURE_FACTOR;
190
268
  /** The pressure margin over an estimated deploy: none when sizing at the minimum. */
191
269
  const marginFor = (d) => (minimal ? 0 : pressureMargin(d));
192
270
  /** Goals that refuse to complete a bonus they cannot hold (R3); the others only warn. */
193
- const guarded = balanced || goal === 'defend';
271
+ let guarded = balanced || goal === 'defend';
194
272
  const focus = new Set(opts.focusBonusIds ?? []);
195
273
  const reserve = Math.min(income, Math.max(0, Math.floor(opts.reserve ?? 0)));
196
274
  const custom = opts.enemyDeploy !== undefined;
@@ -226,6 +304,58 @@ function opponentsCtx(input) {
226
304
  guardedByHeld.add(t);
227
305
  }
228
306
  const untrustedAt = (player, t) => (guardedByHeld.has(t) ? (untrusted.get(player) ?? 0) : 0);
307
+ // ---- #382: the siege (plan/siege.ts) ----
308
+ const siegeArgs = {
309
+ g,
310
+ state: new Map(board.territories.map((t) => [t.territoryId, t])),
311
+ mineAtStart,
312
+ foe,
313
+ incomeOfPlayer,
314
+ deployOf,
315
+ myIncome: Math.max(0, earnedIncome - Math.max(0, Math.floor(input.cardArmies ?? 0))),
316
+ tracks: input.tracks,
317
+ settings: s,
318
+ ...(input.turn !== undefined ? { turn: input.turn } : {}),
319
+ ...(input.siegeMemory ? { memory: input.siegeMemory } : {}),
320
+ };
321
+ const sieged = opts.goal === 'siege' ? siegeOf({ ...siegeArgs, target: opts.siegeTarget }) : undefined;
322
+ // #382 item 2: adapting with no goal, the profile picks the siege when it fits (siegeFit), and hands back
323
+ // once its assault trigger fires or the fit is gone.
324
+ let siege = sieged && 'siege' in sieged ? sieged.siege : undefined;
325
+ let siegeHandBack;
326
+ if (auto && opts.siegeAuto !== false && (profile.format === '1v1' || profile.format === 'ffa') && (profile.phase === 'contact' || profile.phase === 'late')) {
327
+ const c = siegeOf({ ...siegeArgs, target: undefined });
328
+ if ('siege' in c) {
329
+ const fit = siegeFit(c.siege, { format: profile.format, phase: profile.phase, standing: profile.standing, leader: profile.ranking?.commonThreat });
330
+ if (fit.fits) {
331
+ siege = { ...c.siege, auto: fit.fit };
332
+ // The siege wins over the profile's own goal (a `defend` it picked included): it plans as balanced.
333
+ goal = 'balanced';
334
+ balanced = true;
335
+ guarded = true;
336
+ }
337
+ else if (fit.handBack)
338
+ siegeHandBack = `A siege on player ${c.siege.target} would fit (#382), but its assault trigger has fired (${fit.handBack}): the profile hands back to its own goal for the assault.`;
339
+ }
340
+ }
341
+ // Until the trigger fires, no pass attacks the target's territories but its breakable bonuses' members.
342
+ const held = siege && !siege.ready ? siege : undefined;
343
+ const heldLand = new Set(held
344
+ ? board.territories.flatMap((t) => t.owner.kind === 'player' && t.owner.playerId === held.target && !held.breakMembers.has(t.territoryId) ? [t.territoryId] : [])
345
+ : []);
346
+ const withSiege = held
347
+ ? { ...truce, siegeHeld: (t) => heldLand.has(t), noTarget: (t) => truce.noTarget(t) || heldLand.has(t) }
348
+ : truce;
349
+ // #441: the neutrals an avoided player is visibly collecting are no targets either; #457: nor a truce partner's.
350
+ const skirted = skirtedNeutrals({ ...input, board }, { foe, deployOf, settings: s, ...(truce.keptWith ? { truce: truce.keptWith } : {}) });
351
+ const truceNow = skirted.size
352
+ ? {
353
+ ...withSiege,
354
+ skirted,
355
+ avoided: (t) => skirted.has(t) || withSiege.avoided(t),
356
+ noTarget: (t) => skirted.has(t) || withSiege.noTarget(t),
357
+ }
358
+ : withSiege;
229
359
  /**
230
360
  * #201: the planning horizon. Once the outlook (#178) says the game is decided — winning or losing
231
361
  * for OUTLOOK_TURNS turns running — every payback test counts the turns the game has left instead
@@ -266,7 +396,7 @@ function opponentsCtx(input) {
266
396
  allies,
267
397
  foe,
268
398
  teamFocus: teamFocusOf(board, allies, foe),
269
- truce,
399
+ truce: truceNow,
270
400
  turnNow,
271
401
  incomePrior,
272
402
  incomePriorSkipped,
@@ -278,7 +408,11 @@ function opponentsCtx(input) {
278
408
  strike,
279
409
  goal,
280
410
  balanced,
411
+ ...(siege ? { siege } : {}),
412
+ ...(sieged && 'warning' in sieged ? { siegeWarning: sieged.warning } : {}),
413
+ ...(siegeHandBack ? { siegeHandBack } : {}),
281
414
  minimal,
415
+ ...(trendNow ? { incomeTrend: trendNow } : {}),
282
416
  pressureFactor,
283
417
  marginFor,
284
418
  guarded,
@@ -349,8 +483,11 @@ function boardCtx(input, o) {
349
483
  */
350
484
  const uncounted = (id) => (state.get(id)?.specialUnits ?? []).some((u) => u.kind !== 'commander');
351
485
  const uncountedKind = (id) => [...new Set((state.get(id)?.specialUnits ?? []).filter((u) => u.kind !== 'commander').map((u) => (u.kind === 'boss' ? 'a boss' : u.kind === 'custom' ? 'a custom unit' : 'a special unit')))].join(' and ');
352
- /** What a territory defends as now: its armies plus its special units. */
353
- const defenceAt = (id) => armiesOf(id) + unitsAt(id);
486
+ /**
487
+ * What a territory defends as now: its armies plus its special units. #417 (the breach force): land a
488
+ * static seat left whose armies the fog hides stands on {@link VACATED_FOG_ARMIES} at most.
489
+ */
490
+ const defenceAt = (id) => (fogVacated(input.vacated, state.get(id), id) ? VACATED_FOG_ARMIES : armiesOf(id)) + unitsAt(id);
354
491
  // ---- income change (#70): the one computation nextIncome, R3 and the negative-bonus rules use ----
355
492
  const bonusTs = new Map(g.map.bonuses.map((b) => [b.id, bonusTerritories(g, b.id)]));
356
493
  /** The bonuses each territory is in (superbonuses through their members included). */
@@ -631,7 +768,28 @@ function standingCtx(o, b) {
631
768
  export function planContext(input) {
632
769
  const o = opponentsCtx(input);
633
770
  const b = boardCtx(input, o);
634
- return { ...o, ...b, ...combatCtx(o, b), ...standingCtx(o, b) };
771
+ const c = combatCtx(o, b);
772
+ // #421 (owner decision, 2026-11-20): in contact on a flat income the strike share is held out of
773
+ // captures (the reserve holds back captures only, so holds keep their exact need first).
774
+ const contact = new Set();
775
+ for (const id of b.mine)
776
+ for (const n of neighborsOf(o.g, id)) {
777
+ const st = b.territories.get(n);
778
+ if (st?.owner.kind === 'player' && st.armies !== null && o.foe(st.owner.playerId))
779
+ contact.add(st.owner.playerId);
780
+ }
781
+ const pileArgs = {
782
+ territories: b.territories, mineSet: b.mineSet, unitsAt: b.unitsAt, foe: o.foe, income: o.income,
783
+ ...(o.incomeTrend ? { incomeTrend: o.incomeTrend } : {}), auto: o.auto, goal: o.goal, noSplit: c.noSplit,
784
+ };
785
+ const strikeShare = o.opts.strikeShare === false ? 0 : strikeShareOf({ ...pileArgs, format: o.profile.format, siege: o.siege?.target, contact });
786
+ const reserve = Math.min(o.income, o.reserve + strikeShare);
787
+ // #421: the pile itself, for the break and all-in spends.
788
+ const pile = pileOf(pileArgs);
789
+ return {
790
+ ...o, ...b, ...c, ...standingCtx(o, b), reserve, strikeShare: reserve - o.reserve,
791
+ ...(pile ? { pile: { my: pile.my, turns: pile.turns } } : {}),
792
+ };
635
793
  }
636
794
  /**
637
795
  * The rationale and warnings that state what the estimates phase decided: the goal and the profile
@@ -640,23 +798,30 @@ export function planContext(input) {
640
798
  * every plan, in this order.
641
799
  */
642
800
  export function noteEstimates(ctx, state) {
643
- const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, goal, minimal, pressureFactor, decidedGame } = ctx;
801
+ const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, minimal, pressureFactor, decidedGame, siege } = ctx;
644
802
  const { rates, minWin, exactCombat, bombOn, luck, weightedRounding, noSplit, armiesBehindVs } = ctx;
645
803
  const { warnings, rationale } = state;
646
804
  const profileText = `${profile.format}, ${profile.phase}, ${profile.standing}`;
647
805
  if (opts.adapt && opts.goal !== undefined) {
648
- rationale.push(`Goal ${goal} was given explicitly, so it overrides the game profile (${profileText}): none of the profile's rules apply.`);
806
+ // #385: under `siege` the planner runs as `balanced`, so name the goal the caller gave.
807
+ rationale.push(`Goal ${opts.goal} was given explicitly, so it overrides the game profile (${profileText}): none of the profile's rules apply.`);
649
808
  // Also a warning: live, a script that always passed `goal: balanced` switched the 1v1 rules
650
809
  // (strike stack, breaks before expansion) off for two whole games, and nobody noticed.
651
- warnings.push(`Goal ${goal} was given explicitly, so none of the game-profile rules for ${profile.format === 'ffa' ? 'an FFA' : profile.format === 'teams' ? 'a team game' : 'a 1v1'} apply this turn (standing ${profile.standing}): leave the goal out to let the profile choose it and apply them.`);
810
+ warnings.push(`Goal ${opts.goal} was given explicitly, so none of the game-profile rules for ${profile.format === 'ffa' ? 'an FFA' : profile.format === 'teams' ? 'a team game' : 'a 1v1'} apply this turn (standing ${profile.standing}): leave the goal out to let the profile choose it and apply them.`);
652
811
  }
653
812
  else if (auto) {
654
813
  const strongest = estimateList.reduce((m, e) => Math.max(m, e.estimate), 0);
655
- rationale.push(strike
656
- ? `Goal balanced from the game profile (${profileText}): behind on income (${income} against ~${strongest}) in a 1v1 — strike: break the opponent's bonuses with minimal attacks before expansion that completes nothing (holds of my own bonuses that pay for themselves still come first), sized at the minimum (no extra margin beyond what the rules require).`
657
- : minimal
658
- ? `Goal defend from the game profile (${profileText}): behind on income (${income} against ~${strongest}), so defend first and size attacks at the minimum (no extra margin beyond what the rules require).`
659
- : `Goal balanced from the game profile (${profileText}): the base goal.`);
814
+ // #287: a 1v1 can read behind on the armies in view alone; then the incomes are not why.
815
+ const behindWhy = income <= BEHIND_RATIO * strongest
816
+ ? `behind on income (${income} against ~${strongest})`
817
+ : `behind on the board, not on income (${income} against ~${strongest}: the standing says why)`;
818
+ rationale.push(siege?.auto
819
+ ? `Goal siege from the game profile (${profileText}): it plans as balanced against player ${siege.target}, its cheap bonus breaks first and its other territories held back until the assault trigger fires${minimal ? `; ${behindWhy}, attacks are sized at the minimum (no extra margin beyond what the rules require)` : ''}.`
820
+ : strike
821
+ ? `Goal balanced from the game profile (${profileText}): ${behindWhy} in a 1v1 — strike: break the opponent's bonuses with minimal attacks before expansion that completes nothing (holds of my own bonuses that pay for themselves still come first), sized at the minimum (no extra margin beyond what the rules require).`
822
+ : minimal
823
+ ? `Goal defend from the game profile (${profileText}): ${behindWhy}, so defend first and size attacks at the minimum (no extra margin beyond what the rules require).`
824
+ : `Goal balanced from the game profile (${profileText}): the base goal.`);
660
825
  if (pressureFactor !== PRESSURE_FACTOR)
661
826
  rationale.push(`Ahead in a 1v1 (${income} against ~${strongest}): keep attacking — pressure on an opponent next to the fog is allowed when each capture costs up to ${pressureFactor}× a typical neutral capture (instead of ${PRESSURE_FACTOR}×).`);
662
827
  }
@@ -688,6 +853,14 @@ export function noteEstimates(ctx, state) {
688
853
  rationale.push('An opponent may hold a Bomb (#163): it halves one territory of mine next to it after the deploys and before any move, so every hold here is sized as if its stack were halved first (my commander unharmed), and the leftover goes to two stacks, not one, unless it concentrates for an attack.');
689
854
  if (s.multiAttack)
690
855
  rationale.push(`Multi-attack is on: the plan does not chain its own attacks from captured territories, but an enemy stack's chain — a capture, then the survivors on from it, through territories not mine — counts as a threat to the territory of mine, or the capture, it reaches (luck-free, at most ${CHAIN_MAX_STEPS} attacks deep).`);
856
+ // #441: a neutral skipped for an avoided player, beside my land (one the plan could reach this turn); #457: or a truce partner.
857
+ for (const [n, k] of ctx.truce.skirted ?? [])
858
+ if (neighborsOf(ctx.g, n).some((x) => ctx.mineSet.has(x))) {
859
+ const why = k.why === 'stack' ? `its only enemy neighbour is player ${k.player}` : `it sits in a bonus player ${k.player} visibly holds most of`;
860
+ rationale.push(k.truce
861
+ ? `Not taking ${ctx.label(n)}: ${why}, with whom a truce binds you, and taking it may read as a breach to player ${k.player} — raise it with player ${k.player} instead (it is taken only when it completes a bonus of mine) (#457).`
862
+ : `Not taking ${ctx.label(n)}: ${why}, whom the plan avoids, and its capture would not hold next turn, so taking it would only provoke that player (#441).`);
863
+ }
691
864
  if (noSplit) {
692
865
  rationale.push('No-Split: each territory issues at most one attack or transfer this turn, and it sends the whole stack (every army there, this turn\'s deploys included, less the guard); a territory that would split keeps its first (best) order, and one that must hold issues none.');
693
866
  }
@@ -82,7 +82,8 @@ export function fillSecondLine(pc, ps, book) {
82
82
  const owed = e.size - secondLineKept.get(id);
83
83
  if (owed <= 0)
84
84
  continue;
85
- const k = Math.min(owed, Math.max(0, ps.budget - reserve), roomAt(id));
85
+ // #421: the strike share holds back captures only, never the second line's exact need.
86
+ const k = Math.min(owed, Math.max(0, ps.budget - (reserve - pc.strikeShare)), roomAt(id));
86
87
  if (k > 0) {
87
88
  deploy(id, k);
88
89
  // The deployed armies join the garrison: they stay, as the guard would.
@@ -8,11 +8,56 @@ import { bonusTerritories } from '../bonuses.js';
8
8
  import { bfsDistances, neighborsOf } from '../graph.js';
9
9
  import { chargeDeploys } from '../local-deploy.js';
10
10
  import { twoStepReaches } from '../lookahead.js';
11
- import { BREACH_WEIGHT, CITE_CLOSE, CITE_OPEN, CITE_SEP, CONCEDE_FACTOR, nearMissMargin, } from './shared.js';
11
+ import { opensBehind } from '../opens.js';
12
+ import { BREACH_WEIGHT, CITE_CLOSE, CITE_OPEN, CITE_SEP, CONCEDE_FACTOR, MIN_ENEMY_DEPLOY, nearMissMargin, } from './shared.js';
12
13
  import { capRoom, relaxedFor } from './relations.js';
13
14
  import { byNum } from './util.js';
14
15
  /** #235: the most territories a cut-off line names. */
15
16
  const MAX_CUT_NAMED = 4;
17
+ /**
18
+ * #420: `t`'s hold is sized only on the fog prior (#119) — its opponent has no usable track and its
19
+ * figure is the prior, above what the evidence gives (its base and visible bonuses, an observed deploy,
20
+ * a Reinforcement card on the clock), and `t` holds against the stacks beside it plus that evidence.
21
+ * Returns the evidence figure, else `null`. Only a plain border: one opponent beside it (every other
22
+ * neighbour mine or neutral), no chain, split, joint or worst-case sizing, no Bomb, no figure Local
23
+ * Deployment or #275 changed, no given `enemy_deploy`.
24
+ */
25
+ export function priorOnlyHold(pc, b, t) {
26
+ if (pc.custom || pc.bombOn || b.chain || b.split || b.worst !== undefined || b.alone !== undefined || b.commanderWorst)
27
+ return null;
28
+ const e = pc.estimates.get(b.player);
29
+ if (!e || e.source !== 'prior' || e.tracked !== null || b.deploy !== pc.deployOf(b.player))
30
+ return null;
31
+ for (const n of neighborsOf(pc.g, t.id)) {
32
+ const o = pc.territories.get(n)?.owner;
33
+ if (pc.mineSet.has(n) || o?.kind === 'neutral' || (o?.kind === 'player' && o.playerId === b.player))
34
+ continue;
35
+ return null;
36
+ }
37
+ const floor = Math.max(MIN_ENEMY_DEPLOY, e.base);
38
+ const evidence = Math.max(e.opening ? floor : Math.max(floor, e.base + e.bonusIncome), e.observed ?? 0) + (e.card?.armies ?? 0);
39
+ if (evidence >= b.deploy)
40
+ return null;
41
+ const take = pc.toTake(t.have + t.units);
42
+ return take !== null && take > b.movable + Math.max(evidence, b.growth) ? evidence : null;
43
+ }
44
+ /** #420: the share of my income plain holds may take when even or ahead. */
45
+ export const HOLD_CAP_EVEN = 0.5;
46
+ /** #420: the share of my income plain holds may take when behind. */
47
+ export const HOLD_CAP_BEHIND = 0.7;
48
+ /**
49
+ * #420 (owner decision of 2026-11-20, "Total hold cap"): the armies plain holds may take this turn —
50
+ * {@link HOLD_CAP_BEHIND} of my income when the profile reads me behind, else {@link HOLD_CAP_EVEN}
51
+ * (rounded down) — or `null` under a `defend` goal the caller gave (`goal` defend while not adapting) or
52
+ * with `options.holdCap: false`.
53
+ */
54
+ export function holdCapOf(pc) {
55
+ if (pc.opts.holdCap === false || (pc.goal === 'defend' && !pc.auto))
56
+ return null;
57
+ const behind = pc.profile.standing === 'behind';
58
+ const share = behind ? HOLD_CAP_BEHIND : HOLD_CAP_EVEN;
59
+ return { armies: Math.floor(share * pc.income), share, behind };
60
+ }
16
61
  /**
17
62
  * Define the holds of one pass, step by step in planPass's order. Nothing here deploys, moves or
18
63
  * says anything yet: planPass runs assessThreats, triage, withdraw, reconsider and
@@ -264,7 +309,23 @@ export function twoStepHolds(pc, ps, book, threats, hb, pass, prev) {
264
309
  }
265
310
  return v;
266
311
  };
267
- const guardsTwoStep = (t) => myCommanders.has(t) || heldBonusValue(t) > 0;
312
+ /**
313
+ * #291: my `t` is the only way in to held bonuses (they are not its own): behind a conceded border it is the next
314
+ * gate, not interior, so it guards against a stack two steps away too. Judged on the start of the turn, as the
315
+ * reaches are (found once per plan).
316
+ */
317
+ const opensMemo = new Map();
318
+ const source = (x) => {
319
+ const o = state.get(x)?.owner;
320
+ return o === undefined || o.kind === 'unknown' || (o.kind === 'player' && foe(o.playerId));
321
+ };
322
+ const opensHeld = (t) => {
323
+ let v = opensMemo.get(t);
324
+ if (v === undefined)
325
+ opensMemo.set(t, (v = opensBehind(g, heldAtStart, source, t, new Set()).income > 0));
326
+ return v;
327
+ };
328
+ const guardsTwoStep = (t) => myCommanders.has(t) || heldBonusValue(t) > 0 || opensHeld(t);
268
329
  /**
269
330
  * Every two-step reach to a territory of mine worth guarding (lookahead.ts, as check_plan), by
270
331
  * territory: found once per {@link planTurn} (it depends only on the start board) and shared by
@@ -444,7 +505,7 @@ export function twoStepHolds(pc, ps, book, threats, hb, pass, prev) {
444
505
  export function holdOrConcede(pc, ps, book, threats, hb, prev) {
445
506
  const { goal, paybackTurns, label, unitsAt, bombOn, toTake, myCommanders } = pc;
446
507
  const { warnings, rationale, locked } = ps;
447
- const { deploy, valueOf, stakeAt, cutOff, breachAt } = book;
508
+ const { deploy, valueOf, stakeAt, cutOff, breachAt, opensAt } = book;
448
509
  const { borders, recentlyTakenFrom } = threats;
449
510
  const { threatened, conceded } = hb;
450
511
  const { stayAt } = prev;
@@ -456,6 +517,8 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
456
517
  const cutNoted = new Set();
457
518
  /** #275: the borders whose breach is already named. */
458
519
  const breachNoted = new Set();
520
+ /** #291: the gates whose opened value is already named. */
521
+ const opensNoted = new Set();
459
522
  /** Rule 1a's pre-deploy threat warning per border, restated once the deploys are known. */
460
523
  const threatWarnings = new Map();
461
524
  const assessThreats = () => {
@@ -493,6 +556,14 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
493
556
  const more = breach.ids.length > MAX_CUT_NAMED ? ` and ${breach.ids.length - MAX_CUT_NAMED} more` : '';
494
557
  rationale.push(`${label(b.id)} alone shields ${named}${more} within two moves behind it (+${breach.income} income): with the guard off a breach walks straight in, so its value counts ${BREACH_WEIGHT * 100}% of that (+${breach.worth}) (#275).`);
495
558
  }
559
+ // #291: a gate whose loss opens held bonuses to the enemy says so.
560
+ const opens = opensAt(b.id);
561
+ if (opens && !opensNoted.has(b.id)) {
562
+ opensNoted.add(b.id);
563
+ const named = opens.ids.slice(0, MAX_CUT_NAMED).map(label).join(', ');
564
+ const more = opens.ids.length > MAX_CUT_NAMED ? ` and ${opens.ids.length - MAX_CUT_NAMED} more` : '';
565
+ rationale.push(`${label(b.id)} is the only way in to ${named}${more} (+${opens.income} income): losing it opens them to the enemy, so its value counts half of that (+${opens.worth}) (#291).`);
566
+ }
496
567
  const from = recentlyTakenFrom(b.id);
497
568
  threatened.push({
498
569
  id: b.id,
@@ -526,7 +597,30 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
526
597
  const heldStack = (t) => `${t.have + t.holdCost} armies${t.units ? ' and my commander' : ''}`;
527
598
  /** The borders a hold deployed to, by the player threatening them (for the #69 rationale). */
528
599
  const heldAgainst = new Map();
529
- const hold = (t) => {
600
+ /**
601
+ * #420 (owner decision of 2026-11-20, "Total hold cap"): plain holds take at most
602
+ * {@link HOLD_CAP_EVEN} of my income when even or ahead, {@link HOLD_CAP_BEHIND} when behind (the
603
+ * profile's standing). A held bonus's own gate (rule 1h's units, `gate`) and my commander's hold are
604
+ * funded first, outside the cap, and do not count toward it. Not under a `defend` goal the caller gave.
605
+ */
606
+ const holdCap = holdCapOf(pc);
607
+ let capSpent = 0;
608
+ /** #420: a plain hold of `t` would take the holds past the cap. */
609
+ const overCap = (t) => holdCap !== null && !t.critical && capSpent + t.holdCost > holdCap.armies;
610
+ /** #420: what a plain hold deployed outside {@link hold} (rule 4a's hold-and-break) takes of the cap. */
611
+ const chargeCap = (armies) => {
612
+ capSpent += armies;
613
+ };
614
+ /** #420: `t` is conceded for the cap (said unless `quiet`); its line reads like rule 1a's, so a revival lifts it. */
615
+ const concedeCapped = (t, quiet = false) => {
616
+ conceded.add(t.id);
617
+ if (quiet || !holdCap)
618
+ return;
619
+ warnings.push(`${label(t.id)} cannot be held within the hold cap (#420: plain holds take at most ${holdCap.armies} of my ${pc.income} income, ${holdCap.share * 100}% ${holdCap.behind ? 'when behind' : 'when even or ahead'}; ${capSpent} already go to holds, and it needs ${t.holdCost}, protects +${t.value}): conceded`);
620
+ };
621
+ const hold = (t, gate = false) => {
622
+ if (!gate && !t.critical)
623
+ capSpent += t.holdCost;
530
624
  noteRecent(t);
531
625
  deploy(t.id, t.holdCost);
532
626
  locked.add(t.id);
@@ -535,7 +629,7 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
535
629
  heldAgainst.set(by, (heldAgainst.get(by) ?? new Set()).add(t.id));
536
630
  rationale.push(`Deploy ${t.holdCost + (t.given ?? 0)} 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.`);
537
631
  };
538
- return { threatWarnings, assessThreats, acting, concedeUnaffordable, noteRecent, heldStack, heldAgainst, hold };
632
+ return { threatWarnings, assessThreats, acting, concedeUnaffordable, noteRecent, heldStack, heldAgainst, hold, overCap, chargeCap, concedeCapped };
539
633
  }
540
634
  /** Rule 1h (#51): every bonus I hold in full with a threatened border is one unit, held whole or conceded. */
541
635
  export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
@@ -691,8 +785,9 @@ export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
691
785
  let rest = cost;
692
786
  for (const m of todo) {
693
787
  rest -= m.holdCost;
788
+ // #420: a held bonus's own gate, outside the hold cap.
694
789
  if (!each?.(m, rest))
695
- hold(m);
790
+ hold(m, true);
696
791
  heldBorders.add(m.id);
697
792
  }
698
793
  return true;
@@ -774,7 +869,7 @@ export function floorTier(pc, ps, book, threats, hb, prev) {
774
869
  const near = new Set(missing.flatMap(sourcesOf));
775
870
  return cost <= income + [...near].reduce((n, x) => n + avail.get(x), 0);
776
871
  });
777
- const { uneconomic, acting, concedeUnaffordable, heldStack, hold, heldBorders, commanderHeld, buildUnits, unitBorders, concedeUnit, leftFor, fundUnit, fundNearMiss, } = prev;
872
+ const { uneconomic, acting, concedeUnaffordable, heldStack, hold, heldBorders, commanderHeld, buildUnits, unitBorders, concedeUnit, leftFor, fundUnit, fundNearMiss, overCap, concedeCapped, } = prev;
778
873
  // ---- 1h. floor tier and one shared deploy (#118) ----
779
874
  // One enemy deploy lands on one target. Sizing every border of a held bonus for the whole of
780
875
  // it conceded every bonus once the deploy outgrew them, though the stacks already next to the
@@ -917,6 +1012,8 @@ export function floorTier(pc, ps, book, threats, hb, prev) {
917
1012
  concedeUnaffordable(t, room);
918
1013
  return;
919
1014
  }
1015
+ if (overCap(t))
1016
+ return concedeCapped(t, quiet);
920
1017
  hold(t);
921
1018
  heldBorders.add(t.id);
922
1019
  };
@@ -1279,6 +1376,8 @@ export function floorTier(pc, ps, book, threats, hb, prev) {
1279
1376
  concedeUnaffordable(t, left);
1280
1377
  return;
1281
1378
  }
1379
+ if (acting && overCap(t))
1380
+ return concedeCapped(t, quiet);
1282
1381
  triageBudget -= t.holdCost;
1283
1382
  if (acting) {
1284
1383
  hold(t);
@@ -1512,7 +1611,7 @@ export function withdrawals(pc, ps, book, threats, hb, prev) {
1512
1611
  export function reconsiderAndGarrison(pc, ps, book, threats, hb, prev) {
1513
1612
  const { g, guarded, reserve, paybackTurns, label, bonusName, mine, mineSet, unitsAt, toTake, myCommanders } = pc;
1514
1613
  const { warnings, rationale, deployed, locked, captured, moves } = ps;
1515
- const { orderOf, deploy, pools, valueCache, cutCache, breachCache, valueOf } = book;
1614
+ const { orderOf, deploy, pools, valueCache, cutCache, breachCache, opensCache, valueOf } = book;
1516
1615
  const local = pools !== null && pools.bonuses.length > 0;
1517
1616
  const { borders } = threats;
1518
1617
  const { conceded, kept, garrisoned } = hb;
@@ -1529,6 +1628,7 @@ export function reconsiderAndGarrison(pc, ps, book, threats, hb, prev) {
1529
1628
  valueCache.clear();
1530
1629
  cutCache.clear();
1531
1630
  breachCache.clear();
1631
+ opensCache.clear();
1532
1632
  if (!conceded.size)
1533
1633
  return;
1534
1634
  for (const t of [...conceded].sort(byNum)) {
@@ -1611,7 +1711,8 @@ export function reconsiderAndGarrison(pc, ps, book, threats, hb, prev) {
1611
1711
  continue;
1612
1712
  const cost = todo.reduce((n, x) => n + x.d, 0);
1613
1713
  const worth = b.value + have / paybackTurns;
1614
- if (cost > paybackTurns * b.value || cost > CONCEDE_FACTOR * worth || cost > ps.budget - reserve)
1714
+ // #421: the strike share holds back captures only, never this garrison.
1715
+ if (cost > paybackTurns * b.value || cost > CONCEDE_FACTOR * worth || cost > ps.budget - (reserve - pc.strikeShare))
1615
1716
  continue;
1616
1717
  // The pools are checked for the members together: each may fit the free pool on its own
1617
1718
  // while together they overdraw it.