fix(viewer): silence routine plan updates and trim stale metadata
This commit is contained in:
parent
1b6f1f3566
commit
a8ace70a2e
7 changed files with 194 additions and 180 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/old-ui",
|
||||
"version": "1.2.21",
|
||||
"version": "1.2.22",
|
||||
"scripts": {
|
||||
"serve": "vite --port 5193",
|
||||
"build": "vite build",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/viewer",
|
||||
"version": "5.22.21",
|
||||
"version": "5.22.22",
|
||||
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
|
||||
"contributors": [
|
||||
"coyotte508",
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ describe("AnalysisPanel", () => {
|
|||
const pendingRestore = {
|
||||
lines: [[{ kind: "move", move: "terrans up nav." }]],
|
||||
active: 0,
|
||||
baseRound: 1,
|
||||
baseMoveCount: 9,
|
||||
};
|
||||
const { container, emitted } = render(AnalysisPanel, { props: { active: true, pendingRestore } });
|
||||
|
|
@ -65,7 +64,6 @@ describe("AnalysisPanel", () => {
|
|||
const pendingRestore = {
|
||||
lines: [[{ kind: "move", move: "terrans up nav." }], [{ kind: "move", move: "terrans up gaia." }], []],
|
||||
active: 1,
|
||||
baseRound: 1,
|
||||
baseMoveCount: 9,
|
||||
};
|
||||
const { container } = render(AnalysisPanel, { props: { active: true, pendingRestore } });
|
||||
|
|
@ -78,7 +76,6 @@ describe("AnalysisPanel", () => {
|
|||
const pendingRestore = {
|
||||
lines: [[{ kind: "move", move: "terrans up nav." }]],
|
||||
active: 0,
|
||||
baseRound: 1,
|
||||
baseMoveCount: 9,
|
||||
};
|
||||
const { container } = render(AnalysisPanel, { props: { active: false, pendingRestore } });
|
||||
|
|
|
|||
|
|
@ -933,7 +933,6 @@ describe("Game", () => {
|
|||
|
||||
expect(vm.analysisRolledForward).to.equal(true);
|
||||
expect(vm.engine.round).to.equal(2);
|
||||
expect(vm.analysisBaseRound).to.equal(2);
|
||||
expect(vm.engine.playerToMove).to.equal(0);
|
||||
|
||||
vm.applyAnalysisMove("terrans up nav.");
|
||||
|
|
@ -962,7 +961,6 @@ describe("Game", () => {
|
|||
expect(vm.analysisMode).to.equal(true);
|
||||
expect(vm.analysisRolledForward).to.equal(true);
|
||||
expect(vm.engine.round).to.equal(2);
|
||||
expect(vm.analysisBaseRound).to.equal(2);
|
||||
expect(vm.engine.playerToMove).to.equal(2);
|
||||
expect(vm.analysisEntries).to.deep.equal([{ kind: "move", move: "firaks up nav." }]);
|
||||
expect(vm.analysisCommitPlan.live).to.equal(null);
|
||||
|
|
@ -1476,7 +1474,7 @@ describe("Game", () => {
|
|||
// terrans still owes their own booster pick - the last setup move before round 1.
|
||||
const vm = mountAsSeat(0, new Engine(SETUP_MOVES.slice(0, -1)));
|
||||
vm.enterAnalysisMode();
|
||||
expect(vm.analysisBaseRound).to.equal(1); // §3.7 - "setup gives you setup plus round 1"
|
||||
expect(vm.engine.phase).to.equal(Phase.SetupBooster);
|
||||
|
||||
vm.applyAnalysisMove("terrans booster booster3");
|
||||
|
||||
|
|
@ -1969,6 +1967,32 @@ describe("Game", () => {
|
|||
});
|
||||
|
||||
describe("Phase 6 - staleness on re-entry (§3.5)", () => {
|
||||
it("restores a pre-tabs draft and saves it without obsolete round metadata", () => {
|
||||
const live = new Engine(SETUP_MOVES);
|
||||
const entries = [{ kind: "move", move: "terrans up nav." }];
|
||||
window.localStorage.setItem(
|
||||
"analysis-mode::0",
|
||||
JSON.stringify({ entries, baseRound: 1, baseMoveCount: live.moveHistory.length })
|
||||
);
|
||||
const vm = mountAsSeat(0, live);
|
||||
vm.enterAnalysisMode();
|
||||
expect(vm.analysisEntries).to.deep.equal(entries);
|
||||
expect(vm.analysisAppliedCount).to.equal(1);
|
||||
expect(JSON.parse(window.localStorage.getItem("analysis-mode::0"))).to.deep.equal({
|
||||
lines: [entries],
|
||||
played: [[]],
|
||||
active: 0,
|
||||
baseMoveCount: live.moveHistory.length,
|
||||
baseMove: live.moveHistory[live.moveHistory.length - 1],
|
||||
});
|
||||
vm.exitAnalysisMode();
|
||||
vm.enterAnalysisMode();
|
||||
expect(vm.analysisEntries).to.deep.equal(entries);
|
||||
expect(vm.analysisAppliedCount).to.equal(1);
|
||||
vm.$el.remove();
|
||||
vm.$destroy();
|
||||
});
|
||||
|
||||
it("repairs an already-saved blocked income and keeps the Gaia conversion in played history", () => {
|
||||
const live = new Engine(SETUP_MOVES);
|
||||
const pass = "terrans pass booster2 returning booster7";
|
||||
|
|
@ -2031,7 +2055,10 @@ describe("Game", () => {
|
|||
]);
|
||||
const saved = JSON.parse(window.localStorage.getItem("analysis-mode::0"));
|
||||
expect(saved.lines).to.deep.equal([[nav]]);
|
||||
expect(saved.played[0]).to.have.length(2);
|
||||
expect(saved.played).to.deep.equal(vm.analysisPlayed);
|
||||
expect(saved.baseMoveCount).to.equal(live.moveHistory.length);
|
||||
expect(saved.baseMove).to.equal(live.moveHistory[live.moveHistory.length - 1]);
|
||||
expect(saved).not.to.have.property("baseRound");
|
||||
vm.$el.remove();
|
||||
vm.$destroy();
|
||||
}
|
||||
|
|
@ -2068,7 +2095,7 @@ describe("Game", () => {
|
|||
second.$destroy();
|
||||
});
|
||||
|
||||
it("auto-replays a stored line and shows a notice when only opponents moved since it was saved", () => {
|
||||
it("silently auto-replays a stored line when only opponents moved since it was saved", async () => {
|
||||
const first = mountAsSeat(0);
|
||||
first.enterAnalysisMode();
|
||||
first.applyAnalysisMove("terrans up nav.");
|
||||
|
|
@ -2088,7 +2115,9 @@ describe("Game", () => {
|
|||
|
||||
expect(second.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans up nav." }]);
|
||||
expect(second.analysisPendingRestore).to.equal(null);
|
||||
expect(second.analysisNotice).to.contain("board changed");
|
||||
expect(second.analysisNotice).to.equal(null);
|
||||
await second.$nextTick();
|
||||
expect(second.$el.querySelector(".analysis-strip")).to.equal(null);
|
||||
|
||||
second.$el.remove();
|
||||
second.$destroy();
|
||||
|
|
@ -2196,14 +2225,14 @@ describe("Game", () => {
|
|||
|
||||
const liveEngine = new Engine(SETUP_MOVES);
|
||||
liveEngine.moveHistory.push("nevlas up nav (0 ⇒ 1).");
|
||||
liveEngine.round = 3; // baseRound was 1, so round > baseRound + 1 - the window has moved on
|
||||
liveEngine.round = 3; // Plans do not expire when the live game advances.
|
||||
|
||||
const second = mountAsSeat(0, liveEngine);
|
||||
second.enterAnalysisMode();
|
||||
|
||||
expect(second.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans up nav." }]);
|
||||
expect(second.analysisPendingRestore).to.equal(null);
|
||||
expect(second.analysisNotice).to.contain("board changed");
|
||||
expect(second.analysisNotice).to.equal(null);
|
||||
|
||||
second.$el.remove();
|
||||
second.$destroy();
|
||||
|
|
@ -2236,7 +2265,7 @@ describe("Game", () => {
|
|||
vm.$destroy();
|
||||
});
|
||||
|
||||
it("trims a matching manual move without closing planning, and persists the remainder", () => {
|
||||
it("silently trims a matching manual move without closing planning, and persists the remainder", async () => {
|
||||
const vm = mountAsSeat(0, researchGame());
|
||||
vm.enterAnalysisMode();
|
||||
vm.applyAnalysisMove("terrans up nav.");
|
||||
|
|
@ -2245,6 +2274,9 @@ describe("Game", () => {
|
|||
vm.$store.dispatch("externalData", arrived);
|
||||
expect(vm.analysisMode).to.equal(true);
|
||||
expect(vm.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans up gaia." }]);
|
||||
expect(vm.analysisNotice).to.equal(null);
|
||||
await vm.$nextTick();
|
||||
expect(vm.$el.querySelector(".analysis-strip")).to.equal(null);
|
||||
vm.$el.remove();
|
||||
vm.$destroy();
|
||||
const second = mountAsSeat(0, Engine.fromData(JSON.parse(JSON.stringify(arrived))));
|
||||
|
|
@ -2254,7 +2286,7 @@ describe("Game", () => {
|
|||
second.$destroy();
|
||||
});
|
||||
|
||||
it("keeps the sandbox OPEN and re-bases the line when an opponent moves - their turn does not invalidate it", () => {
|
||||
it("silently keeps the sandbox open and re-bases the line when an opponent moves", async () => {
|
||||
// The reported bug: any incoming move closed sandbox mode, so a line was treated as dead
|
||||
// because somebody built on the far side of the map.
|
||||
const vm = mountAsSeat(0);
|
||||
|
|
@ -2270,7 +2302,9 @@ describe("Game", () => {
|
|||
expect(vm.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans up nav." }]);
|
||||
// Re-anchored onto the new history, so the stored line is not stale next time either.
|
||||
expect(vm.analysisBaseMoveCount).to.equal(baseBefore + 1);
|
||||
expect(vm.analysisNotice).to.contain("plans were updated");
|
||||
expect(vm.analysisNotice).to.equal(null);
|
||||
await vm.$nextTick();
|
||||
expect(vm.$el.querySelector(".analysis-strip")).to.equal(null);
|
||||
// Exiting now restores the NEW real board, not the one from before the opponent moved.
|
||||
vm.exitAnalysisMode();
|
||||
expect(vm.engine.moveHistory.length).to.equal(arrived.moveHistory.length);
|
||||
|
|
@ -2333,7 +2367,7 @@ describe("Game", () => {
|
|||
expect(second.analysisPendingRestore).to.equal(null);
|
||||
|
||||
expect(second.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans up nav." }]);
|
||||
expect(second.analysisNotice).to.contain("already played");
|
||||
expect(second.analysisNotice).to.equal(null);
|
||||
expect(second.analysisPlayed[0]).to.have.length(1);
|
||||
const recorded = JSON.parse(JSON.stringify(second.analysisPlayed));
|
||||
second.exitAnalysisMode();
|
||||
|
|
@ -2379,7 +2413,7 @@ describe("Game", () => {
|
|||
second.restoreAnalysisLine();
|
||||
|
||||
expect(second.analysisEntries).to.deep.equal([{ kind: "move", move: "terrans build m 2A3." }]);
|
||||
expect(second.analysisNotice).to.contain("board changed");
|
||||
expect(second.analysisNotice).to.contain("no longer apply");
|
||||
second.$el.remove();
|
||||
second.$destroy();
|
||||
});
|
||||
|
|
@ -2411,7 +2445,7 @@ describe("Game", () => {
|
|||
|
||||
const arrived = JSON.parse(JSON.stringify(vm.analysisBackup));
|
||||
arrived.moveHistory = [...arrived.moveHistory, "nevlas up nav."];
|
||||
arrived.round = 3; // baseRound was 1 - no amount of re-basing brings that window back
|
||||
arrived.round = 3; // Plans do not expire when the live game advances.
|
||||
vm.$store.dispatch("externalData", arrived);
|
||||
|
||||
expect(vm.analysisMode).to.equal(true);
|
||||
|
|
|
|||
|
|
@ -369,7 +369,6 @@ import Engine, {
|
|||
Phase,
|
||||
Player,
|
||||
ResearchField,
|
||||
Round,
|
||||
} from "@gaia-project/engine";
|
||||
import { chargeDecisionSeats, hasConcurrentCharges } from "@gaia-project/engine/src/pending-charges";
|
||||
import type { PremoveCommand, PremovePlan, PremoveRun, PremoveTiming } from "@gaia-project/engine/src/premove-types";
|
||||
|
|
@ -510,7 +509,6 @@ export default class Game extends Vue {
|
|||
analysisOrigin: Engine = null;
|
||||
analysisComposeBase: Engine = null;
|
||||
analysisSeat: number = null;
|
||||
analysisBaseRound: number = null;
|
||||
analysisBaseMoveCount: number = null;
|
||||
// The REAL move history the origin was cloned from. Not `analysisOrigin.moveHistory`, which is a
|
||||
// different list: `settleAnalysisClone`/`advancePastOwnPass` play opponents' declines
|
||||
|
|
@ -520,8 +518,8 @@ export default class Game extends Vue {
|
|||
// `reanchorAnalysisLine`, which compares against this instead.
|
||||
analysisRealHistory: string[] = [];
|
||||
// §13's lines. Every line is rooted at the same `analysisOrigin` (that is what makes switching
|
||||
// between them a replay rather than a second board takeover), so `analysisBaseRound`/
|
||||
// `analysisBaseMoveCount` above stay session-wide rather than becoming per-line - and staleness
|
||||
// between them a replay rather than a second board takeover), so `analysisBaseMoveCount` above
|
||||
// stays session-wide rather than becoming per-line - and staleness
|
||||
// (§3.5) stays one decision for the whole set. There is always at least one line, from the moment
|
||||
// the sandbox opens: Line 1 is not something the player has to create, and there is no Save button
|
||||
// because every line already persists on every completed turn (see `setAnalysisEntries`).
|
||||
|
|
@ -1078,7 +1076,6 @@ export default class Game extends Vue {
|
|||
origin,
|
||||
this.myPremovePlan.moves.map((move) => ({ kind: "move", move })),
|
||||
seat,
|
||||
origin.round,
|
||||
costs
|
||||
);
|
||||
return costs;
|
||||
|
|
@ -1232,7 +1229,6 @@ export default class Game extends Vue {
|
|||
this.analysisOrigin,
|
||||
entries,
|
||||
this.analysisSeat,
|
||||
this.analysisBaseRound,
|
||||
this.premoveAvailable ? (this.analysisSeatIsOnTurnForReal ? 1 : 0) : Infinity
|
||||
);
|
||||
const plan = planAnalysisCommit({
|
||||
|
|
@ -1249,14 +1245,13 @@ export default class Game extends Vue {
|
|||
const { engine } = replayAnalysisLine(
|
||||
this.analysisOrigin,
|
||||
entries.slice(0, entries.indexOf(moveEntries[index])),
|
||||
this.analysisSeat,
|
||||
this.analysisBaseRound
|
||||
this.analysisSeat
|
||||
);
|
||||
return { round: engine.round, phase: engine.phase };
|
||||
});
|
||||
}
|
||||
plan.costs = [];
|
||||
replayAnalysisLine(this.analysisOrigin, entries, this.analysisSeat, this.analysisBaseRound, plan.costs);
|
||||
replayAnalysisLine(this.analysisOrigin, entries, this.analysisSeat, plan.costs);
|
||||
return plan;
|
||||
}
|
||||
|
||||
|
|
@ -1322,9 +1317,6 @@ export default class Game extends Vue {
|
|||
// leech answer (the state a live async game spends most of its time in) used to open a sandbox
|
||||
// with no commands for this seat at all and no way to play anything.
|
||||
settleAnalysisClone(this.analysisOrigin, seat);
|
||||
// Read the first playable round from the settled clone, including when entry rolls past
|
||||
// our own pass. Setup itself is not a playable round.
|
||||
this.analysisBaseRound = Math.max(this.analysisOrigin.round, Round.Round1);
|
||||
// Sealed-bid auctions (§2.7) - null the real backend for the duration, so a Preference Split/
|
||||
// Silent bid phase submits an ordinary local move instead of going through the server; restored
|
||||
// on exit. `analysisMode` (store state, not just this component) is what SealedBidPanel.ts's
|
||||
|
|
@ -1367,7 +1359,6 @@ export default class Game extends Vue {
|
|||
}
|
||||
const incoming = markAnalysisSeat(Engine.fromData(JSON.parse(JSON.stringify(payload))), seat);
|
||||
const newMoves = incomingHistory.slice(originHistory.length);
|
||||
let played = 0;
|
||||
this.analysisLines = this.analysisLines.map((entries, index) => {
|
||||
const result = dropPlayedAnalysisPrefix(
|
||||
incoming,
|
||||
|
|
@ -1378,7 +1369,6 @@ export default class Game extends Vue {
|
|||
this.analysisPlayed[index]
|
||||
);
|
||||
this.$set(this.analysisPlayed, index, [...(this.analysisPlayed[index] ?? []), ...result.played]);
|
||||
played = Math.max(played, result.dropped);
|
||||
return result.entries;
|
||||
});
|
||||
const ownMove = ownMoveCount(incoming, newMoves, seat) > 0;
|
||||
|
|
@ -1411,14 +1401,9 @@ export default class Game extends Vue {
|
|||
this.analysisPendingCharge = pendingCharge;
|
||||
if (draft) this.applyAnalysisMove(draft);
|
||||
this.analysisNotice =
|
||||
played > 0
|
||||
? `${played} already played ${played === 1 ? "move" : "moves"} kept in plan history.`
|
||||
: entries.length > 0
|
||||
? "The board changed. Your plans were updated."
|
||||
: null;
|
||||
if (applied < entries.length) {
|
||||
this.analysisNotice = "The board changed. Some planned moves no longer apply; they are kept for you to edit.";
|
||||
}
|
||||
applied < entries.length
|
||||
? "The board changed. Some planned moves no longer apply; they are kept for you to edit."
|
||||
: null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1426,7 +1411,7 @@ export default class Game extends Vue {
|
|||
* Only a rollback/divergence needs an explicit restore; ordinary progress is automatic. */
|
||||
private resolveAnalysisStaleness(seat: number, stored: AnalysisLineSet | null) {
|
||||
const fresh = (options: { persist?: boolean } = {}) =>
|
||||
this.setAnalysisLineSet(emptyAnalysisLineSet(this.analysisBaseRound, this.analysisBaseMoveCount), options);
|
||||
this.setAnalysisLineSet(emptyAnalysisLineSet(this.analysisBaseMoveCount), options);
|
||||
if (!stored) {
|
||||
fresh();
|
||||
return;
|
||||
|
|
@ -1458,14 +1443,10 @@ export default class Game extends Vue {
|
|||
});
|
||||
const active = lines[normalizeAnalysisLineSet(stored).active] ?? [];
|
||||
const applied = this.setAnalysisLineSet({ ...stored, lines, played: histories }, { prune: false });
|
||||
if (sameBase && played === 0) return;
|
||||
this.analysisNotice =
|
||||
played > 0
|
||||
? `${played} already played ${played === 1 ? "move" : "moves"} kept in plan history.`
|
||||
: "The board changed. Your plans were updated.";
|
||||
if (applied < active.length) {
|
||||
this.analysisNotice = "The board changed. Some planned moves no longer apply; they are kept for you to edit.";
|
||||
}
|
||||
(!sameBase || played > 0) && applied < active.length
|
||||
? "The board changed. Some planned moves no longer apply; they are kept for you to edit."
|
||||
: null;
|
||||
}
|
||||
|
||||
/** A divergent history cannot prove which moves were played. Restore without deleting any. */
|
||||
|
|
@ -1711,8 +1692,7 @@ export default class Game extends Vue {
|
|||
const { engine, applied, blockedReason } = replayAnalysisLine(
|
||||
this.analysisOrigin,
|
||||
this.analysisEntries.slice(0, index),
|
||||
this.analysisSeat,
|
||||
this.analysisBaseRound
|
||||
this.analysisSeat
|
||||
);
|
||||
if (applied !== index || !engine.newTurn || engine.ended) return;
|
||||
this.analysisEdit = {
|
||||
|
|
@ -1828,7 +1808,6 @@ export default class Game extends Vue {
|
|||
this.analysisOrigin,
|
||||
entries,
|
||||
this.analysisSeat,
|
||||
this.analysisBaseRound,
|
||||
costs
|
||||
);
|
||||
const kept = options.prune === false ? entries : entries.slice(0, applied);
|
||||
|
|
@ -1878,7 +1857,6 @@ export default class Game extends Vue {
|
|||
lines: this.analysisLines,
|
||||
played: this.analysisPlayed,
|
||||
active: this.analysisActiveLine,
|
||||
baseRound: this.analysisBaseRound,
|
||||
baseMoveCount: this.analysisBaseMoveCount,
|
||||
baseMove: this.analysisRealHistory[this.analysisBaseMoveCount - 1],
|
||||
},
|
||||
|
|
@ -1909,13 +1887,7 @@ export default class Game extends Vue {
|
|||
if (hit) {
|
||||
return hit;
|
||||
}
|
||||
const summary = summarizeAnalysisLine(
|
||||
this.analysisOrigin,
|
||||
entries,
|
||||
this.analysisSeat,
|
||||
this.analysisBaseRound,
|
||||
index
|
||||
);
|
||||
const summary = summarizeAnalysisLine(this.analysisOrigin, entries, this.analysisSeat, index);
|
||||
cache.set(key, summary);
|
||||
return summary;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Engine, {
|
|||
} from "@gaia-project/engine";
|
||||
import { expect } from "chai";
|
||||
import { passedChargeGame } from "../testing/passed-charge";
|
||||
import type { AnalysisEntry, MoveCost } from "./analysis";
|
||||
import type { AnalysisEntry, AnalysisLineSet, MoveCost } from "./analysis";
|
||||
import {
|
||||
advancePastOwnPass,
|
||||
analysisCommitPrefix,
|
||||
|
|
@ -81,8 +81,7 @@ describe("replayAnalysisLine", () => {
|
|||
const { engine, applied, blockedReason } = replayAnalysisLine(
|
||||
planning,
|
||||
[{ kind: "move", move: `hadsch-hallas pass ${booster}` }],
|
||||
0,
|
||||
1
|
||||
0
|
||||
);
|
||||
expect(blockedReason).to.equal(undefined);
|
||||
expect(applied).to.equal(1);
|
||||
|
|
@ -100,7 +99,7 @@ describe("replayAnalysisLine", () => {
|
|||
it("reports spending without subtracting the resources earned by the same move", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const costs: MoveCost[] = [];
|
||||
replayAnalysisLine(origin, [{ kind: "move", move: "terrans spend 1q for 1o. up sci." }], 0, 1, costs);
|
||||
replayAnalysisLine(origin, [{ kind: "move", move: "terrans spend 1q for 1o. up sci." }], 0, costs);
|
||||
expect(costs).to.deep.equal([
|
||||
[
|
||||
{ type: Resource.Qic, count: 1 },
|
||||
|
|
@ -113,7 +112,7 @@ describe("replayAnalysisLine", () => {
|
|||
it("replays a legal line onto a fresh clone of the origin", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans up nav." }];
|
||||
const { engine, applied, blockedReason } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { engine, applied, blockedReason } = replayAnalysisLine(origin, entries, 0);
|
||||
expect(blockedReason).to.equal(undefined);
|
||||
expect(applied).to.equal(1);
|
||||
expect(engine.moveHistory[engine.moveHistory.length - 1]).to.equal("terrans up nav (0 ⇒ 1).");
|
||||
|
|
@ -129,8 +128,7 @@ describe("replayAnalysisLine", () => {
|
|||
{ kind: "move", move: "terrans action power3." },
|
||||
{ kind: "move", move: "terrans action power4." },
|
||||
],
|
||||
0,
|
||||
1
|
||||
0
|
||||
);
|
||||
expect(applied).to.equal(1);
|
||||
expect(engine.players[0].data.power.area3).to.equal(0);
|
||||
|
|
@ -144,7 +142,7 @@ describe("replayAnalysisLine", () => {
|
|||
{ kind: "move", move: "terrans build m 99x99." },
|
||||
{ kind: "move", move: "nevlas up nav." },
|
||||
];
|
||||
const { engine, applied, blockedReason } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { engine, applied, blockedReason } = replayAnalysisLine(origin, entries, 0);
|
||||
expect(blockedReason).to.be.a("string").and.not.equal("");
|
||||
expect(applied).to.equal(1);
|
||||
expect(engine.moveHistory[engine.moveHistory.length - 1]).to.equal("terrans up nav (0 ⇒ 1).");
|
||||
|
|
@ -156,13 +154,7 @@ describe("replayAnalysisLine", () => {
|
|||
origin.clearAvailableCommands();
|
||||
const before = JSON.stringify(origin);
|
||||
const costs: MoveCost[] = [];
|
||||
const { engine, applied } = replayAnalysisLine(
|
||||
origin,
|
||||
[{ kind: "move", move: "terrans build m 0x2." }],
|
||||
0,
|
||||
1,
|
||||
costs
|
||||
);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans build m 0x2." }], 0, costs);
|
||||
expect(applied).to.equal(1);
|
||||
expect(costs[0].filter((cost) => cost.type === Resource.GaiaFormer)).to.deep.equal([
|
||||
{ type: Resource.GaiaFormer, count: 1 },
|
||||
|
|
@ -175,20 +167,20 @@ describe("replayAnalysisLine", () => {
|
|||
it("leaves the original engine untouched", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const before = JSON.stringify(origin);
|
||||
replayAnalysisLine(origin, [{ kind: "move", move: "terrans up nav." }], 0, 1);
|
||||
replayAnalysisLine(origin, [{ kind: "move", move: "terrans up nav." }], 0);
|
||||
expect(JSON.stringify(origin)).to.equal(before);
|
||||
});
|
||||
|
||||
it("returns the origin itself, unmodified, for an empty line", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [], 0, 1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [], 0);
|
||||
expect(applied).to.equal(0);
|
||||
expect(engine.moveHistory).to.deep.equal(origin.moveHistory);
|
||||
});
|
||||
|
||||
it("marks the seat's player data as the sandbox seat on the replayed engine", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const { engine } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans up nav." }], 0, 1);
|
||||
const { engine } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans up nav." }], 0);
|
||||
expect(engine.players[0].data.analysis).to.equal(true);
|
||||
});
|
||||
|
||||
|
|
@ -198,7 +190,7 @@ describe("replayAnalysisLine", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans booster booster3" }]; // last setup move
|
||||
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(engine.phase).to.equal(Phase.RoundMove);
|
||||
expect(engine.round).to.equal(1);
|
||||
|
|
@ -214,8 +206,8 @@ describe("replayAnalysisLine", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans booster booster3" }];
|
||||
|
||||
const first = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const second = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const first = replayAnalysisLine(origin, entries, 0);
|
||||
const second = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(second.engine.players[0].data.credits).to.equal(first.engine.players[0].data.credits);
|
||||
});
|
||||
|
|
@ -226,7 +218,7 @@ describe("replayAnalysisLine", () => {
|
|||
origin.player(0).data.credits = 0;
|
||||
origin.player(0).data.ores = 0; // cannot afford a trading station at all
|
||||
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0, 1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0);
|
||||
|
||||
expect(applied).to.equal(0);
|
||||
const data = engine.players[0].data;
|
||||
|
|
@ -238,7 +230,7 @@ describe("replayAnalysisLine", () => {
|
|||
const origin = new Engine(SETUP_MOVES);
|
||||
applySoloRoundFlow(origin, 0);
|
||||
Object.assign(origin.player(0).data.power, { area1: 0, area2: 0, area3: 0 });
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans action power3." }], 0, 1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans action power3." }], 0);
|
||||
expect(applied).to.equal(0);
|
||||
expect(engine.players[0].data.power).to.deep.equal(origin.players[0].data.power);
|
||||
expect(engine.players[0].data.analysisAssumedPower).to.equal(0);
|
||||
|
|
@ -252,7 +244,7 @@ describe("replayAnalysisLine", () => {
|
|||
const before = { ...origin.players[0].data.power };
|
||||
const entries: AnalysisEntry[] = [{ kind: "adjust", charge: 2 }];
|
||||
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(1);
|
||||
// chargePower moves tokens up a level - the receiving areas grow by the charge regardless of
|
||||
|
|
@ -270,7 +262,7 @@ describe("replayAnalysisLine", () => {
|
|||
{ kind: "move", move: "terrans up nav." },
|
||||
];
|
||||
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(0);
|
||||
});
|
||||
|
|
@ -283,7 +275,7 @@ describe("replayAnalysisLine", () => {
|
|||
{ kind: "adjust", charge: 3 },
|
||||
];
|
||||
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0, 1);
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(2);
|
||||
});
|
||||
|
|
@ -679,7 +671,7 @@ describe("resolveOpponentDecisions", () => {
|
|||
const origin = new Engine(SETUP_MOVES);
|
||||
applySoloRoundFlow(origin, 0);
|
||||
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0, 1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0);
|
||||
|
||||
expect(applied).to.equal(1);
|
||||
expect(engine.phase).to.equal(Phase.RoundMove);
|
||||
|
|
@ -726,8 +718,7 @@ describe("opponents' setup turns in planning", () => {
|
|||
const { engine: result, applied } = replayAnalysisLine(
|
||||
engine,
|
||||
[{ kind: "move", move: "nevlas booster booster7" }],
|
||||
1,
|
||||
Round.Round1
|
||||
1
|
||||
);
|
||||
expect(applied).to.equal(1);
|
||||
expect(result.phase).to.equal(Phase.RoundMove);
|
||||
|
|
@ -951,21 +942,63 @@ describe("analysis line persistence", () => {
|
|||
});
|
||||
|
||||
it("round-trips a saved set for the same seat", () => {
|
||||
const set = { lines: [[up], []], active: 1, baseRound: 1, baseMoveCount: 9 };
|
||||
const set = { lines: [[up], []], active: 1, baseMoveCount: 9 };
|
||||
saveAnalysisLines(0, set);
|
||||
expect(loadAnalysisLines(0)).to.deep.equal(set);
|
||||
});
|
||||
|
||||
it("drops obsolete metadata from stored multi-plan drafts while retaining the base move and played history", () => {
|
||||
const key = `analysis-mode:${window.location.search}:0`;
|
||||
const set: AnalysisLineSet = {
|
||||
lines: [[up], []],
|
||||
active: 1,
|
||||
baseMoveCount: 14,
|
||||
baseMove: "nevlas pass booster4",
|
||||
played: [
|
||||
[
|
||||
{ move: "terrans pass booster5", moveIndex: 12 },
|
||||
{ move: "terrans income 2t", moveIndex: 13, incomeResolved: true, historyMove: "nevlas pass booster4" },
|
||||
],
|
||||
[],
|
||||
],
|
||||
};
|
||||
const obsolete = { ...set, baseRound: 2, obsoleteMetadata: "ignored" };
|
||||
window.localStorage.setItem(key, JSON.stringify(obsolete));
|
||||
|
||||
const loaded = loadAnalysisLines(0);
|
||||
expect(loaded).to.deep.equal(set);
|
||||
saveAnalysisLines(0, loaded);
|
||||
expect(JSON.parse(window.localStorage.getItem(key))).to.deep.equal(set);
|
||||
|
||||
// Saving an old-shaped object directly must also discard fields that are no longer used.
|
||||
saveAnalysisLines(0, obsolete);
|
||||
expect(JSON.parse(window.localStorage.getItem(key))).to.deep.equal(set);
|
||||
});
|
||||
|
||||
it("preserves whether optional fields were absent or explicitly present during normalization", () => {
|
||||
const empty = emptyAnalysisLineSet(9);
|
||||
expect(empty).to.deep.equal({ lines: [[]], active: 0, baseMoveCount: 9 });
|
||||
for (const set of [
|
||||
empty,
|
||||
{ ...empty, baseMove: "", played: [] },
|
||||
{ ...empty, baseMove: undefined, played: undefined },
|
||||
]) {
|
||||
const normalized = normalizeAnalysisLineSet(set);
|
||||
expect(normalized).to.deep.equal(set);
|
||||
expect(normalized).to.have.all.keys(Object.keys(set));
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps different seats' lines separate", () => {
|
||||
saveAnalysisLines(0, emptyAnalysisLineSet(1, 9));
|
||||
saveAnalysisLines(0, emptyAnalysisLineSet(9));
|
||||
expect(loadAnalysisLines(1)).to.equal(null);
|
||||
});
|
||||
|
||||
it("keeps hosted games separate even when their iframe URL and seat match", () => {
|
||||
const set = { lines: [[up]], active: 0, baseRound: 1, baseMoveCount: 9 };
|
||||
const set = { lines: [[up]], active: 0, baseMoveCount: 9 };
|
||||
saveAnalysisLines(0, set, "init 2 first-game");
|
||||
expect(loadAnalysisLines(0, "init 2 second-game")).to.equal(null);
|
||||
saveAnalysisLines(0, emptyAnalysisLineSet(1, 9), "init 2 second-game");
|
||||
saveAnalysisLines(0, emptyAnalysisLineSet(9), "init 2 second-game");
|
||||
clearAnalysisLine(0, "init 2 second-game");
|
||||
expect(loadAnalysisLines(0, "init 2 first-game")).to.deep.equal(set);
|
||||
});
|
||||
|
|
@ -975,7 +1008,7 @@ describe("analysis line persistence", () => {
|
|||
});
|
||||
|
||||
it("clearAnalysisLine removes every stored line outright, not just empties them", () => {
|
||||
saveAnalysisLines(0, { lines: [[up], [up]], active: 0, baseRound: 1, baseMoveCount: 9 });
|
||||
saveAnalysisLines(0, { lines: [[up], [up]], active: 0, baseMoveCount: 9 });
|
||||
clearAnalysisLine(0);
|
||||
expect(loadAnalysisLines(0)).to.equal(null);
|
||||
});
|
||||
|
|
@ -983,12 +1016,14 @@ describe("analysis line persistence", () => {
|
|||
// §13's migration. Real in-progress games are carrying a pre-tabs value right now (master deploys
|
||||
// to production on push), so a single stored line has to come back as Line 1 rather than as
|
||||
// "nothing stored" - losing a line the player can see in the UI is not an acceptable upgrade.
|
||||
it("reads a pre-tabs single line back as Line 1", () => {
|
||||
window.localStorage.setItem(
|
||||
`analysis-mode:${window.location.search}:0`,
|
||||
JSON.stringify({ entries: [up], baseRound: 2, baseMoveCount: 14 })
|
||||
);
|
||||
expect(loadAnalysisLines(0)).to.deep.equal({ lines: [[up]], active: 0, baseRound: 2, baseMoveCount: 14 });
|
||||
it("reads a pre-tabs single line back as Line 1 and drops baseRound when saving it", () => {
|
||||
const key = `analysis-mode:${window.location.search}:0`;
|
||||
window.localStorage.setItem(key, JSON.stringify({ entries: [up], baseRound: 2, baseMoveCount: 14 }));
|
||||
const expected = { lines: [[up]], active: 0, baseMoveCount: 14 };
|
||||
const loaded = loadAnalysisLines(0);
|
||||
expect(loaded).to.deep.equal(expected);
|
||||
saveAnalysisLines(0, loaded);
|
||||
expect(JSON.parse(window.localStorage.getItem(key))).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it("treats a stored value of neither shape as nothing stored", () => {
|
||||
|
|
@ -997,25 +1032,22 @@ describe("analysis line persistence", () => {
|
|||
});
|
||||
|
||||
it("normalizes a set with no lines or an out-of-range active index", () => {
|
||||
expect(normalizeAnalysisLineSet({ lines: [], active: 4, baseRound: 1, baseMoveCount: 9 })).to.deep.equal({
|
||||
expect(normalizeAnalysisLineSet({ lines: [], active: 4, baseMoveCount: 9 })).to.deep.equal({
|
||||
lines: [[]],
|
||||
active: 0,
|
||||
baseRound: 1,
|
||||
baseMoveCount: 9,
|
||||
});
|
||||
expect(normalizeAnalysisLineSet({ lines: [[up], []], active: 7, baseRound: 1, baseMoveCount: 9 }).active).to.equal(
|
||||
1
|
||||
);
|
||||
expect(normalizeAnalysisLineSet({ lines: [[up], []], active: 7, baseMoveCount: 9 }).active).to.equal(1);
|
||||
});
|
||||
|
||||
it("caps a set at MAX_ANALYSIS_LINES", () => {
|
||||
const lines = Array.from({ length: MAX_ANALYSIS_LINES + 3 }, () => [up]);
|
||||
const capped = normalizeAnalysisLineSet({ lines, active: 0, baseRound: 1, baseMoveCount: 9 });
|
||||
const capped = normalizeAnalysisLineSet({ lines, active: 0, baseMoveCount: 9 });
|
||||
expect(capped.lines.length).to.equal(MAX_ANALYSIS_LINES);
|
||||
});
|
||||
|
||||
it("counts every move across every line", () => {
|
||||
expect(analysisLineSetSize({ lines: [[up, up], [], [up]], active: 0, baseRound: 1, baseMoveCount: 9 })).to.equal(3);
|
||||
expect(analysisLineSetSize({ lines: [[up, up], [], [up]], active: 0, baseMoveCount: 9 })).to.equal(3);
|
||||
});
|
||||
|
||||
it("labels alternative plans alphabetically", () => {
|
||||
|
|
@ -1034,14 +1066,14 @@ describe("summarizeAnalysisLine (§13)", () => {
|
|||
{ kind: "move", move: "terrans up nav." },
|
||||
{ kind: "adjust", charge: 1 },
|
||||
];
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, Round.Round1, 0);
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, 0);
|
||||
expect(summary.moves).to.equal(1);
|
||||
expect(summary.applied).to.equal(1);
|
||||
});
|
||||
|
||||
it("reports an empty line as no moves and no change", () => {
|
||||
const origin = markAnalysisSeat(new Engine(SETUP_MOVES), 0);
|
||||
expect(summarizeAnalysisLine(origin, [], 0, Round.Round1, 0)).to.deep.equal({
|
||||
expect(summarizeAnalysisLine(origin, [], 0, 0)).to.deep.equal({
|
||||
label: "Plan A",
|
||||
moves: 0,
|
||||
victoryPoints: 0,
|
||||
|
|
@ -1054,8 +1086,8 @@ describe("summarizeAnalysisLine (§13)", () => {
|
|||
const origin = markAnalysisSeat(new Engine(SETUP_MOVES), 0);
|
||||
const base = origin.players[0].data.victoryPoints;
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans up nav." }];
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, Round.Round1, 1);
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, 1);
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0);
|
||||
expect(summary.label).to.equal("Plan B");
|
||||
expect(summary.moves).to.equal(1);
|
||||
expect(summary.applied).to.equal(1);
|
||||
|
|
@ -1067,13 +1099,7 @@ describe("summarizeAnalysisLine (§13)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
origin.player(0).data.credits = 0;
|
||||
origin.player(0).data.ores = 0;
|
||||
const summary = summarizeAnalysisLine(
|
||||
origin,
|
||||
[{ kind: "move", move: "terrans build ts -1x2." }],
|
||||
0,
|
||||
Round.Round1,
|
||||
0
|
||||
);
|
||||
const summary = summarizeAnalysisLine(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0, 0);
|
||||
expect(summary.moves).to.equal(1);
|
||||
expect(summary.applied).to.equal(0);
|
||||
expect(summary.overdrawn).to.equal(false);
|
||||
|
|
@ -1087,7 +1113,7 @@ describe("summarizeAnalysisLine (§13)", () => {
|
|||
{ kind: "move", move: "terrans up nav." },
|
||||
{ kind: "move", move: "terrans up nonsense." },
|
||||
];
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, Round.Round1, 0);
|
||||
const summary = summarizeAnalysisLine(origin, entries, 0, 0);
|
||||
expect(summary.moves).to.equal(2);
|
||||
expect(summary.applied).to.equal(1);
|
||||
});
|
||||
|
|
@ -1099,7 +1125,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans up nav." }];
|
||||
|
||||
const moves = committableAnalysisMoves(origin, entries, 0, 1);
|
||||
const moves = committableAnalysisMoves(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans up nav."]);
|
||||
});
|
||||
|
|
@ -1112,7 +1138,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
{ kind: "adjust", charge: 2 },
|
||||
];
|
||||
|
||||
const moves = committableAnalysisMoves(origin, entries, 0, 1);
|
||||
const moves = committableAnalysisMoves(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans up nav."]);
|
||||
});
|
||||
|
|
@ -1124,7 +1150,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
origin.player(0).data.ores = 0; // nothing real to spend - only the sandbox grant can pay for this
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans build ts -1x2." }];
|
||||
|
||||
const moves = committableAnalysisMoves(origin, entries, 0, 1);
|
||||
const moves = committableAnalysisMoves(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal([]);
|
||||
});
|
||||
|
|
@ -1134,7 +1160,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans build m -1x2" }];
|
||||
|
||||
const moves = committableAnalysisMoves(origin, entries, 0, 1);
|
||||
const moves = committableAnalysisMoves(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans build m -1x2"]);
|
||||
});
|
||||
|
|
@ -1147,8 +1173,8 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
{ kind: "move", move: "terrans build ts 4A4 cheap." },
|
||||
];
|
||||
|
||||
expect(committableAnalysisMoves(origin, entries, 0, Round.Round1)).to.deep.equal(["terrans up nav."]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, Round.Round1, 1).moves).to.deep.equal([
|
||||
expect(committableAnalysisMoves(origin, entries, 0)).to.deep.equal(["terrans up nav."]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1).moves).to.deep.equal([
|
||||
"terrans up nav.",
|
||||
"terrans build ts 4A4 cheap.",
|
||||
]);
|
||||
|
|
@ -1158,8 +1184,8 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
const origin = new Engine(SETUP_MOVES);
|
||||
applySoloRoundFlow(origin, 0);
|
||||
|
||||
expect(committableAnalysisMoves(origin, [], 0, 1)).to.deep.equal([]);
|
||||
expect(committableAnalysisMoves(origin, [{ kind: "adjust", charge: 1 }], 0, 1)).to.deep.equal([]);
|
||||
expect(committableAnalysisMoves(origin, [], 0)).to.deep.equal([]);
|
||||
expect(committableAnalysisMoves(origin, [{ kind: "adjust", charge: 1 }], 0)).to.deep.equal([]);
|
||||
});
|
||||
|
||||
it("truncates at an opponent's move, which setup pass-and-play puts in the line as an ordinary entry", () => {
|
||||
|
|
@ -1171,7 +1197,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
{ kind: "move", move: "nevlas build m 0x-4" },
|
||||
];
|
||||
|
||||
const moves = committableAnalysisMoves(origin, entries, 0, 1);
|
||||
const moves = committableAnalysisMoves(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans build m -1x2"]);
|
||||
});
|
||||
|
|
@ -1184,7 +1210,7 @@ describe("committableAnalysisMoves (§6, decision #13)", () => {
|
|||
{ kind: "move", move: "terrans build m -1x2" },
|
||||
];
|
||||
|
||||
expect(committableAnalysisMoves(origin, entries, 0, 1)).to.deep.equal([]);
|
||||
expect(committableAnalysisMoves(origin, entries, 0)).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1194,7 +1220,7 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
origin.players[0].data.knowledge = 12;
|
||||
const moves = ["terrans up nav.", "terrans up terra.", "terrans up int.", "terrans pass booster4"];
|
||||
const entries: AnalysisEntry[] = moves.map((move) => ({ kind: "move", move }));
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1)).to.deep.equal({ moves, cut: null });
|
||||
expect(analysisCommitPrefix(origin, entries, 0)).to.deep.equal({ moves, cut: null });
|
||||
});
|
||||
|
||||
it("requires enough resources in the simulated position even for future premoves", () => {
|
||||
|
|
@ -1204,8 +1230,8 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
{ kind: "adjust", charge: 1 },
|
||||
{ kind: "move", move: "terrans up nav." },
|
||||
];
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1, 0).moves).to.deep.equal([]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1, 1).moves).to.deep.equal([]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 0).moves).to.deep.equal([]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1).moves).to.deep.equal([]);
|
||||
});
|
||||
|
||||
it("can queue a power action after explicit simulated charges, but cannot play it immediately", () => {
|
||||
|
|
@ -1215,15 +1241,15 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
{ kind: "adjust", charge: 4 },
|
||||
{ kind: "move", move: "terrans action power3." },
|
||||
];
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1, 0).moves).to.deep.equal(["terrans action power3."]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1, 1).moves).to.deep.equal([]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 0).moves).to.deep.equal(["terrans action power3."]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1).moves).to.deep.equal([]);
|
||||
});
|
||||
|
||||
it("reports no cut for a line that is committable end to end", () => {
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
applySoloRoundFlow(origin, 0);
|
||||
|
||||
const { moves, cut } = analysisCommitPrefix(origin, [{ kind: "move", move: "terrans up nav." }], 0, 1);
|
||||
const { moves, cut } = analysisCommitPrefix(origin, [{ kind: "move", move: "terrans up nav." }], 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans up nav."]);
|
||||
expect(cut).to.equal(null);
|
||||
|
|
@ -1235,7 +1261,7 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
origin.player(0).data.credits = 0;
|
||||
origin.player(0).data.ores = 0;
|
||||
|
||||
const { moves, cut } = analysisCommitPrefix(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0, 1);
|
||||
const { moves, cut } = analysisCommitPrefix(origin, [{ kind: "move", move: "terrans build ts -1x2." }], 0);
|
||||
|
||||
expect(moves).to.deep.equal([]);
|
||||
expect(cut).to.equal("illegal");
|
||||
|
|
@ -1245,17 +1271,15 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
const seeded = new Engine(["init 2 randomSeed"]);
|
||||
applySoloRoundFlow(seeded, 0);
|
||||
expect(
|
||||
analysisCommitPrefix(seeded, [{ kind: "faction", lineup: [Faction.Terrans, Faction.Nevlas] }], 0, 1).cut
|
||||
analysisCommitPrefix(seeded, [{ kind: "faction", lineup: [Faction.Terrans, Faction.Nevlas] }], 0).cut
|
||||
).to.equal("faction");
|
||||
|
||||
const origin = new Engine(SETUP_MOVES);
|
||||
const entries: AnalysisEntry[] = [{ kind: "move", move: "terrans build ts 4A4 cheap." }];
|
||||
expect(analysisCommitPrefix(origin, entries, 0, Round.Round1, 0).moves).to.deep.equal([
|
||||
"terrans build ts 4A4 cheap.",
|
||||
]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, Round.Round1, 1).moves).to.deep.equal([]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 0).moves).to.deep.equal(["terrans build ts 4A4 cheap."]);
|
||||
expect(analysisCommitPrefix(origin, entries, 0, 1).moves).to.deep.equal([]);
|
||||
expect(
|
||||
analysisCommitPrefix(origin, [{ kind: "move", move: "terrans build ts 3A3 cheap." }], 0, Round.Round1, 1).moves
|
||||
analysisCommitPrefix(origin, [{ kind: "move", move: "terrans build ts 3A3 cheap." }], 0, 1).moves
|
||||
).to.deep.equal(["terrans build ts 3A3 cheap."]);
|
||||
});
|
||||
|
||||
|
|
@ -1267,7 +1291,7 @@ describe("analysisCommitPrefix - the cut reason behind the prefix", () => {
|
|||
{ kind: "move", move: "nevlas build m -1x0" },
|
||||
];
|
||||
|
||||
const { moves, cut } = analysisCommitPrefix(origin, entries, 0, 1);
|
||||
const { moves, cut } = analysisCommitPrefix(origin, entries, 0);
|
||||
|
||||
expect(moves).to.deep.equal(["terrans build m -1x2"]);
|
||||
expect(cut).to.equal("foreign");
|
||||
|
|
@ -1489,7 +1513,7 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
|
||||
// Follow the engine’s placement offers for this faction.
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const { engine } = replayAnalysisLine(origin, entries, 0);
|
||||
if (engine.phase !== Phase.SetupBuilding) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -1498,14 +1522,14 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
entries.push({ kind: "move", move: `terrans build ${first.building} ${first.coordinates}` });
|
||||
}
|
||||
|
||||
const mid = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const mid = replayAnalysisLine(origin, entries, 0);
|
||||
expect(mid.engine.phase).to.equal(Phase.SetupBooster);
|
||||
expect(mid.engine.playerToMove).to.equal(0); // nevlas' pick was skipped
|
||||
expect(mid.engine.players[1].data.occupied).to.have.length(0);
|
||||
const mine = mid.engine.findAvailableCommand(0, Command.ChooseRoundBooster).data.boosters[0];
|
||||
entries.push({ kind: "move", move: `terrans booster ${mine}` });
|
||||
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(entries.length);
|
||||
expect(engine.phase).to.equal(Phase.RoundMove);
|
||||
|
|
@ -1526,7 +1550,7 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "faction", lineup: [Faction.Nevlas, Faction.Terrans] }];
|
||||
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(1);
|
||||
expect(engine.phase).to.equal(Phase.SetupBuilding);
|
||||
|
|
@ -1538,8 +1562,8 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const entries: AnalysisEntry[] = [{ kind: "faction", lineup: [Faction.Itars, Faction.Terrans] }];
|
||||
|
||||
const first = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const second = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const first = replayAnalysisLine(origin, entries, 0);
|
||||
const second = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(first.engine.players.map((pl) => pl.faction)).to.deep.equal([Faction.Itars, Faction.Terrans]);
|
||||
expect(second.engine.players.map((pl) => pl.faction)).to.deep.equal([Faction.Itars, Faction.Terrans]);
|
||||
|
|
@ -1550,7 +1574,7 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
applySoloRoundFlow(origin, 0);
|
||||
const before = JSON.stringify(origin);
|
||||
|
||||
replayAnalysisLine(origin, [{ kind: "faction", lineup: [Faction.Itars, Faction.Terrans] }], 0, Round.Round1);
|
||||
replayAnalysisLine(origin, [{ kind: "faction", lineup: [Faction.Itars, Faction.Terrans] }], 0);
|
||||
|
||||
expect(JSON.stringify(origin)).to.equal(before);
|
||||
});
|
||||
|
|
@ -1562,7 +1586,7 @@ describe("the round-0 faction seed (§11)", () => {
|
|||
{ kind: "move", move: "terrans up nav." },
|
||||
];
|
||||
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0, Round.Round1);
|
||||
const { applied } = replayAnalysisLine(origin, entries, 0);
|
||||
|
||||
expect(applied).to.equal(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -159,14 +159,13 @@ export function computeAnalysisStatus(
|
|||
* now, and dropping it on read would throw away work the player can see in the UI. */
|
||||
export interface AnalysisLine {
|
||||
entries: AnalysisEntry[];
|
||||
baseRound: number;
|
||||
baseMoveCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Several lines at once (§13) - "work out line A, work out line B, flip between them".
|
||||
*
|
||||
* `baseRound`/`baseMoveCount` sit on the SET, not on each line, because every line in it is rooted
|
||||
* `baseMoveCount` sits on the SET, not on each line, because every line in it is rooted
|
||||
* at the same `analysisOrigin`: the sandbox clones the board once on entry and each line is just a
|
||||
* different sequence of turns played from that one point. That is what keeps staleness (§3.5) a
|
||||
* single decision for the whole set rather than a per-line one, and it is why switching lines is
|
||||
|
|
@ -191,7 +190,6 @@ export interface AnalysisLineSet {
|
|||
played?: AnalysisPlayedMove[][];
|
||||
/** Index into `lines`. Always in range once `normalizeAnalysisLineSet` has seen the value. */
|
||||
active: number;
|
||||
baseRound: number;
|
||||
baseMoveCount: number;
|
||||
/** Last real move at the saved base, used to detect a rollback before trimming. */
|
||||
baseMove?: string;
|
||||
|
|
@ -216,13 +214,17 @@ export function normalizeAnalysisLineSet(set: AnalysisLineSet): AnalysisLineSet
|
|||
lines.push([]);
|
||||
}
|
||||
const active = Number.isInteger(set.active) ? Math.min(Math.max(set.active, 0), lines.length - 1) : 0;
|
||||
return { ...set, lines, active };
|
||||
// Select only active fields so obsolete metadata from older saves is not written back.
|
||||
const normalized: AnalysisLineSet = { lines, active, baseMoveCount: set.baseMoveCount };
|
||||
if (Object.prototype.hasOwnProperty.call(set, "baseMove")) normalized.baseMove = set.baseMove;
|
||||
if (Object.prototype.hasOwnProperty.call(set, "played")) normalized.played = set.played;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/** An empty set rooted at the given base - the sandbox's opening state, and what a cleared or
|
||||
* expired set is replaced by. */
|
||||
export function emptyAnalysisLineSet(baseRound: number, baseMoveCount: number): AnalysisLineSet {
|
||||
return { lines: [[]], active: 0, baseRound, baseMoveCount };
|
||||
/** An empty set rooted at the given base - the sandbox's opening state, and what an explicitly
|
||||
* discarded set is replaced by. */
|
||||
export function emptyAnalysisLineSet(baseMoveCount: number): AnalysisLineSet {
|
||||
return { lines: [[]], active: 0, baseMoveCount };
|
||||
}
|
||||
|
||||
/** Every entry across every line, for the "is there anything here at all" questions (the restore
|
||||
|
|
@ -263,7 +265,6 @@ export function loadAnalysisLines(seat: number, scope?: string): AnalysisLineSet
|
|||
return normalizeAnalysisLineSet({
|
||||
lines: [line.entries],
|
||||
active: 0,
|
||||
baseRound: line.baseRound,
|
||||
baseMoveCount: line.baseMoveCount,
|
||||
});
|
||||
}
|
||||
|
|
@ -324,7 +325,6 @@ export function summarizeAnalysisLine(
|
|||
origin: Engine,
|
||||
entries: AnalysisEntry[],
|
||||
seat: number,
|
||||
baseRound: number,
|
||||
index: number
|
||||
): AnalysisLineSummary {
|
||||
const baseVictoryPoints = origin.players[seat]?.data.victoryPoints ?? 0;
|
||||
|
|
@ -332,7 +332,7 @@ export function summarizeAnalysisLine(
|
|||
if (entries.length === 0) {
|
||||
return { label, moves: 0, victoryPoints: 0, overdrawn: false, applied: 0 };
|
||||
}
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, seat, baseRound);
|
||||
const { engine, applied } = replayAnalysisLine(origin, entries, seat);
|
||||
const data = engine.players[seat]?.data;
|
||||
return {
|
||||
label,
|
||||
|
|
@ -343,14 +343,8 @@ export function summarizeAnalysisLine(
|
|||
};
|
||||
}
|
||||
|
||||
/** §6/decision #13 - committing "clears the line", unlike a normal exit (decision #2), which keeps
|
||||
* it for later restoration. Removes the storage key outright rather than persisting an empty line,
|
||||
* so nothing is left for a later `loadAnalysisLines` to find.
|
||||
*
|
||||
* With §13's tab strip that means ALL lines, not just the committed one, and deliberately so: every
|
||||
* other line in the set was an ALTERNATIVE to the move that has now been played for real, worked out
|
||||
* from a board state the game has since left. Keeping them would leave tabs sitting there whose
|
||||
* numbers describe a table that no longer exists. */
|
||||
/** Explicitly discards the pending saved set, not a committed plan. Remove the storage key before
|
||||
* the caller saves its fresh set, so a failed write cannot leave the discarded plans behind. */
|
||||
export function clearAnalysisLine(seat: number, scope?: string): void {
|
||||
if (typeof window !== "undefined") {
|
||||
try {
|
||||
|
|
@ -937,7 +931,6 @@ export function replayAnalysisLine(
|
|||
origin: Engine,
|
||||
entries: AnalysisEntry[],
|
||||
seat: number,
|
||||
baseRound: number,
|
||||
costs?: MoveCost[]
|
||||
): {
|
||||
engine: Engine;
|
||||
|
|
@ -1017,13 +1010,8 @@ export function replayAnalysisLine(
|
|||
|
||||
/** Moves that can be submitted now, replayed without simulated charges. Faction changes and
|
||||
* other players' moves cannot be submitted. The returned prefix stops at the first invalid move. */
|
||||
export function committableAnalysisMoves(
|
||||
origin: Engine,
|
||||
entries: AnalysisEntry[],
|
||||
seat: number,
|
||||
baseRound: number
|
||||
): string[] {
|
||||
return analysisCommitPrefix(origin, entries, seat, baseRound).moves;
|
||||
export function committableAnalysisMoves(origin: Engine, entries: AnalysisEntry[], seat: number): string[] {
|
||||
return analysisCommitPrefix(origin, entries, seat).moves;
|
||||
}
|
||||
|
||||
/** Why the committable prefix stops where it does - the one thing `committableAnalysisMoves`' bare
|
||||
|
|
@ -1053,7 +1041,6 @@ export function analysisCommitPrefix(
|
|||
origin: Engine,
|
||||
entries: AnalysisEntry[],
|
||||
seat: number,
|
||||
baseRound: number,
|
||||
affordableTurns = Infinity
|
||||
): { moves: string[]; cut: AnalysisCommitCut | null } {
|
||||
if (entries.some((entry) => entry.kind === "faction")) {
|
||||
|
|
@ -1070,7 +1057,7 @@ export function analysisCommitPrefix(
|
|||
count <= affordableTurns
|
||||
? moveEntries.slice(0, count)
|
||||
: entries.slice(0, entries.indexOf(moveEntries[count - 1]) + 1);
|
||||
return replayAnalysisLine(origin, prefix, seat, baseRound);
|
||||
return replayAnalysisLine(origin, prefix, seat);
|
||||
};
|
||||
let affordable = 0;
|
||||
let cut: AnalysisCommitCut | null = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue