Preserve playtest settings and benchmark equipment after pathfinding fix

This commit is contained in:
coyotte508 2026-09-08 22:17:02 +02:00
commit 1a1487613d
7 changed files with 806 additions and 24 deletions

View file

@ -0,0 +1,681 @@
{
"description": "Matched all-scenario experiments after correcting village distance around map gaps. Complete-team wins, default skills, 2\u20134 players, all seven scenarios and difficulty cycling 1\u20134. Every game checked for termination and exact replay. Training candidates evaluated before held-out seeds.",
"baselineCommit": "fdac316",
"routeCommit": "9c03772",
"currentChanges": "Connected-path distance in route planning and Rope equipment decisions; original policy weights retained.",
"training": [
{
"name": "old",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 168,
"wins": 15,
"moves": 10887,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 0
},
"3": {
"games": 24,
"wins": 1
},
"4": {
"games": 24,
"wins": 0
},
"5": {
"games": 24,
"wins": 5
},
"6": {
"games": 24,
"wins": 1
},
"7": {
"games": 24,
"wins": 1
}
},
"equipment": {
"radio": 46,
"rope": 53,
"flare": 92,
"water": 52,
"binoculars": 32,
"aid": 77,
"map": 31,
"shovel": 24,
"torch": 39,
"machete": 28,
"compass": 10,
"tape": 10
},
"stalled": []
},
{
"name": "route",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 168,
"wins": 46,
"moves": 10592,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 7
},
"3": {
"games": 24,
"wins": 5
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 9
},
"6": {
"games": 24,
"wins": 6
},
"7": {
"games": 24,
"wins": 7
}
},
"equipment": {
"radio": 43,
"rope": 56,
"flare": 88,
"water": 55,
"binoculars": 26,
"aid": 77,
"map": 29,
"shovel": 25,
"torch": 36,
"machete": 33,
"compass": 14,
"tape": 13
},
"stalled": []
},
{
"name": "current",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 168,
"wins": 48,
"moves": 10608,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 8
},
"3": {
"games": 24,
"wins": 4
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 9
},
"6": {
"games": 24,
"wins": 7
},
"7": {
"games": 24,
"wins": 8
}
},
"equipment": {
"radio": 44,
"rope": 68,
"flare": 88,
"water": 56,
"binoculars": 27,
"aid": 77,
"map": 29,
"shovel": 26,
"torch": 36,
"machete": 33,
"compass": 16,
"tape": 13
},
"stalled": []
},
{
"name": "frugal",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 1.5
},
"games": 168,
"wins": 44,
"moves": 10689,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 6
},
"3": {
"games": 24,
"wins": 4
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 9
},
"6": {
"games": 24,
"wins": 6
},
"7": {
"games": 24,
"wins": 7
}
},
"equipment": {
"radio": 45,
"rope": 69,
"flare": 86,
"water": 55,
"binoculars": 27,
"aid": 76,
"map": 28,
"shovel": 25,
"torch": 34,
"machete": 31,
"compass": 15,
"tape": 13
},
"stalled": []
},
{
"name": "generous",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.3
},
"games": 168,
"wins": 46,
"moves": 10529,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 8
},
"3": {
"games": 24,
"wins": 5
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 8
},
"6": {
"games": 24,
"wins": 7
},
"7": {
"games": 24,
"wins": 6
}
},
"equipment": {
"radio": 43,
"rope": 68,
"flare": 89,
"water": 55,
"binoculars": 27,
"aid": 77,
"map": 28,
"shovel": 27,
"machete": 35,
"tape": 18,
"torch": 35,
"compass": 17
},
"stalled": []
},
{
"name": "stamina",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 3,
"teamwork": 0.4,
"cost": 0.8
},
"games": 168,
"wins": 44,
"moves": 10516,
"byScenario": {
"1": {
"games": 24,
"wins": 6
},
"2": {
"games": 24,
"wins": 7
},
"3": {
"games": 24,
"wins": 4
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 9
},
"6": {
"games": 24,
"wins": 6
},
"7": {
"games": 24,
"wins": 7
}
},
"equipment": {
"radio": 43,
"rope": 67,
"flare": 89,
"water": 56,
"binoculars": 27,
"aid": 77,
"map": 28,
"shovel": 26,
"torch": 36,
"compass": 17,
"machete": 33,
"tape": 13
},
"stalled": []
},
{
"name": "teamwork",
"family": "training",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.8,
"cost": 0.8
},
"games": 168,
"wins": 48,
"moves": 10623,
"byScenario": {
"1": {
"games": 24,
"wins": 7
},
"2": {
"games": 24,
"wins": 8
},
"3": {
"games": 24,
"wins": 4
},
"4": {
"games": 24,
"wins": 5
},
"5": {
"games": 24,
"wins": 9
},
"6": {
"games": 24,
"wins": 7
},
"7": {
"games": 24,
"wins": 8
}
},
"equipment": {
"radio": 44,
"rope": 68,
"flare": 88,
"water": 56,
"binoculars": 27,
"aid": 77,
"map": 29,
"shovel": 26,
"machete": 34,
"torch": 36,
"tape": 14,
"compass": 16
},
"stalled": []
}
],
"heldout": [
{
"name": "old",
"family": "heldout",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 252,
"wins": 29,
"moves": 16071,
"byScenario": {
"1": {
"games": 36,
"wins": 16
},
"2": {
"games": 36,
"wins": 2
},
"3": {
"games": 36,
"wins": 3
},
"4": {
"games": 36,
"wins": 1
},
"5": {
"games": 36,
"wins": 4
},
"6": {
"games": 36,
"wins": 1
},
"7": {
"games": 36,
"wins": 2
}
},
"equipment": {
"water": 117,
"aid": 76,
"flare": 41,
"radio": 56,
"shovel": 70,
"binoculars": 135,
"machete": 64,
"torch": 60,
"compass": 33,
"rope": 51,
"map": 49,
"tape": 8
},
"stalled": []
},
{
"name": "route",
"family": "heldout",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 252,
"wins": 61,
"moves": 16353,
"byScenario": {
"1": {
"games": 36,
"wins": 17
},
"2": {
"games": 36,
"wins": 5
},
"3": {
"games": 36,
"wins": 5
},
"4": {
"games": 36,
"wins": 5
},
"5": {
"games": 36,
"wins": 12
},
"6": {
"games": 36,
"wins": 8
},
"7": {
"games": 36,
"wins": 9
}
},
"equipment": {
"water": 112,
"aid": 74,
"flare": 43,
"radio": 54,
"shovel": 69,
"binoculars": 130,
"machete": 76,
"torch": 62,
"compass": 30,
"rope": 54,
"map": 50,
"tape": 13
},
"stalled": []
},
{
"name": "current",
"family": "heldout",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.4,
"cost": 0.8
},
"games": 252,
"wins": 61,
"moves": 16220,
"byScenario": {
"1": {
"games": 36,
"wins": 17
},
"2": {
"games": 36,
"wins": 6
},
"3": {
"games": 36,
"wins": 5
},
"4": {
"games": 36,
"wins": 6
},
"5": {
"games": 36,
"wins": 12
},
"6": {
"games": 36,
"wins": 8
},
"7": {
"games": 36,
"wins": 7
}
},
"equipment": {
"water": 112,
"aid": 74,
"flare": 41,
"radio": 54,
"shovel": 69,
"binoculars": 129,
"machete": 76,
"torch": 62,
"compass": 30,
"rope": 61,
"map": 50,
"tape": 11
},
"stalled": []
},
{
"name": "teamwork",
"family": "heldout",
"policy": {
"equipment": true,
"lead": 1,
"progress": 4,
"success": 18,
"stamina": 1,
"teamwork": 0.8,
"cost": 0.8
},
"games": 252,
"wins": 61,
"moves": 16189,
"byScenario": {
"1": {
"games": 36,
"wins": 17
},
"2": {
"games": 36,
"wins": 6
},
"3": {
"games": 36,
"wins": 5
},
"4": {
"games": 36,
"wins": 6
},
"5": {
"games": 36,
"wins": 11
},
"6": {
"games": 36,
"wins": 8
},
"7": {
"games": 36,
"wins": 8
}
},
"equipment": {
"water": 112,
"aid": 74,
"flare": 41,
"radio": 54,
"shovel": 69,
"binoculars": 129,
"machete": 79,
"torch": 62,
"compass": 32,
"rope": 61,
"map": 49,
"tape": 13
},
"stalled": []
}
]
}

View file

@ -63,3 +63,23 @@ The higher-lead candidate stalled once: two neighbors ended up sharing an isolat
Bots already in the village prefer to leave scarce, reachable entrances for approaching comparison neighbors. The preference uses public routes, weights teammates near lava more heavily, and favors leaving shorter approaches available. It applies only to village destinations safe from the next eruption and routes without eruption markers; ordinary dice and route scoring still apply. Neighbors already in the village or with finalized routes do not add pressure to move.
Matched comparison for the village-space change: 240 identical seeded games using the same engine, with only the previous AI module substituted for the baseline. Scenario 1 used 50 seeds at each of 2/3/4 players; scenarios 2–7 used five seeds at each player count. Difficulty cycled through 1–4. Baseline: 70 wins (63 + 7), 13,911 moves. Updated: 72 wins (64 + 8), 13,631 moves. Both completed all games without deadlocks and with exact replays. The gain from 29.2% to 30.0% is small and does not establish statistical significance.
## Connected-path distance and equipment retuning
Scenario 7 exposed a geometric error: coordinate distance penalized walking around the gap between the starting trail and village, encouraging repeated stays. Planning and Rope now use shortest connected paths through walkable locations, excluding lava. This uses public board information only.
The matched experiment in `ai-detour-benchmark.json` covers all seven scenarios, 2–4 players, difficulty 1–4 and default skills. Seven candidates each played 168 training games (1,176 runs). Four candidates then played 252 separate held-out games each (1,008 runs). Every run terminated and replayed exactly.
| Policy | Training wins / 168 | Held-out wins / 252 |
| ------------------------------------ | ------------------: | ------------------: |
| Previous coordinate distance | 15 | 29 |
| Connected route distance | 46 | 61 |
| Connected route and Rope distance | 48 | 61 |
| More conservative equipment spending | 44 | Not tested |
| More generous equipment spending | 46 | Not tested |
| More stamina emphasis | 44 | Not tested |
| More teammate emphasis | 48 | 61 |
The selected policy retains the original weights and corrects distance for both routes and Rope. Held-out wins increased from 11.5% to 24.2% versus the previous AI. Scenario 7 increased from 2/36 to 7/36; that per-scenario sample is small. Rope's correction tied route-only results overall and lost two scenario-7 wins in held-out seeds, so its geometric correctness should not be confused with a demonstrated additional win-rate improvement. Equipment weight changes did not establish a stronger policy.
Reproduce a current-policy batch with `node scripts/benchmark-policy.mjs current heldout 12`. Use `teamwork`, `frugal`, `generous`, or `stamina` to test the recorded alternatives. `FUJI_BENCH_ENGINE` can select an alternate compiled engine directory for matched historical comparisons. Reports are written to `work/benchmarks`. Seed families are independent of policy names.

View file

@ -41,6 +41,23 @@ const ruleAt = (game: View, seat: number) =>
const valueOf = (d: Die, r: Requirement) => (matches(face(d), r) ? d.face : 0);
const urgency = (game: View, seat: number) => (threatened(game).includes(game.players[seat]!.position) ? 3 : 1);
function distancesToVillage(game: View): Map<string, number> {
// Measure progress along the trail, including detours around gaps and lava.
const villageDistances = new Map<string, number>();
const frontier = game.board.filter((c) => walkable(c) && terrain(c.terrain).kind === "village");
frontier.forEach((c) => villageDistances.set(c.id, 0));
for (let i = 0; i < frontier.length; i++) {
const current = frontier[i]!;
for (const next of game.board) {
if (!walkable(next) || villageDistances.has(next.id)) continue;
if (Math.abs(current.x - next.x) + Math.abs(current.y - next.y) !== 1) continue;
villageDistances.set(next.id, villageDistances.get(current.id)! + 1);
frontier.push(next);
}
}
return villageDistances;
}
// Convolve independent fair rolls; revealed faces are point masses. This is a
// prior, not access to private rolls or a model of another player's strategy.
export function contributionDistribution(dice: Die[], rule: Requirement): number[] {
@ -244,14 +261,8 @@ function chooseEquipment(game: View, seat: number, policy: AiPolicy): Move | und
);
} else if (effect === "rope") {
const origin = cell(game, player.position);
const villageDistance = (id: string) => {
const c = cell(game, id);
return Math.min(
...game.board
.filter((t) => terrain(t.terrain).kind === "village")
.map((t) => Math.abs(t.x - c.x) + Math.abs(t.y - c.y))
);
};
const distances = distancesToVillage(game);
const villageDistance = (id: string) => distances.get(id) ?? game.board.length;
for (const c of game.board.filter(
(c) =>
walkable(c) &&
@ -378,19 +389,7 @@ export function chooseMove(game: View, seat: number, policy: AiPolicy = DEFAULT_
// Fewer alternatives and shorter approaches make this entrance more valuable.
return cost + (18 * urgency(game, arrival.seat)) / arrival.options.length / Math.max(1, route.length - 1);
}, 0);
// Measure progress along the trail, including detours around gaps and lava.
const villageDistances = new Map<string, number>();
const frontier = game.board.filter((c) => walkable(c) && terrain(c.terrain).kind === "village");
frontier.forEach((c) => villageDistances.set(c.id, 0));
for (let i = 0; i < frontier.length; i++) {
const current = frontier[i]!;
for (const next of game.board) {
if (!walkable(next) || villageDistances.has(next.id)) continue;
if (Math.abs(current.x - next.x) + Math.abs(current.y - next.y) !== 1) continue;
villageDistances.set(next.id, villageDistances.get(current.id)! + 1);
frontier.push(next);
}
}
const villageDistances = distancesToVillage(game);
const score = (path: string[]) => {
const c = cell(game, path.at(-1)!);
const closestVillage = villageDistances.get(c.id) ?? game.board.length;

View file

@ -1181,3 +1181,17 @@ test("AI follows the connected trail around scenario 7's gap instead of camping
assert.deepEqual(chooseMove(stripSecret(s, seat), seat), previous);
}
});
test("AI uses Rope to advance around a map gap even when coordinate distance increases", async () => {
const { chooseMove } = await import("../index.js");
const s = initGame(3, { scenario: 7 }, "rope-detour");
s.phase = "equipment";
for (const [i, p] of s.players.entries()) {
p.position = ["5,4", "6,5", "6,3"][i]!;
p.path = [p.position];
p.ready = false;
p.cards = [];
}
s.players[0]!.cards = [{ id: "rope", used: 0, availableRound: 0 }];
assert.deepEqual(chooseMove(stripSecret(s, 0), 0), { action: "equipment", id: "rope", tiles: ["5,3"] });
});

View file

@ -94,6 +94,15 @@
let newDifficulty = $state(1);
let newScenario = $state(1);
let newSeed = $state("first-light");
function openNewGame() {
const current = store.state;
if (current) {
newScenario = current.scenario ?? 1;
newDifficulty = current.difficulty;
newPlayers = current.players.length;
}
newGame = true;
}
const reachable = $derived(s && seat !== undefined ? paths(s, seat) : {});
const reserved = $derived.by(() => {
const locations: Record<string, string> = {};
@ -439,7 +448,7 @@
<p class="muted small">Includes the seed, settings, move history and all players’ dice.</p>
{#if debugStatus}<p class="small" role="status">{debugStatus}</p>{/if}
</fieldset>
<button onclick={() => (newGame = true)}>New game</button>
<button onclick={openNewGame}>New game</button>
<button
onclick={() => {
newSeed = crypto.randomUUID().slice(0, 8);
@ -735,7 +744,7 @@
>{s.players.reduce((n, p) => n + 4 - p.injuries.length + p.cards.length, 0)} expedition points</strong
>{/if}
</div>
{#if store.local}<button class="primary" onclick={() => (newGame = true)}>Start a new expedition</button>{/if}
{#if store.local}<button class="primary" onclick={openNewGame}>Start a new expedition</button>{/if}
{:else if !me}<p class="instruction">Follow the expedition. Private dice remain hidden until the reveal.</p>
{:else if s.phase === "setup"}
{#if me.setupDone}<p class="instruction">

View file

@ -0,0 +1,50 @@
import fs from "node:fs";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import assert from "node:assert/strict";
const [name = "current", family = "training", countArg = "8"] = process.argv.slice(2);
const dir = pathToFileURL(resolve(process.env.FUJI_BENCH_ENGINE ?? "packages/engine/dist") + "/");
const output = resolve("work/benchmarks");
fs.mkdirSync(output, { recursive: true });
const { initGame, chooseMove, stripSecret, applyMove, replay, DEFAULT_AI_POLICY } = await import(
new URL("index.js", dir)
);
const { currentPlayer } = await import(new URL("wrapper.js", dir));
const tweaks = {
current: {},
old: {},
route: {},
frugal: { cost: 1.5 },
generous: { cost: 0.3 },
stamina: { stamina: 3 },
teamwork: { teamwork: 0.8 },
};
const policy = { ...DEFAULT_AI_POLICY, ...tweaks[name] };
const result = { name, family, policy, games: 0, wins: 0, moves: 0, byScenario: {}, equipment: {}, stalled: [] };
for (let scenario = 1; scenario <= 7; scenario++) {
for (let players = 2; players <= 4; players++)
for (let seed = 0; seed < Number(countArg); seed++) {
let g = initGame(players, { scenario, difficulty: 1 + (seed % 4) }, `detour-${family}-${seed}`),
n = 0;
while (!g.outcome && n < 1000) {
const cp = currentPlayer(g),
seat = Array.isArray(cp) ? cp[0] : cp;
assert.notEqual(seat, undefined);
const m = chooseMove(stripSecret(g, seat), seat, policy);
g = applyMove(g, m, seat);
if (m.action === "equipment") result.equipment[m.copy ?? m.id] = (result.equipment[m.copy ?? m.id] ?? 0) + 1;
n++;
}
if (!g.outcome) result.stalled.push({ scenario, players, seed });
assert.deepEqual(replay(g), g);
result.games++;
result.moves += n;
const won = Number(g.outcome === "won");
result.wins += won;
result.byScenario[scenario] ??= { games: 0, wins: 0 };
result.byScenario[scenario].games++;
result.byScenario[scenario].wins += won;
}
fs.writeFileSync(resolve(output, `${name}-${family}.json`), JSON.stringify(result, null, 2));
console.log(name, scenario, result.games, result.wins);
}

View file

@ -1,11 +1,15 @@
import { chromium } from "playwright";
import { readFileSync, mkdirSync } from "node:fs";
import assert from "node:assert/strict";
import { replay } from "../packages/engine/dist/index.js";
import { replay, initGame } from "../packages/engine/dist/index.js";
mkdirSync("work/browser", { recursive: true });
const browser = await chromium.launch({ executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
try {
const page = await browser.newPage();
await page.addInitScript(
(state) => localStorage.setItem("fuji-dev-v1", JSON.stringify(state)),
initGame(4, { scenario: 7, difficulty: 3 }, "debug-test")
);
await page.goto("http://127.0.0.1:5187");
await page.locator(".map").waitFor();
await page.getByText("Playtest tools", { exact: true }).click();
@ -20,6 +24,11 @@ try {
assert.deepEqual(replay(snapshot.game), snapshot.game);
assert.equal(snapshot.seat, 0);
console.log("Debug export preserves exact state, selected seat and deterministic replay.");
await page.getByRole("button", { name: "New game", exact: true }).click();
const modal = page.getByRole("dialog");
for (const label of ["7", "Level 3", "4 players"])
assert.equal(await modal.getByRole("button", { name: label, exact: true }).getAttribute("aria-pressed"), "true");
console.log("New games retain the restored scenario, difficulty and player count.");
} finally {
await browser.close();
}