Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Bird Watch rules: a tested `bird-watch/watch.js` that shows birds on perches for a moment and asks where each one sat, from plain data #195
Check · Review · Land · Live done — Landed and live in production.
I added the Bird Watch rules as bird-watch/watch.js with its tests in bird-watch/watch.test.mjs. bun test bird-watch passes (9 tests). The repo has no scripts/gate.ts, scripts/fast.ts or tsconfig.json, so I ran none of those.
shipped production is serving it deploy ab54f53
I added the Bird Watch rules as bird-watch/watch.js with its tests in bird-watch/watch.test.mjs. bun test bird-watch passes (9 tests). The repo has no scripts/gate.ts, scripts/fast.ts or tsconfig.json, so I ran none of those. bun x tsc --noEmit only printed its help text, so type-checking did not actually run.
Rules, in watch.js
- Start:
start(seed)states the 10 perches and 8 species, and gives 3 pairs of binoculars. Nothing is shown until the firstround(). - Rounds: Round 1 shows 2 birds and each round adds one, up to 6 birds in round 5. Every bird has its own species and its own perch, and the same seed always gives the same rounds.
- Questions:
ask(state)names one bird from the round just shown, and asking again repeats the same question. A round has one question per bird. - Answers:
answer(state, perch)marks the answer right or wrong, and a perch that does not exist is refused withbad-perch. A wrong answer costs one pair, and the game ends at zero. - End: The game also ends once round 5 is cleared. A win needs 4 rounds cleared. Both end lines report the rounds cleared and the answers right.
Choices I made
- A round counts as cleared once all its questions are answered, even if some were wrong. Wrong answers cost binoculars but don't fail the round.
- Refused moves return the same state with a
why:over,unanswered,no-question,not-askedorbad-perch. - The module is a plain function-style module (
module.exports, orroot.BirdWatchin a browser), likelily-pond/pond.js.
Not done: no page and no catalogue entry, as the issue says. I did not touch shell.js, index.html, town.js or rounds.mjs.
Try it: run bun test bird-watch/watch.test.mjs.
I couldn't find a cause in this pull for the preview failure, so I pushed an empty commit to re-run the check. That re-run has not finished yet, so the preview may still fail if the hang comes back.
The deploy log stalled in empire/page.test.mjs ("a box round the villagers selects them…"), and the 600s timeout was hit there. This pull only adds bird-watch/watch.js and its test, which are pure functions with no server or timers, and nothing else in the diff touches empire/. Run locally, empire/page.test.mjs passes (14 tests, about 9s).
If the re-run hangs in empire/page.test.mjs again, the test itself needs a fix, and that belongs in its own pull.
The Bird Watch rules and tests are unchanged from my last message, and bun test bird-watch passes (9 tests).
Clean rules-only module, as the issue asked: pure functions, seeded and deterministic, no DOM, timers or Math.random. Refused moves return the same state with a reason. Input is validated at the boundary: answer() rejects non-string and unknown perches, including __proto__, and the tests cover that. The 9 tests cover determinism, distinct perches and species over 100 seeds, round growth, question order, both endings and the win line. No server, storage or dependency is touched, so the security and terminal items do not apply. Page and catalogue entry are left for the follow-up, as the pull says.
I added the Bird Watch rules as
bird-watch/watch.jswith its tests inbird-watch/watch.test.mjs.bun test bird-watchpasses (9 tests). The repo has noscripts/gate.ts,scripts/fast.tsortsconfig.json, so I ran none of those.bun x tsc --noEmitonly printed its help text, so type-checking did not actually run.Rules, in
watch.jsstart(seed)states the 10 perches and 8 species, and gives 3 pairs of binoculars. Nothing is shown until the firstround().ask(state)names one bird from the round just shown, and asking again repeats the same question. A round has one question per bird.answer(state, perch)marks the answer right or wrong, and a perch that does not exist is refused withbad-perch. A wrong answer costs one pair, and the game ends at zero.Choices I made
why:over,unanswered,no-question,not-askedorbad-perch.module.exports, orroot.BirdWatchin a browser), likelily-pond/pond.js.Not done: no page and no catalogue entry, as the issue says. I did not touch
shell.js,index.html,town.jsorrounds.mjs.Try it: run
bun test bird-watch/watch.test.mjs.Closes #180