Skip repeated pass-only turns and remove outer viewer margins
This commit is contained in:
parent
e2d9c7b2b0
commit
20faf56008
9 changed files with 130 additions and 17 deletions
|
|
@ -59,7 +59,7 @@
|
|||
},
|
||||
{
|
||||
"id": "shipping",
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"title": "Shipping and storage",
|
||||
"description": "Load matching ships, earn points and keep only what your storage allows."
|
||||
},
|
||||
|
|
|
|||
|
|
@ -512,6 +512,7 @@ function startRole(s, id, p, captured = false) {
|
|||
if (s.captured?.id === id) s.captured = null;
|
||||
s.role = id.startsWith("adventurer") ? "adventurer" : id;
|
||||
s.owner = p;
|
||||
s.roleHistoryStart = s.history.length;
|
||||
s.phaseVP = s.players.map(() => 0);
|
||||
if (s.role === "recruiter")
|
||||
for (const a of s.players) if (a.puertoma) a.puertoma.recruited = 0;
|
||||
|
|
@ -1273,14 +1274,34 @@ export function setPlayerSettings(s, p, settings) {
|
|||
};
|
||||
return next;
|
||||
}
|
||||
function repeatedRolePass(s, t) {
|
||||
if (s.players[t.p]?.puertoma) return null;
|
||||
// Role selection and out-of-turn Bohío moves do not acknowledge a role turn.
|
||||
// The boundary also resets for captured roles; older games fall back to history.
|
||||
const start =
|
||||
s.roleHistoryStart ??
|
||||
s.history.findLastIndex((h) => h.move.type === "role");
|
||||
if (
|
||||
start < 0 ||
|
||||
!s.history
|
||||
.slice(start)
|
||||
.some((h) => h.p === t.p && !["role", "bohio"].includes(h.move.type))
|
||||
)
|
||||
return null;
|
||||
const choices = legal(s, t.p);
|
||||
return choices.length === 1 && choices[0].type === "pass" ? choices[0] : null;
|
||||
}
|
||||
export function resolveForcedActions(state) {
|
||||
let s = clone(state);
|
||||
settle(s);
|
||||
for (let guard = 0; guard < 1000; guard++) {
|
||||
if (s.finished || !s.tasks.length) return s;
|
||||
const t = s.tasks[0];
|
||||
if (!playerSettings(s, t.p).autoForcedActions) return s;
|
||||
const forced = forcedAction(s, t, s.players[t.p]);
|
||||
const forced =
|
||||
repeatedRolePass(s, t) ??
|
||||
(playerSettings(s, t.p).autoForcedActions
|
||||
? forcedAction(s, t, s.players[t.p])
|
||||
: null);
|
||||
if (!forced) return s;
|
||||
s = applyMove(s, forced, t.p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/puerto-rico",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Puerto Rico 1897 Special Edition for Boardgamers Space",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const server = createServer(async (req, res) => {
|
|||
res.end(
|
||||
req.url === "/viewer.js"
|
||||
? await readFile(new URL("../dist/viewer.js", import.meta.url))
|
||||
: '<!doctype html><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{margin:0}</style><div id="game"></div><script src="/viewer.js"></script>',
|
||||
: '<!doctype html><meta name="viewport" content="width=device-width, initial-scale=1"><div id="game"></div><script src="/viewer.js"></script>',
|
||||
);
|
||||
});
|
||||
await new Promise((r) => server.listen(0, "127.0.0.1", r));
|
||||
|
|
@ -63,12 +63,20 @@ try {
|
|||
"thumbnail captures only the harbour",
|
||||
);
|
||||
await page.evaluate(() => scrollTo(0, 0));
|
||||
const outer = await page.locator(".pr-game").boundingBox();
|
||||
assert.equal(outer.x, 0, "no document side margin");
|
||||
assert.equal(
|
||||
await page
|
||||
.locator("body")
|
||||
.evaluate((el) => getComputedStyle(el).marginTop),
|
||||
"0px",
|
||||
);
|
||||
if (width <= 760)
|
||||
assert.equal(
|
||||
await page
|
||||
.locator(".pr-game")
|
||||
.evaluate((el) => getComputedStyle(el).paddingLeft),
|
||||
"0px",
|
||||
"8px",
|
||||
);
|
||||
if (width <= 760) {
|
||||
assert.equal(
|
||||
|
|
|
|||
|
|
@ -432,7 +432,10 @@ test("replay restores each playable boundary and log slices omit secrets", () =>
|
|||
states.push(s);
|
||||
}
|
||||
for (const i of [1, 5, 13, 36])
|
||||
assert.deepEqual(e.replay(s, { to: i }), states[i - 1]);
|
||||
assert.deepEqual(
|
||||
e.replay(s, { to: e.logLength(states[i - 1]) }),
|
||||
states[i - 1],
|
||||
);
|
||||
const slice = e.logSlice(s, { player: 0, start: 5, end: 5 });
|
||||
assert.equal(slice.frames.length, 1);
|
||||
assert.equal(slice.frames[0].history, undefined);
|
||||
|
|
|
|||
|
|
@ -237,3 +237,81 @@ test("an already waiting empty storage step normalizes without changing the inpu
|
|||
assert.equal(s.tasks[0].kind, "store");
|
||||
assert.deepEqual(r.history, s.history);
|
||||
});
|
||||
|
||||
test("Captain keeps each first turn but skips later pass-only turns without opting in", () => {
|
||||
let s = E.init(3, [], {}, "captain-repeat-pass");
|
||||
s.players[0].goods.corn = 1;
|
||||
s.players[0].goods.sugar = 1;
|
||||
s = E.move(s, { type: "role", id: "captain" }, 0);
|
||||
s = E.move(
|
||||
s,
|
||||
E.legal(s).find((m) => m.type === "ship" && m.good === "corn"),
|
||||
0,
|
||||
);
|
||||
assert.equal(E.currentPlayer(s), 1);
|
||||
assert.deepEqual(E.legal(s), [{ type: "pass" }]);
|
||||
s = E.move(s, { type: "pass" }, 1);
|
||||
assert.equal(E.currentPlayer(s), 2);
|
||||
s = E.move(s, { type: "pass" }, 2);
|
||||
assert.equal(E.currentPlayer(s), 0);
|
||||
s = E.move(
|
||||
s,
|
||||
E.legal(s).find((m) => m.type === "ship" && m.good === "sugar"),
|
||||
0,
|
||||
);
|
||||
assert.equal(s.tasks[0].kind, "role");
|
||||
assert.deepEqual(
|
||||
s.history.slice(-3).map((h) => [h.p, h.move.type]),
|
||||
[
|
||||
[1, "pass"],
|
||||
[2, "pass"],
|
||||
[0, "pass"],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test("empty Captain first pass remains manual, including the role chooser", () => {
|
||||
let s = E.init(3, [], {}, "captain-first-pass");
|
||||
s = E.move(s, { type: "role", id: "captain" }, 0);
|
||||
for (let p = 0; p < 3; p++) {
|
||||
assert.equal(E.currentPlayer(s), p);
|
||||
assert.equal(s.tasks[0].kind, "ship");
|
||||
s = E.move(s, { type: "pass" }, p);
|
||||
}
|
||||
assert.equal(s.tasks[0].kind, "role");
|
||||
assert.deepEqual(E.replay(s), s);
|
||||
});
|
||||
|
||||
test("Trader skips its redundant finish but keeps the next player's first pass", () => {
|
||||
let s = E.init(3, [], {}, "trader-repeat-pass");
|
||||
s.players[0].goods.corn = 1;
|
||||
s = E.move(s, { type: "role", id: "trader" }, 0);
|
||||
s = E.move(
|
||||
s,
|
||||
E.legal(s).find((m) => m.type === "trade"),
|
||||
0,
|
||||
);
|
||||
assert.equal(E.currentPlayer(s), 1);
|
||||
assert.deepEqual(
|
||||
s.history.slice(-2).map((h) => h.move.type),
|
||||
["trade", "pass"],
|
||||
);
|
||||
assert.deepEqual(E.legal(s), [{ type: "pass" }]);
|
||||
});
|
||||
|
||||
test("a new role resets acknowledgement and Bohío alternatives remain manual", () => {
|
||||
let s = E.init(3, [], {}, "role-pass-boundary");
|
||||
s = E.move(s, { type: "role", id: "trader" }, 0);
|
||||
s = E.move(s, { type: "pass" }, 0);
|
||||
s = E.move(s, { type: "pass" }, 1);
|
||||
s = E.move(s, { type: "pass" }, 2);
|
||||
s = E.move(s, { type: "role", id: "captain" }, E.currentPlayer(s));
|
||||
assert.equal(s.tasks[0].kind, "ship");
|
||||
const p = E.currentPlayer(s);
|
||||
s.players[p].buildings = [{ id: "bohio", w: 1, c: 0 }];
|
||||
s.players[p].estates = [{ id: "corn", w: 0, c: 0 }];
|
||||
s.history.push({ p, move: { type: "pass" } });
|
||||
const resolved = E.resolveForcedActions(s);
|
||||
assert.equal(resolved.history.length, s.history.length);
|
||||
assert(E.legal(resolved).some((m) => m.type === "bohio"));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -116,9 +116,9 @@ function playChapter(id) {
|
|||
assert.deepEqual(before, frames.at(-1), "move leaves its input untouched");
|
||||
assert(step.complete(state));
|
||||
assert.equal(
|
||||
state.history.filter((h) => h.p === 0).length,
|
||||
state.history.filter((h) => h.p === 0 && h.move.type !== "pass").length,
|
||||
state.tutorial.completed,
|
||||
"only the learner performs learner moves",
|
||||
"learner actions are scripted; redundant passes may resolve automatically",
|
||||
);
|
||||
frames.push(clone(state));
|
||||
}
|
||||
|
|
@ -218,16 +218,17 @@ test("basics demonstrates accumulated role coins, production, privilege and unch
|
|||
});
|
||||
|
||||
test("shipping enforces single-type ships, mandatory loading and base storage", () => {
|
||||
const [, role, loaded, storage, ended] = playChapter("shipping");
|
||||
const [, role, storage, ended] = playChapter("shipping");
|
||||
assert(!engine.legal(role).some((move) => move.type === "pass"));
|
||||
assert(!engine.legal(role).some((move) => move.good === "coffee"));
|
||||
assert.throws(() => engine.move(role, { type: "pass" }, 0));
|
||||
assert.throws(() =>
|
||||
engine.move(role, { type: "ship", ship: 1, good: "coffee" }, 0),
|
||||
);
|
||||
assert.equal(loaded.ships[0].amount, 4);
|
||||
assert.equal(loaded.players[0].vp, 3);
|
||||
assert.deepEqual(engine.legal(loaded), [{ type: "pass" }]);
|
||||
assert.equal(storage.ships[0].amount, 4);
|
||||
assert.equal(storage.players[0].vp, 3);
|
||||
assert.equal(storage.tasks[0].kind, "store");
|
||||
assert(storage.history.some((h) => h.p === 0 && h.move.type === "pass"));
|
||||
assert.throws(() =>
|
||||
engine.move(
|
||||
storage,
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ const definitions = {
|
|||
ship: 0,
|
||||
good: "fruit",
|
||||
})),
|
||||
lesson("pass", "actions", () => ({ type: "pass" })),
|
||||
lesson("store", "actions", () => ({
|
||||
type: "store",
|
||||
types: [],
|
||||
|
|
@ -253,7 +252,7 @@ export const chapters = Object.fromEntries(
|
|||
id,
|
||||
{
|
||||
id,
|
||||
version: 1,
|
||||
version: id === "shipping" ? 2 : 1,
|
||||
titleKey: `tutorial.${id}.title`,
|
||||
descriptionKey: `tutorial.${id}.description`,
|
||||
initialState: definition.initialState,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
body:has(.pr-game) {
|
||||
margin: 0;
|
||||
}
|
||||
.pr-game {
|
||||
--paper: #e8dcc1;
|
||||
--panel: #f7edda;
|
||||
|
|
@ -26,7 +29,7 @@
|
|||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
min-height: 100vh;
|
||||
padding: 0 0 calc(var(--dock-height, 60px) + 24px);
|
||||
padding: 0 16px calc(var(--dock-height, 60px) + 24px);
|
||||
box-sizing: border-box;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
|
@ -1493,7 +1496,7 @@
|
|||
}
|
||||
@media (max-width: 760px) {
|
||||
.pr-game {
|
||||
padding: 0 0 calc(var(--dock-height, 60px) + 24px);
|
||||
padding: 0 8px calc(var(--dock-height, 60px) + 24px);
|
||||
font-size: 13px;
|
||||
}
|
||||
.pr-game .game-header {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue