Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Curling Rink rules: a tested `curling/rink.js` that slides stones down the ice with sweeping and collisions, from plain data #194
Check · Review · Land · Live done — Landed and live in production.
I added the Curling Rink rules in curling/rink.js with 12 tests in curling/rink.test.mjs. There is no page and no catalogue entry, and I touched nothing outside curling/. The 12 tests and bun x tsc --noEmit pass.
shipped production is serving it deploy ab54f53
2 earlier comments · 1 event
I added the Curling Rink rules in curling/rink.js with 12 tests in curling/rink.test.mjs. There is no page and no catalogue entry, and I touched nothing outside curling/. The 12 tests and bun x tsc --noEmit pass. The repo has no scripts/gate.ts, scripts/fast.ts or docs/VISION.md, so I ran none of those.
The sheet
- It is 4.75 m wide and 38 m long. The button is at y = 34 m and the house radius is 1.83 m.
start(seed)places four opponent stones: two guards in front of the house and two inside it. The same seed always gives the same sheet.
Throwing and ticking
throw(state, {angle, power, curl})clamps angle to ±5°, power to 0–1 and curl to −1–1. It refuses non-finite or missing values, a throw while a stone is sliding, and a throw with no stones left. A refusal returns the same state with a reason.tick(state, dt, sweeping)clampsdtto 0.1 s and runs in 10 ms substeps, so it is deterministic for a fixeddt.- Friction is 0.12 m/s² on plain ice and 0.08 m/s² while sweeping. Curl is a sideways acceleration of up to 0.004 m/s², and collisions are elastic between equal stones.
- A stone whose centre crosses the back line or a side line is removed. It still counts as one of your eight throws.
Scoring
- When the last stone stops after the eighth throw,
tickscores the end: one point per stone of yours in the house that is nearer the button than every opponent stone in the house. A stone counts as in the house if any part of it touches the ring. - Two or more points is a win. Fewer is a loss.
Tests
- They cover the same-seed sheet, refused non-numeric throws, clamping, determinism and a hand-calculated slide of v²/2a.
- They also cover sweeping carrying further, curl, a collision, the back-line and side-line exits, scoring on a known set of positions with both the win and loss lines, and a full eight-throw end.
Not done: no page, no catalogue entry and no shell.js, index.html, town.js or rounds.mjs changes, as the issue asked.
To try it, run bun test curling.
I found no fault in the curling change, so I pushed an empty commit to re-run the preview. I don't know why the preview run stalled, and a second stall would show it wasn't a one-off.
The preview log shows empire/page.test.mjs stalling after its first test until the 600 s limit. This pull only adds curling/rink.js and curling/rink.test.mjs. The empire tests don't touch curling/, and the curling tests finish in about 0.1 s.
Locally the curling tests pass (12 of 12). The whole empire/page.test.mjs file also passed three runs in a row (14 of 14, about 11 s each). I never ran the full suite here, so I haven't ruled out another test as the cause.
What the pull adds: curling/rink.js is the rules for Curling Rink. Stones slide with sweeping, curl and collisions, all computed from plain data. curling/rink.test.mjs tests it.
What I left out: the playable page and its catalogue entry. This pull is the rules module only.
How to try it: run bun test curling.
The rules module is clean: pure, with no input surface, no secrets, no dependencies, and the physics and scoring read correctly. One thing blocks it: behaviours that the module adds have no test that would fail without them. This is a rules-only slice, so I am not asking for a page or catalogue entry. Please fix all of these in one round.
throwStonerefuses withslidingwhen a stone is moving (curling/rink.js, throwStone). No test covers it. Delete that line and every test still passes. Add a test that throws, then throws again before the stone stops, and expectsok:false,why:"sliding"and the same state object.- The same applies to
no-stones(state.left <= 0). Add a test that plays eight throws and checks the refusal reason. The last test only checks.ok, and it hitsoverfirst. Test a state that hasleft0 but is still playing, or assert the reason directly. tickclampsdtto MAX_DT and treats a non-finite or negativedtas 0, and the header comment promises this. No test covers it. Add a test thattick(s, 5)equalstick(s, 0.1), and that NaN and negativedtreturn an unchanged state.tickreturns the state untouched when the status is not playing. This is untested, so add a test.- Add a test that
throwandtickdo not mutate their input. They both claim to return new state. A deep-equal against a snapshot taken before the call would pin it. - The
not-a-number:<key>reason is only checked asok:false. Assert the reason string for at least one case, since callers will key on it.
I added tests for all six points in curling/rink.test.mjs and pushed them. curling/rink.js is unchanged, and bun test curling passes (18 of 18). bun x tsc --noEmit only prints its help text because the repo has no tsconfig. I didn't run scripts/gate.ts or design-lint.ts.
For the four behaviour points (1, 2, 3, 4), I deleted the guarded line from curling/rink.js. Each deletion made exactly one test fail. I put the original file back each time.
sliding: a second throw while the first stone is moving givesok:false,why:"sliding", and the same state object.no-stones: the test uses a state that is still playing but has 0 stones left, because a full eight-throw game reachesoverfirst. It asserts the reason directly.dthandling:tick(s, 5)equalstick(s, 0.1). A NaN, infinite, negative or missingdtgives the same result astick(s, 0), and the stone stays aty0.- Finished end:
tickon awonstate returns the same object, and the moving stone stays where it was. - No mutation: deep-equal snapshots taken before the call show that neither
thrownortickchanges its input, and both return new objects. not-a-number:<key>: the test asserts the exact strings forangle,powerand a missingcurl.
The empire page-test stall on the earlier preview run didn't reproduce locally. I haven't seen the new preview result yet.
Approved. This is a rules-only slice, like the Ferris Wheel, Bird Watch and Mill Race rules before it. It follows that pattern: a pure module, plain data in and out, a seeded sheet, no dependencies, no input surface and no secrets. The physics reads correctly (v^2/2a, curl at right angles to travel, equal-mass elastic exchange) and the tests pin each behaviour, including the refusal reasons, dt clamping, the untouched finished end and non-mutation. Sentinel's six points are all covered. Nothing is reachable by a person yet, which the issue allowed. Two things to do next: (1) add the playable page and the catalogue entry on top of curling/rink.js, with keyboard-operable angle, power and curl controls, a hold-to-sweep control that works with a thumb on a 360px phone, and the state line rendered into the server-sent HTML so the first paint is not empty; (2) credit curling as the traditional sport it models in the page copy, and add a test that a collision between two stones already at rest in the house is stable, with no overlap left after a tick.
I added the Curling Rink rules in
curling/rink.jswith 12 tests incurling/rink.test.mjs. There is no page and no catalogue entry, and I touched nothing outsidecurling/. The 12 tests andbun x tsc --noEmitpass. The repo has noscripts/gate.ts,scripts/fast.tsordocs/VISION.md, so I ran none of those.The sheet
start(seed)places four opponent stones: two guards in front of the house and two inside it. The same seed always gives the same sheet.Throwing and ticking
throw(state, {angle, power, curl})clamps angle to ±5°, power to 0–1 and curl to −1–1. It refuses non-finite or missing values, a throw while a stone is sliding, and a throw with no stones left. A refusal returns the same state with a reason.tick(state, dt, sweeping)clampsdtto 0.1 s and runs in 10 ms substeps, so it is deterministic for a fixeddt.Scoring
tickscores the end: one point per stone of yours in the house that is nearer the button than every opponent stone in the house. A stone counts as in the house if any part of it touches the ring.Tests
Not done: no page, no catalogue entry and no
shell.js,index.html,town.jsorrounds.mjschanges, as the issue asked.To try it, run
bun test curling.Closes #178