Enable hosted one-player games with two automatic Puertomas
This commit is contained in:
parent
0f9c08aad3
commit
1f01dfe04f
9 changed files with 172 additions and 22 deletions
|
|
@ -3,7 +3,7 @@
|
|||
## Product decisions
|
||||
|
||||
- Target **Puerto Rico 1897: Special Edition**, including the June 2026 errata. Keep one fixed release configuration (`release-config.js`); expansion switches are internal, with no expansion picker in BGS or the viewer.
|
||||
- Read [source notes](docs/sources.md) before changing rules. Achievements and Puertoma use the sourced decks documented there. Festival's unique-building reservation remains an explicit interpretation. Keep local Puertoma separate from ordinary hosted bot seats, and do not invent components.
|
||||
- Read [source notes](docs/sources.md) before changing rules. Achievements and Puertoma use the sourced decks documented there. Festival's unique-building reservation remains an explicit interpretation. Choosing one platform participant automatically creates two virtual Puertomas; multiplayer bot seats still use human rules. Keep those modes distinct, and do not invent components.
|
||||
- Use BGS locale and color-blind preferences, without duplicate controls. Favor readable pictograms with tooltips; colors must not be the only identifiers. Role warnings remain advisory, never forbidding a legal strategic choice.
|
||||
- The local preview skips the market draft and saves progress in the browser. Preserve the user's session; use a separate browser context for destructive playtests.
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[Play now at boardgamers.space](https://boardgamers.space/boardgame/puerto-rico)
|
||||
|
||||
Implementation for Boardgamers Space, targeting **Puerto Rico 1897: Special Edition** and the official June 2026 errata. Version 1 is published as a **private beta** on [BGS](https://boardgamers.space/boardgame/puerto-rico), with Unlisted disabled. The engine package is `@boardgamers/puerto-rico@0.2.1`; English and French are configured in the platform metadata.
|
||||
Implementation for Boardgamers Space, targeting **Puerto Rico 1897: Special Edition** and the official June 2026 errata. Version 1 is published as a **private beta** on [BGS](https://boardgamers.space/boardgame/puerto-rico), with Unlisted disabled. The engine package is `@boardgamers/puerto-rico@0.2.2`; English and French are configured in the platform metadata.
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
|
|
@ -27,9 +27,9 @@ Implemented modules:
|
|||
- Festival: three shared objectives and physical resource reservations.
|
||||
- Festival Activities: all 12 activity definitions, three drawn per game.
|
||||
- Achievements: the complete 30-card deck, secret dealing, optional internal draft, automatic completion and endgame scoring.
|
||||
- Puertoma: exact eight-card tiebreaker deck, shared action tracker, permanent workers, estate production, building levels and reservations, all 12 ability types, three difficulty levels and expansion interactions. Available through local solo preview or internal `options.puertoma = { humans: 1, difficulty: "normal" }` with three total seats.
|
||||
- Puertoma: exact eight-card tiebreaker deck, shared action tracker, permanent workers, estate production, building levels and reservations, all 12 ability types, three difficulty levels and expansion interactions. Available by choosing 1 player on BGS, through local solo preview, or internal `options.puertoma = { humans: 1, difficulty: "normal" }` with three total seats.
|
||||
|
||||
The fixed multiplayer BGS configuration includes all six expansion modules. Puertoma is available locally; hosted bot seats continue to use the human rules. See [source notes](docs/sources.md) for provenance and the Festival unique-building marker interpretation.
|
||||
The fixed multiplayer BGS configuration includes all six expansion modules. Choose **1 player** on BGS to start a solo game against **two automatic Puertomas** at normal difficulty. Their turns resolve automatically on the server; the platform tracks only the human participant, while the viewer and replay show all three boards and final scores. Hosted multiplayer bot seats continue to use the human rules. See [source notes](docs/sources.md) for provenance and the Festival unique-building marker interpretation.
|
||||
|
||||
The engine accepts the optional `costSwap`, `alternativeStart`, `tailorLimit`, `pairingRestrictions` and `achievementDraft` balance variants internally. They are disabled in the fixed configuration and not exposed in the UI.
|
||||
|
||||
|
|
@ -56,6 +56,6 @@ The implementation remains a preview pending playtesting, and the Festival marke
|
|||
|
||||
## Private BGS publication
|
||||
|
||||
`pnpm publish:private` builds the bundles, packages only the self-contained engine and its manifest, checks complete 2–5-player games from the extracted package, and uploads the engine/viewer to BGS. The script reads the admin token from `~/.bgs` without logging it, preserves the existing game/request identity, refuses to replace a public version, and verifies the private/listed flags and CDN bytes. It grants beta access to `coyotte508` if needed. Metadata snapshots and package artifacts stay in ignored `.local/release/`.
|
||||
`pnpm publish:private` builds the bundles, packages only the self-contained engine and its manifest, checks complete 1–5-player games from the extracted package, and uploads the engine/viewer to BGS. The script reads the admin token from `~/.bgs` without logging it, preserves the existing game/request identity, refuses to replace a public version, and verifies the private/listed flags and CDN bytes. It grants beta access to `coyotte508` if needed. Metadata snapshots and package artifacts stay in ignored `.local/release/`.
|
||||
|
||||
The hosted bundle has no local preview controls or runtime asset dependencies. Global BGS locale and color-blind preferences are handled by the viewer; expansion switches remain internal. Tutorials are not yet registered.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,74 @@
|
|||
export * from "../engine/index.js";
|
||||
import { init as create } from "../engine/index.js";
|
||||
import * as game from "../engine/index.js";
|
||||
import { RELEASE } from "../release-config.js";
|
||||
export function init(players, _expansions, _options, seed) {
|
||||
return create(players, RELEASE.expansions, RELEASE.options, seed);
|
||||
|
||||
const solo = (s) => s.options.hostedSolo === true;
|
||||
function checkSeat(s, p) {
|
||||
if (solo(s) && p !== 0)
|
||||
throw Error(
|
||||
"Puertomas are automatic opponents, not platform participants.",
|
||||
);
|
||||
}
|
||||
function opponents(s) {
|
||||
if (!solo(s)) return s;
|
||||
// BGS has one participant. Resolve the virtual opponents on the server before
|
||||
// returning, so the platform never waits for a nonexistent participant.
|
||||
let moves = 0;
|
||||
while (!game.ended(s) && game.currentPlayer(s) !== 0) {
|
||||
if (++moves > 1000)
|
||||
throw Error("Puertoma turns did not return to the human player.");
|
||||
s = game.moveAI(s);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
export function init(players, _expansions, _options, seed) {
|
||||
const options =
|
||||
players === 1
|
||||
? {
|
||||
...RELEASE.options,
|
||||
hostedSolo: true,
|
||||
puertoma: { humans: 1, difficulty: "normal" },
|
||||
}
|
||||
: RELEASE.options;
|
||||
const s = game.init(
|
||||
players === 1 ? 3 : players,
|
||||
RELEASE.expansions,
|
||||
options,
|
||||
seed,
|
||||
);
|
||||
if (players === 1)
|
||||
s.players.slice(1).forEach((p, i) => (p.name = `Puertoma ${i + 1}`));
|
||||
return opponents(s);
|
||||
}
|
||||
export function move(s, m, p) {
|
||||
checkSeat(s, p);
|
||||
return opponents(game.move(s, m, p));
|
||||
}
|
||||
export function moveAI(s, p = game.currentPlayer(s)) {
|
||||
checkSeat(s, p);
|
||||
return opponents(game.moveAI(s, p));
|
||||
}
|
||||
export function dropPlayer(s, p) {
|
||||
checkSeat(s, p);
|
||||
return game.dropPlayer(s, p);
|
||||
}
|
||||
export function setPlayerMetaData(s, p, data) {
|
||||
checkSeat(s, p);
|
||||
return game.setPlayerMetaData(s, p, data);
|
||||
}
|
||||
export function scores(s) {
|
||||
const result = game.scores(s);
|
||||
return solo(s) ? result.slice(0, 1) : result;
|
||||
}
|
||||
export function rankings(s) {
|
||||
// The human's rank still compares against both Puertomas, while BGS receives
|
||||
// exactly one result per registered participant.
|
||||
const result = game.rankings(s);
|
||||
return solo(s) ? result.slice(0, 1) : result;
|
||||
}
|
||||
|
||||
export function createAnalysis(s, options) {
|
||||
const copy = game.createAnalysis(s, options);
|
||||
if (solo(copy)) copy.players.slice(1).forEach((p) => (p.bot = true));
|
||||
return opponents(copy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"label": "Puerto Rico: Special Edition",
|
||||
"public": false,
|
||||
"players": [2, 3, 4, 5],
|
||||
"description": "Choose roles, develop your island, produce goods and ship them for points. This Special Edition adaptation includes New Buildings, Citizens, Smuggler, Festival Festival Activities and Achievements, in one fixed configuration for 2–5 players.",
|
||||
"players": [1, 2, 3, 4, 5],
|
||||
"description": "Choose roles, develop your island, produce goods and ship them for points. This Special Edition adaptation includes New Buildings, Citizens, Smuggler, Festival, Festival Activities and Achievements, in one fixed configuration for 1–5 players. Choose 1 player to play against two automatic Puertomas.",
|
||||
"rules": "Choose a role, then all players carry out its action in turn; the player who chose it receives a privilege. Plant estates, recruit workers, construct buildings and produce goods. Sell goods for money or ship them for points. When everyone has chosen their roles, pass the governor marker and begin the next round. Most points from shipping, buildings and bonuses wins.\n\n[Official Special Edition rules (English)](https://awakenrealms.com/images/download/puerto-rico/EN/EN_PR_Rulebook_210x285mm_bleed3mm%20%5B44%20pages%5D.pdf). In-game help is available in English and French.",
|
||||
"credits": "Designed by **Andreas Seyfarth**. Based on **Puerto Rico 1897: Special Edition**, published by **Awaken Realms** and **Ravensburger**.\n\nOriginal vector interface illustrations for this digital adaptation. The private multiplayer playtest includes all six modules listed above. Puertoma solo mode is available in the local preview.",
|
||||
"credits": "Designed by **Andreas Seyfarth**. Based on **Puerto Rico 1897: Special Edition**, published by **Awaken Realms** and **Ravensburger**.\n\nOriginal vector interface illustrations for this digital adaptation. The private multiplayer playtest includes all six modules listed above. Choosing 1 player starts solo mode against two automatic Puertomas.",
|
||||
"links": {
|
||||
"publisher": "https://awakenrealms.com/games/awaken-realms/puerto-rico"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/puerto-rico",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Puerto Rico 1897 Special Edition for Boardgamers Space",
|
||||
|
|
|
|||
|
|
@ -57,20 +57,24 @@ export async function packageEngine() {
|
|||
const engine = await import(
|
||||
pathToFileURL(join(unpacked, "package/dist/engine.js"))
|
||||
);
|
||||
for (const players of [2, 3, 4, 5]) {
|
||||
for (const players of [1, 2, 3, 4, 5]) {
|
||||
let state = engine.init(players, [], {}, `release-${players}`);
|
||||
assert.deepEqual(state.expansions, RELEASE.expansions);
|
||||
let moves = 0;
|
||||
while (!engine.ended(state) && moves++ < 6000)
|
||||
while (!engine.ended(state) && moves++ < 6000) {
|
||||
if (players === 1) assert.equal(engine.currentPlayer(state), 0);
|
||||
state = engine.moveAI(state);
|
||||
}
|
||||
assert.ok(
|
||||
engine.ended(state),
|
||||
`Packed engine completes a ${players}-player game`,
|
||||
);
|
||||
assert.equal(engine.scores(state).length, players);
|
||||
assert.equal(engine.rankings(state).length, players);
|
||||
if (players === 1) assert.equal(state.players.length, 3);
|
||||
}
|
||||
console.log(
|
||||
`Packed ${name}@${version}: only bundled engine + manifest; 2–5-player games passed.`,
|
||||
`Packed ${name}@${version}: only bundled engine + manifest; 1–5-player games passed.`,
|
||||
);
|
||||
return { tarball, name, version };
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ if (!access.some((u) => u.username === "coyotte508"))
|
|||
const published = await api("/1"),
|
||||
meta = await api("/meta");
|
||||
assert.equal(published.public, false);
|
||||
assert.deepEqual(published.players, defaults.players);
|
||||
assert.ok(!meta.unlisted);
|
||||
assert.equal(published.engine.package.version, version);
|
||||
assert.equal(published.viewer.url, uploaded.url);
|
||||
|
|
|
|||
81
test/bgs-solo.test.js
Normal file
81
test/bgs-solo.test.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as host from "../bgs/engine.js";
|
||||
import * as game from "../engine/index.js";
|
||||
import { RELEASE } from "../release-config.js";
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
test("platform advertises 1–5 players; one participant gets two normal Puertomas", () => {
|
||||
const metadata = JSON.parse(
|
||||
readFileSync(new URL("../bgs/game.json", import.meta.url)),
|
||||
);
|
||||
assert.deepEqual(metadata.players, [1, 2, 3, 4, 5]);
|
||||
const s = host.init(1, [], {}, "host-solo");
|
||||
assert.equal(s.players.length, 3);
|
||||
assert.deepEqual(
|
||||
s.players.slice(1).map((p) => p.name),
|
||||
["Puertoma 1", "Puertoma 2"],
|
||||
);
|
||||
assert(s.players.slice(1).every((p) => p.bot && p.puertoma));
|
||||
assert.equal(s.puertoma.difficulty, "normal");
|
||||
assert.equal(host.currentPlayer(s), 0);
|
||||
assert.equal(host.scores(s).length, 1);
|
||||
assert.equal(host.rankings(s).length, 1);
|
||||
assert.equal(s.tasks[0].kind, "achievementChoose");
|
||||
assert.equal(game.stripSecret(s, 0).players[0].achievementOffer.length, 6);
|
||||
assert.throws(() => host.moveAI(s, 1));
|
||||
assert.throws(() => host.setPlayerMetaData(s, 1, { name: "Human" }));
|
||||
});
|
||||
test("a hosted solo game always returns to the human and fully replays virtual turns", () => {
|
||||
let s = host.init(1, [], {}, "host-solo-complete");
|
||||
s = host.setPlayerMetaData(s, 0, { name: "Alice" });
|
||||
const initial = structuredClone(s);
|
||||
let actions = 0;
|
||||
while (!host.ended(s) && actions++ < 1500) {
|
||||
assert.equal(host.currentPlayer(s), 0);
|
||||
assert(host.legal(s, 0).length);
|
||||
const input = s,
|
||||
before = structuredClone(s),
|
||||
m = game.chooseAI(s, 0);
|
||||
s = host.move(s, m, 0);
|
||||
assert.deepEqual(input, before);
|
||||
if (actions === 10) assert.deepEqual(before, host.replay(before));
|
||||
assert.equal(host.scores(s).length, 1);
|
||||
}
|
||||
assert(host.ended(s));
|
||||
assert(s.history.some((h) => h.p === 1));
|
||||
assert(s.history.some((h) => h.p === 2));
|
||||
assert.deepEqual(host.replay(s), s);
|
||||
const botPosition = s.history.findIndex((h) => h.p === 1) + 1;
|
||||
const sandbox = host.createAnalysis(s, { to: botPosition });
|
||||
assert.equal(host.currentPlayer(sandbox), 0);
|
||||
assert(sandbox.players.slice(1).every((p) => p.bot));
|
||||
assert.equal(host.scores(sandbox).length, 1);
|
||||
assert.deepEqual(host.rankings(s), [game.rankings(s)[0]]);
|
||||
const all = game.stripSecret(s, 0);
|
||||
assert.equal(all.results.length, 3);
|
||||
const frame = host.logSlice(s, { player: 0, start: 0, end: 0 }).frames[0];
|
||||
assert.equal(frame.players.length, 3);
|
||||
assert.equal(frame.players[0].name, "Alice");
|
||||
assert.equal(frame.puertoma.deck, undefined);
|
||||
assert.deepEqual(initial, host.replay(initial));
|
||||
});
|
||||
test("multiplayer creation and moves keep the existing human rules and result counts", () => {
|
||||
for (const n of [2, 3, 4, 5]) {
|
||||
const s = host.init(n, [], {}, `host-multi-${n}`);
|
||||
assert.deepEqual(
|
||||
s,
|
||||
game.init(n, RELEASE.expansions, RELEASE.options, `host-multi-${n}`),
|
||||
);
|
||||
assert.equal(s.puertoma, undefined);
|
||||
assert.equal(host.scores(s).length, n);
|
||||
assert.equal(host.rankings(s).length, n);
|
||||
assert.deepEqual(host.moveAI(s), game.moveAI(s));
|
||||
}
|
||||
});
|
||||
test("older multiplayer saves still use their original configuration", () => {
|
||||
let s = game.init(3, ["smuggler"], {}, "old-save");
|
||||
s = game.moveAI(s);
|
||||
assert.deepEqual(host.moveAI(s), game.moveAI(s));
|
||||
assert.equal(host.scores(s).length, 3);
|
||||
});
|
||||
|
|
@ -4,6 +4,7 @@ import { chromium } from "playwright";
|
|||
import { createServer } from "node:http";
|
||||
import { readFile, mkdir } from "node:fs/promises";
|
||||
import * as E from "../engine/index.js";
|
||||
import * as hosted from "../bgs/engine.js";
|
||||
import { RELEASE } from "../release-config.js";
|
||||
const server = createServer(async (req, res) => {
|
||||
res.setHeader(
|
||||
|
|
@ -203,20 +204,15 @@ try {
|
|||
assert.ok(composer.y + composer.height <= 844);
|
||||
await page.keyboard.press("Escape");
|
||||
// Achievement selection sends a real legal move; opponents see card backs.
|
||||
let solo = E.init(
|
||||
3,
|
||||
RELEASE.expansions,
|
||||
{ puertoma: { humans: 1 } },
|
||||
"browser-solo",
|
||||
);
|
||||
let solo = hosted.init(1, [], {}, "browser-solo");
|
||||
await page.evaluate((s) => host.emit("state", s), E.stripSecret(solo, 0));
|
||||
assert.equal(await page.locator(".achievement-choices button").count(), 6);
|
||||
await page.locator(".achievement-choices button").first().click();
|
||||
const card = await page.evaluate(() => played.at(-1));
|
||||
assert.equal(card.type, "achievementChoose");
|
||||
solo = E.move(solo, card, 0);
|
||||
solo = hosted.move(solo, card, 0);
|
||||
while (["achievementChoose", "draft"].includes(solo.tasks[0]?.kind))
|
||||
solo = E.moveAI(solo);
|
||||
solo = hosted.moveAI(solo);
|
||||
await page.evaluate((s) => host.emit("state", s), E.stripSecret(solo, 0));
|
||||
assert.equal(await page.locator(".achievement-card").count(), 4);
|
||||
assert.equal(await overflow(), false, `Achievement layout at ${width}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue