Add a hand size setup option independent of two tiles per turn

handSize offers 6 (default), 8, 10 or 12 tiles, with or without
twoTiles. Normalized options omit it at the legacy size (6, or 8 with
twoTiles), so games created without it keep their init log and replay
exactly; unknown values are ignored and logged.

Setup, refills, dead-tile replacement and public positions all use the
chosen size. The rack picks columns per hand size with container
queries: one row where it fits, otherwise two even rows, and three rows
of four for 12 tiles on the narrowest phones.
This commit is contained in:
Mike Isom 2026-11-04 07:02:46 -07:00
commit 33cd27df1b
8 changed files with 245 additions and 28 deletions

View file

@ -143,10 +143,34 @@
},
{
"name": "twoTiles",
"label": "Two tiles per turn (hands of 8)",
"label": "Two tiles per turn",
"type": "checkbox",
"default": false
},
{
"name": "handSize",
"label": "Tiles in hand",
"type": "select",
"default": "6",
"items": [
{
"name": "6",
"label": "6 (standard)"
},
{
"name": "8",
"label": "8"
},
{
"name": "10",
"label": "10"
},
{
"name": "12",
"label": "12"
}
]
},
{
"name": "limitedLog",
"label": "Limited game log (only last round)",

View file

@ -14,7 +14,7 @@ There are 7 hotel chains, in three price tiers:
- **Medium:** Worldwide, American, Festival
- **Major:** Imperial, Continental
Each chain has 25 shares. Everyone starts with $6,000 and a hand of 6 tiles. Before the game, each player places one tile from the pool; the lowest tile (by number, then letter) goes first, and play continues in seat order.
Each chain has 25 shares. Everyone starts with $6,000 and a hand of 6 tiles (or 8, 10 or 12 with the Tiles in hand option). Before the game, each player places one tile from the pool; the lowest tile (by number, then letter) goes first, and play continues in seat order.
A chain of 11 or more tiles is **safe**: it can never be taken over.
@ -22,7 +22,7 @@ A chain of 11 or more tiles is **safe**: it can never be taken over.
1. **Place one tile** from your hand.
2. **Buy up to 3 shares** by default, in any active chains (optional; see Shares per turn below).
3. **Draw** back up to 6 tiles.
3. **Draw** back up to 6 tiles (or the game’s hand size).
### What a tile does
@ -39,9 +39,9 @@ A chain of 11 or more tiles is **safe**: it can never be taken over.
### Two tiles per turn
If the game uses **Two tiles per turn**, each player holds 8 tiles instead of 6 and places two tiles every turn.
If the game uses **Two tiles per turn**, each player places two tiles every turn. The number of tiles in hand is a separate option, so you can combine two tiles per turn with any hand size. (Two-tile games started before that option existed use hands of 8.)
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.
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 your hand size.
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.
@ -147,7 +147,8 @@ Because replaying the game would show the full history, replay is only available
## Game options
- **Limited game log:** the log shows only what happened since your last turn, until the game ends (see above).
- **Two tiles per turn:** hands of 8 tiles and two tiles placed every turn (see above).
- **Two tiles per turn:** two tiles placed every turn (see above).
- **Tiles in hand:** 6 (standard), 8, 10 or 12 tiles in each hand, with or without two tiles per turn.
- **Shares per turn:** buy up to 3 (standard), 4 or 5 shares in total per turn, independently of stock swaps.
- **Stock swap:** optional 1:1 exchanges with the bank before buying; Off / 3 / 5 / 7 / Unlimited shares per turn (see above).
- **Public holdings:** everyone's cash and shares are visible.

View file

@ -0,0 +1,106 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { legalMoves } from "./legal.js";
import { applyMove } from "./moves.js";
import { positionAt } from "./position.js";
import { initGame } from "./setup.js";
import { chainAt, checkInvariants, row, scenario, t } from "./test/helpers.js";
import type { GameState, Move } from "./types.js";
import * as wrapper from "../wrapper.js";
const place = (tile: string): Move => ({ type: "place", tile });
const buy: Move = { type: "buy", shares: {} };
function play(state: GameState, seat: number, move: Move): GameState {
applyMove(state, move, seat);
checkInvariants(state);
return state;
}
test("§15 handSize: every seat is dealt the chosen hand in every mode and player count", () => {
for (const handSize of ["6", "8", "10", "12"]) {
for (const twoTiles of [false, true]) {
for (let players = 2; players <= 6; players++) {
const modes = players === 2 ? ["bank", "fourHands"] : ["bank"];
for (const twoPlayerMode of modes) {
const state = initGame(
players,
{ ...(twoTiles && { twoTiles }), ...(players === 4 && { teamPlay: true }), twoPlayerMode, handSize },
`deal-${handSize}-${players}-${twoPlayerMode}-${twoTiles}`
);
checkInvariants(state);
const size = Number(handSize);
assert.ok(state.seats.every((seat) => seat.hand.length === size));
assert.ok(positionAt(state, state.log.length).seats.every((seat) => seat.tiles === size));
const view = wrapper.stripSecret(state, 0);
assert.ok(
view.seats.every((seat) => seat.hand.length === size),
"masked hands keep their size"
);
}
}
}
}
// Six hands of 12 plus six turn-order tiles still leave 30 of the 108 tiles to draw.
assert.equal(initGame(6, { handSize: "12" }, "deal-max").pool.length, 30);
});
test("§15 handSize: the hand refills to the chosen size after a turn", () => {
const hand = ["5E", "9G", "11G", "3I", "6I", "9I", "1G", "1I", "12A", "12C"];
const state = scenario({ hands: [hand, ["12E"]], poolTop: ["12G", "12I"], options: { handSize: "10" } });
play(state, 0, place("5E"));
assert.equal(state.seats[0]!.hand.length, 10);
assert.ok(state.seats[0]!.hand.includes(t("12G")));
assert.ok(!state.seats[0]!.hand.includes(t("12I")));
});
test("§15 handSize: dead tiles are replaced up to the chosen size", () => {
const state = scenario({
board: { ...chainAt("tower", row("A", 1, 11)), ...chainAt("continental", row("C", 1, 11)) },
hands: [["1B", "10G", "12E", "12G", "12I", "10I", "8I", "6I", "4I", "2I", "8G", "6G"], ["5E"]],
options: { handSize: "12" },
});
play(state, 0, place("10G"));
play(state, 0, buy);
assert.ok(state.removed.includes(t("1B")));
assert.equal(state.seats[0]!.hand.length, 12);
assert.deepEqual(state.log.filter((entry) => entry.type === "drew").at(-1), { type: "drew", seat: 0, count: 2 });
});
test("§15 handSize with twoTiles: both tiles are placed, then the hand refills to the chosen size", () => {
const state = scenario({
board: chainAt("tower", ["1A", "2A"]),
hands: [["5E", "9I", "12A", "12C", "12E", "12G"], ["10C"], ["10E"]],
poolTop: ["7G", "7I"],
options: { twoTiles: true, handSize: "6" },
});
assert.equal(state.options.handSize, 6);
play(state, 0, place("5E"));
play(state, 0, place("9I"));
play(state, 0, buy);
assert.equal(state.seats[0]!.hand.length, 6);
assert.deepEqual(state.seats[0]!.hand.slice(-2), [t("7G"), t("7I")]);
});
/** Plays a random game to the end, checking invariants after every move, and replays it. */
function playToEnd(players: number, options: Record<string, unknown>, seed: string): GameState {
const state = wrapper.init(players, [], options, seed);
for (let step = 0; !state.ended; step++) {
assert.ok(step < 5000, `${seed} did not finish`);
const moves = legalMoves(state);
const others = moves.filter((move) => move.type !== "announce");
const choices = others.length > 0 && step % 23 !== 0 ? others : moves;
wrapper.move(state, choices[(step * 7919) % choices.length]!, wrapper.currentPlayer(state)!);
checkInvariants(state);
}
assert.deepEqual(wrapper.replay(structuredClone(state)), state, `§14.7 ${seed} replays exactly`);
return state;
}
test("§14.8 handSize 12: full games finish and replay with 6 players, two-player bank mode and four hands", () => {
playToEnd(6, { handSize: "12" }, "hand-12-six");
playToEnd(6, { handSize: "12", twoTiles: true }, "hand-12-six-two-tiles");
playToEnd(2, { handSize: "12", twoPlayerMode: "bank" }, "hand-12-bank");
playToEnd(2, { handSize: "12", twoPlayerMode: "fourHands", twoTiles: true }, "hand-12-four-hands");
playToEnd(4, { handSize: "10", teamPlay: true, publicHoldings: true }, "hand-10-teams");
});

View file

@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import { test } from "node:test";
import { endConditionHolds } from "./board.js";
import { applyMove } from "./moves.js";
import { DEFAULT_OPTIONS, normalizeOptions } from "./options.js";
import { DEFAULT_OPTIONS, handSize, normalizeOptions } from "./options.js";
import { sharePrice } from "./prices.js";
import { initGame } from "./setup.js";
import { chainAt, checkInvariants, row, scenario } from "./test/helpers.js";
@ -93,6 +93,45 @@ test("§3.5 options are never rejected: unknown values are ignored and logged",
assert.doesNotThrow(() => wrapper.init(2, [], { teamPlay: true, twoPlayerMode: "fourHands", endSize: 7 }, "x"));
});
test("§15 handSize: missing keeps the legacy hand of 6, or 8 with twoTiles, and leaves the init log unchanged", () => {
assert.equal("handSize" in normalizeOptions(3, {}).options, false);
assert.equal(handSize(normalizeOptions(3, {}).options), 6);
assert.equal("handSize" in normalizeOptions(3, { twoTiles: true }).options, false);
assert.equal(handSize(normalizeOptions(3, { twoTiles: true }).options), 8);
const init = initGame(3, {}, "no-hand-size").log[0] as Extract<LogEntry, { type: "init" }>;
assert.deepEqual(init.options, DEFAULT_OPTIONS);
});
test("§15 handSize: every size is read as BGS sends it, alone or with twoTiles; the legacy size is omitted", () => {
for (const twoTiles of [false, true]) {
const legacy = twoTiles ? 8 : 6;
for (const size of [6, 8, 10, 12]) {
for (const sent of [String(size), size]) {
const { options, ignored } = normalizeOptions(3, { ...(twoTiles && { twoTiles }), handSize: sent });
assert.deepEqual(ignored, []);
assert.equal(handSize(options), size);
assert.equal(options.handSize, size === legacy ? undefined : size);
assert.equal("handSize" in options, size !== legacy, `handSize ${sent} with twoTiles ${twoTiles}`);
}
}
}
assert.deepEqual(normalizeOptions(3, { handSize: "10" }).options, { ...DEFAULT_OPTIONS, handSize: 10 });
});
test("§15 handSize: unknown values are ignored and logged, keeping the legacy size", () => {
for (const value of ["7", 7, "", "eight", "08", " 8", 6.5, 14, true, null, ["8"]]) {
for (const twoTiles of [false, true]) {
const state = initGame(3, { ...(twoTiles && { twoTiles }), handSize: value }, "bad-hand-size");
assert.equal("handSize" in state.options, false);
assert.deepEqual(
ignoredLog(state).map((e) => [e.option, e.value, e.reason]),
[["handSize", value, "unknown value"]]
);
assert.ok(state.seats.every((seat) => seat.hand.length === (twoTiles ? 8 : 6)));
}
}
});
test("§15 endSize 31: a 31-tile chain meets the end condition; safe size and prices are unchanged", () => {
const tiles = [...row("A", 1, 12), ...row("B", 1, 12), ...row("C", 1, 7)];
const board = scenario({ board: chainAt("tower", tiles), hands: [["9I"]] }).board;

View file

@ -13,6 +13,8 @@ export interface GameOptions {
sharesPerTurn?: 4 | 5;
/** Omitted when off, like stockSwap. */
twoTiles?: true;
/** Omitted at the legacy size (6, or 8 with twoTiles), so games created before it replay. */
handSize?: 6 | 8 | 10 | 12;
/**
* 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.
@ -37,6 +39,7 @@ export const DEFAULT_OPTIONS: GameOptions = {
};
const END_SIZES = [41, 31];
const HAND_SIZES = [6, 8, 10, 12, "6", "8", "10", "12"];
/**
* Reads the creator's options defensively. BGS omits unticked checkboxes and always sends
@ -107,6 +110,16 @@ export function normalizeOptions(
options.twoTilesRelaxed = true;
}
}
if (raw.handSize !== undefined) {
if (HAND_SIZES.includes(raw.handSize as number | string)) {
const size = Number(raw.handSize) as 6 | 8 | 10 | 12;
if (size !== legacyHandSize(options)) {
options.handSize = size;
}
} else {
ignored.push({ option: "handSize", value: raw.handSize, reason: "unknown value" });
}
}
if (raw.limitedLog === true) {
options.limitedLog = true;
}
@ -119,11 +132,16 @@ export function sharePurchaseLimit(options: GameOptions): number {
return options.sharesPerTurn ?? MAX_BUY;
}
/** rules.md §15 twoTiles: hands hold 8 tiles instead of 6. */
export function handSize(options: GameOptions): number {
/** Games created before the handSize option hold 6 tiles, or 8 with twoTiles. */
function legacyHandSize(options: GameOptions): number {
return options.twoTiles ? TWO_TILE_HAND_SIZE : HAND_SIZE;
}
/** rules.md §15 handSize: the number of tiles each seat draws up to. */
export function handSize(options: GameOptions): number {
return options.handSize ?? legacyHandSize(options);
}
/** Internal seats per real player: fourHands gives each of the 2 players two seats. */
export function seatOwners(players: number, options: GameOptions): number[] {
if (players === 2 && options.twoPlayerMode === "fourHands") {

View file

@ -1,7 +1,7 @@
// Local dev harness (not part of the BGS bundle): runs the real engine in the page, plays
// random moves on request, and lets you view the game as any player or as a spectator.
// URL parameters: players=2..6, seed=..., view=N, hotseat=0, theme=light|dark, locale=de, and any game option, e.g. publicHoldings=1,
// twoPlayerMode=fourHands, teamPlay=1, autoEnd=1, endSize=31. For reproducible screenshots: moves=N plays N random moves,
// twoPlayerMode=fourHands, teamPlay=1, autoEnd=1, endSize=31, twoTiles=1, handSize=12. For reproducible screenshots: moves=N plays N random moves,
// merger=1 then plays on to the next merger decision, bar=0 hides this toolbar.
import * as rules from "acquire-engine";
import { currentSeat, legalMoves, type GameState } from "acquire-engine";
@ -34,7 +34,7 @@ for (const key of ["publicHoldings", "teamPlay", "autoEnd", "twoTiles", "limited
options[key] = true;
}
}
for (const key of ["twoPlayerMode", "endSize", "stockSwap", "sharesPerTurn"]) {
for (const key of ["twoPlayerMode", "endSize", "stockSwap", "sharesPerTurn", "handSize"]) {
const value = params.get(key);
if (value) {
options[key] = value;

View file

@ -1,5 +1,5 @@
<script lang="ts">
import { HIDDEN, parseTile, sortTiles, tileLabel, tileLegality, type Tile } from "acquire-engine";
import { handSize, HIDDEN, parseTile, sortTiles, tileLabel, tileLegality, type Tile } from "acquire-engine";
import { ofType, turnLimit } from "./decisions";
import { seatName } from "./format";
import type { ViewerStore } from "./store.svelte";
@ -40,7 +40,7 @@
{@const limited = hand.filter((tile) => turnLimit(state, seat, tile) !== undefined)}
<section class="hand" aria-label={t("hand.of", { name: seatName(state, seat, store.lang) })}>
<h2>{store.seats.length > 1 ? t("hand.seat", { seat: seat + 1 }) : t("hand.yours")}</h2>
<div class="tiles" class:eight={state.options.twoTiles}>
<div class="tiles" data-size={handSize(state.options)}>
{#each hand as tile, index (index)}
{@const permanent = dead.includes(tile)}
{@const blocked = permanent || paused.includes(tile) || limited.includes(tile)}
@ -102,27 +102,52 @@
<style>
.hand {
margin: 12px 0 0;
container-type: inline-size;
}
.hand:first-child {
margin-top: 0;
}
/* Six tiles fit on one row; the 12px gaps leave room for outlines drawn outside the tiles. */
/* Six tiles fit on one row; the 12px gaps leave room for outlines drawn outside the tiles.
A row of n 52px tiles needs 64n + 4px; 44px tiles need 56n + 4px. */
.tiles {
--columns: 6;
display: grid;
grid-template-columns: repeat(6, minmax(0, 52px));
grid-template-columns: repeat(var(--columns), minmax(0, 52px));
gap: 12px;
padding: 8px;
background: var(--rack);
width: max-content;
max-width: 100%;
}
/* Eight tiles (two tiles per turn) take one row where it fits and two rows of four on phones. */
.tiles.eight {
grid-template-columns: repeat(8, minmax(0, 52px));
/* Larger hands take one row where the rack's column fits it, otherwise two even rows. */
.tiles[data-size="8"] {
--columns: 4;
}
@media (max-width: 560px) {
.tiles.eight {
grid-template-columns: repeat(4, minmax(0, 52px));
.tiles[data-size="10"] {
--columns: 5;
}
.tiles[data-size="12"] {
--columns: 6;
}
@container (min-width: 516px) {
.tiles[data-size="8"] {
--columns: 8;
}
}
@container (min-width: 644px) {
.tiles[data-size="10"] {
--columns: 10;
}
}
@container (min-width: 772px) {
.tiles[data-size="12"] {
--columns: 12;
}
}
/* Narrow phones: three rows of four rather than tiles below the 44px touch size. */
@container (max-width: 339px) {
.tiles[data-size="12"] {
--columns: 4;
}
}
.tile {

View file

@ -41,7 +41,8 @@ original 1976 rules were silent or ambiguous, the choice made here is marked
3. The player who placed the **lowest** tile goes first. Compare by number first, then
letter: `2B` beats `2E` and `3A`. Play then proceeds clockwise (in seat order) from
that player. **[DECISION]** "Clockwise" means ascending seat order, wrapping around.
4. Each player then draws **6** tiles into their private hand.
4. Each player then draws **6** tiles into their private hand (the `handSize` option, §15,
may set 8, 10 or 12).
5. **[DECISION]** Options are never rejected at setup. An option that does not apply to
the player count (see §15) is ignored, and the game log records that it was ignored.
@ -57,7 +58,8 @@ player.
3. **End-of-game announcement** (§11). Optional. **[DECISION]** Allowed at exactly two
points: before placing a tile, and during the buy step (§11.1).
4. **Replace dead tiles** (§5.3).
5. **Draw** one tile to bring the hand back to 6, if the pool is not empty.
5. **Draw** one tile to bring the hand back to 6 (or the `handSize`, §15), if the pool is
not empty.
If the game was announced as over during this turn, run final scoring (§11.2) after
the turn completes instead of passing to the next player.
@ -70,8 +72,7 @@ they cannot buy anything.
### 4.1 Two tiles per turn (house rule)
With `twoTiles` enabled (§15), hands hold **8** tiles instead of 6 (at setup and when
drawing), and each turn places two tiles:
With `twoTiles` enabled (§15), each turn places two tiles:
1. At the start of the turn, the active seat discards its permanently unplayable tiles
(§5.2) and draws replacements. They are not replaced at the end of the turn.
@ -88,10 +89,12 @@ drawing), and each turn places two tiles:
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.
5. Buy (§9, including §9.1 swaps) once, after both tiles, then draw back up to the hand size.
The end may also be announced between the two tiles, if an end condition holds at that
moment. Dropped seats place their first two playable tiles by the §16 default.
moment. Dropped seats place their first two playable tiles by the §16 default. The hand
size is the separate `handSize` option (§15); games created before it hold **8** tiles with
`twoTiles`.
## 5. Placing a Tile
@ -389,7 +392,8 @@ switches on one engine, not as separate code paths. Defaults reproduce the stand
| `autoEnd` | true / false | false | When true, the game ends automatically at the end of the turn in which an end condition (§11.1) first holds, instead of waiting for an announcement. |
| `sharesPerTurn` | 3 / 4 / 5 | 3 | Maximum shares purchased per turn in total across all active chains (house rule). Independent of stock swaps; see §9. |
| `stockSwap` | `off` / 3 / 5 / 7 / `unlimited` | `off` | Optional 1:1 exchanges with the bank before buying, paying or receiving the price difference. See §9.1. |
| `twoTiles` | true / false | false | Hands of 8 tiles and two placements per turn (house rule). See §4.1. |
| `twoTiles` | true / false | false | Two placements per turn (house rule). See §4.1. |
| `handSize` | 6 / 8 / 10 / 12 | 6 | Tiles each seat draws at setup and refills to (house rule), with or without `twoTiles`. **[DECISION]** Without `handSize` in the init options (games created before it), hands hold 6, or 8 with `twoTiles`; normalized options omit `handSize` at that legacy size so those games replay identically. Twelve tiles for each of 6 players use 78 of the 108 tiles at setup, counting turn-order tiles. |
| `limitedLog` | true / false | false | The log shows only what happened since your last turn until the game ends (house rule). See §13. |
| `endSize` | 41 / 31 | 41 | The chain size that triggers the end condition in §11.1. Setting 31 gives a shorter game (house rule). Does not change the safe size (11) or the price table. |