@chrischall/warapp-mcp 0.23.0 → 0.23.2
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/dist/analysis/plan/captures.js +1 -1
- package/dist/analysis/plan/deploy-estimates.js +17 -6
- package/dist/analysis/plan/estimates.js +1 -0
- package/dist/analysis/plan/relations.js +1 -1
- package/dist/analysis/plan/targets.js +33 -7
- package/dist/analysis/plan/threats.js +1 -1
- package/dist/analysis/relations.js +40 -7
- package/dist/bundle.js +223 -49
- package/dist/tools/calibration-harness.js +8 -1
- package/dist/tools/calibration-job.js +133 -0
- package/dist/tools/calibration-worker.js +10 -0
- package/dist/tools/calibration.js +52 -9
- package/dist/tools/check-plan.js +2 -1
- package/dist/tools/relations.js +3 -2
- package/dist/tools/turn.js +6 -2
- package/dist/trend.js +1 -0
- package/dist/version.js +1 -1
- package/manifest.json +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/bundle.js
CHANGED
|
@@ -45745,7 +45745,7 @@ var require_snapshot_utils = __commonJS({
|
|
|
45745
45745
|
var require_snapshot_recorder = __commonJS({
|
|
45746
45746
|
"node_modules/undici/lib/mock/snapshot-recorder.js"(exports, module) {
|
|
45747
45747
|
"use strict";
|
|
45748
|
-
var { writeFile: writeFile18, readFile:
|
|
45748
|
+
var { writeFile: writeFile18, readFile: readFile27, mkdir: mkdir19 } = __require("node:fs/promises");
|
|
45749
45749
|
var { dirname: dirname4, resolve: resolve6 } = __require("node:path");
|
|
45750
45750
|
var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
|
|
45751
45751
|
var { InvalidArgumentError, UndiciError } = require_errors4();
|
|
@@ -45963,7 +45963,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
45963
45963
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
45964
45964
|
}
|
|
45965
45965
|
try {
|
|
45966
|
-
const data2 = await
|
|
45966
|
+
const data2 = await readFile27(resolve6(path), "utf8");
|
|
45967
45967
|
const parsed = JSON.parse(data2);
|
|
45968
45968
|
if (Array.isArray(parsed)) {
|
|
45969
45969
|
this.#snapshots.clear();
|
|
@@ -101559,7 +101559,7 @@ function armiesFreed(pc, ps, threats, relaxed, hold) {
|
|
|
101559
101559
|
}
|
|
101560
101560
|
return Math.min(freed, income);
|
|
101561
101561
|
}
|
|
101562
|
-
var RECORD_BROKEN = (r) => `Record it with warapp_record_agreement (${r.agreement ? `agreement_id ${r.agreement}, ` : ""}status broken-by-them) before submitting: until then warapp_submit_turn refuses an order on its covered territories.`;
|
|
101562
|
+
var RECORD_BROKEN = (r) => `Record it with warapp_record_agreement (${r.agreement ? `agreement_id ${r.agreement}, ` : ""}status broken-by-them) before submitting: until then warapp_submit_turn refuses an order on its covered territories. If the partner had agreed to that move (a capture allowed in chat, the usual reason), record a \`theirs\` exception with warapp_record_agreement's \`exceptions\` instead: that is no break (#665).`;
|
|
101563
101563
|
function reportTruce(pc, ps, tp, freedOn) {
|
|
101564
101564
|
const { truce, label: label3, turnNow } = pc;
|
|
101565
101565
|
if (!truce.given.length) return void 0;
|
|
@@ -102448,7 +102448,8 @@ function planEnemyEstimates(input2) {
|
|
|
102448
102448
|
reinforcement: ctx.reinforcement,
|
|
102449
102449
|
...ctx.reinforcementPlays ? { plays: ctx.reinforcementPlays } : {},
|
|
102450
102450
|
...previousBoard && input2.previousOrders ? { previousOrders: input2.previousOrders } : {},
|
|
102451
|
-
...ctx.trackCalibration ? { calibration: ctx.trackCalibration } : {}
|
|
102451
|
+
...ctx.trackCalibration ? { calibration: ctx.trackCalibration } : {},
|
|
102452
|
+
...ctx.trackCalibrationDamping !== void 0 ? { damping: ctx.trackCalibrationDamping } : {}
|
|
102452
102453
|
});
|
|
102453
102454
|
const priced = applyKnown(
|
|
102454
102455
|
applyArmyPrice(applySanctions(estimates, input2.sanctions ?? [], turn), input2.settings?.armyCostMultiplier ?? 0),
|
|
@@ -106022,7 +106023,7 @@ function borderThreats(pc, ps, input2, src, forces) {
|
|
|
106022
106023
|
if (e.trackCalibration) {
|
|
106023
106024
|
const c = e.trackCalibration;
|
|
106024
106025
|
warnings.push(
|
|
106025
|
-
`Player ${p}'s tracked income ~${c.raw} is raised to ~${c.figure} (#568, draft): past games' tracker read ${c.geoMean.toFixed(2)}\xD7 the true income at this frontier coverage (${c.band}, ${c.n} samples), divided by its square root (${c.factor.toFixed(2)}).`
|
|
106026
|
+
`Player ${p}'s tracked income ~${c.raw} is raised to ~${c.figure} (#568, draft): past games' tracker read ${c.geoMean.toFixed(2)}\xD7 the true income at this frontier coverage (${c.band}, ${c.n} samples), divided by ${c.damping === 0.5 ? "its square root" : `it to the ${c.damping} power`} (${c.factor.toFixed(2)}).`
|
|
106026
106027
|
);
|
|
106027
106028
|
}
|
|
106028
106029
|
if (e.cardInTrack) {
|
|
@@ -106571,14 +106572,23 @@ function bonusScoring(pc, ps, threats, prev) {
|
|
|
106571
106572
|
if (!remaining.length) continue;
|
|
106572
106573
|
}
|
|
106573
106574
|
const rest = new Set(remaining);
|
|
106574
|
-
const
|
|
106575
|
-
const
|
|
106575
|
+
const others = completedOver((x) => mineSet.has(x) || rest.has(x), remaining).filter((id) => id !== b.id);
|
|
106576
|
+
const valueOf = (id) => g.bonusById.get(id).value;
|
|
106577
|
+
const penalties = others.filter((id) => valueOf(id) < 0);
|
|
106578
|
+
const penalty = penalties.reduce((n, id) => n + valueOf(id), 0);
|
|
106579
|
+
const extras2 = penalty < 0 ? others.filter((id) => valueOf(id) > 0) : [];
|
|
106580
|
+
const extra = extras2.reduce((n, id) => n + valueOf(id), 0);
|
|
106576
106581
|
const perGain = territoryShare(remaining.length);
|
|
106577
|
-
const net = b.value + penalty + perGain;
|
|
106578
|
-
if (penalty < 0 && remaining.some(bonusTarget))
|
|
106582
|
+
const net = b.value + penalty + extra + perGain;
|
|
106583
|
+
if (penalty < 0 && remaining.some(bonusTarget)) {
|
|
106584
|
+
const also = [
|
|
106585
|
+
...extras2.length ? [`${extras2.length} other positive bonus${extras2.length === 1 ? "" : "es"} (+${extra})`] : [],
|
|
106586
|
+
`${penalties.length} negative bonus${penalties.length === 1 ? "" : "es"} (${penalty})`
|
|
106587
|
+
].join(" and ");
|
|
106579
106588
|
rationale.push(
|
|
106580
|
-
`Bonus ${b.name} (#${b.id}) (+${b.value}) is worth
|
|
106589
|
+
`Bonus ${b.name} (#${b.id}) (+${b.value}) is worth ${net >= 0 ? "+" : ""}${net} net once complete: its missing members also complete ${also}${extras2.length ? "" : ", and each step short of completion only adds penalties"}.`
|
|
106581
106590
|
);
|
|
106591
|
+
}
|
|
106582
106592
|
if (net <= 0 && !isFocus) {
|
|
106583
106593
|
for (const t of remaining) uneconomicMember.add(t);
|
|
106584
106594
|
if (remaining.some(bonusTarget))
|
|
@@ -106654,8 +106664,8 @@ function bonusScoring(pc, ps, threats, prev) {
|
|
|
106654
106664
|
let neutralEachLoss = foggedNeutral ? neutralLoss : 0;
|
|
106655
106665
|
if (wasteShare > 0 && (fogged || foggedNeutral)) {
|
|
106656
106666
|
const surcharge = (each, eachLoss) => {
|
|
106657
|
-
const
|
|
106658
|
-
return { extra, extraLoss:
|
|
106667
|
+
const extra2 = Number.isFinite(each) ? Math.ceil(wasteShare * Math.max(0, wasteCost - each)) : 0;
|
|
106668
|
+
return { extra: extra2, extraLoss: extra2 > 0 ? Math.ceil(wasteShare * Math.max(0, wasteLoss - eachLoss)) : 0 };
|
|
106659
106669
|
};
|
|
106660
106670
|
const a = fogged ? surcharge(fogEach, fogLoss) : { extra: 0, extraLoss: 0 };
|
|
106661
106671
|
const n = foggedNeutral ? surcharge(neutralEach, neutralEachLoss) : { extra: 0, extraLoss: 0 };
|
|
@@ -106728,6 +106738,8 @@ function bonusScoring(pc, ps, threats, prev) {
|
|
|
106728
106738
|
borders: analyzeBonus(g, b.id).borderTerritoryIds.length,
|
|
106729
106739
|
defenseCost,
|
|
106730
106740
|
net,
|
|
106741
|
+
// #664: the income the steps short of completion cost (its penalties less per-territory income), as before.
|
|
106742
|
+
interimPenalty: -penalty - perGain,
|
|
106731
106743
|
frontier,
|
|
106732
106744
|
fogged,
|
|
106733
106745
|
fogEach,
|
|
@@ -106804,7 +106816,11 @@ function closestBonus(pc, ps, input2, prev, hd) {
|
|
|
106804
106816
|
};
|
|
106805
106817
|
const scoreRank = new Map(plans.map((p, i2) => [p.bonusId, i2]));
|
|
106806
106818
|
const completesWith = (p) => plans.filter((q) => q.remaining.every((t) => p.remaining.includes(t)));
|
|
106807
|
-
const incomeOf = (p) =>
|
|
106819
|
+
const incomeOf = (p) => {
|
|
106820
|
+
const rest = new Set(p.remaining);
|
|
106821
|
+
const bonuses = pc.completedOver((x) => pc.mineSet.has(x) || rest.has(x), p.remaining);
|
|
106822
|
+
return bonuses.reduce((n, id) => n + pc.g.bonusById.get(id).value, 0) + pc.territoryShare(p.remaining.length);
|
|
106823
|
+
};
|
|
106808
106824
|
const perArmy = (p) => {
|
|
106809
106825
|
const r = prev.ratio(p);
|
|
106810
106826
|
return Number.isFinite(r) && p.net > 0 ? r * incomeOf(p) / p.net : r;
|
|
@@ -107761,7 +107777,7 @@ function bonusPasses(pc, ps, book, hd, tgt, prev) {
|
|
|
107761
107777
|
const st = state.get(x);
|
|
107762
107778
|
restCost += !st || st.owner.kind === "unknown" || st.armies === null ? Infinity : captureCost(defenceAt(x), s) ?? Infinity;
|
|
107763
107779
|
}
|
|
107764
|
-
const penalty = p.
|
|
107780
|
+
const penalty = p.interimPenalty;
|
|
107765
107781
|
const step = gainWith([t]);
|
|
107766
107782
|
const after = incomeAfter2(/* @__PURE__ */ new Set([...heldNow(), t]));
|
|
107767
107783
|
const turns = after > 0 ? Math.max(1, Math.ceil(restCost / after)) : Infinity;
|
|
@@ -114754,11 +114770,15 @@ function trackOpponents(g, boards, me, settings = {}, game) {
|
|
|
114754
114770
|
// src/analysis/plan/deploy-estimates.ts
|
|
114755
114771
|
var MIN_TRACK_CALIBRATION_SAMPLES = 5;
|
|
114756
114772
|
var TRACK_CALIBRATION_DAMPING = 0.5;
|
|
114757
|
-
|
|
114773
|
+
var FFA_TRACK_CALIBRATION_DAMPING = 0.75;
|
|
114774
|
+
function trackCalibrationDampingFor(format) {
|
|
114775
|
+
return format === "ffa" ? FFA_TRACK_CALIBRATION_DAMPING : TRACK_CALIBRATION_DAMPING;
|
|
114776
|
+
}
|
|
114777
|
+
function trackCalibrationFactor(calibration, share, damping = TRACK_CALIBRATION_DAMPING) {
|
|
114758
114778
|
const band = coverageBucket(share);
|
|
114759
114779
|
const c = calibration?.[band];
|
|
114760
114780
|
if (!c || c.n < MIN_TRACK_CALIBRATION_SAMPLES || !(c.geoMean > 0) || c.geoMean >= 1) return void 0;
|
|
114761
|
-
return { band, geoMean: c.geoMean, n: c.n, factor: c.geoMean **
|
|
114781
|
+
return { band, geoMean: c.geoMean, n: c.n, factor: c.geoMean ** damping, damping };
|
|
114762
114782
|
}
|
|
114763
114783
|
function openingArmies(g, board, when = {}) {
|
|
114764
114784
|
if (when.previous !== void 0 || when.turn !== null && when.turn !== void 0 && when.turn > 1) return null;
|
|
@@ -114922,10 +114942,10 @@ function enemyDeployEstimates(g, board, me, settings = {}, previous, tracks, pri
|
|
|
114922
114942
|
const coverage2 = usable2 ? trackCoverage(usable2.turns.filter((x) => usable2.incomeTurns.includes(x.from))) : null;
|
|
114923
114943
|
let trackCalibration = null;
|
|
114924
114944
|
if (usable2 && tracked !== null && tracked > 0) {
|
|
114925
|
-
const c = trackCalibrationFactor(when.calibration, coverage2 ? coverage2.share : null);
|
|
114945
|
+
const c = trackCalibrationFactor(when.calibration, coverage2 ? coverage2.share : null, when.damping);
|
|
114926
114946
|
const figure = c ? Math.min(Math.max(couldEarn, tracked), Math.round(tracked / c.factor)) : tracked;
|
|
114927
114947
|
if (c && figure > tracked) {
|
|
114928
|
-
trackCalibration = { raw: tracked, band: c.band, geoMean: c.geoMean, n: c.n, factor: c.factor, figure };
|
|
114948
|
+
trackCalibration = { raw: tracked, band: c.band, geoMean: c.geoMean, n: c.n, factor: c.factor, damping: c.damping, figure };
|
|
114929
114949
|
tracked = figure;
|
|
114930
114950
|
}
|
|
114931
114951
|
}
|
|
@@ -116214,7 +116234,7 @@ function serverBuild() {
|
|
|
116214
116234
|
}
|
|
116215
116235
|
|
|
116216
116236
|
// src/version.ts
|
|
116217
|
-
var VERSION2 = "0.23.
|
|
116237
|
+
var VERSION2 = "0.23.2";
|
|
116218
116238
|
|
|
116219
116239
|
// src/decision-log.ts
|
|
116220
116240
|
var DECISION_LOG_VERSION = 1;
|
|
@@ -116796,9 +116816,9 @@ async function recordGameEvent(dir, gameId, playerId, ev, o = {}, opts = {}) {
|
|
|
116796
116816
|
return false;
|
|
116797
116817
|
}
|
|
116798
116818
|
}
|
|
116799
|
-
async function recordJoin(dir, gameId, playerId,
|
|
116819
|
+
async function recordJoin(dir, gameId, playerId, join32, opts = {}) {
|
|
116800
116820
|
try {
|
|
116801
|
-
const kept = encodeValue(
|
|
116821
|
+
const kept = encodeValue(join32);
|
|
116802
116822
|
return await updateDecisionLog(dir, gameId, playerId, (log) => ({ ...log, join: kept }), opts);
|
|
116803
116823
|
} catch {
|
|
116804
116824
|
return false;
|
|
@@ -117221,8 +117241,21 @@ function expectedArmies(t, before, orders, mine3) {
|
|
|
117221
117241
|
if (m.from === t) n -= m.armies;
|
|
117222
117242
|
if (m.to === t && mine3.has(m.from)) n += m.armies;
|
|
117223
117243
|
}
|
|
117244
|
+
for (const c of orders.cards ?? []) {
|
|
117245
|
+
if (c.card !== "Airlift" || c.armies === void 0) continue;
|
|
117246
|
+
if (c.from === t) n -= c.armies;
|
|
117247
|
+
if (c.to === t && c.from !== void 0 && mine3.has(c.from)) n += c.armies;
|
|
117248
|
+
}
|
|
117224
117249
|
return n;
|
|
117225
117250
|
}
|
|
117251
|
+
var GIVES_AWAY = /* @__PURE__ */ new Set(["Gift", "Blockade", "EmergencyBlockade"]);
|
|
117252
|
+
function gaveAway(t, orders) {
|
|
117253
|
+
return (orders?.cards ?? []).some((c) => GIVES_AWAY.has(c.card) && c.target === t);
|
|
117254
|
+
}
|
|
117255
|
+
function airliftUncounted(t, orders, cards2) {
|
|
117256
|
+
if (orders.cards === void 0) return cards2 === void 0 || cards2.includes("Airlift");
|
|
117257
|
+
return orders.cards.some((c) => c.card === "Airlift" && c.armies === void 0 && (c.from === t || c.to === t));
|
|
117258
|
+
}
|
|
117226
117259
|
function fedByHitSource(t, orders, mine3, was, now, me) {
|
|
117227
117260
|
return orders.moves.some((m) => {
|
|
117228
117261
|
if (m.to !== t || !mine3.has(m.from)) return false;
|
|
@@ -117283,6 +117316,7 @@ function breachWatch(input2) {
|
|
|
117283
117316
|
const shown2 = ownerShown(after);
|
|
117284
117317
|
const neighbours = neighborsOf(graph, c);
|
|
117285
117318
|
const partnerNext = neighbours.some((n) => ownerOn(ownerShown(was.get(n))) === partner || ownerOn(ownerShown(now.get(n))) === partner);
|
|
117319
|
+
if (gaveAway(c, from.orders)) continue;
|
|
117286
117320
|
if (shown2 && ownerOn(shown2) === partner) {
|
|
117287
117321
|
taken.push(c);
|
|
117288
117322
|
continue;
|
|
@@ -117297,7 +117331,7 @@ function breachWatch(input2) {
|
|
|
117297
117331
|
if (before == null || nowArmies == null) continue;
|
|
117298
117332
|
if (expectedArmies(c, before, from.orders, mine3) - nowArmies <= 0) continue;
|
|
117299
117333
|
if (!partnerNext) continue;
|
|
117300
|
-
if (fedByHitSource(c, from.orders, mine3, was, now, me)) {
|
|
117334
|
+
if (fedByHitSource(c, from.orders, mine3, was, now, me) || airliftUncounted(c, from.orders, input2.cards)) {
|
|
117301
117335
|
ambiguous2.push(c);
|
|
117302
117336
|
continue;
|
|
117303
117337
|
}
|
|
@@ -117504,7 +117538,8 @@ function planRelationsFrom(input2) {
|
|
|
117504
117538
|
graph,
|
|
117505
117539
|
boards: input2.boards,
|
|
117506
117540
|
me,
|
|
117507
|
-
...incomes.mine !== null ? { incomes: { mine: incomes.mine, partner: partnerIncome ?? null } } : {}
|
|
117541
|
+
...incomes.mine !== null ? { incomes: { mine: incomes.mine, partner: partnerIncome ?? null } } : {},
|
|
117542
|
+
...input2.cards ? { cards: input2.cards } : {}
|
|
117508
117543
|
});
|
|
117509
117544
|
const others = [...incomes.opponents].filter(([id]) => id !== a.with);
|
|
117510
117545
|
const endgame = incomes.mine !== null && partnerIncome !== null && partnerIncome !== void 0 && others.every(([, v]) => v !== null) ? truceEndgame({ mine: incomes.mine, partner: partnerIncome, others: others.map(([, v]) => v) }) : false;
|
|
@@ -117718,7 +117753,7 @@ function truceVerdict(price, income) {
|
|
|
117718
117753
|
return {
|
|
117719
117754
|
verdict: "no",
|
|
117720
117755
|
reasons: [
|
|
117721
|
-
`player ${p} broke the truce${b ? `: ${b.term} on turn ${b.turn} (${b.evidence})` : ""}; it is an ordinary opponent now, and no truce is priced as trusted (T8)`
|
|
117756
|
+
`player ${p} broke the truce${b ? `: ${b.term} on turn ${b.turn} (${b.evidence})` : ""}; it is an ordinary opponent now, and no truce is priced as trusted (T8). If the partner had agreed to that move, record a \`theirs\` exception with warapp_record_agreement instead (#665)`
|
|
117722
117757
|
]
|
|
117723
117758
|
};
|
|
117724
117759
|
}
|
|
@@ -137830,9 +137865,9 @@ function parseEndRules(raw) {
|
|
|
137830
137865
|
function parseFeedTime(s) {
|
|
137831
137866
|
if (s === void 0) return void 0;
|
|
137832
137867
|
const us = /^\s*(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{2}):(\d{2})\s*$/.exec(s);
|
|
137833
|
-
const
|
|
137834
|
-
if (!us && !
|
|
137835
|
-
const [, mo, d, y, h, mi, se] = us ? us.map(Number) : [0,
|
|
137868
|
+
const iso5 = /^\s*(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?Z?\s*$/.exec(s);
|
|
137869
|
+
if (!us && !iso5) return void 0;
|
|
137870
|
+
const [, mo, d, y, h, mi, se] = us ? us.map(Number) : [0, iso5[2], iso5[3], iso5[1], iso5[4], iso5[5], iso5[6]].map(Number);
|
|
137836
137871
|
const t = Date.UTC(y, mo - 1, d, h, mi, se);
|
|
137837
137872
|
return Number.isFinite(t) ? t : void 0;
|
|
137838
137873
|
}
|
|
@@ -138095,7 +138130,8 @@ function ordersOf(o) {
|
|
|
138095
138130
|
card: c.card,
|
|
138096
138131
|
...isNum(c.from) ? { from: c.from } : {},
|
|
138097
138132
|
...isNum(c.to) ? { to: c.to } : {},
|
|
138098
|
-
...isNum(c.target) ? { target: c.target } : {}
|
|
138133
|
+
...isNum(c.target) ? { target: c.target } : {},
|
|
138134
|
+
...isNum(c.armies) ? { armies: c.armies } : {}
|
|
138099
138135
|
}))
|
|
138100
138136
|
} : {}
|
|
138101
138137
|
};
|
|
@@ -139942,9 +139978,9 @@ async function captureGameEvent(ctx, gameId, me, ev, o = {}) {
|
|
|
139942
139978
|
if (!ctx.dataDir) return;
|
|
139943
139979
|
await recordGameEvent(ctx.dataDir, gameId, me, ev, o, modeOf2(ctx));
|
|
139944
139980
|
}
|
|
139945
|
-
async function captureJoin(ctx, gameId, me,
|
|
139981
|
+
async function captureJoin(ctx, gameId, me, join32) {
|
|
139946
139982
|
if (!ctx.dataDir) return;
|
|
139947
|
-
await recordJoin(ctx.dataDir, gameId, me,
|
|
139983
|
+
await recordJoin(ctx.dataDir, gameId, me, join32, modeOf2(ctx));
|
|
139948
139984
|
}
|
|
139949
139985
|
async function captureOpponentRead(ctx, gameId, me, player2, read) {
|
|
139950
139986
|
if (!ctx.dataDir) return;
|
|
@@ -155727,7 +155763,9 @@ function myOrdersOf2(orders) {
|
|
|
155727
155763
|
card: o.card,
|
|
155728
155764
|
...o.from !== void 0 ? { from: o.from } : {},
|
|
155729
155765
|
...o.to !== void 0 ? { to: o.to } : {},
|
|
155730
|
-
...o.target !== void 0 ? { target: o.target } : {}
|
|
155766
|
+
...o.target !== void 0 ? { target: o.target } : {},
|
|
155767
|
+
// #665: the truce watch counts what an Airlift took out of or landed on a territory.
|
|
155768
|
+
...o.card === "Airlift" && o.armies !== void 0 ? { armies: o.armies } : {}
|
|
155731
155769
|
}
|
|
155732
155770
|
] : []
|
|
155733
155771
|
)
|
|
@@ -155898,6 +155936,7 @@ async function truceRelations(ctx, a) {
|
|
|
155898
155936
|
boards: [...a.boards, { turn, board: a.board }],
|
|
155899
155937
|
me: me.id,
|
|
155900
155938
|
turn,
|
|
155939
|
+
...cardsInPlay(game),
|
|
155901
155940
|
players: game.players.map((p) => ({
|
|
155902
155941
|
id: p.id,
|
|
155903
155942
|
...p.isAI ? { isAI: true } : {},
|
|
@@ -156047,7 +156086,7 @@ async function livePlanSetup(ctx, a) {
|
|
|
156047
156086
|
...mapPace ? { mapPace } : {},
|
|
156048
156087
|
// #568: this format's own calibration raises each tracked figure by its coverage band's damped factor
|
|
156049
156088
|
// (none in a 1v1, where the fog prior already lifts the tracker: trackCalibrationFor).
|
|
156050
|
-
...trackCalibration ? { trackCalibration } : {},
|
|
156089
|
+
...trackCalibration ? { trackCalibration, trackCalibrationDamping: trackCalibrationDampingFor(profileFormatOf(game.players)) } : {},
|
|
156051
156090
|
// #164: an opponent's Reinforcement card, from the turn the card clock says one can be in hand.
|
|
156052
156091
|
...opponentReinforcement(game.settings, hand) ? { reinforcement: opponentReinforcement(game.settings, hand) } : {},
|
|
156053
156092
|
// #427: the Reinforcement plays seen in the turns' orders (card plays not fogged): a play restarts the clock.
|
|
@@ -156507,7 +156546,7 @@ async function commanderCheck(ctx, a) {
|
|
|
156507
156546
|
info: a.info,
|
|
156508
156547
|
...opening ? { opening } : {},
|
|
156509
156548
|
...mapPace ? { mapPace } : {},
|
|
156510
|
-
...trackCalibration ? { trackCalibration } : {}
|
|
156549
|
+
...trackCalibration ? { trackCalibration, trackCalibrationDamping: trackCalibrationDampingFor(profileFormatOf(a.game.players)) } : {}
|
|
156511
156550
|
});
|
|
156512
156551
|
const tripwires = a.tripwires ?? (await readTripwires({
|
|
156513
156552
|
dataDir: ctx.dataDir,
|
|
@@ -159890,7 +159929,7 @@ async function updateAgreementRecord(o) {
|
|
|
159890
159929
|
let context;
|
|
159891
159930
|
if (agreement.status !== before?.status && (agreement.status === "broken-by-them" || agreement.status === "broken-by-me")) {
|
|
159892
159931
|
const boards = await cachedBoards(dir, game, me);
|
|
159893
|
-
breachFlag = strongestFlag(breachWatch({ agreement, graph, boards, me: me.id }));
|
|
159932
|
+
breachFlag = strongestFlag(breachWatch({ agreement, graph, boards, me: me.id, ...cardsInPlay(game) }));
|
|
159894
159933
|
const incomes = incomesOf(graph, boards, game, me, map2);
|
|
159895
159934
|
const partnerIncome = incomes.opponents.get(agreement.with) ?? null;
|
|
159896
159935
|
context = {
|
|
@@ -160101,6 +160140,7 @@ function registerRelationsTools(server, ctx, opts = {}) {
|
|
|
160101
160140
|
graph,
|
|
160102
160141
|
boards,
|
|
160103
160142
|
me: me.id,
|
|
160143
|
+
...cardsInPlay(game),
|
|
160104
160144
|
...live_ && incomes.mine !== null ? { incomes: { mine: incomes.mine, partner: incomes.opponents.get(a.with) ?? null } } : {}
|
|
160105
160145
|
}) : [];
|
|
160106
160146
|
const endgame = live_ ? endgameOf(incomes, a.with) : null;
|
|
@@ -162065,7 +162105,7 @@ function registerCheckPlanTool(server, ctx) {
|
|
|
162065
162105
|
info,
|
|
162066
162106
|
...opening ? { opening } : {},
|
|
162067
162107
|
...mapPace ? { mapPace } : {},
|
|
162068
|
-
...trackCalibration ? { trackCalibration } : {},
|
|
162108
|
+
...trackCalibration ? { trackCalibration, trackCalibrationDamping: trackCalibrationDampingFor(profileFormatOf(game.players)) } : {},
|
|
162069
162109
|
...enemy_deploy !== void 0 ? { enemyDeploy: enemy_deploy } : {},
|
|
162070
162110
|
assumeCards,
|
|
162071
162111
|
// #444: the stated incomes scale the other opponents' prior, as warapp_plan_turn has them.
|
|
@@ -163622,7 +163662,7 @@ function registerJoinGameTool(server, ctx) {
|
|
|
163622
163662
|
}
|
|
163623
163663
|
};
|
|
163624
163664
|
},
|
|
163625
|
-
async execute({ gameId, name: name2, url: url4, team, color, account, join:
|
|
163665
|
+
async execute({ gameId, name: name2, url: url4, team, color, account, join: join32 }) {
|
|
163626
163666
|
await requireApprovedAccount(ctx, account);
|
|
163627
163667
|
const game = { id: gameId, name: name2, url: url4 };
|
|
163628
163668
|
let vacationEnded = false;
|
|
@@ -163660,7 +163700,7 @@ function registerJoinGameTool(server, ctx) {
|
|
|
163660
163700
|
unreadable: () => notShown(),
|
|
163661
163701
|
classify: (seated) => seated ? { status: "joined", outcome: "confirmed", game, ...extra() } : notShown()
|
|
163662
163702
|
});
|
|
163663
|
-
if (result2.outcome === "confirmed" &&
|
|
163703
|
+
if (result2.outcome === "confirmed" && join32) await captureJoin(ctx, gameId, Number(account), join32);
|
|
163664
163704
|
return result2;
|
|
163665
163705
|
}
|
|
163666
163706
|
}
|
|
@@ -166503,8 +166543,8 @@ function readTemplateLengths(body) {
|
|
|
166503
166543
|
const n = body.int32();
|
|
166504
166544
|
for (let i2 = 0; i2 < n; i2++) {
|
|
166505
166545
|
const id = body.int32();
|
|
166506
|
-
const
|
|
166507
|
-
if (Number.isFinite(
|
|
166546
|
+
const minutes3 = body.float64();
|
|
166547
|
+
if (Number.isFinite(minutes3)) out.set(id, minutes3);
|
|
166508
166548
|
}
|
|
166509
166549
|
return out;
|
|
166510
166550
|
}
|
|
@@ -166570,7 +166610,7 @@ function registerSettingsRead(server, ctx) {
|
|
|
166570
166610
|
},
|
|
166571
166611
|
async ({ lengths }) => {
|
|
166572
166612
|
const { settings, unlocked } = await readSettings2(ctx);
|
|
166573
|
-
let
|
|
166613
|
+
let minutes3;
|
|
166574
166614
|
let lengthsNote;
|
|
166575
166615
|
if (lengths === true && unlocked.length > 0) {
|
|
166576
166616
|
try {
|
|
@@ -166579,7 +166619,7 @@ function registerSettingsRead(server, ctx) {
|
|
|
166579
166619
|
Method.GetTemplateLengths,
|
|
166580
166620
|
(w) => writeGetTemplateLengthsParams(w, unlocked.map((t) => t.id))
|
|
166581
166621
|
);
|
|
166582
|
-
|
|
166622
|
+
minutes3 = readTemplateLengths(env.body);
|
|
166583
166623
|
} catch (e) {
|
|
166584
166624
|
lengthsNote = `The template lengths could not be read (${failureText(e)}).`;
|
|
166585
166625
|
}
|
|
@@ -166589,7 +166629,7 @@ function registerSettingsRead(server, ctx) {
|
|
|
166589
166629
|
name: shownName2(t.name),
|
|
166590
166630
|
mapId: t.mapId,
|
|
166591
166631
|
...templateView(settings.templates.get(t.id) ?? QUICKMATCH_TEMPLATE_SETTINGS.off),
|
|
166592
|
-
...
|
|
166632
|
+
...minutes3 ? { averageMinutes: minutes3.has(t.id) ? Math.round(minutes3.get(t.id)) : null } : {}
|
|
166593
166633
|
}));
|
|
166594
166634
|
return respond(void 0, ["compact"], () => ({
|
|
166595
166635
|
...settingsView(settings),
|
|
@@ -171331,7 +171371,7 @@ function registerAcceptInviteTool(server, ctx) {
|
|
|
171331
171371
|
}
|
|
171332
171372
|
};
|
|
171333
171373
|
},
|
|
171334
|
-
async execute({ gameId, name: name2, url: url4, color, account, join:
|
|
171374
|
+
async execute({ gameId, name: name2, url: url4, color, account, join: join32 }) {
|
|
171335
171375
|
await requireApprovedAccount(ctx, account);
|
|
171336
171376
|
const game = { id: gameId, name: untrustedText(name2), url: url4 };
|
|
171337
171377
|
let vacationEnded = false;
|
|
@@ -171364,7 +171404,7 @@ function registerAcceptInviteTool(server, ctx) {
|
|
|
171364
171404
|
unreadable: () => notShown(),
|
|
171365
171405
|
classify: (seated) => seated ? { status: "accepted", outcome: "confirmed", game, ...extra() } : notShown()
|
|
171366
171406
|
});
|
|
171367
|
-
if (result2.outcome === "confirmed" &&
|
|
171407
|
+
if (result2.outcome === "confirmed" && join32) await captureJoin(ctx, gameId, Number(account), join32);
|
|
171368
171408
|
return result2;
|
|
171369
171409
|
}
|
|
171370
171410
|
}
|
|
@@ -173432,13 +173472,16 @@ var HARNESS_APPROXIMATIONS = [
|
|
|
173432
173472
|
"the history boards: no capture, no failed attack, no orders cached; army growth alone is not orders) or a boot of my seat in turns",
|
|
173433
173473
|
"1-4 is reported apart, never averaged in."
|
|
173434
173474
|
];
|
|
173475
|
+
var yieldToLoop = () => new Promise((resolve6) => setImmediate(resolve6));
|
|
173435
173476
|
async function calibrationHarness(dir, opts = {}) {
|
|
173436
173477
|
const src = await calibrationSources(dir);
|
|
173437
173478
|
const counts = { histories: src.statuses, skipped: src.skipped, scored: 0, recordOnly: 0, benchmarked: 0, samples: 0 };
|
|
173438
173479
|
const byFormat = {};
|
|
173439
173480
|
const benchByFormat = {};
|
|
173440
173481
|
const eraEntries = [];
|
|
173482
|
+
let done = 0;
|
|
173441
173483
|
for (const input2 of src.inputs) {
|
|
173484
|
+
opts.signal?.throwIfAborted();
|
|
173442
173485
|
const { history: h, settings, map: map2, cached: cached4 } = input2;
|
|
173443
173486
|
if (input2.source === "record-only") counts.recordOnly++;
|
|
173444
173487
|
const me = h.me;
|
|
@@ -173491,7 +173534,10 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
173491
173534
|
});
|
|
173492
173535
|
eraEntries.push({ era, basis, format, territories: graph.territoryById.size, flags, bench });
|
|
173493
173536
|
}
|
|
173537
|
+
opts.progress?.(++done, src.inputs.length);
|
|
173538
|
+
await yieldToLoop();
|
|
173494
173539
|
}
|
|
173540
|
+
opts.signal?.throwIfAborted();
|
|
173495
173541
|
const calibration = {};
|
|
173496
173542
|
for (const [format, ests] of Object.entries(byFormat))
|
|
173497
173543
|
for (const [k, c] of Object.entries(ests))
|
|
@@ -173502,7 +173548,117 @@ async function calibrationHarness(dir, opts = {}) {
|
|
|
173502
173548
|
return { counts, calibration, benchmark, byEra: benchmarkByEra(eraEntries) };
|
|
173503
173549
|
}
|
|
173504
173550
|
|
|
173551
|
+
// src/tools/calibration-job.ts
|
|
173552
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
173553
|
+
import { readFile as readFile26 } from "node:fs/promises";
|
|
173554
|
+
import { join as join31 } from "node:path";
|
|
173555
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
173556
|
+
import { Worker } from "node:worker_threads";
|
|
173557
|
+
var HARNESS_LIMIT_MS = 3 * 60 * 60 * 1e3;
|
|
173558
|
+
var harnessFolder = (dir) => join31(dir, "calibration");
|
|
173559
|
+
var harnessResultPath = (dir) => join31(harnessFolder(dir), "harness.json");
|
|
173560
|
+
var jobs = /* @__PURE__ */ new Map();
|
|
173561
|
+
async function readSaved(dir) {
|
|
173562
|
+
try {
|
|
173563
|
+
const v = JSON.parse(await readFile26(harnessResultPath(dir), "utf8"));
|
|
173564
|
+
return typeof v.finishedAt === "string" && typeof v.result === "object" && v.result !== null ? v : void 0;
|
|
173565
|
+
} catch {
|
|
173566
|
+
return void 0;
|
|
173567
|
+
}
|
|
173568
|
+
}
|
|
173569
|
+
var iso4 = (ms) => new Date(ms).toISOString();
|
|
173570
|
+
var minutes2 = (ms) => Math.round(ms / 6e4);
|
|
173571
|
+
async function harnessJob(dir, opts = {}) {
|
|
173572
|
+
const now = opts.now ?? Date.now;
|
|
173573
|
+
const limit = opts.limitMs ?? HARNESS_LIMIT_MS;
|
|
173574
|
+
const job = jobs.get(dir);
|
|
173575
|
+
if (job?.state === "running") {
|
|
173576
|
+
const ran = now() - job.startedAt;
|
|
173577
|
+
if (ran > limit) {
|
|
173578
|
+
job.stop();
|
|
173579
|
+
const error62 = `The harness was stopped after ${minutes2(limit)} minute${minutes2(limit) === 1 ? "" : "s"} (${job.done} of ${job.total ?? "?"} games done).`;
|
|
173580
|
+
jobs.set(dir, { state: "failed", error: error62 });
|
|
173581
|
+
return harnessJob(dir, opts);
|
|
173582
|
+
}
|
|
173583
|
+
const previous = await readSaved(dir);
|
|
173584
|
+
return { status: "running", done: job.done, total: job.total, startedAt: iso4(job.startedAt), minutesRunning: minutes2(ran), ...previous ? { previous } : {} };
|
|
173585
|
+
}
|
|
173586
|
+
if (job?.state === "failed") {
|
|
173587
|
+
if (!opts.peek) jobs.delete(dir);
|
|
173588
|
+
return { status: "failed", error: job.error };
|
|
173589
|
+
}
|
|
173590
|
+
const saved = await readSaved(dir);
|
|
173591
|
+
if (saved && !opts.rerun) return { status: "done", finishedAt: saved.finishedAt, result: saved.result };
|
|
173592
|
+
if (opts.peek) return { status: "none" };
|
|
173593
|
+
const startedAt = now();
|
|
173594
|
+
const running = { state: "running", startedAt, done: 0, total: null, stop: () => void 0 };
|
|
173595
|
+
const handle = (opts.run ?? defaultRunner())(dir, (done, total) => {
|
|
173596
|
+
running.done = done;
|
|
173597
|
+
running.total = total;
|
|
173598
|
+
});
|
|
173599
|
+
running.stop = handle.stop;
|
|
173600
|
+
jobs.set(dir, running);
|
|
173601
|
+
handle.done.then(
|
|
173602
|
+
async (result2) => {
|
|
173603
|
+
if (jobs.get(dir) !== running) return;
|
|
173604
|
+
try {
|
|
173605
|
+
await writeJsonAtomic(harnessResultPath(dir), harnessFolder(dir), { finishedAt: iso4(now()), result: result2 });
|
|
173606
|
+
jobs.delete(dir);
|
|
173607
|
+
} catch (e) {
|
|
173608
|
+
jobs.set(dir, { state: "failed", error: `The harness finished but its result could not be saved: ${messageOf2(e)}` });
|
|
173609
|
+
}
|
|
173610
|
+
},
|
|
173611
|
+
(e) => {
|
|
173612
|
+
if (jobs.get(dir) === running) jobs.set(dir, { state: "failed", error: messageOf2(e) });
|
|
173613
|
+
}
|
|
173614
|
+
);
|
|
173615
|
+
return { status: "started", startedAt: iso4(startedAt), ...saved ? { previous: saved } : {} };
|
|
173616
|
+
}
|
|
173617
|
+
var messageOf2 = (e) => (e instanceof Error ? e.message : String(e)).slice(0, 300);
|
|
173618
|
+
function workerFile(base = import.meta.url) {
|
|
173619
|
+
for (const rel of ["./calibration-worker.js", "./tools/calibration-worker.js"]) {
|
|
173620
|
+
const p = fileURLToPath2(new URL(rel, base));
|
|
173621
|
+
if (existsSync4(p)) return p;
|
|
173622
|
+
}
|
|
173623
|
+
return void 0;
|
|
173624
|
+
}
|
|
173625
|
+
function defaultRunner() {
|
|
173626
|
+
const file2 = workerFile();
|
|
173627
|
+
return file2 ? workerRunner(file2) : inProcessRunner;
|
|
173628
|
+
}
|
|
173629
|
+
function workerRunner(file2) {
|
|
173630
|
+
return (dir, onProgress) => {
|
|
173631
|
+
const worker = new Worker(file2, { workerData: { dir } });
|
|
173632
|
+
const done = new Promise((resolve6, reject) => {
|
|
173633
|
+
worker.on("message", (m) => {
|
|
173634
|
+
if (m.type === "progress") onProgress(m.done, m.total);
|
|
173635
|
+
else if (m.type === "done") resolve6(m.result);
|
|
173636
|
+
else if (m.type === "error") reject(new Error(m.message));
|
|
173637
|
+
});
|
|
173638
|
+
worker.on("error", reject);
|
|
173639
|
+
worker.on("exit", (code2) => reject(new Error(`The harness worker exited (code ${code2}) before it finished.`)));
|
|
173640
|
+
});
|
|
173641
|
+
return { done, stop: () => void worker.terminate() };
|
|
173642
|
+
};
|
|
173643
|
+
}
|
|
173644
|
+
var inProcessRunner = (dir, onProgress) => {
|
|
173645
|
+
const stop = new AbortController();
|
|
173646
|
+
return { done: calibrationHarness(dir, { progress: onProgress, signal: stop.signal }), stop: () => stop.abort(new Error("The harness was stopped.")) };
|
|
173647
|
+
};
|
|
173648
|
+
|
|
173505
173649
|
// src/tools/calibration.ts
|
|
173650
|
+
var HARNESS_WAIT_MS = 25e3;
|
|
173651
|
+
async function harnessView(dir, rerun, waitMs = HARNESS_WAIT_MS) {
|
|
173652
|
+
let view = await harnessJob(dir, { rerun });
|
|
173653
|
+
const until = Date.now() + waitMs;
|
|
173654
|
+
while ((view.status === "started" || view.status === "running") && Date.now() < until) {
|
|
173655
|
+
await new Promise((r) => setTimeout(r, Math.min(500, Math.max(0, until - Date.now()))));
|
|
173656
|
+
const peek = await harnessJob(dir, { peek: true });
|
|
173657
|
+
if (peek.status === "none") break;
|
|
173658
|
+
view = peek.status === "failed" ? await harnessJob(dir) : peek;
|
|
173659
|
+
}
|
|
173660
|
+
return view;
|
|
173661
|
+
}
|
|
173506
173662
|
var MAX_SAMPLES = 2e3;
|
|
173507
173663
|
var CALIBRATION_NOTE = "Each sample is one income estimate a planned turn worked from, against that opponent's true income (base plus full bonuses, cards and the army cap aside) on the board the turn was played on, read from the finished game's history. ratio = estimate \xF7 truth; meanError = estimate \u2212 truth in armies. Reported only: nothing plans on it. Only games whose decision log was given the end-of-game truth count (games played on builds with the decision log, finished, their history read); `method` (the tracker's, incl. rise-capped) is logged only since #569. The consequences block is a proxy: a lost territory has many causes.";
|
|
173508
173664
|
async function calibrationGames(dir) {
|
|
@@ -173541,22 +173697,23 @@ function registerCalibrationTool(server, dataDir2) {
|
|
|
173541
173697
|
{
|
|
173542
173698
|
title: "Score the income estimates against finished games",
|
|
173543
173699
|
_meta: mintMeta("lookup", ["how accurate are the income estimates", "calibrate opponent income", "estimate accuracy"]),
|
|
173544
|
-
description: `Score the opponent income estimates this server planned with against the truth its finished games kept (the decision log's end-of-game truth): each estimate \xF7 the true income, and its signed error in armies, overall and by format, seats, phase (turns 1\u20134, 5\u201310, 11+), frontier coverage band, estimate source, thin evidence, the tracker's income method (rise-capped or not; logged since #569), leader vs trailer, and phase by coverage; the catch-up lag after a true income jump of 1.5\xD7 or more (turns until the estimate reaches two thirds of the truth; only jumps on a planned turn, the rest counted as unwatched); a consequences proxy (turns that lost a territory the plan did not concede, with an estimate under half the truth vs without); the largest misses; each pipeline stage's figure \xF7 the truth (visible, observed, tracked, prior, stated, blend, thin, known; logged since #568); for each estimate under two thirds of the truth, the tracker step that held it (rise cap, tripwire, window, could-earn ceiling, ambiguous armies, readings, a later stage, or no track; logged since #586); and what correcting the tracked figure by its coverage band would have read at dampings 0 to 1 (leave one game out). \`samples: true\` adds the scored rows (at most ${MAX_SAMPLES}), name-free, as a fixture set; \`harness: true\`
|
|
173700
|
+
description: `Score the opponent income estimates this server planned with against the truth its finished games kept (the decision log's end-of-game truth): each estimate \xF7 the true income, and its signed error in armies, overall and by format, seats, phase (turns 1\u20134, 5\u201310, 11+), frontier coverage band, estimate source, thin evidence, the tracker's income method (rise-capped or not; logged since #569), leader vs trailer, and phase by coverage; the catch-up lag after a true income jump of 1.5\xD7 or more (turns until the estimate reaches two thirds of the truth; only jumps on a planned turn, the rest counted as unwatched); a consequences proxy (turns that lost a territory the plan did not concede, with an estimate under half the truth vs without); the largest misses; each pipeline stage's figure \xF7 the truth (visible, observed, tracked, prior, stated, blend, thin, known; logged since #568); for each estimate under two thirds of the truth, the tracker step that held it (rise cap, tripwire, window, could-earn ceiling, ambiguous armies, readings, a later stage, or no track; logged since #586); and what correcting the tracked figure by its coverage band would have read at dampings 0 to 1 (leave one game out). \`samples: true\` adds the scored rows (at most ${MAX_SAMPLES}), name-free, as a fixture set; \`harness: true\` adds the #318 harness over the cached boards (tracker, fog prior and plan estimate by coverage band, and the opening benchmark): it runs in the background, since it can take most of an hour on many games, so the first call starts it and later calls say \`running\` (games done of total) until it is \`done\`; the result is kept, so a later call returns it at once (\`rerun: true\` starts a fresh run). Games are numbered by their place in the report, never by id, and no player is named. Makes no war.app request; writes only the harness result, in this server's own data. Read-only.`,
|
|
173545
173701
|
annotations: toolAnnotations({ title: "Income estimate calibration", readOnly: true, destructive: false, idempotent: true, openWorld: false }),
|
|
173546
173702
|
inputSchema: external_exports.object({
|
|
173547
173703
|
samples: external_exports.boolean().optional().describe(`Also return the scored rows, name-free (default false; at most ${MAX_SAMPLES}).`),
|
|
173548
|
-
harness: external_exports.boolean().optional().describe("Also
|
|
173704
|
+
harness: external_exports.boolean().optional().describe("Also the #318 harness over the cached boards and the opening benchmark (default false): started in the background on the first call; call again until its status is `done`."),
|
|
173705
|
+
rerun: external_exports.boolean().optional().describe("With `harness`, start a fresh harness run over a kept result (default false)."),
|
|
173549
173706
|
format: external_exports.enum(["1v1", "ffa", "team"]).optional().describe("Only games of this format.")
|
|
173550
173707
|
})
|
|
173551
173708
|
},
|
|
173552
|
-
async ({ samples, harness, format }) => {
|
|
173709
|
+
async ({ samples, harness, rerun, format }) => {
|
|
173553
173710
|
const dir = dataDir2();
|
|
173554
173711
|
if (!dir) refuse("This server has no data directory, so there is nothing to score.", "Nothing to do here.");
|
|
173555
173712
|
const src = await calibrationGames(dir);
|
|
173556
173713
|
const games = format ? src.games.filter((g) => g.format === format) : src.games;
|
|
173557
173714
|
const report2 = incomeCalibration(games);
|
|
173558
173715
|
const rows = samples ? incomeSamples(games) : [];
|
|
173559
|
-
const
|
|
173716
|
+
const job = harness ? await harnessView(dir, rerun === true) : void 0;
|
|
173560
173717
|
return respond(void 0, ["compact"], () => ({
|
|
173561
173718
|
readAs: CALIBRATION_NOTE,
|
|
173562
173719
|
sources: {
|
|
@@ -173571,11 +173728,28 @@ function registerCalibrationTool(server, dataDir2) {
|
|
|
173571
173728
|
empty: "No finished game with the end-of-game truth in its decision log yet: the truth is written when a finished game's history is read (warapp_backfill_history, warapp_my_games' sweep, warapp_get_game on it)."
|
|
173572
173729
|
},
|
|
173573
173730
|
...samples ? { samples: rows.slice(0, MAX_SAMPLES), ...rows.length > MAX_SAMPLES ? { samplesLeftOut: rows.length - MAX_SAMPLES } : {} } : {},
|
|
173574
|
-
...
|
|
173731
|
+
...job ? { harness: harnessOut(job) } : {}
|
|
173575
173732
|
}));
|
|
173576
173733
|
}
|
|
173577
173734
|
);
|
|
173578
173735
|
}
|
|
173736
|
+
function harnessOut(job) {
|
|
173737
|
+
switch (job.status) {
|
|
173738
|
+
case "done":
|
|
173739
|
+
return { status: "done", finishedAt: job.finishedAt, ...job.result, approximations: HARNESS_APPROXIMATIONS, note: "A kept result: `rerun: true` starts a fresh run." };
|
|
173740
|
+
case "failed":
|
|
173741
|
+
return { status: "failed", error: job.error, note: "Call again with `harness: true` to start a fresh run." };
|
|
173742
|
+
case "started":
|
|
173743
|
+
case "running":
|
|
173744
|
+
return {
|
|
173745
|
+
...job,
|
|
173746
|
+
...job.previous ? { previous: { finishedAt: job.previous.finishedAt, ...job.previous.result, approximations: HARNESS_APPROXIMATIONS } } : {},
|
|
173747
|
+
note: "The harness runs in the background: call warapp_calibration with `harness: true` again in a few minutes for its progress, then its result."
|
|
173748
|
+
};
|
|
173749
|
+
default:
|
|
173750
|
+
return job;
|
|
173751
|
+
}
|
|
173752
|
+
}
|
|
173579
173753
|
|
|
173580
173754
|
// src/tools/turn-history.ts
|
|
173581
173755
|
var MAX_HISTORY_TURNS = 20;
|
|
@@ -23,14 +23,18 @@ export const HARNESS_APPROXIMATIONS = [
|
|
|
23
23
|
'the history boards: no capture, no failed attack, no orders cached; army growth alone is not orders) or a boot of my seat in turns',
|
|
24
24
|
'1-4 is reported apart, never averaged in.',
|
|
25
25
|
];
|
|
26
|
-
/**
|
|
26
|
+
/** Lets the event loop run between games, so a progress notification or a cancellation gets through. */
|
|
27
|
+
const yieldToLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
28
|
+
/** Run the harness over `dir`. Never requests. */
|
|
27
29
|
export async function calibrationHarness(dir, opts = {}) {
|
|
28
30
|
const src = await calibrationSources(dir);
|
|
29
31
|
const counts = { histories: src.statuses, skipped: src.skipped, scored: 0, recordOnly: 0, benchmarked: 0, samples: 0 };
|
|
30
32
|
const byFormat = {};
|
|
31
33
|
const benchByFormat = {};
|
|
32
34
|
const eraEntries = [];
|
|
35
|
+
let done = 0;
|
|
33
36
|
for (const input of src.inputs) {
|
|
37
|
+
opts.signal?.throwIfAborted();
|
|
34
38
|
const { history: h, settings, map, cached } = input;
|
|
35
39
|
if (input.source === 'record-only')
|
|
36
40
|
counts.recordOnly++;
|
|
@@ -88,7 +92,10 @@ export async function calibrationHarness(dir, opts = {}) {
|
|
|
88
92
|
});
|
|
89
93
|
eraEntries.push({ era, basis, format, territories: graph.territoryById.size, flags, bench });
|
|
90
94
|
}
|
|
95
|
+
opts.progress?.(++done, src.inputs.length);
|
|
96
|
+
await yieldToLoop();
|
|
91
97
|
}
|
|
98
|
+
opts.signal?.throwIfAborted();
|
|
92
99
|
const calibration = {};
|
|
93
100
|
for (const [format, ests] of Object.entries(byFormat))
|
|
94
101
|
for (const [k, c] of Object.entries(ests))
|