Add private-information-safe ongoing analysis scenarios
This commit is contained in:
parent
a79212a8c7
commit
026dfa1a62
3 changed files with 42 additions and 0 deletions
|
|
@ -1626,3 +1626,22 @@ test("analysis uses public log boundaries and keeps player-specific views playab
|
|||
}
|
||||
assert.deepEqual(state, original);
|
||||
});
|
||||
|
||||
test("ongoing analysis rebuilds hidden dice and future draws without source secrets", async () => {
|
||||
const wrapper = await import("../wrapper.js");
|
||||
const source = prepared();
|
||||
const before = structuredClone(source);
|
||||
const changed = structuredClone(source);
|
||||
changed.seed = "other-secret";
|
||||
changed.counter += 100;
|
||||
changed.deck.reverse();
|
||||
for (const p of changed.players.slice(1)) for (const d of p.dice) d.face = (d.face % 6) + 1;
|
||||
changed.history = [{ player: 1, move: { secret: "private" } }];
|
||||
changed.chatMessages = ["private"];
|
||||
const result = wrapper.createAnalysisScenario(source, { player: 0, seed: "simulation" });
|
||||
assert.deepEqual(result, wrapper.createAnalysisScenario(changed, { player: 0, seed: "simulation" }));
|
||||
assert.deepEqual(source, before);
|
||||
assert.deepEqual(result.players[0]!.dice, source.players[0]!.dice);
|
||||
assert.equal(result.deck.length, source.deck.length);
|
||||
assert.deepEqual(result.history, []);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1217,3 +1217,24 @@ export function replay(s: State, to?: number, logTo?: number): State {
|
|||
if (to === undefined && logTo === undefined && s.planningSnapshot) restorePlanning(state, s.planningSnapshot);
|
||||
return state;
|
||||
}
|
||||
|
||||
/** Start a manual sandbox from only the requesting seat's visible information. */
|
||||
export function createAnalysisScenario(data: State, { player, seed }: { player?: number; seed: string }): State {
|
||||
const { deckCount, ...visible } = stripSecret(data, player);
|
||||
const s: State = { ...visible, seed, counter: 0, deck: [], history: [], initOptions: {} };
|
||||
const used = new Set([...s.discard, ...s.players.flatMap((p) => p.cards.map((c) => c.id))]);
|
||||
s.deck = shuffle(
|
||||
s,
|
||||
EQUIPMENT.map((c) => c.id).filter((id) => !used.has(id))
|
||||
).slice(0, deckCount);
|
||||
for (const p of s.players)
|
||||
roll(
|
||||
s,
|
||||
p.dice.filter((d) => d.face === 0)
|
||||
);
|
||||
roll(
|
||||
s,
|
||||
s.ghost.filter((d) => d.face === 0)
|
||||
);
|
||||
return s;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,3 +63,5 @@ export function createAnalysis(s: State, { to }: { to: number; sourceEnded: bool
|
|||
delete copy.chatMessages;
|
||||
return copy;
|
||||
}
|
||||
|
||||
export { createAnalysisScenario } from "./src/game.js";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue