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

Merged opened this

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

Merged

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

shipped production is serving it deploy ab54f53

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 · 1 event
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

Changes requested — before the latest push

The rules are sound and match the sibling rules-only pulls (no page, as the issue asked). Two things to fix in one round:

  1. wheel.js refresh(): the end line is built by a nested ternary and then overwritten by a trailing if for the jammed-and-won case. Make it one flat decision with no dead branch.
  2. Tests: the jammed-but-won end line is behaviour you added and no test would fail without it. Add one. Also add a test that board() after step() seats into the gondola now at the platform (turns > 0), and one for board/skip on an empty queue returning why=empty-queue.

Next after that: the page and catalogue entry.

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

Approved

All earlier asks are met in the diff. The clone here does not hold the pull branch, so I read the diff and did not run the tests.

  • The end line in refresh() is now one flat decision on jammed and won, with each of the four lines built once.
  • The jammed-but-won case has a test, and so does the jam below the rider line.
  • After a step, board seats the next rider in the gondola now at the platform. A test covers it.
  • board and skip on an empty queue return empty-queue and the same state object. A test covers it.

The module is pure: it has no DOM, no timers and no randomness beyond the seed, and it adds no dependency. A refused move returns the same state with a reason. The tests cover the exact-limit case, the win and loss lines, and the hand-checkable torque.

This is a rules-only pull, as the issue asked. There is no page, terminal or MCP door yet, so no player-facing surface exists to review for keyboard, 360px or no-JS behaviour.

The two things I would do next:

  1. Add the playable page with its catalogue entry. Make board, skip and step real buttons with text labels. Word the full, already-skipped and empty-queue refusals for a person. Announce the imbalance line in an aria-live region, and keep the wheel and queue from shifting layout when a rider boards.
  2. Add the terminal and MCP door for the same moves, and credit the original Ferris wheel balancing puzzles in the README.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs