@chrischall/warapp-mcp 0.5.0 → 0.7.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 (125) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +133 -8
  4. package/dist/analysis/accept-surrender.js +20 -2
  5. package/dist/analysis/calibrate.js +1 -0
  6. package/dist/analysis/card-support.js +177 -17
  7. package/dist/analysis/card-threats.js +126 -14
  8. package/dist/analysis/chat-advice.js +182 -0
  9. package/dist/analysis/chat-blocks.js +106 -0
  10. package/dist/analysis/chat-intent.js +559 -0
  11. package/dist/analysis/chat-read.js +159 -0
  12. package/dist/analysis/decision-replay.js +279 -0
  13. package/dist/analysis/decision-truth.js +146 -0
  14. package/dist/analysis/finished-game.js +62 -3
  15. package/dist/analysis/game-lessons.js +15 -10
  16. package/dist/analysis/hold-diff.js +3 -1
  17. package/dist/analysis/income-trend.js +38 -0
  18. package/dist/analysis/intel.js +75 -0
  19. package/dist/analysis/opens.js +64 -0
  20. package/dist/analysis/opponent-profile.js +121 -10
  21. package/dist/analysis/opponents.js +246 -20
  22. package/dist/analysis/outlook.js +360 -15
  23. package/dist/analysis/picks.js +91 -12
  24. package/dist/analysis/plan/after-leftover.js +4 -1
  25. package/dist/analysis/plan/bonus-attempts.js +105 -0
  26. package/dist/analysis/plan/capture-instead.js +116 -0
  27. package/dist/analysis/plan/captures.js +49 -7
  28. package/dist/analysis/plan/conceded-out.js +13 -2
  29. package/dist/analysis/plan/estimates.js +203 -30
  30. package/dist/analysis/plan/guard-off.js +2 -1
  31. package/dist/analysis/plan/holds.js +110 -9
  32. package/dist/analysis/plan/jabs.js +113 -0
  33. package/dist/analysis/plan/leftover.js +393 -8
  34. package/dist/analysis/plan/orders.js +76 -4
  35. package/dist/analysis/plan/relations.js +135 -2
  36. package/dist/analysis/plan/report.js +69 -3
  37. package/dist/analysis/plan/second-sizing.js +133 -0
  38. package/dist/analysis/plan/shared.js +279 -27
  39. package/dist/analysis/plan/siege.js +303 -0
  40. package/dist/analysis/plan/stand-still.js +9 -5
  41. package/dist/analysis/plan/state.js +8 -0
  42. package/dist/analysis/plan/stockpile.js +104 -0
  43. package/dist/analysis/plan/strike.js +39 -7
  44. package/dist/analysis/plan/targets.js +256 -110
  45. package/dist/analysis/plan/threats.js +148 -10
  46. package/dist/analysis/plan/transfers.js +57 -6
  47. package/dist/analysis/plan/two-move.js +70 -0
  48. package/dist/analysis/plan/vacated.js +124 -2
  49. package/dist/analysis/planner.js +527 -49
  50. package/dist/analysis/profile.js +13 -2
  51. package/dist/analysis/since-last.js +18 -5
  52. package/dist/analysis/stress.js +8 -2
  53. package/dist/board.js +36 -2
  54. package/dist/bonus-attempt-store.js +55 -0
  55. package/dist/build-id.js +106 -0
  56. package/dist/bundle.js +54138 -41059
  57. package/dist/cards.js +7 -5
  58. package/dist/chat-automation.js +22 -0
  59. package/dist/chat.js +35 -1
  60. package/dist/client.js +14 -0
  61. package/dist/commerce.js +111 -0
  62. package/dist/decision-log.js +1093 -0
  63. package/dist/finished-store.js +5 -1
  64. package/dist/index.js +9 -1
  65. package/dist/lessons-store.js +322 -21
  66. package/dist/live.js +43 -0
  67. package/dist/move-order.js +64 -3
  68. package/dist/normalize.js +17 -0
  69. package/dist/open-games.js +36 -16
  70. package/dist/outlook-log.js +42 -1
  71. package/dist/profile-store.js +12 -2
  72. package/dist/protocol/methods.js +62 -5
  73. package/dist/protocol/rpc.js +8 -0
  74. package/dist/relations-store.js +38 -4
  75. package/dist/review-export.js +198 -0
  76. package/dist/siege-store.js +49 -0
  77. package/dist/state-bundle.js +584 -0
  78. package/dist/state-cli.js +71 -0
  79. package/dist/strategy/notes.js +56 -0
  80. package/dist/team-cards.js +25 -0
  81. package/dist/tools/accept-surrender.js +23 -9
  82. package/dist/tools/award.js +20 -2
  83. package/dist/tools/card-advice.js +93 -28
  84. package/dist/tools/card-plays.js +2 -2
  85. package/dist/tools/card-support-advice.js +37 -7
  86. package/dist/tools/chat-advice.js +330 -0
  87. package/dist/tools/chat-inbox.js +19 -4
  88. package/dist/tools/chat.js +106 -17
  89. package/dist/tools/check-plan.js +68 -12
  90. package/dist/tools/commerce-deploy.js +33 -0
  91. package/dist/tools/common.js +31 -0
  92. package/dist/tools/decision-capture.js +459 -0
  93. package/dist/tools/end-of-game.js +151 -21
  94. package/dist/tools/game-kind.js +92 -0
  95. package/dist/tools/how-lost.js +7 -2
  96. package/dist/tools/index.js +10 -0
  97. package/dist/tools/join-game.js +10 -4
  98. package/dist/tools/live-context.js +6 -0
  99. package/dist/tools/live.js +10 -1
  100. package/dist/tools/map-curves.js +73 -0
  101. package/dist/tools/notifications.js +4 -3
  102. package/dist/tools/opponents.js +2 -0
  103. package/dist/tools/past-games.js +74 -8
  104. package/dist/tools/picks.js +61 -10
  105. package/dist/tools/profile-hook.js +62 -3
  106. package/dist/tools/profile-opponents.js +4 -0
  107. package/dist/tools/push.js +2 -2
  108. package/dist/tools/relations.js +139 -0
  109. package/dist/tools/scout.js +16 -2
  110. package/dist/tools/state.js +232 -0
  111. package/dist/tools/strategy.js +3 -3
  112. package/dist/tools/stress-opponents.js +7 -2
  113. package/dist/tools/surrender-pending.js +10 -1
  114. package/dist/tools/surrender.js +18 -3
  115. package/dist/tools/survival.js +11 -3
  116. package/dist/tools/team-brief.js +2 -2
  117. package/dist/tools/team.js +12 -3
  118. package/dist/tools/turn.js +643 -76
  119. package/dist/tools/where.js +3 -1
  120. package/dist/version.js +1 -1
  121. package/manifest.json +32 -3
  122. package/mint.yaml +37 -4
  123. package/package.json +4 -4
  124. package/server.json +20 -2
  125. package/skills/warapp-mcp/SKILL.md +73 -17
@@ -2152,6 +2152,62 @@ export const STRATEGY_NOTES = [
2152
2152
  source: S.diplomacyGames,
2153
2153
  basis: 'source',
2154
2154
  },
2155
+ // ---- diplomacy: chat as game information (#415) ----
2156
+ {
2157
+ id: 'diplomacy-chat-income-check',
2158
+ topic: 'diplomacy',
2159
+ when: on({ format: ['ffa'] }),
2160
+ text: 'An income check in free-for-all chat is mostly a hunt for the leader: a forum poster gives "player X has ' +
2161
+ '1000 income" as the post that turns a game into a popularity contest. Leading or close to it, say little and ' +
2162
+ 'give no figure; when another player clearly leads, your honest income helps the table see it.',
2163
+ source: S.forumFfaChatEtiquette,
2164
+ basis: 'derived',
2165
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2166
+ },
2167
+ {
2168
+ id: 'diplomacy-chat-withhold',
2169
+ topic: 'diplomacy',
2170
+ when: on({ format: ['ffa'] }),
2171
+ text: 'Answering chat is a choice: one forum poster simply ignored a deal offered by mail, while another warns that ' +
2172
+ 'ignoring it hands rivals an edge. Withholding breaks no rule and a vague reply is fine; what you do say should ' +
2173
+ 'be true, so say less rather than invent.',
2174
+ source: S.forumFfaChatEtiquette,
2175
+ basis: 'derived',
2176
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2177
+ },
2178
+ {
2179
+ id: 'diplomacy-chat-gang-up-ask',
2180
+ topic: 'diplomacy',
2181
+ when: on({ format: ['ffa'] }),
2182
+ text: 'The usual pitch is "X wins unless we gang up". Treat it as a deal offer: when X leads and you do not, price it ' +
2183
+ 'with warapp_advise_diplomacy as you would a truce. When you are X, it is a warning that others are being ' +
2184
+ 'turned on you: check the borders facing the asker and its neighbours.',
2185
+ source: S.forumFfaChatEtiquette,
2186
+ basis: 'derived',
2187
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2188
+ },
2189
+ {
2190
+ id: 'diplomacy-chat-threat',
2191
+ topic: 'diplomacy',
2192
+ when: on({ format: ['ffa'] }),
2193
+ text: 'One poster on truce disputes counts threatening moves of any kind as a possible breach. Read a threat in chat ' +
2194
+ 'the same way, as information about where the sender is looking rather than a reason to answer in kind: check ' +
2195
+ 'the borders facing that player before you commit.',
2196
+ source: S.forumTrucePsychology,
2197
+ basis: 'derived',
2198
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2199
+ },
2200
+ {
2201
+ id: 'diplomacy-chat-trust-little',
2202
+ topic: 'diplomacy',
2203
+ when: on({ format: ['ffa'] }),
2204
+ text: 'A forum guide to free-for-alls advises making pacts by private message but trusting a new partner only a ' +
2205
+ 'little at first, since some players betray quickly. Answer a truce offer by pricing it ' +
2206
+ '(warapp_advise_diplomacy) rather than agreeing in the same breath, and keep that border guarded while it is new.',
2207
+ source: S.ffa,
2208
+ basis: 'derived',
2209
+ encoded: 'the chat advice (adviseReply, src/analysis/chat-advice.ts, #415)',
2210
+ },
2155
2211
  {
2156
2212
  id: 'teams-team-chat',
2157
2213
  topic: 'format',
@@ -1,3 +1,10 @@
1
+ // PLAN-TEAMS C3.7: the team hand and my teammates' entered card plays (#163). A team shares one hand, so a
2
+ // card my teammate has already entered a play or a discard of is theirs this turn: the plan never plays it
3
+ // too, and the card advice says who plays each card.
4
+ //
5
+ // UNVERIFIED live: whether war.app sends a teammate's orders before they commit (V5). VERIFIED (V8, #310): how a
6
+ // team's hand and its limit are keyed (teamCardLimit). Tolerant: no teammate orders read means no claim.
7
+ import { cardsToShed } from './cards.js';
1
8
  /** Every card play and discard in my teammates' entered orders (`teammates`: their player ids), in entry order. */
2
9
  export function teamCardClaims(entries, teammates) {
3
10
  const out = [];
@@ -82,3 +89,21 @@ export function unclaimedFirst(hand, claimed) {
82
89
  const ids = new Set(claimed.map((c) => c.card.id));
83
90
  return [...hand.filter((c) => !ids.has(c.id)), ...hand.filter((c) => ids.has(c.id))];
84
91
  }
92
+ /**
93
+ * The team's card limit as war.app applies it (V8, #310; the client bundle's GameValidateOrders, the hand seen
94
+ * live): the standing keeps each player's cards under that player's id, and a team's hand is every card under
95
+ * any of its players, counted against `MaxCardsHold` (the settings call it the most "a player or team" may hold).
96
+ * The cards my committed teammates' orders play or discard leave it first; then mine. Over the limit, war.app
97
+ * refuses (error 51) only the orders of the last of the team still playing to commit: while a teammate has yet
98
+ * to commit, they may still shed, and the orders are taken. `binding` holds only when every committed
99
+ * teammate's orders were read, so an unread teammate never makes a refusal.
100
+ */
101
+ export function teamCardLimit(hand, rules, mates, entries) {
102
+ const playing = mates.filter((m) => (m.state ?? 'Playing') === 'Playing');
103
+ const committed = playing.filter((m) => m.hasCommittedOrders);
104
+ const lastToCommit = playing.every((m) => m.hasCommittedOrders);
105
+ const ordersRead = committed.every((m) => entries?.some((e) => e.playerId === m.id && e.orders !== null) === true);
106
+ const { left } = teamHandLeft(hand, teamCardClaims(entries, new Set(committed.map((m) => m.id))));
107
+ const shed = cardsToShed(left, rules);
108
+ return { left, shed, lastToCommit, ordersRead, binding: lastToCommit && ordersRead };
109
+ }
@@ -6,7 +6,8 @@
6
6
  // them and refuses when no surrender is pending from that player or my acceptance is not owed; a
7
7
  // finished game and a game I am not playing are refused first. The preview says what accepting does
8
8
  // here: whose seat, whether its land turns neutral or goes to an AI, who borders that land (from the
9
- // live board when it reads), whether it goes through now or others still owe theirs, whether it
9
+ // live board when it reads; #417: and that its land behind the fog is unknown, the standing carrying no
10
+ // per-player count), whether it goes through now or others still owe theirs, whether it
10
11
  // leaves only my side playing (a win), and in a free-for-all one advice line naming the neighbour
11
12
  // that gains most (strategy note ffa-surrender-veto).
12
13
  //
@@ -15,7 +16,7 @@
15
16
  // which carries no result, and nothing is ever resent.
16
17
  import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
17
18
  import { z } from 'zod';
18
- import { surrenderLand, winsOnAcceptance } from '../analysis/accept-surrender.js';
19
+ import { hiddenLandLine, surrenderLand, winsOnAcceptance } from '../analysis/accept-surrender.js';
19
20
  import { parseGameId } from '../client.js';
20
21
  import { inGameOf, playersByInGameId } from '../live.js';
21
22
  import { Method, writeAcceptSurrenderParams } from '../protocol/methods.js';
@@ -28,6 +29,7 @@ import { mapOf } from './map.js';
28
29
  import { resolvePlayer } from './resolve.js';
29
30
  import { noBrowserNote } from './session.js';
30
31
  import { readDetailsSeats } from './surrender-pending.js';
32
+ import { captureGameEvent, turnOfGame } from './decision-capture.js';
31
33
  import { resolveTeamsFor } from './team-source.js';
32
34
  import { defineGatedWrite, mySeat, refuse, requireMe, requirePlaying, sendAndVerify, worded } from './write-kit.js';
33
35
  const PLAYING = 'Playing';
@@ -83,15 +85,17 @@ function adviceOf(opts) {
83
85
  return `${cite} Who borders its land is unknown: the live board could not be read.`;
84
86
  const top = opts.land.neighbours[0];
85
87
  const ai = opts.toAI === true ? ' Its land goes to an AI, which keeps playing it, so it is not up for taking at once.' : '';
88
+ // #417: say plainly that its land behind the fog is not counted.
89
+ const hidden = opts.land.hiddenLand === null ? ' Its land behind the fog is unknown (#417): only what is in view is counted.' : '';
86
90
  if (!top)
87
- return `${cite} No player borders its land in view, so no neighbour gains it at once.${ai}`;
91
+ return `${cite} No player borders its land in view, so no neighbour gains it at once.${ai}${hidden}`;
88
92
  const mine = opts.land.neighbours.find((n) => n.inGameId === opts.meInGame)?.bordering ?? 0;
89
93
  const fog = opts.land.hiddenNeighbours ? ` (${opts.land.hiddenNeighbours} territories beside it are hidden by fog)` : '';
90
94
  if (top.inGameId === opts.meInGame) {
91
- return `${cite} You border its land with the most territories (${top.bordering})${fog}, so of its neighbours you gain most from it.${ai}`;
95
+ return `${cite} You border its land with the most territories (${top.bordering})${fog}, so of its neighbours you gain most from it.${ai}${hidden}`;
92
96
  }
93
97
  return (`${cite} ${opts.idOf(top.inGameId)} borders its land with the most territories (${top.bordering}; you: ${mine})${fog}, ` +
94
- `so it gains most from it.${ai}`);
98
+ `so it gains most from it.${ai}${hidden}`);
95
99
  }
96
100
  export function registerAcceptSurrenderTool(server, ctx) {
97
101
  defineGatedWrite(server, {
@@ -104,7 +108,8 @@ export function registerAcceptSurrenderTool(server, ctx) {
104
108
  'player, when your acceptance is not owed (already given, or your seat cannot accept), in a finished game, ' +
105
109
  'and in a game you are not playing. `player` names the surrendering player (name or id); it may be omitted ' +
106
110
  'when one surrender is pending. The preview says what accepting does: whose seat, whether its land turns ' +
107
- 'neutral or goes to an AI, which players border that land (live board), whether it goes through now or ' +
111
+ 'neutral or goes to an AI, which players border that land (live board) and how much of it the fog may hide ' +
112
+ '(the count behind the fog is unknown: only the land in view is counted), whether it goes through now or ' +
108
113
  'others still owe their acceptance, whether it leaves only your side playing (a win), and in a free-for-all ' +
109
114
  `one advice line naming the neighbour that gains most (strategy note ${FFA_SURRENDER_NOTE}). Accepting is the ` +
110
115
  "owner's decision. The outcome is read back from GameFeed and the game details (`accepted`, `pending` — others " +
@@ -222,6 +227,10 @@ export function registerAcceptSurrenderTool(server, ctx) {
222
227
  };
223
228
  }),
224
229
  hiddenNeighbours: land.hiddenNeighbours,
230
+ // #417: what the fog hides of its land: unknown (null) under any fog, said plainly.
231
+ hiddenLand: land.hiddenLand,
232
+ hiddenOnBoard: land.hiddenOnBoard,
233
+ hiddenLine: hiddenLandLine(land),
225
234
  }
226
235
  : null,
227
236
  othersStillToAccept,
@@ -232,14 +241,14 @@ export function registerAcceptSurrenderTool(server, ctx) {
232
241
  untrusted: UNTRUSTED_PREVIEW_NOTE,
233
242
  },
234
243
  },
235
- state: { gameId, name: gameLabel(game), me, player: target.player, inGameId: target.inGameId, alreadyAI },
244
+ state: { gameId, name: gameLabel(game), me, player: target.player, inGameId: target.inGameId, alreadyAI, turn: turnOfGame(game) },
236
245
  };
237
246
  },
238
- async execute({ gameId, name, me, player, inGameId, alreadyAI }) {
247
+ async execute({ gameId, name, me, player, inGameId, alreadyAI, turn }) {
239
248
  await requireApprovedAccount(ctx, writeAccount(me));
240
249
  const game = { id: gameId, name };
241
250
  const who = { player, inGameId };
242
- return sendAndVerify({
251
+ const result = await sendAndVerify({
243
252
  send: async () => {
244
253
  await ctx.rpc.call('AcceptSurrender', Method.AcceptSurrender, (w) => writeAcceptSurrenderParams(w, { gameId, playerId: inGameId, accept: true }));
245
254
  },
@@ -306,6 +315,11 @@ export function registerAcceptSurrenderTool(server, ctx) {
306
315
  };
307
316
  },
308
317
  });
318
+ // #437: my acceptance, once confirmed, into the decision log (by GameFeed id; a seat without one is not kept).
319
+ if (result.outcome === 'confirmed' && player !== null && turn !== undefined) {
320
+ await captureGameEvent(ctx, gameId, me, { turn, kind: 'surrender-accepted-by-me', player }, { create: true });
321
+ }
322
+ return result;
309
323
  },
310
324
  });
311
325
  }
@@ -7,6 +7,7 @@ import { readFirstMover, resolveFirstMover, verifiedFirstMover, writeFirstMover
7
7
  import { readPickRecord, writeAward } from '../pick-list.js';
8
8
  import { pickSettings } from './picks.js';
9
9
  import { isTeamGame, teammatesOf } from '../teams.js';
10
+ import { capturePicksAward } from './decision-capture.js';
10
11
  const isMine = (t, me) => t.owner.kind === 'player' && t.owner.playerId === me;
11
12
  /** The army count every territory of mine holds, when they all hold the same (the starting armies on turn 1). */
12
13
  function uniformArmies(board, me) {
@@ -22,6 +23,7 @@ function uniformArmies(board, me) {
22
23
  * list is kept for this player, the list did not explain the start, or the first board has
23
24
  * passed unread. Reads the award (and keeps it) on turn 1; later turns reuse what was kept.
24
25
  * `write: false` reads it the same way and keeps nothing (#275 pattern 3: a write's preview).
26
+ * The reading kept is logged once into the game's decision log too (#437 task 3, `decisionLog` its mode).
25
27
  * Never throws.
26
28
  */
27
29
  export async function loadAward(dataDir, game, me, board, turn, o = {}) {
@@ -47,8 +49,10 @@ export async function loadAward(dataDir, game, me, board, turn, o = {}) {
47
49
  // A start the board shows as nobody's, mine or a neutral cannot be another player's: the list is not the one awarded from.
48
50
  if (reading?.opponentStarts.some((t) => contradicts(state.get(t), me.id)))
49
51
  reading = null;
50
- if (o.write !== false)
52
+ if (o.write !== false) {
51
53
  await writeAward(dataDir, game.id, me.id, reading);
54
+ await capturePicksAward(dataDir, o.decisionLog, game.id, me.id, turn, reading);
55
+ }
52
56
  }
53
57
  if (!reading)
54
58
  return undefined;
@@ -177,6 +181,11 @@ export function awardView(a, game, turn, name) {
177
181
  notes,
178
182
  };
179
183
  }
184
+ const FROM_SAID = {
185
+ explicit: 'first_mover given',
186
+ award: 'the award of picks',
187
+ inferred: 'inferred from my first order there, not verified',
188
+ };
180
189
  /**
181
190
  * Who moves first on `turn` (#127): `first_mover` when given, else what this server knows — a
182
191
  * turn kept at `<dataDir>/move-order/` alternated, or the award of picks — in a two-player game
@@ -190,6 +199,7 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
190
199
  cyclicDuel,
191
200
  ...(explicit ? { explicit } : {}),
192
201
  award: award?.firstMover ?? null,
202
+ ...(o.inferred ? { inferred: o.inferred } : {}),
193
203
  ...(remembered ? { remembered } : {}),
194
204
  });
195
205
  if (dataDir && record && o.write !== false)
@@ -200,7 +210,15 @@ export async function firstMoverFor(dataDir, game, me, turn, explicit, award, o
200
210
  firstMover: resolved.firstMover,
201
211
  // #215 review: only a first mover the user gave is verified; the award's is the wiki's rule.
202
212
  verified: verifiedFirstMover(resolved),
203
- view: { who: resolved.firstMover === 'me' ? 'you' : 'opponent', source: resolved.source, ...(resolved.from ? { from: resolved.from } : {}) },
213
+ view: {
214
+ who: resolved.firstMover === 'me' ? 'you' : 'opponent',
215
+ source: resolved.source,
216
+ ...(resolved.from ? { from: resolved.from } : {}),
217
+ line: `${resolved.firstMover === 'me' ? 'You move' : 'The opponent moves'} first` +
218
+ `${turn === null ? ' this turn' : ` on turn ${turn}`} (` +
219
+ (resolved.from ? `alternated from turn ${resolved.from.turn}: ${FROM_SAID[resolved.from.source]}` : FROM_SAID[resolved.source]) +
220
+ ').',
221
+ },
204
222
  warnings,
205
223
  };
206
224
  }
@@ -4,14 +4,17 @@
4
4
  // (Diplomacy, Sanctions), and (PLAN-TEAMS D2) where to play my Diplomacy, Sanctions, Airlift and
5
5
  // Gift. Read-only; everything here is advice — of these only the advised Order Delay is added to the
6
6
  // orders; my Bomb and Emergency Blockade and the D2 cards carry an `order` to pass to warapp_submit_turn.
7
- import { adviseOrderDelay, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
8
- import { bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
9
- import { supportAdvice } from './card-support-advice.js';
7
+ import { adviseOrderDelay, CARD_BLOCKADE, CARD_ORDER_DELAY, CARD_REINFORCEMENT, isMyCard, readActiveCards } from '../cards.js';
8
+ import { blockadeOffer, bombAdvice, bombExposure, wallOffer, wallThreats } from '../analysis/card-threats.js';
9
+ import { bonusTerritories } from '../analysis/bonuses.js';
10
+ import { diplomacyOpponents, supportAdvice } from './card-support-advice.js';
11
+ export { intelOrders } from './card-support-advice.js';
10
12
  import { inGameId } from '../live.js';
11
13
  import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
12
14
  import { isTeamGame, teammatesOf as teamOf } from '../teams.js';
13
15
  const CARD_BOMB = 13;
14
16
  const CARD_EMERGENCY_BLOCKADE = 3;
17
+ const CARD_DIPLOMACY = 8;
15
18
  /** The game around my hand, for the card policy; in a team game with `me`, my in-game id (V8). */
16
19
  export function cardGame(game, me) {
17
20
  const team = isTeamGame(game.players);
@@ -50,8 +53,8 @@ export const handOwners = (game, me) => [
50
53
  ];
51
54
  /** In a team game: the hand and the limit are the team's (said once in the plan's warnings). */
52
55
  export const TEAM_HAND = "This is a team game: the hand and the card limit are the team's, shared with your teammates. The hand shown " +
53
- "gathers every card under you and your teammates on the live board; how war.app keys a team's hand is not yet " +
54
- 'verified, so check the hand in the game before shedding cards.';
56
+ "is every card under you and your teammates (war.app keeps each player's cards under that player's id), and war.app " +
57
+ 'refuses only the last of the team to commit while the team is over the limit: agree in team chat who sheds.';
55
58
  /** A card setting's `MultiplyAmount` (Blockade, Emergency Blockade), when the game sets one. */
56
59
  function multiplier(settings, key) {
57
60
  const r = settings?.raw[key];
@@ -79,17 +82,44 @@ export function adviseCards(input) {
79
82
  const { game, me, turn, hand, choice, plan, label } = input;
80
83
  const view = {};
81
84
  const warnings = [];
82
- // V8: in a team game a card read under a teammate's id is theirs to play (unverified), never advised to me.
85
+ // V8 (#310): in a team game a card read under a teammate's id is left to them, never advised to me.
83
86
  const own = hand.filter((c) => isMyCard(c, cardGame(game, me).me));
84
87
  const gone = new Set([...choice.plays, ...choice.discards].map((c) => c.id));
85
88
  const held = (type) => own.find((c) => c.type === type && !gone.has(c.id));
86
89
  const friends = new Set(teammatesOf(game, me).map((p) => p.id));
90
+ // The cards in effect (unverified decoding), by GameFeed id: read once, for the Bomb's peace and the warnings below.
91
+ const active = readActiveCards(input.info);
92
+ const byInGame = new Map(game.players.flatMap((p) => {
93
+ try {
94
+ return [[inGameId(p), p]];
95
+ }
96
+ catch {
97
+ return [];
98
+ }
99
+ }));
100
+ const feed = (id) => (id === undefined ? undefined : byInGame.get(id)?.id);
101
+ const activeView = active.map((a) => ({
102
+ card: a.card,
103
+ ...(a.players ? { players: a.players.map((p) => feed(p) ?? p) } : {}),
104
+ ...(a.target !== undefined ? { target: feed(a.target) ?? a.target } : {}),
105
+ ...(a.playedBy !== undefined ? { playedBy: feed(a.playedBy) ?? a.playedBy } : {}),
106
+ ...(a.expiresAfterTurn !== undefined ? { expiresAfterTurn: a.expiresAfterTurn } : {}),
107
+ ...(a.untilTurn !== undefined ? { untilTurn: a.untilTurn } : {}),
108
+ }));
109
+ // #452: the players at peace with me — a Diplomacy card in force (decoded, or the plan's T9 set) or a
110
+ // binding truce — whose territories the Bomb advice passes over, as the Sanctions and Diplomacy advice do.
111
+ const peace = new Set([
112
+ ...activeView.flatMap((a) => (a.card === 'Diplomacy' && a.players?.includes(me.id) ? a.players.filter((p) => p !== me.id) : [])),
113
+ ...(input.enforced ?? []),
114
+ ...(input.truces ?? []).map((t) => t.player),
115
+ ]);
87
116
  const cb = {
88
117
  graph: input.graph,
89
118
  board: input.board,
90
119
  me: me.id,
91
120
  friends,
92
121
  ...(input.truceCovered?.size ? { noBomb: input.truceCovered } : {}),
122
+ ...(peace.size ? { peace } : {}),
93
123
  deploys: plan.deploys,
94
124
  moves: plan.moves,
95
125
  enemyDeploy: plan.enemyDeploy,
@@ -160,9 +190,19 @@ export function adviseCards(input) {
160
190
  const offer = ebMultiplier !== undefined ? wallOffer(cb, ebMultiplier, plan.conceded) : undefined;
161
191
  if (offer) {
162
192
  view.emergencyBlockade = { ...offer, order: { kind: 'card', card: wallCard.id, target: offer.territory } };
193
+ const bonusName = (id) => input.graph.map.bonuses.find((b) => b.id === id)?.name ?? `${id}`;
194
+ const p = offer.protects;
195
+ const shields = p.territories.length
196
+ ? ` It shields ${p.territories
197
+ .map((t) => {
198
+ const of = p.bonuses.filter((b) => bonusTerritories(input.graph, b.bonus).includes(t));
199
+ return `${label(t)}${of.length ? ` (${of.map((b) => `bonus ${bonusName(b.bonus)}, +${b.value} a turn`).join('; ')})` : ''}`;
200
+ })
201
+ .join(', ')}${p.commander ? ', where your commander stands,' : ''} from player ${offer.player}'s ~${offer.reach}, which can reach ${p.territories.length === 1 ? 'it' : 'them'} next turn only through the wall.`
202
+ : '';
163
203
  warnings.push(`Consider an Emergency Blockade on ${label(offer.territory)}: the plan concedes it, and its ${offer.givesUp} armies × ${ebMultiplier} make a ` +
164
- `wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks; if not, ` +
165
- 'the territory and its armies are given away. Advice only, not in the orders: pass `cards.advice.emergencyBlockade.order` ' +
204
+ `wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} would lose ~${offer.kills} attacking — if it attacks.${shields} ` +
205
+ `It gives up ${label(offer.territory)} and its ${offer.givesUp} armies for good (it turns neutral). Advice only, not in the orders: pass \`cards.advice.emergencyBlockade.order\` ` +
166
206
  'to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).');
167
207
  }
168
208
  else if (ebMultiplier === undefined) {
@@ -170,26 +210,41 @@ export function adviseCards(input) {
170
210
  }
171
211
  }
172
212
  }
213
+ // #434: my Blockade on the one gate into held bonuses the plan concedes — never on a member of one.
214
+ const blockadeCard = held(CARD_BLOCKADE);
215
+ if (blockadeCard) {
216
+ const bkMultiplier = multiplier(game.settings, 'BlockadeCard');
217
+ const offer = bkMultiplier !== undefined ? blockadeOffer(cb, bkMultiplier, plan.conceded) : undefined;
218
+ if (offer) {
219
+ view.blockade = {
220
+ territory: offer.territory,
221
+ armies: offer.armies,
222
+ wall: offer.wall,
223
+ player: offer.player,
224
+ reach: offer.reach,
225
+ bonuses: offer.opens.bonuses,
226
+ income: offer.opens.income,
227
+ behind: offer.opens.ids,
228
+ commander: offer.commander,
229
+ order: { kind: 'card', card: blockadeCard.id, target: offer.territory },
230
+ };
231
+ const bonusName = (id) => input.graph.map.bonuses.find((b) => b.id === id)?.name ?? `${id}`;
232
+ const into = [
233
+ ...offer.opens.bonuses.map((b) => `bonus ${bonusName(b)} (+${input.graph.map.bonuses.find((x) => x.id === b)?.value ?? 0} a turn)`),
234
+ ...(offer.commander ? ['your commander'] : []),
235
+ ].join(' and ');
236
+ warnings.push(`Consider a Blockade on ${label(offer.territory)}: the plan concedes it, and it is the only way into ${into} — every route from an enemy or the fog runs through it. ` +
237
+ `Its ${offer.armies} armies after the plan × ${bkMultiplier} make a wall of ${offer.wall} that player ${offer.player}'s ~${offer.reach} cannot take. ` +
238
+ `The wall forms at the end of the turn, so it holds only if ${label(offer.territory)} is still yours then, and it gives the territory and its armies away for good (it turns neutral). ` +
239
+ 'Advice only, not in the orders: pass `cards.advice.blockade.order` to warapp_submit_turn to play it.');
240
+ }
241
+ else if (bkMultiplier === undefined) {
242
+ warnings.push('You hold a Blockade, but the game does not say its multiplier, so no wall is sized for it.');
243
+ }
244
+ }
173
245
  // The cards in effect (unverified decoding): Diplomacy protecting a player, Sanctions on me.
174
- const active = readActiveCards(input.info);
175
246
  if (active.length) {
176
- const byInGame = new Map(game.players.flatMap((p) => {
177
- try {
178
- return [[inGameId(p), p]];
179
- }
180
- catch {
181
- return [];
182
- }
183
- }));
184
- const feed = (id) => (id === undefined ? undefined : byInGame.get(id)?.id);
185
- view.active = active.map((a) => ({
186
- card: a.card,
187
- ...(a.players ? { players: a.players.map((p) => feed(p) ?? p) } : {}),
188
- ...(a.target !== undefined ? { target: feed(a.target) ?? a.target } : {}),
189
- ...(a.playedBy !== undefined ? { playedBy: feed(a.playedBy) ?? a.playedBy } : {}),
190
- ...(a.expiresAfterTurn !== undefined ? { expiresAfterTurn: a.expiresAfterTurn } : {}),
191
- ...(a.untilTurn !== undefined ? { untilTurn: a.untilTurn } : {}),
192
- }));
247
+ view.active = activeView;
193
248
  const owner = (t) => {
194
249
  const o = input.board.territories.find((x) => x.territoryId === t)?.owner;
195
250
  return o?.kind === 'player' ? o.playerId : undefined;
@@ -199,12 +254,20 @@ export function adviseCards(input) {
199
254
  if (a.card === 'Diplomacy' && a.players?.includes(me.id)) {
200
255
  const other = a.players.find((p) => p !== me.id);
201
256
  const hit = plan.moves.filter((m) => m.kind === 'attack' && other !== undefined && owner(m.to) === other);
257
+ // #424: its last turn (gone by the next): say so, and chain it with a Diplomacy card in hand —
258
+ // outside a 1v1, where the support advice chains it too (a 1v1 is advised no Diplomacy).
259
+ const last = turn !== null && a.untilTurn === turn + 1;
202
260
  warnings.push(`Diplomacy is in effect between you and player ${other}${until}: neither can attack the other.` +
203
261
  (other !== undefined && input.enforced?.has(other)
204
262
  ? ' The plan honours it (T9): no hold against that player and no attack on it.'
205
263
  : hit.length
206
264
  ? ` The plan's attacks on ${hit.map((m) => label(m.to)).join(', ')} would do nothing — drop or redirect them.`
207
- : ''));
265
+ : '') +
266
+ (last
267
+ ? ` This is its last turn: from turn ${a.untilTurn} it can attack you again — ${held(CARD_DIPLOMACY) && diplomacyOpponents(game, me.id, friends) >= 2
268
+ ? 'chain it: play your Diplomacy card on it this turn (it starts the turn after it is played), or ready the borders it faces.'
269
+ : 'ready the borders it faces.'}`
270
+ : ''));
208
271
  }
209
272
  if (a.card === 'Sanctions' && a.target === me.id) {
210
273
  const pct = game.settings?.raw.SanctionsCard?.Percentage;
@@ -218,7 +281,9 @@ export function adviseCards(input) {
218
281
  }
219
282
  // PLAN-TEAMS D2: my Diplomacy, Sanctions, Airlift and Gift — advice only, each with its order.
220
283
  const atPeace = new Set((view.active ?? []).flatMap((a) => (a.card === 'Diplomacy' && a.players?.includes(me.id) ? a.players.filter((p) => p !== me.id) : [])));
221
- const support = supportAdvice({ game, me, plan, cards: own.filter((c) => !gone.has(c.id)), cb, atPeace, truces: input.truces ?? [] });
284
+ // #424: the cards in force whose last turn this is (gone by the next): chained, not passed over.
285
+ const lastTurn = new Set((view.active ?? []).flatMap((a) => a.card === 'Diplomacy' && a.players?.includes(me.id) && turn !== null && a.untilTurn === turn + 1 ? a.players.filter((p) => p !== me.id) : []));
286
+ const support = supportAdvice({ game, me, plan, cards: own.filter((c) => !gone.has(c.id)), cb, atPeace, lastTurn, truces: input.truces ?? [], ...(input.unverifiedPlays ? { unverifiedPlays: input.unverifiedPlays } : {}) });
222
287
  Object.assign(view, support.view);
223
288
  warnings.push(...support.warnings);
224
289
  return { view, warnings };
@@ -2,8 +2,8 @@
2
2
  // Surveillance, Airlift, Gift, Diplomacy and Sanctions, and the combat cards Bomb and Emergency Blockade. Each card's fields come from the client
3
3
  // bundle's `GameOrderPlayCard<X>` writer and its refusals mirror the bundle's `GameValidateOrders`
4
4
  // (the error code each check stands in for is named), so a target war.app would refuse is refused
5
- // here before anything is sent. The encodings are golden-pinned but UNVERIFIED live (V9,
6
- // docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
5
+ // here before anything is sent. The encodings are golden-pinned; Airlift's (#296) and Diplomacy's (#369) are
6
+ // verified live, the rest UNVERIFIED live (V9, docs/WEB-PROTOCOL.md "Targeted card plays"). Third-party names reach errors only through
7
7
  // `untrustedText`.
8
8
  import { McpToolError } from '@chrischall/mcp-utils';
9
9
  import { inGameId } from '../live.js';
@@ -1,9 +1,13 @@
1
1
  // PLAN-TEAMS D2: where to play my Diplomacy, Sanctions, Airlift and Gift cards this turn, read against the
2
2
  // plan (src/analysis/card-support.ts). Advice only, never auto-played: each carries the `order` to pass to
3
- // warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9). Players and territories by id only.
3
+ // warapp_submit_turn as is, whose encodings are UNVERIFIED live (V9) save Airlift's and Diplomacy's (verified
4
+ // live, #296 and #369) — except (#434) a spy card whose play is verified live, which warapp_plan_turn puts
5
+ // into its orders (`intelOrders`). Players and territories by id only.
4
6
  import { airliftAdvice, diplomacyAdvice, giftAdvice, intelAdvice, sanctionsAdvice } from '../analysis/card-support.js';
5
7
  import { visibleIncomeFor } from '../analysis/plan/shared.js';
6
8
  import { STRENGTH_INCOME_TURNS } from '../analysis/profile.js';
9
+ import { UNVERIFIED_CARD_PLAYS } from '../protocol/methods.js';
10
+ import { dealtMode } from './map-details.js';
7
11
  const CARD_SPY = 2;
8
12
  const CARD_RECONNAISSANCE = 10;
9
13
  const CARD_SURVEILLANCE = 11;
@@ -16,7 +20,12 @@ const CARD_AIRLIFT = 6;
16
20
  const CARD_GIFT = 7;
17
21
  const CARD_DIPLOMACY = 8;
18
22
  const CARD_SANCTIONS = 9;
23
+ /** #434: the advised spy-card plays verified live, which warapp_plan_turn adds to its orders. */
24
+ export function intelOrders(view) {
25
+ return [view.spy, view.reconnaissance, view.surveillance].flatMap((a) => (a?.inOrders ? [a.order] : []));
26
+ }
19
27
  const PLAY_IT = 'Advice only, not in the orders: pass its `order` to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).';
28
+ const IN_ORDERS = 'In the orders: its encoding is verified live. Drop it from the orders to keep the card.';
20
29
  /** The Sanctions percentage (`SanctionsCard.Percentage`), when the settings carry one. */
21
30
  function percentage(game) {
22
31
  const raw = game.settings?.raw.SanctionsCard;
@@ -48,6 +57,13 @@ function strengths(input) {
48
57
  strength: armies + STRENGTH_INCOME_TURNS * visibleIncomeFor(input.cb.graph, input.cb.board, playerId, input.game.settings),
49
58
  }));
50
59
  }
60
+ /**
61
+ * #424: the opponents still playing (teammates out). A lone one in contact is advised Diplomacy only
62
+ * outside a 1v1 (2 or more), and the last-turn warning offers a chain only then too.
63
+ */
64
+ export function diplomacyOpponents(game, me, friends) {
65
+ return game.players.filter((p) => p.id !== me && !friends?.has(p.id) && (p.state ?? 'Playing') === 'Playing').length;
66
+ }
51
67
  /** The D2 advice for the cards in `cards`: a view and one warning per card advised. */
52
68
  export function supportAdvice(input) {
53
69
  const { me, cards, cb } = input;
@@ -56,7 +72,8 @@ export function supportAdvice(input) {
56
72
  const first = (type) => cards.find((c) => c.type === type);
57
73
  const dip = first(CARD_DIPLOMACY);
58
74
  if (dip) {
59
- const d = diplomacyAdvice(cb, { atPeace: input.atPeace, truces: input.truces });
75
+ const opponents = diplomacyOpponents(input.game, me.id, cb.friends);
76
+ const d = diplomacyAdvice(cb, { atPeace: input.atPeace, truces: input.truces, opponents, ...(input.lastTurn ? { lastTurn: input.lastTurn } : {}) });
60
77
  if (d) {
61
78
  if (d.player !== undefined && d.pressure) {
62
79
  view.diplomacy = {
@@ -65,6 +82,7 @@ export function supportAdvice(input) {
65
82
  armies: d.pressure.armies,
66
83
  ...(d.overTruce ? { overTruce: d.overTruce } : {}),
67
84
  ...(d.skipped.length ? { skipped: d.skipped } : {}),
85
+ ...(d.chain ? { chain: true } : {}),
68
86
  order: { kind: 'card', card: dip.id, players: [me.id, d.player] },
69
87
  };
70
88
  }
@@ -98,6 +116,7 @@ export function supportAdvice(input) {
98
116
  to: a.to,
99
117
  armies: a.armies,
100
118
  ...(a.teammate !== undefined ? { teammate: a.teammate } : {}),
119
+ ...(a.redeploy ? { redeploy: a.redeploy } : {}),
101
120
  order: { kind: 'card', card: air.id, from: a.from, to: a.to, armies: a.armies },
102
121
  };
103
122
  warnings.push(`${a.why} ${PLAY_IT}`);
@@ -110,16 +129,27 @@ export function supportAdvice(input) {
110
129
  .filter((p) => p.id !== me.id && !cb.friends?.has(p.id) && (p.state ?? 'Playing') === 'Playing')
111
130
  .map((p) => p.id);
112
131
  const fog = input.game.settings?.fog;
113
- const intel = intelAdvice(cb, { ...(fog !== undefined ? { fog } : {}), opponents, held: new Set(intelCards.keys()) });
132
+ // #443: the distribution mode's territories, when the map already carries them (no read here).
133
+ const starts = dealtMode(input.game.settings, cb.graph.map)?.territories;
134
+ const intel = intelAdvice(cb, {
135
+ ...(fog !== undefined ? { fog } : {}),
136
+ opponents,
137
+ held: new Set(intelCards.keys()),
138
+ ...(starts?.length ? { likelyStarts: new Set(starts) } : {}),
139
+ });
140
+ // #434: a play verified live goes into the orders; until then (all three today) advice only.
141
+ const unverified = input.unverifiedPlays ?? UNVERIFIED_CARD_PLAYS;
114
142
  for (const a of intel.advice) {
115
143
  const id = intelCards.get(a.card).id;
144
+ const live = !unverified.has(a.card);
145
+ const flag = live ? { inOrders: true } : {};
116
146
  if (a.card === 'Spy' && a.player !== undefined)
117
- view.spy = { player: a.player, order: { kind: 'card', card: id, player: a.player } };
147
+ view.spy = { player: a.player, ...flag, order: { kind: 'card', card: id, player: a.player } };
118
148
  if (a.card === 'Reconnaissance' && a.target !== undefined)
119
- view.reconnaissance = { target: a.target, order: { kind: 'card', card: id, target: a.target } };
149
+ view.reconnaissance = { target: a.target, ...flag, order: { kind: 'card', card: id, target: a.target } };
120
150
  if (a.card === 'Surveillance' && a.bonus !== undefined)
121
- view.surveillance = { bonus: a.bonus, order: { kind: 'card', card: id, bonus: a.bonus } };
122
- warnings.push(`${a.why} ${PLAY_IT}`);
151
+ view.surveillance = { bonus: a.bonus, ...flag, order: { kind: 'card', card: id, bonus: a.bonus } };
152
+ warnings.push(`${a.why} ${live ? IN_ORDERS : PLAY_IT}`);
123
153
  }
124
154
  warnings.push(...intel.hold);
125
155
  }