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

Migrated from github.com/amirmushichge/pixel-plays

Hopscotch rules: a tested `hopscotch/court.js` where you toss a stone onto a seeded hopscotch court and hop the squares in order, skipping the stone's square, before your turns run out, in a two-file pull with a test file that runs in under a second #380

opened this

Merged 10h 55m ago, live in production

This adds the Hopscotch rules as a two-file pull, hopscotch/court.js and hopscotch/court.test.mjs. It adds no page or catalogue entry. bun test hopscotch/court.test.mjs passes 11 of 11 in about 0.017 s wall time (12 ms reported by bun).

Notes

opened this

This adds the Hopscotch rules as a two-file pull, hopscotch/court.js and hopscotch/court.test.mjs. It adds no page or catalogue entry. bun test hopscotch/court.test.mjs passes 11 of 11 in about 0.017 s wall time (12 ms reported by bun). The test file calls the rules module directly and loads no page, renderer or server. I did not run the full bun test, and the repo has no scripts/gate.ts, so there was no gate run.

The rules

  • Shape: court.js has the same UMD shape as churns.js and exports Hopscotch in the browser. It uses plain data in and out, a seeded mulberry32 generator, and no Math.random.
  • start(seed): it gives the same court, turns and meter period for the same seed. The court has 8–11 squares in order, always with at least one side-by-side double. There are 3–5 turns, and the period is set so every square can be read.
  • meter(state, tick): a pure triangle wave of the tick that reads 1 to N.
  • Ticks: toss(state) takes no tick argument, so the state carries a tick and I added tick(state, n) to advance it. The page will need to call it as the meter sweeps.
  • toss(state): it lands the stone on the square the meter reads. Landing on the needed square starts hopping. Any other square costs one turn, and the last turn lost ends the game.
  • hop(state, square): it accepts only the next square in order and never the stone's square. Finishing the round clears the needed square and moves the need on to the next. Clearing square N wins.
  • Refusals: each returns the same state object with a reason and costs no turn. The reasons are no-toss, out-of-order, on-stone, unknown-square, already-hopping and game-over. unknown-square is one I added for a square that is not an integer in range.
  • End lines: "You win: N squares cleared, T turns left" and "Out of turns: C of N squares cleared, T turns left".
  • restart(state): it gives the same seed fresh.
  • State fields: need, turns, phase, cleared, score and line.
  • Score: it is cleared*100 + turns*10, which the issue did not specify.

Tests

  • They cover each rule in the issue: determinism, the toss at the needed reading and one either side, a missed toss costing a turn, in-order hopping with the stone skipped, every refusal, both endings, restart, and that nothing mutates frozen input.
  • Mutation: the no-mutation test freezes the state and checks every call.

Not done: no shell.js, index.html, town.js, rounds.mjs, forge.json, scripts/, playtest.test.mjs or serve.test.mjs changes, and no UI.

To try it: bun test hopscotch/court.test.mjs.

🤖 Generated with Claude Code

Closes #375

commented

This adds the Hopscotch rules as a two-file pull, hopscotch/court.js and hopscotch/court.test.mjs. It adds no page or catalogue entry. bun test hopscotch/court.test.mjs passes 11 of 11 in about 0.017 s wall time (12 ms reported by bun). The test file calls the rules module directly and loads no page, renderer or server. I did not run the full bun test, and the repo has no scripts/gate.ts, so there was no gate run.

The rules

  • Shape: court.js has the same UMD shape as churns.js and exports Hopscotch in the browser. It uses plain data in and out, a seeded mulberry32 generator, and no Math.random.
  • start(seed): it gives the same court, turns and meter period for the same seed. The court has 8–11 squares in order, always with at least one side-by-side double. There are 3–5 turns, and the period is set so every square can be read.
  • meter(state, tick): a pure triangle wave of the tick that reads 1 to N.
  • Ticks: toss(state) takes no tick argument, so the state carries a tick and I added tick(state, n) to advance it. The page will need to call it as the meter sweeps.
  • toss(state): it lands the stone on the square the meter reads. Landing on the needed square starts hopping. Any other square costs one turn, and the last turn lost ends the game.
  • hop(state, square): it accepts only the next square in order and never the stone's square. Finishing the round clears the needed square and moves the need on to the next. Clearing square N wins.
  • Refusals: each returns the same state object with a reason and costs no turn. The reasons are no-toss, out-of-order, on-stone, unknown-square, already-hopping and game-over. unknown-square is one I added for a square that is not an integer in range.
  • End lines: "You win: N squares cleared, T turns left" and "Out of turns: C of N squares cleared, T turns left".
  • restart(state): it gives the same seed fresh.
  • State fields: need, turns, phase, cleared, score and line.
  • Score: it is cleared*100 + turns*10, which the issue did not specify.

Tests

  • They cover each rule in the issue: determinism, the toss at the needed reading and one either side, a missed toss costing a turn, in-order hopping with the stone skipped, every refusal, both endings, restart, and that nothing mutates frozen input.
  • Mutation: the no-mutation test freezes the state and checks every call.

Not done: no shell.js, index.html, town.js, rounds.mjs, forge.json, scripts/, playtest.test.mjs or serve.test.mjs changes, and no UI.

To try it: bun test hopscotch/court.test.mjs.

🤖 Generated with Claude Code

merged this
Sign in to join this conversation.

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

Keyboard shortcuts

Docs