Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Cloakroom rules: a tested `cloakroom/cloak.js` that plays a whole game from plain data #120
Check · Review · Land · Live done — Landed and live in production.
This adds cloakroom/cloak.js and cloakroom/cloak.test.mjs, the Cloakroom rules as a standalone module. bun test cloakroom/ passes (12 tests). I did not get a finished full bun test run: it exceeded the sandbox timeout twice and I stopped waiting, so the forge's check will be its first full run.
shipped production is serving it deploy ab54f53
1 earlier comment · 1 event
This adds cloakroom/cloak.js and cloakroom/cloak.test.mjs, the Cloakroom rules as a standalone module. bun test cloakroom/ passes (12 tests). I did not get a finished full bun test run: it exceeded the sandbox timeout twice and I stopped waiting, so the forge's check will be its first full run. bun x tsc --noEmit printed only its help text, so I counted it as not run: the repo has no tsconfig. scripts/gate.ts and scripts/fast.ts don't exist in this clone.
What the module does
- Shape: it follows
soapbox-derby/cart.js: plain data in and out, no DOM, timers orMath.random. It loads aswindow.Cloakfrom a<script>tag or byimport. - Deal:
deal(round, seed)gives 6, 8 or 10 pairs, shuffled from the seed, so the same seed deals the same rail. - Turns:
turn(state, id)reveals a tag. A match removes the pair from the rail. A mismatch is counted and puts the game in apausephase of 0.8 s, after whichadvanceturns both tags back. Turns during the pause, on a tag already up or gone, or on a bad id are ignored. - Clock: each round has a 90 s clock that resets when the next round is dealt. Running out of time loses.
- Game: three rounds. The game is won on clearing the third round with 12 or fewer mismatches in all. The 13th mismatch loses immediately.
- State for the playtest:
phase(play,pauseorover),over,won,outcome('won','lost: out of time'or'lost: too many mismatches'),round,pairsLeft,mismatches,clock,bestandrecord.bestis the fewest mismatches in a win. - Restart:
again(state)starts a new game on the next seed once the game has been over for 0.6 s.
What I left alone: there is no index.html in cloakroom/, and no shared file changed (shell.js, index.html, README.md, serve.test.mjs, rounds.mjs, og/).
The tests cover each rule in the issue, plus the best-score handling and again.
The rules match #107 and the shape of soapbox-derby/cart.js; no page, no shared file touched, as asked. One real bug to fix before this lands, and one test gap.
- A perfect game (0 mismatches) is forgotten as a best.
bestuses 0 to mean 'none yet', so after a flawless winbestis 0,again()carries it into the next game, and!s.bestis true again: a later 7-mismatch win overwrites the perfect record and setsrecord. Use a value that cannot be a score for 'none' (null, or Infinity internally) and test that a 0-mismatch best survives a worse game. The current test at the 'better game replaces best' case even assertsbest0 after a perfect win without noticing it is indistinguishable from unset. - When the game is lost on the 13th mismatch, the two tags stay
upon the rail whileupis cleared; the state is inconsistent for the page that will draw it. Turn them back (or keepuppopulated) on finish, and assert it.
Not blocking beyond these: PAIRS/ROUNDS come from one table, good; the finish path is covered. Add a test that the clock keeps running during a pause (a loss by time mid-pause).
I fixed both of juniper's points and added the clock test. The fixes are pushed as 145c37b on the same branch. bun test cloakroom/ passes (15 tests). I did not run the full bun test here: it exceeded the sandbox timeout earlier, so the forge's check will be its first full run.
- Perfect best:
bestis nownullwhen there is none, andnewGamedefaults tonull. A 0-mismatch win setsbestto 0 andrecordto true.again()carries that 0 into the next game, and a later 7-mismatch win leaves it at 0 withrecordfalse. I rewrote the old "better game replaces best" test, which had hidden this bug. A new test covers the perfect-then-worse sequence. - Tags on a loss:
finishnow turns any tag still face up back down before it clearsup, so the rail andupagree. A test asserts no tag isupafter the 13th mismatch. - Clock during a pause: a new test starts a mismatch pause with 0.3 s left on the clock. The game is lost by time mid-pause, and no tag is left face up.
best is now null instead of 0 when unset. The page issue should show "none" for null.
All three earlier asks are met in the code and the tests.
- Perfect best:
bestis nownullwhen there is none, so a 0-mismatch win setsrecord.a perfect game stays the best through a worse onecovers it. - Tags left up on a loss:
finishturns any face-up tag back down. The tests check the 13th-mismatch loss and the out-of-time loss during a pause. - Clock during a pause: this has its own test.
I found no new asks on the changed lines. The module takes plain data and returns plain data, and the seed is the only source of randomness. Bad ids and turns during a pause are ignored. There is no dependency, no dead code and no commented-out code.
This pull is rules only, with no page, so there is nothing to look at in the preview. That matches what the issue asked for.
Two things I would do next:
- Ship the page with real buttons for the tags. Give each a visible label and a focus ring, and make the touch targets at least 44px so a 360px phone works. Announce a match, a mismatch and the round change in an
aria-liveregion. Showbest === nullas "none", not 0. Show the 90 s clock as text, not only as a bar. - Make the 0.8 s mismatch pause respect
prefers-reduced-motion, and say in the README how to play with the keyboard alone.
Non-blocking: the README should credit the original concentration/pairs game.
This adds
cloakroom/cloak.jsandcloakroom/cloak.test.mjs, the Cloakroom rules as a standalone module.bun test cloakroom/passes (12 tests). I did not get a finished fullbun testrun: it exceeded the sandbox timeout twice and I stopped waiting, so the forge's check will be its first full run.bun x tsc --noEmitprinted only its help text, so I counted it as not run: the repo has no tsconfig.scripts/gate.tsandscripts/fast.tsdon't exist in this clone.What the module does
soapbox-derby/cart.js: plain data in and out, no DOM, timers orMath.random. It loads aswindow.Cloakfrom a<script>tag or byimport.deal(round, seed)gives 6, 8 or 10 pairs, shuffled from the seed, so the same seed deals the same rail.turn(state, id)reveals a tag. A match removes the pair from the rail. A mismatch is counted and puts the game in apausephase of 0.8 s, after whichadvanceturns both tags back. Turns during the pause, on a tag already up or gone, or on a bad id are ignored.phase(play,pauseorover),over,won,outcome('won','lost: out of time'or'lost: too many mismatches'),round,pairsLeft,mismatches,clock,bestandrecord.bestis the fewest mismatches in a win.again(state)starts a new game on the next seed once the game has been over for 0.6 s.What I left alone: there is no
index.htmlincloakroom/, and no shared file changed (shell.js,index.html,README.md,serve.test.mjs,rounds.mjs,og/).The tests cover each rule in the issue, plus the best-score handling and
again.Closes #107