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

Migrated from github.com/amirmushichge/pixel-plays

Ferryman rules: a tested `ferryman/ferry.js` that plays the fox, goose and grain crossing from plain data #152

Merged opened this

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

Merged

I added the Ferryman rules in ferryman/ferry.js and tests in ferryman/ferry.test.mjs. All 14 tests pass. tsc --noEmit printed no errors.

Notes

shipped production is serving it deploy ab54f53

opened this

I added the Ferryman rules in ferryman/ferry.js and tests in ferryman/ferry.test.mjs. All 14 tests pass. tsc --noEmit printed no errors. I didn't run scripts/gate.ts or scripts/fast.ts because neither exists in this clone. docs/VISION.md and AGENTS.md are also missing, so I followed the shape of coconut-shy/shy.js.

What it does

  • State and moves: the state records which bank (near or far) the ferry and each passenger are on. cross(state, passenger) takes null, a name, or an array of names for a ferry with more than one seat. It returns { state, event } and never changes the state you pass in.
  • Refusals: a passenger on the other bank, an unknown passenger, a passenger listed twice, too many riders, or a move after the round is over is refused. The state comes back unchanged, with the reason in event.reason.
  • Losses: after each crossing it checks only the bank the ferry left. A forbidden pair there ends the round as a loss that names who ate whom, for example "the fox ate the goose". Running out of crossings is also a loss.
  • Wins: when everyone is across, the round ends as a win, with a line like "7 of par 7: par!" or "2 over".
  • Report: report(state) gives the outcome, crossings against par, and who was eaten. again(state) starts a fresh round of the same level.
  • Par proof: solve(level) is a breadth-first search for the shortest solution. The tests check that each level's par equals its length and that playing it wins.
LevelPassengersSeatsParCrossing limit
The classic threefox, goose, grain17none
The dog and the fox (the dog chases the fox)dog, fox, goose, grain23none
Against the tidedog, fox, goose, grain235

Choices and omissions

  • Par on level 2: I assumed par 5, but the search found 3 (dog and goose over, back alone, fox and grain over), so I set par to 3.
  • Level 3: it has the same pieces as level 2 and only adds the limit of 5.
  • Not touched: shell.js, index.html and rounds.mjs. There is no page and no catalogue entry yet.

To try it: bun test ferryman.

Closes #138

commented

I added the Ferryman rules in ferryman/ferry.js and tests in ferryman/ferry.test.mjs. All 14 tests pass. tsc --noEmit printed no errors. I didn't run scripts/gate.ts or scripts/fast.ts because neither exists in this clone. docs/VISION.md and AGENTS.md are also missing, so I followed the shape of coconut-shy/shy.js.

What it does

  • State and moves: the state records which bank (near or far) the ferry and each passenger are on. cross(state, passenger) takes null, a name, or an array of names for a ferry with more than one seat. It returns { state, event } and never changes the state you pass in.
  • Refusals: a passenger on the other bank, an unknown passenger, a passenger listed twice, too many riders, or a move after the round is over is refused. The state comes back unchanged, with the reason in event.reason.
  • Losses: after each crossing it checks only the bank the ferry left. A forbidden pair there ends the round as a loss that names who ate whom, for example "the fox ate the goose". Running out of crossings is also a loss.
  • Wins: when everyone is across, the round ends as a win, with a line like "7 of par 7: par!" or "2 over".
  • Report: report(state) gives the outcome, crossings against par, and who was eaten. again(state) starts a fresh round of the same level.
  • Par proof: solve(level) is a breadth-first search for the shortest solution. The tests check that each level's par equals its length and that playing it wins.
LevelPassengersSeatsParCrossing limit
The classic threefox, goose, grain17none
The dog and the fox (the dog chases the fox)dog, fox, goose, grain23none
Against the tidedog, fox, goose, grain235

Choices and omissions

  • Par on level 2: I assumed par 5, but the search found 3 (dog and goose over, back alone, fox and grain over), so I set par to 3.
  • Level 3: it has the same pieces as level 2 and only adds the limit of 5.
  • Not touched: shell.js, index.html and rounds.mjs. There is no page and no catalogue entry yet.

To try it: bun test ferryman.

Approved

Clean rules module in the shape of tower-duel/duel.js and coconut-shy/shy.js: plain data in and out, no DOM, timers or randomness, state never mutated, refusals leave state untouched. Passenger names are checked against the level list before indexing, so there is no prototype-key trick. Only the bank the ferry left is checked for danger, which is correct. I traced the level 2 par of 3 by hand and it holds. The BFS in the tests proves each par is the minimum. Every behaviour has a test. No page, shell or catalogue wiring, which matches the rules-only scope the pull states. Non-blocking: level 3 is nearly the same puzzle as level 2 (limit 5 vs par 3). The page pull could credit the old river-crossing riddle (Alcuin) in its copy.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs