Offer seeded random scenarios in BGS game options

This commit is contained in:
coyotte508 2026-09-08 23:46:37 +02:00
commit a75eb644e5
4 changed files with 20 additions and 3 deletions

View file

@ -7,7 +7,7 @@
"engine": {
"package": {
"name": "fuji-engine",
"version": "0.1.1"
"version": "0.1.2"
},
"entryPoint": "dist/wrapper.js"
},
@ -55,6 +55,10 @@
{
"name": "7",
"label": "Scenario 7"
},
{
"name": "random",
"label": "Random"
}
]
},

View file

@ -1,6 +1,6 @@
{
"name": "fuji-engine",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"license": "AGPL-3.0-only",
"files": [

View file

@ -1306,3 +1306,15 @@ test("safe village residents sacrifice strong dice for escaping neighbors withou
p.cards = [{ id: "machete", used: 0, availableRound: 0 }];
assert.equal(chooseMove(stripSecret(s, 0), 0).id, "machete");
});
test("random scenario is seeded, covers all seven layouts and replays exactly", () => {
const seen = new Set<number>();
for (let i = 0; i < 50; i++) {
const s = initGame(3, { scenario: "random" }, `random-scenario-${i}`);
assert(s.scenario! >= 1 && s.scenario! <= 7);
seen.add(s.scenario!);
assert.deepEqual(initGame(3, { scenario: "random" }, s.seed), s);
assert.deepEqual(replay(s), s);
}
assert.equal(seen.size, 7);
});

View file

@ -235,7 +235,7 @@ export function initGame(players = 3, options: Record<string, unknown> = {}, see
if (!Number.isInteger(players) || players < 2 || players > 4) throw Error("Fuji supports 2–4 players.");
const difficulty = Number(options.difficulty ?? 1);
if (!Number.isInteger(difficulty) || difficulty < 1 || difficulty > 4) throw Error("Choose difficulty 1–4.");
const scenario = Number(options.scenario ?? 1);
let scenario = options.scenario === "random" ? 1 : Number(options.scenario ?? 1);
if (!Number.isInteger(scenario) || scenario < 1 || scenario > 7) throw Error("Choose scenario 1–7.");
const s: State = {
schemaVersion: 1,
@ -260,6 +260,7 @@ export function initGame(players = 3, options: Record<string, unknown> = {}, see
history: [],
initOptions: { autoMovement: true, autoProgress: true, ...options },
};
if (options.scenario === "random") s.scenario = scenario = 1 + Math.floor(random(s) * SCENARIOS.length);
const lands = shuffle(
s,
Array.from({ length: 24 }, (_, i) => i + 4)