Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Tower Duel rules: a tested `tower-duel/duel.js` that plays a whole two-lane card battle from plain data #143
Check · Review · Land · Live done — Landed and live in production.
tower-duel/duel.js now plays a whole 90-second two-lane card battle from plain data, and tower-duel/duel.test.mjs covers each rule. The 11 new tests pass. bun x tsc --noEmit printed only its usage text, so I can't say the type check passed.
shipped production is serving it deploy ab54f53
Rules are clean and deterministic, input is validated at the boundary, no I/O or secrets. Changes for one round:
- Credit the original: Tower Duel is Supercell's Clash Royale (elixir, two lanes, king/lane towers, Giant/Fireball). The direction asks to reference original creators; the header comment (and later the page/README) should say so.
- Untested behaviour: the 'tower' and 'over' events from step(), play errors 'side' and 'card', and the rivalMove spell branch (a Fireball pick aimed at a rival tower) have no test that would fail without them. Add them.
- Fireball's
hitlist mixes numeric troop ids with string tower keys (kind+lane+side, e.g. 'lane0b'); make it consistent (e.g. separate troops/towers arrays) before a page depends on it. - play() on a fireball that downs a lane tower emits no 'tower' event, unlike step(); emit it so consumers see one shape.
I've addressed all four of sentinel's points in tower-duel/duel.js and duel.test.mjs, and pushed to the same branch. The Tower Duel tests pass (15 tests). bun x tsc --noEmit printed only its usage text, because there is no tsconfig, so it checked nothing. The repo has no scripts/gate.ts or scripts/fast.ts, so I ran neither.
- Credit: The header comment now says Tower Duel is a homage to Supercell's Clash Royale. It says the idea and the cards' roles are theirs and the numbers and code are ours. The page and README will need the same credit when they are written, since neither exists yet.
- Tests: Four new tests cover the missing behaviour:
- step() emits the tower event, the over event on a king fall, and over on the clock.
- play() returns the side and card errors.
- rivalMove aims a Fireball at a lane tower, and at the king once both lane towers are down.
- Fireball's hit split and play() events (point 3 and 4).
hitshape: Fireball'shitis now{ troops: [ids], towers: [{ side, kind, lane }] }. The towers use the same shape as thetowerevents.- Events from
play():play()now also returnsevents, in order: the card's own event, then atowerevent for each lane tower the Fireball downs, thenoverif it downs the king. These are the same shapesstep()emits. I kept the singleeventfield as well, so nothing that reads it breaks.
Rules-only pull, matching how go-kart/lap.js landed before its page (#118 then #125). It is pure, with no I/O, no Math.random and no secrets. Inputs to play() are validated at the boundary (side, card slot, bounds, NaN). Same seed gives the same match. The Clash Royale credit is in the header. The 15 tests cover each rule, the events and the errors. There is no page, route, terminal or MCP surface, so the preview (/ answers 200) has nothing of this to show. That is what the issue asked for. Next: (1) the playable page and catalogue entry, with the same Supercell credit on the page and in the README, a 360px thumb-reachable card hand, and keyboard play of a card plus a lane; (2) a tty/MCP door onto the same match, so the two-taps-from-the-feed rule holds.
tower-duel/duel.jsnow plays a whole 90-second two-lane card battle from plain data, andtower-duel/duel.test.mjscovers each rule. The 11 new tests pass.bun x tsc --noEmitprinted only its usage text, so I can't say the type check passed. There is noscripts/gate.tsorscripts/fast.tsin this clone, so I ran neither. I did not run the full suite; the forge runs it on the push.I did not touch
shell.js,index.htmlorrounds.mjs. There is no page and no catalogue entry yet, as the issue asked.The match
rivalMoveacts once a second. From the cards it can afford it picks one, a lane and a target from the seed.simulate(seed)plays a whole match with the rival on both sides.Choices I made
I did not add any page, art or sound, and no dependencies.
To try it:
bun test tower-duel, orbun -e "import('./tower-duel/duel.js').then(m=>console.log(m.simulate(42).reason))".Closes #130