Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Dinghy Race rules: a tested `dinghy-race/dinghy.js` that plays a whole game from plain data #121
Check · Review · Land · Live done — Landed and live in production.
I added dinghy-race/dinghy.js and dinghy-race/dinghy.test.mjs. bun test dinghy-race/ passes (18 tests). bun x tsc --noEmit only printed its help text (this repo has no tsconfig), so it checked nothing.
shipped production is serving it deploy ab54f53
I added dinghy-race/dinghy.js and dinghy-race/dinghy.test.mjs. bun test dinghy-race/ passes (18 tests). bun x tsc --noEmit only printed its help text (this repo has no tsconfig), so it checked nothing. I did not run a bare bun test, and there is no scripts/gate.ts or scripts/fast.ts here. Nothing else changed: no index.html, and no edits to shell.js, README.md, rounds.mjs, serve.test.mjs or og/.
Rules
- Format: the file is plain data in and out, with no DOM, timers or
Math.random. It follows thesoapbox-derby/cart.jspattern: it exports forimportand setswindow.Dinghyunder a<script>tag. - Speed:
boatSpeed(sail, heading, wind)is a pure function of its three arguments, in degrees (0 is north, wind is the bearing it blows from).
- The best sail angle is half the angle to the wind (bestSail).
- It falls off quadratically on either side and reaches zero at ±40°.
- Inside 25° of the wind the boat stops dead, whatever the sail.
- Speed follows a piecewise-linear polar curve, fastest on a broad reach (135° off the wind) at a top speed of 7 m/s. I picked the polar shape and the 7 m/s top speed myself; the issue didn't specify them.
- Course: one race is start → three buoys → back over the line, 480 m in all. The boat steers itself to the next buoy. The wind shifts by a seeded amount in [−10°, +10°) at each buoy, and a test confirms no seed can push any leg into the stopped zone.
- Rivals: the two rivals sail a fixed seeded pace of 3.7–4.2 m/s.
- State:
newRound(best, seed)andadvance(s, dt, {sail})keep the state the playtest will read:
- phase, over, score, outcome, line, buoy, place, time, best and record.
- A win is first or second place; third is a loss.
- score is 2 for first, 1 for second and 0 for third.
- again(s) starts the next race after a short pause.
Tests: the tests cover the best angle, the fall-off on either side, head-to-wind stopping dead, and the seeded wind shift at each buoy. They also cover the fixed rival pace, a scripted perfect trim that wins on seed 2, and a fixed 45° sail that finishes third on seed 0. Another test finds a seed where a slightly mistrimmed boat lands second, which is still a win.
Beyond the issue: a race with no finish is called off at 300 s and placed by distance along the course. This stops a boat with the sail pulled in tight from sitting stuck forever.
Not done: I didn't build the page, the listing or any wiring; those belong to the issue that waits on this one.
Clean. This is a pure rules module with no I/O, network, storage, DOM, eval or shell, so there is no auth, body-cap, escaping or secret surface to miss. It follows the same rules-only pattern as the merged cloakroom pull (#120). Inputs (seed, dt, sail, best) are coerced finite and clamped, and the file has no Math.random. Randomness is seeded, so races replay. The tests cover each rule, including junk input, replay, seeded wind shifts, a check that no seed puts a leg in the no-go zone, and the second-place and called-off cases. The page and listing are out of scope here and wait on the follow-up issue.
I added
dinghy-race/dinghy.jsanddinghy-race/dinghy.test.mjs.bun test dinghy-race/passes (18 tests).bun x tsc --noEmitonly printed its help text (this repo has no tsconfig), so it checked nothing. I did not run a barebun test, and there is noscripts/gate.tsorscripts/fast.tshere. Nothing else changed: noindex.html, and no edits toshell.js,README.md,rounds.mjs,serve.test.mjsorog/.Rules
Math.random. It follows thesoapbox-derby/cart.jspattern: it exports forimportand setswindow.Dinghyunder a<script>tag.boatSpeed(sail, heading, wind)is a pure function of its three arguments, in degrees (0 is north, wind is the bearing it blows from).- The best sail angle is half the angle to the wind (
bestSail). - It falls off quadratically on either side and reaches zero at ±40°. - Inside 25° of the wind the boat stops dead, whatever the sail. - Speed follows a piecewise-linear polar curve, fastest on a broad reach (135° off the wind) at a top speed of 7 m/s. I picked the polar shape and the 7 m/s top speed myself; the issue didn't specify them.newRound(best, seed)andadvance(s, dt, {sail})keep the state the playtest will read:-
phase,over,score,outcome,line,buoy,place,time,bestandrecord. - A win is first or second place; third is a loss. -scoreis 2 for first, 1 for second and 0 for third. -again(s)starts the next race after a short pause.Tests: the tests cover the best angle, the fall-off on either side, head-to-wind stopping dead, and the seeded wind shift at each buoy. They also cover the fixed rival pace, a scripted perfect trim that wins on seed 2, and a fixed 45° sail that finishes third on seed 0. Another test finds a seed where a slightly mistrimmed boat lands second, which is still a win.
Beyond the issue: a race with no finish is called off at 300 s and placed by distance along the course. This stops a boat with the sail pulled in tight from sitting stuck forever.
Not done: I didn't build the page, the listing or any wiring; those belong to the issue that waits on this one.
Closes #109