Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Go-Kart Fete rules: a tested `go-kart/lap.js` that plays a whole game from plain data #118

Merged opened this

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

Merged

I added the Go-Kart Fete rules as two new files, go-kart/lap.js and go-kart/lap.test.mjs. bun test go-kart/ passes (16 tests). I did not run the whole bun test and did not run bun x tsc --noEmit meaningfully (the repository has no tsconfig, so it only printed help).

Notes

shipped production is serving it deploy ab54f53

opened this

I added the Go-Kart Fete rules as two new files, go-kart/lap.js and go-kart/lap.test.mjs. bun test go-kart/ passes (16 tests). I did not run the whole bun test and did not run bun x tsc --noEmit meaningfully (the repository has no tsconfig, so it only printed help). scripts/gate.ts and scripts/fast.ts don't exist in this clone, so neither was run.

What it does

  • Throttle and speed: holding the throttle gathers 6 m/s² up to 26 m/s, and letting go brakes at 14 m/s² down to a stop. Speed comes from a pure speedStep(v, throttle, dt).
  • Bends: each lap has three bends, with safe speeds of 13, 16 and 10 m/s. Entering one faster puts the kart in the bales and stops it for 1 s, emitting a bales event. The same applies on every lap.
  • Rivals: three karts at fixed paces from rivalPace(race, k, seed). They start around 16.5 m/s, gain 1.5 m/s each race, and vary by ±1 m/s by kart and seed. There is no Math.random.
  • Scoring and game: after three laps, place scores 3, 2, 1 or 0. A game is three races with a 2.5 s rest between them. The state reports race, lap, place, speed, total, best, phase, over, outcome, score and a text line ("Won with 7 points"). A win is a total of 6 or more.
  • Loading: it loads as the window.Lap global from a <script> tag or by import, the same way soapbox-derby/cart.js does.

Tests

  • Speed curve, brake curve, bale stop and later-lap bends, rival pace rising per race, the points table, place counting, and rest then next race.
  • A careful scripted throttle wins with 9 points; holding full throttle crashes at every bend and loses with 0; never pressing the throttle never finishes a race.
  • The same seed gives the same game, and a tap restarts only after the game has been over for a moment.

What I left alone: go-kart/ has no index.html, and I changed no shared file (shell.js, index.html, README.md, serve.test.mjs, rounds.mjs, og/).

To try it: run bun test go-kart/, or load the file in a script and call Lap.newGame() then Lap.advance(state, dt, { throttle }).

🤖 Generated with Claude Code

Closes #103

2 earlier comments · 1 event
commented

I added the Go-Kart Fete rules as two new files, go-kart/lap.js and go-kart/lap.test.mjs. bun test go-kart/ passes (16 tests). I did not run the whole bun test and did not run bun x tsc --noEmit meaningfully (the repository has no tsconfig, so it only printed help). scripts/gate.ts and scripts/fast.ts don't exist in this clone, so neither was run.

What it does

  • Throttle and speed: holding the throttle gathers 6 m/s² up to 26 m/s, and letting go brakes at 14 m/s² down to a stop. Speed comes from a pure speedStep(v, throttle, dt).
  • Bends: each lap has three bends, with safe speeds of 13, 16 and 10 m/s. Entering one faster puts the kart in the bales and stops it for 1 s, emitting a bales event. The same applies on every lap.
  • Rivals: three karts at fixed paces from rivalPace(race, k, seed). They start around 16.5 m/s, gain 1.5 m/s each race, and vary by ±1 m/s by kart and seed. There is no Math.random.
  • Scoring and game: after three laps, place scores 3, 2, 1 or 0. A game is three races with a 2.5 s rest between them. The state reports race, lap, place, speed, total, best, phase, over, outcome, score and a text line ("Won with 7 points"). A win is a total of 6 or more.
  • Loading: it loads as the window.Lap global from a <script> tag or by import, the same way soapbox-derby/cart.js does.

Tests

  • Speed curve, brake curve, bale stop and later-lap bends, rival pace rising per race, the points table, place counting, and rest then next race.
  • A careful scripted throttle wins with 9 points; holding full throttle crashes at every bend and loses with 0; never pressing the throttle never finishes a race.
  • The same seed gives the same game, and a tap restarts only after the game has been over for a moment.

What I left alone: go-kart/ has no index.html, and I changed no shared file (shell.js, index.html, README.md, serve.test.mjs, rounds.mjs, og/).

To try it: run bun test go-kart/, or load the file in a script and call Lap.newGame() then Lap.advance(state, dt, { throttle }).

🤖 Generated with Claude Code

commented

This pull adds the Go-Kart Fete rules as go-kart/lap.js and go-kart/lap.test.mjs, plus a one-line fix in serve.mjs for the failing deploy check.

The failing check: serve.test.mjs "every game page and its track is served" was flaky, and the failure was not caused by the go-kart files. It also failed on a clean checkout of origin/main, with Malformed_HTTP_Response on GET /stari-most/, right after the HEAD request for the previous game's mp3. The test passed when run alone and failed about half the time when the whole file ran.

The fix: serve.mjs now sends no body on HEAD, as the /stats route already does. Before, it passed the file body to res.end even for HEAD. I did not confirm that this was the cause, but serve.test.mjs then passed four runs in a row.

What I didn't run: the full bun test, since the forge's check runs it on this push.

The rules: these are unchanged from the first push. bun test go-kart/ passes (16 tests).

  • Throttle and speed: speed is a pure speedStep function. A held throttle gathers 6 m/s² up to 26 m/s, and letting go brakes at 14 m/s².
  • Bends: three per lap, with safe speeds of 13, 16 and 10 m/s. Entering one faster stops the kart in the bales for 1 s.
  • Rivals: three karts with seeded paces, each race quicker than the last.
  • Scoring: place after three laps scores 3, 2, 1 or 0. A game is three races, and a total of 6 or more wins.
  • State for the playtest: the state exposes phase, score, over, outcome and a text line.
  • Loading: it loads as the window.Lap global or by import.

Nothing else is touched, and there is no index.html in go-kart/ yet.

To try it: run bun test go-kart/ serve.test.mjs.

🤖 Generated with Claude Code

Changes requested — before the latest push

The rules module is clean and well tested: pure, seeded, no Math.random, 16 tests that pin speed, bends, scoring and the full careful/reckless games. Two things to fix in one round.

  1. (first) serve.mjs changes HEAD behaviour with no test. The list requires every behaviour a change adds to have a test that fails without it. Add a case to serve.test.mjs: a HEAD on a static file answers 200 with the same content-length and an empty body. Also the pull says the HEAD fix is unconfirmed as the cause of the flake; either show the test reproducing the Malformed_HTTP_Response before the fix, or split the unrelated server change into its own pull so this one is only the rules.
  1. Nothing reachable yet: /go-kart/ answers 404 on the preview, there is no index.html, no entry in the feed/index.html, no README line and no credit to the original creators of the go-kart/village-fete idea. A rules-only step is acceptable if the issue was scoped that way, but then say in the pull which issue follows to make it reachable and link it as a dependency, so the module is not left as a function nobody can call.

Small: lap.js exports constants (RIVALS, PACE_*, etc.) that no test or caller uses; trim the api to what the page will need, or leave it if the page pull follows immediately.

commented

This pull is rules only again: it adds go-kart/lap.js and go-kart/lap.test.mjs, and nothing else differs from the merge base. I did not re-run bun test go-kart/ after the revert, but the revert only touches serve.mjs, which the go-kart tests don't use. Both files are unchanged since my first push, when bun test go-kart/ passed (16 tests).

Changes since your review

  • serve.mjs HEAD change: I reverted it. It was unrelated to the rules, and I could not show it was the cause. The issue also forbids touching serve.test.mjs, so I could not add the HEAD test you asked for. The flaky "every game page and its track is served" test (Malformed_HTTP_Response on GET /stari-most/) also fails on a clean origin/main. It needs its own pull, with a test that reproduces the failure first. I did not open one.

Where I did not change course

  • Reachability: a rules-only step is how #103 was scoped, so go-kart/ still has no index.html, feed entry or README line. #104, "Add Go-Kart Fete: the playable page and its place in the catalogue", already waits on this issue. It will add the page, the listing, and the credit for the original idea.
  • Exported constants: I left them in lap.js's exports, since the page in #104 will draw the bends, laps and rival paces from them.

To try it: run bun test go-kart/.

🤖 Generated with Claude Code

Approved

Rules-only step, scoped that way by #103; the page, catalogue entry and credit follow in #104, which already waits on this. /go-kart/ is 404 on the preview, which is expected. I read every line: pure, seeded, no Math.random, no I/O, inputs sanitised with finite/clamp, the bale re-trigger is guarded (a kart stopped at a bend cannot re-cross it), and the 16 tests pin speed, braking, bends on later laps, pace, scoring, rest and the full careful/reckless games. No security surface here. Two nits for a follow-up, not blockers: the test named "never touching the throttle scores nothing and loses" asserts over === false, so rename it; and trim the exports once #104 shows what the page uses.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs