Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Clock Mender rules: a tested `clock-mender/gears.js` where you set gears on pegs to link the winding key to the clock hands within par, from plain data, in a two-file pull with a test file that runs in under a second #312
Check · Review · Land · Live done — Landed and live in production.
Clock Mender rules: clock-mender/gears.js and clock-mender/gears.test.mjs are added, and nothing else is touched. All 10 tests pass, and bun test clock-mender/gears.test.mjs runs in 47 ms (0.053 s wall). The test file calls the rules module directly: no page, renderer or server.
shipped production is serving it deploy ab54f53
1 earlier comment · 1 event
Clock Mender rules: clock-mender/gears.js and clock-mender/gears.test.mjs are added, and nothing else is touched. All 10 tests pass, and bun test clock-mender/gears.test.mjs runs in 47 ms (0.053 s wall). The test file calls the rules module directly: no page, renderer or server. I ran bun x tsc --noEmit; it printed only its usage text, so it did no type check. There is no scripts/gate.ts or scripts/fast.ts in this repo, so I ran neither.
Rules
- Geometry: pegs are named
"x,y". A size-s gear reaches pegs exactly s away, so two gears of sizes a and b mesh when their squared distance equals (a+b)² and overlap when it is less. Everything is compared in exact integers, with no square roots. A size-1 gear reaches pegs 2 away, sizes 1 and 2 reach 3 away, and sizes 2 and 3 reach the 3-4-5 peg (5 away). - Levels:
start(level)gives one of 7 hand-made levels. Each has a grid, key peg, arbor peg, blocked pegs, tray, required direction, par and stated solution. An invalid level number gives level 0. placeandlift:place(state, peg, size)andlift(state, peg)return{ok, state, why}. A refused call returns the same state object. Reasons:
- place: blocked, taken, not-in-tray, overlap, off-plate, game-over.
- lift: fixed, empty, off-plate, game-over.
drive:drive(state)runs from the key, which turns clockwise, and alternates direction along each mesh. A mesh joining two gears that already turn the same way jams the train, so nothing turns andjammedis true. A loop elsewhere that the key doesn't reach is ignored. Solved means the arbor turns the required way with no jam.- Win and restart: the win line is, for example, "You win: the hands turn anticlockwise with 2 gears, par 2 (on par)", or "N under par" / "N over par".
restart(state)is always allowed, and there is no loss state.
Choices to check
- The key and arbor are fixed size-1 gears and don't count toward par.
- A won game refuses
placeandliftwithgame-over, as the issue says. To undo a win you restart. - Par is the length of the stated solution. The tests check each stated solution solves its level at that length, but not that no shorter solution exists.
- Level 6 ("Three-gear trap") has the 1-2-3 sizes mesh pairwise, which gives the odd-loop jam.
I did not add a page, a catalogue entry or any wiring. Nothing in the pull needed the 600 s or CPU-limit caveat.
Rules are plain data in/out, integer-exact geometry, every refusal returns the same state object with a reason, and the tests cover each stated rule. I checked all seven stated solutions by hand against the mesh/direction rules and they hold. I could not run the suite here (my clone sits at the base, without the new files), so the passing run and 47 ms timing rest on the builder's report. Two things I would do next: (1) the page and catalogue entry so the rules are reachable, since a rules module nobody can call is not yet a game, and it should be keyboard-operable with 44px pegs on a 360px phone; (2) add a test that a jammed loop the key never reaches is ignored, which is the current behaviour, and decide it is intended. Also trim unused exports (DIRS, KEY_SIZE) unless the page will use them.
Left #293 open: 1 unticked item remain (place(state, peg, size) puts a gear from the tray on a free, unblocked peg, and lift(state, peg) returns it to the tray. Both refuse anything else with a reason: a blocked or taken peg, a size not in the tray, a gear that would overlap another, or a game already over. A refused call returns the same state.).
Clock Mender rules:
clock-mender/gears.jsandclock-mender/gears.test.mjsare added, and nothing else is touched. All 10 tests pass, andbun test clock-mender/gears.test.mjsruns in 47 ms (0.053 s wall). The test file calls the rules module directly: no page, renderer or server. I ranbun x tsc --noEmit; it printed only its usage text, so it did no type check. There is noscripts/gate.tsorscripts/fast.tsin this repo, so I ran neither.Rules
"x,y". A size-s gear reaches pegs exactly s away, so two gears of sizes a and b mesh when their squared distance equals (a+b)² and overlap when it is less. Everything is compared in exact integers, with no square roots. A size-1 gear reaches pegs 2 away, sizes 1 and 2 reach 3 away, and sizes 2 and 3 reach the 3-4-5 peg (5 away).start(level)gives one of 7 hand-made levels. Each has a grid, key peg, arbor peg, blocked pegs, tray, required direction, par and stated solution. An invalid level number gives level 0.placeandlift:place(state, peg, size)andlift(state, peg)return{ok, state, why}. A refused call returns the same state object. Reasons:-
place:blocked,taken,not-in-tray,overlap,off-plate,game-over. -lift:fixed,empty,off-plate,game-over.drive:drive(state)runs from the key, which turns clockwise, and alternates direction along each mesh. A mesh joining two gears that already turn the same way jams the train, so nothing turns andjammedis true. A loop elsewhere that the key doesn't reach is ignored. Solved means the arbor turns the required way with no jam.restart(state)is always allowed, and there is no loss state.Choices to check
placeandliftwithgame-over, as the issue says. To undo a win you restart.I did not add a page, a catalogue entry or any wiring. Nothing in the pull needed the 600 s or CPU-limit caveat.
Closes #293