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

Migrated from github.com/amirmushichge/pixel-plays

Duck Race stream: every seed lays rocks, eddies and fast water inside the stream, checked across seeds in `duck-race/stream.test.mjs` #290

Merged opened this

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

Merged

Every seed from 1 to 200 now gives a stream with at least one rock, one eddy and one patch of fast water. The checking test passes along with the 11 existing tests, which I left unchanged. bun test duck-race/stream.test.mjs runs in about 0.11 s (0.12 s wall-clock).

Notes

shipped production is serving it deploy ab54f53

opened this

Every seed from 1 to 200 now gives a stream with at least one rock, one eddy and one patch of fast water. The checking test passes along with the 11 existing tests, which I left unchanged. bun test duck-race/stream.test.mjs runs in about 0.11 s (0.12 s wall-clock). bun x tsc --noEmit printed only its help text, because the repo has no tsconfig, so there was no type check. The repo has no scripts/gate.ts or scripts/fast.ts, and I did not run the full suite.

What was wrong: the old layout gave seed 90 no eddy. Fast water was never missing, since FAST_PATCHES is 8.

What changed

  • duck-race/stream.js:

- layout now guarantees both obstacle kinds, and the guarantee is stated in a comment next to the layout code. - A seed with fewer than two obstacles gets more on free slots, starting from a seeded slot. - A seed with only one kind has its first obstacle turned into the missing kind. - Seeds that already had both kinds keep exactly the same obstacles. I did not check how many of the 200 seeds were changed. - Obstacle ids are reassigned in order of position after the added obstacles, so the "next obstacle ahead" lookup stays correct. - rivalTurn and the stated constants are untouched. SLOT and FIRST_SLOT are now exported so the test can use them.

  • duck-race/stream.test.mjs: a new test loops over seeds 1 to 200 and checks:

- start(seed) is deep-equal to a second start(seed). - A rock, an eddy and fast water are all present. - Every fast patch has a lane in 0..LANES-1 and satisfies 0 <= from < to <= LENGTH. - Every obstacle has at >= FIRST_SLOT*SLOT and at < LENGTH. - The four ducks have ids 0 to 3, each at x === 0 in its own lane, with exactly one yours.

Not done: I did not touch rival behaviour or any other constant. The guarantee needs at least two free obstacle slots, which the 18 slots always provide.

To try it, run bun test duck-race/stream.test.mjs.

Closes #286

1 earlier comment · 1 event
commented

Every seed from 1 to 200 now gives a stream with at least one rock, one eddy and one patch of fast water. The checking test passes along with the 11 existing tests, which I left unchanged. bun test duck-race/stream.test.mjs runs in about 0.11 s (0.12 s wall-clock). bun x tsc --noEmit printed only its help text, because the repo has no tsconfig, so there was no type check. The repo has no scripts/gate.ts or scripts/fast.ts, and I did not run the full suite.

What was wrong: the old layout gave seed 90 no eddy. Fast water was never missing, since FAST_PATCHES is 8.

What changed

  • duck-race/stream.js:

- layout now guarantees both obstacle kinds, and the guarantee is stated in a comment next to the layout code. - A seed with fewer than two obstacles gets more on free slots, starting from a seeded slot. - A seed with only one kind has its first obstacle turned into the missing kind. - Seeds that already had both kinds keep exactly the same obstacles. I did not check how many of the 200 seeds were changed. - Obstacle ids are reassigned in order of position after the added obstacles, so the "next obstacle ahead" lookup stays correct. - rivalTurn and the stated constants are untouched. SLOT and FIRST_SLOT are now exported so the test can use them.

  • duck-race/stream.test.mjs: a new test loops over seeds 1 to 200 and checks:

- start(seed) is deep-equal to a second start(seed). - A rock, an eddy and fast water are all present. - Every fast patch has a lane in 0..LANES-1 and satisfies 0 <= from < to <= LENGTH. - Every obstacle has at >= FIRST_SLOT*SLOT and at < LENGTH. - The four ducks have ids 0 to 3, each at x === 0 in its own lane, with exactly one yours.

Not done: I did not touch rival behaviour or any other constant. The guarantee needs at least two free obstacle slots, which the 18 slots always provide.

To try it, run bun test duck-race/stream.test.mjs.

Changes requested — before the latest push

The guarantee works and the 12 tests pass in about 0.1 s, but two things are missing. (1) Box 1 asks for the guarantee to be stated in a comment next to the constants. The comment sits inside layout, 40 lines below them. Put it by SLOT, FIRST_SLOT and OBSTACLE_CHANCE, and leave a one-line pointer in layout. (2) The new test cannot fail without the first branch of the fix. That branch adds obstacles for a seed with fewer than two. Seed 90 only exercises the kind swap, and nothing in 1..200 is shown to exercise the sparse branch, so it may be dead code. Either add a test that reaches it, or drop it. To reach it, scan seeds with layout until you find one with fewer than two obstacles from the base rules and assert the result. If no such seed exists in a sensible range, remove the branch. This is a preview-only library change, so there is no phone, keyboard or security surface to judge. Also assert in the test that obstacle ids equal their index, since the fix renumbers them.

commented

I made both changes and added the sparse-seed test; I kept the sparse branch rather than dropping it. The 13 tests in duck-race/stream.test.mjs pass in about 0.11 s. As before, bun x tsc --noEmit has no tsconfig to check against, and I did not run the full suite.

  • Comment placement: the guarantee is now written beside SLOT, FIRST_SLOT and OBSTACLE_CHANCE in duck-race/stream.js. layout keeps a one-line pointer to it.
  • Sparse branch is reachable: I scanned the base rules and found seeds whose base draw is a single obstacle: 675585, 950906 and 1555868. The first appears after about 675,000 seeds. The branch is rare, but it is real, so I kept it.
  • New test: it runs those three seeds and checks that each has at least two obstacles, a rock and an eddy. It also checks that the obstacles are sorted by at, on distinct slots, at or past FIRST_SLOT * SLOT and before LENGTH, with ids equal to their index. I switched the branch off temporarily and the test failed, so it does catch that branch going missing.
  • Obstacle ids: the 1..200 test now also asserts o.id === index for every obstacle.
Approved

Both earlier asks are met: the guarantee comment now sits beside SLOT/FIRST_SLOT/OBSTACLE_CHANCE, and the sparse branch is shown reachable (seeds 675585, 950906, 1555868) and covered by its own test, with ids asserted as index. I could not run the head locally (the clone is at base), so I read the diff. The layout stays pure, the ids are re-sorted, and the kind fix always has a donor because at least two obstacles exist. Next, in order: (1) Non-blocking: state in the README or pull how many of seeds 1..200 the guarantee changed. (2) Non-blocking: replace the one-line pointer comment in layout with nothing, since the constants comment already says it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs