@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,384 @@
|
|
|
1
|
+
import { captureFinished } from '../analysis/finished-game.js';
|
|
2
|
+
import { aggregateCalibration, calibrationSamples, flatTurn, historyHabits, incomeCurve, lessonLoss, mapFacts, } from '../analysis/game-lessons.js';
|
|
3
|
+
import { profileFormatOf } from '../analysis/opponent-profile.js';
|
|
4
|
+
import { trackGame } from '../analysis/opponents.js';
|
|
5
|
+
import { recordLessons, recordMapGame } from '../lessons-store.js';
|
|
6
|
+
import { endingOf, foldGame, markHistoryFolded, profileFileState } from '../profile-store.js';
|
|
7
|
+
import { MAX_FINISHED_RECORDS, finishedPath, finishedRecordOf, markProcessed, readFinishedState, readProcessed, touchFinished, writeFinishedRecord, } from '../finished-store.js';
|
|
8
|
+
import { withPathLock } from '../path-lock.js';
|
|
9
|
+
import { finalOutlookOf, readOutlookLog } from '../outlook-log.js';
|
|
10
|
+
import { readPickRecord } from '../pick-list.js';
|
|
11
|
+
import { finishedGameKey, playerRecordSalt, playerSaltForWrite } from '../player-record-store.js';
|
|
12
|
+
import { holdsSeat } from '../player-states.js';
|
|
13
|
+
import { profileEnabled } from '../profile-store.js';
|
|
14
|
+
import { nameFreeSettings } from '../replay.js';
|
|
15
|
+
import { historyBoards, historyReport, readBoardHistory, readCachedOrders, readCachedPlayer } from '../trend.js';
|
|
16
|
+
import { graphOf } from './common.js';
|
|
17
|
+
import { mapOf } from './map.js';
|
|
18
|
+
import { cardsInPlay, foldFinished, observeSettings, profiledOpponents } from './profile-hook.js';
|
|
19
|
+
import { keptTeams } from './team-source.js';
|
|
20
|
+
import { plannerSettings } from './turn.js';
|
|
21
|
+
/** Finished games the warapp_my_games sweep processes per call (each one GameFeed history read). */
|
|
22
|
+
export const END_OF_GAME_PER_CALL = 2;
|
|
23
|
+
const SAFE = /^[a-z_]{1,40}$/;
|
|
24
|
+
/** Bound on the in-process memos below (oldest forgotten first). */
|
|
25
|
+
const MEMO_LIMIT = 1000;
|
|
26
|
+
function remember(set, key) {
|
|
27
|
+
set.delete(key);
|
|
28
|
+
set.add(key);
|
|
29
|
+
while (set.size > MEMO_LIMIT)
|
|
30
|
+
set.delete(set.values().next().value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Games (per data dir and account) whose history request this process already spent, whatever came
|
|
34
|
+
* of it: a game in here is never read again by any trigger in this process, even when no record
|
|
35
|
+
* could be written (a read-only or full data dir) or the reply showed it not finished or not mine.
|
|
36
|
+
*/
|
|
37
|
+
const attempted = new Set();
|
|
38
|
+
const attemptKey = (dataDir, me, gameId) => `${dataDir}\0${me}\0${gameId}`;
|
|
39
|
+
/** Finished games (per data dir) whose signed-in account could not be read for the pass: asked once per process. */
|
|
40
|
+
const accountUnread = new Set();
|
|
41
|
+
/** Whether a pass on `gameId` as `me` spent its history read before (the lasting mark; an unreadable marks file: no). */
|
|
42
|
+
async function isMarked(dataDir, salt, me, gameId) {
|
|
43
|
+
const marks = await readProcessed(dataDir);
|
|
44
|
+
return marks !== 'unreadable' && marks.has(finishedGameKey(salt, me, gameId));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Whether `gameId` still needs its pass as `me`: `true` unless a record or a processed mark is there
|
|
48
|
+
* (or the pass cannot run: off, no data dir, malformed salt; or this process already spent its read). Read-only: never makes the salt. Never throws.
|
|
49
|
+
*/
|
|
50
|
+
export async function needsEndOfGame(dataDir, env, gameId, me) {
|
|
51
|
+
if (!dataDir || !profileEnabled(env))
|
|
52
|
+
return false;
|
|
53
|
+
if (attempted.has(attemptKey(dataDir, me, gameId)))
|
|
54
|
+
return false;
|
|
55
|
+
try {
|
|
56
|
+
const salt = await playerRecordSalt(dataDir);
|
|
57
|
+
if (!salt)
|
|
58
|
+
return true;
|
|
59
|
+
if ((await readFinishedState(finishedPath(dataDir, salt, me, gameId))) !== 'missing')
|
|
60
|
+
return false;
|
|
61
|
+
return !(await isMarked(dataDir, salt, me, gameId));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The end-of-game pass for `gameId` as `me` (the GameFeed id). `seen` is the read that showed it
|
|
69
|
+
* finished (absent from the sweep, whose own read serves). Never throws.
|
|
70
|
+
*/
|
|
71
|
+
export async function endOfGame(deps, gameId, me, seen, opts = {}) {
|
|
72
|
+
const { dataDir, env } = deps;
|
|
73
|
+
if (!profileEnabled(env))
|
|
74
|
+
return { status: 'off' };
|
|
75
|
+
if (!dataDir)
|
|
76
|
+
return { status: 'no-data-dir' };
|
|
77
|
+
if (me === undefined)
|
|
78
|
+
return { status: 'account-unknown' };
|
|
79
|
+
if (seen && seen.state !== 'Finished')
|
|
80
|
+
return { status: 'not-finished' };
|
|
81
|
+
if (seen && !seen.players.some((p) => p.id === me && holdsSeat(p.state)))
|
|
82
|
+
return { status: 'not-a-player' };
|
|
83
|
+
try {
|
|
84
|
+
const salt = await playerSaltForWrite(dataDir);
|
|
85
|
+
if (!salt)
|
|
86
|
+
return { status: 'unavailable' };
|
|
87
|
+
const path = finishedPath(dataDir, salt, me, gameId);
|
|
88
|
+
let read;
|
|
89
|
+
const result = await withPathLock(path, async () => {
|
|
90
|
+
const state = await readFinishedState(path);
|
|
91
|
+
if (state === 'unreadable')
|
|
92
|
+
return { status: 'record-unreadable' };
|
|
93
|
+
if (state !== 'missing' && (!opts.retry || state.status === 'captured' || !opts.history))
|
|
94
|
+
return { status: 'already-processed' };
|
|
95
|
+
// The one history read: the caller's, else one request, sent once (no transport retry) and never retried.
|
|
96
|
+
let game = opts.history;
|
|
97
|
+
let failure;
|
|
98
|
+
if (!game) {
|
|
99
|
+
if (state === 'missing' && (await isMarked(dataDir, salt, me, gameId)))
|
|
100
|
+
return { status: 'already-processed' };
|
|
101
|
+
// The request is spent from here on, whatever follows: never again in this process.
|
|
102
|
+
const key = attemptKey(dataDir, me, gameId);
|
|
103
|
+
if (attempted.has(key))
|
|
104
|
+
return { status: 'attempted' };
|
|
105
|
+
remember(attempted, key);
|
|
106
|
+
try {
|
|
107
|
+
// P2: GetMap=false, so the client never re-reads the game for a map it lacks (no `lacksTerritory`
|
|
108
|
+
// refresh, which would repeat the history read); a cached map is attached by its id. `noRetry`:
|
|
109
|
+
// a 429 or 5xx is not re-sent by the client's transport retry either, so the POST goes out once.
|
|
110
|
+
game = await deps.client.getGame(gameId, { history: true, settings: true, map: false, noRetry: true });
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
const kind = e.kind;
|
|
114
|
+
failure = { reason: 'request-failed', ...(typeof kind === 'string' && SAFE.test(kind) ? { kind } : {}) };
|
|
115
|
+
}
|
|
116
|
+
// Still in play: no lasting mark (it may end later); this process remembers the attempt.
|
|
117
|
+
if (game && game.state !== 'Finished')
|
|
118
|
+
return { status: 'not-finished' };
|
|
119
|
+
// The lasting mark, before anything else can fail: it outlives the record bound (P2).
|
|
120
|
+
await markProcessed(dataDir, finishedGameKey(salt, me, gameId));
|
|
121
|
+
// No map cached: one map-only read (no history), never a second history read.
|
|
122
|
+
if (game && !game.map && game.players.some((p) => p.id === me && holdsSeat(p.state))) {
|
|
123
|
+
const withMap = await deps.client.getGame(gameId).catch(() => undefined);
|
|
124
|
+
if (withMap?.map)
|
|
125
|
+
game.map = withMap.map;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (game && game.state !== 'Finished')
|
|
129
|
+
return { status: 'not-finished' };
|
|
130
|
+
if (game && !game.players.some((p) => p.id === me && holdsSeat(p.state)))
|
|
131
|
+
return { status: 'not-a-player' };
|
|
132
|
+
// The caller's history read is consumed here too: the lasting mark, so a pruned record is never re-read (P2).
|
|
133
|
+
if (opts.history)
|
|
134
|
+
await markProcessed(dataDir, finishedGameKey(salt, me, gameId));
|
|
135
|
+
read = game;
|
|
136
|
+
const shown = game ?? seen;
|
|
137
|
+
const { record, history } = await buildRecord(dataDir, salt, me, gameId, game, shown, failure);
|
|
138
|
+
try {
|
|
139
|
+
const protect = opts.protectIds ? new Set(opts.protectIds.map((id) => finishedPath(dataDir, salt, me, id))) : undefined;
|
|
140
|
+
await writeFinishedRecord(dataDir, path, record, opts.keep, protect);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return { status: 'failed' };
|
|
144
|
+
}
|
|
145
|
+
const processed = history && game ? await processHistory(dataDir, env, salt, me, gameId, game, history) : undefined;
|
|
146
|
+
return {
|
|
147
|
+
status: record.status,
|
|
148
|
+
...(record.turns ? { turns: record.turns.length } : {}),
|
|
149
|
+
...(record.failure ? { failure: record.failure } : {}),
|
|
150
|
+
...(processed ? { processed } : {}),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
if (opts.fold && (result.status === 'captured' || result.status === 'history-unreadable')) {
|
|
154
|
+
const game = read ?? seen;
|
|
155
|
+
if (game)
|
|
156
|
+
result.profileFold = await foldFinished(dataDir, env, game);
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return { status: 'failed' };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** The record of one pass: the capture when the history read, else what the reads that came say. */
|
|
165
|
+
async function buildRecord(dataDir, salt, me, gameId, read, shown, failure) {
|
|
166
|
+
const pick = await readPickRecord(dataDir, gameId, me);
|
|
167
|
+
const picks = pick?.list ? { list: pick.list, ...(pick.award !== undefined ? { award: pick.award } : {}) } : null;
|
|
168
|
+
// #312: the final outlook line, when this server planned the game as me.
|
|
169
|
+
const log = await readOutlookLog(dataDir, gameId, me);
|
|
170
|
+
const outlook = log ? finalOutlookOf(log) : undefined;
|
|
171
|
+
const common = {
|
|
172
|
+
outlook,
|
|
173
|
+
salt,
|
|
174
|
+
me,
|
|
175
|
+
game: shown,
|
|
176
|
+
settings: shown ? nameFreeSettings(shown) : undefined,
|
|
177
|
+
mapId: shown?.settings?.mapId ?? shown?.map?.id,
|
|
178
|
+
picks,
|
|
179
|
+
};
|
|
180
|
+
if (!read)
|
|
181
|
+
return { record: finishedRecordOf({ ...common, status: 'read-failed', failure, capture: capture(shown, me, [], new Map(), undefined) }) };
|
|
182
|
+
const report = historyReport(read);
|
|
183
|
+
const orders = (await readCachedPlayer(dataDir, gameId)) === me ? await readCachedOrders(dataDir, gameId, me) : new Map();
|
|
184
|
+
const map = read.map ? mapOf(read) : undefined;
|
|
185
|
+
if ('unreadable' in report) {
|
|
186
|
+
const u = report.unreadable;
|
|
187
|
+
return {
|
|
188
|
+
record: finishedRecordOf({
|
|
189
|
+
...common,
|
|
190
|
+
status: 'history-unreadable',
|
|
191
|
+
failure: { reason: u.reason, keys: u.keys, ...(u.layout ? { layout: u.layout } : {}), ...(u.shape ? { shape: u.shape } : {}), ...(u.turns !== undefined ? { turns: u.turns } : {}) },
|
|
192
|
+
capture: capture(read, me, [], orders, undefined),
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const boards = historyBoards(read.history, read.players, read.numberOfTurns !== undefined ? { numberOfTurns: read.numberOfTurns } : {});
|
|
197
|
+
const graph = map ? graphOf(map) : undefined;
|
|
198
|
+
const captured = capture(read, me, boards, orders, graph);
|
|
199
|
+
return {
|
|
200
|
+
record: finishedRecordOf({ ...common, status: 'captured', layout: report.read.layout, noMap: !map, capture: captured, boards }),
|
|
201
|
+
history: { capture: captured, boards, orders, graph },
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Process a captured history (#312 E2), each part on its own (one failing leaves the others): fold the
|
|
206
|
+
* opponent profiles from it (part C: `observeTurn` over the full boards with my cached orders, `history`
|
|
207
|
+
* replacing the live entry, never counting a game twice), keep the game in its map's record, and add
|
|
208
|
+
* its lessons (the turn my income went flat, how I lost, and the tracker's estimates over my cached
|
|
209
|
+
* boards scored against the truth by coverage). Never throws.
|
|
210
|
+
*/
|
|
211
|
+
async function processHistory(dataDir, env, salt, me, gameId, game, h) {
|
|
212
|
+
const out = { profiles: 'no-map', map: 'no-map', lessons: 'no-map' };
|
|
213
|
+
const g = h.graph;
|
|
214
|
+
if (!g)
|
|
215
|
+
return out;
|
|
216
|
+
const teams = await keptTeams(dataDir, game).catch(() => undefined);
|
|
217
|
+
const resolved = teams?.game ?? game;
|
|
218
|
+
const mine = resolved.players.find((p) => p.id === me);
|
|
219
|
+
const seated = resolved.players.filter((p) => holdsSeat(p.state));
|
|
220
|
+
const format = profileFormatOf(resolved.players);
|
|
221
|
+
const opponents = mine ? profiledOpponents(resolved, mine) : resolved.players.filter((p) => p.id !== me).map((p) => p.id);
|
|
222
|
+
const key = finishedGameKey(salt, me, gameId);
|
|
223
|
+
const c = h.capture;
|
|
224
|
+
try {
|
|
225
|
+
out.profiles = !teams?.known || !mine ? 'teams-unknown' : await foldHistory(dataDir, env, me, gameId, resolved, opponents, format, seated.length, h);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
out.profiles = 'failed';
|
|
229
|
+
}
|
|
230
|
+
const mapId = game.settings?.mapId ?? game.map?.id;
|
|
231
|
+
if (mapId !== undefined) {
|
|
232
|
+
out.map = await recordMapGame(dataDir, mapId, {
|
|
233
|
+
key,
|
|
234
|
+
format,
|
|
235
|
+
seats: seated.length,
|
|
236
|
+
result: c.outcome.result,
|
|
237
|
+
turns: c.outcome.turn,
|
|
238
|
+
...mapFacts(g, me, c.outcome.winners, c.starts, c.turns),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const cachedOrders = await readCachedOrders(dataDir, gameId, me);
|
|
243
|
+
const cached = ((await readCachedPlayer(dataDir, gameId)) === me ? await readBoardHistory(dataDir, gameId, me) : []).map((b) => {
|
|
244
|
+
const o = cachedOrders.get(b.turn);
|
|
245
|
+
return { turn: b.turn, board: b.board, ...(o ? { orders: o } : {}) };
|
|
246
|
+
});
|
|
247
|
+
// Every seat as still playing: a final state would read a seat out on every earlier board.
|
|
248
|
+
const asPlaying = resolved.players.map(({ state: _state, ...p }) => p);
|
|
249
|
+
const samples = calibrationSamples({
|
|
250
|
+
graph: g,
|
|
251
|
+
me,
|
|
252
|
+
cached,
|
|
253
|
+
history: h.boards,
|
|
254
|
+
plannerSettings: plannerSettings(game.settings),
|
|
255
|
+
incomeSettings: game.settings,
|
|
256
|
+
game: trackGame(asPlaying, game.settings, game.map),
|
|
257
|
+
opponents,
|
|
258
|
+
});
|
|
259
|
+
out.lessons = await recordLessons(dataDir, {
|
|
260
|
+
key,
|
|
261
|
+
format,
|
|
262
|
+
seats: seated.length,
|
|
263
|
+
result: c.outcome.result,
|
|
264
|
+
flatAfterTurn: flatTurn(incomeCurve(c.turns, me)),
|
|
265
|
+
howLost: lessonLoss({
|
|
266
|
+
result: c.outcome.result,
|
|
267
|
+
me,
|
|
268
|
+
boards: h.boards,
|
|
269
|
+
orders: h.orders,
|
|
270
|
+
graph: g,
|
|
271
|
+
settings: game.settings,
|
|
272
|
+
numberOfTurns: c.outcome.turn,
|
|
273
|
+
outTurn: c.outcome.outTurn,
|
|
274
|
+
}),
|
|
275
|
+
calibration: aggregateCalibration(samples),
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
out.lessons = 'failed';
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
/** Part C: fold the opponents' habits read off the history, as `history` (replacing a live entry). */
|
|
284
|
+
async function foldHistory(dataDir, env, me, gameId, game, opponents, format, players, h) {
|
|
285
|
+
const byId = new Map(game.players.map((p) => [p.id, p]));
|
|
286
|
+
// Never a human who became an AI (no turn of the change is known).
|
|
287
|
+
const watched = opponents.filter((id) => !byId.get(id)?.humanTurnedIntoAI);
|
|
288
|
+
const habits = historyHabits({
|
|
289
|
+
graph: h.graph,
|
|
290
|
+
me,
|
|
291
|
+
boards: h.boards,
|
|
292
|
+
orders: h.orders,
|
|
293
|
+
settings: observeSettings(game),
|
|
294
|
+
...cardsInPlay(game),
|
|
295
|
+
opponents: watched,
|
|
296
|
+
});
|
|
297
|
+
const seats = [...habits].map(([id, hb]) => ({ id, ai: byId.get(id)?.isAI === true, habits: hb, ending: endingOf(byId.get(id)?.state) }));
|
|
298
|
+
if (!seats.length)
|
|
299
|
+
return 'nothing';
|
|
300
|
+
const foldedBefore = (await profileFileState(dataDir, gameId, me)) === 'folded';
|
|
301
|
+
const r = await foldGame(dataDir, { me, gameId, format, players, source: 'history', seats, foldedBefore }, env);
|
|
302
|
+
if (r !== 'folded')
|
|
303
|
+
return 'failed';
|
|
304
|
+
await markHistoryFolded(dataDir, gameId, me);
|
|
305
|
+
return 'folded';
|
|
306
|
+
}
|
|
307
|
+
function capture(game, me, boards, orders, graph) {
|
|
308
|
+
if (!game)
|
|
309
|
+
return undefined;
|
|
310
|
+
return captureFinished({
|
|
311
|
+
graph,
|
|
312
|
+
settings: game.settings,
|
|
313
|
+
me,
|
|
314
|
+
players: game.players.filter((p) => holdsSeat(p.state)),
|
|
315
|
+
numberOfTurns: game.numberOfTurns,
|
|
316
|
+
boards,
|
|
317
|
+
orders,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The account a finished game was played as: the board cache's, else `identity` (the signed-in
|
|
322
|
+
* account, a page read through the bridge or the direct leg). Nothing at all with profiling off or no
|
|
323
|
+
* data directory (the pass cannot run, so no request is made for it). A failed `identity` read is not
|
|
324
|
+
* repeated for the same game in this process: the warapp_my_games sweep, which reads the account
|
|
325
|
+
* anyway, picks the game up later. Never throws.
|
|
326
|
+
*/
|
|
327
|
+
export async function finishedAccount(dataDir, env, gameId, identity) {
|
|
328
|
+
if (!dataDir || !profileEnabled(env))
|
|
329
|
+
return undefined;
|
|
330
|
+
const cached = await readCachedPlayer(dataDir, gameId).catch(() => undefined);
|
|
331
|
+
if (cached !== undefined)
|
|
332
|
+
return cached;
|
|
333
|
+
const key = `${dataDir}\0${gameId}`;
|
|
334
|
+
if (!identity || accountUnread.has(key))
|
|
335
|
+
return undefined;
|
|
336
|
+
let me;
|
|
337
|
+
try {
|
|
338
|
+
me = await identity();
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
me = undefined;
|
|
342
|
+
}
|
|
343
|
+
if (me === undefined)
|
|
344
|
+
remember(accountUnread, key);
|
|
345
|
+
return me;
|
|
346
|
+
}
|
|
347
|
+
/** How many of the newest finished games the sweep considers: half the store bound, so their records always fit. */
|
|
348
|
+
export const sweepWindow = (keep = MAX_FINISHED_RECORDS) => Math.max(1, Math.floor(keep / 2));
|
|
349
|
+
/**
|
|
350
|
+
* The sweep (warapp_my_games): of `gameIds` (finished games of mine, newest first), process at most
|
|
351
|
+
* `limit` not yet processed, one at a time, each folding its profiles too. `pending` counts those
|
|
352
|
+
* left for a later call. Never throws.
|
|
353
|
+
*
|
|
354
|
+
* The processed marks outlive the record bound, but they are bounded too, so the sweep looks only at
|
|
355
|
+
* the newest {@link sweepWindow} games (half the record bound): older ones are never its candidates.
|
|
356
|
+
* Its writes never prune a record of a game in that window (`protectIds`), and each call refreshes the
|
|
357
|
+
* window's records, so the records the harness and the reports read stay the newest games'. A game the
|
|
358
|
+
* sweep processed is so never read again (P2).
|
|
359
|
+
*/
|
|
360
|
+
export async function sweepFinished(deps, me, gameIds, { limit = END_OF_GAME_PER_CALL, keep = MAX_FINISHED_RECORDS } = {}) {
|
|
361
|
+
const window = gameIds.slice(0, sweepWindow(keep));
|
|
362
|
+
const todo = [];
|
|
363
|
+
for (const id of window)
|
|
364
|
+
if (await needsEndOfGame(deps.dataDir, deps.env, id, me))
|
|
365
|
+
todo.push(id);
|
|
366
|
+
await refreshProcessed(deps, me, window).catch(() => undefined);
|
|
367
|
+
const processed = [];
|
|
368
|
+
for (const id of todo.slice(0, limit)) {
|
|
369
|
+
const r = await endOfGame(deps, id, me, undefined, { fold: true, keep, protectIds: window });
|
|
370
|
+
processed.push({ gameId: id, status: r.status, ...(r.turns !== undefined ? { turns: r.turns } : {}) });
|
|
371
|
+
}
|
|
372
|
+
return { processed, pending: Math.max(0, todo.length - limit) };
|
|
373
|
+
}
|
|
374
|
+
/** Mark the window's records most recently used, so a prune drops a record outside the window first. */
|
|
375
|
+
async function refreshProcessed(deps, me, window) {
|
|
376
|
+
const { dataDir, env } = deps;
|
|
377
|
+
if (!dataDir || !profileEnabled(env))
|
|
378
|
+
return;
|
|
379
|
+
const salt = await playerRecordSalt(dataDir);
|
|
380
|
+
if (!salt)
|
|
381
|
+
return;
|
|
382
|
+
for (const id of window)
|
|
383
|
+
await touchFinished(finishedPath(dataDir, salt, me, id));
|
|
384
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { leavers } from '../normalize.js';
|
|
3
|
+
import { recordFinalResult } from '../outlook-log.js';
|
|
4
|
+
import { historyReport } from '../trend.js';
|
|
5
|
+
import { currentTurn, gameIdArg, mapSummary, readAnnotations, respond, turnsCompleted, untrustedDescription, viewArg } from './common.js';
|
|
6
|
+
import { lookupMeta } from './hints.js';
|
|
7
|
+
import { lossReport } from './how-lost.js';
|
|
8
|
+
import { endOfGame, finishedAccount } from './end-of-game.js';
|
|
9
|
+
import { foldFinished } from './profile-hook.js';
|
|
10
|
+
const VIEWS = ['compact', 'full', 'raw'];
|
|
11
|
+
function settingsDigest(s) {
|
|
12
|
+
if (!s)
|
|
13
|
+
return null;
|
|
14
|
+
const { raw: _raw, ...digest } = s;
|
|
15
|
+
return digest;
|
|
16
|
+
}
|
|
17
|
+
function compact(game) {
|
|
18
|
+
const out = {
|
|
19
|
+
game: {
|
|
20
|
+
id: game.id,
|
|
21
|
+
name: game.name ?? null,
|
|
22
|
+
state: game.state,
|
|
23
|
+
// #130: the turn being played, as every turn tool reports it; the completed count apart.
|
|
24
|
+
turn: currentTurn(game),
|
|
25
|
+
turnsCompleted: turnsCompleted(game),
|
|
26
|
+
created: game.created ?? null,
|
|
27
|
+
lastTurnTime: game.lastTurnTime ?? null,
|
|
28
|
+
},
|
|
29
|
+
players: game.players.map((p) => {
|
|
30
|
+
const row = { id: p.id, name: p.name, state: p.state ?? null, committed: p.hasCommittedOrders };
|
|
31
|
+
if (p.isAI)
|
|
32
|
+
row.ai = true;
|
|
33
|
+
if (p.humanTurnedIntoAI)
|
|
34
|
+
row.turnedIntoAI = true;
|
|
35
|
+
return row;
|
|
36
|
+
}),
|
|
37
|
+
// Humans still to commit orders this turn (only meaningful while playing).
|
|
38
|
+
waitingOn: game.state === 'Playing'
|
|
39
|
+
? game.players.filter((p) => p.state === 'Playing' && !p.isAI && !p.hasCommittedOrders).map((p) => p.name)
|
|
40
|
+
: [],
|
|
41
|
+
settings: settingsDigest(game.settings),
|
|
42
|
+
// #178: how the game ends and what a leaver's seat becomes.
|
|
43
|
+
endRules: game.endRules ?? null,
|
|
44
|
+
map: game.map ? mapSummary(game.map) : null,
|
|
45
|
+
boardAvailable: game.standing !== undefined,
|
|
46
|
+
};
|
|
47
|
+
// #178: humans who have not committed, with the time left to each boot (lastTurnTime UNVERIFIED).
|
|
48
|
+
// Only where a boot setting exists: without AutoBoot or DirectBoot nobody is close to a boot, and
|
|
49
|
+
// the list would repeat `waitingOn`.
|
|
50
|
+
const l = leavers(game, Date.now());
|
|
51
|
+
const booted = l.players.filter((p) => p.autoBootInMinutes !== undefined || p.directBootInMinutes !== undefined);
|
|
52
|
+
if (booted.length)
|
|
53
|
+
out.leavers = {
|
|
54
|
+
players: booted.map(({ playerId, ...rest }) => ({ id: playerId, name: game.players.find((p) => p.id === playerId)?.name ?? null, ...rest })),
|
|
55
|
+
unverified: l.unverified,
|
|
56
|
+
};
|
|
57
|
+
if (game.history !== undefined)
|
|
58
|
+
out.history = game.history;
|
|
59
|
+
if (game.chat !== undefined)
|
|
60
|
+
out.chat = game.chat;
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `dir` is the data directory: a finished game this server planned gets its final result in the
|
|
65
|
+
* outlook log (#178), and its opponent profile is folded into the cross-game stores (B2,
|
|
66
|
+
* docs/PLAN-PROFILES.md; off with `WARAPP_PLAYER_PROFILE=off` in `env`): the per-game file kept while it
|
|
67
|
+
* was played, else, once, its cached boards (#264's backfill), reported as `profileFold`. A finished game
|
|
68
|
+
* the cached account did not win says how (`howLost`, #274, src/tools/how-lost.ts), as does (#283) a game
|
|
69
|
+
* still playing once that account's seat is out. A finished game of mine gets its end-of-game pass once
|
|
70
|
+
* (`endOfGame`, #312, src/tools/end-of-game.ts): the account is the board cache's, else `identity` (the
|
|
71
|
+
* signed-in account).
|
|
72
|
+
*/
|
|
73
|
+
export function registerGameTool(server, client, dir, env, identity) {
|
|
74
|
+
server.registerTool('warapp_get_game', {
|
|
75
|
+
title: 'Get a war.app (Warzone) game',
|
|
76
|
+
description: untrustedDescription('Look up one war.app (Warzone) multiplayer game by id: its state (lobby, distributing, playing, finished), ' +
|
|
77
|
+
'the turn being played (`turn`; `turnsCompleted` counts the finished ones), the players and who has committed orders (who the game is waiting on), and a digest of ' +
|
|
78
|
+
'its settings — fog, kill rates, luck, rounding, base income, army cap, enabled cards — plus which map it ' +
|
|
79
|
+
'is on and whether the board is available for warapp_analyze_board; the end-of-game, boot and AI settings ' +
|
|
80
|
+
'(`endRules`) and the humans who have not committed with the time left to each boot (`leavers`, when the game boots; from ' +
|
|
81
|
+
'lastTurnTime, whose meaning is unverified). Optional game history and chat. ' +
|
|
82
|
+
'A game I lost says how (`howLost`), once finished or, while the others play on, once my seat is out (eliminated, ' +
|
|
83
|
+
'booted or surrendered): a surrender or boot by my state, with the last turn played here and the last logged outlook ' +
|
|
84
|
+
'(its state, my income and armies against the strongest opponent\'s in view); an elimination from the boards ' +
|
|
85
|
+
'this server cached while it played — the turn (certain only when it is the newest completed turn), my commander\'s territory ' +
|
|
86
|
+
'that fell with what it held, the attackers that needed and who bordered it (at a commander walk\'s destination, ' +
|
|
87
|
+
'which may instead have fallen before the walk ran), or else my last territories (inferred, never seen). ' +
|
|
88
|
+
'A finished game is folded once into the opponent profiles (`profileFold`; from the turns kept while it was played, ' +
|
|
89
|
+
'else from the boards cached then — a backfill; no other request), as warapp_profile_opponents reads them. ' +
|
|
90
|
+
'A finished game of mine also gets its end-of-game pass once (`endOfGame`: its history read once — one more ' +
|
|
91
|
+
'request — and kept name-free for later games: the outcome, my picks, every player\'s income and bonuses by turn, ' +
|
|
92
|
+
'what stood where my attacks failed — then folded into the opponent profiles, the map\'s record and the lessons ' +
|
|
93
|
+
'(`endOfGame.processed`); a failed read is recorded and not retried, except by a call with ' +
|
|
94
|
+
'`include_history`, which re-runs it from that read). ' +
|
|
95
|
+
'For the map\'s bonuses and chokepoints use warapp_get_map. Read-only.'),
|
|
96
|
+
_meta: lookupMeta(['warzone game', 'war.app game', 'whose turn is it', 'game status']),
|
|
97
|
+
annotations: readAnnotations('Get a war.app game'),
|
|
98
|
+
inputSchema: z.object({
|
|
99
|
+
game_id: gameIdArg,
|
|
100
|
+
include_history: z
|
|
101
|
+
.boolean()
|
|
102
|
+
.optional()
|
|
103
|
+
.describe('Also fetch past turns (GetHistory; war.app documents it for finished games). The result then says ' +
|
|
104
|
+
'whether the history read (`historyRead`: boards, first and last turn, layout) or why not ' +
|
|
105
|
+
'(`historyUnreadable`: reason and the reply\'s top-level key names). Default false.'),
|
|
106
|
+
include_chat: z.boolean().optional().describe('Also fetch the game chat (GetChat). Default false.'),
|
|
107
|
+
view: viewArg(VIEWS, 'compact (default) keeps the game state and turn, players with committed flags, a settings digest and a map ' +
|
|
108
|
+
'summary; "full" is every normalized field (all settings as sent, the board standing) with the map ' +
|
|
109
|
+
'summarized; "raw" is the whole normalized game including the full map.'),
|
|
110
|
+
}),
|
|
111
|
+
}, async ({ game_id, include_history, include_chat, view }) => {
|
|
112
|
+
const game = await client.getGame(game_id, {
|
|
113
|
+
settings: true,
|
|
114
|
+
...(include_history ? { history: true } : {}),
|
|
115
|
+
...(include_chat ? { chat: true } : {}),
|
|
116
|
+
});
|
|
117
|
+
let fold;
|
|
118
|
+
let lost;
|
|
119
|
+
let end;
|
|
120
|
+
if (dir) {
|
|
121
|
+
await recordFinalResult(dir(), game);
|
|
122
|
+
// #274: a game I lost says how, from the boards cached while it was played.
|
|
123
|
+
lost = await lossReport(dir(), game);
|
|
124
|
+
// The first read that shows the game finished folds its opponent profile, or backfills it from
|
|
125
|
+
// the cached boards once (#264; best effort, no request).
|
|
126
|
+
if (game.state === 'Finished')
|
|
127
|
+
fold = await foldFinished(dir(), env ?? process.env, game);
|
|
128
|
+
// #312: once per finished game of mine, its history read once and kept name-free; an explicit
|
|
129
|
+
// `include_history` re-runs a failed pass from this read.
|
|
130
|
+
if (game.state === 'Finished') {
|
|
131
|
+
const me = await finishedAccount(dir(), env ?? process.env, game.id, identity);
|
|
132
|
+
end = await endOfGame({ client, dataDir: dir(), env: env ?? process.env }, game.id, me, game, include_history ? { history: game, retry: true } : {});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const folded = {
|
|
136
|
+
...(fold && fold.status !== 'off' ? { profileFold: fold } : {}),
|
|
137
|
+
...(lost ? { howLost: lost } : {}),
|
|
138
|
+
...(end && end.status !== 'off' ? { endOfGame: end } : {}),
|
|
139
|
+
};
|
|
140
|
+
// #302: with the history asked for, whether it read, and if not why (key names and counts only).
|
|
141
|
+
const report = include_history ? historyReport(game) : undefined;
|
|
142
|
+
const historyRead = report ? ('read' in report ? { historyRead: report.read } : { historyUnreadable: report.unreadable }) : {};
|
|
143
|
+
return respond(view, VIEWS, (rung) => {
|
|
144
|
+
if (rung === 'compact')
|
|
145
|
+
return { ...compact(game), ...folded, ...historyRead };
|
|
146
|
+
if (rung === 'full')
|
|
147
|
+
return { game: { ...game, map: game.map ? mapSummary(game.map) : undefined }, ...folded, ...historyRead };
|
|
148
|
+
return { game };
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// warapp_plan_turn's `guess` (src/analysis/guess.ts): how it is shown, and the orders that carry it.
|
|
2
|
+
const pct = (p) => `${Math.round(p * 100)}%`;
|
|
3
|
+
const r2 = (x) => Math.round(x * 100) / 100;
|
|
4
|
+
/** The guess for the tool: compact (borders by name with hold probability, losses, deploys, a sentence) or full. */
|
|
5
|
+
export function guessView(guess, rung, name, opponentName) {
|
|
6
|
+
const label = (id) => `${name(id).name} (#${id})`;
|
|
7
|
+
const deployed = guess.borders.map((b) => `${b.guessDeploy} on ${label(b.id)}`).join(', ');
|
|
8
|
+
const odds = guess.borders
|
|
9
|
+
.map((b) => b.holdAloneProbability > b.holdProbability
|
|
10
|
+
? `${label(b.id)} holds everything ${pct(b.holdProbability)}, its stacks alone ${pct(b.holdAloneProbability)}`
|
|
11
|
+
: `${label(b.id)} holds everything ${pct(b.holdProbability)}`)
|
|
12
|
+
.join('; ');
|
|
13
|
+
const summary = `The opponent touches ${guess.borders.length} of your borders and the ${guess.budget} armies the plan deploys there ` +
|
|
14
|
+
`cannot hold them all against its stacks plus its deploy of ${guess.enemyDeploy}: whichever split you fix, it can hit the ` +
|
|
15
|
+
`border left short (worst case ${guess.fixedLoss} of ${guess.worthAtStake} worth at stake; the plan's split ${guess.planLoss}). ` +
|
|
16
|
+
`Drawing the split at random, weighted by worth (${odds}), expects to lose ${r2(guess.mixedLoss)}. ` +
|
|
17
|
+
`This turn's draw: ${deployed}. Optional — guessOrders carries it, orders keep the plan's split.`;
|
|
18
|
+
const opponent = { id: guess.opponent, name: opponentName };
|
|
19
|
+
const deploys = guess.deploys.map((d) => ({ territory: name(d.territoryId), armies: d.armies }));
|
|
20
|
+
if (rung === 'compact')
|
|
21
|
+
return {
|
|
22
|
+
opponent,
|
|
23
|
+
borders: guess.borders.map((b) => ({ ...name(b.id), holdProbability: b.holdProbability, holdAloneProbability: b.holdAloneProbability })),
|
|
24
|
+
fixedLoss: guess.fixedLoss,
|
|
25
|
+
mixedLoss: r2(guess.mixedLoss),
|
|
26
|
+
planLoss: guess.planLoss,
|
|
27
|
+
deploys,
|
|
28
|
+
summary,
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
opponent,
|
|
32
|
+
enemyDeploy: guess.enemyDeploy,
|
|
33
|
+
budget: guess.budget,
|
|
34
|
+
worthAtStake: guess.worthAtStake,
|
|
35
|
+
borders: guess.borders.map((b) => ({ ...b, name: name(b.id).name })),
|
|
36
|
+
fixedLoss: guess.fixedLoss,
|
|
37
|
+
mixedLoss: guess.mixedLoss,
|
|
38
|
+
planLoss: guess.planLoss,
|
|
39
|
+
targets: guess.targets.map((t) => ({ ...name(t.id), probability: t.probability })),
|
|
40
|
+
mix: guess.mix,
|
|
41
|
+
allocation: guess.allocation,
|
|
42
|
+
deploys,
|
|
43
|
+
summary,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The plan's orders with the guess's deploys in place of the plan's: every deploy order replaced by
|
|
48
|
+
* the guess's deploy list (same total), at the place the first deploy stood; every other order kept.
|
|
49
|
+
*/
|
|
50
|
+
export function guessOrdersOf(orders, guess) {
|
|
51
|
+
const at = orders.findIndex((o) => o.kind === 'deploy');
|
|
52
|
+
const rest = orders.filter((o) => o.kind !== 'deploy');
|
|
53
|
+
const deploys = guess.deploys.map((d) => ({ kind: 'deploy', territory: d.territoryId, armies: d.armies }));
|
|
54
|
+
const index = at < 0 ? rest.length : orders.slice(0, at).filter((o) => o.kind !== 'deploy').length;
|
|
55
|
+
return [...rest.slice(0, index), ...deploys, ...rest.slice(index)];
|
|
56
|
+
}
|