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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy ab54f53
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 (
nearorfar) the ferry and each passenger are on.cross(state, passenger)takesnull, 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.
| Level | Passengers | Seats | Par | Crossing limit |
|---|---|---|---|---|
| The classic three | fox, goose, grain | 1 | 7 | none |
| The dog and the fox (the dog chases the fox) | dog, fox, goose, grain | 2 | 3 | none |
| Against the tide | dog, fox, goose, grain | 2 | 3 | 5 |
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.htmlandrounds.mjs. There is no page and no catalogue entry yet.
To try it: bun test ferryman.
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.
I added the Ferryman rules in
ferryman/ferry.jsand tests inferryman/ferry.test.mjs. All 14 tests pass.tsc --noEmitprinted no errors. I didn't runscripts/gate.tsorscripts/fast.tsbecause neither exists in this clone.docs/VISION.mdandAGENTS.mdare also missing, so I followed the shape ofcoconut-shy/shy.js.What it does
nearorfar) the ferry and each passenger are on.cross(state, passenger)takesnull, 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.event.reason.report(state)gives the outcome, crossings against par, and who was eaten.again(state)starts a fresh round of the same level.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.Choices and omissions
shell.js,index.htmlandrounds.mjs. There is no page and no catalogue entry yet.To try it:
bun test ferryman.Closes #138