@chrischall/warapp-mcp 0.19.0 → 0.20.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.
@@ -5,7 +5,6 @@
5
5
  import { bonusTerritories } from '../bonuses.js';
6
6
  import { armiesToTake, straightKills } from '../combat.js';
7
7
  import { neighborsOf } from '../graph.js';
8
- import { poolShortfall } from '../local-deploy.js';
9
8
  import { noLossNeutral } from './after-leftover.js';
10
9
  import { deadAdvanceLine, deadAdvanceOf } from './dead-advance.js';
11
10
  import { visibleState } from './observe.js';
@@ -557,9 +556,8 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
557
556
  }
558
557
  return true;
559
558
  };
560
- // #421: the strike share is said on its own line (planner.ts), not as the caller's reserve.
561
- if (reserve - pc.strikeShare)
562
- rationale.push(`Hold a reserve of ${reserve - pc.strikeShare} out of captures.`);
559
+ if (reserve)
560
+ rationale.push(`Hold a reserve of ${reserve} out of captures.`);
563
561
  // ---- 3a. combined (multi-source) captures (R4) ----
564
562
  /**
565
563
  * The cheapest combined capture of `t` (fewest sources) under exact 0%-luck,
@@ -898,8 +896,8 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
898
896
  const { g, s, guarded, capturePaybackTurns: paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
899
897
  const { warnings, rationale, deployed, avail, captured, combined, moves, survivorsAt, captureOrder, staged, incoming, } = ps;
900
898
  const { heldNow, gainWith } = book;
901
- const { heldBorders, keptIncome, keptHeld, stayAt } = hd;
902
- const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, frontierNeeds, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
899
+ const { heldBorders, keptIncome, stayAt } = hd;
900
+ const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
903
901
  const { worstCase, tryCapture, siblings, fundedOnConceded, bareOn } = prev;
904
902
  // ---- pass 1: complete a bonus this turn (all or nothing) ----
905
903
  /** Snapshot the captures, deploys and notes so far; the result undoes everything since. */
@@ -1073,45 +1071,6 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1073
1071
  const denied = new Map();
1074
1072
  /** The start of rule 4d's rationale line for a stopped `t` (one per attempt that differed). */
1075
1073
  const stoppedLine = (t) => `Do not take ${label(t)}: it adds a border facing an enemy without completing a bonus,`;
1076
- /**
1077
- * #297: in a 1v1, the gate budget's veto: a capture of `t` that opens another border facing the opponent (a gate,
1078
- * each sized for its stack plus the whole floating deploy) is stopped when the frontier would then need more next
1079
- * turn than the next income, and more than it needs without that capture. Its rationale line, else `null`. Rule
1080
- * 4d runs it in a 1v1 in place of its start-of-turn escape, and rule 4e's contact fallback runs it where rule 4d is
1081
- * only a cost (#114): a gate the income cannot hold is lost next turn, armies and all.
1082
- */
1083
- const gateStop = (t) => {
1084
- if (pc.profile.format !== '1v1' || !guarded || inFocus(t))
1085
- return null;
1086
- const held = heldNow();
1087
- if (completedBy(held).some((id) => g.bonusById.get(id).value > 0 && bonusTs.get(id).includes(t)))
1088
- return null;
1089
- const stays = (x) => (mineSet.has(x) ? stayAt(x) : (survivorsAt.get(x) ?? 0));
1090
- const without = new Set([...held].filter((x) => x !== t));
1091
- if (frontierDelta(without, [t], stays).enemy <= 0)
1092
- return null;
1093
- const f = frontierOf(held, stays);
1094
- const next = keptIncome(held);
1095
- // #433: under Local Deployment a bonus's armies deploy only on its own territories, so the gates get only the
1096
- // free income and the pools of the bonuses they are in: the whole income read "not short" when that was short.
1097
- const pooled = s.localDeployments ? poolShortfall(g, keptHeld(held), next, frontierNeeds(held, stays)) : null;
1098
- const short = pooled ? pooled.short : Math.max(0, f.holdCost - next);
1099
- if (short <= 0 || f.holdCost <= frontierOf(without, stays).holdCost)
1100
- return null;
1101
- const byPools = pooled !== null && f.holdCost <= next;
1102
- if (!stopped.some((x) => x.t === t))
1103
- stopped.push({ t, holdCost: f.holdCost, income: next, ...(byPools ? { deployable: pooled.deployable } : {}) });
1104
- return byPools
1105
- ? `${stoppedLine(t)} and in this 1v1 it opens another gate${gateFoe(t)}: the gates would then need ${f.holdCost} next turn against its one floating deploy; under Local Deployment only ${pooled.deployable} of the next income of ${next} can be deployed on them (the free income and the pools of the bonuses they are in): ${short} short (#297, #433).`
1106
- : `${stoppedLine(t)} and in this 1v1 it opens another gate${gateFoe(t)}: the gates would then need ${f.holdCost} next turn against its one floating deploy, more than the next income of ${next} (#297).`;
1107
- };
1108
- /** #297: " facing player P" for the opponent beside `t` (in a 1v1, the one opponent), else nothing. */
1109
- const gateFoe = (t) => {
1110
- const o = neighborsOf(g, t)
1111
- .map((n) => state.get(n)?.owner)
1112
- .find((x) => x?.kind === 'player' && pc.foe(x.playerId));
1113
- return o?.kind === 'player' ? ` facing player ${o.playerId}` : '';
1114
- };
1115
1074
  /**
1116
1075
  * #426: whether only the fog faces `t` once taken: no neighbour not mine is a player's territory shown with
1117
1076
  * its armies (a stack in view). A player's territory whose armies the fog hides, or one not shown at all,
@@ -1127,7 +1086,7 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1127
1086
  * Rule 4d's frontier budget, judged with `t` just captured: under a guarded goal, a capture
1128
1087
  * that adds a border facing an enemy without completing a bonus (and not focused) is stopped
1129
1088
  * when holding the frontier next turn would then need more than the next income, and more than
1130
- * it needed at the start of the turn (in a 1v1, more than without it: {@link gateStop}, #297). Returns the rationale line when stopped, else `null`.
1089
+ * it needed at the start of the turn. Returns the rationale line when stopped, else `null`.
1131
1090
  */
1132
1091
  const outgrows = (t) => {
1133
1092
  if (!guarded || inFocus(t))
@@ -1142,13 +1101,9 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1142
1101
  const f = frontierOf(held, stays);
1143
1102
  const next = keptIncome(held);
1144
1103
  const start = startHold();
1145
- // #297: in a 1v1 the start-of-turn hold is no excuse — a capture that opens another gate the next income
1146
- // cannot hold is stopped even when this turn's other orders bring the total back under where it started.
1147
- // #433: nor, under Local Deployment, is a next income the gates' pools and free income cannot carry there.
1148
- const gate = pc.profile.format === '1v1' ? gateStop(t) : null;
1149
- if (f.holdCost <= next && !gate)
1104
+ if (f.holdCost <= next)
1150
1105
  return null;
1151
- if (f.holdCost <= start && !gate)
1106
+ if (f.holdCost <= start)
1152
1107
  return null;
1153
1108
  // #281: land a static seat left, which a live stack beside it takes free next turn: the border
1154
1109
  // comes either way, so the hold cost alone never refuses it (the capture still spends only what
@@ -1171,14 +1126,11 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1171
1126
  // The owner's cap (2026-11-22): only while the hold the capture adds is at most the next income (1×);
1172
1127
  // over it, rule 4d decides as before (a golden synthetic board let one through at 85 against an income of 9).
1173
1128
  const adds = f.holdCost - frontierOf(without, stays).holdCost;
1174
- if (!gate && adds <= next && noLossNeutral(pc, tgt, t) && fogOnlyFaces(t)) {
1129
+ if (adds <= next && noLossNeutral(pc, tgt, t) && fogOnlyFaces(t)) {
1175
1130
  denied.set(t, `Take ${label(t)} though holding the frontier next turn would then need ${f.holdCost} (the next income is ${next}): its defenders kill none of the attackers, only the fog faces its new border and the ${adds} it adds are within that income, so all it risks is the armies that land there (#426).`);
1176
1131
  return null;
1177
1132
  }
1178
- // Only the 1v1 gate budget stops it (rule 4d's start-of-turn escape would have let it through): its own line.
1179
- if (gate && (f.holdCost <= start || f.holdCost <= next))
1180
- return gate;
1181
- const why = `${stoppedLine(t)} and the frontier would then need ${f.holdCost} next turn to hold (${f.enemyBorders} enemy-facing borders), more than the next income of ${next} and more than the ${start} it needed at the start of the turn.${gate ? ` In this 1v1 that is another gate${gateFoe(t)} (#297).` : ''}`;
1133
+ const why = `${stoppedLine(t)} and the frontier would then need ${f.holdCost} next turn to hold (${f.enemyBorders} enemy-facing borders), more than the next income of ${next} and more than the ${start} it needed at the start of the turn.`;
1182
1134
  if (!stopped.some((x) => x.t === t))
1183
1135
  stopped.push({ t, holdCost: f.holdCost, income: next });
1184
1136
  return why;
@@ -1328,5 +1280,5 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1328
1280
  if (closest)
1329
1281
  run(todo.filter((t) => leadSteps.has(t) && !captured.has(t)), true);
1330
1282
  };
1331
- return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, gateStop, givenUp, completableNow, tryExpand, advance };
1283
+ return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, givenUp, completableNow, tryExpand, advance };
1332
1284
  }
@@ -4,8 +4,8 @@
4
4
  // territories are worth (#70, #85, #125), where I stand on armies (#167, #201, rule 0p.3) — and the
5
5
  // rationale and warnings that state them. Pure: it reads the input and writes only
6
6
  // `state.warnings` / `state.rationale`.
7
- import { siegeFit, siegeOf } from './siege.js';
8
- import { pileOf, strikeShareOf } from './stockpile.js';
7
+ import { siegeOf } from './siege.js';
8
+ import { pileOf } from './stockpile.js';
9
9
  import { armiesForGold } from '../../commerce.js';
10
10
  import { holdsSeat } from '../../player-states.js';
11
11
  import { isTeamGame, teammatesOf } from '../../teams.js';
@@ -345,9 +345,8 @@ function opponentsCtx(input) {
345
345
  /** Rule 0p.3 (#72): behind on income in a 1v1 — strike (stay balanced, break first), never defend. */
346
346
  const strike = behind && profile.format === '1v1';
347
347
  // #382: a siege plans as balanced; `siege` below carries what differs.
348
- // (`let`: the profile's siege, below, replaces the goal it picked.)
349
- let goal = opts.goal === 'siege' ? 'balanced' : (opts.goal ?? (behind && !strike ? 'defend' : 'balanced'));
350
- let balanced = goal === 'balanced';
348
+ const goal = opts.goal === 'siege' ? 'balanced' : (opts.goal ?? (behind && !strike ? 'defend' : 'balanced'));
349
+ const balanced = goal === 'balanced';
351
350
  /** Rule 0p.3: behind — size attacks at the minimum (no pressure margin). */
352
351
  const minimal = behind;
353
352
  /** #303: my income over the last turns, this one (what I deploy, card armies out) last. */
@@ -359,7 +358,7 @@ function opponentsCtx(input) {
359
358
  /** The pressure margin over an estimated deploy: none when sizing at the minimum. */
360
359
  const marginFor = (d) => (minimal ? 0 : pressureMargin(d));
361
360
  /** Goals that refuse to complete a bonus they cannot hold (R3); the others only warn. */
362
- let guarded = balanced || goal === 'defend';
361
+ const guarded = balanced || goal === 'defend';
363
362
  const focus = new Set(opts.focusBonusIds ?? []);
364
363
  const reserve = Math.min(income, Math.max(0, Math.floor(opts.reserve ?? 0)));
365
364
  const custom = opts.enemyDeploy !== undefined;
@@ -410,25 +409,7 @@ function opponentsCtx(input) {
410
409
  ...(input.siegeMemory ? { memory: input.siegeMemory } : {}),
411
410
  };
412
411
  const sieged = opts.goal === 'siege' ? siegeOf({ ...siegeArgs, target: opts.siegeTarget }) : undefined;
413
- // #382 item 2: adapting with no goal, the profile picks the siege when it fits (siegeFit), and hands back
414
- // once its assault trigger fires or the fit is gone.
415
- let siege = sieged && 'siege' in sieged ? sieged.siege : undefined;
416
- let siegeHandBack;
417
- if (auto && opts.siegeAuto !== false && (profile.format === '1v1' || profile.format === 'ffa') && (profile.phase === 'contact' || profile.phase === 'late')) {
418
- const c = siegeOf({ ...siegeArgs, target: undefined });
419
- if ('siege' in c) {
420
- const fit = siegeFit(c.siege, { format: profile.format, phase: profile.phase, standing: profile.standing, leader: profile.ranking?.commonThreat });
421
- if (fit.fits) {
422
- siege = { ...c.siege, auto: fit.fit };
423
- // The siege wins over the profile's own goal (a `defend` it picked included): it plans as balanced.
424
- goal = 'balanced';
425
- balanced = true;
426
- guarded = true;
427
- }
428
- else if (fit.handBack)
429
- 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.`;
430
- }
431
- }
412
+ const siege = sieged && 'siege' in sieged ? sieged.siege : undefined;
432
413
  // Until the trigger fires, no pass attacks the target's territories but its breakable bonuses' members.
433
414
  const held = siege && !siege.ready ? siege : undefined;
434
415
  const heldLand = new Set(held
@@ -501,7 +482,6 @@ function opponentsCtx(input) {
501
482
  balanced,
502
483
  ...(siege ? { siege } : {}),
503
484
  ...(sieged && 'warning' in sieged ? { siegeWarning: sieged.warning } : {}),
504
- ...(siegeHandBack ? { siegeHandBack } : {}),
505
485
  minimal,
506
486
  ...(trendNow ? { incomeTrend: trendNow } : {}),
507
487
  pressureFactor,
@@ -861,25 +841,15 @@ export function planContext(input) {
861
841
  const o = opponentsCtx(input);
862
842
  const b = boardCtx(input, o);
863
843
  const c = combatCtx(o, b);
864
- // #421 (owner decision, 2026-11-20): in contact on a flat income the strike share is held out of
865
- // captures (the reserve holds back captures only, so holds keep their exact need first).
866
- const contact = new Set();
867
- for (const id of b.mine)
868
- for (const n of neighborsOf(o.g, id)) {
869
- const st = b.territories.get(n);
870
- if (st?.owner.kind === 'player' && st.armies !== null && o.foe(st.owner.playerId))
871
- contact.add(st.owner.playerId);
872
- }
873
844
  const pileArgs = {
874
845
  territories: b.territories, mineSet: b.mineSet, unitsAt: b.unitsAt, foe: o.foe, income: o.income,
875
846
  ...(o.incomeTrend ? { incomeTrend: o.incomeTrend } : {}), auto: o.auto, goal: o.goal, noSplit: c.noSplit,
876
847
  };
877
- const strikeShare = o.opts.strikeShare === false ? 0 : strikeShareOf({ ...pileArgs, format: o.profile.format, siege: o.siege?.target, contact });
878
- const reserve = Math.min(o.income, o.reserve + strikeShare);
848
+ const reserve = o.reserve;
879
849
  // #421: the pile itself, for the break and all-in spends.
880
850
  const pile = pileOf(pileArgs);
881
851
  return {
882
- ...o, ...b, ...c, ...standingCtx(o, b), reserve, strikeShare: reserve - o.reserve,
852
+ ...o, ...b, ...c, ...standingCtx(o, b), reserve,
883
853
  ...(pile ? { pile: { my: pile.my, turns: pile.turns } } : {}),
884
854
  };
885
855
  }
@@ -890,7 +860,7 @@ export function planContext(input) {
890
860
  * every plan, in this order.
891
861
  */
892
862
  export function noteEstimates(ctx, state) {
893
- const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, minimal, pressureFactor, decidedGame, siege } = ctx;
863
+ const { board, s, opts, earnedIncome: income, estimateList, profile, auto, strike, minimal, pressureFactor, decidedGame } = ctx;
894
864
  const { rates, minWin, exactCombat, bombOn, luck, weightedRounding, noSplit, armiesBehindVs } = ctx;
895
865
  const { warnings, rationale } = state;
896
866
  const profileText = `${profile.format}, ${profile.phase}, ${profile.standing}`;
@@ -907,13 +877,11 @@ export function noteEstimates(ctx, state) {
907
877
  const behindWhy = income <= BEHIND_RATIO * strongest
908
878
  ? `behind on income (${income} against ~${strongest})`
909
879
  : `behind on the board, not on income (${income} against ~${strongest}: the standing says why)`;
910
- rationale.push(siege?.auto
911
- ? `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)` : ''}.`
912
- : strike
913
- ? `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).`
914
- : minimal
915
- ? `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).`
916
- : `Goal balanced from the game profile (${profileText}): the base goal.`);
880
+ rationale.push(strike
881
+ ? `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).`
882
+ : minimal
883
+ ? `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).`
884
+ : `Goal balanced from the game profile (${profileText}): the base goal.`);
917
885
  if (pressureFactor !== PRESSURE_FACTOR)
918
886
  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}×).`);
919
887
  }
@@ -82,8 +82,7 @@ export function fillSecondLine(pc, ps, book) {
82
82
  const owed = e.size - secondLineKept.get(id);
83
83
  if (owed <= 0)
84
84
  continue;
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));
85
+ const k = Math.min(owed, Math.max(0, ps.budget - reserve), roomAt(id));
87
86
  if (k > 0) {
88
87
  deploy(id, k);
89
88
  // The deployed armies join the garrison: they stay, as the guard would.
@@ -7,7 +7,7 @@
7
7
  // (#167) and the turns to eliminate each opponent (#179). planPass runs them where they ran before:
8
8
  // the expected outcome and the offence report after Order Priority for a strike, the plan last,
9
9
  // after the move order (plan/move-order.ts).
10
- import { siegeFitLine, siegeLines, siegeReport } from './siege.js';
10
+ import { siegeLines, siegeReport } from './siege.js';
11
11
  import { bonusTerritories } from '../bonuses.js';
12
12
  import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, straightKills } from '../combat.js';
13
13
  import { classifyExchange } from '../exchange.js';
@@ -96,10 +96,6 @@ export function reportExpected(pc, ps, book, threats, hd, tgt, caps) {
96
96
  const { short, deployable } = poolShortfall(g, keptHeld(after), frontier.income, lacks);
97
97
  return { player, gates: list, need, onGates, deficit, income: frontier.income, short, deployable };
98
98
  })();
99
- // Warned only when this plan's own captures open a gate the budget cannot pay for (the shortfall alone is in the report).
100
- const opened = gates ? gates.gates.filter((x) => captured.has(x.id)).map((x) => x.id) : [];
101
- if (gates && gates.short > 0 && opened.length)
102
- warnings.push(`Gate budget (#297): this plan's capture of ${opened.map(label).join(', ')} opens ${opened.length === 1 ? 'a gate' : 'gates'} the income cannot hold — ${gates.gates.length} gates facing player ${gates.player}${gates.gates.some((x) => x.conceded) ? ` (${gates.gates.filter((x) => x.conceded).length} conceded)` : ''} need ${gates.need} against its one floating deploy; ${gates.onGates} stand on them, ${gates.deficit} short across them, and the next income is ${gates.income}${gates.deployable !== undefined ? ` (${gates.deployable} of it deployable on them under Local Deployment)` : ''}: ${gates.short} short.`);
103
99
  const startCost = startHold();
104
100
  const outgrown = frontier.holdCost > frontier.income && frontier.holdCost > startCost;
105
101
  // A capture stopped by one pass but taken by a later one (the next income grew in between) is
@@ -708,14 +704,9 @@ export function finishPlan(pc, ps, pass, threats, hd, tgt, expected, sentAt, slo
708
704
  warnings.push(pc.siegeWarning);
709
705
  if (pc.siege)
710
706
  rationale.unshift(...siegeLines(pc.siege, label, pc.bonusName));
711
- const chose = pc.siege ? siegeFitLine(pc.siege, pc.bonusName) : undefined;
712
- if (chose)
713
- rationale.unshift(chose);
714
- if (pc.siegeHandBack)
715
- rationale.push(pc.siegeHandBack);
716
707
  return {
717
708
  goal: pc.opts.goal === 'siege' || pc.siege ? 'siege' : goal,
718
- ...(pc.siege ? { siege: siegeReport(pc.siege, g, captured, pc.bonusName) } : {}),
709
+ ...(pc.siege ? { siege: siegeReport(pc.siege, g, captured) } : {}),
719
710
  profile,
720
711
  // Deploys interleave like moves, and the order they land in shows the opponent my income and
721
712
  // the move order: next to a visible enemy first, in the back after (ascending id within each).
@@ -190,53 +190,6 @@ export function siegeOf(o) {
190
190
  };
191
191
  }
192
192
  // ---- The profile's siege (#382 item 2) ----
193
- /** A sure break fits a siege when it costs at most this many turns of the income it takes away. */
194
- export const SIEGE_FIT_TURNS = 2;
195
- /** … one turn only when the target retook that bonus on this many earlier siege turns or more. */
196
- export const SIEGE_RETAKEN_TURNS = 2;
197
- /** In a free-for-all the target must earn this multiple of every other opponent in contact with me. */
198
- export const SIEGE_FFA_DOMINANCE = 1.5;
199
- /**
200
- * Whether the profile picks the siege (no explicit goal; #382). It fits when, against the siege's target:
201
- * - the format is a 1v1 or a free-for-all (a team game focuses its fire by `teams-focus`), in contact
202
- * (phase `contact` or `late`);
203
- * - I am not ahead (ahead, the assault and the 1v1 pressure rules play; an unknown standing is no fit);
204
- * - in a free-for-all the target is the leader on strength (not me) and earns at least
205
- * {@link SIEGE_FFA_DOMINANCE} × every other opponent in contact with me (one war, not two fronts);
206
- * - a sure break (every member in view, a member next to mine) costs at most {@link SIEGE_FIT_TURNS} turns of
207
- * its bonus — one when the target retook it on {@link SIEGE_RETAKEN_TURNS} earlier siege turns — and at most
208
- * my income, so one turn's deploys can pay for a break every turn (a siege that cannot afford its breaks only
209
- * holds the assault back: corpus case 921, where it idled a 23-army stack beside a sure capture).
210
- * Once the assault trigger fires the siege hands back (`handBack`): the profile's own goal plays the assault.
211
- */
212
- export function siegeFit(s, o) {
213
- if (o.format === 'teams' || (o.phase !== 'contact' && o.phase !== 'late'))
214
- return { fits: false };
215
- if (o.standing !== 'even' && o.standing !== 'behind')
216
- return { fits: false };
217
- if (o.format === 'ffa' && (o.leader !== s.target || s.rivals.some((r) => r.income * SIEGE_FFA_DOMINANCE > s.opponentIncome)))
218
- return { fits: false };
219
- const retakes = (b) => s.earlier.filter((t) => t.breaks.includes(b)).length;
220
- const fits = s.breaks.flatMap((b) => {
221
- if (b.probable || b.cost === null)
222
- return [];
223
- const retaken = retakes(b.bonusId) >= SIEGE_RETAKEN_TURNS;
224
- const turns = retaken ? 1 : SIEGE_FIT_TURNS;
225
- return b.cost <= turns * b.value && b.cost <= s.myIncome ? [{ bonusId: b.bonusId, value: b.value, cost: b.cost, turns, retaken }] : [];
226
- });
227
- if (!fits.length)
228
- return { fits: false };
229
- if (s.ready)
230
- return { fits: false, handBack: s.trigger };
231
- return { fits: true, fit: fits[0] };
232
- }
233
- /** The line that says why the profile chose the siege. */
234
- export function siegeFitLine(s, bonusName) {
235
- const f = s.auto;
236
- if (!f)
237
- return undefined;
238
- return `The profile chose the siege on player ${s.target} (#382): in contact, not ahead, ${s.rivals.length ? `every other opponent beside me earning at most 1/${SIEGE_FFA_DOMINANCE} of its income, ` : ''}and ${bonusName(f.bonusId)} (+${f.value}) for ${f.cost} breaks within ${f.turns} turn${f.turns === 1 ? '' : 's'} of its income${f.retaken ? ` (counted one turn: retaken after ${SIEGE_RETAKEN_TURNS} earlier breaks)` : ''}. Breaking it costs less than it takes away, so attrition beats an assault until the trigger fires; an explicit goal overrides it.`;
239
- }
240
193
  /** The rationale lines a siege adds (first in the plan's rationale). */
241
194
  export function siegeLines(s, label, bonusName) {
242
195
  const ratio = s.ratio === null ? 'it earns nothing' : `my ${s.myIncome} is ${s.ratio}× its income`;
@@ -262,7 +215,7 @@ export function siegeLines(s, label, bonusName) {
262
215
  return [head, breaks, state];
263
216
  }
264
217
  /** The report of a siege once the plan's captures are known. */
265
- export function siegeReport(s, g, captured, bonusName) {
218
+ export function siegeReport(s, g, captured) {
266
219
  const brokenThisTurn = s.breaks
267
220
  .filter((b) => bonusTerritories(g, b.bonusId).some((t) => captured.has(t)))
268
221
  .map((b) => ({ bonusId: b.bonusId, value: b.value }));
@@ -293,7 +246,6 @@ export function siegeReport(s, g, captured, bonusName) {
293
246
  ratio: s.ratio,
294
247
  fallenTo: s.fallenTo,
295
248
  ...(memory ? { memory } : {}),
296
- ...(s.auto ? { auto: siegeFitLine(s, bonusName ?? ((b) => `bonus ${b}`)) } : {}),
297
249
  brokenThisTurn,
298
250
  breaks: s.breaks,
299
251
  ready: s.ready,
@@ -332,7 +332,7 @@ export function neverStandStill(pc, ps, book, threats, hd, tgt, caps) {
332
332
  const { growthOf, facing } = threats;
333
333
  const { conceded } = hd;
334
334
  const { targets, bonusTarget, targetScoreCost, toFinish, plans, finishCost, sizeOf } = tgt;
335
- const { stopped, outgrows, gateStop } = caps;
335
+ const { stopped, outgrows } = caps;
336
336
  /**
337
337
  * #125: the step rule 4e ranked first and could not afford this turn (its size, nothing else):
338
338
  * the leftover saves toward it (rule 5) and idle stacks stage toward it (rule 6).
@@ -617,9 +617,8 @@ export function neverStandStill(pc, ps, book, threats, hd, tgt, caps) {
617
617
  failed.set(st.t, { kind: 'hold', ...short });
618
618
  continue;
619
619
  }
620
- // #114: in contact rule 4d is a cost (ranked above), not a veto — except the 1v1 gate budget (#297):
621
- // a gate the next income cannot hold is lost next turn, armies and all.
622
- const stop = contact ? gateStop(st.t) : outgrows(st.t);
620
+ // #114: in contact rule 4d is a cost (ranked above), not a veto (#603: nor is #297's gate budget any more).
621
+ const stop = contact ? null : outgrows(st.t);
623
622
  if (stop === null) {
624
623
  taken = pick;
625
624
  break;
@@ -4,8 +4,6 @@ import { neighborsOf } from '../graph.js';
4
4
  export const STOCKPILE_TURNS = 4;
5
5
  /** #421: the visible-army lead over one opponent beside me that turns a stockpile into a strike stack facing it. */
6
6
  export const STOCKPILE_LEAD = 2;
7
- /** #421 (owner decision, 2026-11-20): the share of a flat income held out of captures for the strike stack. */
8
- export const STRIKE_SHARE = 0.25;
9
7
  /** My armies in view and each other player's (special units counted), visible territories only. */
10
8
  export function armiesInView(a) {
11
9
  const by = new Map();
@@ -56,20 +54,6 @@ export function stockpileOf(a) {
56
54
  line: `${my} armies of mine stand on the board, ${turns} turns of my flat ${a.income} income, ${ratio} player ${p}'s in view`,
57
55
  };
58
56
  }
59
- /**
60
- * #421 (owner decision, 2026-11-20): in contact on a flat income — where rule 0p.3c builds a strike stack
61
- * (a 1v1 adapting, a siege, or the stockpile above) — {@link STRIKE_SHARE} of my income, rounded down, is
62
- * held out of captures for the stack. Holds still take their exact need first; the leftover deploy then
63
- * gives the stack what the captures left, ahead of comfort margins. 0 otherwise.
64
- */
65
- export function strikeShareOf(a) {
66
- if (!a.incomeTrend?.flat || a.income <= 0)
67
- return 0;
68
- const stack = (a.siege !== undefined && a.contact.has(a.siege)) ||
69
- (a.auto && a.format === '1v1' && a.goal !== 'defend' && a.contact.size > 0) ||
70
- stockpileOf({ ...a, siege: a.siege !== undefined, facing: a.contact }) !== undefined;
71
- return stack ? Math.floor(STRIKE_SHARE * a.income) : 0;
72
- }
73
57
  /**
74
58
  * #421 (owner decision, 2026-11-20): the contested bonuses an all-in completion could take on the pile — a
75
59
  * positive bonus I hold a member of, whose every missing member is in view (armies shown) beside a territory of
@@ -5,7 +5,7 @@ import { neighborsOf } from '../graph.js';
5
5
  import { MIN_ENEMY_DEPLOY, visibleState, } from './shared.js';
6
6
  import { byNum, pct } from './util.js';
7
7
  import { stackFacing } from './strike.js';
8
- import { STRIKE_SHARE, stockpileOf } from './stockpile.js';
8
+ import { stockpileOf } from './stockpile.js';
9
9
  /** Rule 0p.3c (#72, #120, #201, #421): the strike stack's border (a 1v1, a siege or a stockpile), chosen before the leftover deploy. */
10
10
  export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
11
11
  const { g, income, profile, auto, goal, estimates, deployOf, incomeOfPlayer, paybackTurns, territories: state, label, mine, armiesOf, unitsAt, defenceAt, completedBy, inFocus, guard, rates, costAt, noSplit, } = pc;
@@ -151,11 +151,6 @@ export function chooseStrikeStack(pc, ps, book, threats, open, stays) {
151
151
  ...(stockpile ? { facing: stockpile.why } : {}),
152
152
  };
153
153
  }
154
- // #421 (owner decision, 2026-11-20): the share the estimates phase held out of captures.
155
- if (pc.strikeShare > 0)
156
- rationale.push(stack
157
- ? `Strike share (#421): ${pc.strikeShare} of my flat ${income} income (${STRIKE_SHARE * 100}%) was held out of captures for the strike stack on ${label(stack.id)}, ahead of comfort margins; holds took their exact need first.`
158
- : `Strike share (#421): ${pc.strikeShare} of my flat ${income} income (${STRIKE_SHARE * 100}%) was held out of captures for a strike stack, but no border could carry one this turn: it goes to the leftover as usual.`);
159
154
  return { stack, smallExpansion };
160
155
  }
161
156
  /** #102: spend the strike stack on the enemy territories next to it, once the leftover deploy is in. */
@@ -361,7 +361,13 @@ export function finishOffHelper(pc, ps, book, threats, hd, tgt, cap) {
361
361
  if (uncoverable)
362
362
  return { best, bestUnfunded, canEliminate };
363
363
  const sizes = tried.map(() => 0);
364
+ // An attempt is `enough` only when at least `need` targets fall (or all, under pressure), and a target
365
+ // falls only when attacked: sizings that attack fewer are never tried (nothing they could yield is used).
366
+ const need = pressure ? ts.length : Math.max(1, Math.min(ts.length - 1, Math.ceil(ts.length / 2)));
367
+ let attacking = 0;
364
368
  const visit = (i) => {
369
+ if (attacking + tried.length - i < need)
370
+ return;
365
371
  if (i === tried.length) {
366
372
  const a = attempt([...sizes]);
367
373
  restore(reserved);
@@ -379,7 +385,11 @@ export function finishOffHelper(pc, ps, book, threats, hd, tgt, cap) {
379
385
  }
380
386
  for (const e of sharesOf[i]) {
381
387
  sizes[i] = e;
388
+ if (e !== SKIP)
389
+ attacking++;
382
390
  visit(i + 1);
391
+ if (e !== SKIP)
392
+ attacking--;
383
393
  }
384
394
  };
385
395
  if (tried.length)
@@ -381,15 +381,22 @@ export function frontierCosts(pc, threats, hd, prev) {
381
381
  * held; facing an enemy when a visible enemy is next to it, and then `need` is the deploys it
382
382
  * needs next turn to hold (the R3 arithmetic: threat = movable + max(deploy, growth) per player).
383
383
  */
384
+ // #603: the opponent's one floating deploy counts once, at the border it adds most to, not on every border.
385
+ const deployOnce = pc.opts.experiments?.includes('legacy-frontier') !== true;
384
386
  const borderOf = (x, held, have) => {
385
387
  if (neighborsOf(g, x).every((n) => held.has(n)))
386
- return { border: false, enemy: false, need: 0 };
388
+ return { border: false, enemy: false, need: 0, needStack: 0, player: -1 };
387
389
  // G2: next turn's threat — a player a Diplomacy card shields me from only this turn counts.
388
390
  const th = nextTurnAt(x, (n) => held.has(n));
389
391
  if (!th)
390
- return { border: true, enemy: false, need: 0 };
392
+ return { border: true, enemy: false, need: 0, needStack: 0, player: -1 };
391
393
  const units = mineSet.has(x) ? unitsAt(x) : 0;
392
- return { border: true, enemy: true, need: Math.max(0, holdArmies(th.threat) - have - units) };
394
+ const need = Math.max(0, holdArmies(th.threat) - have - units);
395
+ if (!deployOnce)
396
+ return { border: true, enemy: true, need, needStack: need, player: th.player };
397
+ const st = nextTurnAt(x, (n) => held.has(n), 0);
398
+ const needStack = st ? Math.min(need, Math.max(0, holdArmies(st.threat) - have - units)) : 0;
399
+ return { border: true, enemy: true, need, needStack, player: th.player };
393
400
  };
394
401
  /**
395
402
  * A border's cost in armies: {@link NEUTRAL_BORDER_COST}, plus its hold need when it faces an
@@ -456,13 +463,20 @@ export function frontierCosts(pc, threats, hd, prev) {
456
463
  let borders = 0;
457
464
  let enemyBorders = 0;
458
465
  let holdCost = 0;
466
+ /** deploy-once: per opponent, the most its one floating deploy adds to any one border's need. */
467
+ const floating = new Map();
459
468
  for (const x of [...held].sort(byNum)) {
460
469
  const b = borderOf(x, held, haveOf(x));
461
470
  borders += Number(b.border);
462
471
  enemyBorders += Number(b.enemy);
463
- if (!conceded.has(x) || stood.has(x))
464
- holdCost += b.need;
472
+ if (!conceded.has(x) || stood.has(x)) {
473
+ holdCost += b.needStack;
474
+ if (b.need > b.needStack)
475
+ floating.set(b.player, Math.max(floating.get(b.player) ?? 0, b.need - b.needStack));
476
+ }
465
477
  }
478
+ for (const v of floating.values())
479
+ holdCost += v;
466
480
  return { borders, enemyBorders, holdCost };
467
481
  };
468
482
  /**
@@ -508,16 +522,6 @@ export function bonusScoring(pc, ps, threats, prev) {
508
522
  const wasteShare = s.wastelands && s.wastelands.count > 0 && s.wastelands.size > 0 && g.territoryById.size > 0
509
523
  ? Math.min(1, s.wastelands.count / g.territoryById.size)
510
524
  : 0;
511
- /**
512
- * #432: a visible neutral at the game's wasteland size or more, when the game has wastelands larger than its
513
- * ordinary neutrals (`neutralArmies`, when the settings give it).
514
- */
515
- const isWasteland = (st) => s.wastelands !== undefined &&
516
- s.wastelands.count > 0 &&
517
- s.wastelands.size > (s.neutralArmies ?? 0) &&
518
- st.owner.kind === 'neutral' &&
519
- st.armies !== null &&
520
- st.armies >= s.wastelands.size;
521
525
  const wasteCost = wasteShare > 0 ? (costOf(s.wastelands.size) ?? Infinity) : 0;
522
526
  const wasteLoss = wasteShare > 0 ? Math.min(wasteCost - 1, straightKills(s.wastelands.size, rates.defensiveKillRate)) + 1 : 0;
523
527
  /** Every positive bonus worth completing (net > 0) still missing members: its armies to finish (rule 4e). */
@@ -624,8 +628,6 @@ export function bonusScoring(pc, ps, threats, prev) {
624
628
  // #125: the economy test charges the armies lost, not the armies sent.
625
629
  let loss = 0;
626
630
  let worstLoss = 0;
627
- /** #432: its missing members in view that are wastelands. */
628
- const wastelands = [];
629
631
  const known = (t, armies) => {
630
632
  const c = costAt(t, armies) ?? Infinity;
631
633
  cost += c;
@@ -674,8 +676,6 @@ export function bonusScoring(pc, ps, threats, prev) {
674
676
  const c = costAt(t) ?? Infinity;
675
677
  cost += c;
676
678
  worst = Math.max(worst, c);
677
- if (isWasteland(st))
678
- wastelands.push(t);
679
679
  const l = econCostAt(t);
680
680
  loss += l;
681
681
  worstLoss = Math.max(worstLoss, l);
@@ -716,10 +716,7 @@ export function bonusScoring(pc, ps, threats, prev) {
716
716
  cost += fogged * fogEach + foggedNeutral * neutralEach;
717
717
  loss += fogged * fogLoss + foggedNeutral * neutralEachLoss;
718
718
  const fogNeutral = foggedNeutral ? { count: foggedNeutral, each: neutralEach, size: neutralSize } : undefined;
719
- // #432: while the gate budget is short, no bonus is built through a wasteland: its armies go to the gates —
720
- // unless this turn's captures can complete it (owner decision 2026-11-22: a completing wasteland is taken).
721
- const wasteStop = !isFocus && pc.shortGates !== undefined && wastelands.length > 0 && !remaining.every(bonusTarget);
722
- const economic = isFocus || (loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net && !wasteStop);
719
+ const economic = isFocus || (loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net);
723
720
  // #435: a shared bonus I am nearer to but that is not worth working stays as C3.3 left it — skipped
724
721
  // with its members plain expansion, never marked uneconomic (45701358 turn 1: a 344-member super-bonus,
725
722
  // 6 members to my teammate's 5, would otherwise have stopped expansion into all its members).
@@ -734,10 +731,6 @@ export function bonusScoring(pc, ps, threats, prev) {
734
731
  (economic ? economicMember : uneconomicMember).add(t);
735
732
  if (!remaining.some(bonusTarget))
736
733
  continue;
737
- if (!economic && wasteStop && loss <= paybackTurns * net && worstLoss <= WASTELAND_FACTOR * net) {
738
- 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).`);
739
- continue;
740
- }
741
734
  if (!economic) {
742
735
  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).`);
743
736
  continue;