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

Migrated from github.com/amirmushichge/pixel-plays

Duck Race rules: a tested `duck-race/stream.js` where you steer a rubber duck across stream lanes past rocks and eddies against three rivals, from plain data, in a two-file pull with a test file that runs in under a second #260

Merged opened this

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

Merged

Duck Race rules: duck-race/stream.js and duck-race/stream.test.mjs, nothing else touched. bun test duck-race/stream.test.mjs passes: 9 tests, 106 assertions, 52 ms by bun's own timer and 0.06 s wall clock. The test file imports only the rules module, with no page, renderer or server.

Notes

shipped production is serving it deploy ab54f53

opened this

Duck Race rules: duck-race/stream.js and duck-race/stream.test.mjs, nothing else touched.

bun test duck-race/stream.test.mjs passes: 9 tests, 106 assertions, 52 ms by bun's own timer and 0.06 s wall clock. The test file imports only the rules module, with no page, renderer or server. The repo has no scripts/gate.ts and no tsconfig, so I ran neither the gate nor a type check (tsc just printed its help). I did not run the full suite; the forge's check does that.

The rules

  • Stream: start(seed) gives a 100-unit stream with 5 lanes and a 60 s limit. Rocks and eddies sit on 5-unit slots from unit 10 on, so no two share a spot, and eight 12-unit patches of fast water are laid out too. You start in lane 2 with three rivals, each with a seeded pace of 0.9–1.1. The same seed always gives the same stream and rival behaviour.
  • Movement: tick(state, dt) carries every duck at 5 units/s. Fast water multiplies that by 1.5. An eddy holds a duck for 1.5 s. A rock stops a duck until it changes lane, and each rock a duck hits counts as one touch.
  • Steering: steer(state, -1 | 1) moves your duck one lane, with a 0.4 s cooldown after each move. It is refused with a reason at a bank (bank), in the cooldown (cooldown), for a bad direction, once your duck has finished, and after the race.
  • Rivals: a rival that sees an unhit rock or eddy within 7 units in its lane turns by the seeded rivalTurn(seed, id, n). If that turn would go past a bank, it turns the other way.
  • End and score: the race ends when every duck has crossed or the time limit runs out. Finishers are ordered by interpolated finish time, then the rest by distance covered. First place scores 100, plus 50 for never touching a rock. Other places score 0. The state's line reads "You win: 1st of 4, …" or "You lose: 4th of 4, 0 points".

Choices

  • A tick is cut into 0.05 s slices so a fast duck can't skip over an obstacle.
  • Steering is still allowed while your duck is held in an eddy. The hold itself is not cut short.
  • The clean-run bonus applies only to first place.

Not done: no page and no catalogue entry, as the issue says.

The check didn't run here, so I can't say whether it will hit the 600 s limit.

Try it: bun test duck-race/stream.test.mjs.

🤖 Generated with Claude Code

Closes #248

2 earlier comments · 2 events
commented

Duck Race rules: duck-race/stream.js and duck-race/stream.test.mjs, nothing else touched.

bun test duck-race/stream.test.mjs passes: 9 tests, 106 assertions, 52 ms by bun's own timer and 0.06 s wall clock. The test file imports only the rules module, with no page, renderer or server. The repo has no scripts/gate.ts and no tsconfig, so I ran neither the gate nor a type check (tsc just printed its help). I did not run the full suite; the forge's check does that.

The rules

  • Stream: start(seed) gives a 100-unit stream with 5 lanes and a 60 s limit. Rocks and eddies sit on 5-unit slots from unit 10 on, so no two share a spot, and eight 12-unit patches of fast water are laid out too. You start in lane 2 with three rivals, each with a seeded pace of 0.9–1.1. The same seed always gives the same stream and rival behaviour.
  • Movement: tick(state, dt) carries every duck at 5 units/s. Fast water multiplies that by 1.5. An eddy holds a duck for 1.5 s. A rock stops a duck until it changes lane, and each rock a duck hits counts as one touch.
  • Steering: steer(state, -1 | 1) moves your duck one lane, with a 0.4 s cooldown after each move. It is refused with a reason at a bank (bank), in the cooldown (cooldown), for a bad direction, once your duck has finished, and after the race.
  • Rivals: a rival that sees an unhit rock or eddy within 7 units in its lane turns by the seeded rivalTurn(seed, id, n). If that turn would go past a bank, it turns the other way.
  • End and score: the race ends when every duck has crossed or the time limit runs out. Finishers are ordered by interpolated finish time, then the rest by distance covered. First place scores 100, plus 50 for never touching a rock. Other places score 0. The state's line reads "You win: 1st of 4, …" or "You lose: 4th of 4, 0 points".

Choices

  • A tick is cut into 0.05 s slices so a fast duck can't skip over an obstacle.
  • Steering is still allowed while your duck is held in an eddy. The hold itself is not cut short.
  • The clean-run bonus applies only to first place.

Not done: no page and no catalogue entry, as the issue says.

The check didn't run here, so I can't say whether it will hit the 600 s limit.

Try it: bun test duck-race/stream.test.mjs.

🤖 Generated with Claude Code

Changes requested — before the latest push

The rules read well, the sizes are stated and the test file is rules-only and fast. One real bug to fix first: a rival that hits a rock can never leave it.

  1. rivalThink only looks at obstacles not already in d.hit. The rock a rival has just struck is in d.hit, so ahead does not find it, the rival never calls shift, and d.stuck stays true. It only escapes if another unhit obstacle happens to sit in its lane within 7 units. A rival can hit a rock when it dodges into a lane whose rock is under 2 units ahead (the 0.4 s cooldown at 5 u/s). Such a rival is parked for the rest of the race. That breaks the 'a rock stops a duck until it changes lane' rule for rivals, and it also stops the race ending on 'every duck has passed the bridge'. Fix: a stuck rival turns away by the seeded rule once its cooldown is 0, and does not need an unhit obstacle ahead to do so. Add a test with a rival placed on a rock that shows it leaves and finishes. Add a seed sweep that asserts no rival is stuck at the end of a long run if the rule allows it.
  1. The header comment says 'The page (not yet written) draws what this decides'. That is a note about the pull's state and will go stale. Drop it.

Not required: steering while held in an eddy is allowed, which you stated. Fine. No page or catalogue entry or tty door is needed for a rules-only issue.

commented

Both review points are fixed and pushed to the same branch. bun test duck-race/stream.test.mjs passes: 11 tests, 150 assertions, 0.12 s wall clock. I did not run the full suite.

  • Stuck rivals: you were right, a rival that hit a rock could never leave it. A rival now acts once its cooldown is 0, and it turns away by the seeded rule if it is stuck on a rock or sees an unhit rock or eddy ahead (rivalThink in duck-race/stream.js). If that turn would go past a bank, it turns the other way, as before.
  • Header comment: I removed the "page (not yet written)" note.
  • New tests:

- A rival placed on a rock waits out its cooldown, then turns by the seeded rule and finishes. - A sweep over seeds 1–40 asserts that, after a full time-limit run, no rival is stuck and every rival has crossed the bridge. It passes for all 40 seeds.

Approved

Both earlier asks are met: rivals stuck on a rock now turn away once their cooldown ends (rivalThink, with a test and a 40-seed sweep), and the stale 'page not yet written' comment is gone. The rules are plain data in and out, seeded, and well covered. Two things I would do next, both non-blocking: (1) Non-blocking: the pull should state the measured time per issue box 6 for the final head (11 tests, 0.12s wall is stated, fine). (2) Non-blocking: build the playable page next with a keyboard (arrow keys) and large touch targets for lane steering on a 360px phone, announcing the line in an aria-live region. I could not run the test file in my clone, which does not hold the branch files; I judged from the diff and the author's reported run.

commented

Left #248 open: 1 unticked item remain (duck-race/stream.js holds the rules as plain data in, plain data out, with no DOM. start(seed) gives a stated stream length, a stated number of lanes, a seeded layout of rocks, eddies and fast water along it, and your duck plus three rival ducks at the start line; the same seed always gives the same stream and the same rival behaviour.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs