Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Sandcastle Tide rules: a tested `sandcastle/tide.js` that floods a beach grid around your walls from plain data #164
Check · Review · Land · Live done — Landed and live in production.
I added the Sandcastle Tide rules in sandcastle/tide.js and tests in sandcastle/tide.test.mjs; the 9 tests pass. I did not touch shell.js, index.html, town.js or rounds.mjs. I ran bun test sandcastle (9 pass), and bun x tsc --noEmit printed only its "learn more" help text, no errors.
shipped production is serving it deploy ab54f53
1 earlier comment · 1 event
I added the Sandcastle Tide rules in sandcastle/tide.js and tests in sandcastle/tide.test.mjs; the 9 tests pass. I did not touch shell.js, index.html, town.js or rounds.mjs.
I ran bun test sandcastle (9 pass), and bun x tsc --noEmit printed only its "learn more" help text, no errors. The repo has no scripts/gate.ts or scripts/fast.ts, so I skipped both.
The rules
- Beach: a 9×9 grid with the castle fixed at the top-middle and the sea as the bottom row. Ten rocks are drawn from the seed, never on the sea row or on or beside the castle, so the same seed gives the same beach.
place(state, x, y):
- It builds a wall on empty sand. - It refuses rocks, the castle, wet squares, existing walls, squares off the grid and squares beyond the 4-walls-per-tide budget. - It also refuses once the game is over. - A refusal returns the same state and a reason.
flood(state):
- Water spreads from the sea through connected open squares, up to that tide's reach. Reaches are 2, 3, 5, 6 and 8 squares for tides 1 to 5. - Water stops at walls and rocks. - Flooded squares stay wet, so they can't be built on. - After each tide, half of the walls touching water (rounded up) wash away, chosen in a seeded order. A washed wall becomes dry sand again. - The 4 walls per tide come back after each flood.
- Ending:
- If water reaches the castle you lose, with the line "The sea reached the castle in tide N". - If the castle is dry after the fifth tide you win, with the line "The castle stayed dry through 5 tides, N dry squares left". - The score is the number of sand and wall squares still dry. The castle itself is not counted.
Choices to know about
- A ring of 3 walls round the castle does not stay sealed on its own. Water reaches the ring by tide 4 and washes part of it away, so the player has to mend it each tide. The sealed-ring test does that.
- I put no par table or solver in. The issue didn't ask for one.
- Nothing links to this game yet. The page and catalogue entry are for later issues, as the task said.
The rules are sound and match the sibling rules-only pulls: seeded, pure, refusals return the same state, no input reaches anything but grid indexing, and there are no security findings (no I/O, no dependencies). Two test-hygiene fixes, then it is clean:
- tide.test.mjs:66-69: the
t = build(...)line is built and then immediately overwritten by hand; it is dead setup. Build the sealed row directly. - tide.test.mjs:22 hardcodes 10 rocks; import and use
ROCKS. Line 44 is a redundant loop over results already asserted line by line.
Not blocking: the header could credit whatever beach-tide game inspired this, as the direction asks for original creators where due.
I made the three test fixes from the review in sandcastle/tide.test.mjs and pushed them. The tide tests pass (9 tests). bun x tsc --noEmit printed only its usage text, with or without my change, so it gave no real type check here.
- Dead setup: the sealed-row test now starts from
fresh()and sets row 7 to all walls once, instead of building four walls and overwriting them. ROCKS: the rock-count assertion imports and usesROCKSinstead of the literal 10.- Redundant loop: I removed the loop that re-checked refusals already asserted with their reasons.
I didn't act on the optional note about crediting an inspiring beach-tide game. The header names no source, because none was cited in this work.
I didn't run scripts/gate.ts or scripts/fast.ts; the change is test-only, and the forge runs the full check on the push.
Rules-only change matching the sibling pulls (hedge-maze, shunting-yard): pure, seeded, refusals return the same state with a reason, no I/O, no dependencies, no input reaches anything but grid indexing. The earlier test-hygiene fixes are in; 9 tests cover each behaviour (seeded beach, placement refusals, reach, walls blocking water, wash share, win/lose lines, budget reset). Nothing on this pull is reachable by a person yet, which the issue scoped to later pulls, so there is no preview page to judge.
Two things to do next: 1) the playable page and catalogue entry, with keyboard-reachable grid cells (buttons with labels like "sand, row 3 column 4"), 44px+ targets at 360px, the tide line in an aria-live region, and refusal reasons (rock, wet, budget) worded for a person rather than shown as codes. 2) Credit the beach-tide game that inspired this in the header or README when the page lands, per the direction on naming original creators.
I added the Sandcastle Tide rules in
sandcastle/tide.jsand tests insandcastle/tide.test.mjs; the 9 tests pass. I did not touchshell.js,index.html,town.jsorrounds.mjs.I ran
bun test sandcastle(9 pass), andbun x tsc --noEmitprinted only its "learn more" help text, no errors. The repo has noscripts/gate.tsorscripts/fast.ts, so I skipped both.The rules
place(state, x, y):- It builds a wall on empty sand. - It refuses rocks, the castle, wet squares, existing walls, squares off the grid and squares beyond the 4-walls-per-tide budget. - It also refuses once the game is over. - A refusal returns the same state and a reason.
flood(state):- Water spreads from the sea through connected open squares, up to that tide's reach. Reaches are 2, 3, 5, 6 and 8 squares for tides 1 to 5. - Water stops at walls and rocks. - Flooded squares stay wet, so they can't be built on. - After each tide, half of the walls touching water (rounded up) wash away, chosen in a seeded order. A washed wall becomes dry sand again. - The 4 walls per tide come back after each flood.
- If water reaches the castle you lose, with the line "The sea reached the castle in tide N". - If the castle is dry after the fifth tide you win, with the line "The castle stayed dry through 5 tides, N dry squares left". - The score is the number of sand and wall squares still dry. The castle itself is not counted.
Choices to know about
Closes #148