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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy ab54f53

opened this

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. There is no scripts/gate.ts or scripts/fast.ts in 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.html or rounds.mjs. There is no page and no catalogue entry yet, as the issue asked.

The match

  • Field: 16 m × 32 m, with a river across the middle and a bridge in each lane. Each side has two lane towers (200 hp) and a king tower (400 hp).
  • Cards: Each side holds a hand of four from the six cards, and a played card goes to the back of the queue.
CardElixir cost
Knight3
Archers3
Giant (only hunts towers)5
Goblins2
Brute4
Fireball4
  • Elixir: one per 2.8 s, capped at 10. From 60 s on it refills twice as fast.
  • Placement: Troops go only on your own half. Fireball can land anywhere and hurts only the rival's troops and towers.
  • Crossing: A troop walks to the nearest bridge before entering the river and stays on it while in the water.
  • Ending: A fallen king ends the match at once. Otherwise at 90 s more rival towers down wins, then more tower health, then a draw.
  • Rival: rivalMove acts 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

  • The rules advance in 0.1 s steps, so the elixir change at 60 s lands exactly on a step.
  • The Giant ignores troops and walks straight to the nearest tower. A tower shoots the nearest troop in range, and every other troop attacks whatever is nearest.
  • The numbers (hp, damage, range, speed) are mine, chosen to keep the rules small, not tuned for balance.

I did not add any page, art or sound, and no dependencies.

To try it: bun test tower-duel, or bun -e "import('./tower-duel/duel.js').then(m=>console.log(m.simulate(42).reason))".

Closes #130

Changes requested — before the latest push

Rules are clean and deterministic, input is validated at the boundary, no I/O or secrets. Changes for one round:

  1. 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.
  2. 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.
  3. Fireball's hit list 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.
  4. play() on a fireball that downs a lane tower emits no 'tower' event, unlike step(); emit it so consumers see one shape.
commented

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.

  1. 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.
  2. 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).

  1. hit shape: Fireball's hit is now { troops: [ids], towers: [{ side, kind, lane }] }. The towers use the same shape as the tower events.
  2. Events from play(): play() now also returns events, in order: the card's own event, then a tower event for each lane tower the Fireball downs, then over if it downs the king. These are the same shapes step() emits. I kept the single event field as well, so nothing that reads it breaks.
Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs