Make village bots preserve entrances for approaching teammates
This commit is contained in:
parent
a2d9ea5262
commit
fdac316b4d
6 changed files with 210 additions and 127 deletions
|
|
@ -1,101 +1,105 @@
|
|||
{
|
||||
"label": "Fuji",
|
||||
"description": "Escape Mount Fuji together. Private alpha: all seven scenarios.",
|
||||
"players": [2, 3, 4],
|
||||
"credits": "Game design: Wolfgang Warsch. Illustrations: Weberson Santiago. Publisher: Feuerland Spiele.",
|
||||
"public": false,
|
||||
"engine": {
|
||||
"package": {
|
||||
"name": "fuji-engine",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"entryPoint": "dist/wrapper.js"
|
||||
},
|
||||
"viewer": {
|
||||
"url": "",
|
||||
"topLevelVariable": "fuji",
|
||||
"replayable": false,
|
||||
"dependencies": {
|
||||
"scripts": [],
|
||||
"stylesheets": []
|
||||
},
|
||||
"fullScreen": true
|
||||
},
|
||||
"options": [
|
||||
{
|
||||
"name": "scenario",
|
||||
"label": "Scenario",
|
||||
"type": "select",
|
||||
"default": "1",
|
||||
"items": [
|
||||
{
|
||||
"name": "1",
|
||||
"label": "Scenario 1"
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"label": "Scenario 2"
|
||||
},
|
||||
{
|
||||
"name": "3",
|
||||
"label": "Scenario 3"
|
||||
},
|
||||
{
|
||||
"name": "4",
|
||||
"label": "Scenario 4"
|
||||
},
|
||||
{
|
||||
"name": "5",
|
||||
"label": "Scenario 5"
|
||||
},
|
||||
{
|
||||
"name": "6",
|
||||
"label": "Scenario 6"
|
||||
},
|
||||
{
|
||||
"name": "7",
|
||||
"label": "Scenario 7"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "difficulty",
|
||||
"label": "Difficulty",
|
||||
"type": "select",
|
||||
"default": "1",
|
||||
"items": [
|
||||
{
|
||||
"name": "1",
|
||||
"label": "Level 1 (tie or lower: lose 3 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"label": "Level 2 (tie or lower: lose 4 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "3",
|
||||
"label": "Level 3 (tie or lower: lose 5 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "4",
|
||||
"label": "Level 4 (tie or lower: lose 6 stamina)"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"preferences": [
|
||||
{
|
||||
"name": "colorblind",
|
||||
"label": "Show color labels (colorblind support)",
|
||||
"type": "checkbox",
|
||||
"default": false
|
||||
}
|
||||
],
|
||||
"alias": null,
|
||||
"links": {
|
||||
"source": "https://codeberg.org/boardgamers/fuji",
|
||||
"bgg": "https://boardgamegeek.com/boardgame/258308/fuji",
|
||||
"publisher": "https://www.feuerland-spiele.de/",
|
||||
"buy": "https://boardgamegeek.com/boardgame/258308/fuji/marketplace/stores"
|
||||
}
|
||||
"label": "Fuji",
|
||||
"description": "Escape Mount Fuji together. Private alpha: all seven scenarios.",
|
||||
"players": [
|
||||
2,
|
||||
3,
|
||||
4
|
||||
],
|
||||
"credits": "Game design: Wolfgang Warsch. Illustrations: Weberson Santiago. Publisher: Feuerland Spiele.",
|
||||
"public": false,
|
||||
"engine": {
|
||||
"package": {
|
||||
"name": "fuji-engine",
|
||||
"version": "0.1.1"
|
||||
},
|
||||
"entryPoint": "dist/wrapper.js"
|
||||
},
|
||||
"viewer": {
|
||||
"url": "",
|
||||
"topLevelVariable": "fuji",
|
||||
"replayable": false,
|
||||
"dependencies": {
|
||||
"scripts": [],
|
||||
"stylesheets": []
|
||||
},
|
||||
"fullScreen": true
|
||||
},
|
||||
"options": [
|
||||
{
|
||||
"name": "scenario",
|
||||
"label": "Scenario",
|
||||
"type": "select",
|
||||
"default": "1",
|
||||
"items": [
|
||||
{
|
||||
"name": "1",
|
||||
"label": "Scenario 1"
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"label": "Scenario 2"
|
||||
},
|
||||
{
|
||||
"name": "3",
|
||||
"label": "Scenario 3"
|
||||
},
|
||||
{
|
||||
"name": "4",
|
||||
"label": "Scenario 4"
|
||||
},
|
||||
{
|
||||
"name": "5",
|
||||
"label": "Scenario 5"
|
||||
},
|
||||
{
|
||||
"name": "6",
|
||||
"label": "Scenario 6"
|
||||
},
|
||||
{
|
||||
"name": "7",
|
||||
"label": "Scenario 7"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "difficulty",
|
||||
"label": "Difficulty",
|
||||
"type": "select",
|
||||
"default": "1",
|
||||
"items": [
|
||||
{
|
||||
"name": "1",
|
||||
"label": "Level 1 (tie or lower: lose 3 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "2",
|
||||
"label": "Level 2 (tie or lower: lose 4 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "3",
|
||||
"label": "Level 3 (tie or lower: lose 5 stamina)"
|
||||
},
|
||||
{
|
||||
"name": "4",
|
||||
"label": "Level 4 (tie or lower: lose 6 stamina)"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"preferences": [
|
||||
{
|
||||
"name": "colorblind",
|
||||
"label": "Show color labels (colorblind support)",
|
||||
"type": "checkbox",
|
||||
"default": false
|
||||
}
|
||||
],
|
||||
"alias": null,
|
||||
"links": {
|
||||
"source": "https://codeberg.org/boardgamers/fuji",
|
||||
"bgg": "https://boardgamegeek.com/boardgame/258308/fuji",
|
||||
"publisher": "https://www.feuerland-spiele.de/",
|
||||
"buy": "https://boardgamegeek.com/boardgame/258308/fuji/marketplace/stores"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,3 +57,9 @@ The benchmark uses scenario 1 and the default skill assignments. It measures com
|
|||
The escape-emphasis policy was selected before held-out evaluation. It won **112/300 (37.3%)**, compared with **87/300 (29.0%)** for the baseline: an 8.3 percentage-point improvement on this seed set. Neither stalled in held-out evaluation. The small training differences between equipment variants are not evidence of a universally optimal parameter set.
|
||||
|
||||
The higher-lead candidate stalled once: two neighbors ended up sharing an isolated village card with no remaining legal distinct destinations. That candidate was rejected. This late-game engine/rules edge case remains recorded in the report; the AI cannot invent a legal move in that state. All other benchmark games terminated. Tests also exercise each equipment card in constructed useful situations, since conservative lending and Carabiner use are rare in full games without multiple Wireless reveals.
|
||||
|
||||
## Village space
|
||||
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
{
|
||||
"name": "fuji-engine",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./wrapper": "./dist/wrapper.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
||||
"test": "tsc --outDir dist-test && node --test dist-test/src/*.spec.js",
|
||||
"prepack": "pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"seedrandom": "3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "24.10.1",
|
||||
"@types/seedrandom": "3.0.8",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
"name": "fuji-engine",
|
||||
"version": "0.1.1",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./wrapper": "./dist/wrapper.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
||||
"test": "tsc --outDir dist-test && node --test dist-test/src/*.spec.js",
|
||||
"prepack": "pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"seedrandom": "3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "24.10.1",
|
||||
"@types/seedrandom": "3.0.8",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,6 +344,40 @@ export function chooseMove(game: View, seat: number, policy: AiPolicy = DEFAULT_
|
|||
const cooperative = choices.filter(preservesEscape);
|
||||
if (cooperative.length) choices.splice(0, choices.length, ...cooperative);
|
||||
const danger = new Set(threatened(game));
|
||||
// A village resident should leave scarce entrances to approaching neighbors.
|
||||
// Only public routes matter; never inspect their hidden rolls.
|
||||
const arrivals =
|
||||
terrain(cell(game, p.position).terrain).kind === "village"
|
||||
? neighbors(game, seat)
|
||||
.filter(
|
||||
(i) =>
|
||||
!game.players[i]!.ready && terrain(cell(game, game.players[i]!.position).terrain).kind !== "village"
|
||||
)
|
||||
.map((i) => {
|
||||
const claimed = new Set(
|
||||
neighbors(game, i)
|
||||
.filter((j) => j !== seat && game.players[j]!.ready)
|
||||
.map((j) => game.players[j]!.path.at(-1))
|
||||
);
|
||||
const options = Object.values(paths(game, i)).filter((route) => {
|
||||
const target = cell(game, route.at(-1)!);
|
||||
return (
|
||||
terrain(target.terrain).kind === "village" &&
|
||||
!danger.has(target.id) &&
|
||||
!claimed.has(target.id) &&
|
||||
!route.slice(1).some((id) => cell(game, id).eruption)
|
||||
);
|
||||
});
|
||||
return { seat: i, options };
|
||||
})
|
||||
: [];
|
||||
const entranceCost = (destination: string) =>
|
||||
arrivals.reduce((cost, arrival) => {
|
||||
const route = arrival.options.find((route) => route.at(-1) === destination);
|
||||
if (!route) return cost;
|
||||
// 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);
|
||||
const score = (path: string[]) => {
|
||||
const c = cell(game, path.at(-1)!);
|
||||
const closestVillage = Math.min(
|
||||
|
|
@ -384,6 +418,11 @@ export function chooseMove(game: View, seat: number, policy: AiPolicy = DEFAULT_
|
|||
closestVillage * policy.progress +
|
||||
(terrain(c.terrain).kind === "village" ? 8 : 0) +
|
||||
(c.equipment ? 1 : 0) -
|
||||
(terrain(c.terrain).kind === "village" &&
|
||||
!danger.has(c.id) &&
|
||||
!path.slice(1).some((id) => cell(game, id).eruption)
|
||||
? entranceCost(c.id) - entranceCost(p.position)
|
||||
: 0) -
|
||||
path.slice(1).reduce((cost, id) => cost + cell(game, id).eruption * 4, 0)
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1122,3 +1122,37 @@ test("a shared destination remains forbidden when another route is available", (
|
|||
s.players[0]!.ready = true;
|
||||
assert.throws(() => applyMove(s, { action: "ready" }, 1), /different destinations/);
|
||||
});
|
||||
|
||||
test("village bots leave the only reachable entrance for an approaching neighbor", async () => {
|
||||
const { chooseMove } = await import("../index.js");
|
||||
const s = prepared();
|
||||
s.players.forEach((p) => {
|
||||
p.cards = [];
|
||||
p.ready = false;
|
||||
});
|
||||
for (const c of s.board) if (terrain(c.terrain).kind === "village") c.terrain = 28;
|
||||
const positions = ["4,2", "3,4", "6,0"];
|
||||
s.players.forEach((p, i) => {
|
||||
p.position = positions[i]!;
|
||||
p.path = [p.position];
|
||||
});
|
||||
s.players[0]!.dice.forEach((d) => {
|
||||
d.face = 1;
|
||||
});
|
||||
const entrances = Object.keys(paths(s, 1)).filter((id) => terrain(cell(s, id).terrain).kind === "village");
|
||||
assert.deepEqual(entrances, ["4,2"]);
|
||||
const move = chooseMove(stripSecret(s, 0), 0);
|
||||
assert.equal(move.action, "plan");
|
||||
const route = move.path as string[];
|
||||
assert.notEqual(route.at(-1), "4,2");
|
||||
assert.equal(terrain(cell(s, route.at(-1)!).terrain).kind, "village");
|
||||
assert(!route.slice(1).some((id) => cell(s, id).eruption || cell(s, id).lava));
|
||||
const noArrival = structuredClone(s);
|
||||
noArrival.players[1]!.position = "5,0";
|
||||
noArrival.players[1]!.path = ["5,0"];
|
||||
assert.equal(chooseMove(stripSecret(noArrival, 0), 0).action, "ready");
|
||||
s.players[1]!.dice.forEach((d) => {
|
||||
d.face = 6;
|
||||
});
|
||||
assert.deepEqual(chooseMove(stripSecret(s, 0), 0), move, "Hidden teammate dice must not affect entrance sharing");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ await request(version, "PUT", {
|
|||
rules: "[How to play Fuji](https://boardgamers.space/page/fuji/rules)",
|
||||
});
|
||||
console.log("Registered private Fuji v1.");
|
||||
await request(version + "/engine", "POST", readFileSync("fuji-engine-0.1.0.tgz"), true);
|
||||
await request(version + "/engine", "POST", readFileSync(`fuji-engine-${draft.engine.package.version}.tgz`), true);
|
||||
const js = await request(
|
||||
version + "/viewer/file?filename=fuji-viewer.iife.js",
|
||||
"POST",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue