@chrischall/warapp-mcp 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +99 -6
- package/dist/analysis/accept-surrender.js +20 -2
- package/dist/analysis/calibrate.js +1 -0
- package/dist/analysis/card-support.js +175 -16
- package/dist/analysis/card-threats.js +68 -3
- package/dist/analysis/chat-advice.js +182 -0
- package/dist/analysis/chat-blocks.js +106 -0
- package/dist/analysis/chat-intent.js +559 -0
- package/dist/analysis/chat-read.js +159 -0
- package/dist/analysis/decision-replay.js +279 -0
- package/dist/analysis/decision-truth.js +146 -0
- package/dist/analysis/finished-game.js +62 -3
- package/dist/analysis/game-lessons.js +12 -6
- package/dist/analysis/opponent-profile.js +46 -3
- package/dist/analysis/opponents.js +245 -19
- package/dist/analysis/outlook.js +323 -17
- package/dist/analysis/plan/after-leftover.js +4 -1
- package/dist/analysis/plan/captures.js +4 -3
- package/dist/analysis/plan/estimates.js +70 -6
- package/dist/analysis/plan/guard-off.js +2 -1
- package/dist/analysis/plan/holds.js +79 -6
- package/dist/analysis/plan/leftover.js +145 -5
- package/dist/analysis/plan/relations.js +115 -2
- package/dist/analysis/plan/shared.js +201 -11
- package/dist/analysis/plan/stand-still.js +2 -2
- package/dist/analysis/plan/stockpile.js +104 -0
- package/dist/analysis/plan/strike.js +34 -7
- package/dist/analysis/plan/targets.js +168 -53
- package/dist/analysis/plan/threats.js +108 -5
- package/dist/analysis/plan/transfers.js +11 -0
- package/dist/analysis/plan/two-move.js +70 -0
- package/dist/analysis/plan/vacated.js +124 -2
- package/dist/analysis/planner.js +302 -42
- package/dist/analysis/since-last.js +18 -5
- package/dist/board.js +36 -2
- package/dist/build-id.js +106 -0
- package/dist/bundle.js +14943 -10146
- package/dist/chat-automation.js +22 -0
- package/dist/client.js +14 -0
- package/dist/decision-log.js +1093 -0
- package/dist/finished-store.js +5 -1
- package/dist/lessons-store.js +322 -21
- package/dist/open-games.js +36 -16
- package/dist/outlook-log.js +42 -1
- package/dist/protocol/methods.js +4 -2
- package/dist/review-export.js +198 -0
- package/dist/state-bundle.js +62 -3
- package/dist/state-cli.js +5 -3
- package/dist/strategy/notes.js +56 -0
- package/dist/tools/accept-surrender.js +23 -9
- package/dist/tools/award.js +5 -1
- package/dist/tools/card-advice.js +77 -23
- package/dist/tools/card-support-advice.js +36 -7
- package/dist/tools/chat-advice.js +330 -0
- package/dist/tools/chat-inbox.js +15 -4
- package/dist/tools/chat.js +41 -11
- package/dist/tools/check-plan.js +14 -2
- package/dist/tools/decision-capture.js +459 -0
- package/dist/tools/end-of-game.js +146 -18
- package/dist/tools/game-kind.js +92 -0
- package/dist/tools/how-lost.js +7 -2
- package/dist/tools/index.js +3 -0
- package/dist/tools/join-game.js +10 -4
- package/dist/tools/live-context.js +6 -0
- package/dist/tools/live.js +10 -1
- package/dist/tools/map-curves.js +73 -0
- package/dist/tools/notifications.js +4 -3
- package/dist/tools/opponents.js +2 -0
- package/dist/tools/past-games.js +74 -8
- package/dist/tools/picks.js +49 -10
- package/dist/tools/profile-hook.js +62 -3
- package/dist/tools/profile-opponents.js +2 -0
- package/dist/tools/push.js +2 -2
- package/dist/tools/relations.js +2 -0
- package/dist/tools/scout.js +16 -2
- package/dist/tools/state.js +6 -1
- package/dist/tools/strategy.js +3 -3
- package/dist/tools/stress-opponents.js +2 -0
- package/dist/tools/surrender-pending.js +10 -1
- package/dist/tools/surrender.js +18 -3
- package/dist/tools/turn.js +313 -18
- package/dist/tools/where.js +3 -1
- package/dist/version.js +1 -1
- package/manifest.json +23 -2
- package/mint.yaml +23 -0
- package/package.json +1 -1
- package/server.json +20 -2
- package/skills/warapp-mcp/SKILL.md +42 -8
package/dist/finished-store.js
CHANGED
|
@@ -36,6 +36,7 @@ import { profileFormatOf } from './analysis/opponent-profile.js';
|
|
|
36
36
|
import { writeJsonAtomic } from './map-store.js';
|
|
37
37
|
import { finishedGameKey, playerKey } from './player-record-store.js';
|
|
38
38
|
import { holdsSeat } from './player-states.js';
|
|
39
|
+
import { contractFinalOutlook } from './outlook-log.js';
|
|
39
40
|
import { withPathLock } from './path-lock.js';
|
|
40
41
|
export const MAX_FINISHED_RECORDS = 500;
|
|
41
42
|
/** The processed marks kept: ten times the record bound. */
|
|
@@ -211,6 +212,7 @@ export function finishedRecordOf(p) {
|
|
|
211
212
|
}
|
|
212
213
|
: {}),
|
|
213
214
|
...(c ? { outcome: { ...c.outcome, winners: c.outcome.winners.map(key) } } : {}),
|
|
215
|
+
...(p.kinds ? { kinds: p.kinds } : {}),
|
|
214
216
|
...(p.outlook ? { outlook: p.outlook } : {}),
|
|
215
217
|
...(p.picks !== undefined ? { picks: p.picks } : {}),
|
|
216
218
|
...(h ? { starts: keyed(h.starts) } : {}),
|
|
@@ -278,7 +280,9 @@ export async function readFinishedRecord(path) {
|
|
|
278
280
|
if (typeof state === 'string')
|
|
279
281
|
return state;
|
|
280
282
|
try {
|
|
281
|
-
|
|
283
|
+
const rec = JSON.parse(await readFile(path, 'utf8'));
|
|
284
|
+
// #454: a record written with the income lean as the outlook's state reads as even with that lean.
|
|
285
|
+
return rec.outlook ? { ...rec, outlook: contractFinalOutlook(rec.outlook) } : rec;
|
|
282
286
|
}
|
|
283
287
|
catch {
|
|
284
288
|
return 'unreadable';
|
package/dist/lessons-store.js
CHANGED
|
@@ -3,22 +3,29 @@
|
|
|
3
3
|
// - `<dataDir>/maps-record/<mapId>.json` (version 1), one per map I finished a game on: the games
|
|
4
4
|
// kept and their outcomes, and per game (at most `MAX_MAP_ENTRIES`, the oldest dropped first, its
|
|
5
5
|
// counts kept) the format, seats, my result, my start region (territories and the bonuses they
|
|
6
|
-
// touch) and income curve, and each winner's start region and income after turns 4
|
|
7
|
-
// to beat). At most `MAX_MAP_RECORDS` maps, the least recently written dropped first.
|
|
6
|
+
// touch) and income curve, and each winner's start region, income curve (#419) and income after turns 4
|
|
7
|
+
// and 8 (the pace to beat). At most `MAX_MAP_RECORDS` maps, the least recently written dropped first.
|
|
8
8
|
// - `<dataDir>/lessons.json` (version 1): per format the games, outcomes, how each lost game was lost
|
|
9
9
|
// (a cause, never who), the turn my income first went flat, and the tracker's estimates scored
|
|
10
10
|
// against the true incomes by frontier coverage (#294): aggregates only — a game's entry (at most
|
|
11
11
|
// `MAX_LESSON_ENTRIES`) holds the same counts for that game alone, so processing it again replaces
|
|
12
12
|
// its share, never adds it twice; a dropped entry's counts stay in the totals.
|
|
13
13
|
//
|
|
14
|
+
// - #437: a lottery or no-show game (`excludedKind`) is in neither store's figures: each keeps
|
|
15
|
+
// `excluded: { lottery, noShow, keys }` instead (a game counted apart once; one counted before is taken
|
|
16
|
+
// back out). Map entries keep the game's kinds and settings key and flags, and the views read only the
|
|
17
|
+
// games matching the current game's format and settings (`MapMatch`).
|
|
18
|
+
//
|
|
14
19
|
// Every game is keyed by `finishedGameKey` (an HMAC of my account and the game under the one shared
|
|
15
20
|
// salt): no game or player id, no name, no clock. Territory, bonus and map ids are the map's own,
|
|
16
21
|
// public data. 0600 files in 0700 folders, atomic writes under the in-process path lock; a file that
|
|
17
22
|
// exists but does not parse (not JSON, not an object, another version, a malformed total) is never
|
|
18
23
|
// overwritten (`failed`). Off with `WARAPP_PLAYER_PROFILE=off` (the end-of-game pass does not run).
|
|
19
|
-
// Profiles and lessons INFORM ONLY (P1): no planner decision reads any of this
|
|
24
|
+
// Profiles and lessons INFORM ONLY (P1): no planner decision reads any of this, save the winners' curves
|
|
25
|
+
// (#419, owner decision of 2026-11-20: `mapPaceAt` / `formatPaceAt`, thin evidence's upper bound).
|
|
20
26
|
import { readdir, readFile, stat, unlink } from 'node:fs/promises';
|
|
21
27
|
import { join } from 'node:path';
|
|
28
|
+
import { GAME_KINDS } from './analysis/finished-game.js';
|
|
22
29
|
import { addCalibration, COVERAGE_BUCKETS, } from './analysis/game-lessons.js';
|
|
23
30
|
import { PROFILE_FORMATS } from './analysis/opponent-profile.js';
|
|
24
31
|
import { writeJsonAtomic } from './map-store.js';
|
|
@@ -39,6 +46,7 @@ const isFormat = (v) => PROFILE_FORMATS.includes(v);
|
|
|
39
46
|
const RESULTS = ['won', 'lost', 'surrendered', 'eliminated', 'booted', 'ended-by-vote', 'unknown'];
|
|
40
47
|
const isResult = (v) => RESULTS.includes(v);
|
|
41
48
|
const CAUSES = ['commander', 'last-territories', 'unknown', 'surrendered', 'booted', 'still-holding'];
|
|
49
|
+
const kindsOf = (v) => Array.isArray(v) && v.every((k) => GAME_KINDS.includes(k)) ? v : undefined;
|
|
42
50
|
/** Read a store: `missing`, the parsed object, or `unreadable` (exists, not JSON or not an object). */
|
|
43
51
|
async function readStore(path) {
|
|
44
52
|
let text;
|
|
@@ -64,6 +72,51 @@ const bumpCount = (c, k, by) => {
|
|
|
64
72
|
else
|
|
65
73
|
delete c[k];
|
|
66
74
|
};
|
|
75
|
+
// ---- #437: games counted apart ----
|
|
76
|
+
/** Excluded games' keys kept per store (the newest), so a game is never counted apart twice. */
|
|
77
|
+
export const MAX_EXCLUDED_KEYS = 500;
|
|
78
|
+
const isExcludedKey = (k) => isRec(k) && typeof k.key === 'string' && HASH.test(k.key) && (k.kind === 'lottery' || k.kind === 'no-show');
|
|
79
|
+
/** The excluded block as stored: absent → `null`; malformed → `undefined`. */
|
|
80
|
+
function excludedOf(v) {
|
|
81
|
+
if (v === undefined)
|
|
82
|
+
return null;
|
|
83
|
+
if (!isRec(v) || !isInt(v.lottery) || !isInt(v.noShow) || !Array.isArray(v.keys) || !v.keys.every(isExcludedKey))
|
|
84
|
+
return undefined;
|
|
85
|
+
return { lottery: v.lottery, noShow: v.noShow, keys: v.keys.map((k) => ({ key: k.key, kind: k.kind })) };
|
|
86
|
+
}
|
|
87
|
+
const bump = (e, kind, by) => ({
|
|
88
|
+
lottery: e.lottery + (kind === 'lottery' ? by : 0),
|
|
89
|
+
noShow: e.noShow + (kind === 'no-show' ? by : 0),
|
|
90
|
+
});
|
|
91
|
+
/** `ex` with `key` counted apart as `kind` (a key there under another kind moves; the same: unchanged). */
|
|
92
|
+
function withExcluded(ex, key, kind) {
|
|
93
|
+
const e = withoutExcluded(ex, key, kind) ?? { lottery: 0, noShow: 0, keys: [] };
|
|
94
|
+
if (e.keys.some((k) => k.key === key))
|
|
95
|
+
return e;
|
|
96
|
+
return { ...bump(e, kind, 1), keys: [...e.keys, { key, kind }].slice(-MAX_EXCLUDED_KEYS) };
|
|
97
|
+
}
|
|
98
|
+
/** `ex` without `key` (a game counted apart before, now counted otherwise), unless it is kept as `keep`. */
|
|
99
|
+
function withoutExcluded(ex, key, keep) {
|
|
100
|
+
const old = ex?.keys.find((k) => k.key === key);
|
|
101
|
+
if (!ex || !old || old.kind === keep)
|
|
102
|
+
return ex;
|
|
103
|
+
return { ...bump(ex, old.kind, -1), keys: ex.keys.filter((k) => k.key !== key) };
|
|
104
|
+
}
|
|
105
|
+
/** The counts a summary shows (absent when nothing was counted apart). */
|
|
106
|
+
const excludedCounts = (ex) => (ex && (ex.lottery || ex.noShow) ? { excluded: { lottery: ex.lottery, noShow: ex.noShow } } : {});
|
|
107
|
+
const SETTINGS_KEY = /^sha256:[0-9a-f]{16}$/;
|
|
108
|
+
/** A map entry's settings as stored; `undefined` when malformed. */
|
|
109
|
+
function entrySettingsOf(v) {
|
|
110
|
+
if (!isRec(v) || !(v.key === null || (typeof v.key === 'string' && SETTINGS_KEY.test(v.key))))
|
|
111
|
+
return undefined;
|
|
112
|
+
if ((v.localDeployments !== undefined && typeof v.localDeployments !== 'boolean') || (v.commanders !== undefined && typeof v.commanders !== 'boolean'))
|
|
113
|
+
return undefined;
|
|
114
|
+
return {
|
|
115
|
+
key: v.key,
|
|
116
|
+
...(typeof v.localDeployments === 'boolean' ? { localDeployments: v.localDeployments } : {}),
|
|
117
|
+
...(typeof v.commanders === 'boolean' ? { commanders: v.commanders } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
67
120
|
const regionOf = (v) => (isRec(v) && ints(v.territories) && ints(v.bonuses) ? { territories: v.territories, bonuses: v.bonuses } : undefined);
|
|
68
121
|
function mapEntryOf(v) {
|
|
69
122
|
if (!isRec(v) || typeof v.key !== 'string' || !HASH.test(v.key) || !isFormat(v.format) || !isInt(v.seats) || !isResult(v.result) || !intOrNull(v.turns))
|
|
@@ -79,8 +132,16 @@ function mapEntryOf(v) {
|
|
|
79
132
|
const r = regionOf(w);
|
|
80
133
|
if (!r || !isRec(w) || !intOrNull(w.income4) || !intOrNull(w.income8))
|
|
81
134
|
return undefined;
|
|
82
|
-
|
|
135
|
+
// #419: the winner's curve, absent on entries kept before it.
|
|
136
|
+
if (w.income !== undefined && !(Array.isArray(w.income) && w.income.every(intOrNull)))
|
|
137
|
+
return undefined;
|
|
138
|
+
winners.push({ ...r, ...(w.income !== undefined ? { income: w.income } : {}), income4: w.income4, income8: w.income8 });
|
|
83
139
|
}
|
|
140
|
+
const kinds = kindsOf(v.kinds);
|
|
141
|
+
const settings = entrySettingsOf(v.settings);
|
|
142
|
+
// An additive field that does not read leaves the entry out, as any malformed field does.
|
|
143
|
+
if ((v.kinds !== undefined && !kinds) || (v.settings !== undefined && !settings))
|
|
144
|
+
return undefined;
|
|
84
145
|
return {
|
|
85
146
|
key: v.key,
|
|
86
147
|
format: v.format,
|
|
@@ -89,6 +150,8 @@ function mapEntryOf(v) {
|
|
|
89
150
|
turns: v.turns,
|
|
90
151
|
me: { ...mine, income: m.income, income4: m.income4, income8: m.income8 },
|
|
91
152
|
winners,
|
|
153
|
+
...(kinds ? { kinds } : {}),
|
|
154
|
+
...(settings ? { settings } : {}),
|
|
92
155
|
};
|
|
93
156
|
}
|
|
94
157
|
/** The record of `mapId`: an empty one when missing, `unreadable` when it cannot be parsed. Never throws. */
|
|
@@ -100,10 +163,11 @@ export async function readMapRecord(dir, mapId) {
|
|
|
100
163
|
if (v === 'missing')
|
|
101
164
|
return { version: 1, mapId, games: 0, outcomes: {}, entries: [] };
|
|
102
165
|
const outcomes = countsOf(v.outcomes);
|
|
103
|
-
|
|
166
|
+
const excluded = excludedOf(v.excluded);
|
|
167
|
+
if (v.version !== 1 || v.mapId !== mapId || !isInt(v.games) || !outcomes || excluded === undefined)
|
|
104
168
|
return 'unreadable';
|
|
105
169
|
const entries = (Array.isArray(v.entries) ? v.entries : []).map(mapEntryOf).filter((e) => e !== undefined);
|
|
106
|
-
return { version: 1, mapId, games: v.games, outcomes, entries };
|
|
170
|
+
return { version: 1, mapId, games: v.games, outcomes, entries, ...(excluded ? { excluded } : {}) };
|
|
107
171
|
}
|
|
108
172
|
catch {
|
|
109
173
|
return 'unreadable';
|
|
@@ -128,7 +192,9 @@ export async function recordMapGame(dir, mapId, entry, keep = MAX_MAP_RECORDS) {
|
|
|
128
192
|
rec.games++;
|
|
129
193
|
bumpCount(rec.outcomes, entry.result, 1);
|
|
130
194
|
rec.entries = [...rec.entries.filter((e) => e.key !== entry.key), entry].slice(-MAX_MAP_ENTRIES);
|
|
131
|
-
|
|
195
|
+
// #437: a game counted apart before is counted as a game now.
|
|
196
|
+
const excluded = withoutExcluded(rec.excluded, entry.key);
|
|
197
|
+
await writeJsonAtomic(path, mapRecordDir(dir), { ...rec, ...(excluded ? { excluded } : {}) });
|
|
132
198
|
return 'kept';
|
|
133
199
|
});
|
|
134
200
|
if (r === 'kept')
|
|
@@ -139,6 +205,73 @@ export async function recordMapGame(dir, mapId, entry, keep = MAX_MAP_RECORDS) {
|
|
|
139
205
|
return 'failed';
|
|
140
206
|
}
|
|
141
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* #419: give a game's winners kept before #419 their income curves, from the history its end-of-game record kept
|
|
210
|
+
* (`curves`: each winner's start territories and curve). A winner is matched by its start territories, or, with
|
|
211
|
+
* one winner and one curve, as that one; a winner with a curve keeps it. `filled` when one was added, `unchanged`
|
|
212
|
+
* when none could be, `missing` without the record or the game, `failed` on an unreadable record (never
|
|
213
|
+
* overwritten) or a failed write. Never throws.
|
|
214
|
+
*/
|
|
215
|
+
export async function fillWinnerCurves(dir, mapId, key, curves) {
|
|
216
|
+
const path = mapRecordPath(dir, mapId);
|
|
217
|
+
const same = (a, b) => a.length === b.length && [...a].sort((x, y) => x - y).every((x, i) => x === [...b].sort((p, q) => p - q)[i]);
|
|
218
|
+
try {
|
|
219
|
+
return await withPathLock(path, async () => {
|
|
220
|
+
const rec = await readMapRecord(dir, mapId);
|
|
221
|
+
if (rec === 'unreadable')
|
|
222
|
+
return 'failed';
|
|
223
|
+
const e = rec.entries.find((x) => x.key === key);
|
|
224
|
+
if (!e)
|
|
225
|
+
return 'missing';
|
|
226
|
+
let filled = false;
|
|
227
|
+
e.winners = e.winners.map((w) => {
|
|
228
|
+
if (w.income)
|
|
229
|
+
return w;
|
|
230
|
+
const c = curves.find((x) => same(x.territories, w.territories)) ?? (e.winners.length === 1 && curves.length === 1 ? curves[0] : undefined);
|
|
231
|
+
if (!c)
|
|
232
|
+
return w;
|
|
233
|
+
filled = true;
|
|
234
|
+
return { territories: w.territories, bonuses: w.bonuses, income: c.income, income4: w.income4, income8: w.income8 };
|
|
235
|
+
});
|
|
236
|
+
if (!filled)
|
|
237
|
+
return 'unchanged';
|
|
238
|
+
await writeJsonAtomic(path, mapRecordDir(dir), rec);
|
|
239
|
+
return 'filled';
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return 'failed';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* #437: count a lottery or no-show game apart in its map's record: never in its games, outcomes or entries
|
|
248
|
+
* (a game counted there before is taken back out), once per game. `excluded`, or `failed` (an unreadable
|
|
249
|
+
* record is never overwritten; a failed write). Never throws.
|
|
250
|
+
*/
|
|
251
|
+
export async function recordMapExcluded(dir, mapId, key, kind, keep = MAX_MAP_RECORDS) {
|
|
252
|
+
const path = mapRecordPath(dir, mapId);
|
|
253
|
+
try {
|
|
254
|
+
const r = await withPathLock(path, async () => {
|
|
255
|
+
const rec = await readMapRecord(dir, mapId);
|
|
256
|
+
if (rec === 'unreadable')
|
|
257
|
+
return 'failed';
|
|
258
|
+
const old = rec.entries.find((e) => e.key === key);
|
|
259
|
+
if (old) {
|
|
260
|
+
bumpCount(rec.outcomes, old.result, -1);
|
|
261
|
+
rec.games = Math.max(0, rec.games - 1);
|
|
262
|
+
rec.entries = rec.entries.filter((e) => e.key !== key);
|
|
263
|
+
}
|
|
264
|
+
await writeJsonAtomic(path, mapRecordDir(dir), { ...rec, excluded: withExcluded(rec.excluded, key, kind) });
|
|
265
|
+
return 'excluded';
|
|
266
|
+
});
|
|
267
|
+
if (r === 'excluded')
|
|
268
|
+
await pruneMapRecords(dir, keep, path).catch(() => undefined);
|
|
269
|
+
return r;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return 'failed';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
142
275
|
async function pruneMapRecords(dir, keep, protect) {
|
|
143
276
|
const folder = mapRecordDir(dir);
|
|
144
277
|
const files = [];
|
|
@@ -173,24 +306,136 @@ const median = (xs) => {
|
|
|
173
306
|
const m = Math.floor(s.length / 2);
|
|
174
307
|
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
175
308
|
};
|
|
176
|
-
/**
|
|
177
|
-
|
|
309
|
+
/** The match without its unset fields. */
|
|
310
|
+
const matchBy = (m) => ({
|
|
311
|
+
...(m.format !== undefined ? { format: m.format } : {}),
|
|
312
|
+
...(m.localDeployments !== undefined ? { localDeployments: m.localDeployments } : {}),
|
|
313
|
+
...(m.commanders !== undefined ? { commanders: m.commanders } : {}),
|
|
314
|
+
});
|
|
315
|
+
/** The entries `match` reads, and how many matched only because a flag was not kept. Pure. */
|
|
316
|
+
export function matchedEntries(rec, match) {
|
|
317
|
+
if (!match)
|
|
318
|
+
return { entries: rec.entries, settingsUnknown: 0 };
|
|
319
|
+
const m = matchBy(match);
|
|
320
|
+
let settingsUnknown = 0;
|
|
321
|
+
const entries = rec.entries.filter((e) => {
|
|
322
|
+
if (m.format !== undefined && e.format !== m.format)
|
|
323
|
+
return false;
|
|
324
|
+
let unknown = false;
|
|
325
|
+
for (const flag of ['localDeployments', 'commanders']) {
|
|
326
|
+
if (m[flag] === undefined)
|
|
327
|
+
continue;
|
|
328
|
+
const kept = e.settings?.[flag];
|
|
329
|
+
if (kept === undefined)
|
|
330
|
+
unknown = true;
|
|
331
|
+
else if (kept !== m[flag])
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (unknown)
|
|
335
|
+
settingsUnknown++;
|
|
336
|
+
return true;
|
|
337
|
+
});
|
|
338
|
+
return { entries, settingsUnknown };
|
|
339
|
+
}
|
|
340
|
+
/** The outcomes of `entries`. */
|
|
341
|
+
function outcomesOf(entries) {
|
|
342
|
+
const out = {};
|
|
343
|
+
for (const e of entries)
|
|
344
|
+
bumpCount(out, e.result, 1);
|
|
345
|
+
return out;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* What a map's record says in short: games, my results, and the winners' pace beside mine (medians over the
|
|
349
|
+
* kept games). With `match` (#437), only the games of the current game's format (and settings): their games,
|
|
350
|
+
* results and pace, and `matched` says how many of the kept entries matched. `excluded`: lottery and no-show
|
|
351
|
+
* games counted apart. Pure.
|
|
352
|
+
*/
|
|
353
|
+
export function mapRecordSummary(rec, match) {
|
|
178
354
|
const of = (xs) => median(xs.filter((x) => x !== null));
|
|
179
|
-
const
|
|
355
|
+
const { entries, settingsUnknown } = matchedEntries(rec, match);
|
|
356
|
+
const winners = entries.flatMap((e) => e.winners);
|
|
180
357
|
return {
|
|
181
|
-
games: rec.games,
|
|
182
|
-
outcomes: rec.outcomes,
|
|
358
|
+
games: match ? entries.length : rec.games,
|
|
359
|
+
outcomes: match ? outcomesOf(entries) : rec.outcomes,
|
|
183
360
|
pace: {
|
|
184
361
|
winners: { income4: of(winners.map((w) => w.income4)), income8: of(winners.map((w) => w.income8)) },
|
|
185
|
-
mine: { income4: of(
|
|
362
|
+
mine: { income4: of(entries.map((e) => e.me.income4)), income8: of(entries.map((e) => e.me.income8)) },
|
|
186
363
|
},
|
|
364
|
+
...(match ? { matched: { by: matchBy(match), entries: entries.length, of: rec.entries.length, settingsUnknown } } : {}),
|
|
365
|
+
...excludedCounts(rec.excluded),
|
|
187
366
|
};
|
|
188
367
|
}
|
|
368
|
+
// ---- #419: the fog prior's pace ----
|
|
369
|
+
/**
|
|
370
|
+
* #419 (owner decision of 2026-11-20): the past games a pace needs. With fewer on this map (of this format and
|
|
371
|
+
* settings) the pace is the format's, relative to my income; with fewer there too, none.
|
|
372
|
+
*/
|
|
373
|
+
export const MIN_PACE_GAMES = 3;
|
|
374
|
+
/** A game's winner income after `afterTurn` completed turns: the highest of its winners' (`null` when none was kept). */
|
|
375
|
+
function winnerAt(e, afterTurn) {
|
|
376
|
+
let best = null;
|
|
377
|
+
for (const w of e.winners) {
|
|
378
|
+
const x = w.income?.[afterTurn];
|
|
379
|
+
if (typeof x === 'number' && (best === null || x > best))
|
|
380
|
+
best = x;
|
|
381
|
+
}
|
|
382
|
+
return best;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* #419: the median past winner's income after `afterTurn` completed turns on this map (rounded up), over the
|
|
386
|
+
* games `match` reads (#437), one figure a game (its highest winner); `null` with fewer than
|
|
387
|
+
* {@link MIN_PACE_GAMES} games that kept one. Pure.
|
|
388
|
+
*/
|
|
389
|
+
export function mapPaceAt(rec, afterTurn, match) {
|
|
390
|
+
const xs = matchedEntries(rec, match).entries.flatMap((e) => {
|
|
391
|
+
const w = winnerAt(e, afterTurn);
|
|
392
|
+
return w === null ? [] : [w];
|
|
393
|
+
});
|
|
394
|
+
if (xs.length < MIN_PACE_GAMES)
|
|
395
|
+
return null;
|
|
396
|
+
return { income: Math.ceil(median(xs) - 1e-9), games: xs.length };
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* #419: the relative per-format pace: the median, over every map's games `match` reads, of the winner's income ÷
|
|
400
|
+
* mine after `afterTurn` completed turns (a game where I earned nothing then, or either figure is missing, left
|
|
401
|
+
* out), rounded to 2 places; `null` with fewer than {@link MIN_PACE_GAMES} games. Pure.
|
|
402
|
+
*/
|
|
403
|
+
export function formatPaceAt(recs, afterTurn, match) {
|
|
404
|
+
const xs = [];
|
|
405
|
+
for (const rec of recs)
|
|
406
|
+
for (const e of matchedEntries(rec, match).entries) {
|
|
407
|
+
const w = winnerAt(e, afterTurn);
|
|
408
|
+
const m = e.me.income[afterTurn];
|
|
409
|
+
if (w !== null && typeof m === 'number' && m > 0)
|
|
410
|
+
xs.push(w / m);
|
|
411
|
+
}
|
|
412
|
+
if (xs.length < MIN_PACE_GAMES)
|
|
413
|
+
return null;
|
|
414
|
+
return { ratio: Math.round(median(xs) * 100) / 100, games: xs.length };
|
|
415
|
+
}
|
|
416
|
+
/** Every map record kept (unreadable ones left out), by map id. Never throws. */
|
|
417
|
+
export async function readMapRecords(dir) {
|
|
418
|
+
const out = [];
|
|
419
|
+
let names;
|
|
420
|
+
try {
|
|
421
|
+
names = await readdir(mapRecordDir(dir));
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return out;
|
|
425
|
+
}
|
|
426
|
+
const ids = names.filter((n) => /^\d+\.json$/.test(n)).map((n) => Number(n.slice(0, -5))).sort((a, b) => a - b);
|
|
427
|
+
for (const id of ids) {
|
|
428
|
+
const r = await readMapRecord(dir, id);
|
|
429
|
+
if (r !== 'unreadable')
|
|
430
|
+
out.push(r);
|
|
431
|
+
}
|
|
432
|
+
return out;
|
|
433
|
+
}
|
|
189
434
|
/** My results per bonus my start touched, and how often each bonus held a winner's start (#312 E3), most games first then by id. Pure. */
|
|
190
|
-
export function mapRecordStarts(rec) {
|
|
435
|
+
export function mapRecordStarts(rec, match) {
|
|
191
436
|
const mine = new Map();
|
|
192
437
|
const winners = new Map();
|
|
193
|
-
for (const e of rec.entries) {
|
|
438
|
+
for (const e of matchedEntries(rec, match).entries) {
|
|
194
439
|
for (const b of e.me.bonuses) {
|
|
195
440
|
const x = mine.get(b) ?? { games: 0, outcomes: {} };
|
|
196
441
|
x.games++;
|
|
@@ -238,9 +483,10 @@ function lessonEntryOf(v) {
|
|
|
238
483
|
return undefined;
|
|
239
484
|
const loss = lossOf(v.howLost);
|
|
240
485
|
const calibration = calibrationOf(v.calibration);
|
|
241
|
-
|
|
486
|
+
const kinds = kindsOf(v.kinds);
|
|
487
|
+
if (loss === undefined || !calibration || (v.kinds !== undefined && !kinds))
|
|
242
488
|
return undefined;
|
|
243
|
-
return { key: v.key, format: v.format, seats: v.seats, result: v.result, flatAfterTurn: v.flatAfterTurn, howLost: loss, calibration };
|
|
489
|
+
return { key: v.key, format: v.format, seats: v.seats, result: v.result, flatAfterTurn: v.flatAfterTurn, howLost: loss, calibration, ...(kinds ? { kinds } : {}) };
|
|
244
490
|
}
|
|
245
491
|
function totalsOf(v) {
|
|
246
492
|
if (!isRec(v) || !isInt(v.games))
|
|
@@ -261,7 +507,8 @@ export async function readLessons(dir) {
|
|
|
261
507
|
return v;
|
|
262
508
|
if (v === 'missing')
|
|
263
509
|
return { version: 1, byFormat: {}, entries: [] };
|
|
264
|
-
|
|
510
|
+
const excluded = excludedOf(v.excluded);
|
|
511
|
+
if (v.version !== 1 || !isRec(v.byFormat) || excluded === undefined)
|
|
265
512
|
return 'unreadable';
|
|
266
513
|
const byFormat = {};
|
|
267
514
|
for (const [k, t] of Object.entries(v.byFormat)) {
|
|
@@ -271,7 +518,7 @@ export async function readLessons(dir) {
|
|
|
271
518
|
byFormat[k] = totals;
|
|
272
519
|
}
|
|
273
520
|
const entries = (Array.isArray(v.entries) ? v.entries : []).map(lessonEntryOf).filter((e) => e !== undefined);
|
|
274
|
-
return { version: 1, byFormat, entries };
|
|
521
|
+
return { version: 1, byFormat, entries, ...(excluded ? { excluded } : {}) };
|
|
275
522
|
}
|
|
276
523
|
catch {
|
|
277
524
|
return 'unreadable';
|
|
@@ -313,7 +560,9 @@ export async function recordLessons(dir, entry) {
|
|
|
313
560
|
applyEntry(t, entry, 1);
|
|
314
561
|
file.byFormat[entry.format] = t;
|
|
315
562
|
file.entries = [...file.entries.filter((e) => e.key !== entry.key), entry].slice(-MAX_LESSON_ENTRIES);
|
|
316
|
-
|
|
563
|
+
// #437: a game counted apart before is counted as a game now.
|
|
564
|
+
const excluded = withoutExcluded(file.excluded, entry.key);
|
|
565
|
+
await writeJsonAtomic(path, dir, { ...file, ...(excluded ? { excluded } : {}) });
|
|
317
566
|
return 'kept';
|
|
318
567
|
});
|
|
319
568
|
}
|
|
@@ -321,6 +570,36 @@ export async function recordLessons(dir, entry) {
|
|
|
321
570
|
return 'failed';
|
|
322
571
|
}
|
|
323
572
|
}
|
|
573
|
+
/**
|
|
574
|
+
* #437: count a lottery or no-show game apart: never in a format's totals or the entries (a game counted
|
|
575
|
+
* there before has its share taken back), once per game. `excluded`, or `failed` (an unreadable store is
|
|
576
|
+
* never overwritten; a failed write). Never throws.
|
|
577
|
+
*/
|
|
578
|
+
export async function recordLessonsExcluded(dir, key, kind) {
|
|
579
|
+
const path = lessonsPath(dir);
|
|
580
|
+
try {
|
|
581
|
+
return await withPathLock(path, async () => {
|
|
582
|
+
const file = await readLessons(dir);
|
|
583
|
+
if (file === 'unreadable')
|
|
584
|
+
return 'failed';
|
|
585
|
+
const old = file.entries.find((e) => e.key === key);
|
|
586
|
+
if (old) {
|
|
587
|
+
const t = file.byFormat[old.format];
|
|
588
|
+
if (t) {
|
|
589
|
+
applyEntry(t, old, -1);
|
|
590
|
+
if (t.games <= 0)
|
|
591
|
+
delete file.byFormat[old.format];
|
|
592
|
+
}
|
|
593
|
+
file.entries = file.entries.filter((e) => e.key !== key);
|
|
594
|
+
}
|
|
595
|
+
await writeJsonAtomic(path, dir, { ...file, excluded: withExcluded(file.excluded, key, kind) });
|
|
596
|
+
return 'excluded';
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
return 'failed';
|
|
601
|
+
}
|
|
602
|
+
}
|
|
324
603
|
const r2 = (x) => Math.round(x * 100) / 100;
|
|
325
604
|
/** A calibration's bands summarized ({@link RatioSummary}); a band with no sample is left out. Pure. */
|
|
326
605
|
export function calibrationSummary(c) {
|
|
@@ -352,5 +631,27 @@ export function lessonsSummary(file) {
|
|
|
352
631
|
calibration: calibrationSummary(t.calibration),
|
|
353
632
|
};
|
|
354
633
|
}
|
|
355
|
-
return { games, byFormat, calibration: calibrationSummary(all) };
|
|
634
|
+
return { games, byFormat, calibration: calibrationSummary(all), ...excludedCounts(file.excluded) };
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* #436: the outlook's calibration — per coverage band, past games' tracked income ÷ the true income
|
|
638
|
+
* (geometric mean and samples): this format's band when it has `min` samples or more, else every format's
|
|
639
|
+
* band together; a band with fewer than `min` either way is left out. Pure.
|
|
640
|
+
*/
|
|
641
|
+
export function outlookCalibration(file, format, min) {
|
|
642
|
+
let all = {};
|
|
643
|
+
for (const f of PROFILE_FORMATS) {
|
|
644
|
+
const t = file.byFormat[f];
|
|
645
|
+
if (t && t.games > 0)
|
|
646
|
+
all = addCalibration(all, t.calibration);
|
|
647
|
+
}
|
|
648
|
+
const own = file.byFormat[format]?.calibration ?? {};
|
|
649
|
+
const out = {};
|
|
650
|
+
for (const k of COVERAGE_BUCKETS) {
|
|
651
|
+
const x = (own[k]?.n ?? 0) >= min ? own[k] : all[k];
|
|
652
|
+
if (!x || x.n < min)
|
|
653
|
+
continue;
|
|
654
|
+
out[k] = { geoMean: r2(Math.exp(x.logSum / x.n)), n: x.n };
|
|
655
|
+
}
|
|
656
|
+
return out;
|
|
356
657
|
}
|
package/dist/open-games.js
CHANGED
|
@@ -474,36 +474,56 @@ const POLICY_MIN_BOOT_MINUTES = 12 * 60;
|
|
|
474
474
|
* map size went unread breaks it too). Lobbies are not counted against the game cap. Pure.
|
|
475
475
|
*/
|
|
476
476
|
export function joiningPolicy(game, screen) {
|
|
477
|
+
const breaks = policyBreaks(game, screen).map((b) => b.text);
|
|
478
|
+
if (breaks.length)
|
|
479
|
+
return { passes: false, breaks };
|
|
480
|
+
const unchecked = [];
|
|
481
|
+
if (!screen)
|
|
482
|
+
unchecked.push("the cheapest neutral's cost");
|
|
483
|
+
return unchecked.length ? { passes: null, breaks, unchecked } : { passes: true, breaks };
|
|
484
|
+
}
|
|
485
|
+
/** The joining policy's checks, by code, in policy order (#437: the decision log's join context). */
|
|
486
|
+
export const POLICY_CHECKS = ['commerce', 'mods', 'custom-scenario', 'neutral-cost', 'seats', 'boot-time', 'lottery'];
|
|
487
|
+
/** Each rule `game` breaks, its code and the policy's words, in policy order. Pure. */
|
|
488
|
+
function policyBreaks(game, screen) {
|
|
477
489
|
const breaks = [];
|
|
478
490
|
if (game.rules.some((r) => r.startsWith('Commerce')))
|
|
479
|
-
breaks.push('Commerce — the policy joins no Commerce games');
|
|
491
|
+
breaks.push({ code: 'commerce', text: 'Commerce — the policy joins no Commerce games' });
|
|
480
492
|
if (game.rules.includes('Mods'))
|
|
481
|
-
breaks.push('Mods — the policy joins no mod games');
|
|
493
|
+
breaks.push({ code: 'mods', text: 'Mods — the policy joins no mod games' });
|
|
482
494
|
if (game.rules.includes('Custom scenario'))
|
|
483
|
-
breaks.push('Custom scenario — the policy joins no custom scenarios');
|
|
495
|
+
breaks.push({ code: 'custom-scenario', text: 'Custom scenario — the policy joins no custom scenarios' });
|
|
484
496
|
if (screen && !screen.passes) {
|
|
485
|
-
breaks.push(
|
|
486
|
-
|
|
487
|
-
:
|
|
497
|
+
breaks.push({
|
|
498
|
+
code: 'neutral-cost',
|
|
499
|
+
text: screen.armiesToTake === null
|
|
500
|
+
? 'Costly neutrals — the cheapest cannot be taken at these kill rates; the policy is at most one turn of base income'
|
|
501
|
+
: `Costly neutrals — the cheapest takes ${screen.armiesToTake} armies, ${screen.turnsOfBaseIncome ?? '∞'} turns of base income; the policy is at most one turn`,
|
|
502
|
+
});
|
|
488
503
|
}
|
|
489
504
|
const seats = game.maxPlayers ?? game.seats;
|
|
490
505
|
if (seats > POLICY_MAX_SEATS)
|
|
491
|
-
breaks.push(`${seats} seats — the policy is 1v1 or at most four players`);
|
|
506
|
+
breaks.push({ code: 'seats', text: `${seats} seats — the policy is 1v1 or at most four players` });
|
|
492
507
|
if (game.bootTimeMinutes !== undefined && game.bootTimeMinutes < POLICY_MIN_BOOT_MINUTES) {
|
|
493
|
-
breaks.push(`Boot time ${game.bootTime} — the policy wants at least 12 hours`);
|
|
508
|
+
breaks.push({ code: 'boot-time', text: `Boot time ${game.bootTime} — the policy wants at least 12 hours` });
|
|
494
509
|
}
|
|
495
510
|
if (game.lottery === true)
|
|
496
|
-
breaks.push(`Lottery (${game.lotteryBasis ?? 'a tiny map'}) — pure luck; the policy joins no lotteries`);
|
|
511
|
+
breaks.push({ code: 'lottery', text: `Lottery (${game.lotteryBasis ?? 'a tiny map'}) — pure luck; the policy joins no lotteries` });
|
|
497
512
|
// A likely lottery (the lottery shape, map size unread) breaks the policy too: a caller filtering on
|
|
498
513
|
// breaks must not let one through (#217 live check).
|
|
499
514
|
if (game.lottery === null)
|
|
500
|
-
breaks.push(`Likely a lottery (${game.lotteryBasis ?? 'map size not read'}) — the policy joins no lotteries`);
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
515
|
+
breaks.push({ code: 'lottery', text: `Likely a lottery (${game.lotteryBasis ?? 'map size not read'}) — the policy joins no lotteries` });
|
|
516
|
+
return breaks;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* {@link joiningPolicy} by code (#437): the checks broken, passed and not checked (the neutral cost without
|
|
520
|
+
* the lobby's screen), and the verdict. Pure.
|
|
521
|
+
*/
|
|
522
|
+
export function policyChecks(game, screen) {
|
|
523
|
+
const broke = [...new Set(policyBreaks(game, screen).map((b) => b.code))];
|
|
524
|
+
const unchecked = screen ? [] : ['neutral-cost'];
|
|
525
|
+
const passed = POLICY_CHECKS.filter((c) => !broke.includes(c) && !unchecked.includes(c));
|
|
526
|
+
return { passes: broke.length ? false : unchecked.length ? null : true, broke, passed, unchecked };
|
|
507
527
|
}
|
|
508
528
|
/**
|
|
509
529
|
* A map of at most this many territories makes a lottery (#217): every player starts on (or next
|
package/dist/outlook-log.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
8
8
|
import { randomUUID } from 'node:crypto';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
|
+
import { splitReading } from './analysis/outlook.js';
|
|
10
11
|
const isRec = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
11
12
|
/** Turns kept per game (a long game is still a small file). */
|
|
12
13
|
const OUTLOOK_LOG_TURNS = 500;
|
|
@@ -22,12 +23,28 @@ export async function readOutlookLog(dir, gameId, playerId) {
|
|
|
22
23
|
const c = JSON.parse(await readFile(outlookLogPath(dir, gameId), 'utf8'));
|
|
23
24
|
if (!isRec(c) || c.gameId !== gameId || c.playerId !== playerId || !isRec(c.turns))
|
|
24
25
|
return undefined;
|
|
25
|
-
return c;
|
|
26
|
+
return contractStates(c);
|
|
26
27
|
}
|
|
27
28
|
catch {
|
|
28
29
|
return undefined;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* #454: a log written while #453 put the income lean in the state (`ahead`, `behind`, `unknown`) reads as
|
|
34
|
+
* `even` with that lean, per turn and on the latest; every other entry is left as it is.
|
|
35
|
+
*/
|
|
36
|
+
function contractStates(log) {
|
|
37
|
+
const fix = (e) => {
|
|
38
|
+
const { state, lean } = splitReading(e.state);
|
|
39
|
+
return lean && e.lean === undefined ? { ...e, state, lean } : e;
|
|
40
|
+
};
|
|
41
|
+
for (const [k, t] of Object.entries(log.turns))
|
|
42
|
+
if (isRec(t))
|
|
43
|
+
log.turns[k] = fix(t);
|
|
44
|
+
if (isRec(log.latest))
|
|
45
|
+
log.latest = fix(log.latest);
|
|
46
|
+
return log;
|
|
47
|
+
}
|
|
31
48
|
async function write(dir, log) {
|
|
32
49
|
const path = outlookLogPath(dir, log.gameId);
|
|
33
50
|
await mkdir(join(dir, 'outlook'), { recursive: true, mode: 0o700 });
|
|
@@ -47,6 +64,7 @@ export async function recordOutlook(dir, gameId, playerId, outlook) {
|
|
|
47
64
|
high: t.strongest?.high ?? null,
|
|
48
65
|
ratio: t.ratio,
|
|
49
66
|
state: t.state,
|
|
67
|
+
...(t.lean ? { lean: t.lean } : {}),
|
|
50
68
|
...(t.estimated ? { estimated: true } : {}),
|
|
51
69
|
...(t.figures
|
|
52
70
|
? {
|
|
@@ -63,6 +81,18 @@ export async function recordOutlook(dir, gameId, playerId, outlook) {
|
|
|
63
81
|
}
|
|
64
82
|
: {}),
|
|
65
83
|
...(t.evidence ? { evidence: logged(t.evidence) } : {}),
|
|
84
|
+
...(t.income
|
|
85
|
+
? {
|
|
86
|
+
income: {
|
|
87
|
+
mine: t.income.mine,
|
|
88
|
+
low: t.income.theirs.low,
|
|
89
|
+
high: t.income.theirs.high,
|
|
90
|
+
estimate: t.income.theirs.estimate,
|
|
91
|
+
lean: t.income.lean,
|
|
92
|
+
calibrated: t.income.calibrated,
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
66
96
|
};
|
|
67
97
|
const keep = Object.keys(log.turns)
|
|
68
98
|
.map(Number)
|
|
@@ -74,9 +104,14 @@ export async function recordOutlook(dir, gameId, playerId, outlook) {
|
|
|
74
104
|
log.latest = {
|
|
75
105
|
turn: last.turn,
|
|
76
106
|
state: outlook.state,
|
|
107
|
+
...(outlook.lean ? { lean: outlook.lean } : {}),
|
|
77
108
|
heldTurns: outlook.heldTurns,
|
|
78
109
|
basis: outlook.basis,
|
|
79
110
|
...(outlook.evidence ? { evidence: logged(outlook.evidence) } : {}),
|
|
111
|
+
// #436: the surrender line as it stood (advice only), figures only.
|
|
112
|
+
...(outlook.surrenderLine
|
|
113
|
+
? { surrenderLine: { crossed: outlook.surrenderLine.crossed, turnsBelow: outlook.surrenderLine.turnsBelow, line: outlook.surrenderLine.line } }
|
|
114
|
+
: {}),
|
|
80
115
|
};
|
|
81
116
|
await write(dir, log);
|
|
82
117
|
}
|
|
@@ -84,6 +119,11 @@ export async function recordOutlook(dir, gameId, playerId, outlook) {
|
|
|
84
119
|
// The log is optional.
|
|
85
120
|
}
|
|
86
121
|
}
|
|
122
|
+
/** #454: a final outlook read back from a finished record: one written with the lean as the state reads as `even` with that lean. */
|
|
123
|
+
export function contractFinalOutlook(o) {
|
|
124
|
+
const { state, lean } = splitReading(o.state);
|
|
125
|
+
return lean && o.lean === undefined ? { ...o, state, lean } : o;
|
|
126
|
+
}
|
|
87
127
|
export function finalOutlookOf(log) {
|
|
88
128
|
const l = log.latest;
|
|
89
129
|
if (!l || typeof l.turn !== 'number')
|
|
@@ -92,6 +132,7 @@ export function finalOutlookOf(log) {
|
|
|
92
132
|
return {
|
|
93
133
|
turn: l.turn,
|
|
94
134
|
state: l.state ?? null,
|
|
135
|
+
...(l.lean ? { lean: l.lean } : {}),
|
|
95
136
|
heldTurns: typeof l.heldTurns === 'number' ? l.heldTurns : 0,
|
|
96
137
|
...(t?.ratio ? { ratio: { low: t.ratio.low, high: t.ratio.high } } : {}),
|
|
97
138
|
...(t?.estimated ? { estimated: true } : {}),
|