Outline safe chains with a double perimeter

This commit is contained in:
coyotte508 2026-10-24 22:47:09 +02:00
commit 99b346a099
7 changed files with 150 additions and 7 deletions

View file

@ -1,10 +1,14 @@
# Acquire private beta — 23 October 2026
# Acquire private beta — 24 October 2026
Private BGS registration: `acquire`, version `1`. Engine `0.0.2`, viewer `0.0.14`.
Private BGS registration: `acquire`, version `1`. Engine `0.0.2`, viewer `0.0.15`.
Source: <https://github.com/boardgamers/mergers-game>. Keep `public: false`.
## Validation
- Safe chains have a contrasting double perimeter, with interior tile seams left unchanged.
The chain table's safe label uses the same double border. Checks cover the 11-tile threshold,
irregular shapes and holes, board edges, placement/undo, both themes and narrow screens.
- Merger disposal has sell-all and maximum-trade shortcuts alongside the quantity controls.
Sale totals use the absorbed chain's price; trade gains/losses compare the shares surrendered
with the survivor shares received at the post-merger price. Shortcuts wait for Confirm,
@ -30,7 +34,7 @@ Source: <https://github.com/boardgamers/mergers-game>. Keep `public: false`.
Desktop/phone checks exercise repeated undo, saved-state refreshes, final history and clock totals.
- `pnpm check`: formatting, lint, TypeScript/Svelte checks, 207 engine tests,
64 viewer/tutorial tests, and the production build. Two pre-existing lint warnings
66 viewer/tutorial tests, and the production build. Two pre-existing lint warnings
remain (an unused test import and Svelte's `bind:this` assignment).
- Protocol diagnostics: all eight required engine methods; full core/chat/replay
viewer coverage, preferences, avatars and theme handlers. Protocol `0.10.0` is the

View file

@ -1,6 +1,6 @@
{
"name": "acquire-viewer",
"version": "0.0.14",
"version": "0.0.15",
"private": true,
"description": "Browser viewer for Acquire on boardgamers.space",
"license": "AGPL-3.0-only",

View file

@ -12,6 +12,7 @@
import { ofType } from "./decisions";
import { chainName } from "./format";
import { CHAIN_STYLES } from "./palette";
import { safeBorders } from "./safeBorders";
import { useStore } from "./store.svelte";
let {
@ -34,6 +35,8 @@
const store = useStore();
const t = $derived(store.lang.t);
const playable = $derived(new Set(ofType(store.moves, "place").map((move) => parseTile(move.tile)!)));
const borders = $derived(safeBorders(state.board));
const safeChains = $derived(new Set(borders.map(({ chain }) => chain)));
const held = $derived(
new Set(
store.replayAt === undefined && !store.readOnly
@ -96,11 +99,14 @@
</div>
{:else}
{@const style = CHAIN_STYLES[cell]}
{@const safe = safeChains.has(cell)}
<div
class="square chain"
class:safe
style:background={style.fill}
style:color={style.text}
aria-label={t("board.chain", { tile: label, chain: chainName(cell) })}
aria-label={`${t("board.chain", { tile: label, chain: chainName(cell) })}${safe ? ` — ${t("chains.safe")}` : ""}`}
title={safe ? `${chainName(cell)} — ${t("chains.safe")}` : undefined}
>
<span class="corner-label">{label}</span>
<span class="letter">{style.letter}</span>
@ -108,6 +114,22 @@
{/if}
{/each}
{/each}
{#if borders.length > 0}
<svg
class="safe-borders"
viewBox={`0 0 ${BOARD_COLUMNS} ${BOARD_ROWS}`}
preserveAspectRatio="none"
aria-hidden="true"
>
{#each borders as { chain, path } (chain)}
<g data-chain={chain}>
<path d={path} stroke={CHAIN_STYLES[chain].text} stroke-width="5" />
<path d={path} stroke={CHAIN_STYLES[chain].fill} stroke-width="3" />
<path d={path} stroke={CHAIN_STYLES[chain].text} stroke-width="1" />
</g>
{/each}
</svg>
{/if}
</div>
</div>
@ -140,12 +162,27 @@
}
/* The dark board shows through 2px gaps between squares; the gaps are not outlines. */
.board {
position: relative;
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
gap: 2px;
padding: 2px;
background: var(--gap);
}
.safe-borders {
/* Inset to the centre of the outside gap: each SVG unit is one tile plus its 2px gap. */
position: absolute;
inset: 1px;
width: calc(100% - 2px);
height: calc(100% - 2px);
overflow: visible;
pointer-events: none;
}
.safe-borders path {
fill: none;
stroke-linecap: square;
vector-effect: non-scaling-stroke;
}
.square {
position: relative;
aspect-ratio: 1;
@ -240,4 +277,8 @@
font-size: 8px;
line-height: 1;
}
.chain.safe .corner-label {
top: 4px;
left: 5px;
}
</style>

View file

@ -55,8 +55,9 @@
color: var(--ink-muted);
}
.safe {
margin-left: 6px;
padding: 0 4px;
margin-inline-start: 6px;
padding: 0 3px;
border: 3px double var(--on-accent);
font-size: 11px;
font-weight: 600;
background: var(--accent);

View file

@ -0,0 +1,41 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { parseTile, TILE_COUNT, type Cell } from "acquire-engine";
import { safeBorders } from "./safeBorders.ts";
test("safe borders appear at 11 tiles, omit interior seams, and disappear when a position is restored", () => {
const board: Cell[] = Array(TILE_COUNT).fill(null);
for (let column = 1; column <= 10; column++) {
board[parseTile(`${column}A`)!] = "tower";
}
assert.deepEqual(safeBorders(board), []);
board[parseTile("11A")!] = "tower";
const [outline] = safeBorders(board);
assert.equal(outline!.chain, "tower");
assert.equal(outline!.path.split(" ").length, 24, "an 11 × 1 footprint has 24 exterior unit edges");
assert.deepEqual(
outline!.path.split(" ").filter((edge) => edge.endsWith("v1")),
["M0,0v1", "M11,0v1"]
);
board[parseTile("11A")!] = null;
assert.deepEqual(safeBorders(board), []);
});
test("safe borders follow concave edges and enclosed gaps at the bottom-right board boundary", () => {
const board: Cell[] = Array(TILE_COUNT).fill(null);
for (let x = 8; x < 12; x++) {
for (let y = 5; y < 9; y++) {
if (x === 8 || x === 11 || y === 5 || y === 8) {
board[x * 9 + y] = "continental";
}
}
}
board[parseTile("1A")!] = "luxor";
const borders = safeBorders(board);
assert.equal(borders.length, 1);
const edges = borders[0]!.path.split(" ");
assert.equal(edges.length, 24, "16 exterior edges plus 8 around the empty centre");
for (const edge of ["M12,8v1", "M11,9h1", "M9,6h1", "M9,6v1", "M11,7v1", "M10,8h1"]) {
assert.ok(edges.includes(edge), edge);
}
});

View file

@ -0,0 +1,30 @@
import { BOARD_COLUMNS, BOARD_ROWS, CHAIN_IDS, isSafe, type Cell } from "acquire-engine";
/** Trace exposed tile edges only, leaving the interior grid of a safe chain unobstructed. */
export function safeBorders(board: Cell[]) {
return CHAIN_IDS.filter((chain) => isSafe(board, chain)).map((chain) => {
const edges: string[] = [];
const matches = (x: number, y: number) =>
x >= 0 && x < BOARD_COLUMNS && y >= 0 && y < BOARD_ROWS && board[x * BOARD_ROWS + y] === chain;
for (let x = 0; x < BOARD_COLUMNS; x++) {
for (let y = 0; y < BOARD_ROWS; y++) {
if (!matches(x, y)) {
continue;
}
if (!matches(x, y - 1)) {
edges.push(`M${x},${y}h1`);
}
if (!matches(x + 1, y)) {
edges.push(`M${x + 1},${y}v1`);
}
if (!matches(x, y + 1)) {
edges.push(`M${x},${y + 1}h1`);
}
if (!matches(x - 1, y)) {
edges.push(`M${x},${y}v1`);
}
}
}
return { chain, path: edges.join(" ") };
});
}

View file

@ -271,6 +271,10 @@ try {
assert.match(await page.locator(".paused-note").innerText(), /12I.*can't found an 8th chain/);
assert.match(await page.locator(".square.dead").getAttribute("aria-label"), /5D.*would merge safe chains/);
assert.equal(await page.locator("button.tile.dead, button.tile.paused, button.square.dead").count(), 0);
assert.equal(await page.locator(".safe-borders g").count(), 2);
assert.equal(await page.locator(".square.chain.safe").count(), 22);
assert.match(await page.locator(".square.chain.safe").first().getAttribute("aria-label"), /safe/);
assert.equal(await page.locator(".safe-borders").evaluate((node) => getComputedStyle(node).pointerEvents), "none");
for (const theme of ["dark", "light"]) {
await page.evaluate((theme) => window.acquireDev.emitter.emit("theme", { dark: theme === "dark" }), theme);
for (const locale of locales) {
@ -295,12 +299,34 @@ try {
await page
.locator("section.hand")
.screenshot({ path: new URL(`dead-tiles-${theme}-${width}.png`, output).pathname });
await page.locator(".frame").screenshot({ path: new URL(`safe-chains-${theme}-${width}.png`, output).pathname });
}
}
report.scenarios.push(
"dead tiles and temporary blocks: distinct symbols, readable coordinates and notes, equal tile heights, all locales in both themes"
);
await open("players=3&hotseat=0&view=0&theme=dark");
await page.evaluate((state) => {
const { allTiles, parseTile } = window.acquireDev.rules;
state.board[parseTile("11A")] = null;
state.seats[0].hand = [parseTile("11A")];
const held = new Set(state.seats.flatMap((seat) => seat.hand));
state.pool = allTiles().filter((tile) => state.board[tile] === null && !held.has(tile));
window.acquireDev.load(state);
}, preparedPosition("scoring"));
await settle();
assert.equal(await page.locator(".safe-borders").count(), 0);
await page.getByRole("button", { name: "Place 11A", exact: true }).click();
await page.waitForSelector('.safe-borders [data-chain="tower"]');
assert.equal(await page.locator(".square.chain.safe").count(), 11);
await page.getByRole("button", { name: "Undo", exact: true }).click();
await page.waitForSelector(".safe-borders", { state: "detached" });
assert.equal(await page.locator(".square.chain.safe").count(), 0);
report.scenarios.push(
"safe chain perimeter: both themes, narrow screens, 11-tile threshold, private placement and undo"
);
for (const theme of ["light", "dark"]) {
await page.setViewportSize({ width: 1920, height: 1280 });
await open(`players=4&moves=95&publicHoldings=1&theme=${theme}`);