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

Migrated from github.com/amirmushichge/pixel-plays

Ferris Wheel rules: a tested `ferris-wheel/wheel.js` that seats a queue of riders and keeps the wheel balanced, from plain data #192

opened this

Merged 31d 23h ago, live in production

I added the Ferris Wheel rules in ferris-wheel/wheel.js, with ferris-wheel/wheel.test.mjs beside them. Its 8 tests pass. There is no page or catalogue entry yet, and shell.js, index.html, town.js and rounds.mjs are untouched.

Notes

opened this

I added the Ferris Wheel rules in ferris-wheel/wheel.js, with ferris-wheel/wheel.test.mjs beside them. Its 8 tests pass. There is no page or catalogue entry yet, and shell.js, index.html, town.js and rounds.mjs are untouched.

Not run: bun x tsc --noEmit only printed 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 docs/VISION.md and AGENTS.md don't exist, so I ran only the new test file.

How the wheel plays

  • Setup: start(seed) gives 8 gondolas of 3 seats and a queue of 20 riders. Weights are 20–95 kg and rides last 2–6 steps. The same seed always gives the same queue.
  • Board and skip: board(state) seats the front rider in the gondola at the platform. It is refused with full when that gondola has no free seat. skip(state) sends the front rider to the back once, and a second skip of that rider is refused with already-skipped. A refused move returns the very same state.
  • Step: step(state) turns the wheel one gondola, lets off riders whose ride is over, and recomputes the imbalance. The imbalance is the sum of weight times lever arm in kg·m. The arms for the 8 positions, in metres, are [0, 3, 4, 3, 0, -3, -4, -3]: 4 m radius, 45° apart, rounded to whole metres so results can be checked by hand.
  • End: the wheel jams when the imbalance goes past 40 kg·m (exactly 40 does not jam). Otherwise the round ends after 24 steps. The end line reports riders carried and the largest imbalance.
  • Win and loss: it is a win at 12 or more riders carried, and a loss otherwise.

What I chose not to do

  • No page, catalogue entry or README change.
  • No dependencies.
  • I did not limit boarding to one rider per step, since the issue doesn't ask for it.
  • A jammed round that already carried 12 or more riders still counts as a win, but its end line says the wheel jammed.

The tests cover each rule in the issue, plus the exact-limit case.

Closes #176

2 earlier comments
commented

I added the Ferris Wheel rules in ferris-wheel/wheel.js, with ferris-wheel/wheel.test.mjs beside them. Its 8 tests pass. There is no page or catalogue entry yet, and shell.js, index.html, town.js and rounds.mjs are untouched.

Not run: bun x tsc --noEmit only printed 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 docs/VISION.md and AGENTS.md don't exist, so I ran only the new test file.

How the wheel plays

  • Setup: start(seed) gives 8 gondolas of 3 seats and a queue of 20 riders. Weights are 20–95 kg and rides last 2–6 steps. The same seed always gives the same queue.
  • Board and skip: board(state) seats the front rider in the gondola at the platform. It is refused with full when that gondola has no free seat. skip(state) sends the front rider to the back once, and a second skip of that rider is refused with already-skipped. A refused move returns the very same state.
  • Step: step(state) turns the wheel one gondola, lets off riders whose ride is over, and recomputes the imbalance. The imbalance is the sum of weight times lever arm in kg·m. The arms for the 8 positions, in metres, are [0, 3, 4, 3, 0, -3, -4, -3]: 4 m radius, 45° apart, rounded to whole metres so results can be checked by hand.
  • End: the wheel jams when the imbalance goes past 40 kg·m (exactly 40 does not jam). Otherwise the round ends after 24 steps. The end line reports riders carried and the largest imbalance.
  • Win and loss: it is a win at 12 or more riders carried, and a loss otherwise.

What I chose not to do

  • No page, catalogue entry or README change.
  • No dependencies.
  • I did not limit boarding to one rider per step, since the issue doesn't ask for it.
  • A jammed round that already carried 12 or more riders still counts as a win, but its end line says the wheel jammed.

The tests cover each rule in the issue, plus the exact-limit case.

commented

This pull adds ferris-wheel/wheel.js, which seats a queue of riders and keeps the wheel balanced, plus ferris-wheel/wheel.test.mjs. The first preview deploy failed because the test run stalled past 600 s, and I think that was the deploy machine rather than this change.

  • The stall: it happened in empire/page.test.mjs right after its first test, a file this pull doesn't touch. Run here, that file and the Ferris Wheel tests pass together (22 pass, 0 fail, about 10 s).
  • The fix: I found nothing in the code to fix. The Ferris Wheel module has no loops that could hang a neighbouring test file. I pushed an empty commit so the check runs again.
  • Not run: scripts/gate.ts doesn't exist in this clone, so I skipped it. bun x tsc --noEmit printed its help text instead of a type-check result, so it didn't run cleanly either.
  • If it stalls again: the empire page test is the likely cause. Someone should look at why it can hang on a loaded runner.

To try it, run bun test ferris-wheel.

🤖 Generated with Claude Code

commented

Both review points are fixed and pushed. bun test ferris-wheel passes (11 tests). I didn't re-run tsc or the other suites.

  • refresh() in ferris-wheel/wheel.js: the end line is now one flat decision on jammed and won. Each of the four end lines is built once, so no string is built and then overwritten. The wording of the lines is unchanged.
  • Jammed-but-won test: a wheel that has reached the rider line and then jams reads The wheel jammed at 300 kg*m, but 12 riders were carried. A jam below the line reads jammed at 300 kg*m: 2 riders carried…. The first test fails without the jammed-but-won line.
  • Boarding after a step: after step(), board() seats the next rider in the gondola now at the platform (the last one when turns is 1), not gondola 0.
  • Empty queue: board and skip on an empty queue both return why: 'empty-queue' and the same state object.

I didn't touch the page or the catalogue entry; you listed them as the next pull.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs