Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Lock Keeper rules: a tested `lock-keeper/lock.js` that works boats through a flight of canal locks from plain data #154
Merged 33d 16h ago, live in production
I added the Lock Keeper rules in lock-keeper/lock.js with tests in lock-keeper/lock.test.mjs. The new test file passes (11 tests, about 7 s, almost all of it the par search). scripts/gate.ts and scripts/fast.ts don't exist in this clone, so I didn't run them.
-
Reviews
Changes requested — before the latest pushThe rules read correctly and the tests cover each refusal, the flood and the win. One thing has to change before this lands.
Fix first:
newRound(seed)callspar(seed). For any seed outside the shipped 1, 2 and 3, that runs a synchronous breadth-first search of up to 80 levels on the caller's thread. The test file takes about 7 s mostly because of this, andnewRound(7)in the determinism test pays for it. Starting a round on an unshipped seed will freeze a page or a request far past the 50 ms bar. MakenewRoundO(1). Either leaveparout of the state (use the table value ornull) and exposepar(seed)as an explicit call, or restrictnewRoundto SEEDS. Add a test thatnewRound(7)returns quickly and that itsparis a number ornull, never a hang.shortestcan also returnnullafter 80 levels, solinemust not printpar null.Also fix:
newRoundBareduplicates the lock literal innewRound. Extract onefreshLocks()and use it in both.- The
PARScomment has stray alignment spaces. throughis exported and used only inside the module. Keep it only if the page will call it.
ApprovedReviewed every line of lock-keeper/lock.js and its tests. It is a pure rules module with no I/O, no network, no storage, no eval and no secrets, so there is no injection, authorization or escaping surface. apply() validates lock and act at the boundary, returns the same state object on refusal and never throws. newRound is O(1) now that par is a table lookup. I checked the gate and paddle rules and the flood rule by hand, and the tests cover the refusals, the flood, the win and the determinism of the queue. I did not run the tests: the checkout I had did not contain lock-keeper/. Like the sibling rules pulls (ferryman, hoopla, tower-duel), it ships the rules only, as the issue asks. Nit, not blocking: the PARS comment is still spaced differently from its neighbours.
-
Checks
shipped production is serving it deploy 7b8dc66
-
History
- Lock Keeper: newRound is O(1), par is the table value or null; one freshLocks() 8164834
- Lock Keeper rules: a tested lock-keeper/lock.js that works boats through a flight of three canal locks (#140) 35f2f78
- Town layout: a tested `town.js` that places one isometric building per game and picks the building under a point (#142) db45970
- Add Go-Kart Fete: the playable page and its place in the catalogue, on the rules already in `go-kart/lap.js` (#125) 273a249
- Add Coconut Shy: the playable page and its place in the catalogue, on the rules already in `coconut-shy/shy.js` (#126) 07b3d0a
- main is red: Espresso Bar, Firefly Jar, Signal Box and Soapbox Derby have no scripted round in rounds.mjs (#129) 1f38243
- Add Dinghy Race: the playable page and its place in the catalogue, on the rules already in `dinghy-race/dinghy.js` (#128) d793ca5
- Add Cloakroom: the playable page and its place in the catalogue, on the rules already in `cloakroom/cloak.js` (#123) 58406d4
- Add Egg Basket: slide the basket along the henhouse to catch eggs rolling off the roof before they crack (#117) 281a1c6
- Coconut Shy rules: a tested `coconut-shy/shy.js` that plays a whole game from plain data (#119) a6f45f0
- Go-Kart Fete rules: a tested `go-kart/lap.js` that plays a whole game from plain data (#118) 57e78b4
- Bell Tower peal-length page test is slow (≈4.5 s) and needed a 30 s budget (#122) e3fd868
- Dinghy Race rules: a tested `dinghy-race/dinghy.js` that plays a whole game from plain data (#121) 0e7807c
- Cloakroom rules: a tested `cloakroom/cloak.js` that plays a whole game from plain data (#120) 7d12e0d
- build age of empires 2. take your time and be thorough. focus on a full gamep… (#115) 7a8fe89
- Add Hot Air Balloon: ride the wind layers and set the basket down on the marked field (#116) 32a9aa4
- the picker above the game needs to be better for all the games we have now (#100) d0bf4f9
- Add Tug of War: pull in rhythm with your team to drag the rope's ribbon over your line at the village fete (#97) 97bb230
- Add Sheepdog: guide the flock through the gate and into the pen before the light goes (#93) 6f1ec61
- Add Firefly Jar: tap the glowing fireflies into a jar on a summer night before the moths put the lantern out (#90) 6db3d65
I addressed all of @juniper's points and pushed to the same branch. The new test file passes (12 tests). I didn't run tsc or the other checks again after this change. The test file still takes about 5.5 s because of the par-reachability test, which runs the search on purpose.
newRoundis O(1):par(seed)now returns the table value for seeds 1 to 3 andnullfor any other seed, with no search.shortest(seed)is the explicit, slow way to find a par. I dropped the memo cache because nothing needs it now.linewith no par: it leaves out the "(par …)" part whenparisnull, so it never printspar null.- New test:
newRound(7)returns in under 50 ms, itsparisnull, and itslinehas no mention of par. Seed 1 still reports par 36. freshLocks(): one shared function now builds the locks, andnewRoundBareis gone.- Cleanups: I fixed the stray spaces in the
PARScomment and removedthroughfrom the exports, since only the module uses it.
🤖 Generated with Claude Code
I added the Lock Keeper rules in
lock-keeper/lock.jswith tests inlock-keeper/lock.test.mjs. The new test file passes (11 tests, about 7 s, almost all of it the par search).scripts/gate.tsandscripts/fast.tsdon't exist in this clone, so I didn't run them. I did not runscripts/design-lint.tsbecause nothing insrc/web/changed.What it does
loworhighlevel, a top and bottom gate, and a top and bottom paddle.apply(state, { lock, act })takespaddle-top,paddle-bottom,gate-top,gate-bottomormove. It returns{ state, ok, why, events }.uneven-water,gate-open,gate-closed,no-room,no-boat,round-over,no-such-lockorno-such-act. It never throws.reason: 'flood'.move, only through an open gate. A lock holds one boat and a middle pound holds two.opsagainstpar.newRound(seed)gives one boat waiting at each end and, for some seeds, a third, so 2 or 3 boats. The same seed always gives the same queue. Shipped seeds are 1, 2 and 3.shortest(seed), over every legal operation sequence that avoids a flood. The test checks that the search gives the same figures, so par is reachable and no shorter solution exists.Choices to know about
I did not touch
shell.js,index.htmlorrounds.mjs, and I added no page and no catalogue entry, as the issue asked.To try it, run
bun test lock-keeper/lock.test.mjs.🤖 Generated with Claude Code
Closes #140