@chrischall/warapp-mcp 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +2 -2
  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 +76 -13
  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 +513 -0
  14. package/dist/analysis/plan/doomed-out.js +135 -0
  15. package/dist/analysis/plan/estimates.js +3 -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/stand-still.js +5 -3
  25. package/dist/analysis/plan/state.js +12 -0
  26. package/dist/analysis/plan/strike-stack.js +467 -0
  27. package/dist/analysis/plan/strike.js +3 -463
  28. package/dist/analysis/plan/targets.js +213 -26
  29. package/dist/analysis/plan/threats.js +12 -4
  30. package/dist/analysis/plan/transfers.js +24 -1
  31. package/dist/analysis/plan/two-move.js +1 -1
  32. package/dist/analysis/plan/withdraw.js +316 -0
  33. package/dist/analysis/planner.js +54 -11
  34. package/dist/analysis/player.js +4 -0
  35. package/dist/analysis/relations.js +8 -2
  36. package/dist/analysis/stress.js +1 -1
  37. package/dist/bundle.js +8008 -7184
  38. package/dist/my-games.js +2 -0
  39. package/dist/open-games.js +94 -10
  40. package/dist/tools/card-advice.js +26 -11
  41. package/dist/tools/card-support-advice.js +17 -1
  42. package/dist/tools/check-plan.js +2 -1
  43. package/dist/tools/commander-check.js +2 -1
  44. package/dist/tools/decision-capture.js +4 -2
  45. package/dist/tools/join-game.js +44 -8
  46. package/dist/tools/live.js +33 -5
  47. package/dist/tools/open-games.js +2 -2
  48. package/dist/tools/picks.js +120 -47
  49. package/dist/tools/turn.js +43 -4
  50. package/dist/version.js +1 -1
  51. package/manifest.json +1 -1
  52. package/package.json +1 -1
  53. package/server.json +2 -2
@@ -5,6 +5,9 @@
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
+ import { noLossNeutral } from './after-leftover.js';
10
+ import { visibleState } from './observe.js';
8
11
  import { captureCost } from './shared.js';
9
12
  import { byNum } from './util.js';
10
13
  import { denialLine, emptyEnemyLine } from './vacated.js';
@@ -17,7 +20,7 @@ export function capturesPhase(pc, ps, pass, book, threats, hd, tgt) {
17
20
  }
18
21
  /** R3: a completion must leave a frontier I can hold; No-Split (#124): a stack that must hold. */
19
22
  export function captureRules(pc, ps, book, threats, hd) {
20
- const { g, s, foe, goal, guarded, reserve, deployOf, territories: state, label, bonusName, mine, mineSet, armiesOf, unitsAt, defenceAt, bonusTs, completedBy, guard, toTake, noSplit, myCommanders, } = pc;
23
+ const { g, s, foe, goal, guarded, reserve, deployOf, territories: state, label, bonusName, mine, mineSet, armiesOf, unitsAt, defenceAt, bonusTs, completedBy, guard, toTake, noSplit, myCommanders, rates, } = pc;
21
24
  const { warnings, rationale, deployed, avail, captured, survivorsAt, incoming } = ps;
22
25
  const { guardAt, valueOf } = book;
23
26
  const { holdArmies, nextTurnAt, exposure, borderAt } = threats;
@@ -39,8 +42,9 @@ export function captureRules(pc, ps, book, threats, hd) {
39
42
  * The total need is checked, not each member alone: holding the bonus needs every
40
43
  * exposed member held. The leftover is as of this check; a later capture this turn
41
44
  * may still spend it (defence funds held borders first, so this is rarely material).
45
+ * `lost`: the attackers the capture of `t` loses (#422), for the payback exemption below.
42
46
  */
43
- const defensible = (t, survivors) => {
47
+ const defensible = (t, survivors, lost) => {
44
48
  const after = new Set([...mine, ...captured]);
45
49
  const completes = g.map.bonuses
46
50
  .filter((b) => {
@@ -84,6 +88,8 @@ export function captureRules(pc, ps, book, threats, hd) {
84
88
  .flatMap(exposedOf))
85
89
  earlier.set(e.id, Math.max(earlier.get(e.id) ?? 0, e.added));
86
90
  let ok = true;
91
+ /** #422: the completions let through on payback, kept only when the capture is (no other bonus refuses it). */
92
+ const payback = [];
87
93
  for (const b of completes) {
88
94
  const exposed = exposedOf(b.id);
89
95
  const total = exposed.reduce((sum, e) => sum + e.added, 0);
@@ -93,10 +99,28 @@ export function captureRules(pc, ps, book, threats, hd) {
93
99
  // A completion that adds no exposure (total 0) is never refused: refusing it saves nothing,
94
100
  // whatever the earlier completions need (it only adds income).
95
101
  if (total === 0 || total + before <= nextIncome + Math.min(spare, held)) {
102
+ // #422: judged holdable now (a later try, with more income), so no longer a payback completion.
103
+ ps.paybackBonuses.delete(b.id);
96
104
  if (anyway.length && guarded)
97
105
  rationale.push(`Complete bonus ${bonusName(b.id)} though ${anyway.map((e) => label(e.id)).join(', ')} may fall next turn: ${anyway.length === 1 ? 'it is' : 'they are'} exposed whether or not it is completed, so refusing would save nothing.`);
98
106
  continue;
99
107
  }
108
+ // #422: the payback exemption. A bonus held at the end of this turn pays its value in next turn's
109
+ // income even if it falls straight after, so a completion whose losses — the attackers its captures
110
+ // lose this turn plus the armies left on the members that would fall — are at most that value
111
+ // repays itself in one turn: refusing it only gives the income up.
112
+ if (guarded) {
113
+ const falls = exposed.filter((e) => e.added > 0);
114
+ const left = falls.reduce((n, e) => n + stays(e.id), 0);
115
+ const killed = bonusTerritories(g, b.id)
116
+ .filter((m) => captured.has(m) && !mineSet.has(m))
117
+ .reduce((n, m) => n + (m === t && lost !== undefined ? lost : straightKills(defenceAt(m), rates.defensiveKillRate)), 0);
118
+ if (killed + left <= b.value) {
119
+ const line = `Complete bonus ${bonusName(b.id)} though its frontier cannot be held next turn (it needs ${total} more armies${before ? `, on top of the ${before} this turn's other completions need` : ''}, next income ${nextIncome}): it can lose at most ${killed + left} armies (${killed} killed taking it, ${left} left on ${falls.map((e) => label(e.id)).join(', ')}), no more than the +${b.value} it pays next turn (#422).`;
120
+ payback.push({ line, bonusId: b.id, falls: falls.map((e) => e.id) });
121
+ continue;
122
+ }
123
+ }
100
124
  const worst = [...exposed].sort((a, b) => b.added - a.added || b.need - a.need || a.id - b.id)[0];
101
125
  const head = `completing ${bonusName(b.id)} leaves ${label(worst.id)} indefensible (player ${worst.player} can take it for ${worst.take}; next income ${nextIncome})`;
102
126
  if (guarded) {
@@ -114,6 +138,14 @@ export function captureRules(pc, ps, book, threats, hd) {
114
138
  warnings.push(w);
115
139
  }
116
140
  }
141
+ if (ok)
142
+ for (const x of payback) {
143
+ if (!rationale.includes(x.line))
144
+ rationale.push(x.line);
145
+ for (const f of x.falls)
146
+ ps.paybackFalls.set(f, x.line);
147
+ ps.paybackBonuses.set(x.bonusId, x.line);
148
+ }
117
149
  return ok;
118
150
  };
119
151
  // ---- No-Split: the whole stack moves (#124) ----
@@ -476,7 +508,7 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
476
508
  captured.add(t);
477
509
  const survivors = sent - straightKills(defendersSeen(t), rates.defensiveKillRate);
478
510
  // A commander strike is never refused by R3: killing the commander eliminates a player.
479
- if (!strikes.has(t) && !r3Exempt.has(t) && !defensible(t, survivors)) {
511
+ if (!strikes.has(t) && !r3Exempt.has(t) && !defensible(t, survivors, sent - survivors)) {
480
512
  // Undo: under a guarded goal a bonus that falls next turn is not completed.
481
513
  avail.set(src, avail.get(src) + sent - need);
482
514
  const left = (deployed.get(src) ?? 0) - need;
@@ -631,7 +663,9 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
631
663
  }
632
664
  avail.set(plan.finisher, avail.get(plan.finisher) - plan.armies);
633
665
  captured.add(t);
634
- if (!defensible(t, plan.survivors)) {
666
+ // #422: what the combined capture loses — every softener's dead and the finisher's.
667
+ const lost = plan.softeners.reduce((n, x) => n + x.armies - x.survivors, 0) + plan.armies - plan.survivors;
668
+ if (!defensible(t, plan.survivors, lost)) {
635
669
  for (const [k, v] of before.avail)
636
670
  avail.set(k, v);
637
671
  incoming.clear();
@@ -851,11 +885,11 @@ export function captureHelper(pc, ps, pass, book, threats, hd, tgt, prev) {
851
885
  }
852
886
  /** Pass 1 (complete a bonus, all or nothing) and pass 2 (advance one a capture at a time, rule 4c(c), 4d). */
853
887
  export function bonusPasses(pc, ps, book, hd, tgt, prev) {
854
- const { g, s, guarded, paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
888
+ const { g, s, guarded, capturePaybackTurns: paybackTurns, territories: state, label, bonusName, mineSet, incomeGain, incomeAfter, defenceAt, bonusTs, completedBy, inFocus, } = pc;
855
889
  const { warnings, rationale, deployed, avail, captured, combined, moves, survivorsAt, captureOrder, staged, incoming, } = ps;
856
890
  const { heldNow, gainWith } = book;
857
- const { heldBorders, keptIncome, stayAt } = hd;
858
- const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
891
+ const { heldBorders, keptIncome, keptHeld, stayAt } = hd;
892
+ const { targets, leadSteps, leadTry, leadNote, bonusTarget, frontierDelta, targetScoreCost, frontierOf, frontierNeeds, startHold, toFinish, byCloseness, committing, denials, emptyEnemies, } = tgt;
859
893
  const { worstCase, tryCapture, siblings, fundedOnConceded, bareOn } = prev;
860
894
  // ---- pass 1: complete a bonus this turn (all or nothing) ----
861
895
  /** Snapshot the captures, deploys and notes so far; the result undoes everything since. */
@@ -1048,11 +1082,18 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1048
1082
  return null;
1049
1083
  const f = frontierOf(held, stays);
1050
1084
  const next = keptIncome(held);
1051
- if (f.holdCost <= next || f.holdCost <= frontierOf(without, stays).holdCost)
1085
+ // #433: under Local Deployment a bonus's armies deploy only on its own territories, so the gates get only the
1086
+ // free income and the pools of the bonuses they are in: the whole income read "not short" when that was short.
1087
+ const pooled = s.localDeployments ? poolShortfall(g, keptHeld(held), next, frontierNeeds(held, stays)) : null;
1088
+ const short = pooled ? pooled.short : Math.max(0, f.holdCost - next);
1089
+ if (short <= 0 || f.holdCost <= frontierOf(without, stays).holdCost)
1052
1090
  return null;
1091
+ const byPools = pooled !== null && f.holdCost <= next;
1053
1092
  if (!stopped.some((x) => x.t === t))
1054
- stopped.push({ t, holdCost: f.holdCost, income: next });
1055
- return `${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).`;
1093
+ stopped.push({ t, holdCost: f.holdCost, income: next, ...(byPools ? { deployable: pooled.deployable } : {}) });
1094
+ return byPools
1095
+ ? `${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).`
1096
+ : `${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).`;
1056
1097
  };
1057
1098
  /** #297: " facing player P" for the opponent beside `t` (in a 1v1, the one opponent), else nothing. */
1058
1099
  const gateFoe = (t) => {
@@ -1061,6 +1102,17 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1061
1102
  .find((x) => x?.kind === 'player' && pc.foe(x.playerId));
1062
1103
  return o?.kind === 'player' ? ` facing player ${o.playerId}` : '';
1063
1104
  };
1105
+ /**
1106
+ * #426: whether only the fog faces `t` once taken: no neighbour not mine is a player's territory shown with
1107
+ * its armies (a stack in view). A player's territory whose armies the fog hides, or one not shown at all,
1108
+ * is the fog.
1109
+ */
1110
+ const fogOnlyFaces = (t) => neighborsOf(g, t).every((n) => {
1111
+ if (mineSet.has(n))
1112
+ return true;
1113
+ const st = state.get(n);
1114
+ return !(st?.owner.kind === 'player' && pc.foe(st.owner.playerId) && visibleState(st));
1115
+ });
1064
1116
  /**
1065
1117
  * Rule 4d's frontier budget, judged with `t` just captured: under a guarded goal, a capture
1066
1118
  * that adds a border facing an enemy without completing a bonus (and not focused) is stopped
@@ -1080,11 +1132,12 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1080
1132
  const f = frontierOf(held, stays);
1081
1133
  const next = keptIncome(held);
1082
1134
  const start = startHold();
1083
- if (f.holdCost <= next)
1084
- return null;
1085
1135
  // #297: in a 1v1 the start-of-turn hold is no excuse — a capture that opens another gate the next income
1086
1136
  // cannot hold is stopped even when this turn's other orders bring the total back under where it started.
1137
+ // #433: nor, under Local Deployment, is a next income the gates' pools and free income cannot carry there.
1087
1138
  const gate = pc.profile.format === '1v1' ? gateStop(t) : null;
1139
+ if (f.holdCost <= next && !gate)
1140
+ return null;
1088
1141
  if (f.holdCost <= start && !gate)
1089
1142
  return null;
1090
1143
  // #281: land a static seat left, which a live stack beside it takes free next turn: the border
@@ -1102,8 +1155,18 @@ export function bonusPasses(pc, ps, book, hd, tgt, prev) {
1102
1155
  denied.set(t, emptyEnemyLine(pc, t, e));
1103
1156
  return null;
1104
1157
  }
1158
+ // #426: a no-loss neutral whose new border faces only the fog (no player's territory beside it shown with
1159
+ // its armies): its hold cost prices a stack nobody has seen, and the capture risks only the armies that
1160
+ // land. Not in a 1v1, where #297's gate budget prices the one opponent's floating deploy wherever it is.
1161
+ // The owner's cap (2026-11-22): only while the hold the capture adds is at most the next income (1×);
1162
+ // over it, rule 4d decides as before (a golden synthetic board let one through at 85 against an income of 9).
1163
+ const adds = f.holdCost - frontierOf(without, stays).holdCost;
1164
+ if (!gate && adds <= next && noLossNeutral(pc, tgt, t) && fogOnlyFaces(t)) {
1165
+ 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).`);
1166
+ return null;
1167
+ }
1105
1168
  // Only the 1v1 gate budget stops it (rule 4d's start-of-turn escape would have let it through): its own line.
1106
- if (gate && f.holdCost <= start)
1169
+ if (gate && (f.holdCost <= start || f.holdCost <= next))
1107
1170
  return gate;
1108
1171
  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).` : ''}`;
1109
1172
  if (!stopped.some((x) => x.t === t))
@@ -1,3 +1,9 @@
1
+ // #265: a member of a bonus this turn's captures complete that faces an enemy and is short of its
2
+ // hold once the captures land. Rule 1c (#18) and the #122 garrison keep and garrison such members;
3
+ // what neither could fund is the leftover's first call (rule 5, plan/leftover.ts), and a combined
4
+ // capture (#17) it is a source of is rebalanced at the same kills to leave armies on it
5
+ // (plan/captures.ts, `rebalanceCombined`).
6
+ import { paybackLive } from './state.js';
1
7
  /**
2
8
  * `weakMember(id)`: my open `id` in a positive bonus this turn's captures complete (one I did not
3
9
  * hold at the start), next to a visible enemy once the captures land, whose `stays` armies (with
@@ -8,7 +14,8 @@ export function completedMembers(pc, ps, threats, open, stays) {
8
14
  const { g, mine, mineSet, completedBy, bonusTs, unitsAt, toTake } = pc;
9
15
  const before = new Set(completedBy(mineSet));
10
16
  const now = completedBy(new Set([...mine, ...ps.captured]))
11
- .filter((b) => !before.has(b) && (g.bonusById.get(b)?.value ?? 0) > 0)
17
+ // #422: a payback completion is expected to fall next turn: its members are no weak members to fund.
18
+ .filter((b) => !before.has(b) && !paybackLive(ps, ps.paybackBonuses, b) && (g.bonusById.get(b)?.value ?? 0) > 0)
12
19
  .sort((a, b) => g.bonusById.get(b).value - g.bonusById.get(a).value || a - b);
13
20
  const weakMember = (id) => {
14
21
  if (!now.length || !mineSet.has(id) || !open(id))
@@ -20,6 +20,21 @@ import { teamFocusLine } from './team.js';
20
20
  import { byNum } from './util.js';
21
21
  /** #272: a target holding at most this many armies is "empty or near-empty". */
22
22
  export const CONCEDED_OUT_MAX = 2;
23
+ /**
24
+ * #286: rule 1c keeps my `x` — a positive bonus containing it is completed by this turn's captures —
25
+ * so its armies would not withdraw: they are its garrison, not a free step. Live, a +2 member
26
+ * attacked out with 3 into an uneconomic bonus, was kept, and ended 1 army short of its hold.
27
+ */
28
+ export function keptByCompletion(pc, ps, x) {
29
+ const { g, mineSet } = pc;
30
+ const holding = (y) => mineSet.has(y) || ps.captured.has(y);
31
+ return g.map.bonuses.some((b) => {
32
+ if (b.value <= 0)
33
+ return false;
34
+ const ts = bonusTerritories(g, b.id);
35
+ return ts.includes(x) && ts.every(holding) && !ts.every((y) => mineSet.has(y));
36
+ });
37
+ }
23
38
  export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
24
39
  const { g, goal, foe, territories: state, label, bonusName, mineSet, unitsAt, uncounted, defenceAt, costAt, myCommanders, noSplit } = pc;
25
40
  const { avail, captured, spared, rationale } = ps;
@@ -46,17 +61,7 @@ export function attackOutOfConceded(pc, ps, book, hd, tgt, caps) {
46
61
  }
47
62
  return { completes, advances };
48
63
  };
49
- /**
50
- * #286: rule 1c keeps `x` — a positive bonus containing it is completed by this turn's captures —
51
- * so its armies would not withdraw: they are its garrison, not a free step. Live, a +2 member
52
- * attacked out with 3 into an uneconomic bonus, was kept, and ended 1 army short of its hold.
53
- */
54
- const keptBy1c = (x) => g.map.bonuses.some((b) => {
55
- if (b.value <= 0)
56
- return false;
57
- const ts = bonusTerritories(g, b.id);
58
- return ts.includes(x) && ts.every(holding) && !ts.every((y) => mineSet.has(y));
59
- });
64
+ const keptBy1c = (x) => keptByCompletion(pc, ps, x);
60
65
  const tried = new Set();
61
66
  for (;;) {
62
67
  const cands = [];