@chrischall/warapp-mcp 0.8.0 → 0.10.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.
@@ -17,6 +17,7 @@
17
17
  // 4h. the army cap prices idle armies (#253) .................. plan/cap-spend.ts
18
18
  // 5. the leftover deploy, 3b's short borders (#121) ........... plan/leftover.ts
19
19
  // 5b. a neutral the leftover pays for (#218) ................. plan/after-leftover.ts
20
+ // #319's bind (#416): other expansion waits for the nearest bonus .. plan/spread-bind.ts
20
21
  // 6. transfers, #125 staging ................................. plan/transfers.ts
21
22
  // #277: a held bonus funded from a second sure sizing ......... plan/second-sizing.ts
22
23
  // 7. move order, rule 1s's Order Priority ..................... plan/move-order.ts
@@ -1227,6 +1228,16 @@
1227
1228
  // at least TWO_MOVE_MIN_VALUE two moves away through a visible neutral is a two-turn completion
1228
1229
  // (cost: that neutral plus the territory); the neutral in between is a `stage` candidate under
1229
1230
  // `balanced` (net over both costs, ranked as an advance), else taken before the advances.
1231
+ // #319 binds (#416, owner 2026-11-22; plan/spread-bind.ts): while #319's opening warning fires, pass-3
1232
+ // plain expansion and advances into other bonuses may not spend deploys, or armies on a territory beside the
1233
+ // nearest bonus's missing members, until that bonus's reachable steps are funded. Holds keep their places.
1234
+ // The nearest bonus is the one the warning names; its reachable steps are its missing members that are
1235
+ // capture targets beside a territory of mine; funded = captured by this plan, after which the rest flows
1236
+ // as before (a step refused for another reason keeps the bind for the turn: the leftover saves toward it).
1237
+ // A stack beside two bonuses' missing members is the nearest bonus's. Bound: other bonuses' advances (pass
1238
+ // 2, the `balanced` advance slots, #439's stage), pass 3 and rule 5b; never the bonus's own members, a
1239
+ // focused bonus, completions, holds, breaks, counters, the 1v1 race, strikes, rule 4e, 4g or 4h. What is
1240
+ // bound may still attack with the armies on my other territories. A "#319 binds the deploys" line says so.
1230
1241
  // 3b. One surplus per territory (#121). A border that holds at the start of the turn (its armies
1231
1242
  // beat its visible threat, rule 1) and is not conceded keeps what holds it, as my commander's
1232
1243
  // territory does (rule 1k): a capture from it spends only its armies above that, plus deploys
@@ -1672,6 +1683,7 @@ import { threatsPhase } from './plan/threats.js';
1672
1683
  import { applyShortGates } from './plan/horizon.js';
1673
1684
  import { targetsPhase } from './plan/targets.js';
1674
1685
  import { capturesPhase } from './plan/captures.js';
1686
+ import { spreadBind } from './plan/spread-bind.js';
1675
1687
  import { completedMembers } from './plan/completed.js';
1676
1688
  import { chooseStrikeStack, leadStrikes, spendStrikeStack, strikesPhase } from './plan/strike.js';
1677
1689
  import { contestedBonuses } from './plan/stockpile.js';
@@ -1924,6 +1936,11 @@ function planAttempts(input) {
1924
1936
  }
1925
1937
  /** #421: per plan, the strike share its pass held out of captures (absent when none). */
1926
1938
  const shareOutcome = new WeakMap();
1939
+ const closenessOutcome = new WeakMap();
1940
+ /** #505: rule 4f's nearest bonus and turns to finish for a plan `planTurn` made; `undefined` for any other object. */
1941
+ export function planCloseness(plan) {
1942
+ return closenessOutcome.get(plan);
1943
+ }
1927
1944
  /**
1928
1945
  * #421 (owner decision, 2026-11-20): the strike share is held out of captures, ahead of comfort margins,
1929
1946
  * but never at the cost of next income — when the plan without it earns more next turn (a completion the
@@ -2038,6 +2055,10 @@ function planPass(input, pass) {
2038
2055
  const { strikes, worstCase, defendersAt, tryCapture, snapshot, complete, tryExpand, advance } = caps;
2039
2056
  /** #439: single-territory bonuses two moves away, each with its neutral in between. */
2040
2057
  const stages = twoMoveStages(pc, tgt);
2058
+ /** #416 part 4: while #319 fires, other advances and pass 3 wait for the nearest bonus's steps (plan/spread-bind.ts). */
2059
+ const bind = spreadBind(pc, ps, tgt);
2060
+ const bound = (exempt, f) => (bind ? bind.bound(exempt, f) : f());
2061
+ const otherBonus = (p) => p.focus || p.bonusId === bind?.bonusId;
2041
2062
  // ---- 1e. finish off an opponent, 1s. strike an enemy commander, #165 guard-off breaks (plan/strike.ts) ----
2042
2063
  const { struck } = strikesPhase(pc, ps, book, threats, hd, tgt, caps);
2043
2064
  // ---- #276: guard off — free retakes and raids one step deeper (plan/guard-off.ts) ----
@@ -2177,12 +2198,12 @@ function planPass(input, pass) {
2177
2198
  worthOf.set(p.bonusId, p.net === p.value ? `+${p.value}` : `+${p.value}, net +${p.net}`);
2178
2199
  if (p.completable)
2179
2200
  candidates.push({ kind: 'complete', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => complete(p)) });
2180
- candidates.push({ kind: 'advance', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => advance(p)) });
2201
+ candidates.push({ kind: 'advance', score, cost: p.cost, id: p.bonusId, value: p.net, focus: p.focus, borders: p.borders, run: spend(() => bound(otherBonus(p), () => advance(p))) });
2181
2202
  }
2182
2203
  // #439: a single-territory bonus two moves away is a two-turn completion: its neutral in between
2183
2204
  // competes as an advance does, on the income per army of both captures.
2184
2205
  for (const st of stages)
2185
- candidates.push({ kind: 'stage', score: st.net / st.cost, cost: st.cost, id: st.bonusId, value: st.net, focus: false, borders: 0, target: st.via, run: spend(() => stageTwoMove(pc, ps, st, gainWith, tryExpand)) });
2206
+ candidates.push({ kind: 'stage', score: st.net / st.cost, cost: st.cost, id: st.bonusId, value: st.net, focus: false, borders: 0, target: st.via, run: spend(() => bound(st.bonusId === bind?.bonusId, () => stageTwoMove(pc, ps, st, gainWith, tryExpand))) });
2186
2207
  // #417, the 1v1 race: while a static seat's land is still untaken, its cheap captures rank ahead of
2187
2208
  // rule 0p.1's "expansion last" (`ahead` below); held-bonus gates and my commander's hold go first.
2188
2209
  const races = oneVsOne ? raceTargets(pc, targets, captured) : [];
@@ -2807,11 +2828,11 @@ function planPass(input, pass) {
2807
2828
  // #439: the neutral in between toward a single-territory bonus two moves away, before any advance.
2808
2829
  if (goal !== 'complete-bonus')
2809
2830
  for (const st of stages) {
2810
- stageTwoMove(pc, ps, st, gainWith, tryExpand);
2831
+ bound(st.bonusId === bind?.bonusId, () => stageTwoMove(pc, ps, st, gainWith, tryExpand));
2811
2832
  garrisonCompleted();
2812
2833
  }
2813
2834
  for (const p of byCloseness) {
2814
- advance(p);
2835
+ bound(otherBonus(p), () => advance(p));
2815
2836
  garrisonCompleted();
2816
2837
  }
2817
2838
  // #285: as under `balanced`.
@@ -2846,41 +2867,44 @@ function planPass(input, pass) {
2846
2867
  const plainScore = plainOrderCosts(pc, tgt, eligible.map((t) => t.id));
2847
2868
  const rest = eligible.sort((a, b) => plainScore.get(a.id) - plainScore.get(b.id) || a.cost - b.cost || a.id - b.id);
2848
2869
  // Rule 4c: plain expansion never lowers income (a capture completing a negative bonus).
2849
- for (const t of rest) {
2850
- const gain = gainWith([t.id]);
2851
- if (gain < 0 && !inFocus(t.id))
2852
- continue;
2853
- if (tgt.emptyEnemies.has(t.id)) {
2854
- // #281: never one lowering income, focused or not; sized for its owner's deploy (#120).
2855
- if (gain >= 0)
2856
- tryEmptyEnemy(pc, ps, book, tgt, caps, t.id);
2857
- continue;
2858
- }
2859
- // #125: its own economy test. A member of an economic bonus is judged by that bonus; any
2860
- // other capture pays for the armies it loses with the income it adds within PAYBACK_TURNS,
2861
- // and one that adds none may lose at most PLAIN_EXPANSION_LOSS.
2862
- {
2863
- const refused = plainEconomy(pc, tgt, t.id, gain);
2864
- if (refused) {
2865
- const { lost, worth } = refused;
2866
- const reach = Math.max(...neighborsOf(g, t.id).filter((x) => avail.has(x)).map((x) => (avail.get(x) ?? 0) + roomAt(x)));
2867
- if (reach >= t.cost)
2868
- rationale.push(worth > 0
2869
- ? `Do not expand into ${label(t.id)}: it adds +${worth} a turn and loses ~${lost} armies, more than ${pc.capturePaybackTurns} turns of it pay back.`
2870
- : `Do not expand into ${label(t.id)}: it adds no income and loses ~${lost} armies (more than ${PLAIN_EXPANSION_LOSS}), in no bonus worth completing.`);
2871
- continue;
2870
+ // #416: the nearest bonus's own members are its steps; everything else waits under #319's bind.
2871
+ const nearestTs = bind ? new Set(bonusTs.get(bind.bonusId)) : undefined;
2872
+ for (const t of rest)
2873
+ bound(nearestTs?.has(t.id) ?? true, () => {
2874
+ const gain = gainWith([t.id]);
2875
+ if (gain < 0 && !inFocus(t.id))
2876
+ return;
2877
+ if (tgt.emptyEnemies.has(t.id)) {
2878
+ // #281: never one lowering income, focused or not; sized for its owner's deploy (#120).
2879
+ if (gain >= 0)
2880
+ tryEmptyEnemy(pc, ps, book, tgt, caps, t.id);
2881
+ return;
2872
2882
  }
2873
- }
2874
- // #281 × #282: a denial is never sourced from the territory my commander walks from (its transit hold).
2875
- // #426: a no-loss capture in a bonus too costly to finish says why it is taken all the same.
2876
- const reason = onlyNoLoss(pc, tgt, t.id)
2877
- ? `expands territory: a no-loss capture (its defenders kill none of the attackers; what lands stays mine), so the cost of finishing its bonus does not stop it (#426)`
2878
- : 'expands territory';
2879
- if (tgt.denials.has(t.id))
2880
- withoutTransit(pc, tgt, t.id, () => tryExpand(t.id, reason));
2881
- else
2882
- tryExpand(t.id, reason);
2883
- }
2883
+ // #125: its own economy test. A member of an economic bonus is judged by that bonus; any
2884
+ // other capture pays for the armies it loses with the income it adds within PAYBACK_TURNS,
2885
+ // and one that adds none may lose at most PLAIN_EXPANSION_LOSS.
2886
+ {
2887
+ const refused = plainEconomy(pc, tgt, t.id, gain);
2888
+ if (refused) {
2889
+ const { lost, worth } = refused;
2890
+ const reach = Math.max(...neighborsOf(g, t.id).filter((x) => avail.has(x)).map((x) => (avail.get(x) ?? 0) + roomAt(x)));
2891
+ if (reach >= t.cost)
2892
+ rationale.push(worth > 0
2893
+ ? `Do not expand into ${label(t.id)}: it adds +${worth} a turn and loses ~${lost} armies, more than ${pc.capturePaybackTurns} turns of it pay back.`
2894
+ : `Do not expand into ${label(t.id)}: it adds no income and loses ~${lost} armies (more than ${PLAIN_EXPANSION_LOSS}), in no bonus worth completing.`);
2895
+ return;
2896
+ }
2897
+ }
2898
+ // #281 × #282: a denial is never sourced from the territory my commander walks from (its transit hold).
2899
+ // #426: a no-loss capture in a bonus too costly to finish says why it is taken all the same.
2900
+ const reason = onlyNoLoss(pc, tgt, t.id)
2901
+ ? `expands territory: a no-loss capture (its defenders kill none of the attackers; what lands stays mine), so the cost of finishing its bonus does not stop it (#426)`
2902
+ : 'expands territory';
2903
+ if (tgt.denials.has(t.id))
2904
+ withoutTransit(pc, tgt, t.id, () => tryExpand(t.id, reason));
2905
+ else
2906
+ tryExpand(t.id, reason);
2907
+ });
2884
2908
  dropEmptyEnemyTargets(ps, tgt, empties);
2885
2909
  }
2886
2910
  // ---- 4e. never stand still (#104, #107), the contact fallback (plan/stand-still.ts) ----
@@ -3062,7 +3086,8 @@ function planPass(input, pass) {
3062
3086
  // ---- 5b. a neutral the leftover pays for (#218) (plan/after-leftover.ts) ----
3063
3087
  // The strike stack concentrates for its strike, and a step's source saves toward it: neither spends.
3064
3088
  const keepWhole = new Set([...(strikeStack ? [strikeStack.id] : []), ...(staging ? [staging.from] : [])]);
3065
- const takenAfter = afterLeftoverCaptures(pc, ps, book, threats, hd, tgt, caps, beforeLeftover, keepWhole, poolDeployed);
3089
+ // #416: rule 5b is plain expansion too: under #319's bind it leaves the stacks beside the nearest bonus alone.
3090
+ const takenAfter = bound(false, () => afterLeftoverCaptures(pc, ps, book, threats, hd, tgt, caps, beforeLeftover, keepWhole, poolDeployed));
3066
3091
  // #288: the rest of the leftover offered to another capture rides the expansion stack's attacks
3067
3092
  // after all when rule 5b took nothing from where it was offered.
3068
3093
  if (offered && !moves.some((m) => m.kind === 'attack' && m.from === offered.at && takenAfter.includes(m.to)))
@@ -3433,6 +3458,16 @@ function planPass(input, pass) {
3433
3458
  allInOutcome.set(plan, tgt.allInTries);
3434
3459
  if (pc.strikeShare > 0)
3435
3460
  shareOutcome.set(plan, pc.strikeShare);
3461
+ {
3462
+ const nearest = tgt.committing ? (tgt.byCloseness.find((p) => !p.focus) ?? tgt.byCloseness[0]) : undefined;
3463
+ const near = tgt.spreadNearest ?? nearest;
3464
+ closenessOutcome.set(plan, {
3465
+ ...(near ? { nearest: near.bonusId } : {}),
3466
+ spread: tgt.spreadNearest !== undefined || plan.warnings.some((w) => w.endsWith('(#319).')),
3467
+ turns: new Map(tgt.plans.map((p) => [p.bonusId, tgt.turnsOf(p)])),
3468
+ remaining: new Map(tgt.plans.map((p) => [p.bonusId, [...p.remaining].sort((a, b) => a - b)])),
3469
+ });
3470
+ }
3436
3471
  // #421: on a stockpile, the contested bonuses this plan does not complete that an all-in push could (planPushed).
3437
3472
  if (pc.pile && !input.stockpileAllIn) {
3438
3473
  const done = new Set(plan.expected.bonusesCompleted);