@chrischall/warapp-mcp 0.13.0 → 0.14.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 (46) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +7 -6
  4. package/dist/analysis/airlift-plan.js +288 -0
  5. package/dist/analysis/blockade-plan.js +178 -0
  6. package/dist/analysis/bomb-plan.js +72 -0
  7. package/dist/analysis/card-threats.js +10 -9
  8. package/dist/analysis/cards-in-effect.js +20 -0
  9. package/dist/analysis/combat.js +5 -0
  10. package/dist/analysis/coordination.js +47 -0
  11. package/dist/analysis/end-game-stats.js +34 -9
  12. package/dist/analysis/lookahead.js +4 -0
  13. package/dist/analysis/plan/relations.js +57 -8
  14. package/dist/analysis/player-record.js +1 -0
  15. package/dist/analysis/relations.js +40 -0
  16. package/dist/analysis/stress.js +42 -2
  17. package/dist/analysis/turn-sim.js +62 -0
  18. package/dist/bundle.js +23244 -21674
  19. package/dist/card-state.js +157 -0
  20. package/dist/finished-store.js +5 -3
  21. package/dist/local-time.js +142 -0
  22. package/dist/relations-store.js +30 -5
  23. package/dist/tools/airlift-readback.js +87 -0
  24. package/dist/tools/alternative-orders.js +21 -0
  25. package/dist/tools/begin-turn.js +19 -5
  26. package/dist/tools/card-advice.js +5 -4
  27. package/dist/tools/card-plays.js +32 -20
  28. package/dist/tools/card-state-view.js +26 -0
  29. package/dist/tools/card-support-advice.js +25 -8
  30. package/dist/tools/chat-inbox.js +1 -1
  31. package/dist/tools/chat.js +1 -1
  32. package/dist/tools/check-plan.js +90 -8
  33. package/dist/tools/end-of-game.js +2 -2
  34. package/dist/tools/game.js +11 -2
  35. package/dist/tools/index.js +7 -1
  36. package/dist/tools/notifications.js +1 -1
  37. package/dist/tools/player-card-readback.js +45 -0
  38. package/dist/tools/relations.js +146 -14
  39. package/dist/tools/sanctions-played.js +51 -0
  40. package/dist/tools/turn.js +479 -13
  41. package/dist/version.js +1 -1
  42. package/manifest.json +9 -2
  43. package/mint.yaml +7 -0
  44. package/package.json +1 -1
  45. package/server.json +8 -2
  46. package/skills/warapp-mcp/SKILL.md +4 -3
@@ -44,6 +44,15 @@ export const TACIT_QUIET_TURNS = 3;
44
44
  * and the partner's. The partner no longer needs me from there on.
45
45
  */
46
46
  export const TRUCE_ENDGAME_RATIO = 0.5;
47
+ /** Territory caps kept per agreement. */
48
+ export const MAX_CAPS = 20;
49
+ /** `a` with `caps` set (one per territory: a new one replaces the old) and `remove` lifted; `caps` absent when none is left. */
50
+ export function withCaps(a, caps, remove = []) {
51
+ const gone = new Set([...remove, ...caps.map((c) => c.territory)]);
52
+ const next = [...(a.caps ?? []).filter((c) => !gone.has(c.territory)), ...caps].slice(-MAX_CAPS);
53
+ const { caps: _old, ...rest } = a;
54
+ return next.length ? { ...rest, caps: next } : rest;
55
+ }
47
56
  /**
48
57
  * Who an exception lets attack: `mine` — the partner agreed I may attack its covered territories;
49
58
  * `theirs` — I agreed the partner may attack (or take) covered territories of mine.
@@ -250,6 +259,36 @@ function fedByHitSource(t, orders, mine, was, now, me) {
250
259
  return nowArmies < expectedArmies(m.from, before, orders, mine);
251
260
  });
252
261
  }
262
+ /**
263
+ * A self-check of the territory caps I promised on `a` (its `caps`): on the newest board, each territory
264
+ * of mine holding more than its cap is one `cap-exceeded` flag `by: 'me'` — my breach, not the
265
+ * partner's, so it never feeds {@link trust}. Nothing for a proposal never agreed, or with no caps.
266
+ */
267
+ export function capSelfCheck(a, boards, me) {
268
+ if (!a.caps?.length || a.agreedTurn === undefined)
269
+ return [];
270
+ const newest = [...boards].sort((x, y) => x.turn - y.turn).at(-1);
271
+ if (!newest)
272
+ return [];
273
+ const at = territoryMap(newest.board);
274
+ const flags = [];
275
+ for (const c of [...a.caps].sort((x, y) => x.territory - y.territory)) {
276
+ const t = visibleState(at.get(c.territory));
277
+ const armies = t?.armies ?? 0;
278
+ if (!t || ownerOn(t) !== me || armies <= c.max)
279
+ continue;
280
+ flags.push({
281
+ kind: 'cap-exceeded',
282
+ by: 'me',
283
+ turn: newest.turn,
284
+ territories: [c.territory],
285
+ armies,
286
+ cap: c.max,
287
+ evidence: `my territory ${c.territory} holds ${armies}, over the cap of ${c.max} I agreed`,
288
+ });
289
+ }
290
+ return flags;
291
+ }
253
292
  /**
254
293
  * What my boards say about the partner keeping `agreement`, over the consecutive turns from the
255
294
  * one it was agreed (and before it ended), as flags with their turn and evidence:
@@ -622,6 +661,7 @@ export function planRelationsFrom(input) {
622
661
  state: broke ? 'broken' : state.phase,
623
662
  ...(state.endsTurn !== undefined ? { endsTurn: state.endsTurn } : {}),
624
663
  ...(a.terms.borderCap !== undefined ? { borderCap: a.terms.borderCap } : {}),
664
+ ...(a.caps?.length ? { territoryCaps: a.caps.map((c) => ({ territory: c.territory, max: c.max })) } : {}),
625
665
  trust: verdict.level,
626
666
  ...(watch.length ? { watch } : {}),
627
667
  // T9: `a.enforced` is never read in. No tool writes it, and only a Diplomacy card the decoder is
@@ -79,7 +79,7 @@ import { couldHoldBonusPools, enemyDeployReaching, freeIncome } from './local-de
79
79
  import { twoStepReaches } from './lookahead.js';
80
80
  import { DEFAULT_BASE_INCOME } from './player.js';
81
81
  import { ownerShown } from './plan/shared.js';
82
- import { simTerritories, simulateTurn, } from './turn-sim.js';
82
+ import { roundHalfDown, simTerritories, simulateTurn, } from './turn-sim.js';
83
83
  const DEFAULT_MAX_REPLIES = 8;
84
84
  /** The chain search's caps (#180), shared with the planner (chains.ts, #199). */
85
85
  export { CHAIN_MAX_NODES, CHAIN_MAX_STEPS } from './chains.js';
@@ -95,10 +95,15 @@ export function stressPlan(input) {
95
95
  const guard = input.settings?.oneArmyStandsGuard === false ? 0 : 1;
96
96
  const myDeploys = input.deploys.map((d) => ({ player: me, territoryId: d.territoryId, armies: d.armies }));
97
97
  const myOrders = input.moves.map((m) => ({ ...m }));
98
+ const myAirlifts = (input.airlifts ?? []).map((a) => ({ ...a, player: me }));
98
99
  const simulate = (sides, moveOrder) => simulateTurn({
99
100
  graph,
100
101
  board,
101
102
  deploys: [...myDeploys, ...sides.flatMap((x) => (x.deploy > 0 ? [{ player: x.player, territoryId: x.deployTo, armies: x.deploy }] : []))],
103
+ ...(input.bombs?.length ? { bombs: input.bombs.map((target) => ({ player: me, target })) } : {}),
104
+ ...(input.abandons?.length ? { abandons: input.abandons.map((w) => ({ ...w, player: me })) } : {}),
105
+ ...(input.blockades?.length ? { blockades: input.blockades.map((w) => ({ ...w, player: me })) } : {}),
106
+ ...(myAirlifts.length ? { airlifts: myAirlifts } : {}),
102
107
  orders: [{ player: me, orders: myOrders }, ...sides.map((x) => ({ player: x.player, orders: x.orders }))],
103
108
  moveOrder,
104
109
  ...(input.settings ? { settings: input.settings } : {}),
@@ -106,7 +111,9 @@ export function stressPlan(input) {
106
111
  ...(input.orderPriority ? { orderPriority: [me] } : {}),
107
112
  });
108
113
  const baseline = simulate([], [me]);
109
- const mineAtStart = new Set([...start].filter(([, t]) => t.owner === me).map(([id]) => id));
114
+ // A territory I wall off (an Emergency Blockade or a Blockade) is given up on purpose: never a loss to a reply.
115
+ const walled = new Set([...(input.abandons ?? []), ...(input.blockades ?? [])].map((w) => w.target));
116
+ const mineAtStart = new Set([...start].filter(([id, t]) => t.owner === me && !walled.has(id)).map(([id]) => id));
110
117
  const mineAfter = (r) => new Set([...r.territories].filter(([, t]) => t.owner === me).map(([id]) => id));
111
118
  const baseMine = mineAfter(baseline);
112
119
  const planned = [...baseMine].filter((id) => !mineAtStart.has(id)).sort(byNum);
@@ -145,6 +152,35 @@ export function stressPlan(input) {
145
152
  if (c && c.owner === me && d.armies > 0)
146
153
  c.armies += d.armies;
147
154
  }
155
+ // My Bombs (phase 30) halve their targets after every deploy, before the Airlifts and moves.
156
+ for (const t of input.bombs ?? []) {
157
+ const c = afterMyDeploys.get(t);
158
+ if (c && c.owner !== 'unknown' && c.owner !== me)
159
+ c.armies = Math.floor(c.armies / 2);
160
+ }
161
+ // My Emergency Blockades (phase 37) wall their territories before the moves.
162
+ for (const w of input.abandons ?? []) {
163
+ const c = afterMyDeploys.get(w.target);
164
+ if (c && c.owner !== 'unknown') {
165
+ c.owner = 'neutral';
166
+ c.armies = roundHalfDown(c.armies * w.multiplier);
167
+ delete c.commander;
168
+ }
169
+ }
170
+ // My Airlifts land before any move, so the dodges and chains are searched on the board after them too.
171
+ for (const a of myAirlifts) {
172
+ const src = afterMyDeploys.get(a.from);
173
+ const dst = afterMyDeploys.get(a.to);
174
+ if (!src || !dst || a.from === a.to || src.owner !== me || !friendly(dst.owner))
175
+ continue;
176
+ const sent = Math.max(0, Math.min(Math.floor(a.armies), src.armies));
177
+ src.armies -= sent;
178
+ dst.armies += sent;
179
+ if (a.commander && src.commander === me && dst.owner === me) {
180
+ delete src.commander;
181
+ dst.commander = me;
182
+ }
183
+ }
148
184
  const allOf = (s, deploy) => (start.get(s)?.armies ?? 0) + deploy;
149
185
  const stacksOf = (id) => [...start]
150
186
  .filter(([, t]) => t.owner === id)
@@ -527,6 +563,10 @@ export function stressPlan(input) {
527
563
  me,
528
564
  opponents: input.opponents,
529
565
  deploys: input.deploys,
566
+ ...(input.airlifts?.length ? { airlifts: input.airlifts } : {}),
567
+ ...(input.bombs?.length ? { bombs: input.bombs } : {}),
568
+ ...(input.abandons?.length ? { abandons: input.abandons } : {}),
569
+ ...(input.blockades?.length ? { blockades: input.blockades } : {}),
530
570
  moves: input.moves,
531
571
  ...(input.settings ? { settings: input.settings } : {}),
532
572
  ...(teams ? { teams } : {}),
@@ -3,6 +3,19 @@
3
3
  //
4
4
  // The rules are the wiki's (docs/STRATEGY.md "Turn resolution" links each page):
5
5
  // - Deployments come before every attack and transfer, and deployed armies may move that turn.
6
+ // - Bombs (card phase 30, after every deploy, before the Airlifts and the moves): the target keeps half its
7
+ // armies, rounded down — the client bundle's GameOrderPlayCardBombResult: round(armies / 2) with a half rounded
8
+ // down — its special units untouched; a Bomb on the bomber's own territory, or one whose armies are hidden,
9
+ // does nothing.
10
+ // - An Emergency Blockade (card phase 37, after the Bombs, before the Airlifts and moves) and a Blockade (phase 60,
11
+ // after every move) turn their territory neutral with its armies × the card's multiplier, rounded with a half
12
+ // down (the bundle's GameOrderPlayCardAbandonResult / …BlockadeResult); special units on it are lost. A Blockade
13
+ // acts only while its player still holds the territory (one taken during the turn stays taken); the Emergency
14
+ // Blockade does not check (the validator already refused a territory not mine).
15
+ // - Airlifts (card phase 43) run after every deploy and before every attack and transfer: the armies
16
+ // leave their source and land on the destination (the player's own, or a teammate's), where they
17
+ // cannot move again that turn (the wiki's Airlift Card). A commander goes along only to its owner's
18
+ // own territory and has then used its move. An Airlift sends what stands on its source when it runs.
6
19
  // - Attack and transfer orders run interleaved in a zigzag over the turn's move order
7
20
  // (1 2 … n, n … 2 1, 1 2 … n), each player's next order in each slot. An order that moves
8
21
  // no armies takes no slot. An Order Priority card makes its player the first mover for the
@@ -41,6 +54,11 @@ const ASSUME_LOSSES = 'Losses on a territory that was attacked fell first on the
41
54
  const ASSUME_SOURCE_LOST = 'An order from a territory that was captured first did nothing (the wiki does not say).';
42
55
  const ASSUME_WIPE = 'With the guard off, an attack that wiped out both sides failed and left one defender (the wiki states this rule under the guard setting).';
43
56
  const ASSUME_PERCENT = 'A percentage order took its share of the armies its territory could still move, the guard left out (the client rounds the share; what it counts is not stated).';
57
+ /** `x` rounded to the nearest whole number, a half rounded down (the client's `O.Bg(x, false, true)`). */
58
+ export function roundHalfDown(x) {
59
+ const whole = Math.floor(x);
60
+ return x - whole > 0.5 ? whole + 1 : whole;
61
+ }
44
62
  /** `pct`% of `n`, rounded to nearest with a half rounded down, as the client works out a percentage order. */
45
63
  export function percentOf(pct, n) {
46
64
  const x = (pct / 100) * n;
@@ -93,6 +111,44 @@ export function simulateTurn(input) {
93
111
  if (c && c.owner === d.player && d.armies > 0)
94
112
  c.armies += d.armies;
95
113
  }
114
+ // Phase 30: the Bombs. The target keeps round-half-down(armies / 2), i.e. half rounded down.
115
+ for (const b of input.bombs ?? []) {
116
+ const c = cells.get(b.target);
117
+ if (!c || c.owner === 'unknown' || c.owner === b.player)
118
+ continue;
119
+ c.armies = Math.floor(c.armies / 2);
120
+ c.moved = Math.min(c.moved, c.armies);
121
+ }
122
+ /** A wall: the territory neutral at its armies × the multiplier (a half rounded down), its special units lost. */
123
+ const wall = (c, m) => {
124
+ c.owner = 'neutral';
125
+ c.armies = roundHalfDown(c.armies * m);
126
+ c.moved = 0;
127
+ delete c.commander;
128
+ delete c.commanderMoved;
129
+ };
130
+ // Phase 37: the Emergency Blockades.
131
+ for (const w of input.abandons ?? []) {
132
+ const c = cells.get(w.target);
133
+ if (c && c.owner !== 'unknown')
134
+ wall(c, w.multiplier);
135
+ }
136
+ // Phase 43: the Airlifts, after every deploy. What lands cannot move again this turn.
137
+ for (const a of input.airlifts ?? []) {
138
+ const src = cells.get(a.from);
139
+ const dst = cells.get(a.to);
140
+ if (!src || !dst || a.from === a.to || src.owner !== a.player || !friendly(dst.owner, a.player))
141
+ continue;
142
+ const sent = Math.max(0, Math.min(Math.floor(a.armies), src.armies));
143
+ src.armies -= sent;
144
+ dst.armies += sent;
145
+ dst.moved += sent;
146
+ if (a.commander && src.commander === a.player && dst.owner === a.player) {
147
+ delete src.commander;
148
+ dst.commander = a.player;
149
+ dst.commanderMoved = true;
150
+ }
151
+ }
96
152
  /** A player whose commander died: everything it holds turns neutral, and its orders stop. */
97
153
  const eliminate = (player) => {
98
154
  if (eliminated.includes(player))
@@ -251,6 +307,12 @@ export function simulateTurn(input) {
251
307
  takeSlot(p);
252
308
  }
253
309
  }
310
+ // Phase 60: the Blockades, after every move, only while their player still holds the territory.
311
+ for (const w of input.blockades ?? []) {
312
+ const c = cells.get(w.target);
313
+ if (c && c.owner === w.player)
314
+ wall(c, w.multiplier);
315
+ }
254
316
  const territories = new Map();
255
317
  for (const [id, c] of cells) {
256
318
  territories.set(id, { owner: c.owner, armies: c.armies, ...(c.commander !== undefined ? { commander: c.commander } : {}) });