@chrischall/warapp-mcp 0.0.0 → 0.2.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.
- package/.claude-plugin/marketplace.json +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +211 -9
- package/dist/analysis/accept-surrender.js +56 -0
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/calibrate.js +239 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/finished-game.js +136 -0
- package/dist/analysis/game-lessons.js +217 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +179 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +552 -0
- package/dist/analysis/opponents.js +1253 -0
- package/dist/analysis/outlook.js +695 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1405 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +1001 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2927 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +584 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1112 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +121082 -36148
- package/dist/calibration-source.js +75 -0
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +265 -0
- package/dist/client.js +439 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/finished-store.js +357 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/lessons-store.js +356 -0
- package/dist/live.js +287 -0
- package/dist/map-details.js +127 -0
- package/dist/map-stats.js +160 -0
- package/dist/map-store.js +242 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +218 -0
- package/dist/normalize.js +443 -0
- package/dist/notifications.js +143 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +165 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +231 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +727 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +615 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +227 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +291 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2223 -0
- package/dist/surrender-pending.js +126 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/accept-surrender.js +311 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +158 -0
- package/dist/tools/chat-read-mark.js +179 -0
- package/dist/tools/chat.js +525 -0
- package/dist/tools/check-plan.js +689 -0
- package/dist/tools/commander-check.js +103 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/end-of-game.js +384 -0
- package/dist/tools/game.js +151 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +152 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-details.js +88 -0
- package/dist/tools/map-stats.js +130 -0
- package/dist/tools/map.js +141 -0
- package/dist/tools/my-games.js +193 -0
- package/dist/tools/notifications.js +484 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +163 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/past-games.js +94 -0
- package/dist/tools/picks.js +305 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +445 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +257 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender-pending.js +74 -0
- package/dist/tools/surrender.js +247 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +178 -0
- package/dist/tools/turn.js +2825 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +300 -0
- package/dist/tools/write-kit.js +164 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +577 -0
- package/dist/version.js +4 -0
- package/manifest.json +194 -4
- package/mint.yaml +106 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +1096 -21
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { INFER_REACH, MAX_LISTED_COMBINATIONS, TRACKED_MIN_TURNS, trackGame, trackOpponents } from '../analysis/index.js';
|
|
3
|
+
import { boardStateFromLive } from '../live.js';
|
|
4
|
+
import { CACHED_TURNS, writeBoardCache } from '../trend.js';
|
|
5
|
+
import { writeGameRecord } from '../replay.js';
|
|
6
|
+
import { gameIdArg, graphOf, namer, readAnnotations, respond, untrustedDescription, viewArg } from './common.js';
|
|
7
|
+
import { lookupMeta } from './hints.js';
|
|
8
|
+
import { loadLiveGame } from './live-context.js';
|
|
9
|
+
import { BRIDGE_NOTE, playerArg, resolveMe } from './live.js';
|
|
10
|
+
import { mapOf } from './map.js';
|
|
11
|
+
import { pastGamesFor } from './past-games.js';
|
|
12
|
+
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
13
|
+
import { recordProfile } from './profile-hook.js';
|
|
14
|
+
import { boardHistory, currentTurn, plannerSettings, requireTurnPhase } from './turn.js';
|
|
15
|
+
import { resolveTeamsFor } from './team-source.js';
|
|
16
|
+
const VIEWS = ['compact', 'full'];
|
|
17
|
+
export function registerOpponentsTool(server, ctx, deps = {}) {
|
|
18
|
+
server.registerTool('warapp_track_opponents', {
|
|
19
|
+
title: 'Track my opponents in a war.app game',
|
|
20
|
+
description: untrustedDescription('Track each opponent of an in-progress war.app (Warzone) game over your own board history (the boards ' +
|
|
21
|
+
`warapp_plan_turn and this tool have read, the last ${CACHED_TURNS} turns, or the game history when war.app sends it): ` +
|
|
22
|
+
'per opponent, by name, its observed deploy each turn (the net change of its armies on territories visible ' +
|
|
23
|
+
'both turns plus what its captures cost; a stack that only came out of the fog is not income, and no turn ' +
|
|
24
|
+
'exceeds what it could earn), its income estimate (each observed deploy is a lower bound under fog, so: the ' +
|
|
25
|
+
'largest of its last three observed turns, or its visible army growth plus losses per turn (stacks out of the fog left out) when more, capped ' +
|
|
26
|
+
'at what it could earn and at least its base income plus the bonuses it visibly holds; it never decays: an ' +
|
|
27
|
+
'earlier figure is carried until a bonus it visibly held is visibly broken; orders you sent through warapp_submit_turn count as measurements; with the method used ' +
|
|
28
|
+
'and the observed range; a turn whose armies could read two ways — a stack walking in from the fog or a deploy, ' +
|
|
29
|
+
'a capture reinforced on its visible attacker or a stack out of the fog, my emptied territory taken — gives its ' +
|
|
30
|
+
'low–high range), its unexplainedArmies (income earned since first seen minus its visible army change, losses ' +
|
|
31
|
+
'and likely combat deaths: in the fog, spent there, or a misread) and inferred bonuses (the ' +
|
|
32
|
+
'combinations of bonuses it could hold whose values best explain the gap between that income and what it ' +
|
|
33
|
+
`visibly earns, only those within ${INFER_REACH} hops of its territories that it could have paid for, nearest first — ` +
|
|
34
|
+
`as candidates, none listed when more than ${MAX_LISTED_COMBINATIONS} fit). Once an opponent has ${TRACKED_MIN_TURNS}+ ` +
|
|
35
|
+
"observed turns, warapp_plan_turn uses this income in place of the single-turn observed figure. Every opponent " +
|
|
36
|
+
'still playing is listed, even with no territory in view (visible, turnsUnseen); one with nothing in view gets ' +
|
|
37
|
+
'earnedAtLeast (its starting armies plus the base income every turn so far: a lower bound on armies received, ' +
|
|
38
|
+
'not held) and a warning when that beats your largest stack or your total visible armies. Notes say how ' +
|
|
39
|
+
'confident each figure is (turns used, missing turns, caps, fog reveals). Only consecutive turns are ' +
|
|
40
|
+
'compared. "full" adds `pastGames` when you have finished games: per format the games, results, how the lost ones were lost, the mean turn ' +
|
|
41
|
+
'your income went flat, and the calibration — this tracker\'s income estimate ÷ the true income from each finished history, by format and ' +
|
|
42
|
+
'by coverage band (how much of the frontier was read), with the shares read under half and over 1.5× (reported only; nothing reads it). ' +
|
|
43
|
+
`Refuses outside a turn phase. ${BRIDGE_NOTE} Read-only on war.app; it caches the board it read.`),
|
|
44
|
+
_meta: lookupMeta(['track opponents', 'enemy income', 'what is my opponent earning', 'hidden bonuses']),
|
|
45
|
+
annotations: readAnnotations('Track war.app opponents'),
|
|
46
|
+
inputSchema: z.object({
|
|
47
|
+
game_id: gameIdArg,
|
|
48
|
+
player: playerArg,
|
|
49
|
+
view: viewArg(VIEWS, 'compact (default) gives each opponent\'s per-turn deploys (with a low–high range when ambiguous), income, unexplained armies, inferred bonuses and notes; "full" adds the territories each turn counted, captured (and which captures came out of the fog, were reinforced, or were mine emptied), grew next to the fog, and skipped as fog reveals, and its army change, losses and likely combat deaths, and `pastGames` (the lessons of your finished games).'),
|
|
50
|
+
}),
|
|
51
|
+
}, async ({ game_id, player, view }) => {
|
|
52
|
+
const feed = await ctx.client.getGame(game_id, { settings: true });
|
|
53
|
+
requireTurnPhase(feed);
|
|
54
|
+
const seat = await resolveMe(ctx, feed.players, player);
|
|
55
|
+
// The teams, once my seat is found: GameFeed's, else the game list's (asked once per game, kept).
|
|
56
|
+
const { game, me, known: teamsKnown } = await resolveTeamsFor(ctx, feed, seat);
|
|
57
|
+
const map = mapOf(game);
|
|
58
|
+
const { territories } = await loadLiveGame(ctx, game);
|
|
59
|
+
const graph = graphOf(map);
|
|
60
|
+
const board = boardStateFromLive(territories, me, game.players);
|
|
61
|
+
const settings = plannerSettings(game.settings);
|
|
62
|
+
const turn = currentTurn(game);
|
|
63
|
+
const history = await boardHistory(ctx, game, me, turn);
|
|
64
|
+
const boards = turn !== null ? [...history.boards, { turn, board }] : [{ turn: 0, board }];
|
|
65
|
+
const tracks = trackOpponents(graph, boards, me.id, settings, trackGame(game.players, game.settings, map, game.endRules));
|
|
66
|
+
if (ctx.dataDir && turn !== null) {
|
|
67
|
+
await writeBoardCache(ctx.dataDir, game.id, me.id, turn, board);
|
|
68
|
+
await writeGameRecord(ctx.dataDir, game);
|
|
69
|
+
await recordProfile(ctx.dataDir, deps.env, game, me, boards, teamsKnown);
|
|
70
|
+
}
|
|
71
|
+
// #312 E3: what my finished games teach (full only; reported only, no track or plan reads it).
|
|
72
|
+
const pastGames = view === 'full' ? await pastGamesFor(ctx.dataDir, deps.env, profileFormatOf(game.players)) : undefined;
|
|
73
|
+
const name = namer(map);
|
|
74
|
+
const players = new Map(game.players.map((p) => [p.id, p.name]));
|
|
75
|
+
const bonusOf = (id) => {
|
|
76
|
+
const b = map.bonuses.find((x) => x.id === id);
|
|
77
|
+
return { id, name: b?.name ?? String(id), value: b?.value ?? 0 };
|
|
78
|
+
};
|
|
79
|
+
return respond(view, VIEWS, (rung) => {
|
|
80
|
+
const turnView = (x) => ({
|
|
81
|
+
turn: x.from,
|
|
82
|
+
deploy: x.observed,
|
|
83
|
+
...(x.raw !== x.observed ? { uncapped: x.raw, cap: x.cap } : {}),
|
|
84
|
+
visibleIncome: x.visibleIncome,
|
|
85
|
+
// #294: how much of its frontier the turn read.
|
|
86
|
+
...(x.coverage ? { coverage: x.coverage } : {}),
|
|
87
|
+
// #119: what my own orders that turn measured (defenders my failed attacks killed, …).
|
|
88
|
+
...(x.measured ? { measured: x.measured } : {}),
|
|
89
|
+
...(x.broken.length ? { brokenBonuses: x.broken.map(bonusOf) } : {}),
|
|
90
|
+
// #123: an ambiguous turn reads between these (fog moves vs deploys, my emptied stacks).
|
|
91
|
+
...(x.low !== x.high ? { range: { low: x.low, high: x.high } } : {}),
|
|
92
|
+
// #271: a failed attack on a hold of mine bounds the turn's deploy; a pattern of captures that
|
|
93
|
+
// needed attackers out of sight is income.
|
|
94
|
+
...(x.repelled && x.repelledFloor ? { repelled: { territories: x.repelled.territories.map(name), attackers: x.repelled.attackers, besideStacks: x.repelled.supply, deployAtLeast: x.repelledFloor } } : {}),
|
|
95
|
+
...(x.fogCaptures ? { fogCaptures: x.fogCaptures } : {}),
|
|
96
|
+
...(rung === 'full'
|
|
97
|
+
? {
|
|
98
|
+
counted: x.counted.map(name),
|
|
99
|
+
captured: x.captured.map(name),
|
|
100
|
+
fromFog: x.fromFog.map(name),
|
|
101
|
+
...(x.reinforced.length ? { reinforced: x.reinforced.map(name) } : {}),
|
|
102
|
+
...(x.grewFromFog.length ? { grewFromFog: x.grewFromFog.map(name) } : {}),
|
|
103
|
+
...(x.emptied.length ? { emptied: x.emptied.map(name) } : {}),
|
|
104
|
+
...(x.unseenAttackers?.length ? { unseenAttackers: x.unseenAttackers.map(name), unseenAttackerArmies: x.unseenAttackerArmies } : {}),
|
|
105
|
+
...(x.arrivals ? { arrivals: x.arrivals } : {}),
|
|
106
|
+
reveals: x.reveals.map(name),
|
|
107
|
+
armyChange: x.net,
|
|
108
|
+
losses: x.losses,
|
|
109
|
+
earned: x.earned,
|
|
110
|
+
...(x.combat ? { combat: x.combat } : {}),
|
|
111
|
+
}
|
|
112
|
+
: {}),
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
game: { id: game.id, name: game.name ?? null, turn },
|
|
116
|
+
player: { id: me.id, name: me.name },
|
|
117
|
+
turns: boards.map((b) => b.turn).sort((a, b) => a - b),
|
|
118
|
+
...(rung === 'full' && pastGames ? { pastGames } : {}),
|
|
119
|
+
// #94: every opponent out of sight whose received armies beat my largest stack or my total.
|
|
120
|
+
warnings: tracks.flatMap((t) => t.warnings),
|
|
121
|
+
opponents: tracks.map((t) => ({
|
|
122
|
+
player: { id: t.playerId, name: players.get(t.playerId) ?? String(t.playerId) },
|
|
123
|
+
firstSeen: t.firstSeen,
|
|
124
|
+
visible: t.visible,
|
|
125
|
+
turnsUnseen: t.turnsUnseen,
|
|
126
|
+
turnsUnseenAtLeast: t.turnsUnseenAtLeast,
|
|
127
|
+
earnedAtLeast: t.earnedAtLeast,
|
|
128
|
+
warnings: t.warnings,
|
|
129
|
+
observed: t.turns.map(turnView),
|
|
130
|
+
income: {
|
|
131
|
+
estimate: t.income,
|
|
132
|
+
visible: t.visibleIncome,
|
|
133
|
+
base: t.base,
|
|
134
|
+
visibleBonuses: t.bonusIncome,
|
|
135
|
+
turns: t.incomeTurns,
|
|
136
|
+
// #99: which term set the estimate, and the spread of what it was observed to deploy.
|
|
137
|
+
method: t.incomeMethod,
|
|
138
|
+
...(t.incomeLowered ? { lowered: t.incomeLowered } : {}),
|
|
139
|
+
observedRange: t.observedRange,
|
|
140
|
+
// #294: how much of its frontier the window's turns read.
|
|
141
|
+
...(t.coverage ? { coverage: t.coverage } : {}),
|
|
142
|
+
usedByPlanner: t.income !== null && t.turns.length >= TRACKED_MIN_TURNS,
|
|
143
|
+
// #250: set by one turn far above the turns before it, with what the boards say of it.
|
|
144
|
+
...(t.incomeJump ? { jump: t.incomeJump } : {}),
|
|
145
|
+
},
|
|
146
|
+
unexplainedArmies: t.unexplained,
|
|
147
|
+
// #164: large stacks last seen on a territory hidden since (the planner counts each where it can reach).
|
|
148
|
+
...(t.lostStacks?.length ? { lostStacks: t.lostStacks } : {}),
|
|
149
|
+
inferredBonuses: t.inferred
|
|
150
|
+
? {
|
|
151
|
+
gap: t.inferred.gap,
|
|
152
|
+
exact: t.inferred.exact,
|
|
153
|
+
candidates: t.inferred.candidates.map((c) => ({ bonuses: c.bonusIds.map(bonusOf), total: c.total, hops: c.hops })),
|
|
154
|
+
...(t.inferred.more ? { more: t.inferred.more } : {}),
|
|
155
|
+
...(t.inferred.implausible ? { implausible: t.inferred.implausible } : {}),
|
|
156
|
+
}
|
|
157
|
+
: null,
|
|
158
|
+
notes: t.notes,
|
|
159
|
+
})),
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// The options an attack/transfer order can carry (#165): Transfer Only, Attack Only, a percentage
|
|
2
|
+
// of the armies, the commander, and attacking teammates. Each is refused unless the game allows
|
|
3
|
+
// it — war.app's own validator refuses a percentage order (error 360), Transfer Only (361) and
|
|
4
|
+
// Attack Only (362) when the setting is off (read from the client bundle) — and every one is
|
|
5
|
+
// UNVERIFIED against a live commit: the encoding follows the client's writer (docs/WEB-PROTOCOL.md).
|
|
6
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
7
|
+
import { percentOf } from '../analysis/turn-sim.js';
|
|
8
|
+
import { untrustedText } from './common.js';
|
|
9
|
+
/** A move's mode, as warapp_submit_turn takes it. */
|
|
10
|
+
export const MOVE_MODES = ['attack-transfer', 'attack-only', 'transfer-only'];
|
|
11
|
+
/** Options used, said once per preview: none of them has been sent in a live commit yet. */
|
|
12
|
+
const OPTIONS_UNVERIFIED = 'Order options (Transfer Only, Attack Only, percentage, the commander, attack teammates) follow the war.app ' +
|
|
13
|
+
"client's own encoding but are not yet verified by a live commit: check the orders in the game after sending.";
|
|
14
|
+
const label = (t) => `${untrustedText(t.name)} (${t.id})`;
|
|
15
|
+
const move = (m) => `${label(m.from)} → ${label(m.to)}`;
|
|
16
|
+
/**
|
|
17
|
+
* Check each move's options against the game's settings and the live board at the start of the
|
|
18
|
+
* turn; throws a clear refusal on the first that cannot be sent, else returns warnings, the
|
|
19
|
+
* commander each commander move takes, and what each percentage order would send now.
|
|
20
|
+
*/
|
|
21
|
+
export function checkMoveOptions(args) {
|
|
22
|
+
const { moves, board, myInGameId: me, teammates } = args;
|
|
23
|
+
const s = args.settings;
|
|
24
|
+
const standing = new Map(board.map((t) => [t.territoryId, t]));
|
|
25
|
+
const ownerOf = (id) => {
|
|
26
|
+
const t = standing.get(id);
|
|
27
|
+
return t && !t.fogged ? t.owner : undefined;
|
|
28
|
+
};
|
|
29
|
+
const warnings = [];
|
|
30
|
+
const commanders = new Map();
|
|
31
|
+
const estimates = new Map();
|
|
32
|
+
let used = false;
|
|
33
|
+
/** Where my commander stands at the start of the turn. */
|
|
34
|
+
const home = board.find((t) => !t.fogged && t.specialUnits?.some((u) => u.kind === 'commander' && u.owner === me));
|
|
35
|
+
const myCommander = home?.specialUnits?.find((u) => u.kind === 'commander' && u.owner === me);
|
|
36
|
+
/** Where my commander is after the commander moves so far. */
|
|
37
|
+
let commanderAt = home?.territoryId;
|
|
38
|
+
let commanderMoves = 0;
|
|
39
|
+
moves.forEach((m, i) => {
|
|
40
|
+
if (m.mode === 'transfer-only' || m.mode === 'attack-only')
|
|
41
|
+
used = true;
|
|
42
|
+
if (m.mode === 'transfer-only' && s?.allowTransferOnly !== true) {
|
|
43
|
+
throw new McpToolError(`Transfer Only orders are off in this game (AllowTransferOnly; war.app refuses one, error 361): ${move(m)}.`, {
|
|
44
|
+
hint: 'Send it without `mode`: an ordinary attack/transfer.',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (m.mode === 'attack-only' && s?.allowAttackOnly !== true) {
|
|
48
|
+
throw new McpToolError(`Attack Only orders are off in this game (AllowAttackOnly; war.app refuses one, error 362): ${move(m)}.`, {
|
|
49
|
+
hint: 'Send it without `mode`: an ordinary attack/transfer.',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const target = ownerOf(m.to.id);
|
|
53
|
+
const friendly = target === me || (target !== undefined && teammates.has(target) && !m.attackTeammates);
|
|
54
|
+
if (m.mode === 'transfer-only' && !friendly) {
|
|
55
|
+
warnings.push(`Transfer Only ${move(m)}: ${label(m.to)} is not yours at the start of the turn, so the order does nothing unless it is yours (or a teammate's) when it runs.`);
|
|
56
|
+
}
|
|
57
|
+
if (m.mode === 'attack-only' && target === me) {
|
|
58
|
+
warnings.push(`Attack Only ${move(m)}: ${label(m.to)} is yours, so the order fires only if it has fallen by the time it runs; otherwise nothing moves.`);
|
|
59
|
+
}
|
|
60
|
+
if (m.percent) {
|
|
61
|
+
used = true;
|
|
62
|
+
if (s?.allowPercentageAttacks !== true) {
|
|
63
|
+
throw new McpToolError(`Percentage orders are off in this game (AllowPercentageAttacks; war.app refuses one, error 360): ${move(m)}.`, {
|
|
64
|
+
hint: 'Send a number of armies instead (leave `percent` out).',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (m.armies < 1 || m.armies > 100) {
|
|
68
|
+
throw new McpToolError(`${move(m)} asks for ${m.armies}%: a percentage order sends 1 to 100 percent.`, {
|
|
69
|
+
hint: 'With `percent`, `armies` is the percentage of the armies the territory can move when the order runs.',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const guard = s?.oneArmyStandsGuard === false ? 0 : 1;
|
|
73
|
+
const now = Math.max(0, (standing.get(m.from.id)?.armies ?? 0) + (args.deployedOn.get(m.from.id) ?? 0) - guard);
|
|
74
|
+
const est = percentOf(m.armies, now);
|
|
75
|
+
estimates.set(i, est);
|
|
76
|
+
warnings.push(`${move(m)} sends ${m.armies}% of the armies ${label(m.from)} can move when it runs: about ${est} now (worked out when the order runs, so it scales with what is left).`);
|
|
77
|
+
}
|
|
78
|
+
else if (m.armies === 0 && !m.commander) {
|
|
79
|
+
throw new McpToolError(`${move(m)} sends no armies.`, {
|
|
80
|
+
hint: 'Send at least one army; 0 is only for a commander moving alone (`commander: true`).',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (m.attackTeammates) {
|
|
84
|
+
used = true;
|
|
85
|
+
if (!teammates.size) {
|
|
86
|
+
throw new McpToolError(`${move(m)} sets attack_teammates, but you have no teammates in this game.`, {
|
|
87
|
+
hint: 'Leave attack_teammates out: outside a team game every territory not yours is attacked anyway.',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (target === undefined || !teammates.has(target)) {
|
|
91
|
+
warnings.push(`${move(m)} attacks teammates, but ${label(m.to)} is not a teammate's at the start of the turn: the flag matters only if it is one when the order runs.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (m.commander) {
|
|
95
|
+
used = true;
|
|
96
|
+
if (s?.commanders !== true) {
|
|
97
|
+
throw new McpToolError(`This game has no commanders, so ${move(m)} cannot take one along.`, { hint: 'Leave `commander` out.' });
|
|
98
|
+
}
|
|
99
|
+
if (!home || !myCommander) {
|
|
100
|
+
throw new McpToolError(`No commander of yours is on the live board, so ${move(m)} cannot take one along.`, {
|
|
101
|
+
hint: 'Leave `commander` out; warapp_get_live_board shows your commander when you have one.',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (commanderMoves > 0 && !(s?.multiAttack && m.from.id === commanderAt)) {
|
|
105
|
+
throw new McpToolError(`Your commander moves once a turn, and ${move(m)} would move it again.`, {
|
|
106
|
+
hint: 'Take the commander along on one move only (under Multi-Attack it may go on from the territory it just took).',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (m.from.id !== commanderAt) {
|
|
110
|
+
throw new McpToolError(`Your commander is not on ${label(m.from)}: it stands on territory ${commanderAt} at the start of the turn.`, {
|
|
111
|
+
hint: 'Take it along on a move from the territory it stands on.',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
commanders.set(i, { id: myCommander.id, owner: me });
|
|
115
|
+
commanderMoves += 1;
|
|
116
|
+
const ontoTeammate = target !== undefined && target !== me && teammates.has(target) && !m.attackTeammates;
|
|
117
|
+
// It reaches m.to only when the order surely carries it there: not onto a teammate's land
|
|
118
|
+
// (it stays home), not an Attack Only onto my own territory or a Transfer Only onto one not
|
|
119
|
+
// mine (either may not fire). Otherwise it is held where it stood, so a Multi-Attack chain
|
|
120
|
+
// from m.to is refused rather than assumed.
|
|
121
|
+
const mayNotFire = (m.mode === 'attack-only' && target === me) || (m.mode === 'transfer-only' && target !== undefined && !friendly);
|
|
122
|
+
if (!ontoTeammate && !mayNotFire)
|
|
123
|
+
commanderAt = m.to.id;
|
|
124
|
+
if (ontoTeammate) {
|
|
125
|
+
warnings.push(`${move(m)} goes to a teammate's territory: a commander does not move onto a teammate's land, so your commander stays on ${label(m.from)}.`);
|
|
126
|
+
}
|
|
127
|
+
else if (!friendly) {
|
|
128
|
+
warnings.push(`Your commander goes with ${move(m)}: it fights as 7 armies after the ones with it, and if it dies (7 damage left over in the battle) you are eliminated.`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (used)
|
|
133
|
+
warnings.push(OPTIONS_UNVERIFIED);
|
|
134
|
+
return { warnings, commanders, estimates };
|
|
135
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { PACE_TURNS, startRegion } from '../analysis/game-lessons.js';
|
|
2
|
+
import { lessonsSummary, mapRecordStarts, mapRecordSummary, readLessons, readMapRecord } from '../lessons-store.js';
|
|
3
|
+
import { profileEnabled } from '../profile-store.js';
|
|
4
|
+
/** The note every view carries: where it comes from, and that no plan reads it. */
|
|
5
|
+
export const PAST_GAMES_NOTE = 'From your own finished games (their histories, read once at the end of each game): reported only — no plan, ranking or estimate reads it.';
|
|
6
|
+
/** Start bonuses listed on the compact views. */
|
|
7
|
+
export const MAP_RECORD_COMPACT = 8;
|
|
8
|
+
/** The record of `mapId` when it holds a game; `unreadable` when it cannot be parsed; `undefined` otherwise (off, no data dir, no map, none kept). Never throws. */
|
|
9
|
+
export async function mapRecordFor(dataDir, env, mapId) {
|
|
10
|
+
if (!dataDir || mapId === undefined || !profileEnabled(env ?? process.env))
|
|
11
|
+
return undefined;
|
|
12
|
+
try {
|
|
13
|
+
const rec = await readMapRecord(dataDir, mapId);
|
|
14
|
+
return rec === 'unreadable' || rec.games > 0 ? rec : undefined;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The map record as warapp_plan_picks and warapp_map_stats show it: games, my results, my results per
|
|
22
|
+
* bonus my start touched (`inPrimary` when the given picks touch it too), the bonuses winners started
|
|
23
|
+
* in, and the pace (medians of the winners' and my income after turns 4 and 8). Pure.
|
|
24
|
+
*/
|
|
25
|
+
export function mapRecordView(rec, o) {
|
|
26
|
+
const { mine, winners } = mapRecordStarts(rec);
|
|
27
|
+
const summary = mapRecordSummary(rec);
|
|
28
|
+
const primary = o.graph && o.picks ? new Set(startRegion(o.graph, o.picks).bonuses) : undefined;
|
|
29
|
+
const cap = (xs) => (o.full ? xs : xs.slice(0, MAP_RECORD_COMPACT));
|
|
30
|
+
return {
|
|
31
|
+
games: summary.games,
|
|
32
|
+
outcomes: summary.outcomes,
|
|
33
|
+
myStarts: cap(mine).map((m) => ({ bonus: o.bonusName(m.bonusId), games: m.games, outcomes: m.outcomes, ...(primary ? { inPrimary: primary.has(m.bonusId) } : {}) })),
|
|
34
|
+
winnerStarts: cap(winners).map((w) => ({ bonus: o.bonusName(w.bonusId), games: w.games })),
|
|
35
|
+
pace: Object.fromEntries(PACE_TURNS.map((t) => [
|
|
36
|
+
`afterTurn${t}`,
|
|
37
|
+
{ winners: t === 4 ? summary.pace.winners.income4 : summary.pace.winners.income8, mine: t === 4 ? summary.pace.mine.income4 : summary.pace.mine.income8 },
|
|
38
|
+
])),
|
|
39
|
+
...(!o.full && (mine.length > MAP_RECORD_COMPACT || winners.length > MAP_RECORD_COMPACT) ? { more: 'view "full" lists every start bonus' } : {}),
|
|
40
|
+
note: PAST_GAMES_NOTE,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The pace beside my income on the boards after turns 4 and 8 (warapp_plan_turn): with `turnsCompleted`
|
|
45
|
+
* one of {@link PACE_TURNS} and a record with a figure for it, my income now beside the median winner's
|
|
46
|
+
* and my own past median there; `undefined` otherwise. Pure.
|
|
47
|
+
*/
|
|
48
|
+
export function paceView(rec, turnsCompleted, myIncome) {
|
|
49
|
+
if (turnsCompleted === null || !PACE_TURNS.includes(turnsCompleted))
|
|
50
|
+
return undefined;
|
|
51
|
+
const s = mapRecordSummary(rec);
|
|
52
|
+
const four = turnsCompleted === 4;
|
|
53
|
+
const winners = four ? s.pace.winners.income4 : s.pace.winners.income8;
|
|
54
|
+
const myPast = four ? s.pace.mine.income4 : s.pace.mine.income8;
|
|
55
|
+
if (winners === null && myPast === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
return {
|
|
58
|
+
afterTurn: turnsCompleted,
|
|
59
|
+
mine: myIncome,
|
|
60
|
+
winners,
|
|
61
|
+
myPast,
|
|
62
|
+
games: s.games,
|
|
63
|
+
...(winners !== null ? { behindWinners: myIncome < winners } : {}),
|
|
64
|
+
note: PAST_GAMES_NOTE,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The lessons summarized (warapp_track_opponents full): per format the games, results, how the lost ones
|
|
69
|
+
* were lost, the mean turn my income went flat, and the tracker's estimate ÷ the true income by coverage
|
|
70
|
+
* band; `thisFormat` names the game's. `unreadable` when the store cannot be parsed; `undefined` when
|
|
71
|
+
* off, without a data dir, or with no game kept. Never throws.
|
|
72
|
+
*/
|
|
73
|
+
export async function pastGamesFor(dataDir, env, format) {
|
|
74
|
+
if (!dataDir || !profileEnabled(env ?? process.env))
|
|
75
|
+
return undefined;
|
|
76
|
+
try {
|
|
77
|
+
const file = await readLessons(dataDir);
|
|
78
|
+
if (file === 'unreadable')
|
|
79
|
+
return 'unreadable';
|
|
80
|
+
const s = lessonsSummary(file);
|
|
81
|
+
if (s.games <= 0)
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
thisFormat: format,
|
|
85
|
+
...s,
|
|
86
|
+
readAs: 'calibration: per coverage band (the share of its frontier the track read, #294), n turns × opponents scored, the mean and geometric mean of ' +
|
|
87
|
+
'the tracked income ÷ the true income from the history, and the shares read under half (low) and over 1.5× (high).',
|
|
88
|
+
note: PAST_GAMES_NOTE,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|