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

Migrated from github.com/amirmushichge/pixel-plays

Mill Race rules: a tested `mill-race/race.js` that turns pipe tiles to carry the stream to the water wheel, from plain data #191

Merged opened this

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

Merged

This adds the Mill Race rules in mill-race/race.js with tests in mill-race/race.test.mjs, and nothing outside that folder. The 7 new tests pass. I couldn't run bun x tsc --noEmit here: it printed only its help text and no type errors.

Notes

shipped production is serving it deploy ab54f53

opened this

This adds the Mill Race rules in mill-race/race.js with tests in mill-race/race.test.mjs, and nothing outside that folder. The 7 new tests pass. I couldn't run bun x tsc --noEmit here: it printed only its help text and no type errors. docs/VISION.md, scripts/gate.ts and scripts/fast.ts don't exist in this clone, so I skipped them.

What changed

  • Grid: start(seed, level) builds a level + 3 square grid of straight, bend, tee and blank tiles, with the sluice on the west edge and the wheel on the east edge. The same seed and level always give the same grid. Levels run 1 to 5.
  • Solvability: each level is laid from a connected west-to-east path, which is then turned out of true by seeded quarter turns. A level never starts already cleared. state.scramble lists each path tile's turns, and undoing them always clears the level.
  • Turning: turn(state, x, y) rotates a tile a quarter turn clockwise and counts one move. It refuses a blank tile, off-grid or non-integer coordinates, and any turn after the game is over, returning the same state and a reason.
  • Flow: flow(state) returns the cells the water reaches from the sluice. When it reaches the wheel, the next, larger level starts. Moves over par carry forward, and clearing level 5 ends the game.
  • Par and result: par for a level is the fewest turns that put its laid path right. The win line is 6 moves over par in total or fewer, with "The wheel turns: …". Anything more gives "The race ran dry: …".

What I chose not to do

  • There is no page, no catalogue entry, and no change to shell.js, index.html, town.js or rounds.mjs, as the issue asked.
  • Par comes from the laid path only. A shortcut through the non-path tiles could beat par, and that just counts as zero over.

Try it: bun test mill-race. In a console, MillRace is the browser global and require('./mill-race/race.js') works under Bun.

🤖 Generated with Claude Code

Closes #174

2 earlier comments · 1 event
commented

This adds the Mill Race rules in mill-race/race.js with tests in mill-race/race.test.mjs, and nothing outside that folder. The 7 new tests pass. I couldn't run bun x tsc --noEmit here: it printed only its help text and no type errors. docs/VISION.md, scripts/gate.ts and scripts/fast.ts don't exist in this clone, so I skipped them.

What changed

  • Grid: start(seed, level) builds a level + 3 square grid of straight, bend, tee and blank tiles, with the sluice on the west edge and the wheel on the east edge. The same seed and level always give the same grid. Levels run 1 to 5.
  • Solvability: each level is laid from a connected west-to-east path, which is then turned out of true by seeded quarter turns. A level never starts already cleared. state.scramble lists each path tile's turns, and undoing them always clears the level.
  • Turning: turn(state, x, y) rotates a tile a quarter turn clockwise and counts one move. It refuses a blank tile, off-grid or non-integer coordinates, and any turn after the game is over, returning the same state and a reason.
  • Flow: flow(state) returns the cells the water reaches from the sluice. When it reaches the wheel, the next, larger level starts. Moves over par carry forward, and clearing level 5 ends the game.
  • Par and result: par for a level is the fewest turns that put its laid path right. The win line is 6 moves over par in total or fewer, with "The wheel turns: …". Anything more gives "The race ran dry: …".

What I chose not to do

  • There is no page, no catalogue entry, and no change to shell.js, index.html, town.js or rounds.mjs, as the issue asked.
  • Par comes from the laid path only. A shortcut through the non-path tiles could beat par, and that just counts as zero over.

Try it: bun test mill-race. In a console, MillRace is the browser global and require('./mill-race/race.js') works under Bun.

🤖 Generated with Claude Code

Changes requested — before the latest push

Rules-only scope matches the issue and the logic reads sound (deterministic seed, laid-then-scrambled solvability, copy-on-turn, refusals return the same state). No page or terminal door is in this pull, so the preview has nothing to show. Three fixes, in one round:

  1. Credit the original. The direction asks for faithful reference to original creators; the header says nothing about this being the pipe-turning genre of Pipe Mania (Lucasfilm Games, 1989, Empire Software / Oasis). Add a short credit in the header comment of race.js.
  2. Dead branch in lay(): both arms of the ternary are identical.
  3. The 'wasted move' test asserts only moves===1 and never checks the over-par accounting that the title of the test claims. Make a real wasted turn (turn a tile 4 extra times, or turn a solved path tile away and back), clear the level, and assert state.over equals the extra moves.
commented

All three fixes are pushed, and the 7 tests in mill-race/race.test.mjs pass. I didn't run bun x tsc --noEmit this round. Last round it printed only its help text.

  1. Credit: the header of race.js now credits Pipe Mania (The Assembly Line, 1989). It names Lucasfilm Games as the US publisher (as Pipe Dream) and Empire Software as the European publisher. It also says the rules and code are this repository's own.
  2. Dead ternary: lay() is now const to = Math.floor(rnd(n++) * size);.
  3. Wasted-move test: the test turns one tile four times, which changes nothing but costs four moves. It checks the tiles are unchanged and moves is 4, then solves the level. It asserts the level clears and over is exactly 4.

Credit wording: I didn't name "Oasis" as you suggested, because I couldn't confirm it. As I remember it, The Assembly Line made the game and Empire published it in Europe. Say if you can point to a source for Oasis and I'll add it. I also didn't name individual designers, since I couldn't confirm who they were.

🤖 Generated with Claude Code

commented

I found nothing in this pull to fix, so I pushed an empty commit to rerun the preview check.

The pull adds only mill-race/race.js and mill-race/race.test.mjs. The failed deploy hit its 600-second limit while running empire/page.test.mjs, which I didn't touch.

Locally, empire/page.test.mjs passes all 14 tests in 9.8s, and the mill-race suite passes all 7 in 0.4s. I did not run the whole suite or the other pre-push checks here, because nothing in the diff reaches anything outside mill-race/. If the rerun times out again in the empire tests, the slowness is in that suite or on the deploy machine, not in the mill-race rules.

Pull description: Mill Race rules. mill-race/race.js turns channel tiles to carry the stream to the water wheel. mill-race/race.test.mjs covers it, including over-par accounting with real wasted turns. I didn't build the playable page; that is a separate step. To try it, run bun test mill-race.

Approved

Rules-only, as the issue asked. No inputs, writes or output are reached, so there is nothing to attack here: turn() validates coordinates with Number.isInteger and bounds, refuses blank tiles and finished games, and copies state before changing it. Generation is seeded with no Math.random, no eval and no dependencies. The header credits Pipe Mania and its publishers and says the rules and code are this repo's own. The tests cover determinism, solvability of 200 seeded levels, refusals, rotation, flow, over-par accounting with real wasted turns, and the win and loss lines. I did not run them or the preview. The pull adds no page, so the preview has nothing to show. Approving.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs