@chrischall/warapp-mcp 0.17.0 → 0.19.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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "MCP server for war.app (Warzone) — your games, players, settings, map bonuses and chokepoints, board analysis and route planning through war.app's per-player GameFeed API, plus the live board, territory picks, cards, turn planning and submission, turn notifications and game chat through your signed-in war.app tab (joining, leaving or surrendering a game, closing out a finished game, accepting another player's surrender, Begin on a speed first turn, picks, turn orders, withdrawing them, chat sends, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated).",
10
- "version": "0.17.0"
10
+ "version": "0.19.0"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "war.app (Warzone)",
16
16
  "source": "./",
17
17
  "description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
18
- "version": "0.17.0",
18
+ "version": "0.19.0",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "warapp-mcp",
3
3
  "displayName": "war.app (Warzone)",
4
- "version": "0.17.0",
4
+ "version": "0.19.0",
5
5
  "description": "war.app (Warzone) game advisor for Claude — games, maps, bonuses, routes, live board, picks, turns, cards and chat",
6
6
  "author": {
7
7
  "name": "Chris Hall",
@@ -17,6 +17,53 @@ export function seatBand(seats) {
17
17
  return 'unknown';
18
18
  return seats === 2 ? '2' : seats <= 6 ? '3-6' : seats <= 16 ? '7-16' : '17-up';
19
19
  }
20
+ /**
21
+ * #586: the step that held a low estimate (under {@link CATCH_UP_SHARE} of the truth) down, read from the
22
+ * tracker's logged figures (#587's `track`), first match in this order:
23
+ * - `after-tracker`: the tracker's income reached it; a later stage (blend, thin evidence, a known income) did not;
24
+ * - `rise-cap`: a window reading reached it and #418's rise cap held the income;
25
+ * - `tripwire`: a window reading reached it and #418's over-read tripwire stepped it down;
26
+ * - `window`: a window reading reached it and the income still did not (a carry lowered by broken bonuses, …);
27
+ * - `ceiling`: a reading reached it before the could-earn cap, which cut it;
28
+ * - `ambiguous`: only the high end reached it (the ambiguous armies #123 reads as moves, not deploys);
29
+ * - `readings`: nothing the boards showed reached it (fog, a thin frontier);
30
+ * - `no-track`: the estimate used no track (the prior or the visible income alone);
31
+ * - `unlogged`: logged before #586 kept the track: no step can be named.
32
+ */
33
+ export const HELD_BY = ['after-tracker', 'rise-cap', 'tripwire', 'window', 'ceiling', 'ambiguous', 'readings', 'no-track', 'unlogged'];
34
+ /** #586: {@link HELD_BY}'s step for one estimate; `null` when it reached {@link CATCH_UP_SHARE} of the truth. Pure. */
35
+ export function heldByOf(estimate, truth, track, stages) {
36
+ const target = CATCH_UP_SHARE * truth;
37
+ if (truth <= 0 || estimate >= target)
38
+ return null;
39
+ if (!track)
40
+ return stages && stages.tracked === null ? 'no-track' : 'unlogged';
41
+ if (track.income === null || !track.window.length)
42
+ return 'no-track';
43
+ if (track.income >= target)
44
+ return 'after-tracker';
45
+ const most = (f) => Math.max(...track.window.map(f));
46
+ if (most((x) => x.observed) >= target)
47
+ return track.rise ? 'rise-cap' : track.trip ? 'tripwire' : 'window';
48
+ if (most((x) => Math.max(x.raw, x.high)) >= target && most((x) => x.cap) < target)
49
+ return 'ceiling';
50
+ if (most((x) => Math.min(x.high, x.cap)) >= target)
51
+ return 'ambiguous';
52
+ return 'readings';
53
+ }
54
+ export function heldByView(samples) {
55
+ const low = samples.filter((s) => s.heldBy !== null);
56
+ const named = low.filter((s) => s.heldBy !== 'unlogged');
57
+ const steps = {};
58
+ for (const step of HELD_BY) {
59
+ if (step === 'unlogged')
60
+ continue;
61
+ const n = named.filter((s) => s.heldBy === step).length;
62
+ if (n)
63
+ steps[step] = { n, share: r3(n / named.length) };
64
+ }
65
+ return { low: low.length, steps, unlogged: low.length - named.length };
66
+ }
20
67
  const r3 = (x) => Math.round(x * 1000) / 1000;
21
68
  export function errorView(samples) {
22
69
  const n = samples.length;
@@ -72,6 +119,7 @@ export function incomeSamples(games) {
72
119
  method: logged.get(a.player)?.method ?? null,
73
120
  leader: top !== null && a.truth >= top,
74
121
  stages: logged.get(a.player)?.stages ?? null,
122
+ heldBy: heldByOf(a.estimate, a.truth, logged.get(a.player)?.track, logged.get(a.player)?.stages ?? null),
75
123
  });
76
124
  }
77
125
  }
@@ -81,11 +129,13 @@ export function incomeSamples(games) {
81
129
  /**
82
130
  * Per game and opponent, a turn whose true income is at least {@link JUMP_FACTOR} × the turn before (both
83
131
  * read, the earlier above 0) is a jump; its lag is the turns from it to the first logged estimate of that
84
- * opponent at or after it that reaches {@link CATCH_UP_SHARE} of that turn's truth. Pure.
132
+ * opponent at or after it that reaches {@link CATCH_UP_SHARE} of that turn's truth. A jump on a turn with no
133
+ * estimate of that opponent logged is `unwatched` and left out (#586). Pure.
85
134
  */
86
135
  export function catchUp(games) {
87
136
  const lagsList = [];
88
137
  let censored = 0;
138
+ let unwatched = 0;
89
139
  for (const g of games) {
90
140
  const turns = turnKeys(g.turns);
91
141
  const truth = new Map(); // player → turn → income
@@ -106,6 +156,10 @@ export function catchUp(games) {
106
156
  const before = series.get(t - 1);
107
157
  if (before === undefined || before <= 0 || income < JUMP_FACTOR * before || t > last)
108
158
  continue;
159
+ if (!estimates.has(t)) {
160
+ unwatched++;
161
+ continue;
162
+ }
109
163
  let lag = null;
110
164
  for (const u of [...estimates.keys()].filter((u) => u >= t).sort((a, b) => a - b)) {
111
165
  const truthU = series.get(u) ?? income;
@@ -133,6 +187,7 @@ export function catchUp(games) {
133
187
  medianLag: n ? (n % 2 ? sorted[n >> 1] : (sorted[(n >> 1) - 1] + sorted[n >> 1]) / 2) : null,
134
188
  lags,
135
189
  censored,
190
+ unwatched,
136
191
  };
137
192
  }
138
193
  export function consequences(games) {
@@ -276,5 +331,6 @@ export function incomeCalibration(games) {
276
331
  worst,
277
332
  byStage: stageErrors(samples),
278
333
  trackedWhatIf: trackedWhatIf(samples),
334
+ heldBy: heldByView(samples),
279
335
  };
280
336
  }
@@ -7,6 +7,7 @@ import { armiesToTake, straightKills } from '../combat.js';
7
7
  import { neighborsOf } from '../graph.js';
8
8
  import { poolShortfall } from '../local-deploy.js';
9
9
  import { noLossNeutral } from './after-leftover.js';
10
+ import { deadAdvanceLine, deadAdvanceOf } from './dead-advance.js';
10
11
  import { visibleState } from './observe.js';
11
12
  import { captureCost } from './shared.js';
12
13
  import { byNum } from './util.js';
@@ -1182,8 +1183,14 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1182
1183
  stopped.push({ t, holdCost: f.holdCost, income: next });
1183
1184
  return why;
1184
1185
  };
1186
+ /** #593: the bonuses this turn's captures could complete (rule 4f's plans): their steps are no dead advance. */
1187
+ const completableIds = new Set(tgt.plans.filter((p) => p.completable).map((p) => p.bonusId));
1188
+ const completableNow = (id) => completableIds.has(id);
1189
+ /** #593: every attack on `t` leaves a conceded border with no deploy: it spends only armies given up anyway. */
1190
+ const givenUp = (t) => moves.every((m) => m.kind !== 'attack' || m.to !== t || (hd.conceded.has(m.from) && !(deployed.get(m.from) ?? 0)));
1185
1191
  /**
1186
- * Capture `t` for expansion, unless rule 4d's frontier budget stops it (then everything is undone).
1192
+ * Capture `t` for expansion, unless rule 4d's frontier budget stops it (then everything is undone), or (#593) it
1193
+ * advances only bonuses whose other member this plan concedes ({@link deadAdvanceOf}).
1187
1194
  * `bare` (#214): a lead step toward the closest bonus, which may be retried at its bare cost.
1188
1195
  * `force` (rule 5b, #218): the source, and the armies on it that stay out of the attack.
1189
1196
  */
@@ -1191,9 +1198,25 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1191
1198
  const restore = snapshot();
1192
1199
  if (!tryCapture(t, reason, force, undefined, bare))
1193
1200
  return false;
1201
+ // #593: never advance a bonus whose other member this plan concedes (its armies go to the next candidate). A
1202
+ // capture every attack of which leaves a conceded border with no deploy spends armies given up anyway; a
1203
+ // no-loss one (#426) risks only what lands.
1204
+ const dead = noLossNeutral(pc, tgt, t) ? null : deadAdvanceOf(pc, t, heldNow(), hd.conceded, tgt.deadBonuses, completableNow);
1205
+ if (dead && !givenUp(t)) {
1206
+ restore();
1207
+ // Said once per territory and bonus (an outer undo may take the line back with the rest).
1208
+ for (const d of dead) {
1209
+ const line = deadAdvanceLine(pc, t, d);
1210
+ if (!rationale.includes(line))
1211
+ rationale.push(line);
1212
+ }
1213
+ return false;
1214
+ }
1194
1215
  const why = outgrows(t);
1195
- if (why === null)
1216
+ if (why === null) {
1217
+ ps.expanded.add(t);
1196
1218
  return true;
1219
+ }
1197
1220
  restore();
1198
1221
  if (leadSteps.has(t))
1199
1222
  leadTry.set(t, { kind: 'frontier' });
@@ -1305,5 +1328,5 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1305
1328
  if (closest)
1306
1329
  run(todo.filter((t) => leadSteps.has(t) && !captured.has(t)), true);
1307
1330
  };
1308
- return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, gateStop, tryExpand, advance };
1331
+ return { snapshot, complete, unstaged, stage, stopped, stoppedLine, denied, outgrows, gateStop, givenUp, completableNow, tryExpand, advance };
1309
1332
  }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The bonuses a capture of `t` would advance though this plan concedes another member of them I hold, when every
3
+ * positive bonus `t` is in is such a bonus and the capture (with `held`, what I hold once this turn's captures so
4
+ * far land) completes none of them; else `null`. Called on expansion captures only (a break or a strike is no
5
+ * advance); never for a focused territory or land a static seat left (#281, #417). `conceded` is the plan's
6
+ * conceded borders as they stand; `carried` the bonuses an earlier plan of this turn found dead; `completable` the
7
+ * bonuses this turn's captures could complete (their steps are exempt).
8
+ */
9
+ export function deadAdvanceOf(pc, t, held, conceded, carried, completable = () => false) {
10
+ if (pc.inFocus(t) || pc.vacated.has(t) || pc.mineSet.has(t))
11
+ return null;
12
+ const bonuses = (pc.bonusesWith.get(t) ?? []).filter((id) => (pc.g.bonusById.get(id)?.value ?? 0) > 0);
13
+ if (!bonuses.length)
14
+ return null;
15
+ const after = new Set([...held, t]);
16
+ const dead = [];
17
+ for (const id of bonuses) {
18
+ const ts = pc.bonusTs.get(id) ?? [];
19
+ // A capture that completes the bonus is no advance (rule 1c then keeps its conceded member, #18).
20
+ if (ts.every((x) => after.has(x)))
21
+ return null;
22
+ const now = ts.filter((x) => x !== t && pc.mineSet.has(x) && conceded.has(x));
23
+ const was = carried.get(id)?.filter((x) => x !== t && pc.mineSet.has(x));
24
+ // A bonus an earlier plan advanced and left incomplete beside a concession is dead whatever this one finds.
25
+ if (was?.length) {
26
+ dead.push({ bonusId: id, members: now.length ? now : [...was], carried: !now.length });
27
+ continue;
28
+ }
29
+ // A step of a bonus this turn's captures can complete (every missing member a target) is left to the
30
+ // finished plan: the completion keeps its conceded member (rule 1c), and a step taken first (#214's order)
31
+ // must not block it; one the plan then leaves incomplete is carried into the next plan.
32
+ if (completable(id) || !now.length)
33
+ return null;
34
+ // Owner, 2026-11-27: an advance that breaks the bonus for the opponent attacking a conceded member is no dead
35
+ // advance — the capture takes his own member of it, or the one member he would still lack once mine fall.
36
+ if (breaksForAttacker(pc, t, ts, now))
37
+ return null;
38
+ dead.push({ bonusId: id, members: now, carried: false });
39
+ }
40
+ return dead;
41
+ }
42
+ /**
43
+ * Owner, 2026-11-27: the foes with a stack beside one of my conceded members `now` of the bonus `ts` (the attackers
44
+ * the concession gives them to), and whether taking `t` breaks the bonus for one of them: `t` is that attacker's, or
45
+ * `t` is neutral and every other member is already that attacker's or one of the conceded members. Pure.
46
+ */
47
+ export function breaksForAttacker(pc, t, ts, now) {
48
+ const ownerOf = (x) => {
49
+ const o = pc.territories.get(x)?.owner;
50
+ return o?.kind === 'player' ? o.playerId : null;
51
+ };
52
+ const attackers = new Set();
53
+ for (const m of now)
54
+ for (const n of pc.g.neighbors.get(m) ?? []) {
55
+ const p = ownerOf(n);
56
+ const st = pc.territories.get(n);
57
+ if (p !== null && pc.foe(p) && (st?.armies ?? 0) > 0)
58
+ attackers.add(p);
59
+ }
60
+ if (!attackers.size)
61
+ return false;
62
+ const owner = ownerOf(t);
63
+ if (owner !== null)
64
+ return attackers.has(owner);
65
+ if (pc.territories.get(t)?.owner.kind !== 'neutral')
66
+ return false;
67
+ const conceded = new Set(now);
68
+ return [...attackers].some((a) => ts.every((x) => x === t || conceded.has(x) || ownerOf(x) === a));
69
+ }
70
+ /** The rationale line for a refused advance of `t` (one per bonus). */
71
+ export function deadAdvanceLine(pc, t, d) {
72
+ const members = d.members.map(pc.label).join(', ');
73
+ const its = d.members.length === 1 ? 'its member' : 'its members';
74
+ return d.carried
75
+ ? `Do not take ${pc.label(t)} toward bonus ${pc.bonusName(d.bonusId)}: the plan that took it conceded ${its} ${members}, so the capture builds a bonus this turn gives up: its armies are left to the plan's other orders (#593).`
76
+ : `Do not take ${pc.label(t)} toward bonus ${pc.bonusName(d.bonusId)}: this plan concedes ${its} ${members}, so the capture builds a bonus this turn gives up: its armies are left to the plan's other orders (#593).`;
77
+ }
@@ -6,6 +6,29 @@ import { armyCapIncome, boardIncome, DEFAULT_BASE_INCOME, incomeRules, territory
6
6
  import { byNum } from './util.js';
7
7
  import { LOW_COVERAGE, MIN_ENEMY_DEPLOY, OWNERS_SHOWN_FOG, PRIOR_EVIDENCE_TURNS, TRACKED_MIN_TURNS, bombPossibleOn, fogPaceIncome, localFreeOn, reinforcementArmiesFor } from './shared.js';
8
8
  import { observeDeploy, ownerShown, trackCoverage, visibleState } from './observe.js';
9
+ import { coverageBucket } from '../game-lessons.js';
10
+ /** #436's gate, repeated for the planner (#568): a band's calibration counts only from this many samples. */
11
+ const MIN_TRACK_CALIBRATION_SAMPLES = 5;
12
+ /**
13
+ * #568 (owner decision 2026-11-27): the tracked figure is divided by its band's past estimate ÷ truth
14
+ * to this power — the square root, as #567's `STATED_DAMPING` damps a stated ratio — so a band that read 0.3×
15
+ * truth raises the tracked figure ~1.8×, not ~3.3×: the factor is a geometric mean over a spread wide enough
16
+ * that the full correction would put half the estimates above the truth.
17
+ */
18
+ export const TRACK_CALIBRATION_DAMPING = 0.5;
19
+ /**
20
+ * #568: the factor a tracked figure read from `share` of its frontier is divided by: its coverage band's past
21
+ * geometric mean of estimate ÷ truth (`calibration`, from lessons.json) to the {@link TRACK_CALIBRATION_DAMPING}
22
+ * power; `undefined` when the band has under {@link MIN_TRACK_CALIBRATION_SAMPLES} samples or read at least the
23
+ * truth (the correction only ever raises).
24
+ */
25
+ export function trackCalibrationFactor(calibration, share) {
26
+ const band = coverageBucket(share);
27
+ const c = calibration?.[band];
28
+ if (!c || c.n < MIN_TRACK_CALIBRATION_SAMPLES || !(c.geoMean > 0) || c.geoMean >= 1)
29
+ return undefined;
30
+ return { band, geoMean: c.geoMean, n: c.n, factor: c.geoMean ** TRACK_CALIBRATION_DAMPING };
31
+ }
9
32
  /**
10
33
  * The army count every visible player territory holds, when they all hold the same one (the
11
34
  * initial allotment). Neutrals are left out (#128): their stacks are not the starting stacks on
@@ -279,6 +302,20 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
279
302
  const observedCap = observation ? couldEarn : null;
280
303
  const observedRaw = observation?.deploy ?? null;
281
304
  const observed = observation ? Math.min(observation.deploy, observedCap) : null;
305
+ // #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
306
+ const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
307
+ // #568: the tracker reads low under fog (every observed deploy a lower bound); past games' estimate ÷
308
+ // truth in its coverage band raises the tracked figure from here on (never above what it could earn, never
309
+ // lowered). The #123 bound above keeps the tracker's own figure.
310
+ let trackCalibration = null;
311
+ if (usable && tracked !== null && tracked > 0) {
312
+ const c = trackCalibrationFactor(when.calibration, coverage ? coverage.share : null);
313
+ const figure = c ? Math.min(Math.max(couldEarn, tracked), Math.round(tracked / c.factor)) : tracked;
314
+ if (c && figure > tracked) {
315
+ trackCalibration = { raw: tracked, band: c.band, geoMean: c.geoMean, n: c.n, factor: c.factor, figure };
316
+ tracked = figure;
317
+ }
318
+ }
282
319
  // A usable track replaces the single-turn observed figure (S3; #235 1c: its newest reading too).
283
320
  const seenSource = tracked !== null
284
321
  ? tracked > visible
@@ -316,8 +353,6 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
316
353
  }
317
354
  const priorUsed = priorBlend ? priorBlend.figure : priorFigure;
318
355
  const source = exact !== null ? 'exact' : priorUsed !== null && priorUsed > seen ? 'prior' : seenSource;
319
- // #294: what its tracked figure was read from (#368: while that is little, thin evidence below).
320
- const coverage = usable ? trackCoverage(usable.turns.filter((x) => usable.incomeTurns.includes(x.from))) : null;
321
356
  // #444: an untracked opponent whose prior a stated income scaled: #368's midpoint between what is in
322
357
  // view (or observed) and that prior.
323
358
  const statedMid = statedRatio !== null && source === 'prior' && !usable ? seen + Math.ceil((priorUsed - seen) / 2 - 1e-9) : null;
@@ -455,6 +490,7 @@ export function enemyDeployEstimates(g, board, me, settings = {}, previous, trac
455
490
  cardPlayed,
456
491
  ...(cardSeen ? { cardSeen: true } : {}),
457
492
  ...(cardInTrack ? { cardInTrack } : {}),
493
+ ...(trackCalibration ? { trackCalibration } : {}),
458
494
  ...(priorFull !== null && priorFigure < priorFull ? { stated: { full: priorFull, scaled: priorFigure, lower: seen, midpoint: statedMid } } : {}),
459
495
  };
460
496
  });
@@ -98,6 +98,7 @@ export function planEnemyEstimates(input) {
98
98
  reinforcement: ctx.reinforcement,
99
99
  ...(ctx.reinforcementPlays ? { plays: ctx.reinforcementPlays } : {}),
100
100
  ...(previousBoard && input.previousOrders ? { previousOrders: input.previousOrders } : {}),
101
+ ...(ctx.trackCalibration ? { calibration: ctx.trackCalibration } : {}),
101
102
  });
102
103
  const priced = applyKnown(applyArmyPrice(applySanctions(estimates, input.sanctions ?? [], turn), input.settings?.armyCostMultiplier ?? 0), input.known ?? []);
103
104
  return { estimates: priced, prior, ...(skipped ? { priorSkipped: skipped } : {}) };
@@ -0,0 +1,86 @@
1
+ import { bonusTerritories } from '../bonuses.js';
2
+ import { neighborsOf } from '../graph.js';
3
+ import { ownerShown, visibleState } from './shared.js';
4
+ /** A one-short denial (item 5a) is worth this share of the bonus: the opponent does not earn it yet. */
5
+ export const ONE_SHORT_WEIGHT = 0.5;
6
+ /** Item 5a's opening: the turns a one-short denial is tried on. */
7
+ export const OPENING_STRIKE_FIRST = 2;
8
+ export const OPENING_STRIKE_LAST = 4;
9
+ /**
10
+ * The opponent bonuses a 1v1 may break behind the fog, and (on the opening turns) the ones it is one
11
+ * territory short of. `known`: the bonuses already breakable (visible, or the tracker's #72 inference),
12
+ * which are left out. Sorted by bonus id.
13
+ */
14
+ export function foggedBreakables(g, state, foe, mine, known, turn) {
15
+ const opening = turn !== null && turn >= OPENING_STRIKE_FIRST && turn <= OPENING_STRIKE_LAST;
16
+ const out = [];
17
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
18
+ if (b.value <= 0 || known.has(b.id))
19
+ continue;
20
+ const ts = bonusTerritories(g, b.id);
21
+ if (!ts.length)
22
+ continue;
23
+ const players = new Set();
24
+ const others = [];
25
+ let fogged = 0;
26
+ for (const t of ts) {
27
+ const st = state.get(t);
28
+ const shown = ownerShown(st);
29
+ if (!shown) {
30
+ fogged++;
31
+ continue;
32
+ }
33
+ if (shown.owner.kind === 'player' && foe(shown.owner.playerId)) {
34
+ players.add(shown.owner.playerId);
35
+ if (!visibleState(st))
36
+ fogged++;
37
+ }
38
+ else
39
+ others.push(t);
40
+ }
41
+ if (players.size !== 1)
42
+ continue;
43
+ const player = [...players][0];
44
+ const members = ts
45
+ .filter((t) => {
46
+ const st = visibleState(state.get(t));
47
+ return st?.owner.kind === 'player' && st.owner.playerId === player && neighborsOf(g, t).some((n) => mine.has(n));
48
+ })
49
+ .sort((x, y) => x - y);
50
+ if (!members.length)
51
+ continue;
52
+ if (!others.length) {
53
+ if (!fogged)
54
+ continue;
55
+ out.push({
56
+ bonusId: b.id,
57
+ value: b.value,
58
+ player,
59
+ probable: `a member in view is its and its ${fogged} fogged member${fogged > 1 ? 's' : ''} could all be its, #593`,
60
+ members,
61
+ fogged,
62
+ });
63
+ continue;
64
+ }
65
+ if (!opening || others.length !== 1 || state.get(others[0])?.owner.kind !== 'neutral')
66
+ continue;
67
+ out.push({
68
+ bonusId: b.id,
69
+ value: b.value,
70
+ player,
71
+ probable: `one territory short of complete, ${others[0]} still neutral, #593`,
72
+ members,
73
+ fogged,
74
+ shortOf: others[0],
75
+ });
76
+ }
77
+ return out;
78
+ }
79
+ /**
80
+ * The deploy a #593 break is sized for: the opponent's deploy estimate on the target (`estimate`) split
81
+ * over `fronts`, the territories of its in view beside my land (it cannot tell which one I strike, and one
82
+ * deploy floats to one place), rounded up; with one such territory, the whole estimate.
83
+ */
84
+ export function partialDeploy(estimate, fronts) {
85
+ return Math.ceil(Math.max(0, estimate) / Math.max(1, fronts));
86
+ }
@@ -8,7 +8,7 @@ import { bonusTerritories } from '../bonuses.js';
8
8
  import { neighborsOf } from '../graph.js';
9
9
  import { twoStepReaches } from '../lookahead.js';
10
10
  import { opensBehind } from '../opens.js';
11
- import { BREACH_WEIGHT, CITE_CLOSE, CITE_OPEN, CITE_SEP, CONCEDE_FACTOR, MIN_ENEMY_DEPLOY, nearMissMargin, } from './shared.js';
11
+ import { BREACH_WEIGHT, HUB_WEIGHT, CITE_CLOSE, CITE_OPEN, CITE_SEP, CONCEDE_FACTOR, MIN_ENEMY_DEPLOY, nearMissMargin, } from './shared.js';
12
12
  import { relaxedFor } from './relations.js';
13
13
  import { byNum } from './util.js';
14
14
  import { lateArrivals, reconsiderAndGarrison, withdrawals } from './withdraw.js';
@@ -141,7 +141,7 @@ export function holdBasics(pc, ps, book, threats) {
141
141
  */
142
142
  export function soloLeaderHolds(pc, ps, book, threats, prev) {
143
143
  const { g, ffaLeader, paybackTurns, label, bonusName, unitsAt, toTake, myCommanders } = pc;
144
- const { valueOf, stakeAt, pools } = book;
144
+ const { valueOf, stakeAt, pools, hubWorthOf } = book;
145
145
  const { borders, borderAt, safeAtStart } = threats;
146
146
  const { uneconomic, stayAt } = prev;
147
147
  if (!ffaLeader)
@@ -220,7 +220,8 @@ export function soloLeaderHolds(pc, ps, book, threats, prev) {
220
220
  continue;
221
221
  let joint = 0;
222
222
  let single = 0;
223
- let worth = bonus.value;
223
+ // #593: a hub among its threatened members adds its share once.
224
+ let worth = bonus.value + hubWorthOf(bonus.id, members);
224
225
  let recent = false;
225
226
  const lowered = [];
226
227
  for (const t of members) {
@@ -503,9 +504,9 @@ export function twoStepHolds(pc, ps, book, threats, hb, pass, prev) {
503
504
  }
504
505
  /** Rule 1a: judge each threatened border, hold it or concede it, and say why (rule 1k's commander included). */
505
506
  export function holdOrConcede(pc, ps, book, threats, hb, prev) {
506
- const { goal, paybackTurns, label, unitsAt, bombOn, toTake, myCommanders } = pc;
507
+ const { goal, paybackTurns, label, bonusName, unitsAt, bombOn, toTake, myCommanders } = pc;
507
508
  const { warnings, rationale, locked } = ps;
508
- const { deploy, valueOf, stakeAt, cutOff, breachAt, opensAt } = book;
509
+ const { deploy, valueOf, stakeAt, cutOff, breachAt, opensAt, hubsAt } = book;
509
510
  const { borders, recentlyTakenFrom } = threats;
510
511
  const { threatened, conceded } = hb;
511
512
  const { stayAt } = prev;
@@ -519,6 +520,8 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
519
520
  const breachNoted = new Set();
520
521
  /** #291: the gates whose opened value is already named. */
521
522
  const opensNoted = new Set();
523
+ /** #593: the hubs whose value is already named. */
524
+ const hubNoted = new Set();
522
525
  /** Rule 1a's pre-deploy threat warning per border, restated once the deploys are known. */
523
526
  const threatWarnings = new Map();
524
527
  const assessThreats = () => {
@@ -564,6 +567,12 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
564
567
  const more = opens.ids.length > MAX_CUT_NAMED ? ` and ${opens.ids.length - MAX_CUT_NAMED} more` : '';
565
568
  rationale.push(`${label(b.id)} is the only way in to ${named}${more} (+${opens.income} income): losing it opens them to the enemy, so its value counts half of that (+${opens.worth}) (#291).`);
566
569
  }
570
+ // #593: a hub of a held bonus says what its fall takes.
571
+ if (!hubNoted.has(b.id))
572
+ for (const h of hubsAt(b.id)) {
573
+ hubNoted.add(b.id);
574
+ rationale.push(`${label(b.id)} borders ${h.borders} of bonus ${bonusName(h.bonusId)}'s ${h.others} other members: its fall takes the rest, so its value counts ${HUB_WEIGHT * 100}% of the bonus more (+${h.worth}) (#593).`);
575
+ }
567
576
  const from = recentlyTakenFrom(b.id);
568
577
  threatened.push({
569
578
  id: b.id,
@@ -635,7 +644,7 @@ export function holdOrConcede(pc, ps, book, threats, hb, prev) {
635
644
  export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
636
645
  const { g, paybackTurns, label, bonusName, incomeAfter, toTake } = pc;
637
646
  const { warnings, rationale, locked } = ps;
638
- const { deploy, undeploy, pools, roomAt, stakeAt } = book;
647
+ const { deploy, undeploy, pools, roomAt, stakeAt, hubWorthOf, hubsAt } = book;
639
648
  const local = pools !== null && pools.bonuses.length > 0;
640
649
  const { expectedAt } = threats;
641
650
  const { threatened, conceded, units } = hb;
@@ -670,7 +679,9 @@ export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
670
679
  // the unit's cost and its payback test. A hold rule 1k could not fully fund still counts.
671
680
  const paying = members.filter((m) => !commanderHeld.has(m.id));
672
681
  const cost = paying.reduce((n, m) => n + m.holdCost, 0);
673
- const worth = b.value + paying.reduce((n, m) => n + (m.have + stakeAt(m.id)) / paybackTurns, 0);
682
+ // #593: a hub among the members it pays for adds HUB_WEIGHT × its value, once.
683
+ const hub = hubWorthOf(b.id, paying.map((m) => m.id));
684
+ const worth = b.value + hub + paying.reduce((n, m) => n + (m.have + stakeAt(m.id)) / paybackTurns, 0);
674
685
  // It pays back within PAYBACK_TURNS, and (as rule 1a asks of every border) costs at
675
686
  // most CONCEDE_FACTOR × its worth, unless a member was just taken from a weak opponent.
676
687
  const recent = members.some((m) => m.recentFrom !== undefined);
@@ -690,6 +701,9 @@ export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
690
701
  conceded: false,
691
702
  floored: false,
692
703
  contested: false,
704
+ ...(hub > 0 && !recent && net <= paybackTurns * b.value && net <= CONCEDE_FACTOR * worth && net > CONCEDE_FACTOR * (worth - hub)
705
+ ? { hubOnly: true }
706
+ : {}),
693
707
  });
694
708
  }
695
709
  };
@@ -697,7 +711,10 @@ export function heldBonusUnits(pc, ps, book, threats, hb, prev) {
697
711
  const inLiveUnit = (id) => units.some((u) => !u.conceded && u.members.some((m) => m.id === id));
698
712
  /** `t` judged on its own: its protected value less the bonuses of the units conceded with it. */
699
713
  const residual = (t) => {
700
- const lost = units.filter((u) => u.conceded && u.members.some((m) => m.id === t.id)).reduce((n, u) => n + u.value, 0);
714
+ // #593: a conceded bonus takes its hub share with it.
715
+ const lost = units
716
+ .filter((u) => u.conceded && u.members.some((m) => m.id === t.id))
717
+ .reduce((n, u) => n + u.value + (hubsAt(t.id).find((h) => h.bonusId === u.bonusId)?.worth ?? 0), 0);
701
718
  const value = Math.max(0, t.value - lost);
702
719
  return { ...t, value, worth: value + (t.have + stakeAt(t.id)) / paybackTurns };
703
720
  };
@@ -1389,7 +1406,9 @@ export function floorTier(pc, ps, book, threats, hb, prev) {
1389
1406
  // #118: CONCEDE_FACTOR and the payback test concede a floored unit only when the armies have
1390
1407
  // a better use: it is kept, and held whole after the captures if what is left covers it.
1391
1408
  const losing = units.filter((u) => u.loss);
1392
- floorUnits(losing);
1409
+ // #593: a unit paying only for its hub share gets the same floor first, but still competes to be held whole; when it
1410
+ // cannot be, `floorOrConcede` finds the floor in place and keeps it contested.
1411
+ floorUnits([...losing, ...units.filter((u) => !u.loss && u.hubOnly)]);
1393
1412
  for (const u of losing)
1394
1413
  contest(u);
1395
1414
  const items = [
@@ -9,7 +9,7 @@ import { neighborsOf } from '../graph.js';
9
9
  import { chargeDeploys, deployPools } from '../local-deploy.js';
10
10
  import { territoryIncome } from '../player.js';
11
11
  import { opensBehind } from '../opens.js';
12
- import { BREACH_WEIGHT, OPENS_WEIGHT, WASTELAND_FACTOR, visibleState } from './shared.js';
12
+ import { BREACH_WEIGHT, HUB_DEGREE, HUB_MIN_MEMBERS, HUB_WEIGHT, OPENS_WEIGHT, WASTELAND_FACTOR, visibleState } from './shared.js';
13
13
  import { byNum } from './util.js';
14
14
  import { secondLineOf } from './guard-off.js';
15
15
  /** Open the deploy book of one pass: sets `ps.budget`, `ps.holdings` and the starting `avail`. */
@@ -326,6 +326,39 @@ export function deployBook(ctx, ps, previousBoard) {
326
326
  return out;
327
327
  };
328
328
  const opensCache = new Map();
329
+ /**
330
+ * #593: the bonuses my `t` is a hub of — positive, held in full, at least {@link HUB_MIN_MEMBERS} members, `t`
331
+ * bordering at least {@link HUB_DEGREE} of the others: its fall takes the rest (on 16 lost 1v1s' boards such a
332
+ * member lost 78% of the rest by the next turn, one bordering < 50% 20%, and none was ever retaken). Each counts
333
+ * {@link HUB_WEIGHT} × its value on top of the bonus. Never double-counted: #235's cut counts bonuses wholly cut
334
+ * off, #275's breach and #291's opens bonuses not containing `t`, so none of them counts `t`'s own bonus.
335
+ */
336
+ const hubsAt = (t) => {
337
+ const cached = hubCache.get(t);
338
+ if (cached)
339
+ return cached;
340
+ const out = [];
341
+ if (ps.holdings.has(t)) {
342
+ const near = new Set(neighborsOf(g, t));
343
+ for (const b of [...g.map.bonuses].sort((x, y) => x.id - y.id)) {
344
+ if (b.value <= 0)
345
+ continue;
346
+ const ts = bonusTerritories(g, b.id);
347
+ if (ts.length < HUB_MIN_MEMBERS || !ts.includes(t) || !ts.every((x) => ps.holdings.has(x)))
348
+ continue;
349
+ const others = ts.filter((x) => x !== t);
350
+ const borders = others.filter((x) => near.has(x)).length;
351
+ if (borders < HUB_DEGREE * others.length)
352
+ continue;
353
+ out.push({ bonusId: b.id, value: b.value, borders, others: others.length, worth: Math.round(HUB_WEIGHT * b.value * 10) / 10 });
354
+ }
355
+ }
356
+ hubCache.set(t, out);
357
+ return out;
358
+ };
359
+ const hubCache = new Map();
360
+ /** #593: the hub worth of bonus `bonusId` among `members` (once per bonus, however many of them are its hubs). */
361
+ const hubWorthOf = (bonusId, members) => members.map((m) => hubsAt(m).find((h) => h.bonusId === bonusId)?.worth ?? 0).reduce((a, b) => Math.max(a, b), 0);
329
362
  const protectedValue = (t) => {
330
363
  // Each bonus is visited once, so it counts once however many of its borders are threatened.
331
364
  // #235: plus the income of what losing it cuts off from the rest of my holdings.
@@ -346,7 +379,8 @@ export function deployBook(ctx, ps, previousBoard) {
346
379
  if (b.value === 0)
347
380
  continue;
348
381
  if (ts.every((x) => ps.holdings.has(x))) {
349
- v += b.value;
382
+ // #593: a hub's fall takes the rest of the bonus, which comes back only member by member.
383
+ v += b.value + (hubsAt(t).find((h) => h.bonusId === b.id)?.worth ?? 0);
350
384
  continue;
351
385
  }
352
386
  // An incomplete bonus I am working on (T is in it): lost access if T is my only way in.
@@ -418,6 +452,9 @@ export function deployBook(ctx, ps, previousBoard) {
418
452
  breachCache,
419
453
  opensAt,
420
454
  opensCache,
455
+ hubsAt,
456
+ hubCache,
457
+ hubWorthOf,
421
458
  stakeAt,
422
459
  };
423
460
  }
@@ -530,6 +530,9 @@ export function reportOffence(pc, ps, book, threats, hd, tgt, holdLocked, leadSp
530
530
  if (lead.spare < sure)
531
531
  return `a lead strike (my army lead is ${leadText()}, over ${SECOND_FRONT_LEAD}×) needs ${sure} — sized for its ${defenceAt(n)} defenders plus player ${p}'s ~${extra} deploy — and the most a neighbour of mine can spare for it is ${lead.spare}${lead.spare > 0 ? ` (${label(lead.x)})` : ''}${deployText}`;
532
532
  }
533
+ // #593: a member of a bonus probably held behind the fog is a break candidate that was not funded.
534
+ if (tgt.foggedMember.has(n))
535
+ return `${label(best.x)} could spare ${best.spare} for it, and it probably breaks a bonus behind the fog (#593), but that break, sized for a partial deploy, did not fit or ranked below what the turn funded`;
533
536
  return `${label(best.x)} could spare ${best.spare} for it, but it breaks no bonus and is no counter-attack, finishing blow or strike — the only reasons the plan attacks a player's territory (rule 2), besides rule 4e's fallback when nothing else is captured${!ffaLead
534
537
  ? ''
535
538
  : !leadLever
@@ -16,6 +16,24 @@ export const BREACH_WEIGHT = 0.5;
16
16
  * reaches only through it) that its protected value counts — the enemy still has to walk in, as with a breach.
17
17
  */
18
18
  export const OPENS_WEIGHT = 0.5;
19
+ /**
20
+ * #593: a member of a positive bonus I hold in full with at least this many members whose fall can take the rest of
21
+ * the bonus (a hub, {@link HUB_DEGREE}). Smaller bonuses are left out: in a 2- or 3-member bonus every member borders
22
+ * most of the others, and the follow-on loss was measured on 4+ members only.
23
+ */
24
+ export const HUB_MIN_MEMBERS = 4;
25
+ /** #593: the share of the bonus's other members a hub borders (at least). */
26
+ export const HUB_DEGREE = 0.75;
27
+ /**
28
+ * #593: the share of the bonus's value a hub's protected value counts on top of the bonus itself. Measured on 16 lost
29
+ * 1v1s' history boards: when a held bonus of 4+ members lost its first member, a member bordering ≥ 75% of the
30
+ * others lost 78% of the rest by the next turn (the whole bonus 6 of 9; every one of 3 hubs bordering all), one
31
+ * bordering < 50% lost 20% (never the whole bonus, 0 of 19), and no lost member was ever retaken (0 of 48). The
32
+ * excess follow-on loss, 0.78 − 0.20 = 0.58 ≈ 0.6 (the owner's choice, 2026-11-27), is the rest of the bonus that has to
33
+ * be taken back member by member before it pays again. Once rule 1c counts this turn's captures, a bonus they complete has hubs too (owner,
34
+ * 2026-11-27).
35
+ */
36
+ export const HUB_WEIGHT = 0.6;
19
37
  /** #201: the shortest payback horizon once the game is decided. */
20
38
  export const DECIDED_PAYBACK_MIN = 3;
21
39
  /** …or when one remaining territory alone costs more than this many times its value (a wasteland). */