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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy ab54f53

opened this

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) clamps dt to 0.1 s and runs in 10 ms substeps, so it is deterministic for a fixed dt.
  • 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, tick scores 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.

Closes #178

2 earlier comments · 1 event
commented

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) clamps dt to 0.1 s and runs in 10 ms substeps, so it is deterministic for a fixed dt.
  • 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, tick scores 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.

commented

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.

Changes requested — before the latest push

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.

  1. throwStone refuses with sliding when 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 expects ok:false, why:"sliding" and the same state object.
  2. 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 hits over first. Test a state that has left 0 but is still playing, or assert the reason directly.
  3. tick clamps dt to MAX_DT and treats a non-finite or negative dt as 0, and the header comment promises this. No test covers it. Add a test that tick(s, 5) equals tick(s, 0.1), and that NaN and negative dt return an unchanged state.
  4. tick returns the state untouched when the status is not playing. This is untested, so add a test.
  5. Add a test that throw and tick do not mutate their input. They both claim to return new state. A deep-equal against a snapshot taken before the call would pin it.
  6. The not-a-number:<key> reason is only checked as ok:false. Assert the reason string for at least one case, since callers will key on it.
commented

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.

  1. sliding: a second throw while the first stone is moving gives ok:false, why:"sliding", and the same state object.
  2. no-stones: the test uses a state that is still playing but has 0 stones left, because a full eight-throw game reaches over first. It asserts the reason directly.
  3. dt handling: tick(s, 5) equals tick(s, 0.1). A NaN, infinite, negative or missing dt gives the same result as tick(s, 0), and the stone stays at y 0.
  4. Finished end: tick on a won state returns the same object, and the moving stone stays where it was.
  5. No mutation: deep-equal snapshots taken before the call show that neither throw nor tick changes its input, and both return new objects.
  6. not-a-number:<key>: the test asserts the exact strings for angle, power and a missing curl.

The empire page-test stall on the earlier preview run didn't reproduce locally. I haven't seen the new preview result yet.

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs