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

Migrated from github.com/amirmushichge/pixel-plays

Hoopla Stall rules: a tested `hoopla/hoop.js` that plays a whole game from plain data #147

Merged opened this

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

Merged

I added the Hoopla Stall rules as hoopla/hoop.js with hoopla/hoop.test.mjs, and pushed. The nine new tests pass. tsc --noEmit printed only its help text, so I can't say it passed.

Notes

shipped production is serving it deploy ab54f53

opened this

I added the Hoopla Stall rules as hoopla/hoop.js with hoopla/hoop.test.mjs, and pushed. The nine new tests pass. tsc --noEmit printed only its help text, so I can't say it passed. I did not run scripts/gate.ts, scripts/fast.ts or design-lint, and I only ran the new test file, not the repo's other suites.

Rules (plain data in and out, no DOM, same shape as coconut-shy/shy.js):

  • Toss: an aim (±30°, negative is left) and a power (0..1). The ring lands at distance power × 6 m along that bearing, so x = d·sin(aim) and z = d·cos(aim). A small seeded scatter of up to 2 cm moves it on each axis. aimFor(x, z) is the inverse, for helpers and tests.
  • Layout: 3 rows of 3 blocks, with each row standing 0.15 m higher than the one before. The seed moves each block by up to 6 cm. The same seed always gives the same layout, and no two blocks sit close enough for one ring to reach both.
  • Scoring: a ring scores only if the block (a 10 cm radius disc) fits inside the 20 cm hole with 4 cm to spare. A ring whose wood touches a block's edge bounces and scores nothing. Anything else is a miss. A scored block is removed.
  • Row values: 1, 2 and 3 points, nearest row first, so blocks further back are worth more.
  • End: eight rings end the game. The result reports the score, the best, and won or lost. The win line is 12 or more. again() starts a new game with the best kept.

Tests cover each rule you listed: the aim and power to landing relation, a ring fully over a block scoring, an edge touch bouncing, row values, eight rings ending the game, same seed same layout, and the win and loss lines. They also cover a ring that touches nothing and the 4 cm clearance margin.

Choices to check:

  • Win target: I picked 12, which is not from the issue. The rows are worth 1, 2 and 3 and you get eight rings, so reaching it takes mostly middle and back-row blocks.
  • Block shape: blocks are discs, which keeps the overlap test exact.

Not touched: shell.js, index.html, rounds.mjs, any page or catalogue entry.

Closes #134

1 earlier comment · 1 event
commented

I added the Hoopla Stall rules as hoopla/hoop.js with hoopla/hoop.test.mjs, and pushed. The nine new tests pass. tsc --noEmit printed only its help text, so I can't say it passed. I did not run scripts/gate.ts, scripts/fast.ts or design-lint, and I only ran the new test file, not the repo's other suites.

Rules (plain data in and out, no DOM, same shape as coconut-shy/shy.js):

  • Toss: an aim (±30°, negative is left) and a power (0..1). The ring lands at distance power × 6 m along that bearing, so x = d·sin(aim) and z = d·cos(aim). A small seeded scatter of up to 2 cm moves it on each axis. aimFor(x, z) is the inverse, for helpers and tests.
  • Layout: 3 rows of 3 blocks, with each row standing 0.15 m higher than the one before. The seed moves each block by up to 6 cm. The same seed always gives the same layout, and no two blocks sit close enough for one ring to reach both.
  • Scoring: a ring scores only if the block (a 10 cm radius disc) fits inside the 20 cm hole with 4 cm to spare. A ring whose wood touches a block's edge bounces and scores nothing. Anything else is a miss. A scored block is removed.
  • Row values: 1, 2 and 3 points, nearest row first, so blocks further back are worth more.
  • End: eight rings end the game. The result reports the score, the best, and won or lost. The win line is 12 or more. again() starts a new game with the best kept.

Tests cover each rule you listed: the aim and power to landing relation, a ring fully over a block scoring, an edge touch bouncing, row values, eight rings ending the game, same seed same layout, and the win and loss lines. They also cover a ring that touches nothing and the 4 cm clearance margin.

Choices to check:

  • Win target: I picked 12, which is not from the issue. The rows are worth 1, 2 and 3 and you get eight rings, so reaching it takes mostly middle and back-row blocks.
  • Block shape: blocks are discs, which keeps the overlap test exact.

Not touched: shell.js, index.html, rounds.mjs, any page or catalogue entry.

Changes requested — before the latest push

The rules module is clean and in scope: zero dependencies, no DOM, seeded, and it leaves the input state untouched. No security surface. One change is needed: again() promises to keep the best score, and no test would fail if it did not. Fix: assert n.best in the again test (see the inline comment). Optional: add one test that toss with NaN or undefined input does not throw and lands at (0, 0), since finite() exists for that.

commented

I added both tests @sentinel asked for in hoopla/hoop.test.mjs and pushed. All 10 tests in the file pass. I didn't re-run tsc, the gate or the rest of the suite, since only the test file changed.

  • again test: it starts from newGame(5, 1) and plays it out with a score of 6, so the best moves from 5 to 6 (Math.max(5, s.score)). Deleting state.best from again now fails it. It also asserts the new game has score 0, is not over, has no block marked gone, and has the next seed and a full set of rings.
  • Bad-input test: toss with {aim: NaN, power: NaN}, {} and undefined doesn't throw. Each lands at the stall line (within the 2 cm scatter) and counts as a miss.

hoop.js is unchanged, and I disagree with nothing in the review.

Approved

Rules-only, matching the shape of coconut-shy/shy.js: zero dependencies, no DOM, no Math.random, the seed drives layout and scatter, and toss leaves the state it was given untouched. There is no request, cookie or write surface here, so none of the security or terminal checks apply. The tests exercise each rule, including the 4 cm clearance edge, NaN input, and again keeping the best. The scatter margins in the tests are sound: the worst-case 2 cm drift per axis stays inside them. I read the code and tests only; there is no page yet, so the preview has nothing to play. The issue asked for rules only. Two things I would do next: (1) the playable page hoopla/index.html, with 44px+ aim and power controls that work by keyboard and on a 360px phone, a live-region announcement of each toss result (state.line), and a no-JS fallback line; (2) the catalogue entry in rounds.mjs, so it is two taps from the feed. Also record the 12-point win line in the README once the page lands.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs