@chrischall/warapp-mcp 0.0.0 → 0.1.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 (177) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.claude-plugin/plugin.json +2 -2
  3. package/README.md +199 -8
  4. package/dist/analysis/award.js +159 -0
  5. package/dist/analysis/bonuses.js +98 -0
  6. package/dist/analysis/breach.js +62 -0
  7. package/dist/analysis/card-support.js +329 -0
  8. package/dist/analysis/card-threats.js +234 -0
  9. package/dist/analysis/cards-in-effect.js +130 -0
  10. package/dist/analysis/chains.js +59 -0
  11. package/dist/analysis/chokepoints.js +140 -0
  12. package/dist/analysis/combat.js +231 -0
  13. package/dist/analysis/commander-safety.js +149 -0
  14. package/dist/analysis/commitments.js +338 -0
  15. package/dist/analysis/exchange.js +155 -0
  16. package/dist/analysis/graph.js +82 -0
  17. package/dist/analysis/guard-off.js +54 -0
  18. package/dist/analysis/guess.js +351 -0
  19. package/dist/analysis/headroom.js +241 -0
  20. package/dist/analysis/hold-diff.js +64 -0
  21. package/dist/analysis/how-lost.js +130 -0
  22. package/dist/analysis/index.js +14 -0
  23. package/dist/analysis/local-deploy.js +159 -0
  24. package/dist/analysis/lookahead.js +108 -0
  25. package/dist/analysis/opponent-profile.js +551 -0
  26. package/dist/analysis/opponents.js +1245 -0
  27. package/dist/analysis/outlook.js +633 -0
  28. package/dist/analysis/overrides.js +60 -0
  29. package/dist/analysis/picks.js +1879 -0
  30. package/dist/analysis/plan/after-leftover.js +140 -0
  31. package/dist/analysis/plan/cap-spend.js +242 -0
  32. package/dist/analysis/plan/captures.js +1195 -0
  33. package/dist/analysis/plan/commander.js +236 -0
  34. package/dist/analysis/plan/completed.js +29 -0
  35. package/dist/analysis/plan/conceded-out.js +131 -0
  36. package/dist/analysis/plan/estimates.js +715 -0
  37. package/dist/analysis/plan/guard-off.js +232 -0
  38. package/dist/analysis/plan/holds.js +1631 -0
  39. package/dist/analysis/plan/leftover.js +760 -0
  40. package/dist/analysis/plan/move-order.js +319 -0
  41. package/dist/analysis/plan/orders.js +317 -0
  42. package/dist/analysis/plan/relations.js +702 -0
  43. package/dist/analysis/plan/report.js +672 -0
  44. package/dist/analysis/plan/shared.js +1218 -0
  45. package/dist/analysis/plan/stand-still.js +823 -0
  46. package/dist/analysis/plan/state.js +44 -0
  47. package/dist/analysis/plan/strike.js +1416 -0
  48. package/dist/analysis/plan/targets.js +651 -0
  49. package/dist/analysis/plan/team.js +299 -0
  50. package/dist/analysis/plan/threats.js +927 -0
  51. package/dist/analysis/plan/transfers.js +328 -0
  52. package/dist/analysis/plan/util.js +5 -0
  53. package/dist/analysis/plan/vacated.js +285 -0
  54. package/dist/analysis/planner.js +2922 -0
  55. package/dist/analysis/player-record.js +144 -0
  56. package/dist/analysis/player.js +268 -0
  57. package/dist/analysis/profile.js +347 -0
  58. package/dist/analysis/relations.js +1030 -0
  59. package/dist/analysis/schedule.js +88 -0
  60. package/dist/analysis/since-last.js +50 -0
  61. package/dist/analysis/static-seats.js +71 -0
  62. package/dist/analysis/stress.js +577 -0
  63. package/dist/analysis/team-brief.js +151 -0
  64. package/dist/analysis/tripwire.js +644 -0
  65. package/dist/analysis/turn-sim.js +259 -0
  66. package/dist/analysis/whereabouts.js +1109 -0
  67. package/dist/board.js +105 -0
  68. package/dist/bundle.js +117959 -36172
  69. package/dist/cards.js +435 -0
  70. package/dist/chat-cursor.js +135 -0
  71. package/dist/chat.js +192 -0
  72. package/dist/client.js +361 -0
  73. package/dist/config.js +62 -0
  74. package/dist/direct/link.js +102 -0
  75. package/dist/direct/session.js +267 -0
  76. package/dist/direct/transport.js +424 -0
  77. package/dist/guess-salt.js +65 -0
  78. package/dist/hosted.js +24 -0
  79. package/dist/index.js +33 -0
  80. package/dist/join-color.js +140 -0
  81. package/dist/live.js +278 -0
  82. package/dist/map-stats.js +152 -0
  83. package/dist/map-store.js +204 -0
  84. package/dist/move-order.js +141 -0
  85. package/dist/my-games.js +180 -0
  86. package/dist/normalize.js +411 -0
  87. package/dist/open-games.js +537 -0
  88. package/dist/outlook-log.js +138 -0
  89. package/dist/path-lock.js +22 -0
  90. package/dist/pick-list.js +193 -0
  91. package/dist/player-record-store.js +229 -0
  92. package/dist/player-states.js +31 -0
  93. package/dist/profile-store.js +677 -0
  94. package/dist/protocol/bundle.js +375 -0
  95. package/dist/protocol/codec.js +556 -0
  96. package/dist/protocol/decoded.js +12 -0
  97. package/dist/protocol/interp.js +1904 -0
  98. package/dist/protocol/methods.js +531 -0
  99. package/dist/protocol/rpc.js +202 -0
  100. package/dist/push/listener.js +393 -0
  101. package/dist/push/packets.js +66 -0
  102. package/dist/push/socketio.js +333 -0
  103. package/dist/push/websocket.js +179 -0
  104. package/dist/redact.js +62 -0
  105. package/dist/relations-store.js +242 -0
  106. package/dist/replay.js +215 -0
  107. package/dist/scalars.js +28 -0
  108. package/dist/scout.js +346 -0
  109. package/dist/stats.js +269 -0
  110. package/dist/strategy/card-clock.js +185 -0
  111. package/dist/strategy/map-notes.js +128 -0
  112. package/dist/strategy/notes.js +2168 -0
  113. package/dist/team-cards.js +84 -0
  114. package/dist/team-orders.js +150 -0
  115. package/dist/teams.js +19 -0
  116. package/dist/tools/award.js +206 -0
  117. package/dist/tools/begin-turn.js +162 -0
  118. package/dist/tools/board.js +77 -0
  119. package/dist/tools/card-advice.js +256 -0
  120. package/dist/tools/card-effects.js +49 -0
  121. package/dist/tools/card-plays.js +434 -0
  122. package/dist/tools/card-support-advice.js +140 -0
  123. package/dist/tools/chat-inbox.js +146 -0
  124. package/dist/tools/chat.js +483 -0
  125. package/dist/tools/check-plan.js +688 -0
  126. package/dist/tools/commander-check.js +102 -0
  127. package/dist/tools/commitments.js +216 -0
  128. package/dist/tools/common.js +143 -0
  129. package/dist/tools/diplomacy.js +342 -0
  130. package/dist/tools/game.js +126 -0
  131. package/dist/tools/guess-view.js +56 -0
  132. package/dist/tools/healthcheck.js +90 -0
  133. package/dist/tools/hints.js +34 -0
  134. package/dist/tools/how-lost.js +154 -0
  135. package/dist/tools/index.js +142 -0
  136. package/dist/tools/join-game.js +327 -0
  137. package/dist/tools/leave-game.js +181 -0
  138. package/dist/tools/live-context.js +339 -0
  139. package/dist/tools/live.js +404 -0
  140. package/dist/tools/map-stats.js +117 -0
  141. package/dist/tools/map.js +133 -0
  142. package/dist/tools/my-games.js +123 -0
  143. package/dist/tools/open-games.js +104 -0
  144. package/dist/tools/opponents.js +151 -0
  145. package/dist/tools/order-options.js +135 -0
  146. package/dist/tools/picks.js +292 -0
  147. package/dist/tools/profile-hook.js +156 -0
  148. package/dist/tools/profile-opponents.js +121 -0
  149. package/dist/tools/profile-reads.js +99 -0
  150. package/dist/tools/push.js +385 -0
  151. package/dist/tools/relations.js +611 -0
  152. package/dist/tools/resolve.js +45 -0
  153. package/dist/tools/route.js +36 -0
  154. package/dist/tools/scout.js +87 -0
  155. package/dist/tools/session.js +163 -0
  156. package/dist/tools/strategy.js +200 -0
  157. package/dist/tools/stress-opponents.js +83 -0
  158. package/dist/tools/surrender.js +240 -0
  159. package/dist/tools/survival.js +189 -0
  160. package/dist/tools/team-brief.js +266 -0
  161. package/dist/tools/team-source.js +222 -0
  162. package/dist/tools/team.js +182 -0
  163. package/dist/tools/turn.js +2761 -0
  164. package/dist/tools/uncommit.js +160 -0
  165. package/dist/tools/where.js +275 -0
  166. package/dist/tools/write-kit.js +158 -0
  167. package/dist/transport-bridge.js +33 -0
  168. package/dist/trend.js +452 -0
  169. package/dist/version.js +4 -0
  170. package/manifest.json +174 -4
  171. package/mint.yaml +101 -14
  172. package/package.json +11 -6
  173. package/server.json +40 -3
  174. package/skills/warapp-api/SKILL.md +95 -4
  175. package/skills/warapp-api/references/scout.mjs +348 -0
  176. package/skills/warapp-api/scripts/warapp.sh +69 -8
  177. package/skills/warapp-mcp/SKILL.md +969 -21
@@ -0,0 +1,77 @@
1
+ import { z } from 'zod';
2
+ import { analyzePlayer } from '../analysis/index.js';
3
+ import { toBoardState } from '../live.js';
4
+ import { gameIdArg, graphOf, readAnnotations, respond, untrustedDescription, viewArg } from './common.js';
5
+ import { lookupMeta } from './hints.js';
6
+ import { loadLiveTerritories } from './live-context.js';
7
+ import { mapOf } from './map.js';
8
+ import { resolvePlayer } from './resolve.js';
9
+ const VIEWS = ['compact', 'full'];
10
+ const COMPACT_THREATS = 15;
11
+ export function registerBoardTool(server, client, live) {
12
+ server.registerTool('warapp_analyze_board', {
13
+ title: 'Analyze a war.app board for a player',
14
+ description: untrustedDescription('Advise one player in an in-progress war.app (Warzone) game from the current board: their territories and ' +
15
+ 'armies, income (base + held bonuses), the bonuses they are closest to completing (missing territories, ' +
16
+ 'who holds them, armies needed at the game\'s kill rates), and visible enemy threats on their borders, ' +
17
+ 'with the assumptions behind the numbers. Uses GameFeed\'s board when it sends one, else the live board ' +
18
+ 'read through your signed-in war.app tab (as warapp_get_live_board) — a lobby has none. For map-only ' +
19
+ 'analysis use warapp_get_map. Read-only; it never submits orders.'),
20
+ _meta: lookupMeta(['warzone advice', 'analyze my board', 'what should i attack', 'my income']),
21
+ annotations: readAnnotations('Analyze a war.app board'),
22
+ inputSchema: z.object({
23
+ game_id: gameIdArg,
24
+ player: z
25
+ .union([z.string(), z.number()])
26
+ .optional()
27
+ .describe('The player to advise: a name (or part of one) or player id — usually your own war.app name. Omit to list the players.'),
28
+ limit: z.coerce.number().int().min(1).max(100).optional().describe('Max bonuses in closestBonuses (default 10).'),
29
+ view: viewArg(VIEWS, `compact (default) labels owners by player name and keeps the top ${COMPACT_THREATS} threats; ` +
30
+ '"full" is the whole analysis with player ids and every threat.'),
31
+ }),
32
+ }, async ({ game_id, player, limit, view }) => {
33
+ const game = await client.getGame(game_id, { settings: true });
34
+ const map = mapOf(game);
35
+ const me = resolvePlayer(game.players, player);
36
+ const standing = game.standing ?? toBoardState(await loadLiveTerritories(live, game), game.players);
37
+ const a = analyzePlayer(graphOf(map), standing, me.id, game.settings, limit !== undefined ? { limit } : {});
38
+ const nameOf = (id) => game.players.find((p) => p.id === id)?.name ?? `player ${id}`;
39
+ const ownerLabel = (o) => o.kind === 'player' ? nameOf(o.playerId) : o.kind === 'unknown' ? 'unknown' : o.kind;
40
+ const territoryName = (id) => map.territories.find((t) => t.id === id)?.name ?? String(id);
41
+ return respond(view, VIEWS, (rung) => {
42
+ if (rung === 'full') {
43
+ return { player: { id: me.id, name: me.name }, players: game.players.map((p) => ({ id: p.id, name: p.name })), ...a };
44
+ }
45
+ return {
46
+ player: { id: me.id, name: me.name },
47
+ boardVerified: a.boardVerified,
48
+ territoryCount: a.territoryCount,
49
+ armies: a.armies,
50
+ income: a.income,
51
+ closestBonuses: a.closestBonuses.map((b) => ({
52
+ bonusId: b.bonusId,
53
+ name: b.name,
54
+ value: b.value,
55
+ owned: `${b.ownedCount} of ${b.territoryCount}`,
56
+ missing: b.missing.map((m) => ({
57
+ territoryId: m.territoryId,
58
+ name: m.name,
59
+ owner: ownerLabel(m.owner),
60
+ armies: m.armies,
61
+ armiesToTake: m.armiesToTake,
62
+ })),
63
+ armiesNeeded: b.armiesNeeded,
64
+ armiesNeededComplete: b.armiesNeededComplete,
65
+ })),
66
+ threats: a.threats.slice(0, COMPACT_THREATS).map((t) => ({
67
+ territoryId: t.territoryId,
68
+ name: t.name,
69
+ player: nameOf(t.playerId),
70
+ armies: t.armies,
71
+ borders: t.adjacentTo.map(territoryName),
72
+ })),
73
+ assumptions: a.assumptions,
74
+ };
75
+ });
76
+ });
77
+ }
@@ -0,0 +1,256 @@
1
+ // The card advice warapp_plan_turn adds to a plan (#163): the game around the hand (team, fog,
2
+ // players), the team's hand, Order Delay's place, my Bomb and Emergency Blockade, the
3
+ // opponents' Bomb and Emergency Blockade when they can hold one, the cards in effect
4
+ // (Diplomacy, Sanctions), and (PLAN-TEAMS D2) where to play my Diplomacy, Sanctions, Airlift and
5
+ // Gift. Read-only; everything here is advice — of these only the advised Order Delay is added to the
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';
10
+ import { inGameId } from '../live.js';
11
+ import { capturePieceValue, cardClock } from '../strategy/card-clock.js';
12
+ import { isTeamGame, teammatesOf as teamOf } from '../teams.js';
13
+ const CARD_BOMB = 13;
14
+ const CARD_EMERGENCY_BLOCKADE = 3;
15
+ /** The game around my hand, for the card policy; in a team game with `me`, my in-game id (V8). */
16
+ export function cardGame(game, me) {
17
+ const team = isTeamGame(game.players);
18
+ let id;
19
+ if (team && me) {
20
+ try {
21
+ id = inGameId(me);
22
+ }
23
+ catch {
24
+ // No in-game id: every card counts as mine, as before.
25
+ }
26
+ }
27
+ return {
28
+ players: game.players.length,
29
+ team,
30
+ ...(game.settings?.fog !== undefined ? { fog: game.settings.fog } : {}),
31
+ ...(id !== undefined ? { me: id } : {}),
32
+ };
33
+ }
34
+ /** My teammates (never me), by GameFeed player. Empty outside a team game. */
35
+ const teammatesOf = (game, me) => teamOf(game.players, me);
36
+ /**
37
+ * The in-game ids whose cards are my hand: mine, and in a team game my teammates' (a team shares
38
+ * one hand; how war.app keys it is unverified, #163).
39
+ */
40
+ export const handOwners = (game, me) => [
41
+ inGameId(me),
42
+ ...teammatesOf(game, me).flatMap((p) => {
43
+ try {
44
+ return [inGameId(p)];
45
+ }
46
+ catch {
47
+ return []; // not a GameFeed player id: no in-game id to read cards under
48
+ }
49
+ }),
50
+ ];
51
+ /** In a team game: the hand and the limit are the team's (said once in the plan's warnings). */
52
+ 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.';
55
+ /** A card setting's `MultiplyAmount` (Blockade, Emergency Blockade), when the game sets one. */
56
+ function multiplier(settings, key) {
57
+ const r = settings?.raw[key];
58
+ if (typeof r !== 'object' || r === null)
59
+ return undefined;
60
+ const m = Number(r.MultiplyAmount);
61
+ return Number.isFinite(m) && m > 0 ? m : undefined;
62
+ }
63
+ /**
64
+ * Whether an opponent can hold `card` this turn: the card is in play and the card clock lets it
65
+ * be in a hand by `turn` (unknown turn: yes).
66
+ */
67
+ export function opponentCanHold(settings, card, turn) {
68
+ const entry = cardClock(settings)?.cards.find((c) => c.card === card);
69
+ if (!entry)
70
+ return false;
71
+ const first = entry.firstPlayableTurn.fastest;
72
+ return first !== null && (turn === null || turn >= first);
73
+ }
74
+ /**
75
+ * The card advice and warnings for a plan. Pure apart from reading the decoded board; the plan's
76
+ * orders are never changed.
77
+ */
78
+ export function adviseCards(input) {
79
+ const { game, me, turn, hand, choice, plan, label } = input;
80
+ const view = {};
81
+ 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.
83
+ const own = hand.filter((c) => isMyCard(c, cardGame(game, me).me));
84
+ const gone = new Set([...choice.plays, ...choice.discards].map((c) => c.id));
85
+ const held = (type) => own.find((c) => c.type === type && !gone.has(c.id));
86
+ const friends = new Set(teammatesOf(game, me).map((p) => p.id));
87
+ const cb = {
88
+ graph: input.graph,
89
+ board: input.board,
90
+ me: me.id,
91
+ friends,
92
+ ...(input.truceCovered?.size ? { noBomb: input.truceCovered } : {}),
93
+ deploys: plan.deploys,
94
+ moves: plan.moves,
95
+ enemyDeploy: plan.enemyDeploy,
96
+ ...(input.settings ? { settings: input.settings } : {}),
97
+ };
98
+ const moveLabel = (k) => {
99
+ const m = plan.moves[k - 1];
100
+ return `${label(m.from)} → ${label(m.to)}`;
101
+ };
102
+ // Order Delay: above every order that is not urgent, when an attack the opponent can answer is planned.
103
+ // #163: an Order Delay that must leave the hand is played where the plan can use it, not discarded.
104
+ const keepDelay = { ...choice, discards: choice.discards.filter((c) => c.type !== CARD_ORDER_DELAY) };
105
+ const delay = adviseOrderDelay(own, keepDelay, plan.moves, plan.moveSlots);
106
+ if (delay) {
107
+ const insteadOfDiscard = choice.discards.some((c) => c.id === delay.card.id);
108
+ view.orderDelay = {
109
+ card: delay.card.id,
110
+ before: delay.before,
111
+ attacks: delay.attacks,
112
+ order: { kind: 'card', card: delay.card.id, before: delay.before },
113
+ ...(insteadOfDiscard ? { insteadOfDiscard: true } : {}),
114
+ };
115
+ if (insteadOfDiscard)
116
+ warnings.push('The Order Delay that had to leave the hand is played (below) instead of discarded.');
117
+ warnings.push(`Play Order Delay above move ${delay.before}${delay.before <= plan.moves.length ? ` (${moveLabel(delay.before)})` : ''}: ` +
118
+ `${delay.attacks.map(moveLabel).join(', ')} ${delay.attacks.length === 1 ? 'is an attack' : 'are attacks'} the opponent can answer first, ` +
119
+ 'and the orders after the card wait until the opponent has moved. The orders carry it (the card with `before`): ' +
120
+ 'war.app accepts a card placed among the moves (verified live); that the later moves then wait for the ' +
121
+ "opponent's is read from the client, not yet seen in a replay. Drop it from the orders to keep the card.");
122
+ }
123
+ const cards = game.settings?.cards ?? [];
124
+ // My Bomb: a target where halving the stack changes the turn, else hold it.
125
+ const bombCard = held(CARD_BOMB);
126
+ if (bombCard) {
127
+ const a = bombAdvice(cb);
128
+ view.bomb = {
129
+ target: a.target ?? null,
130
+ kind: a.kind ?? null,
131
+ why: a.why,
132
+ ...(a.target !== undefined ? { order: { kind: 'card', card: bombCard.id, target: a.target } } : {}),
133
+ };
134
+ warnings.push(a.target !== undefined
135
+ ? `${a.why.replace(/^Bomb (\d+):/, (_, t) => `Bomb ${label(Number(t))}:`)} Advice only, not in the orders: pass \`cards.advice.bomb.order\` to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).`
136
+ : a.why);
137
+ }
138
+ // An opponent's Bomb: the borders that hold only while unbombed.
139
+ if (cards.includes('Bomb') && opponentCanHold(game.settings, 'Bomb', turn)) {
140
+ const exposed = bombExposure(cb);
141
+ if (exposed.length) {
142
+ warnings.push(`If an opponent plays a Bomb, ${exposed
143
+ .map((e) => `${label(e.territory)}${e.commander ? ' (your commander)' : ''} (${e.armies} → ${e.bombed}) falls to player ${e.player}'s ~${e.reach}`)
144
+ .join('; ')}: a bomb halves a stack after the deploys and before any move. Spread the stack over two territories, ` +
145
+ 'or deploy one step back and move up (the bomb lands before the move).');
146
+ }
147
+ }
148
+ const ebMultiplier = multiplier(game.settings, 'EmergencyBlockadeCard');
149
+ if (cards.includes('EmergencyBlockade') || cards.includes('Emergency Blockade')) {
150
+ // An opponent's Emergency Blockade: planned attacks that would die against the wall.
151
+ if (ebMultiplier !== undefined && opponentCanHold(game.settings, 'Emergency Blockade', turn)) {
152
+ for (const w of wallThreats(cb, ebMultiplier)) {
153
+ warnings.push(`The attack on ${label(w.target)} (${w.attackers} armies) would die against an Emergency Blockade: player ${w.player} can turn it ` +
154
+ `into a neutral of (its armies + its deploy) × ${ebMultiplier} ≈ ${w.wall} before the attacks.`);
155
+ }
156
+ }
157
+ // My Emergency Blockade: a conceded border where the wall kills more than I give up.
158
+ const wallCard = held(CARD_EMERGENCY_BLOCKADE);
159
+ if (wallCard) {
160
+ const offer = ebMultiplier !== undefined ? wallOffer(cb, ebMultiplier, plan.conceded) : undefined;
161
+ if (offer) {
162
+ view.emergencyBlockade = { ...offer, order: { kind: 'card', card: wallCard.id, target: offer.territory } };
163
+ 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` ' +
166
+ 'to warapp_submit_turn to play it (the encoding is read from the client, not yet verified live).');
167
+ }
168
+ else if (ebMultiplier === undefined) {
169
+ warnings.push('You hold an Emergency Blockade, but the game does not say its multiplier, so no wall is sized for it.');
170
+ }
171
+ }
172
+ }
173
+ // The cards in effect (unverified decoding): Diplomacy protecting a player, Sanctions on me.
174
+ const active = readActiveCards(input.info);
175
+ 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
+ }));
193
+ const owner = (t) => {
194
+ const o = input.board.territories.find((x) => x.territoryId === t)?.owner;
195
+ return o?.kind === 'player' ? o.playerId : undefined;
196
+ };
197
+ for (const a of view.active) {
198
+ const until = a.untilTurn !== undefined ? ` (until turn ${a.untilTurn})` : '';
199
+ if (a.card === 'Diplomacy' && a.players?.includes(me.id)) {
200
+ const other = a.players.find((p) => p !== me.id);
201
+ const hit = plan.moves.filter((m) => m.kind === 'attack' && other !== undefined && owner(m.to) === other);
202
+ warnings.push(`Diplomacy is in effect between you and player ${other}${until}: neither can attack the other.` +
203
+ (other !== undefined && input.enforced?.has(other)
204
+ ? ' The plan honours it (T9): no hold against that player and no attack on it.'
205
+ : hit.length
206
+ ? ` The plan's attacks on ${hit.map((m) => label(m.to)).join(', ')} would do nothing — drop or redirect them.`
207
+ : ''));
208
+ }
209
+ if (a.card === 'Sanctions' && a.target === me.id) {
210
+ const pct = game.settings?.raw.SanctionsCard?.Percentage;
211
+ const cut = typeof pct === 'number' ? ` by ${Math.round(pct * 100)}%` : '';
212
+ if (!input.sanctionsApplied)
213
+ warnings.push(`Sanctions are on you${until}: your income is cut${cut}, which the modelled income does not apply — deploy what the game shows ` +
214
+ '(warapp_submit_turn takes a lower total when Sanctions are in the game).');
215
+ }
216
+ }
217
+ warnings.push('Active cards are read from the live board by an unverified decoder (#163): check them in the game.');
218
+ }
219
+ // PLAN-TEAMS D2: my Diplomacy, Sanctions, Airlift and Gift — advice only, each with its order.
220
+ 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 ?? [] });
222
+ Object.assign(view, support.view);
223
+ warnings.push(...support.warnings);
224
+ return { view, warnings };
225
+ }
226
+ /**
227
+ * #127: the planner's `cardPieceValue` — what a turn with a capture earns in card pieces
228
+ * (`capturePieceValue`), a progressive Reinforcement card valued at the one in my hand. Empty when the
229
+ * game does not say (no Reinforcement card in play, or a progressive one and none in hand).
230
+ */
231
+ export function cardPieceOption(settings, hand) {
232
+ const inHand = hand.find((c) => c.type === CARD_REINFORCEMENT && c.armies !== undefined && c.armies > 0)?.armies;
233
+ const v = capturePieceValue(settings, inHand);
234
+ return v.armies !== null && v.armies > 0 ? { cardPieceValue: v.armies } : {};
235
+ }
236
+ /**
237
+ * #164: an opponent's Reinforcement card for the threat model: the first turn one can be in a hand
238
+ * (the card clock's fastest), the armies it adds (a fixed card's `FixedArmies`, else the
239
+ * Reinforcement card in my hand as it is worth now) and the capturing turns each further card
240
+ * takes. `undefined` when no Reinforcement card is in play or what it adds is unknown.
241
+ */
242
+ export function opponentReinforcement(settings, hand) {
243
+ const entry = cardClock(settings)?.cards.find((c) => c.card === 'Reinforcement');
244
+ const first = entry?.firstPlayableTurn.fastest;
245
+ if (!entry || first === null || first === undefined)
246
+ return undefined;
247
+ const raw = settings.raw.ReinforcementCard;
248
+ const fixed = typeof raw === 'object' && raw !== null ? Number(raw.FixedArmies) : NaN;
249
+ const inHand = hand.find((c) => c.type === CARD_REINFORCEMENT && c.armies !== undefined && c.armies > 0)?.armies;
250
+ const armies = Number.isFinite(fixed) && fixed > 0 ? Math.floor(fixed) : inHand;
251
+ if (armies === undefined || armies <= 0)
252
+ return undefined;
253
+ const after = entry.cardsAfter.fastest;
254
+ const turnsPerCard = after && after.length >= 2 ? Math.max(1, after[1] - after[0]) : null;
255
+ return { firstTurn: first, armies, turnsPerCard };
256
+ }
@@ -0,0 +1,49 @@
1
+ // PLAN-TEAMS D3: the cards in effect on the live board that warapp_plan_turn and warapp_check_plan
2
+ // rely on — a Diplomacy card between me and a player (T9) and Sanctions on me — read by the
3
+ // unverified active-card decoder (`readActiveCards`, #163) and kept only when `cardsInEffect` is
4
+ // sure of them. Never throws: an unreadable board means no card.
5
+ import { cardsInEffect, sanctionedIncome } from '../analysis/cards-in-effect.js';
6
+ import { readActiveCards } from '../cards.js';
7
+ import { playersByInGameId } from '../live.js';
8
+ /** {@link cardsInEffect} for `me` in `game` from a decoded LatestGameInfo; empty when nothing reads. */
9
+ export function boardCardsInEffect(game, me, turn, info) {
10
+ let active = [];
11
+ try {
12
+ active = readActiveCards(info);
13
+ }
14
+ catch {
15
+ active = [];
16
+ }
17
+ const players = new Map();
18
+ for (const [inGame, p] of playersByInGameId(game.players))
19
+ players.set(inGame, { id: p.id, ...(p.team !== undefined ? { team: p.team } : {}), ...(p.state !== undefined ? { state: p.state } : {}) });
20
+ return cardsInEffect({ active, players, me: me.id, turn, settings: game.settings });
21
+ }
22
+ /** The warning every plan relying on a decoded card carries. */
23
+ export const CARDS_IN_EFFECT_UNVERIFIED = 'The cards in effect are read from the live board by an unverified decoder (#163, PLAN-TEAMS D3): check them in the game.';
24
+ /**
25
+ * My income this turn under the Sanctions on me (the client bundle's rule), with the warning that says
26
+ * so — or the income unchanged and why not, under Local Deployment (how the cut is taken from the
27
+ * bonus pools is not modelled).
28
+ */
29
+ export function sanctionMyIncome(income, effect, opts) {
30
+ if (!effect.sanctionsOnMe.length)
31
+ return { income, applied: false, warnings: [] };
32
+ const pcts = effect.sanctionsOnMe.map((s) => s.percentage);
33
+ const pctText = pcts.map((p) => `${Math.round(p * 100)}%`).join(' then ');
34
+ const until = Math.max(...effect.sanctionsOnMe.map((s) => s.untilTurn));
35
+ if (opts.localDeployments)
36
+ return {
37
+ income,
38
+ applied: false,
39
+ warnings: [
40
+ `Sanctions are on you (${pctText}, until turn ${until}): under Local Deployment the plan does not know which pools the cut comes from, so it plans on ${income} — deploy what the game shows.`,
41
+ ],
42
+ };
43
+ const cut = sanctionedIncome(income, pcts);
44
+ return {
45
+ income: cut,
46
+ applied: true,
47
+ warnings: [`Sanctions are on you (${pctText}, until turn ${until}): the plan's income is ${cut}, not ${income} (the client's rule, rounded to the nearest).`],
48
+ };
49
+ }