@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
@@ -0,0 +1,316 @@
1
+ // Withdrawals from conceded borders (rule 1b), the concessions this turn's captures make worth keeping
2
+ // (rule 1c, R2) and the garrisons of bonuses completed this turn (#122) — split from holds.ts, which
3
+ // re-exports it. Also the move-order helpers those rules share (`knownFirst`, `lateNet`, `sentOut`).
4
+ import { bonusTerritories } from '../bonuses.js';
5
+ import { bfsDistances, neighborsOf } from '../graph.js';
6
+ import { chargeDeploys } from '../local-deploy.js';
7
+ import { CONCEDE_FACTOR, } from './shared.js';
8
+ import { capRoom, } from './relations.js';
9
+ import { paybackLive } from './state.js';
10
+ import { byNum } from './util.js';
11
+ /**
12
+ * #215: I am known to move first (#127) — from a source the hold sizing trusts: one the user gave,
13
+ * not the award of picks' unverified rule (`movesFirstUnverified`, #215 review) — and no opponent
14
+ * may hold an Order Priority card (`opponentsMayHoldOrderPriority`, #215 review): played, it puts
15
+ * its first order (an all-in on a border) before my first.
16
+ */
17
+ export const knownFirst = (pc) => pc.opts.movesFirst === true && pc.opts.movesFirstUnverified !== true && pc.opts.opponentsMayHoldOrderPriority !== true;
18
+ /**
19
+ * #215: the armies withdrawn into my `id` this turn (rule 1b) that a hold may count only if I move
20
+ * first. A transfer in is my own order: when the opponent moves first, its first order — an all-in
21
+ * on `id` — runs before any of mine. So unless I am known to move first (#127, {@link knownFirst})
22
+ * they are late, and a hold sized for the worse order leaves them out. 0 when I am known to move first.
23
+ */
24
+ export function lateArrivals(pc, ps, id) {
25
+ return knownFirst(pc) ? 0 : withdrawnInto(ps, id);
26
+ }
27
+ /**
28
+ * #215 review: the armies a worse-order hold on my `id` leaves out. When the opponent moves first,
29
+ * its first order runs before ALL of mine: the armies withdrawn into `id` are not there yet, and
30
+ * the armies `id` sends out by its own orders are still there. After my orders have run, the
31
+ * withdrawal is in and those armies are gone (the hold #127 sized). A move out of a territory is
32
+ * scheduled after the moves into it (schedule.ts), so the worse of the two is the withdrawal less
33
+ * what leaves: `max(0, late − sent out)`. 0 when I am known to move first.
34
+ */
35
+ export function lateNet(pc, ps, id) {
36
+ const late = lateArrivals(pc, ps, id);
37
+ return late <= 0 ? 0 : Math.max(0, late - sentOut(ps, id));
38
+ }
39
+ /** #215 review: the armies my `id` sends out by its own orders this turn (attacks and transfers). */
40
+ export function sentOut(ps, id) {
41
+ return ps.moves.reduce((n, m) => (m.from === id ? n + m.armies : n), 0);
42
+ }
43
+ /**
44
+ * #215: the armies withdrawn into my `id` this turn (rule 1b), whatever the move order. Only
45
+ * withdrawal transfers count (#215 review): `incoming` also carries a softener's survivors that come
46
+ * home and No-Split extras, which beside an idle transfer in (rule 6) would read as withdrawn.
47
+ */
48
+ export function withdrawnInto(ps, id) {
49
+ const sent = ps.moves.reduce((n, m) => (m.kind === 'transfer' && m.to === id && m.reason === 'withdraws from a conceded border' ? n + m.armies : n), 0);
50
+ return Math.max(0, Math.min(ps.incoming.get(id) ?? 0, sent));
51
+ }
52
+ /** Rule 1b: withdraw from conceded borders (and Order Priority when a withdrawal must go first). */
53
+ export function withdrawals(pc, ps, book, threats, hb, prev) {
54
+ const { g, label, bonusName, mine, mineSet, unitsAt, toTake, noSplit } = pc;
55
+ const { warnings, rationale, avail, locked, moves, incoming } = ps;
56
+ const { coverOf, orderOf, warnSplit, pools, valueOf } = book;
57
+ const local = pools !== null && pools.bonuses.length > 0;
58
+ const { expectedAt, borders } = threats;
59
+ const { conceded, units } = hb;
60
+ const { stayAt, unitBorders } = prev;
61
+ // ---- 1b. withdraw from conceded borders ----
62
+ ps.cardAdvice = null;
63
+ /** Conceded borders of a held bonus whose garrison stays (it holds against the expected attack). */
64
+ const stood = new Set();
65
+ /** Bonuses whose Local Deployment concession warning (#103) is already given. */
66
+ const warnedLocal = new Set();
67
+ /** Local Deployment (#103): conceded borders of a held bonus that might still hold; the leftover may go there. */
68
+ const mayHold = new Set();
69
+ /** Local Deployment: the armies every pool containing `id` holds this turn. */
70
+ const poolsAt = (id) => local ? pools.bonuses.filter((p) => p.territoryIds.includes(id)).reduce((n, p) => n + p.value, 0) : 0;
71
+ /** A border no deploy this turn can hold: its hold needs more than its pools and every free army. */
72
+ const lostAnywayAt = (m) => local && m.holdCost > poolsAt(m.id) + pools.anywhere;
73
+ /** A held bonus that falls whatever this turn deploys: one of its threatened borders cannot be held. */
74
+ const lostAnyway = (u) => u.members.some(lostAnywayAt);
75
+ const withdraw = () => {
76
+ if (!conceded.size)
77
+ return;
78
+ const withdrawals = [];
79
+ const keep = (id) => mineSet.has(id) && !conceded.has(id);
80
+ // Borders that can hold: mine, not conceded, next to something not mine.
81
+ const holding = mine.filter((id) => keep(id) && neighborsOf(g, id).some((n) => !mineSet.has(n)));
82
+ for (const t of [...conceded].sort(byNum)) {
83
+ // #179: a covered exit keeps its cover; only the rest may leave.
84
+ const n = avail.get(t) - coverOf(t);
85
+ // No-Split (#124): a transfer sends the whole stack, so a covered exit sends none.
86
+ if (n <= 0 || (noSplit && coverOf(t) > 0))
87
+ continue;
88
+ // Issue #59: a held bonus's border keeps its garrison while it still holds against the
89
+ // expected attack — withdrawing it would guarantee the loss.
90
+ const held = g.map.bonuses
91
+ .filter((b) => {
92
+ const ts = bonusTerritories(g, b.id);
93
+ return b.value > 0 && ts.includes(t) && ts.every((x) => mineSet.has(x));
94
+ })
95
+ .sort((a, b) => a.id - b.id);
96
+ const stays = stayAt(t);
97
+ const take = toTake(stays) ?? Infinity;
98
+ const expected = expectedAt(t);
99
+ if (held.length && take > expected) {
100
+ locked.add(t);
101
+ stood.add(t);
102
+ rationale.push(`Keep the ${n} movable armies on ${label(t)} (not withdrawn): it is a border of held bonus ${held.map((b) => bonusName(b.id)).join(', ')}, and its ${stays} armies need ${take} to take, above the expected ~${expected} attack (movable + deploy estimate).`);
103
+ continue;
104
+ }
105
+ // Local Deployment (#103): a conceded held bonus keeps its garrisons unless it truly
106
+ // cannot be held — some threatened border needs more than its pools and every free army
107
+ // could give it. Withdrawing turns "might lose it" into "certainly loses it".
108
+ if (local && held.length) {
109
+ const mine1 = units.filter((u) => u.conceded && u.members.some((m) => m.id === t));
110
+ const maybe = mine1.filter((u) => !lostAnyway(u));
111
+ if (maybe.length) {
112
+ locked.add(t);
113
+ stood.add(t);
114
+ mayHold.add(t);
115
+ for (const u of maybe) {
116
+ if (warnedLocal.has(u.bonusId))
117
+ continue;
118
+ warnedLocal.add(u.bonusId);
119
+ warnings.push(`Bonus ${bonusName(u.bonusId)} (+${u.value}) is conceded but might still hold: each of its ${unitBorders(u)} could be held with its own ${u.pool} local armies and the ${pools.anywhere} free ones, so its garrisons stay and its local armies defend it (withdrawing would make the loss certain); it may fall.`);
120
+ }
121
+ rationale.push(`Keep the ${n} movable armies on ${label(t)} (not withdrawn): bonus ${maybe.map((u) => bonusName(u.bonusId)).join(', ')} might still hold under Local Deployment, and withdrawing would guarantee the loss.`);
122
+ continue;
123
+ }
124
+ for (const u of mine1) {
125
+ if (warnedLocal.has(u.bonusId))
126
+ continue;
127
+ warnedLocal.add(u.bonusId);
128
+ const worst = u.members.find((m) => lostAnywayAt(m));
129
+ warnings.push(`Bonus ${bonusName(u.bonusId)} (+${u.value}) cannot be held: ${label(worst.id)} needs ${worst.holdCost}, more than its own ${poolsAt(worst.id)} local armies and all ${pools.anywhere} free ones could give it, so its garrisons withdraw (it is lost either way).`);
130
+ }
131
+ }
132
+ // B2 (T5): never onto a truce's capped border past its cap.
133
+ const options = neighborsOf(g, t)
134
+ .filter((c) => keep(c) && capRoom(pc, ps, c, withdrawals) >= n)
135
+ .map((c) => {
136
+ const dist = bfsDistances(g, [c], { passable: keep });
137
+ let best = Infinity;
138
+ let value = 0;
139
+ for (const h of holding) {
140
+ const d = dist.get(h);
141
+ if (d === undefined)
142
+ continue;
143
+ if (d < best || (d === best && valueOf(h) > value))
144
+ [best, value] = [d, valueOf(h)];
145
+ }
146
+ return { id: c, best, value };
147
+ })
148
+ .sort((a, b) => a.best - b.best || b.value - a.value || a.id - b.id);
149
+ const to = options[0];
150
+ if (!to) {
151
+ const capped = neighborsOf(g, t).some((c) => keep(c) && capRoom(pc, ps, c, withdrawals) < n);
152
+ warnings.push(`${label(t)} is conceded and has nowhere to withdraw to${capped ? ' (a truce caps the armies on the borders beside it)' : ''}: its ${n} movable armies stay.`);
153
+ continue;
154
+ }
155
+ // #118: a border of a bonus I hold in full keeps its garrison — those armies kill attackers
156
+ // where they stand — unless withdrawing them makes another valued border hold this turn.
157
+ // (Under Local Deployment rule 1b's pool test above decides instead.)
158
+ if (held.length && !local) {
159
+ const dest = borders.get(to.id);
160
+ const at = stayAt(to.id) + unitsAt(to.id);
161
+ const makesHold = dest !== undefined &&
162
+ !conceded.has(to.id) &&
163
+ valueOf(to.id) > 0 &&
164
+ (toTake(at) ?? Infinity) <= dest.threat &&
165
+ (toTake(at + n) ?? Infinity) > dest.threat;
166
+ if (!makesHold) {
167
+ locked.add(t);
168
+ stood.add(t);
169
+ rationale.push(`Keep the ${n} movable armies on ${label(t)} (not withdrawn): it is a border of held bonus ${held.map((b) => bonusName(b.id)).join(', ')}, and withdrawing them would make no other valued border hold this turn, while there they kill attackers.`);
170
+ continue;
171
+ }
172
+ }
173
+ if (orderOf(t)) {
174
+ warnSplit(t, `its ${n} remaining armies are not withdrawn to ${label(to.id)}`);
175
+ locked.add(t);
176
+ continue;
177
+ }
178
+ avail.set(t, avail.get(t) - n);
179
+ locked.add(t);
180
+ const reason = 'withdraws from a conceded border';
181
+ withdrawals.push({ from: t, to: to.id, armies: n, kind: 'transfer', reason });
182
+ incoming.set(to.id, (incoming.get(to.id) ?? 0) + n);
183
+ rationale.push(`Withdraw ${n} from ${label(t)} to ${label(to.id)}: ${reason}, toward a border that holds.`);
184
+ warnings.push(`The withdrawal from ${label(t)} only executes if ${label(t)} is still mine when the order runs; play Order Priority so it goes first.`);
185
+ ps.cardAdvice = 'order-priority';
186
+ }
187
+ // Withdrawals go first: they only execute while the border is still mine.
188
+ moves.unshift(...withdrawals);
189
+ };
190
+ return { stood, mayHold, withdraw };
191
+ }
192
+ /** Rule 1c (R2): reconsider concessions after the capture passes; #122: garrison a bonus completed this turn. */
193
+ export function reconsiderAndGarrison(pc, ps, book, threats, hb, prev) {
194
+ const { g, guarded, reserve, paybackTurns, label, bonusName, mine, mineSet, unitsAt, toTake, myCommanders } = pc;
195
+ const { warnings, rationale, deployed, locked, captured, moves } = ps;
196
+ const { orderOf, deploy, pools, valueCache, cutCache, breachCache, opensCache, valueOf } = book;
197
+ const local = pools !== null && pools.bonuses.length > 0;
198
+ const { borders } = threats;
199
+ const { conceded, kept, garrisoned } = hb;
200
+ const { stayAt, heldBorders } = prev;
201
+ // ---- 1c. reconsider concessions after the capture passes (R2) ----
202
+ // Triage ran before captures were known, so a border in a bonus this turn's
203
+ // captures complete was valued +0 and conceded. Re-value every border against
204
+ // the holdings after the captures; a conceded border in a bonus completed this
205
+ // turn is kept (never withdrawn from) and garrisoned from the leftover.
206
+ const reconsider = () => {
207
+ if (!captured.size)
208
+ return;
209
+ ps.holdings = new Set([...mine, ...captured]);
210
+ valueCache.clear();
211
+ cutCache.clear();
212
+ breachCache.clear();
213
+ opensCache.clear();
214
+ if (!conceded.size)
215
+ return;
216
+ for (const t of [...conceded].sort(byNum)) {
217
+ // Already withdrawn from (rule 1b ran first): its armies are gone, and it stays conceded.
218
+ if (moves.some((m) => m.from === t && m.reason === 'withdraws from a conceded border'))
219
+ continue;
220
+ const completes = g.map.bonuses
221
+ .filter((b) => {
222
+ const ts = bonusTerritories(g, b.id);
223
+ // #422: a payback completion is expected to fall next turn: it keeps no conceded border.
224
+ return (b.value > 0 && !paybackLive(ps, ps.paybackBonuses, b.id) && ts.includes(t) && ts.every((x) => ps.holdings.has(x)) && !ts.every((x) => mineSet.has(x)));
225
+ })
226
+ .sort((a, b) => a.id - b.id);
227
+ if (!completes.length)
228
+ continue;
229
+ conceded.delete(t);
230
+ kept.add(t);
231
+ locked.add(t);
232
+ // Drop its concession warning: it is no longer conceded.
233
+ const conceding = `${label(t)} cannot be held `;
234
+ for (let i = warnings.length - 1; i >= 0; i--)
235
+ if (warnings[i].startsWith(conceding) && warnings[i].endsWith(': conceded'))
236
+ warnings.splice(i, 1);
237
+ rationale.push(`Keep ${label(t)} (not conceded): this turn's captures complete ${completes.map((b) => `bonus ${b.name} (#${b.id}) (+${b.value})`).join(', ')}, so it protects +${valueOf(t)}.`);
238
+ }
239
+ };
240
+ // (Under `defend` the withdrawal runs after the capture passes, once `reconsider` has
241
+ // kept any border this turn's captures make valuable; it still goes first in the orders.)
242
+ // ---- #122: a bonus completed this turn is garrisoned like a held one (rule 1h) ----
243
+ // Its members I held at the start of the turn that face an enemy would otherwise get only the
244
+ // leftover (rule 1c), after every advance had spent the income: live, completed bonuses stood
245
+ // beside enemies on 1-army borders and never paid a turn. So once a capture completes a bonus,
246
+ // its threatened members are held whole right away — before any later capture — when the holds
247
+ // pay for themselves as a held bonus's do (cost ≤ PAYBACK_TURNS × value and ≤ CONCEDE_FACTOR ×
248
+ // its worth) and fit what may still be deployed; otherwise they are left to the leftover as
249
+ // before. Captured members are not garrisoned: next turn's deploys land before any attack.
250
+ /** Bonuses whose garrison was judged (funded or not), so each is judged once. */
251
+ const garrisonJudged = new Set();
252
+ /** Do these deploys fit together what may still be deployed (the budget, and the pools under Local Deployment)? */
253
+ const fitsTogether = (adds) => {
254
+ if (adds.reduce((n, x) => n + x.d, 0) > ps.budget)
255
+ return false;
256
+ if (!local)
257
+ return true;
258
+ const next = new Map(deployed);
259
+ for (const x of adds)
260
+ next.set(x.id, (next.get(x.id) ?? 0) + x.d);
261
+ return chargeDeploys(pools, next).anywhereUsed <= pools.anywhere;
262
+ };
263
+ const garrisonCompleted = () => {
264
+ if (!guarded || !captured.size)
265
+ return;
266
+ const after = new Set([...mine, ...captured]);
267
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
268
+ // #422: a payback completion is expected to fall next turn: no garrison is thrown after it.
269
+ if (b.value <= 0 || garrisonJudged.has(b.id) || paybackLive(ps, ps.paybackBonuses, b.id))
270
+ continue;
271
+ const ts = bonusTerritories(g, b.id);
272
+ if (!ts.length || !ts.every((x) => after.has(x)) || ts.every((x) => mineSet.has(x)))
273
+ continue;
274
+ garrisonJudged.add(b.id);
275
+ const todo = [];
276
+ let have = 0;
277
+ let split = false;
278
+ for (const t of ts) {
279
+ const border = borders.get(t);
280
+ if (!mineSet.has(t) || !border || heldBorders.has(t) || myCommanders.has(t))
281
+ continue;
282
+ const stays = stayAt(t) + unitsAt(t);
283
+ let d = 0;
284
+ while ((toTake(stays + d) ?? Infinity) <= border.threat)
285
+ d++;
286
+ if (!d)
287
+ continue;
288
+ // No-Split: a deploy on a territory that already issues an order leaves with it.
289
+ if (orderOf(t))
290
+ split = true;
291
+ todo.push({ id: t, d, threat: border.threat });
292
+ have += stays;
293
+ }
294
+ if (!todo.length || split)
295
+ continue;
296
+ const cost = todo.reduce((n, x) => n + x.d, 0);
297
+ const worth = b.value + have / paybackTurns;
298
+ // #421: the strike share holds back captures only, never this garrison.
299
+ if (cost > paybackTurns * b.value || cost > CONCEDE_FACTOR * worth || cost > ps.budget - (reserve - pc.strikeShare))
300
+ continue;
301
+ // The pools are checked for the members together: each may fit the free pool on its own
302
+ // while together they overdraw it.
303
+ if (!fitsTogether(todo))
304
+ continue;
305
+ for (const x of todo) {
306
+ deploy(x.id, x.d);
307
+ garrisoned.add(x.id);
308
+ heldBorders.add(x.id);
309
+ locked.add(x.id);
310
+ const stays = stayAt(x.id) + unitsAt(x.id);
311
+ rationale.push(`Garrison ${label(x.id)} for bonus ${bonusName(b.id)} (+${b.value}), completed this turn: deploy ${x.d} so its ${stays} armies need ${toTake(stays)} to take, above the ~${x.threat} threat — held like a bonus held at the start, before any later capture, not left to the leftover.`);
312
+ }
313
+ }
314
+ };
315
+ return { reconsider, garrisonCompleted };
316
+ }