@chrischall/warapp-mcp 0.7.0 → 0.9.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 (65) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +5 -4
  4. package/dist/analysis/card-support.js +12 -4
  5. package/dist/analysis/coalition.js +55 -0
  6. package/dist/analysis/local-deploy.js +14 -0
  7. package/dist/analysis/opponents.js +2 -1
  8. package/dist/analysis/picks.js +270 -37
  9. package/dist/analysis/plan/after-leftover.js +26 -4
  10. package/dist/analysis/plan/captures.js +86 -14
  11. package/dist/analysis/plan/completed.js +8 -1
  12. package/dist/analysis/plan/conceded-out.js +16 -11
  13. package/dist/analysis/plan/deploy-estimates.js +544 -0
  14. package/dist/analysis/plan/doomed-out.js +135 -0
  15. package/dist/analysis/plan/estimates.js +4 -1
  16. package/dist/analysis/plan/free-capture.js +34 -0
  17. package/dist/analysis/plan/holds.js +8 -309
  18. package/dist/analysis/plan/horizon.js +42 -0
  19. package/dist/analysis/plan/leftover.js +43 -5
  20. package/dist/analysis/plan/observe.js +896 -0
  21. package/dist/analysis/plan/orders.js +35 -1
  22. package/dist/analysis/plan/report.js +10 -4
  23. package/dist/analysis/plan/shared.js +4 -1376
  24. package/dist/analysis/plan/spread-bind.js +49 -0
  25. package/dist/analysis/plan/stand-still.js +5 -3
  26. package/dist/analysis/plan/state.js +12 -0
  27. package/dist/analysis/plan/strike-stack.js +467 -0
  28. package/dist/analysis/plan/strike.js +3 -463
  29. package/dist/analysis/plan/targets.js +219 -28
  30. package/dist/analysis/plan/threats.js +23 -9
  31. package/dist/analysis/plan/transfers.js +24 -1
  32. package/dist/analysis/plan/two-move.js +1 -1
  33. package/dist/analysis/plan/withdraw.js +316 -0
  34. package/dist/analysis/planner.js +106 -43
  35. package/dist/analysis/player.js +4 -0
  36. package/dist/analysis/relations.js +8 -2
  37. package/dist/analysis/stress.js +1 -1
  38. package/dist/bundle.js +4578 -3405
  39. package/dist/cards.js +37 -0
  40. package/dist/my-games.js +2 -0
  41. package/dist/my-orders.js +134 -0
  42. package/dist/open-games.js +94 -10
  43. package/dist/team-cards.js +2 -2
  44. package/dist/team-orders.js +51 -23
  45. package/dist/tools/card-advice.js +57 -13
  46. package/dist/tools/card-support-advice.js +17 -1
  47. package/dist/tools/check-plan.js +2 -1
  48. package/dist/tools/commander-check.js +2 -1
  49. package/dist/tools/decision-capture.js +4 -2
  50. package/dist/tools/index.js +3 -0
  51. package/dist/tools/join-game.js +44 -8
  52. package/dist/tools/live.js +43 -5
  53. package/dist/tools/my-orders.js +110 -0
  54. package/dist/tools/open-games.js +2 -2
  55. package/dist/tools/picks.js +128 -51
  56. package/dist/tools/team-brief.js +1 -1
  57. package/dist/tools/team.js +25 -9
  58. package/dist/tools/turn.js +61 -6
  59. package/dist/tools/uncommit.js +27 -5
  60. package/dist/trend.js +36 -1
  61. package/dist/version.js +1 -1
  62. package/manifest.json +5 -1
  63. package/package.json +1 -1
  64. package/server.json +2 -2
  65. package/skills/warapp-mcp/SKILL.md +9 -2
@@ -14,13 +14,18 @@ export function targetsPhase(pc, ps, input, threats, hd) {
14
14
  const c1 = { ...c0, ...captureTargets(pc, ps, input, threats, c0) };
15
15
  const c2 = { ...c1, ...frontierCosts(pc, threats, hd, c1) };
16
16
  const c3 = { ...c2, ...bonusScoring(pc, ps, threats, c2) };
17
- const c4 = { ...c3, ...closestBonus(pc, ps, input, c3) };
17
+ const c4 = { ...c3, ...closestBonus(pc, ps, input, c3, hd) };
18
18
  // #281: the vacated land worth denying and (the owner's extension) the empty enemy territories
19
19
  // pass 3 may take, each judged once on the board as it stands.
20
20
  const denials = denialsOf(pc);
21
21
  const emptyEnemies = emptyEnemiesOf(pc, input.previousBoard, threats.reinforcementAt, (t) => c4.targets.has(t) || c4.repulsed.has(t) || pc.truce.noTarget(t));
22
22
  return { ...c4, denials, emptyEnemies };
23
23
  }
24
+ /**
25
+ * #430 (owner decision of 2026-11-22): a retake of a held bonus's lost members costs at most this many
26
+ * times the bonus's value — tighter than PAYBACK_TURNS (10), which the first draft used.
27
+ */
28
+ export const RETAKE_VALUE_TURNS = 5;
24
29
  /** The enemy bonuses I could break and the counter-attacks (under `balanced`, #72). */
25
30
  export function breakTargets(pc, input) {
26
31
  const { g, me, foe, balanced, territories: state, mineSet, unitsAt, costAt } = pc;
@@ -104,6 +109,57 @@ export function captureTargets(pc, ps, input, threats, prev) {
104
109
  const droppedMembers = new Set([...bonusDropped].flatMap((id) => (g.bonusById.has(id) ? bonusTerritories(g, id).filter((t) => !mineSet.has(t)) : [])));
105
110
  /** #421: the missing members of the contested bonuses a stockpile pushes all-in: targets, an opponent's included. */
106
111
  const pileMembers = new Set([...(input.stockpileAllIn ?? [])].flatMap((id) => (g.bonusById.has(id) ? bonusTerritories(g, id).filter((t) => !mineSet.has(t)) : [])));
112
+ /**
113
+ * #430: the opponents' territories that retake a bonus I held in full on `previousBoard`. Under
114
+ * `balanced` an enemy territory was only a break or counter target, so a held bonus that lost a
115
+ * member to a player was never retaken outside the 1v1 strike stack (0 of 166 breaks regained in
116
+ * planner-era games). Such a member is a bonus target, in every format, when the retake completes
117
+ * the bonus this turn (every missing member in view, beside mine, no special unit, a foe's or a
118
+ * neutral; none of #298's dropped members), its capture costs together are at most
119
+ * RETAKE_VALUE_TURNS (5) × the value, and the profile does not read me behind (behind, the turn goes to
120
+ * holds and strikes: the evidence's confound). It then competes as a completion in the bonus passes
121
+ * and rule 4a's greedy step, so a hold that scores higher is still funded first, and R3 still
122
+ * refuses a retake that cannot be held.
123
+ */
124
+ const retakeMembers = new Set();
125
+ if (balanced && input.previousBoard && profile.standing !== 'behind') {
126
+ const before = new Map(input.previousBoard.territories.map((t) => [t.territoryId, t]));
127
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
128
+ const ts = bonusTs.get(b.id) ?? [];
129
+ if (b.value <= 0 || !ts.length || ts.every((t) => mineSet.has(t)) || bonusDropped.has(b.id))
130
+ continue;
131
+ const heldBefore = ts.every((t) => {
132
+ const was = visibleState(before.get(t));
133
+ return was?.owner.kind === 'player' && was.owner.playerId === pc.me;
134
+ });
135
+ if (!heldBefore)
136
+ continue;
137
+ const missing = ts.filter((t) => !mineSet.has(t));
138
+ let cost = 0;
139
+ const ok = missing.every((t) => {
140
+ const st = state.get(t);
141
+ if (!st || st.armies === null || st.owner.kind === 'unknown' || st.owner.kind === 'available')
142
+ return false;
143
+ if (st.owner.kind === 'player' && (!foe(st.owner.playerId) || pc.truce.noTarget(t)))
144
+ return false;
145
+ if (uncounted(t) || droppedMembers.has(t) || !neighborsOf(g, t).some((n) => mineSet.has(n)))
146
+ return false;
147
+ const c = costAt(t);
148
+ if (c === null)
149
+ return false;
150
+ cost += c;
151
+ return true;
152
+ });
153
+ if (!ok || cost > RETAKE_VALUE_TURNS * b.value)
154
+ continue;
155
+ const theirs = missing.filter((t) => state.get(t).owner.kind === 'player');
156
+ if (!theirs.length)
157
+ continue;
158
+ for (const t of theirs)
159
+ retakeMembers.add(t);
160
+ rationale.push(`Retake ${theirs.map(label).join(', ')}: ${theirs.length > 1 ? 'they complete' : 'it completes'} bonus ${b.name} (+${b.value}) again, which I held in full last turn, for ${cost} armies (at most ${RETAKE_VALUE_TURNS} × its value), so ${theirs.length > 1 ? 'they are' : 'it is'} a bonus target (#430).`);
161
+ }
162
+ }
107
163
  /**
108
164
  * #240: territories my attacks failed on repeatedly while their owner reinforced them
109
165
  * (`input.repulsed`, {@link repulsedAttacks}): still that opponent's, armies in view, next to mine,
@@ -163,7 +219,7 @@ export function captureTargets(pc, ps, input, threats, prev) {
163
219
  continue;
164
220
  // #421: a stockpile's push spends armies already on the board: capped at the payback horizon × its value.
165
221
  const pile = input.stockpileAllIn?.has(bonusId) === true;
166
- const cap = pile ? Math.max(0, pc.paybackTurns * b.value) : Math.max(0, Math.min(ALL_IN_VALUE_TURNS * b.value, pc.income));
222
+ const cap = pile ? Math.max(0, pc.capturePaybackTurns * b.value) : Math.max(0, Math.min(ALL_IN_VALUE_TURNS * b.value, pc.income));
167
223
  const sized = [];
168
224
  let why;
169
225
  for (const t of bonusTerritories(g, bonusId).filter((x) => !mineSet.has(x))) {
@@ -189,7 +245,7 @@ export function captureTargets(pc, ps, input, threats, prev) {
189
245
  const cost = sized.reduce((n, x) => n + x.cost, 0);
190
246
  if (!why && cost > cap)
191
247
  why = pile
192
- ? `the push needs ${cost} armies, over the cap of ${cap} (${pc.paybackTurns} × its +${b.value}, #421)`
248
+ ? `the push needs ${cost} armies, over the cap of ${cap} (${pc.capturePaybackTurns} × its +${b.value}, #421)`
193
249
  : `the push needs ${cost} armies, over the cap of ${cap} (${ALL_IN_VALUE_TURNS} × its +${b.value}, at most my income ${pc.income})`;
194
250
  allInTries.set(bonusId, { feasible: !why, cost, cap, ...(why ? { detail: why } : {}) });
195
251
  if (why)
@@ -276,7 +332,7 @@ export function captureTargets(pc, ps, input, threats, prev) {
276
332
  continue;
277
333
  }
278
334
  const enemy = st.owner.kind === 'player';
279
- if (enemy && goal !== 'complete-bonus' && !(balanced && (breakMember.has(t) || counterAt.has(t))) && !pileMembers.has(t)) {
335
+ if (enemy && goal !== 'complete-bonus' && !(balanced && (breakMember.has(t) || counterAt.has(t))) && !pileMembers.has(t) && !retakeMembers.has(t)) {
280
336
  if (!leadStepsOn || unitsAt(t) > 0 || droppedMembers.has(t) || !g.map.bonuses.some((b) => b.value > 0 && bonusTs.get(b.id).includes(t)))
281
337
  continue;
282
338
  const defenders = defenceAt(t);
@@ -297,7 +353,8 @@ export function captureTargets(pc, ps, input, threats, prev) {
297
353
  // Bonus passes work toward my own bonuses; under `balanced` enemy targets are only break candidates.
298
354
  // #203: a lead step is a bonus target too.
299
355
  // #421: a member of a contested bonus a stockpile pushes all-in is a bonus target too.
300
- const bonusTarget = (t) => targets.has(t) && !(balanced && targets.get(t).enemy && !leadSteps.has(t) && !pileMembers.has(t));
356
+ // #430: a member that retakes a bonus I held last turn is a bonus target too.
357
+ const bonusTarget = (t) => targets.has(t) && !(balanced && targets.get(t).enemy && !leadSteps.has(t) && !pileMembers.has(t) && !retakeMembers.has(t));
301
358
  return { targets, leadSteps, leadStepsOn, leadTry, leadNote, bonusTarget, repulsed, costFor, sizeOf, allInTries, bonusDropped, droppedMembers };
302
359
  }
303
360
  /** Rule 4d: what a capture adds to the frontier (#71), and the offence report (#72). */
@@ -398,13 +455,26 @@ export function frontierCosts(pc, threats, hd, prev) {
398
455
  }
399
456
  return { borders, enemyBorders, holdCost };
400
457
  };
458
+ /**
459
+ * #433: each border's share of {@link frontierOf}'s hold cost (the same borders: a conceded one only while its
460
+ * garrison stands), for the Local Deployment pools that can pay it.
461
+ */
462
+ const frontierNeeds = (held, haveOf) => {
463
+ const needs = new Map();
464
+ for (const x of [...held].sort(byNum)) {
465
+ const b = borderOf(x, held, haveOf(x));
466
+ if ((!conceded.has(x) || stood.has(x)) && b.need > 0)
467
+ needs.set(x, b.need);
468
+ }
469
+ return needs;
470
+ };
401
471
  /** The frontier's hold cost at the start of the turn (my armies then; today's concessions left out). */
402
472
  const startHold = () => frontierOf(mineSet, armiesOf).holdCost;
403
- return { survivorsOf, borderOf, borderCost, frontierDelta, edgeCost, scoreCost, targetScoreCost, landScoreCost, offence, offenceSkip, skipOffence, badTrades, frontierOf, startHold };
473
+ return { survivorsOf, borderOf, borderCost, frontierDelta, edgeCost, scoreCost, targetScoreCost, landScoreCost, offence, offenceSkip, skipOffence, badTrades, frontierOf, frontierNeeds, startHold };
404
474
  }
405
475
  /** Bonus scoring (rule 4, R3, #70, #101, #125, #167): the bonuses worth working toward, best first. */
406
476
  export function bonusScoring(pc, ps, threats, prev) {
407
- const { g, s, opts, guarded, focus, paybackTurns, territories: state, label, mineSet, armiesOf, defenceAt, completedOver, territoryShare, rates, costOf, costAt, econCostAt, } = pc;
477
+ const { g, s, opts, guarded, focus, capturePaybackTurns: paybackTurns, territories: state, label, mineSet, armiesOf, defenceAt, completedOver, territoryShare, rates, costOf, costAt, econCostAt, } = pc;
408
478
  const { rationale } = ps;
409
479
  const { exposure } = threats;
410
480
  const { targets, bonusTarget, survivorsOf, frontierDelta, scoreCost } = prev;
@@ -428,6 +498,16 @@ export function bonusScoring(pc, ps, threats, prev) {
428
498
  const wasteShare = s.wastelands && s.wastelands.count > 0 && s.wastelands.size > 0 && g.territoryById.size > 0
429
499
  ? Math.min(1, s.wastelands.count / g.territoryById.size)
430
500
  : 0;
501
+ /**
502
+ * #432: a visible neutral at the game's wasteland size or more, when the game has wastelands larger than its
503
+ * ordinary neutrals (`neutralArmies`, when the settings give it).
504
+ */
505
+ const isWasteland = (st) => s.wastelands !== undefined &&
506
+ s.wastelands.count > 0 &&
507
+ s.wastelands.size > (s.neutralArmies ?? 0) &&
508
+ st.owner.kind === 'neutral' &&
509
+ st.armies !== null &&
510
+ st.armies >= s.wastelands.size;
431
511
  const wasteCost = wasteShare > 0 ? (costOf(s.wastelands.size) ?? Infinity) : 0;
432
512
  const wasteLoss = wasteShare > 0 ? Math.min(wasteCost - 1, straightKills(s.wastelands.size, rates.defensiveKillRate)) + 1 : 0;
433
513
  /** Every positive bonus worth completing (net > 0) still missing members: its armies to finish (rule 4e). */
@@ -456,10 +536,12 @@ export function bonusScoring(pc, ps, threats, prev) {
456
536
  const neutralSize = s.neutralArmies !== undefined && s.neutralArmies >= 0 ? s.neutralArmies : undefined;
457
537
  const neutralCost = neutralSize !== undefined ? (costOf(neutralSize) ?? Infinity) : Infinity;
458
538
  const neutralLoss = neutralSize !== undefined && Number.isFinite(neutralCost) ? Math.min(neutralCost - 1, straightKills(neutralSize, rates.defensiveKillRate)) + 1 : Infinity;
539
+ // #435: whether the Gift card is in play (the shared-bonus handover needs it).
540
+ const giftInPlay = pc.game.cardsInPlay?.includes('Gift') === true;
459
541
  for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
460
542
  const isFocus = focus.has(b.id);
461
543
  const ts = bonusTerritories(g, b.id);
462
- const remaining = ts.filter((t) => !mineSet.has(t));
544
+ let remaining = ts.filter((t) => !mineSet.has(t));
463
545
  if (b.value < 0 && !isFocus) {
464
546
  // Completing it would cut income: never plan into it (an economic
465
547
  // membership elsewhere still wins — see the pass-3 filter).
@@ -482,13 +564,26 @@ export function bonusScoring(pc, ps, threats, prev) {
482
564
  // PLAN-TEAMS C3.3: a bonus pays only the player holding every member, so one with a member my
483
565
  // teammate visibly holds is not mine to complete (plan/team.ts reports the shared ones).
484
566
  const mates = remaining.filter((t) => teammateAt(pc, t));
485
- if (mates.length) {
567
+ // #435 (proposed rule): one of us must work a shared bonus, or nobody does (45701358: four, +69,
568
+ // left to plain expansion). Whoever holds the most members (`nearer`, as team.sharedBonuses reads
569
+ // it) works it: when that is me, alone, its other members are scored as mine to take, and the
570
+ // teammate's members are theirs to hand over (a Gift) — never captured, never costed, and never
571
+ // a completion this turn (`completable` false while they stand), so no income is claimed for it.
572
+ // Owner decision 2026-11-22: only with the Gift card in play — the handover needs one; without it
573
+ // (or the cards unread) a shared bonus is skipped as before.
574
+ const handover = mates.length ? (giftInPlay && nearerMe(pc, ts) ? mates : undefined) : [];
575
+ if (handover === undefined) {
486
576
  if (remaining.some(bonusTarget) || isFocus)
487
577
  rationale.push(`Skip bonus ${b.name} (#${b.id}): my teammate holds ${mates.map(label).join(', ')}, and a bonus pays only the player holding all of it.`);
488
578
  if (isFocus)
489
579
  ps.warnings.push(`Focus on bonus ${b.name} (#${b.id}) ignored: my teammate holds ${mates.map(label).join(', ')} (one owner per bonus).`);
490
580
  continue;
491
581
  }
582
+ if (handover.length) {
583
+ remaining = remaining.filter((t) => !handover.includes(t));
584
+ if (!remaining.length)
585
+ continue;
586
+ }
492
587
  // Cluster as a unit (#70): the negative bonuses its missing members complete come off its
493
588
  // worth (on a map without negative bonuses, net = value).
494
589
  const rest = new Set(remaining);
@@ -519,6 +614,8 @@ export function bonusScoring(pc, ps, threats, prev) {
519
614
  // #125: the economy test charges the armies lost, not the armies sent.
520
615
  let loss = 0;
521
616
  let worstLoss = 0;
617
+ /** #432: its missing members in view that are wastelands. */
618
+ const wastelands = [];
522
619
  const known = (t, armies) => {
523
620
  const c = costAt(t, armies) ?? Infinity;
524
621
  cost += c;
@@ -567,6 +664,8 @@ export function bonusScoring(pc, ps, threats, prev) {
567
664
  const c = costAt(t) ?? Infinity;
568
665
  cost += c;
569
666
  worst = Math.max(worst, c);
667
+ if (isWasteland(st))
668
+ wastelands.push(t);
570
669
  const l = econCostAt(t);
571
670
  loss += l;
572
671
  worstLoss = Math.max(worstLoss, l);
@@ -607,21 +706,42 @@ export function bonusScoring(pc, ps, threats, prev) {
607
706
  cost += fogged * fogEach + foggedNeutral * neutralEach;
608
707
  loss += fogged * fogLoss + foggedNeutral * neutralEachLoss;
609
708
  const fogNeutral = foggedNeutral ? { count: foggedNeutral, each: neutralEach, size: neutralSize } : undefined;
709
+ // #432: while the gate budget is short, no bonus is built through a wasteland: its armies go to the gates —
710
+ // unless this turn's captures can complete it (owner decision 2026-11-22: a completing wasteland is taken).
711
+ const wasteStop = !isFocus && pc.shortGates !== undefined && wastelands.length > 0 && !remaining.every(bonusTarget);
712
+ const economic = isFocus || (loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net && !wasteStop);
713
+ // #435: a shared bonus I am nearer to but that is not worth working stays as C3.3 left it — skipped
714
+ // with its members plain expansion, never marked uneconomic (45701358 turn 1: a 344-member super-bonus,
715
+ // 6 members to my teammate's 5, would otherwise have stopped expansion into all its members).
716
+ if (handover.length && !economic) {
717
+ if (remaining.some(bonusTarget))
718
+ rationale.push(`Skip bonus ${b.name} (#${b.id}): my teammate holds ${handover.map(label).join(', ')}, and a bonus pays only the player holding all of it.`);
719
+ continue;
720
+ }
610
721
  if (b.value > 0)
611
722
  finishCost.set(b.id, { cost, value: b.value, net, fogged, fogEach, ...(fogNeutral ? { fogNeutral } : {}) });
612
- const economic = isFocus || (loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net);
613
723
  for (const t of remaining)
614
724
  (economic ? economicMember : uneconomicMember).add(t);
615
725
  if (!remaining.some(bonusTarget))
616
726
  continue;
727
+ if (!economic && wasteStop && loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net) {
728
+ rationale.push(`Skip bonus ${b.name} (#${b.id}): finishing it means taking the wasteland${wastelands.length === 1 ? '' : 's'} ${wastelands.map(label).join(', ')} (${s.wastelands.size} armies or more) while the gates facing player ${pc.shortGates.player} are ${pc.shortGates.deficit} short (#432).`);
729
+ continue;
730
+ }
617
731
  if (!economic) {
618
732
  rationale.push(`Skip bonus ${b.name} (#${b.id}): uneconomic for +${net === b.value ? b.value : `${b.value} (net +${net})`} (${toFinish(cost, { fogged, fogEach, fogNeutral })}, losing ~${loss}; ${worstLoss} lost on its costliest territory).`);
619
733
  continue;
620
734
  }
735
+ // #435: said once the bonus is worth working (an uneconomic one says only that).
736
+ if (handover.length) {
737
+ const mineN = ts.filter((t) => mineSet.has(t)).length;
738
+ rationale.push(`Bonus ${b.name} (#${b.id}): I hold ${mineN} of its ${ts.length} members, my teammate ${handover.length} — I am nearer, so it is mine to work ` +
739
+ `(#435); it pays only once my teammate hands over ${handover.map(label).join(', ')} (a Gift), so no capture here completes it.`);
740
+ }
621
741
  // R3: what holding the completed bonus's frontier would cost next turn (each
622
742
  // remaining member holding the survivors of its capture, mine their armies now).
623
743
  let defenseCost = 0;
624
- if (guarded && remaining.every(bonusTarget)) {
744
+ if (guarded && !handover.length && remaining.every(bonusTarget)) {
625
745
  const rem = new Set(remaining);
626
746
  const exposed = exposure(ts, (n) => rem.has(n), (m) => {
627
747
  if (!rem.has(m))
@@ -635,13 +755,14 @@ export function bonusScoring(pc, ps, threats, prev) {
635
755
  }
636
756
  // #71: the frontier its missing members add (their hold need left out when R3 judged it).
637
757
  const reach = remaining.filter((t) => targets.has(t));
638
- const frontier = frontierDelta(mineSet, reach, (x) => (mineSet.has(x) ? armiesOf(x) : survivorsOf(x)), !(guarded && remaining.every(bonusTarget))).armies;
758
+ const frontier = frontierDelta(mineSet, reach, (x) => (mineSet.has(x) ? armiesOf(x) : survivorsOf(x)), !(guarded && !handover.length && remaining.every(bonusTarget))).armies;
639
759
  plans.push({
640
760
  bonusId: b.id,
641
761
  value: b.value,
642
762
  focus: isFocus,
643
763
  remaining,
644
- completable: remaining.every(bonusTarget),
764
+ // #435: never complete while a teammate's member is still theirs.
765
+ completable: !handover.length && remaining.every(bonusTarget),
645
766
  cost,
646
767
  borders: analyzeBonus(g, b.id).borderTerritoryIds.length,
647
768
  defenseCost,
@@ -659,16 +780,32 @@ export function bonusScoring(pc, ps, threats, prev) {
659
780
  plans.sort((a, b) => Number(b.focus) - Number(a.focus) || ratio(b) - ratio(a) || a.borders - b.borders || a.bonusId - b.bonusId);
660
781
  return { fogNote, toFinish, plans, wasteShare, wasteCost, wasteLoss, finishCost, economicMember, uneconomicMember, negativeMember, rememberedSaid, ratio };
661
782
  }
783
+ /**
784
+ * #435: whether I alone hold the most members of `ts` among me and each teammate visibly holding one
785
+ * (the `nearer` of team.sharedBonuses, plan/team.ts); a tie is nobody's.
786
+ */
787
+ function nearerMe(pc, ts) {
788
+ const mine = ts.filter((t) => pc.mineSet.has(t)).length;
789
+ const per = new Map();
790
+ for (const t of ts) {
791
+ const o = pc.territories.get(t)?.owner;
792
+ if (o?.kind === 'player' && pc.allies.has(o.playerId))
793
+ per.set(o.playerId, (per.get(o.playerId) ?? 0) + 1);
794
+ }
795
+ return mine > Math.max(0, ...per.values());
796
+ }
662
797
  /** #319: the opening warning's bound: at least this many territories held with no bonus. */
663
798
  export const SPREAD_TERRITORIES = 10;
664
799
  /** #319: the last turn the opening warning runs on (from turn 2). */
665
800
  export const SPREAD_LAST_TURN = 6;
666
801
  /** #319: "near base": an income at most this much above the base income. */
667
802
  export const SPREAD_INCOME_SLACK = 3;
803
+ /** #416: the least value a bonus held in full needs to end rule 4f's commitment and #319's warning. */
804
+ export const HOLDS_BONUS_MIN_VALUE = 2;
668
805
  /** #101: commit to the bonus closest to completion; a break's retake check; #319's spread warning. */
669
- export function closestBonus(pc, ps, input, prev) {
670
- const { g, me, income, profile, territories: state, label, bonusName, mine, mineSet, bonusTs, toTake } = pc;
671
- const { rationale } = ps;
806
+ export function closestBonus(pc, ps, input, prev, hd) {
807
+ const { g, me, income, profile, territories: state, label, bonusName, mine, mineSet, bonusTs, toTake, armiesOf, guard } = pc;
808
+ const { rationale, avail } = ps;
672
809
  const { fogNote, plans } = prev;
673
810
  // ---- #101: commit to the closest bonus ----
674
811
  // While no bonus is held (and in the opening and expansion phases), expansion goes to the bonus
@@ -678,10 +815,18 @@ export function closestBonus(pc, ps, input, prev) {
678
815
  // army of every bonus their capture completes (#438: a pair bonus on top of a single-territory one
679
816
  // counts), then a bonus advanced last turn (a member captured since `previousBoard`) first, then the
680
817
  // score order (value per army, rule 4). Focused bonuses come first.
681
- const holdsBonus = g.map.bonuses.some((b) => {
818
+ // #416: a bonus held counts only from HOLDS_BONUS_MIN_VALUE up: one point of income is no base to build
819
+ // on, and holding a +1 silenced #319 in a live game while the captures stayed spread.
820
+ const heldValues = g.map.bonuses
821
+ .filter((b) => {
682
822
  const ts = bonusTs.get(b.id);
683
823
  return b.value > 0 && ts.length > 0 && ts.every((t) => mineSet.has(t));
684
- });
824
+ })
825
+ .map((b) => b.value);
826
+ const holdsBonus = heldValues.some((v) => v >= HOLDS_BONUS_MIN_VALUE);
827
+ /** #416: a bonus is held, but none worth HOLDS_BONUS_MIN_VALUE: the lines say so instead of "no bonus". */
828
+ const holdsSmallOnly = !holdsBonus && heldValues.length > 0;
829
+ const noBonusText = holdsSmallOnly ? `no bonus worth more than +${HOLDS_BONUS_MIN_VALUE - 1}` : 'no bonus';
685
830
  // #132: in an FFA, contact with one front still leaves neutrals to expand into: keep committing
686
831
  // while any neutral borders a territory of mine.
687
832
  const neutralsInReach = profile.format === 'ffa' && mine.some((t) => neighborsOf(g, t).some((n) => state.get(n)?.owner.kind === 'neutral'));
@@ -705,8 +850,38 @@ export function closestBonus(pc, ps, input, prev) {
705
850
  */
706
851
  const fromMine = bfsDistances(g, mine);
707
852
  const depthOf = (p) => Math.max(0, ...p.remaining.map((t) => fromMine.get(t) ?? 0));
708
- /** Turns to finish a bonus at this income, and at least its depth (with no income, its armies to finish). */
709
- const turnsOf = (p) => (income > 0 ? Math.max(Math.ceil(p.cost / income), depthOf(p)) : p.cost);
853
+ /**
854
+ * #416: the armies already standing beside a bonus's missing members — each territory of mine next to
855
+ * one, counted once, with what it can send beyond the guard and beyond what holds it (`keepFor`:
856
+ * exact holds come first). A start on 10 armies beside a bonus finishes it without waiting for the
857
+ * income, so counting only the income ranked it level with a bonus the deploys need two turns for.
858
+ */
859
+ const standing = new Map();
860
+ const standingBeside = (p) => {
861
+ const was = standing.get(p.bonusId);
862
+ if (was !== undefined)
863
+ return was;
864
+ const rest = new Set(p.remaining);
865
+ let n = 0;
866
+ for (const x of mine) {
867
+ if (!neighborsOf(g, x).some((t) => rest.has(t)))
868
+ continue;
869
+ const movable = Math.min(avail.get(x) ?? 0, armiesOf(x) - guard);
870
+ const keep = hd ? hd.keepFor(x, () => false) : 0;
871
+ n += Math.max(0, movable - keep);
872
+ }
873
+ const credit = Math.min(n, p.cost);
874
+ standing.set(p.bonusId, credit);
875
+ return credit;
876
+ };
877
+ /**
878
+ * Turns to finish a bonus at this income once the armies standing beside it are spent (#416), and at
879
+ * least its depth (with no income, its armies to finish less those).
880
+ */
881
+ const turnsOf = (p) => {
882
+ const left = Math.max(0, p.cost - standingBeside(p));
883
+ return income > 0 ? Math.max(Math.ceil(left / income), depthOf(p)) : left;
884
+ };
710
885
  const scoreRank = new Map(plans.map((p, i) => [p.bonusId, i]));
711
886
  /**
712
887
  * #438: every bonus a plan's capture completes — each plan whose missing members are all among
@@ -719,28 +894,40 @@ export function closestBonus(pc, ps, input, prev) {
719
894
  const r = prev.ratio(p);
720
895
  return Number.isFinite(r) && p.net > 0 ? (r * incomeOf(p)) / p.net : r;
721
896
  };
897
+ /** #416: its missing members in the fog, however each is costed. */
898
+ const foggedOf = (p) => p.fogged + (p.fogNeutral?.count ?? 0);
722
899
  /**
723
900
  * Bonus plans closest to completion first (focus first; ties: the income per army of every bonus
724
- * the capture completes, #438, then advanced last turn, then the score order).
901
+ * the capture completes, #438, then #416's fewer armies to finish and fewer fogged members — the
902
+ * figure least likely to be wrong —, then advanced last turn, then the score order). #416 asked for
903
+ * its keys first; ahead of #438 they ranked a cheap +3 over completing a bonus that lifts a −8
904
+ * penalty (negative-bonuses (c): next income 20 → lower), so they only split what #438 leaves even.
725
905
  */
726
906
  const byCloseness = committing
727
907
  ? [...plans].sort((a, b) => Number(b.focus) - Number(a.focus) ||
728
908
  turnsOf(a) - turnsOf(b) ||
729
909
  perArmy(b) - perArmy(a) ||
910
+ a.cost - b.cost ||
911
+ foggedOf(a) - foggedOf(b) ||
730
912
  Number(advancedLast.has(b.bonusId)) - Number(advancedLast.has(a.bonusId)) ||
731
913
  scoreRank.get(a.bonusId) - scoreRank.get(b.bonusId))
732
914
  : plans;
733
915
  const turnsText = (p) => {
734
916
  const n = turnsOf(p);
735
- const deep = n > Math.ceil(p.cost / income) ? ` (${n} layers deep)` : '';
917
+ const deep = n > Math.max(1, Math.ceil(Math.max(0, p.cost - standingBeside(p)) / income)) ? ` (${n} layers deep)` : '';
736
918
  return income > 0 ? `${n} turn${n === 1 ? '' : 's'}${deep}` : 'no income';
737
919
  };
920
+ /** #416: the armies standing beside it, when any count toward its turns. */
921
+ const standingNote = (p) => {
922
+ const n = standingBeside(p);
923
+ return n > 0 ? ` (${n} standing beside it)` : '';
924
+ };
738
925
  if (committing && byCloseness.length > 1) {
739
926
  const why = holdsBonus
740
927
  ? `${profile.phase[0].toUpperCase()}${profile.phase.slice(1)} phase${profile.phase === 'opening' || profile.phase === 'expansion' ? '' : ', neutrals in reach'}`
741
- : 'No bonus held';
928
+ : `${noBonusText[0].toUpperCase()}${noBonusText.slice(1)} held`;
742
929
  rationale.push(`${why}: expansion goes to the bonus closest to completion first — ${byCloseness
743
- .map((p, i) => `${bonusName(p.bonusId)} ${i ? p.cost : `${p.cost} armies to finish`}${fogNote(p)}, ${turnsText(p)}${i || income <= 0 ? '' : ` at income ${income}`}`)
930
+ .map((p, i) => `${bonusName(p.bonusId)} ${i ? p.cost : `${p.cost} armies to finish`}${fogNote(p)}${standingNote(p)}, ${turnsText(p)}${i || income <= 0 ? '' : ` at income ${income}`}`)
744
931
  .join(', ')} — and a farther bonus gets only armies the closer ones cannot use.`);
745
932
  const top = byCloseness.find((p) => !p.focus);
746
933
  // #438: a capture that completes more than one bonus says what they add up to per army.
@@ -765,9 +952,12 @@ export function closestBonus(pc, ps, input, prev) {
765
952
  }
766
953
  // #319: in the opening (turns 2–6), many territories on an income near base means the captures are
767
954
  // spread over bonuses and none completed (six lost games held 11–20 territories on 8 or less after
768
- // turn 4). A warning only, naming rule 4f's nearest bonus with its armies and turns: no order changes.
955
+ // turn 4). The warning names rule 4f's nearest bonus with its armies and turns; #416 (owner 2026-11-22) binds
956
+ // the deploys to it (plan/spread-bind.ts).
769
957
  const turnNow = pc.game.turn ?? null;
770
958
  const base = Math.max(0, Math.floor(input.settings?.baseIncome ?? DEFAULT_BASE_INCOME));
959
+ /** #416 part 4: the nearest bonus #319 names, whose reachable steps the deploys are bound to (plan/spread-bind.ts). */
960
+ let spreadNearest;
771
961
  if (turnNow !== null &&
772
962
  turnNow >= 2 &&
773
963
  turnNow <= SPREAD_LAST_TURN &&
@@ -775,9 +965,10 @@ export function closestBonus(pc, ps, input, prev) {
775
965
  mine.length >= SPREAD_TERRITORIES &&
776
966
  income <= base + SPREAD_INCOME_SLACK) {
777
967
  const nearest = committing ? byCloseness.find((p) => !p.focus) ?? byCloseness[0] : undefined;
778
- ps.warnings.push(`${mine.length} territories, no bonus: the captures are spread (income ${income}, base ${base}). ` +
968
+ spreadNearest = nearest;
969
+ ps.warnings.push(`${mine.length} territories, ${noBonusText}: the captures are spread (income ${income}, base ${base}). ` +
779
970
  (nearest
780
- ? `Nearest bonus to complete: ${bonusName(nearest.bonusId)}, ${nearest.cost} armies to finish${fogNote(nearest)}, ` +
971
+ ? `Nearest bonus to complete: ${bonusName(nearest.bonusId)}, ${nearest.cost} armies to finish${fogNote(nearest)}${standingNote(nearest)}, ` +
781
972
  `${turnsText(nearest)}${income > 0 ? ` at income ${income}` : ''} (rule 4f).`
782
973
  : 'No bonus is worth completing from here.') +
783
974
  ' Complete one before taking more territories outside it (#319).');
@@ -793,5 +984,5 @@ export function closestBonus(pc, ps, input, prev) {
793
984
  ? `${label(t)} can be retaken after it breaks ${bonusName(bonusId)}: ${survivors} survivors need ${take} to take, against ~${counter} next turn.`
794
985
  : undefined;
795
986
  };
796
- return { holdsBonus, neutralsInReach, committing, advancedLast, fromMine, depthOf, turnsOf, scoreRank, byCloseness, turnsText, retakeChecks, retakeWarning };
987
+ return { holdsBonus, neutralsInReach, committing, advancedLast, fromMine, depthOf, turnsOf, scoreRank, byCloseness, turnsText, spreadNearest, retakeChecks, retakeWarning };
797
988
  }
@@ -10,7 +10,7 @@ import { bfsDistances, neighborsOf } from '../graph.js';
10
10
  import { couldHoldBonusPools, enemyDeployReaching, freeIncome } from '../local-deploy.js';
11
11
  import { incomeBasis, LOST_STACK_TURNS } from '../opponents.js';
12
12
  import { HIDDEN_POOL_INCOMES, MAX_NAMED_REVEALS, coverageText, LOW_COVERAGE, MIN_ENEMY_DEPLOY, openingArmies, ownerShown, visibleState, } from './shared.js';
13
- import { territoryIncome } from '../player.js';
13
+ import { gameBaseIncome, territoryIncome } from '../player.js';
14
14
  import { simTerritories } from '../turn-sim.js';
15
15
  import { byNum } from './util.js';
16
16
  /** Read the threats against my territories, and state them. */
@@ -141,6 +141,8 @@ export function threatSources(pc, ps, input) {
141
141
  // anywhere, so what an estimate holds beyond every bonus it could hold counts as free; without it, a
142
142
  // border faces only the free income and the pools there.
143
143
  const perTerritory = (s.bonusArmyPer ?? 0) > 0;
144
+ /** #433: the free income's floor is the game's own base income (0 and 3 exist), not the 5 of the default. */
145
+ const gameBase = gameBaseIncome(s);
144
146
  if (s.localDeployments && !custom) {
145
147
  const foes = [...new Set([...state.values()].flatMap((t) => (t.owner.kind === 'player' && foe(t.owner.playerId) ? [t.owner.playerId] : [])))].sort(byNum);
146
148
  for (const [p, pools] of couldHoldBonusPools(g, foes, (t) => {
@@ -149,7 +151,7 @@ export function threatSources(pc, ps, input) {
149
151
  })) {
150
152
  enemyPools.set(p, pools);
151
153
  const e = estimates.get(p);
152
- const free = freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0);
154
+ const free = freeIncome(e?.base ?? 0, gameBase, e?.card?.armies ?? 0);
153
155
  const pooled = pools.reduce((n, q) => n + q.value, 0);
154
156
  const figure = deployOf(p);
155
157
  if (perTerritory && figure - pooled > free)
@@ -168,7 +170,7 @@ export function threatSources(pc, ps, input) {
168
170
  if (!pools)
169
171
  return figure;
170
172
  const e = estimates.get(player);
171
- return enemyDeployReaching(figure, freeIncome(e?.base ?? 0, MIN_ENEMY_DEPLOY, e?.card?.armies ?? 0), pools, on, perTerritory);
173
+ return enemyDeployReaching(figure, freeIncome(e?.base ?? 0, gameBase, e?.card?.armies ?? 0), pools, on, perTerritory);
172
174
  };
173
175
  /**
174
176
  * #120: what the owner of enemy territory `t` may add there before my attack lands — its deploy
@@ -244,7 +246,8 @@ export function threatSources(pc, ps, input) {
244
246
  const tr = input.tracks?.find((x) => x.playerId === player);
245
247
  // Its income, a Reinforcement card left out: the card is counted once, in the deploy.
246
248
  const e = estimates.get(player);
247
- const income = Math.max(tr?.income ?? 0, (e?.estimate ?? 0) - (e?.card?.armies ?? 0));
249
+ // #427: a tracked figure a card play had set counts without it.
250
+ const income = Math.max(e?.cardInTrack ? e.cardInTrack.income : (tr?.income ?? 0), (e?.estimate ?? 0) - (e?.card?.armies ?? 0));
248
251
  return {
249
252
  unexplained: Math.max(0, Math.floor(tr?.unexplained ?? 0)),
250
253
  cap: income > 0 ? HIDDEN_POOL_INCOMES * income : null,
@@ -992,13 +995,24 @@ export function borderThreats(pc, ps, input, src, forces) {
992
995
  const used = track.turns.filter((x) => e.trackedTurns.includes(x.from));
993
996
  rationale.push(`Tracked income for player ${p}: ~${e.tracked}/turn (${incomeBasis(track)}): ${used.map((x) => `turn ${x.from} +${x.observed}`).join(', ')}, each observed deploy a lower bound under fog${e.coverage ? `, read from ${coverageText(e.coverage)}` : ''}; at least its visible base + bonuses ${track.visibleIncome}; used in place of the single-turn observed figure (warapp_track_opponents has the details).`);
994
997
  }
995
- // #164: a Reinforcement card the clock says it may hold, on top of its income.
998
+ // #427: a card play the tracker read as income, taken out of its figure.
999
+ if (e.cardInTrack) {
1000
+ const c = e.cardInTrack;
1001
+ warnings.push(`Player ${p}'s tracked income of ${c.was} counts the Reinforcement card it played on turn ${c.turns.join(', ')}: ${c.income} without it (#427), so the card is counted once, on the clock, not carried as income.`);
1002
+ }
1003
+ // #164: a Reinforcement card the clock says it may hold, on top of its income. #427: with card plays
1004
+ // not fogged, a play is seen in the orders, and the next card is due its capturing turns after it.
1005
+ const cardPlaysRead = input.game?.reinforcementPlays !== undefined;
1006
+ const perCard = input.game?.reinforcement?.turnsPerCard;
1007
+ const cardDue = (t) => (perCard === null || perCard === undefined ? 'never (no further card comes)' : `turn ${t + Math.max(1, perCard)}`);
996
1008
  if (e.card)
997
- warnings.push(`Player ${p} may hold a Reinforcement card from turn ${e.card.due} (the card clock${e.cardPlayed !== null ? `; it last played one on turn ${e.cardPlayed}` : ''}): +${e.card.armies} added to its deploy, ~${e.estimate} in all, until a deployment above its income is seen; one card at most is counted, though more may be in hand after a long time due.`);
1009
+ warnings.push(`Player ${p} may hold a Reinforcement card from turn ${e.card.due} (the card clock${e.cardPlayed !== null ? `; it last played one on turn ${e.cardPlayed}${e.cardSeen ? ', seen in the orders' : ''}` : ''}): +${e.card.armies} added to its deploy, ~${e.estimate} in all, until ${cardPlaysRead ? 'a play is seen in the orders' : 'a deployment above its income is seen'}; one card at most is counted, though more may be in hand after a long time due.`);
998
1010
  else if (e.cardPlayed !== null)
999
- warnings.push(e.source === 'exact'
1000
- ? `Player ${p}'s Reinforcement card is taken as played on turn ${e.cardPlayed} (a deployment above its exact income), so none is added until the next can be due; armies the board misread, or that moved into view out of a territory whose armies the fog hid, can look the same, so it may still hold one and the estimate errs low.`
1001
- : `Player ${p}'s Reinforcement card is taken as played on turn ${e.cardPlayed} (a deployment of a card's armies over its visible income), so none is added until the next can be due; income the fog hides can look the same, so it may still hold one and the estimate errs low.`);
1011
+ warnings.push(e.cardSeen
1012
+ ? `Player ${p} played a Reinforcement card on turn ${e.cardPlayed} (seen in that turn's orders: card plays are not fogged in this game), so none is added until the next can be due: ${cardDue(e.cardPlayed)}.`
1013
+ : e.source === 'exact'
1014
+ ? `Player ${p}'s Reinforcement card is taken as played on turn ${e.cardPlayed} (a deployment above its exact income), so none is added until the next can be due; armies the board misread, or that moved into view out of a territory whose armies the fog hid, can look the same, so it may still hold one and the estimate errs low.`
1015
+ : `Player ${p}'s Reinforcement card is taken as played on turn ${e.cardPlayed} (a deployment of a card's armies over its visible income), so none is added until the next can be due; income the fog hides can look the same, so it may still hold one and the estimate errs low.`);
1002
1016
  // #164: the income behind the estimate; a card the clock adds is named on top of it.
1003
1017
  const income = e.estimate - (e.card?.armies ?? 0);
1004
1018
  // G2 (D3): Sanctions on it the decoder is sure of — applied to a figure read off the board only.
@@ -188,6 +188,12 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
188
188
  }
189
189
  return border === undefined ? undefined : { border, front: at };
190
190
  };
191
+ // Rule 6's last target (owner, 2026-11-22; golden s246): with no enemy front and no territory not mine
192
+ // reachable without crossing a border the plan concedes — the last neutral taken, the enemy past those
193
+ // borders — a stack had no target and stood deep inside. It walks up behind the conceded borders on the way to
194
+ // the enemy instead: never into one (the plan gives it up), and one already beside one waits there (#367).
195
+ const behind = [...conceded].filter((c) => held.has(c) && distEnemyThrough.has(c));
196
+ const distBehind = bfsDistances(g, behind, { passable });
191
197
  // #125: staging. Idle armies on a territory facing no visible enemy — a border beside neutrals
192
198
  // included — walk one step toward the source of the capture the leftover saved toward, when
193
199
  // it is no farther than the enemy front; once there they help take it.
@@ -254,7 +260,8 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
254
260
  distEnemyVia.get(t) < (distEnemy.get(t) ?? Infinity) &&
255
261
  distEnemyVia.get(t) <= (distAny.get(t) ?? Infinity) &&
256
262
  !neighborsOf(g, t).some((x) => isEnemy(x));
257
- const dist = via ? distEnemyVia : distEnemy.has(t) ? distEnemy : distAny;
263
+ const toConceded = !via && !distEnemy.has(t) && !distAny.has(t) && distBehind.has(t);
264
+ const dist = via ? distEnemyVia : distEnemy.has(t) ? distEnemy : toConceded ? distBehind : distAny;
258
265
  const n = avail.get(t);
259
266
  if (n <= 0 || locked.has(t))
260
267
  continue;
@@ -280,6 +287,16 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
280
287
  const steps = neighborsOf(g, t)
281
288
  .filter((x) => mineSet.has(x) &&
282
289
  (via ? viaOk(x) : !conceded.has(x)) &&
290
+ // Behind a conceded border: up to the territory beside it, never into it — nor into a territory an attack
291
+ // leaves from this turn or one beside a rival at the start of the turn (an interior walk, not a strike's
292
+ // reinforcement: golden s1405's would have run before the strike that ends a player, taking its first slot).
293
+ (!toConceded ||
294
+ ((dist.get(x) ?? 0) >= 1 &&
295
+ !moves.some((m) => m.from === x && m.kind === 'attack') &&
296
+ !neighborsOf(g, x).some((y) => {
297
+ const o = state.get(y)?.owner;
298
+ return o?.kind === 'player' && o.playerId !== me && !teammateAt(pc, y);
299
+ }))) &&
283
300
  (dist.get(x) ?? Infinity) < d &&
284
301
  capStepRoom(pc, ps, t, x) > 0)
285
302
  .sort((a, b) => dist.get(a) - dist.get(b) || a - b);
@@ -321,6 +338,12 @@ export function transfers(pc, ps, book, threats, hd, caps, staging) {
321
338
  arrived.set(step, (arrived.get(step) ?? 0) + k);
322
339
  // #260: say why a step goes toward a front past a conceded border, and what it heads for.
323
340
  let front = '';
341
+ // Rule 6's last target: say which conceded border the stack walks up behind, and why it stops beside it.
342
+ if (toConceded) {
343
+ const past = pastConceded(step);
344
+ if (past)
345
+ front = ` (no front is reachable without crossing a border the plan concedes: they walk up behind ${label(past.border)}, past which lies ${label(past.front)}, and wait beside it — once it falls the front is there)`;
346
+ }
324
347
  if (via) {
325
348
  const targets = attacksFrom(step);
326
349
  const beside = neighborsOf(g, step).filter((x) => !held.has(x) && isEnemy(x)).sort((a, b) => a - b);
@@ -15,7 +15,7 @@ export const TWO_MOVE_MIN_VALUE = 5;
15
15
  * whose bonus was dropped. Kept only when the two captures repay their armies within the payback turns.
16
16
  */
17
17
  export function twoMoveStages(pc, tgt) {
18
- const { g, territories: state, mineSet, costAt, completedOver, paybackTurns, opts } = pc;
18
+ const { g, territories: state, mineSet, costAt, completedOver, capturePaybackTurns: paybackTurns, opts } = pc;
19
19
  const out = [];
20
20
  for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
21
21
  if (b.value < TWO_MOVE_MIN_VALUE || tgt.bonusDropped.has(b.id))