diff --git a/docs/admin/rules.md b/docs/admin/rules.md index 6a76981..b826a54 100644 --- a/docs/admin/rules.md +++ b/docs/admin/rules.md @@ -43,13 +43,15 @@ If the game uses **Two tiles per turn**, each player holds 8 tiles instead of 6 At the start of your turn, swap out any dead tiles. Then place your first tile and settle anything it causes, including a full merger with everyone's sell, trade or keep decisions, before placing your second. After both tiles, buy shares up to the game’s per-turn limit (3 by default) at the prices on the board, then draw back up to 8. -You may found only one chain per turn, and you can't found a chain and cause a merger in the same turn, in either order. You can cause two mergers, one with each tile. Example: your first tile merges Luxor into Tower, so your second tile can merge again or grow a chain, but it can't found a new one. +You may found only one chain per turn, and your second tile can't cause a merger involving the chain your first tile founded. Otherwise each tile follows the usual rules: you can merge and then found a chain, found a chain and then merge two other chains, or cause two mergers, one with each tile. Example: your first tile founds Worldwide, so your second tile can merge Luxor into Tower or grow Worldwide, but it can't found another chain or cause a merger involving Worldwide. You must play a second tile if any tile in your hand is legal after the first. If none is, go straight to buying. A tile that becomes dead during your turn, for example because your first tile made a chain safe, can't be your second tile; it's swapped out at the start of your next turn. You can announce the end of the game before your first tile, between your two tiles, or while buying, as long as an end condition holds at that moment. -In a two-player game, the bank's tiles are placed right after the merger that drew them, so between your two tiles if your first tile caused it. Mergers caused by the bank's tiles don't count toward your two mergers or the founding rule. If a player leaves, the game places their first two legal tiles for them. +Two-tile games started before this rule was relaxed keep the earlier limit: a turn can't both found a chain and cause a merger, in either order (mergers caused by the bank's tiles don't count). + +In a two-player game, the bank's tiles are placed right after the merger that drew them, so between your two tiles if your first tile caused it. If a player leaves, the game places their first two legal tiles for them. ## Mergers diff --git a/packages/engine/index.ts b/packages/engine/index.ts index 3f3986d..c80f20b 100644 --- a/packages/engine/index.ts +++ b/packages/engine/index.ts @@ -19,4 +19,10 @@ export * from "./src/replay.js"; export * from "./src/position.js"; export * from "./src/simple.js"; export { logWindowStart } from "./src/limited-log.js"; -export { blockedThisTurn, secondPlacementDue, turnPlacements } from "./src/two-tiles.js"; +export { + blockedThisTurn, + secondPlacementDue, + turnPlacements, + twoTileLimit, + type TwoTileLimit, +} from "./src/two-tiles.js"; diff --git a/packages/engine/src/moves.ts b/packages/engine/src/moves.ts index 1a10f8a..5ebb342 100644 --- a/packages/engine/src/moves.ts +++ b/packages/engine/src/moves.ts @@ -17,9 +17,15 @@ import { sharePrice } from "./prices.js"; import { canAnnounce, endGame } from "./scoring.js"; import { parseTile, tileLabel, type Tile } from "./tiles.js"; import { afterPlacement, endTurn, enterBuyPhase } from "./turn.js"; -import { blockedThisTurn } from "./two-tiles.js"; +import { twoTileLimit, type TwoTileLimit } from "./two-tiles.js"; import type { GameState, Move, Shares } from "./types.js"; +const TWO_TILE_LIMIT_ERRORS: Record = { + oneFounding: "A turn cannot found two chains", + mergeFounded: "A turn cannot merge the chain it founded", + foundOrMerge: "A turn cannot both found a chain and cause a merger", +}; + export function currentSeat(state: GameState): number | undefined { if (state.ended) { return undefined; @@ -88,8 +94,9 @@ export function sanitizeMove(state: GameState, raw: unknown, seat: number): Move if (tileLegality(state.board, tile) !== "playable") { throw new Error(`Tile ${tileLabel(tile)} cannot be played now`); } - if (blockedThisTurn(state, tile)) { - throw new Error("A turn cannot found two chains, or both found a chain and cause a merger"); + const limit = twoTileLimit(state, tile); + if (limit !== undefined) { + throw new Error(TWO_TILE_LIMIT_ERRORS[limit]); } return { type: "place", tile: tileLabel(tile) }; } diff --git a/packages/engine/src/options.ts b/packages/engine/src/options.ts index ded5bc5..315bc10 100644 --- a/packages/engine/src/options.ts +++ b/packages/engine/src/options.ts @@ -13,6 +13,11 @@ export interface GameOptions { sharesPerTurn?: 4 | 5; /** Omitted when off, like stockSwap. */ twoTiles?: true; + /** + * Set with twoTiles in games created under the relaxed founding/merger limits (rules.md + * §4.1). Two-tile games logged before them lack it and keep the original limits. + */ + twoTilesRelaxed?: true; /** Omitted when off, like stockSwap. */ limitedLog?: true; } @@ -37,11 +42,13 @@ const END_SIZES = [41, 31]; * Reads the creator's options defensively. BGS omits unticked checkboxes and always sends * selects (as strings), so a missing checkbox means false. Options are never rejected * (rules.md §3.5/§15): anything that does not apply, or has an unknown value, is ignored - * and reported so the log can say so. + * and reported so the log can say so. Replay passes the options `recorded` in the game's + * init log, so games created under an earlier rule revision rebuild with that revision. */ export function normalizeOptions( players: number, - raw: Record + raw: Record, + recorded?: Partial ): { options: GameOptions; ignored: IgnoredOption[] } { const options: GameOptions = { ...DEFAULT_OPTIONS }; const ignored: IgnoredOption[] = []; @@ -96,6 +103,9 @@ export function normalizeOptions( if (raw.twoTiles === true) { options.twoTiles = true; + if (recorded === undefined || recorded.twoTilesRelaxed === true) { + options.twoTilesRelaxed = true; + } } if (raw.limitedLog === true) { options.limitedLog = true; diff --git a/packages/engine/src/replay.ts b/packages/engine/src/replay.ts index d6f4684..3d9f597 100644 --- a/packages/engine/src/replay.ts +++ b/packages/engine/src/replay.ts @@ -15,7 +15,7 @@ export function replayGame(data: GameState, to: number = data.log.length): GameS if (!data.seed || first?.type !== "init") { throw new Error("Replay needs the full game state, including the seed"); } - const state = initGame(first.players, first.rawOptions, data.seed); + const state = initGame(first.players, first.rawOptions, data.seed, first.options); checkLog(state, data, 0); while (state.log.length < to) { const checked = state.log.length; diff --git a/packages/engine/src/setup.ts b/packages/engine/src/setup.ts index 49951ad..db31352 100644 --- a/packages/engine/src/setup.ts +++ b/packages/engine/src/setup.ts @@ -1,5 +1,5 @@ import { CHAIN_IDS, MAX_PLAYERS, MIN_PLAYERS, SHARES_PER_CHAIN, STARTING_CASH } from "./config.js"; -import { handSize, normalizeOptions, seatOwners } from "./options.js"; +import { handSize, normalizeOptions, seatOwners, type GameOptions } from "./options.js"; import { shuffle } from "./prng.js"; import { allTiles } from "./tiles.js"; import { drawTile, startTurn } from "./turn.js"; @@ -9,12 +9,20 @@ function sharesOf(count: number): Shares { return Object.fromEntries(CHAIN_IDS.map((chain) => [chain, count])) as Shares; } -/** Creates a game for `players` real players; fourHands gives each of them two seats. */ -export function initGame(players: number, rawOptions: Record, seed: string): GameState { +/** + * Creates a game for `players` real players; fourHands gives each of them two seats. Replay + * passes the init log's `recorded` options to keep the rules the game was created with. + */ +export function initGame( + players: number, + rawOptions: Record, + seed: string, + recorded?: Partial +): GameState { if (!Number.isInteger(players) || players < MIN_PLAYERS || players > MAX_PLAYERS) { throw new Error(`Acquire needs ${MIN_PLAYERS} to ${MAX_PLAYERS} players`); } - const { options, ignored } = normalizeOptions(players, rawOptions); + const { options, ignored } = normalizeOptions(players, rawOptions, recorded); const seatOwner = seatOwners(players, options); const seats = seatOwner.length; const state: GameState = { diff --git a/packages/engine/src/two-tiles.spec.ts b/packages/engine/src/two-tiles.spec.ts index 349178f..b46e416 100644 --- a/packages/engine/src/two-tiles.spec.ts +++ b/packages/engine/src/two-tiles.spec.ts @@ -4,6 +4,7 @@ import * as wrapper from "../wrapper.js"; import { legalMoves } from "./legal.js"; import { applyMove, currentSeat, dropPlayerSeats } from "./moves.js"; import { normalizeOptions } from "./options.js"; +import { blockedThisTurn, turnPlacements, twoTileLimit } from "./two-tiles.js"; import { positionAt } from "./position.js"; import { initGame } from "./setup.js"; import { turnSummary } from "./simple.js"; @@ -82,41 +83,61 @@ test("§15 twoTiles: the second tile is skipped when none is playable", () => { assert.deepEqual(placeable(state), []); }); -test("§15 twoTiles: after founding, a tile that would found or merge is blocked; growing is allowed", () => { - const state = scenario({ - board: { ...chainAt("tower", ["1E", "2E"]), ...chainAt("luxor", ["4E", "5E"]), "8A": "loose", "1A": "loose" }, - hands: [["9A", "3E", "6E", "2A"], ["12C"], ["12E"]], - poolOnly: true, - options: TWO_TILES, - }); - assert.deepEqual(placeable(state), ["9A", "3E", "6E", "2A"]); - play(state, 0, place("9A")); - play(state, 0, { type: "found", chain: "american" }); - assert.deepEqual(placeable(state), ["6E"]); - for (const tile of ["3E", "2A"]) { - assert.throws(() => applyMove(state, place(tile), 0), /cannot found two chains/); - } - play(state, 0, place("6E")); - assert.equal(state.phase, "buy"); -}); +// Two pairs of chains to merge, and loose tiles to found a chain next to. +const LIMITS_BOARD = { + ...chainAt("tower", ["1A", "2A"]), + ...chainAt("luxor", ["4A", "5A"]), + ...chainAt("american", ["1E", "2E"]), + ...chainAt("festival", ["4E", "5E"]), + "8G": "loose", + "1I": "loose", +} as const; -test("§15 twoTiles: a turn may cause two mergers, but not a merger and a founding", () => { +test("§4.1 twoTiles: a merger with the first tile, then a founding with the second, is allowed", () => { const state = scenario({ - board: { - ...chainAt("tower", ["1A", "2A"]), - ...chainAt("luxor", ["4A", "5A"]), - ...chainAt("american", ["1E", "2E"]), - ...chainAt("festival", ["4E", "5E"]), - "8G": "loose", - }, - hands: [["3A", "3E", "9G"], ["12C"], ["12E"]], + board: LIMITS_BOARD, + hands: [["3A", "9G"], ["12C"], ["12E"]], poolOnly: true, options: TWO_TILES, }); play(state, 0, place("3A")); play(state, 0, { type: "survivor", chain: "tower" }); assert.equal(state.phase, "place"); - assert.deepEqual(placeable(state), ["3E"], "9G would found a chain after a merger"); + assert.deepEqual(placeable(state), ["9G"]); + play(state, 0, place("9G")); + play(state, 0, { type: "found", chain: "worldwide" }); + assert.equal(state.phase, "buy"); + play(state, 0, buy); + assert.equal(turnSummary(state, state.log.length - 1), "Player 1 merged Luxor into Tower, founded Worldwide"); +}); + +test("§4.1 twoTiles: a founding with the first tile, then a merger of two other chains, is allowed", () => { + const state = scenario({ + board: LIMITS_BOARD, + hands: [["9G", "3A", "3E"], ["12C"], ["12E"]], + poolOnly: true, + options: TWO_TILES, + }); + play(state, 0, place("9G")); + play(state, 0, { type: "found", chain: "worldwide" }); + assert.deepEqual(placeable(state), ["3A", "3E"]); + play(state, 0, place("3E")); + play(state, 0, { type: "survivor", chain: "american" }); + assert.equal(state.phase, "buy"); + play(state, 0, buy); + assert.equal(turnSummary(state, state.log.length - 1), "Player 1 founded Worldwide, merged Festival into American"); +}); + +test("§4.1 twoTiles: a merger, then another merger, is allowed", () => { + const state = scenario({ + board: LIMITS_BOARD, + hands: [["3A", "3E", "9G"], ["12C"], ["12E"]], + poolOnly: true, + options: TWO_TILES, + }); + play(state, 0, place("3A")); + play(state, 0, { type: "survivor", chain: "tower" }); + assert.deepEqual(placeable(state), ["3E", "9G"]); play(state, 0, place("3E")); play(state, 0, { type: "survivor", chain: "american" }); assert.equal(state.phase, "buy"); @@ -127,16 +148,53 @@ test("§15 twoTiles: a turn may cause two mergers, but not a merger and a foundi ); }); -test("§15 twoTiles: a founding first rules out a merger with the second tile", () => { +test("§4.1 twoTiles: a turn cannot found two chains; growing the new chain is allowed", () => { const state = scenario({ - board: { ...chainAt("tower", ["1A", "2A"]), ...chainAt("luxor", ["4A", "5A"]), "8G": "loose" }, - hands: [["9G", "3A"], ["12C"], ["12E"]], + board: LIMITS_BOARD, + hands: [["9G", "2I", "10G"], ["12C"], ["12E"]], poolOnly: true, options: TWO_TILES, }); play(state, 0, place("9G")); - play(state, 0, { type: "found", chain: "american" }); - assert.deepEqual(placeable(state), [], "3A would merge after a founding"); + play(state, 0, { type: "found", chain: "worldwide" }); + assert.equal(twoTileLimit(state, t("2I")), "oneFounding"); + assert.throws(() => applyMove(state, place("2I"), 0), /cannot found two chains/); + assert.deepEqual(placeable(state), ["10G"]); + play(state, 0, place("10G")); + assert.equal(state.phase, "buy"); +}); + +test("§4.1 twoTiles: the second tile cannot merge the chain founded this turn", () => { + // 9G founds a chain with 8G; 7G would then merge it with Imperial. + const state = scenario({ + board: { ...LIMITS_BOARD, ...chainAt("imperial", ["6G", "6H"]) }, + hands: [["9G", "7G", "3A"], ["12C"], ["12E"]], + poolOnly: true, + options: TWO_TILES, + }); + assert.equal(twoTileLimit(state, t("7G")), undefined); + play(state, 0, place("9G")); + play(state, 0, { type: "found", chain: "worldwide" }); + assert.equal(twoTileLimit(state, t("7G")), "mergeFounded"); + assert.equal(twoTileLimit(state, t("3A")), undefined); + assert.throws(() => applyMove(state, place("7G"), 0), /cannot merge the chain it founded/); + assert.deepEqual(placeable(state), ["3A"]); + play(state, 0, place("3A")); + play(state, 0, { type: "survivor", chain: "luxor" }); + play(state, 0, buy); + assert.equal(twoTileLimit(state, t("7G")), undefined, "the limit ends with the turn"); +}); + +test("§4.1 twoTiles: the second tile is skipped when only a merger with the new chain remains", () => { + const state = scenario({ + board: { ...LIMITS_BOARD, ...chainAt("imperial", ["6G", "6H"]) }, + hands: [["9G", "7G"], ["12C"], ["12E"]], + poolOnly: true, + options: TWO_TILES, + }); + play(state, 0, place("9G")); + play(state, 0, { type: "found", chain: "worldwide" }); + assert.deepEqual(placeable(state), []); assert.equal(state.phase, "buy"); }); @@ -275,3 +333,76 @@ test("§14.7 twoTiles games replay exactly", () => { } assert.deepEqual(wrapper.replay(state), state); }); + +/** Two-tile games created before the relaxed limits have no `twoTilesRelaxed` option. */ +function legacy(state: GameState): GameState { + delete state.options.twoTilesRelaxed; + const init = state.log[0]; + if (init?.type === "init") { + delete init.options.twoTilesRelaxed; + } + return state; +} + +test("§4.1 twoTiles: new games record the relaxed limits; replay keeps a game's own revision", () => { + assert.equal(normalizeOptions(3, TWO_TILES).options.twoTilesRelaxed, true); + assert.equal("twoTilesRelaxed" in normalizeOptions(3, {}).options, false); + assert.equal("twoTilesRelaxed" in normalizeOptions(3, TWO_TILES, { twoTiles: true }).options, false); + assert.equal(normalizeOptions(3, TWO_TILES, { twoTiles: true, twoTilesRelaxed: true }).options.twoTilesRelaxed, true); + assert.equal("twoTilesRelaxed" in normalizeOptions(3, {}, { twoTilesRelaxed: true }).options, false); +}); + +test("§4.1 twoTiles in games created before the relaxed limits: no founding and merger in one turn", () => { + const foundThenMerge = legacy( + scenario({ + board: LIMITS_BOARD, + hands: [["9G", "3A", "12A"], ["12C"], ["12E"]], + poolOnly: true, + options: TWO_TILES, + }) + ); + play(foundThenMerge, 0, place("9G")); + play(foundThenMerge, 0, { type: "found", chain: "worldwide" }); + assert.equal(twoTileLimit(foundThenMerge, t("3A")), "foundOrMerge"); + assert.throws(() => applyMove(foundThenMerge, place("3A"), 0), /cannot both found a chain and cause a merger/); + assert.deepEqual(placeable(foundThenMerge), ["12A"]); + + const mergeThenFound = legacy( + scenario({ board: LIMITS_BOARD, hands: [["3A", "9G", "3E"], ["12C"], ["12E"]], poolOnly: true, options: TWO_TILES }) + ); + play(mergeThenFound, 0, place("3A")); + play(mergeThenFound, 0, { type: "survivor", chain: "tower" }); + assert.equal(twoTileLimit(mergeThenFound, t("9G")), "foundOrMerge"); + assert.deepEqual(placeable(mergeThenFound), ["3E"], "two mergers are still allowed"); +}); + +test("§4.1 twoTiles in games created before the relaxed limits: bank-caused mergers do not count", () => { + const state = legacy( + scenario({ board: LIMITS_BOARD, hands: [["12A", "9G"], ["12C"], ["12E"]], poolOnly: true, options: TWO_TILES }) + ); + play(state, 0, place("12A")); + state.log.push({ type: "merger", seat: 0, tile: t("3A"), sizes: { tower: 2, luxor: 2 }, byBank: true }); + assert.equal(turnPlacements(state).merged, false); + assert.equal(twoTileLimit(state, t("9G")), undefined); + state.log.push({ type: "merger", seat: 0, tile: t("3E"), sizes: { american: 2, festival: 2 } }); + assert.equal(turnPlacements(state).merged, true); + assert.equal(twoTileLimit(state, t("9G")), "foundOrMerge"); +}); + +test("§14.7 twoTiles games created before the relaxed limits replay under them", () => { + const state = legacy(initGame(3, TWO_TILES, "legacy-two-tiles")); + let differs = false; + for (let i = 0; i < 400 && !state.ended; i++) { + if (state.phase === "place") { + const relaxed = { ...state, options: { ...state.options, twoTilesRelaxed: true as const } }; + differs ||= state.seats[state.activeSeat]!.hand.some( + (tile) => blockedThisTurn(state, tile) && !blockedThisTurn(relaxed, tile) + ); + } + const moves = legalMoves(state).filter((move) => move.type !== "announce"); + play(state, currentSeat(state)!, moves[(i * 7919) % moves.length]!); + } + assert.ok(differs, "the game reaches a turn where the original limits block a tile"); + assert.equal("twoTilesRelaxed" in state.options, false); + assert.deepEqual(wrapper.replay(structuredClone(state)), state); +}); diff --git a/packages/engine/src/two-tiles.ts b/packages/engine/src/two-tiles.ts index fe90707..9f7c620 100644 --- a/packages/engine/src/two-tiles.ts +++ b/packages/engine/src/two-tiles.ts @@ -1,10 +1,25 @@ import { placementEffect } from "./board.js"; +import type { ChainId } from "./config.js"; import type { Tile } from "./tiles.js"; import type { GameState } from "./types.js"; -/** What the active seat's placements have done so far this turn, read from the log. */ -export function turnPlacements(state: GameState): { placed: number; founded: boolean; merged: boolean } { - const result = { placed: 0, founded: false, merged: false }; +/** + * Why rules.md §15 twoTiles rules out a tile this turn: `oneFounding` (a second founding), + * `mergeFounded` (a merger involving the chain founded this turn), or, in games created + * under the original limits, `foundOrMerge` (a founding and a merger in one turn). + */ +export type TwoTileLimit = "oneFounding" | "mergeFounded" | "foundOrMerge"; + +/** + * What the active seat's placements have done so far this turn, read from the log: how many + * tiles it placed, the chain it founded (if any) and whether it caused a merger. + */ +export function turnPlacements(state: GameState): { placed: number; founded: ChainId | null; merged: boolean } { + const result: { placed: number; founded: ChainId | null; merged: boolean } = { + placed: 0, + founded: null, + merged: false, + }; for (let i = state.log.length - 1; i >= 0; i--) { const entry = state.log[i]!; if (entry.type === "turn") { @@ -13,7 +28,7 @@ export function turnPlacements(state: GameState): { placed: number; founded: boo if (entry.type === "move" && entry.move.type === "place") { result.placed++; } else if (entry.type === "founded") { - result.founded = true; + result.founded = entry.chain; } else if (entry.type === "merger" && !entry.byBank) { // rules.md §15 twoTiles: mergers caused by bank tiles do not count. result.merged = true; @@ -23,16 +38,30 @@ export function turnPlacements(state: GameState): { placed: number; founded: boo } /** - * rules.md §15 twoTiles: a turn founds at most one chain, and never both founds a chain and - * causes a merger. Whether `tile` is ruled out by what this turn's placements already did. + * rules.md §4.1: a turn founds at most one chain, and its second tile cannot merge the chain + * its first tile founded. Games created before the relaxed limits (no `twoTilesRelaxed`) + * also forbid founding and merging in the same turn, in either order. */ -export function blockedThisTurn(state: GameState, tile: Tile): boolean { +export function twoTileLimit(state: GameState, tile: Tile): TwoTileLimit | undefined { if (!state.options.twoTiles) { - return false; + return undefined; } const { founded, merged } = turnPlacements(state); - const effect = placementEffect(state.board, tile).kind; - return (effect === "found" && (founded || merged)) || (effect === "merge" && founded); + const effect = placementEffect(state.board, tile); + if (effect.kind === "found" && founded !== null) { + return "oneFounding"; + } + if (!state.options.twoTilesRelaxed) { + return (effect.kind === "found" && merged) || (effect.kind === "merge" && founded !== null) + ? "foundOrMerge" + : undefined; + } + return effect.kind === "merge" && founded !== null && effect.chains.includes(founded) ? "mergeFounded" : undefined; +} + +/** Whether `tile` is ruled out by what this turn's placements already did (rules.md §4.1). */ +export function blockedThisTurn(state: GameState, tile: Tile): boolean { + return twoTileLimit(state, tile) !== undefined; } /** rules.md §15 twoTiles: whether the active seat places another tile before buying. */ diff --git a/packages/viewer/src/lib/Hand.svelte b/packages/viewer/src/lib/Hand.svelte index a8b008a..00d28c6 100644 --- a/packages/viewer/src/lib/Hand.svelte +++ b/packages/viewer/src/lib/Hand.svelte @@ -85,7 +85,7 @@ {paused.map(tileLabel).join(", ")} — {t("hand.eighth")} {/if} - {#each ["oneFounding", "foundOrMerge"] as const as limit (limit)} + {#each ["oneFounding", "mergeFounded", "foundOrMerge"] as const as limit (limit)} {@const tiles = limited.filter((tile) => turnLimit(state, seat, tile) === limit)} {#if tiles.length}
  • diff --git a/packages/viewer/src/lib/decisions.spec.ts b/packages/viewer/src/lib/decisions.spec.ts index 30c29c1..53a0c2f 100644 --- a/packages/viewer/src/lib/decisions.spec.ts +++ b/packages/viewer/src/lib/decisions.spec.ts @@ -137,8 +137,15 @@ test("two-tile limits explain exactly the tiles the engine blocks this turn", () continue; } assert.ok(!placeable.includes(tileLabel(tile))); - const founding = placementEffect(state.board, tile).kind === "found"; - assert.equal(limit, founding && turnPlacements(state).founded ? "oneFounding" : "foundOrMerge"); + const effect = placementEffect(state.board, tile); + const { founded } = turnPlacements(state); + assert.ok(founded, "only a founding earlier this turn limits the second tile"); + if (effect.kind === "merge") { + assert.equal(limit, "mergeFounded"); + assert.ok(effect.chains.includes(founded)); + } else { + assert.deepEqual([effect.kind, limit], ["found", "oneFounding"]); + } assert.equal(turnLimit(state, (seat + 1) % 4, tile), undefined, "limits apply only to the active seat"); } const view = stripSecret(state, seat); diff --git a/packages/viewer/src/lib/decisions.ts b/packages/viewer/src/lib/decisions.ts index d05d2f0..364abcc 100644 --- a/packages/viewer/src/lib/decisions.ts +++ b/packages/viewer/src/lib/decisions.ts @@ -1,18 +1,18 @@ // Which choices the viewer offers. Validity always comes from the engine: these helpers only // filter and look up engine.legalMoves(), so no rule is re-implemented here. import { - blockedThisTurn, CHAIN_IDS, chainSize, currentSeat, legalMoves, placementEffect, - turnPlacements, + twoTileLimit, type ChainId, type GameState, type Move, type Shares, type Tile, + type TwoTileLimit, } from "acquire-engine"; import { chainName, type Lang } from "./format.ts"; @@ -49,13 +49,8 @@ export function describePlacement(state: GameState, tile: Tile, lang: Lang): str * Why `tile` in `seat`'s hand can't be placed this turn under the two-tiles limits * (rules.md §4.1), or undefined when they don't block it. */ -export function turnLimit(state: GameState, seat: number, tile: Tile): "oneFounding" | "foundOrMerge" | undefined { - if (seat !== state.activeSeat || state.ended || !blockedThisTurn(state, tile)) { - return undefined; - } - return placementEffect(state.board, tile).kind === "found" && turnPlacements(state).founded - ? "oneFounding" - : "foundOrMerge"; +export function turnLimit(state: GameState, seat: number, tile: Tile): TwoTileLimit | undefined { + return seat === state.activeSeat && !state.ended ? twoTileLimit(state, tile) : undefined; } function sameShares(a: Partial, b: Partial): boolean { diff --git a/packages/viewer/src/lib/locales/da.ts b/packages/viewer/src/lib/locales/da.ts index 9763fa5..ed02812 100644 --- a/packages/viewer/src/lib/locales/da.ts +++ b/packages/viewer/src/lib/locales/da.ts @@ -92,6 +92,7 @@ export const da: Catalog = { "hand.eighth": "kan ikke grundlægge en 8. kæde", "hand.deadNextTurn": "Udskiftes ved starten af din næste tur", "hand.oneFounding": "kan ikke grundlægge en kæde mere i denne tur", + "hand.mergeFounded": "kan ikke fusionere kæden, du grundlagde i denne tur", "hand.foundOrMerge": "kan ikke både grundlægge en kæde og fusionere i samme tur", "chains.label": "Hotelkæder", "chains.title": "Kæder", diff --git a/packages/viewer/src/lib/locales/de.ts b/packages/viewer/src/lib/locales/de.ts index 9d29e49..da1f95b 100644 --- a/packages/viewer/src/lib/locales/de.ts +++ b/packages/viewer/src/lib/locales/de.ts @@ -92,6 +92,7 @@ export const de: Catalog = { "hand.eighth": "keine 8. Kette möglich", "hand.deadNextTurn": "Werden zu Beginn deines nächsten Zuges ersetzt", "hand.oneFounding": "keine zweite Kettengründung in diesem Zug", + "hand.mergeFounded": "keine Fusion mit der in diesem Zug gegründeten Kette", "hand.foundOrMerge": "nicht Gründung und Fusion im selben Zug", "chains.label": "Hotelketten", "chains.title": "Ketten", diff --git a/packages/viewer/src/lib/locales/el.ts b/packages/viewer/src/lib/locales/el.ts index 18a7588..1f4deb6 100644 --- a/packages/viewer/src/lib/locales/el.ts +++ b/packages/viewer/src/lib/locales/el.ts @@ -92,6 +92,7 @@ export const el: Catalog = { "hand.eighth": "δεν ιδρύεται 8η αλυσίδα", "hand.deadNextTurn": "Αντικατάσταση στην αρχή του επόμενου γύρου σου", "hand.oneFounding": "δεν ιδρύεται δεύτερη αλυσίδα σε αυτόν τον γύρο", + "hand.mergeFounded": "όχι συγχώνευση της αλυσίδας που ιδρύθηκε σε αυτόν τον γύρο", "hand.foundOrMerge": "όχι ίδρυση αλυσίδας και συγχώνευση στον ίδιο γύρο", "chains.label": "Αλυσίδες ξενοδοχείων", "chains.title": "Αλυσίδες", diff --git a/packages/viewer/src/lib/locales/en.ts b/packages/viewer/src/lib/locales/en.ts index 24b24de..72bb38e 100644 --- a/packages/viewer/src/lib/locales/en.ts +++ b/packages/viewer/src/lib/locales/en.ts @@ -99,6 +99,7 @@ export const en = { "hand.eighth": "can't found an 8th chain", "hand.deadNextTurn": "Replaced at the start of your next turn", "hand.oneFounding": "can't found a second chain this turn", + "hand.mergeFounded": "can't merge the chain you founded this turn", "hand.foundOrMerge": "can't both found a chain and merge in one turn", // Chain and price tables diff --git a/packages/viewer/src/lib/locales/fa.ts b/packages/viewer/src/lib/locales/fa.ts index a6987d4..81e9da7 100644 --- a/packages/viewer/src/lib/locales/fa.ts +++ b/packages/viewer/src/lib/locales/fa.ts @@ -92,6 +92,7 @@ export const fa: Catalog = { "hand.eighth": "زنجیره‌ی هشتم ممکن نیست", "hand.deadNextTurn": "در آغاز نوبت بعدی شما جایگزین می‌شوند", "hand.oneFounding": "در این نوبت زنجیره‌ی دوم ممکن نیست", + "hand.mergeFounded": "ادغام زنجیره‌ای که در این نوبت تأسیس شد ممکن نیست", "hand.foundOrMerge": "تأسیس زنجیره و ادغام در یک نوبت ممکن نیست", "chains.label": "زنجیره‌های هتل", "chains.title": "زنجیره‌ها", diff --git a/packages/viewer/src/lib/locales/fr.ts b/packages/viewer/src/lib/locales/fr.ts index 58714c6..eef96ae 100644 --- a/packages/viewer/src/lib/locales/fr.ts +++ b/packages/viewer/src/lib/locales/fr.ts @@ -97,6 +97,7 @@ export const fr: Catalog = { "hand.eighth": "impossible de fonder une 8e chaîne", "hand.deadNextTurn": "Remplacement au début de votre prochain tour", "hand.oneFounding": "impossible de fonder une deuxième chaîne ce tour-ci", + "hand.mergeFounded": "impossible de fusionner la chaîne fondée ce tour-ci", "hand.foundOrMerge": "impossible de fonder une chaîne et de fusionner dans le même tour", "chains.label": "Chaînes d’hôtels", "chains.title": "Chaînes", diff --git a/packages/viewer/src/lib/locales/hi.ts b/packages/viewer/src/lib/locales/hi.ts index a50fb98..f4b95e7 100644 --- a/packages/viewer/src/lib/locales/hi.ts +++ b/packages/viewer/src/lib/locales/hi.ts @@ -91,6 +91,7 @@ export const hi: Catalog = { "hand.eighth": "8वीं श्रृंखला स्थापित नहीं हो सकती", "hand.deadNextTurn": "आपकी अगली बारी की शुरुआत में बदल दी जाएँगी", "hand.oneFounding": "इस बारी में दूसरी श्रृंखला स्थापित नहीं हो सकती", + "hand.mergeFounded": "इस बारी में स्थापित श्रृंखला का विलय नहीं हो सकता", "hand.foundOrMerge": "एक ही बारी में श्रृंखला स्थापित करना और विलय दोनों नहीं हो सकते", "chains.label": "होटल श्रृंखलाएँ", "chains.title": "श्रृंखलाएँ", diff --git a/packages/viewer/src/lib/locales/it.ts b/packages/viewer/src/lib/locales/it.ts index 2283e7b..a340711 100644 --- a/packages/viewer/src/lib/locales/it.ts +++ b/packages/viewer/src/lib/locales/it.ts @@ -96,6 +96,7 @@ export const it: Catalog = { "hand.eighth": "non si può fondare un'8ª catena", "hand.deadNextTurn": "Sostituite all'inizio del tuo prossimo turno", "hand.oneFounding": "non si può fondare una seconda catena in questo turno", + "hand.mergeFounded": "non si può fondere la catena fondata in questo turno", "hand.foundOrMerge": "non si può fondare una catena e fondere nello stesso turno", "chains.label": "Catene alberghiere", "chains.title": "Catene", diff --git a/packages/viewer/src/lib/locales/ko.ts b/packages/viewer/src/lib/locales/ko.ts index 147f95b..f605af6 100644 --- a/packages/viewer/src/lib/locales/ko.ts +++ b/packages/viewer/src/lib/locales/ko.ts @@ -92,6 +92,7 @@ export const ko: Catalog = { "hand.eighth": "8번째 체인은 세울 수 없음", "hand.deadNextTurn": "다음 차례가 시작될 때 교체됩니다", "hand.oneFounding": "이번 차례에 두 번째 체인은 세울 수 없음", + "hand.mergeFounded": "이번 차례에 세운 체인은 합병할 수 없음", "hand.foundOrMerge": "한 차례에 체인 설립과 합병을 모두 할 수 없음", "chains.label": "호텔 체인", "chains.title": "체인", diff --git a/packages/viewer/src/lib/locales/nl.ts b/packages/viewer/src/lib/locales/nl.ts index 27f6faa..667ccab 100644 --- a/packages/viewer/src/lib/locales/nl.ts +++ b/packages/viewer/src/lib/locales/nl.ts @@ -92,6 +92,7 @@ export const nl: Catalog = { "hand.eighth": "kan geen 8e keten stichten", "hand.deadNextTurn": "Worden aan het begin van je volgende beurt vervangen", "hand.oneFounding": "kan deze beurt geen tweede keten stichten", + "hand.mergeFounded": "kan de keten die je deze beurt stichtte niet laten fuseren", "hand.foundOrMerge": "kan niet in één beurt een keten stichten én fuseren", "chains.label": "Hotelketens", "chains.title": "Ketens", diff --git a/packages/viewer/src/lib/locales/pl.ts b/packages/viewer/src/lib/locales/pl.ts index 6859e82..b3be556 100644 --- a/packages/viewer/src/lib/locales/pl.ts +++ b/packages/viewer/src/lib/locales/pl.ts @@ -97,6 +97,7 @@ export const pl: Catalog = { "hand.eighth": "nie można założyć 8. sieci", "hand.deadNextTurn": "Wymiana na początku twojej następnej tury", "hand.oneFounding": "nie można założyć drugiej sieci w tej turze", + "hand.mergeFounded": "nie można połączyć sieci założonej w tej turze", "hand.foundOrMerge": "nie można w jednej turze założyć sieci i połączyć sieci", "chains.label": "Sieci hoteli", "chains.title": "Sieci", diff --git a/packages/viewer/src/lib/locales/pt-BR.ts b/packages/viewer/src/lib/locales/pt-BR.ts index c51152f..55ec4ee 100644 --- a/packages/viewer/src/lib/locales/pt-BR.ts +++ b/packages/viewer/src/lib/locales/pt-BR.ts @@ -96,6 +96,7 @@ export const ptBR: Catalog = { "hand.eighth": "não dá para fundar uma 8ª rede", "hand.deadNextTurn": "Substituição no início do seu próximo turno", "hand.oneFounding": "não dá para fundar uma segunda rede neste turno", + "hand.mergeFounded": "não dá para fundir a rede fundada neste turno", "hand.foundOrMerge": "não dá para fundar uma rede e fundir no mesmo turno", "chains.label": "Redes de hotéis", "chains.title": "Redes", diff --git a/packages/viewer/src/lib/locales/ro.ts b/packages/viewer/src/lib/locales/ro.ts index b9a5c83..e515a4e 100644 --- a/packages/viewer/src/lib/locales/ro.ts +++ b/packages/viewer/src/lib/locales/ro.ts @@ -97,6 +97,7 @@ export const ro: Catalog = { "hand.eighth": "nu se poate înființa un al 8-lea lanț", "hand.deadNextTurn": "Înlocuire la începutul turei tale următoare", "hand.oneFounding": "nu se poate înființa un al doilea lanț în această tură", + "hand.mergeFounded": "nu se poate face fuziunea lanțului înființat în această tură", "hand.foundOrMerge": "nu se poate înființa un lanț și face o fuziune în aceeași tură", "chains.label": "Lanțuri hoteliere", "chains.title": "Lanțuri", diff --git a/packages/viewer/src/lib/locales/ru.ts b/packages/viewer/src/lib/locales/ru.ts index 1befbc9..e25b442 100644 --- a/packages/viewer/src/lib/locales/ru.ts +++ b/packages/viewer/src/lib/locales/ru.ts @@ -97,6 +97,7 @@ export const ru: Catalog = { "hand.eighth": "нельзя основать 8-ю сеть", "hand.deadNextTurn": "Заменяются в начале вашего следующего хода", "hand.oneFounding": "нельзя основать вторую сеть за этот ход", + "hand.mergeFounded": "нельзя слить сеть, основанную в этот ход", "hand.foundOrMerge": "нельзя за один ход и основать сеть, и провести слияние", "chains.label": "Гостиничные сети", "chains.title": "Сети", diff --git a/packages/viewer/src/lib/locales/vi.ts b/packages/viewer/src/lib/locales/vi.ts index 31da1c9..5ae941a 100644 --- a/packages/viewer/src/lib/locales/vi.ts +++ b/packages/viewer/src/lib/locales/vi.ts @@ -92,6 +92,7 @@ export const vi: Catalog = { "hand.eighth": "không thể lập chuỗi thứ 8", "hand.deadNextTurn": "Được thay khi bắt đầu lượt sau của bạn", "hand.oneFounding": "không thể lập chuỗi thứ hai trong lượt này", + "hand.mergeFounded": "không thể sáp nhập chuỗi vừa lập trong lượt này", "hand.foundOrMerge": "không thể vừa lập chuỗi vừa sáp nhập trong cùng một lượt", "chains.label": "Chuỗi khách sạn", "chains.title": "Chuỗi", diff --git a/packages/viewer/src/lib/locales/zh-CN.ts b/packages/viewer/src/lib/locales/zh-CN.ts index cef1e6e..fe306d9 100644 --- a/packages/viewer/src/lib/locales/zh-CN.ts +++ b/packages/viewer/src/lib/locales/zh-CN.ts @@ -91,6 +91,7 @@ export const zhCN: Catalog = { "hand.eighth": "无法创立第 8 个连锁", "hand.deadNextTurn": "在你下一回合开始时更换", "hand.oneFounding": "本回合不能再创立第二个连锁", + "hand.mergeFounded": "不能合并本回合创立的连锁", "hand.foundOrMerge": "同一回合内不能既创立连锁又进行合并", "chains.label": "酒店连锁", "chains.title": "连锁", diff --git a/packages/viewer/src/lib/locales/zh-TW.ts b/packages/viewer/src/lib/locales/zh-TW.ts index 21274ed..04a45e3 100644 --- a/packages/viewer/src/lib/locales/zh-TW.ts +++ b/packages/viewer/src/lib/locales/zh-TW.ts @@ -91,6 +91,7 @@ export const zhTW: Catalog = { "hand.eighth": "無法創立第 8 個連鎖", "hand.deadNextTurn": "在你下一回合開始時更換", "hand.oneFounding": "本回合不能再創立第二個連鎖", + "hand.mergeFounded": "不能合併本回合創立的連鎖", "hand.foundOrMerge": "同一回合內不能既創立連鎖又進行合併", "chains.label": "飯店連鎖", "chains.title": "連鎖", diff --git a/rules.md b/rules.md index cf7343e..772dff3 100644 --- a/rules.md +++ b/rules.md @@ -81,9 +81,13 @@ drawing), and each turn places two tiles: 3. Place the second tile if any tile in hand is playable now; otherwise go straight to buying. A tile that became permanently unplayable during this turn cannot be placed and is replaced at the start of the seat's next turn. -4. A turn founds at most one chain, and never both founds a chain and causes a merger, in - either order. It may cause two mergers, one per tile. Mergers caused by bank tiles do - not count towards these limits. +4. A turn founds at most one chain, and the second tile cannot cause a merger involving the + chain the first tile founded (as survivor or defunct). Otherwise each tile follows the + usual rules: a merger may be followed by a founding or another merger, and a founding by + a merger of other chains. **[DECISION]** Games created before this revision (init + options without `twoTilesRelaxed`) keep the earlier limit, also when replayed: a turn + never both founds a chain and causes a merger, in either order, and mergers caused by + bank tiles do not count towards it. 5. Buy (§9, including §9.1 swaps) once, after both tiles, then draw back up to 8. The end may also be announced between the two tiles, if an end condition holds at that diff --git a/scripts/check-browser.mjs b/scripts/check-browser.mjs index 1fec20f..75cbb59 100644 --- a/scripts/check-browser.mjs +++ b/scripts/check-browser.mjs @@ -170,6 +170,7 @@ try { await page.evaluate((state) => { const { parseTile, allTiles } = window.acquireDev.rules; state.options.twoTiles = true; + state.options.twoTilesRelaxed = true; state.options.limitedLog = true; state.board[parseTile("1C")] = "loose"; state.seats[0].hand = ["2A", "3A", "2C", "5E", "7E", "9E", "7G", "9G"].map(parseTile);