@chrischall/warapp-mcp 0.10.0 → 0.12.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 (65) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +10 -8
  4. package/dist/analysis/cards-in-effect.js +10 -1
  5. package/dist/analysis/chat-mentions.js +17 -0
  6. package/dist/analysis/commander-fog.js +126 -0
  7. package/dist/analysis/end-game-stats.js +149 -0
  8. package/dist/analysis/local-deploy.js +3 -2
  9. package/dist/analysis/outlook.js +133 -55
  10. package/dist/analysis/picks.js +125 -0
  11. package/dist/analysis/plan/commander.js +3 -2
  12. package/dist/analysis/plan/deploy-estimates.js +11 -7
  13. package/dist/analysis/plan/estimates.js +63 -9
  14. package/dist/analysis/plan/relations.js +29 -14
  15. package/dist/analysis/plan/shared.js +21 -0
  16. package/dist/analysis/plan/threats.js +74 -5
  17. package/dist/analysis/player-record.js +31 -1
  18. package/dist/analysis/player.js +23 -10
  19. package/dist/analysis/relations.js +83 -9
  20. package/dist/analysis/scale.js +71 -0
  21. package/dist/analysis/single-pick.js +356 -0
  22. package/dist/bundle.js +3099 -809
  23. package/dist/chat-links.js +141 -0
  24. package/dist/finished-store.js +30 -0
  25. package/dist/index.js +1 -1
  26. package/dist/known-mods.js +33 -0
  27. package/dist/map-stats.js +24 -2
  28. package/dist/mod-alliances.js +217 -0
  29. package/dist/mod-data.js +160 -0
  30. package/dist/my-games.js +53 -2
  31. package/dist/normalize.js +7 -0
  32. package/dist/outlook-log.js +13 -0
  33. package/dist/player-record-store.js +5 -3
  34. package/dist/protocol/methods.js +14 -2
  35. package/dist/relations-store.js +29 -1
  36. package/dist/tools/card-advice.js +29 -9
  37. package/dist/tools/card-effects.js +3 -1
  38. package/dist/tools/card-support-advice.js +1 -1
  39. package/dist/tools/chat-advice.js +1 -1
  40. package/dist/tools/chat-inbox.js +67 -10
  41. package/dist/tools/chat.js +46 -8
  42. package/dist/tools/check-plan.js +115 -11
  43. package/dist/tools/close-finished-game.js +110 -0
  44. package/dist/tools/commander-check.js +80 -1
  45. package/dist/tools/diplomacy.js +11 -2
  46. package/dist/tools/end-of-game.js +57 -3
  47. package/dist/tools/game.js +7 -3
  48. package/dist/tools/how-lost.js +68 -5
  49. package/dist/tools/index.js +21 -1
  50. package/dist/tools/map.js +50 -1
  51. package/dist/tools/mod-alliances.js +191 -0
  52. package/dist/tools/my-games.js +12 -1
  53. package/dist/tools/pace.js +44 -0
  54. package/dist/tools/picks.js +41 -1
  55. package/dist/tools/relations.js +120 -7
  56. package/dist/tools/session.js +20 -6
  57. package/dist/tools/stress-opponents.js +25 -2
  58. package/dist/tools/turn.js +338 -42
  59. package/dist/tools/write-kit.js +1 -0
  60. package/dist/version.js +1 -1
  61. package/manifest.json +10 -2
  62. package/mint.yaml +3 -4
  63. package/package.json +1 -1
  64. package/server.json +2 -2
  65. package/skills/warapp-mcp/SKILL.md +73 -11
@@ -0,0 +1,356 @@
1
+ // Single-pick distribution on a huge map (the mega-game spec, part 2; owner 2026-11-23). With a
2
+ // territory limit of 1 a player is granted one start, so the pick advisor's group search has nothing
3
+ // to group: what matters is which single territory to start on. `rankSingleStarts` scores every
4
+ // pickable territory alone on four things and ranks them:
5
+ //
6
+ // 1. Income at the game's bonus values (overrides applied by the caller's map): a flood opening
7
+ // from the start runs SINGLE_HORIZON turns — each turn the income is deployed and every
8
+ // territory next to the land is taken, members of paying bonuses first, then the territories
9
+ // nearer a paying bonus, then the cheapest, while the armies at the start of the turn cover the
10
+ // capture costs (the armies are pooled: an upper bound on a real opening); another pickable
11
+ // territory is never taken (a rival may start there). Income is the base income, or one army
12
+ // per BonusArmyPer territories when more, plus the bonuses held whole; a bonus worth 0 or less
13
+ // pays nothing and is never steered for, but its territories are crossed. The score is the
14
+ // income above the base over turns 1..SINGLE_HORIZON + 1, each completed bonus discounted by
15
+ // SINGLE_THREAT_LOSS × the chance another start lies within its completion turn + 1 hops of it.
16
+ // 2. Turns to the first income above the base (`firstIncomeTurn`: 0 when held at once).
17
+ // 3. Wastelands (a neutral larger than an ordinary one) within 2 hops: one in a paying bonus
18
+ // blocks it (the flood prices it), any other shields an approach.
19
+ // 4. Commander (start) safety: open approaches (neighbours that are not wastelands), entries into
20
+ // its 2-hop pocket, and the other likely starts near it (each other pickable within
21
+ // RIVAL_RADIUS hops counts the chance a rival starts there, nearer counting more), charged in
22
+ // starting armies, twice with Commanders on (losing the commander ends the game).
23
+ //
24
+ // Pure and deterministic; the ranking is cached per map graph, so paging through it costs nothing.
25
+ import { bonusTerritories } from './bonuses.js';
26
+ import { DEFAULT_DEFENSIVE_KILL_RATE, DEFAULT_OFFENSIVE_KILL_RATE, straightKills } from './combat.js';
27
+ import { neighborsOf } from './graph.js';
28
+ import { captureCost } from './planner.js';
29
+ import { DEFAULT_BASE_INCOME, territoryIncome } from './player.js';
30
+ /** Starts the plan details per call (one page); the submit list is the whole ranking, cut at the client's max. */
31
+ export const SINGLE_PICK_SHOWN = 25;
32
+ /** A map of at least this many territories is huge: there a territory limit of 1 ranks single starts. */
33
+ export const HUGE_MAP_TERRITORIES = 1000;
34
+ /** Turns the flood opening runs. */
35
+ export const SINGLE_HORIZON = 5;
36
+ /** The most starts simulated per call; the rest are ranked after them by their quick score. */
37
+ export const SINGLE_POOL = 600;
38
+ /** Share of a completed bonus's income lost when a rival surely starts within reach of it. */
39
+ export const SINGLE_THREAT_LOSS = 0.5;
40
+ /** Hops within which another likely start presses a start. */
41
+ export const RIVAL_RADIUS = 3;
42
+ const NEAREST_DEPTH = 8;
43
+ // Safety charges, as shares of the starting armies.
44
+ const RIVAL_SHARE = 0.5;
45
+ const APPROACH_SHARE = 0.02;
46
+ const ENTRY_SHARE = 0.02;
47
+ const SHIELD_SHARE = 0.02;
48
+ const COMMANDER_FACTOR = 2;
49
+ const DEFAULT_PICK_ARMIES = 5;
50
+ const DEFAULT_NEUTRALS_IN = 4;
51
+ const DEFAULT_NEUTRALS_OUT = 2;
52
+ const MAX_CACHED = 4;
53
+ const cache = new WeakMap();
54
+ const round2 = (x) => Math.round(x * 100) / 100;
55
+ /** Rank every pickable territory as a lone start (the module header). */
56
+ export function rankSingleStarts(input) {
57
+ const g = input.graph;
58
+ const s = input.settings ?? {};
59
+ const pickable = [...new Set(input.pickable.filter((t) => g.territoryById.has(t)))].sort((a, b) => a - b);
60
+ const known = input.neutralArmies ?? new Map();
61
+ const key = JSON.stringify([
62
+ pickable,
63
+ s,
64
+ input.players,
65
+ [...known].sort((a, b) => a[0] - b[0]),
66
+ g.map.bonuses.length,
67
+ ]);
68
+ let byKey = cache.get(g);
69
+ const hit = byKey?.get(key);
70
+ if (hit)
71
+ return { ...hit, cached: true };
72
+ const clock = input.clock ?? Date.now;
73
+ const started = clock();
74
+ const expired = () => input.budgetMs !== undefined && clock() - started > input.budgetMs;
75
+ const pickSet = new Set(pickable);
76
+ const base = Math.max(0, Math.floor(s.minimumArmyBonus ?? DEFAULT_BASE_INCOME));
77
+ const per = s.bonusArmyPer ?? 0;
78
+ const pickArmies = s.initialPlayerArmiesPerTerritory ?? DEFAULT_PICK_ARMIES;
79
+ const neutralsIn = s.initialNeutralsInDistribution ?? DEFAULT_NEUTRALS_IN;
80
+ const neutralsOut = s.initialNonDistributionArmies ?? DEFAULT_NEUTRALS_OUT;
81
+ const def = s.defensiveKillRate ?? DEFAULT_DEFENSIVE_KILL_RATE;
82
+ const rates = { offensiveKillRate: s.offensiveKillRate ?? DEFAULT_OFFENSIVE_KILL_RATE, defensiveKillRate: def, luckModifier: s.luckModifier };
83
+ const ordinary = (t) => (pickSet.has(t) ? neutralsIn : neutralsOut);
84
+ const armiesAt = (t) => Math.max(0, known.get(t) ?? ordinary(t));
85
+ const waste = new Set();
86
+ for (const t of g.map.territories)
87
+ if (armiesAt(t.id) > ordinary(t.id))
88
+ waste.add(t.id);
89
+ const costOf = new Map();
90
+ const lossOf = new Map();
91
+ const cost = (t) => {
92
+ if (!costOf.has(t)) {
93
+ const n = armiesAt(t);
94
+ costOf.set(t, captureCost(n, rates));
95
+ lossOf.set(t, straightKills(n, def));
96
+ }
97
+ return costOf.get(t);
98
+ };
99
+ // Paying bonuses (value > 0 at the game's values): plain ones steer the flood; superbonuses only pay.
100
+ const paying = g.map.bonuses.filter((b) => b.value > 0);
101
+ const plain = paying.filter((b) => b.bonusIds.length === 0);
102
+ const supers = paying.filter((b) => b.bonusIds.length > 0);
103
+ const members = new Map();
104
+ const payingOf = new Map();
105
+ for (const b of plain) {
106
+ const ms = bonusTerritories(g, b.id).filter((t) => g.territoryById.has(t));
107
+ if (!ms.length)
108
+ continue;
109
+ members.set(b.id, ms);
110
+ for (const t of ms)
111
+ payingOf.set(t, [...(payingOf.get(t) ?? []), b.id]);
112
+ }
113
+ // Hops from every territory to the nearest paying member (map-wide, one search).
114
+ const toPaying = multiSource(g, [...payingOf.keys()]);
115
+ const others = Math.max(1, pickable.length - 1);
116
+ const q = Math.min(1, Math.max(0, (Math.max(1, Math.floor(input.players)) - 1) / others));
117
+ const factor = s.commanders ? COMMANDER_FACTOR : 1;
118
+ // Per bonus: the pickables within SINGLE_HORIZON + 1 hops of a member, with their hops (lazy).
119
+ const nearPicks = new Map();
120
+ const picksNear = (bid) => {
121
+ let out = nearPicks.get(bid);
122
+ if (!out) {
123
+ const d = bounded(g, members.get(bid), SINGLE_HORIZON + 1, () => true);
124
+ out = [...d].filter(([t]) => pickSet.has(t));
125
+ nearPicks.set(bid, out);
126
+ }
127
+ return out;
128
+ };
129
+ const quick = (c) => {
130
+ const own = (payingOf.get(c) ?? []).filter((b) => members.get(b).length === 1);
131
+ const v = own.reduce((n, b) => n + g.bonusById.get(b).value, 0);
132
+ return v * (SINGLE_HORIZON + 1) - (toPaying.get(c) ?? NEAREST_DEPTH * 2);
133
+ };
134
+ const order = [...pickable].sort((a, b) => quick(b) - quick(a) || a - b);
135
+ const pool = order.slice(0, SINGLE_POOL);
136
+ const ranked = [];
137
+ let partial = false;
138
+ for (let i = 0; i < pool.length; i++) {
139
+ if (i % 16 === 0 && expired()) {
140
+ partial = true;
141
+ break;
142
+ }
143
+ ranked.push(simulateStart(pool[i]));
144
+ }
145
+ const done = new Set(ranked.map((r) => r.territoryId));
146
+ ranked.sort((a, b) => b.score - a.score || a.territoryId - b.territoryId);
147
+ for (const c of order)
148
+ if (!done.has(c))
149
+ ranked.push(unsimulated(c));
150
+ const result = { ranked, simulated: done.size, pickable: pickable.length, paying: paying.length, base, ...(partial ? { partial: true } : {}) };
151
+ if (!partial) {
152
+ if (!byKey)
153
+ cache.set(g, (byKey = new Map()));
154
+ if (byKey.size >= MAX_CACHED)
155
+ byKey.delete(byKey.keys().next().value);
156
+ byKey.set(key, result);
157
+ }
158
+ return result;
159
+ function nearestPaying(c) {
160
+ const d = toPaying.get(c);
161
+ if (d === undefined || d > NEAREST_DEPTH)
162
+ return null;
163
+ const ring = [...bounded(g, [c], d, () => true)].filter(([t, h]) => h === d && payingOf.has(t)).map(([t]) => t);
164
+ let best = null;
165
+ for (const t of ring)
166
+ for (const bid of payingOf.get(t)) {
167
+ const b = g.bonusById.get(bid);
168
+ if (!best || b.value > best.value || (b.value === best.value && bid < best.bonusId))
169
+ best = { bonusId: bid, name: b.name, value: b.value, hops: d };
170
+ }
171
+ return best;
172
+ }
173
+ function safetyOf(c) {
174
+ const d = bounded(g, [c], Math.max(RIVAL_RADIUS, NEAREST_DEPTH), (t) => !waste.has(t));
175
+ const approaches = neighborsOf(g, c).filter((n) => !waste.has(n)).length;
176
+ let entries = 0;
177
+ let rivals = 0;
178
+ let nearest = null;
179
+ for (const [t, h] of d) {
180
+ if (h === 2 && neighborsOf(g, t).some((n) => d.get(n) === 3))
181
+ entries++;
182
+ if (t !== c && pickSet.has(t)) {
183
+ if (nearest === null || h < nearest)
184
+ nearest = h;
185
+ if (h <= RIVAL_RADIUS)
186
+ rivals += (q * (RIVAL_RADIUS + 1 - h)) / RIVAL_RADIUS;
187
+ }
188
+ }
189
+ const near2 = bounded(g, [c], 2, () => true);
190
+ const blocking = [];
191
+ const shielding = [];
192
+ for (const t of [...near2.keys()].sort((a, b) => a - b)) {
193
+ if (t === c || !waste.has(t))
194
+ continue;
195
+ (payingOf.has(t) ? blocking : shielding).push(t);
196
+ }
197
+ const penalty = pickArmies * factor * (RIVAL_SHARE * rivals + APPROACH_SHARE * approaches + ENTRY_SHARE * entries - SHIELD_SHARE * shielding.length);
198
+ return { safety: { approaches, entries, nearestStart: nearest, rivalsNear: round2(rivals), penalty: round2(penalty) }, wastelands: { blocking, shielding } };
199
+ }
200
+ function unsimulated(c) {
201
+ const { safety, wastelands } = safetyOf(c);
202
+ return {
203
+ territoryId: c,
204
+ score: round2(quick(c) - safety.penalty),
205
+ income: 0,
206
+ firstIncomeTurn: null,
207
+ nearestPaying: nearestPaying(c),
208
+ bonuses: [],
209
+ wastelands,
210
+ safety,
211
+ simulated: false,
212
+ };
213
+ }
214
+ function simulateStart(c) {
215
+ const held = new Set([c]);
216
+ const left = new Map();
217
+ const completed = new Map();
218
+ const take = (t, turn) => {
219
+ held.add(t);
220
+ for (const bid of payingOf.get(t) ?? []) {
221
+ const n = (left.get(bid) ?? members.get(bid).length) - 1;
222
+ left.set(bid, n);
223
+ if (n === 0)
224
+ completed.set(bid, turn);
225
+ }
226
+ };
227
+ held.delete(c);
228
+ take(c, 0);
229
+ const superDone = new Map();
230
+ const incomeNow = (turn) => {
231
+ for (const b of supers)
232
+ if (!superDone.has(b.id) && bonusTerritories(g, b.id).every((t) => held.has(t)))
233
+ superDone.set(b.id, turn);
234
+ let v = territoryIncome(held.size, base, per);
235
+ for (const bid of completed.keys())
236
+ v += g.bonusById.get(bid).value;
237
+ for (const bid of superDone.keys())
238
+ v += g.bonusById.get(bid).value;
239
+ return v;
240
+ };
241
+ let armies = pickArmies;
242
+ let income = incomeNow(0);
243
+ let extra = income - base;
244
+ let firstIncomeTurn = income > base ? 0 : null;
245
+ for (let turn = 1; turn <= SINGLE_HORIZON; turn++) {
246
+ armies += income;
247
+ const frontier = new Set();
248
+ for (const h of held)
249
+ for (const n of neighborsOf(g, h))
250
+ if (!held.has(n) && !pickSet.has(n) && cost(n) !== null)
251
+ frontier.add(n);
252
+ const pull = (t) => {
253
+ let best = 0;
254
+ for (const bid of payingOf.get(t) ?? []) {
255
+ if (completed.has(bid))
256
+ continue;
257
+ best = Math.max(best, g.bonusById.get(bid).value / (left.get(bid) ?? members.get(bid).length));
258
+ }
259
+ return best;
260
+ };
261
+ const list = [...frontier].sort((a, b) => pull(b) - pull(a) || (toPaying.get(a) ?? 1e9) - (toPaying.get(b) ?? 1e9) || cost(a) - cost(b) || a - b);
262
+ let committed = 0;
263
+ for (const t of list) {
264
+ const k = cost(t);
265
+ if (committed + k > armies)
266
+ continue;
267
+ committed += k;
268
+ take(t, turn);
269
+ }
270
+ for (const t of list)
271
+ if (held.has(t))
272
+ armies -= lossOf.get(t);
273
+ income = incomeNow(turn);
274
+ extra += income - base;
275
+ if (firstIncomeTurn === null && income > base)
276
+ firstIncomeTurn = turn;
277
+ }
278
+ const bonuses = [];
279
+ let discount = 0;
280
+ for (const [bid, turn] of completed) {
281
+ const b = g.bonusById.get(bid);
282
+ const k = picksNear(bid).filter(([t, h]) => t !== c && h <= turn + 1).length;
283
+ const p = 1 - (1 - q) ** k;
284
+ discount += SINGLE_THREAT_LOSS * p * b.value * (SINGLE_HORIZON + 1 - turn);
285
+ bonuses.push({ bonusId: bid, name: b.name, value: b.value, turn, contest: round2(p) });
286
+ }
287
+ bonuses.sort((a, b) => a.turn - b.turn || b.value - a.value || a.bonusId - b.bonusId);
288
+ const { safety, wastelands } = safetyOf(c);
289
+ return {
290
+ territoryId: c,
291
+ score: round2(extra - discount - safety.penalty),
292
+ income: extra,
293
+ firstIncomeTurn,
294
+ nearestPaying: nearestPaying(c),
295
+ bonuses,
296
+ wastelands,
297
+ safety,
298
+ simulated: true,
299
+ };
300
+ }
301
+ }
302
+ /** Hops from the nearest of `sources` to every territory (unbounded). */
303
+ function multiSource(g, sources) {
304
+ return bounded(g, sources, Number.POSITIVE_INFINITY, () => true);
305
+ }
306
+ /** Hops from the nearest of `sources`, at most `depth`, entering only `pass` territories (sources always). */
307
+ function bounded(g, sources, depth, pass) {
308
+ const dist = new Map();
309
+ let frontier = [];
310
+ for (const s of sources)
311
+ if (!dist.has(s)) {
312
+ dist.set(s, 0);
313
+ frontier.push(s);
314
+ }
315
+ for (let d = 1; d <= depth && frontier.length; d++) {
316
+ const next = [];
317
+ for (const t of frontier)
318
+ for (const n of neighborsOf(g, t))
319
+ if (!dist.has(n) && pass(n)) {
320
+ dist.set(n, d);
321
+ next.push(n);
322
+ }
323
+ frontier = next;
324
+ }
325
+ return dist;
326
+ }
327
+ /** One start's reasons, by name: income, bonuses, wastelands and safety. */
328
+ export function singleStartReasons(g, s, base, commanders) {
329
+ const name = (t) => g.territoryById.get(t)?.name ?? String(t);
330
+ const out = [];
331
+ if (!s.simulated)
332
+ out.push('Ranked by its quick score only (nearest paying bonus): the time budget or the pool cap left it unsimulated.');
333
+ else
334
+ out.push(s.firstIncomeTurn === 0
335
+ ? `Income above the ${base} minimum from the start; +${s.income} armies above it over ${SINGLE_HORIZON + 1} turns`
336
+ : s.firstIncomeTurn !== null
337
+ ? `First income above the ${base} minimum after turn ${s.firstIncomeTurn}; +${s.income} armies above it over ${SINGLE_HORIZON + 1} turns`
338
+ : `No income above the ${base} minimum within ${SINGLE_HORIZON} turns`);
339
+ for (const b of s.bonuses.slice(0, 3))
340
+ out.push(`${b.name} (+${b.value}) ${b.turn === 0 ? 'held at once' : `complete on turn ${b.turn}`}` +
341
+ (b.contest > 0 ? `; a rival may start within reach of it (${Math.round(b.contest * 100)}%)` : '; no other start can reach it in time'));
342
+ if (!s.bonuses.length && s.nearestPaying)
343
+ out.push(`Nearest paying bonus: ${s.nearestPaying.name} (+${s.nearestPaying.value}), ${s.nearestPaying.hops} hop${s.nearestPaying.hops === 1 ? '' : 's'} away`);
344
+ if (!s.nearestPaying && !s.bonuses.length)
345
+ out.push(`No paying bonus within ${NEAREST_DEPTH} hops`);
346
+ const { blocking, shielding } = s.wastelands;
347
+ if (blocking.length)
348
+ out.push(`Wasteland in a paying bonus within 2 hops (blocks it): ${blocking.map(name).join(', ')}`);
349
+ if (shielding.length)
350
+ out.push(`Wasteland shielding an approach within 2 hops: ${shielding.map(name).join(', ')}`);
351
+ const f = s.safety;
352
+ out.push(`${commanders ? 'Commander' : 'Start'} safety: ${f.approaches} open approach${f.approaches === 1 ? '' : 'es'}, ${f.entries} entr${f.entries === 1 ? 'y' : 'ies'} into its 2-hop pocket, ` +
353
+ `nearest other start ${f.nearestStart === null ? `over ${NEAREST_DEPTH} hops` : `${f.nearestStart} hop${f.nearestStart === 1 ? '' : 's'}`} away, ` +
354
+ `~${f.rivalsNear} rival start${f.rivalsNear === 1 ? '' : 's'} expected within ${RIVAL_RADIUS} hops (−${f.penalty})`);
355
+ return out;
356
+ }