Compare commits
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: wizwar-audits
|
||||
description: Run the Wiz-War health audits — UI coverage of engine events/cards (the "telepath audit"), live-game ledger inspection by room code, and the pre-deploy determinism gate. Use when asked to audit, when adding cards or events, or when a player reports "the engine did X but I never saw it".
|
||||
---
|
||||
|
||||
# Wiz-War audits
|
||||
|
||||
Three recurring audits keep the maze honest. The first is self-enforcing;
|
||||
the other two are on-demand.
|
||||
|
||||
## 1. UI coverage — "the telepath audit" (automated)
|
||||
|
||||
`packages/engine/test/ui-coverage.test.ts` runs with every `npm test` and
|
||||
fails when:
|
||||
|
||||
- a GameEvent type has no client handling (no `humanize` case in
|
||||
`net.svelte.ts`, no fx in `fx.ts`, no modal check in `App.svelte`) and is
|
||||
not in the test's `SILENT_BY_DESIGN` allowlist — each allowlist entry
|
||||
needs a reason for why the player sees the information another way;
|
||||
- a card resolver demanding a cell/edge target is missing from App's
|
||||
`CELL_CARDS` / `EDGE_CARDS` click-targeting sets (an unaimable cast).
|
||||
|
||||
When adding an **event**: give it a `humanize` line at minimum. Private
|
||||
info (`visibleTo` events carrying cards) deserves the `cardReveal` modal
|
||||
in App.svelte — see `handRevealedPrivate` / `cardsStolenPrivate` /
|
||||
`handTakenPrivate` for the pattern. When adding a **card** with a cell or
|
||||
edge target, add it to the App targeting set; with `params`, wire the
|
||||
named-card picker (`NAMED_CARDS` + suggestions) or a bespoke control.
|
||||
|
||||
The one axis the test cannot judge: whether a `params`-taking card's
|
||||
input UI actually offers sensible choices. Check that by hand when adding
|
||||
one (thief → target's steallables, deja-vu → discard contents, etc.).
|
||||
|
||||
## 2. Live-game audit by room code
|
||||
|
||||
Fetch and replay production ledgers (details in auto-memory
|
||||
`wizwar-fetch-game-files`):
|
||||
|
||||
scp root@104.236.96.198:/var/lib/wizwar/rooms/<CODE>.jsonl <scratchpad>/
|
||||
|
||||
Replay with `createGame({playerIds, seed, sets, colors, deckRev})` +
|
||||
`applyCommand` per command line (see `deploy/replay-verify.mjs`). Stop at
|
||||
any seq to inspect full state. To ask why a bot did something, rebuild
|
||||
the state at its turn and call `automatonCommand(viewFor(state, id),
|
||||
style, tier)` — and if its choice differs from the ledger, the engine
|
||||
refused it and the fallback burned the turn.
|
||||
|
||||
For "which games are open/stalled" sweeps: fetch all `*.jsonl`, replay
|
||||
each, and report phase / round / humans vs bots / last command's `at`.
|
||||
|
||||
## 3. Determinism gate (before deploying engine changes)
|
||||
|
||||
deploy/verify-ledgers.sh 104.236.96.198
|
||||
|
||||
Strict-replays every production ledger against the local engine; one
|
||||
refused command fails. A room whose ledger no longer replays becomes
|
||||
unreachable after restart. Rules changes while games are live need a
|
||||
`deckRev` bump plus an engine gate. Production deckRev is currently 1,
|
||||
so low numbers are not stale.
|
||||
@@ -0,0 +1,341 @@
|
||||
---
|
||||
name: wizwar-duel
|
||||
description: Play Wiz-War live against Eric — join his room as a real seat, reason about every move yourself, and duel turn by turn over the websocket. Use when Eric wants a game, gives a room code, or says "let's play".
|
||||
---
|
||||
|
||||
# Playing Wiz-War against Eric
|
||||
|
||||
You are a PLAYER, not the automaton. Read the board, reason, and choose
|
||||
every command yourself. Eric plays in his browser; you play through the
|
||||
CLI seat at `tools/claude-seat.mjs`. He prompts "go" after his moves —
|
||||
each of his messages is your cue to look and act.
|
||||
|
||||
## The seat client
|
||||
|
||||
Run from the repo root (needs the workspace's `ws` package):
|
||||
|
||||
```bash
|
||||
node tools/claude-seat.mjs join <ROOM> Claude # take a seat (token saved)
|
||||
node tools/claude-seat.mjs view # board + hand + last events
|
||||
node tools/claude-seat.mjs do '<command json>' # one engine command
|
||||
node tools/claude-seat.mjs chat "text" # table talk
|
||||
```
|
||||
|
||||
Seat state persists in `/tmp/wizwar-claude-seat.json` (override:
|
||||
`WIZWAR_SEAT`); server defaults to production (`WIZWAR_SERVER` to point
|
||||
elsewhere). Eric creates the room, gives you the code, and starts the
|
||||
game after you join.
|
||||
|
||||
Commands are the engine's `Command` union (packages/engine/src/game.ts):
|
||||
`{"type":"move","direction":"N|S|E|W"}`, `cast` (with `target`, optional
|
||||
`numberInstanceIds`/`params`), `playNumberForMovement`, `pickUpTreasure`,
|
||||
`dropTreasure`, `warpStep`, `counteract`, `pass`, `punch`, `setAmbush`,
|
||||
`wardChoice`, `endTurn` (with `draw`). A refused command costs nothing —
|
||||
probing legality is free, so when unsure, try it and read the error.
|
||||
|
||||
## Reading the map
|
||||
|
||||
- The renderer prints y=0 at top; **y grows SOUTH**. N = y-1, S = y+1.
|
||||
- `C2` is you, `P1` etc. are opponents, `$c`/`$1` treasures, `h?` homes,
|
||||
two-letter codes are square contents (SA safe, RO rosebush, ST stone,
|
||||
DU dust). `D` on a line is a door, `—` a wall, blank is open.
|
||||
- WARPS line lists rim passages as `2,0N→2,9`: standing at (2,0) and
|
||||
moving N carries you to (2,9). **The warp rides one specific side of
|
||||
its square** — check which before you walk (a wrong guess burns moves;
|
||||
ask me how I know).
|
||||
- Dimensional-warp TOKENS (cast by players) are separate: stand on one
|
||||
and `warpStep`. Creatures use `creatureWarpStep`.
|
||||
|
||||
## Hard-won rules knowledge (each cost me something in game one)
|
||||
|
||||
- `pickUpTreasure` ENDS your turn's actions AND movement — arrive with
|
||||
the grab as your last act, never mid-plan. `dropTreasure` at home too.
|
||||
- You can pick up ANY floor treasure, including your own stolen-and-
|
||||
delivered one sitting on the enemy's home square. Repossession is real.
|
||||
- THIEF and punches need same-square; THIEF steals a *named* card and
|
||||
fizzles (card spent) on a wrong guess.
|
||||
- MENTAL FORCE moves the victim ≤3 *walked* spaces — walls and relocked
|
||||
doors shrink its reach; rev 5+ refuses impossible destinations.
|
||||
- Doors relock behind you when you pass through (rev 4+). Your own
|
||||
escape route can seal itself — and seal pursuers out.
|
||||
- LOS threads through rim warps: you can be seen (and shot) through a
|
||||
warp mouth from the far side of the board. Camping one square off the
|
||||
mouth keeps you hidden.
|
||||
- lock-in-place freezes movement AND warpStep for a full turn; REUSE
|
||||
SPELL retrieves only your LAST cast spell, enabling one re-lock.
|
||||
- An ambush (`setAmbush` interrupt/opportunity-fire + committed attack)
|
||||
triggers on LOS *entry* transitions only — someone already in sight
|
||||
never springs it. It survives forever and fires out of turn.
|
||||
- Walking-dead bleeds ½ life per space moved, permanently. Once cursed,
|
||||
every plan must be priced in steps.
|
||||
|
||||
## Game-two scars (each cost me the game or nearly)
|
||||
|
||||
- **RECOUNT THE SCOREBOARD EVERY TURN**: how many treasures does each
|
||||
player have banked AT HOME right now? I sprinted a "winning" delivery
|
||||
in game two that was actually my FIRST of two — Eric had un-banked me
|
||||
five rounds earlier and let me monologue. Banked counts, not vibes.
|
||||
- A banked treasure is NOT safe: anyone can pick it up off your home
|
||||
square and carry it away. Guard the bank or count it as contested.
|
||||
- LOS is FREE-ANGLE center-to-center (the rulebook's rule), not rows
|
||||
and columns: razor diagonals threading open gaps are legal for
|
||||
everyone — including at you. The board draws bent/straight traces.
|
||||
- ILLUSIONARY ATTACK deals its imitated spell's damage if NOT
|
||||
countered; ANY counteraction dispels it entirely. Counter it with
|
||||
the cheapest thing you hold; never "call the bluff" by passing.
|
||||
- Never trust your ASCII parse of the map for multi-step plans: run a
|
||||
BFS over `view.board.edges` (see tools/claude-seat.mjs view JSON, or
|
||||
write a quick router) before spending a number card on a sprint. I
|
||||
burned a 7-move turn bouncing off six misread walls.
|
||||
- Eric counter-plays YOUR bot upgrades: he summoned a troll bodyguard
|
||||
specifically against the archmage's exile-the-winner instinct, and
|
||||
relocated MY home sector mid-carry. Expect meta-warfare.
|
||||
- In 4p with automatons: the bots are chaos agents — they stun, exile,
|
||||
disease, and con. Herd them at Eric; never assume they're on script.
|
||||
|
||||
## Game-three scars (lost in four rounds)
|
||||
|
||||
- **CHECK `dimWarps` EVERY SINGLE VIEW** — Kestrel (Eric's wizard) has
|
||||
won two games
|
||||
with quietly-placed wormholes ending beside his home. The client
|
||||
prints a !! line for them; treat any new token pair as a five-alarm
|
||||
fire and recompute both players' delivery distances through it.
|
||||
- **Never lead the attack against Kestrel.** Three games, three saved
|
||||
counters sprung at the perfect moment (anti-anti, full-shield bait,
|
||||
full-reflection held three rounds for my lightning). Force his
|
||||
counters out with throwaways or positional threats before committing
|
||||
a real spell; his patience is perfect and he telegraphs nothing.
|
||||
- DESTROY WALL showers the ADJACENT caster with rubble (4 damage) —
|
||||
cast it from range, never on your own square's edge.
|
||||
- Wading a rosebush costs 3. A reflected LIGHTNING BLAST still stuns
|
||||
its caster even at 1 reflected damage — the stun is the payload, and
|
||||
a lost turn against Kestrel is a lost game.
|
||||
- Grab-turn-one openings feel great and prove nothing: deliveries are
|
||||
the only score. He banked quietly both times while I showboated.
|
||||
|
||||
## Game-five scars (eliminated by a rule I implemented myself)
|
||||
|
||||
- **THE ELIMINATION CLOCK**: the moment BOTH treasures you protect sit
|
||||
on living opponents' home bases, you are OUT — points, life, and
|
||||
position notwithstanding. In multiplayer this clock starts ticking
|
||||
the instant your second chest is picked up by anyone. From then on,
|
||||
every turn must either recover a chest or end the game first. I spent
|
||||
three turns optimizing deliveries while two bots quietly carried my
|
||||
death certificate.
|
||||
- **FEAR IS A SELF-CAST AURA** — read the card, not your assumptions:
|
||||
"no player or monster will move to within 3 spaces of you," walls
|
||||
irrelevant, and anyone already within 3 MUST flee on their turn. It
|
||||
is armor for carriers and a hearth-denial tool: a feared wizard
|
||||
standing 2 from your home makes delivery impossible. I invented an
|
||||
elaborate theory about enemy goalkeeping instead of reading my own
|
||||
engine's card text. Check `data/cards.json` when a rule surprises —
|
||||
it is one grep away and it is verbatim.
|
||||
- In four-player, Kestrel plays the TABLE, not the duel: his SWAP
|
||||
yanked a bot off its own doorstep mid-delivery and parked himself by
|
||||
unclaimed treasures — one card, two tempo hits. Expect every card he
|
||||
plays to hurt two players at once, and ask which two before deciding
|
||||
it wasn't aimed at you.
|
||||
- CREATE WALL can sever your announced return route the turn after you
|
||||
telegraph it. If your road home is unique, either don't stand at the
|
||||
far end of it, or carry the picks/doors to re-open it. And CREATE
|
||||
DOOR makes LOCKED doors — it is a key-cutter, worthless without picks.
|
||||
- Bot threat model: archmage automatons DO deliver, but their brains
|
||||
can dither inexplicably (one toured the map for two rounds carrying
|
||||
my elimination). Never count on bot incompetence — count turns to
|
||||
their delivery square as if they play perfectly, and treat every
|
||||
reprieve as a gift, not a pattern.
|
||||
|
||||
## Game-six scars (the heist)
|
||||
|
||||
- **THORNBUSH IS A JAIL, NOT A FORT**: entering one ends your turn,
|
||||
costs your ENTIRE next turn, and deals 1 damage. The "cannot be
|
||||
attacked" line is the bait; the two-turn tempo loss is the hook.
|
||||
Eric: "Few will dive into one unless they are desperate. You were
|
||||
confident, but not desperate." Enter a bush only when the
|
||||
alternative is death — and READ THE WHOLE CARD before calling
|
||||
anything a shelter. Three rules self-owns in two games (fear,
|
||||
thornbush) — the full text is one grep away, in my own repo.
|
||||
- **MIST-BODY IS A BANK ROBBER**: 5 turns untouchable, walks through
|
||||
doors and walls, picks up treasures, immune to every attack-typed
|
||||
card (drop-object, card-erasure, teleport-opponent included). While
|
||||
an enemy is misted, do not plan counterplay — plan for WHERE the
|
||||
mist will be when it lapses, and meanwhile DISPERSE value: banking
|
||||
everything on one home square builds the heist target. A creature
|
||||
guard is scenery to a ghost.
|
||||
- The bait-fork fallacy: I "forked" him between my two treasures, but
|
||||
both forks were MY assets. He ignored both and took the third thing
|
||||
— the treasure I'd just consolidated. When your fork only threatens
|
||||
what you own, it isn't a fork; it's a to-do list you published.
|
||||
|
||||
## Game-nine scar: concentrate your thefts
|
||||
|
||||
- Kestrel won in FOUR ROUNDS by stealing BOTH treasures from the SAME
|
||||
victim (the nearest bot): two bankings = the win, and the second one
|
||||
simultaneously eliminated the victim via the captured-treasures
|
||||
clause. Robbing one player twice beats robbing two players once —
|
||||
same points, one fewer opponent, and the victim's own corner becomes
|
||||
your supply depot. When choosing the second steal, weigh "same
|
||||
victim" heavily.
|
||||
- Also: never chain move commands blind in a script — the (6,6) nook
|
||||
refused all three exits and my pipeline barreled into endTurn,
|
||||
burning a full turn standing still. Verify each step's result, or at
|
||||
minimum stop the chain on the first refusal.
|
||||
|
||||
## Game-ten scars (the closest one)
|
||||
|
||||
- **The champion's carrier-breaker combo**: DROP OBJECT (chest falls at
|
||||
your feet) + ADRENALINE (second attack) + TELEPORT OPPONENT (you,
|
||||
exiled across the maze; the chest, his). A laden wizard within his
|
||||
cast range is a wizard about to be unpacked. Carry through his reach
|
||||
only with a real counteraction in hand — and VERIFY a card actually
|
||||
counters before building your defense on it (NO SPELL is a silencing
|
||||
curse, not a counter; I learned mid-stack).
|
||||
- **He ferries his own death warrant**: when the elimination clause
|
||||
hung on his floor chest, he simply picked his route so the chest
|
||||
traveled with him. Deny-by-custody. Do the same: when MY vulnerable
|
||||
treasure lies on my path, take it along.
|
||||
- Sector relocation can REWRITE the whole world mid-game — arms move,
|
||||
warps rewire, routes invert. After any rotate/relocate event, throw
|
||||
away every cached route and re-run the router.
|
||||
- Eric's deeper frame: on wrap boards (especially 3- and 5-sector
|
||||
layouts) RELOCATE SECTOR is a TOPOLOGY WEAPON — one shift breaks
|
||||
ALL the curved warps at once and "everything is just across the
|
||||
board." Its payload is everyone else's stale mental map: the caster
|
||||
knows the new sewing instantly. Hold it for the moment an enemy's
|
||||
plan leans on a wrap (a warp delivery lane, a rim escape), then cut
|
||||
the seam. Conversely, never build a plan whose ONLY road is a warp
|
||||
while an opponent might hold this card.
|
||||
|
||||
## The board is a torus (from Eric, after game eleven)
|
||||
|
||||
- The warping rims mean there is NO center and NO edge: take the right
|
||||
column and sew it onto the left — identical geography. "Central" and
|
||||
"peripheral" seats are rendering artifacts of where the map unrolls.
|
||||
Thinking in those terms is a trap that limits your options (his
|
||||
words). Judge NOTHING by coordinates: distance is graph distance,
|
||||
threat is graph threat, and the router (BFS over edges + warps) is
|
||||
the only geometry that exists. Mentally re-unroll the map from
|
||||
wherever you stand — every wizard is the center of their own map.
|
||||
- BUT salience is Euclidean even when geometry is not (Eric): humans
|
||||
see "center tiles" and aim their aggression there, so the
|
||||
center-perceived seat pays an attention tax — and a strong player
|
||||
turns it into arbitrage: absorb the squabble, footrace out and back
|
||||
through wraps that make you secretly equidistant from everything.
|
||||
Play the graph for movement, the salience for predicting humans;
|
||||
expect neither bias nor exploitability from the bots — their BFS is
|
||||
natively non-Euclidean.
|
||||
|
||||
## Game-thirteen scars (the goat)
|
||||
|
||||
- **BUTT-HEAD is a cross-map physical nuke**: damage = the full walked
|
||||
distance of the charge, and it found 8 points across half a maze.
|
||||
ABSORB SPELL answers spells ONLY — at low life with no teleport in
|
||||
hand, there is NO answer to big physical; your only defenses are
|
||||
position and never being worth the charge. Audit the hand for
|
||||
physical answers separately from spell answers.
|
||||
- He parks his OWN chest on open floor when he needs free arms —
|
||||
custody is a dial, not a state. Watch every drop: grounded chests
|
||||
are targets again the moment they land.
|
||||
- My game-one wall and his one dust cloud shaped the ENTIRE game:
|
||||
single-square terrain on a junction outlives every spell cast near
|
||||
it. Place terrain at junctions, not corridors.
|
||||
|
||||
## Game-fourteen scars (the five-player raid race)
|
||||
|
||||
- **Terrain is SOFT in tempo math.** I counted a thornbush and an ooze
|
||||
square as two turns of delay on his banking route; DISPEL CREATION
|
||||
removed the bush for one card and zero steps, and he banked that
|
||||
same turn. Any creation (bush, ooze, wall of stone, stones) is one
|
||||
card from gone — count it as HALF a turn of delay, never a wall.
|
||||
- On wide boards (5-6p cross), a raider in my quadrant carrying my
|
||||
chest is usually UNREACHABLE by anything in hand — the interception
|
||||
had to happen a turn earlier, at the grab, not the haul. Defend the
|
||||
chest square, not the exit route.
|
||||
- My real boobytrap finally fired (4 damage to a warping bot) — traps
|
||||
on WARP LANDING squares hit players who never see the token coming.
|
||||
That placement doctrine is proven; repeat it.
|
||||
|
||||
## The passivity audit (Eric, after game thirteen)
|
||||
|
||||
- "You did nothing but draw for several turns" — true, and fatal. A
|
||||
turn that only draws is a LOST turn. When genuinely walled: probe.
|
||||
Dust-stagger attempts, LOS probes, wall punches, terrain casts —
|
||||
motion generates dice, information, and pressure; stillness
|
||||
generates nothing and hands the opponent free repositioning. The
|
||||
round-8 expedition that nearly won game thirteen was available in
|
||||
round 5. If two consecutive turns end in draw-only, something is
|
||||
wrong with the plan, not the maze.
|
||||
|
||||
## The board is the truth (I keep paying for this one)
|
||||
|
||||
- NEVER narrate a persistent effect without re-verifying it in the
|
||||
CURRENT view. My stones get dispelled, my walls get melted, my
|
||||
theories get invented. Before crediting any creation, curse, or
|
||||
blockade in reasoning OR table talk, check the CONTENTS and
|
||||
SUSTAINED lines and the map glyphs THIS turn. Kestrel quietly
|
||||
removes my infrastructure and lets my own commentary reveal that I
|
||||
haven't noticed.
|
||||
- Corollary: every "go" starts with reading the events tail for what
|
||||
the OTHERS did to the board, not just where they stand. A dispel,
|
||||
a stone-to-water, or a rotate-sector in that tail invalidates last
|
||||
turn's map in my head.
|
||||
|
||||
## Playing well
|
||||
|
||||
- Kestrel (Eric) is EXCELLENT: he baited my thief, saved anti-anti for
|
||||
my full shield, and won game one with a home-to-home dimensional-warp
|
||||
superhighway. Infrastructure beats sprinting — watch what he builds,
|
||||
and consider your own wormhole early.
|
||||
- Win = 2 enemy treasures delivered to your home, or last wizard alive.
|
||||
Track BOTH players' step-counted delivery timelines every turn; the
|
||||
race is decided in tempo, not damage.
|
||||
- Hold counters (full-shield, absorb) for permanent curses and lethal
|
||||
damage. Absorb soaks 3 points; it cannot touch durations.
|
||||
- OPSEC: your prose is visible to Eric. NEVER name the cards you hold or
|
||||
draw, and never announce plans. (Game one: I narrated my hand like a
|
||||
debug log until he asked why I was making it easy.) Trash talk freely
|
||||
— about the board, never your hand.
|
||||
- OPSEC round two (game six, violated AGAIN): analysis spoken aloud IS a
|
||||
card shown. Quoting a card's text with delight ("moves a piece to ANY
|
||||
square!") told him exactly what I held and what it does. Card-text
|
||||
lookups for cards in MY hand happen silently; my visible messages may
|
||||
discuss only what is already public on the board or in the chronicle.
|
||||
Even asking rules questions aloud about a specific card is a tell.
|
||||
- OPSEC round three (game fourteen): METAPHORS COUNT. "A door my pick
|
||||
answers" and "key ready for tomorrow" revealed a pick-lock as surely
|
||||
as naming it. The rule in its final form: table prose may reference
|
||||
ONLY public state — positions, banked counts, events already in the
|
||||
chronicle. Nothing about my hand, capabilities, or intentions, in
|
||||
any costume. When in doubt, describe the BOARD, never my options.
|
||||
- Send `chat` for table talk at dramatic moments; it's half the fun.
|
||||
|
||||
## The turn poller (no more idling)
|
||||
|
||||
After ending each turn (or whenever waiting on others), launch the
|
||||
watcher in the background so the harness wakes you the moment the
|
||||
game needs you — your turn or a counteraction window:
|
||||
|
||||
```
|
||||
node <scratchpad>/my-turn-poller.mjs # run_in_background: true
|
||||
```
|
||||
|
||||
(Script lives in the session scratchpad; recreate from the skill's
|
||||
memory if missing: it joins with the saved seat token, watches state
|
||||
messages, and exits with "WAITING ON CLAUDE: <reason>".) Eric asked
|
||||
for this after game eight sat waiting on me — don't make him prompt
|
||||
"your turn" ever again.
|
||||
|
||||
CRITICAL: launch it ONLY with the harness's run_in_background flag —
|
||||
that is what wakes you when it exits. A shell `&` inside a normal
|
||||
command detaches it into the void and nobody hears it fire (game
|
||||
eight, twice). One poller per wait; it exits when the game needs you.
|
||||
|
||||
## Cadence
|
||||
|
||||
1. On "go": `view`, read HIS events since your last turn (the client
|
||||
prints only NEW events; `view` shows a short history tail).
|
||||
2. Think about the whole board — his timeline, yours, threats, LOS.
|
||||
3. Execute your commands one at a time, checking errors.
|
||||
4. `endTurn` with a draw that respects the 7-card hand limit.
|
||||
5. Tell Eric it's his turn — reasoning aloud is fine, hand contents are
|
||||
not. When a stack waits on him, say so and wait for "go".
|
||||
@@ -4,5 +4,6 @@ dist/
|
||||
.env
|
||||
.DS_Store
|
||||
data/
|
||||
.claude/
|
||||
.claude/*
|
||||
!.claude/skills/
|
||||
.playwright-mcp/
|
||||
|
||||
@@ -23,6 +23,14 @@ research), installs dependencies on the droplet, and restarts the service.
|
||||
Games in progress survive: state lives in room files, and clients reconnect
|
||||
automatically.
|
||||
|
||||
Before any deploy that touches the engine, run the determinism gate:
|
||||
|
||||
deploy/verify-ledgers.sh 104.236.96.198
|
||||
|
||||
It fetches every production ledger and strictly replays it against the local
|
||||
engine; a single refused command fails the check. A room whose ledger no
|
||||
longer replays becomes unreachable after restart, so this is not optional.
|
||||
|
||||
## New droplet from scratch
|
||||
|
||||
1. `doctl compute droplet create wizwar --region nyc3 --size s-1vcpu-1gb \
|
||||
@@ -35,4 +43,10 @@ automatically.
|
||||
|
||||
- Logs: `ssh root@<ip> journalctl -u wizwar -f`
|
||||
- Restart: `ssh root@<ip> systemctl restart wizwar`
|
||||
- Backup games: `scp -r root@<ip>:/var/lib/wizwar/rooms ./rooms-backup`
|
||||
- Nightly backups: `wizwar-backup.sh` runs from root's crontab at 07:17 UTC,
|
||||
pushing /var/lib/wizwar to the `kestrel-wizwar-backups` Space (nyc3) via
|
||||
rclone. It is installed at /usr/local/bin/wizwar-backup.sh on the droplet;
|
||||
`setup-droplet.sh` does NOT install it — on a fresh droplet, copy the
|
||||
script, configure rclone (the script refuses to run while the config still
|
||||
holds its CHANGE_ME placeholder), and add the cron entry by hand.
|
||||
- One-off backup: `scp -r root@<ip>:/var/lib/wizwar/rooms ./rooms-backup`
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Strict full-ledger replay: ANY refused command is a hard failure.
|
||||
import { readFileSync } from "fs";
|
||||
import { createGame, applyCommand } from "../packages/engine/src/game.ts";
|
||||
const lines = readFileSync(process.argv[2], "utf8").trim().split("\n").map((l) => JSON.parse(l));
|
||||
const meta = lines.find((l) => l.kind === "meta");
|
||||
const start = lines.find((l) => l.kind === "start");
|
||||
if (!start) {
|
||||
console.log(`OK ${process.argv[2].split("/").pop()}: lobby only, nothing to replay`);
|
||||
process.exit(0);
|
||||
}
|
||||
const joins = lines.filter((l) => l.kind === "join");
|
||||
const playerIds = [...new Set([meta.hostId, ...joins.map((j) => j.name)])];
|
||||
let { state } = createGame({ playerIds, seed: meta.seed, sets: start.expansion ? ["basic", "expansion1"] : ["basic"], colors: start.colors, deckRev: start.deckRev });
|
||||
let n = 0;
|
||||
for (const l of lines) {
|
||||
if (l.kind !== "command") continue;
|
||||
const r = applyCommand(state, l.playerId, l.command);
|
||||
if (!r.ok) { console.log(`FAIL ${process.argv[2].split("/").pop()} seq ${l.seq}: ${r.error}`); process.exit(1); }
|
||||
state = r.state; n++;
|
||||
}
|
||||
console.log(`OK ${process.argv[2].split("/").pop()}: ${n} commands replay clean`);
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# Pre-deploy determinism check: fetch every production ledger and strictly
|
||||
# replay it against the LOCAL engine. Any refused command is a hard failure.
|
||||
# Run from the repo root before deploying any engine change.
|
||||
set -euo pipefail
|
||||
HOST="${1:-104.236.96.198}"
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
scp -q "root@$HOST:/var/lib/wizwar/rooms/*.jsonl" "$TMP/"
|
||||
fails=0
|
||||
for f in "$TMP"/*.jsonl; do
|
||||
# `|| true`: a failing replay must feed the tally, not abort the loop.
|
||||
out=$(npx tsx deploy/replay-verify.mjs "$f" 2>&1 | tail -1) || true
|
||||
case "$out" in
|
||||
OK*) ;;
|
||||
*) echo "${out:-$(basename "$f"): replay crashed with no output}"; fails=$((fails+1));;
|
||||
esac
|
||||
done
|
||||
count=$(ls "$TMP" | wc -l | tr -d ' ')
|
||||
echo "--- $count ledgers checked, $fails failures"
|
||||
[ "$fails" -eq 0 ]
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# Nightly wiz-war ledger backup to DigitalOcean Spaces.
|
||||
# current/ - exact mirror of /var/lib/wizwar
|
||||
# snapshots/ - one dated copy per day, pruned after 90 days
|
||||
# Ledgers are append-only JSONL; the game server never needs stopping.
|
||||
set -u
|
||||
BUCKET="kestrel-wizwar-backups"
|
||||
SRC="/var/lib/wizwar"
|
||||
LOG="/var/log/wizwar/backup.log"
|
||||
STAMP=$(date +%Y-%m-%d)
|
||||
|
||||
if grep -q CHANGE_ME /root/.config/rclone/rclone.conf; then
|
||||
echo "$(date -Is) skipped: Spaces credentials not configured yet" >> "$LOG"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
{
|
||||
echo "=== $(date -Is) backup start"
|
||||
rclone sync "$SRC" "spaces:$BUCKET/wizwar/current" 2>&1
|
||||
rclone copy "$SRC" "spaces:$BUCKET/wizwar/snapshots/$STAMP" 2>&1
|
||||
# Prune dated snapshots older than 90 days (by directory name).
|
||||
CUTOFF=$(date -d "90 days ago" +%Y-%m-%d)
|
||||
rclone lsf "spaces:$BUCKET/wizwar/snapshots/" --dirs-only 2>/dev/null | \
|
||||
while read -r d; do
|
||||
day="${d%/}"
|
||||
if [[ "$day" < "$CUTOFF" ]]; then
|
||||
echo "pruning snapshot $day"
|
||||
rclone purge "spaces:$BUCKET/wizwar/snapshots/$day" 2>&1
|
||||
fi
|
||||
done
|
||||
echo "=== $(date -Is) backup done"
|
||||
} >> "$LOG"
|
||||
@@ -360,6 +360,41 @@ export function hasWarpLineOfSight(
|
||||
to: Cell,
|
||||
blockedCells?: Record<string, true>,
|
||||
): boolean {
|
||||
return warpSightTrace(board, from, to, blockedCells) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* How a sight line reached its target — the material for drawing it. A warp
|
||||
* trace carries the two mouths and the exact rim-crossing points (in board
|
||||
* coordinates, where cell (x,y) spans [x,x+1]) so a renderer can draw the
|
||||
* near leg to `entry` and the far leg from `exit`.
|
||||
*/
|
||||
export type SightTrace =
|
||||
| { kind: "direct" }
|
||||
| {
|
||||
kind: "warp";
|
||||
mouthA: { cell: Cell; side: Side };
|
||||
mouthB: { cell: Cell; side: Side };
|
||||
entry: { x: number; y: number };
|
||||
exit: { x: number; y: number };
|
||||
};
|
||||
|
||||
export function traceSight(
|
||||
board: AssembledBoard,
|
||||
from: Cell,
|
||||
to: Cell,
|
||||
blockedCells?: Record<string, true>,
|
||||
): SightTrace | null {
|
||||
if (hasLineOfSight(board, from, to, blockedCells)) return { kind: "direct" };
|
||||
return warpSightTrace(board, from, to, blockedCells);
|
||||
}
|
||||
|
||||
function warpSightTrace(
|
||||
board: AssembledBoard,
|
||||
from: Cell,
|
||||
to: Cell,
|
||||
blockedCells?: Record<string, true>,
|
||||
): Extract<SightTrace, { kind: "warp" }> | null {
|
||||
const DIR: Record<Side, { x: number; y: number }> = {
|
||||
N: { x: 0, y: -1 }, S: { x: 0, y: 1 }, E: { x: 1, y: 0 }, W: { x: -1, y: 0 },
|
||||
};
|
||||
@@ -372,6 +407,9 @@ export function hasWarpLineOfSight(
|
||||
// A filled mouth chokes the tunnel unless the viewer/target IS the mouth.
|
||||
if (blockedCells?.[cellKey(mouthA)] && cellKey(from) !== cellKey(mouthA)) continue;
|
||||
if (blockedCells?.[cellKey(mouthB)] && cellKey(to) !== cellKey(mouthB)) continue;
|
||||
// A wall built over either mouth seals the tunnel to sight entirely.
|
||||
if (edgeState(board, mouthA, sideA) !== "open") continue;
|
||||
if (edgeState(board, mouthB, w.to.side) !== "open") continue;
|
||||
|
||||
// Rotation taking the far board's inward direction onto sideA.
|
||||
const u = DIR[inward], v = DIR[sideA];
|
||||
@@ -420,10 +458,16 @@ export function hasWarpLineOfSight(
|
||||
segmentClear(board, Pfar.x, Pfar.y, to.x + 0.5, to.y + 0.5, blockedCells,
|
||||
[cellKey(to), cellKey(mouthB)])
|
||||
) {
|
||||
return true;
|
||||
return {
|
||||
kind: "warp",
|
||||
mouthA: { cell: mouthA, side: sideA },
|
||||
mouthB: { cell: mouthB, side: w.to.side },
|
||||
entry: P,
|
||||
exit: Pfar,
|
||||
};
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The game's full line-of-sight check: direct, or through a wraparound opening. */
|
||||
@@ -436,3 +480,34 @@ export function sightBetween(
|
||||
return hasLineOfSight(board, from, to, blockedCells) ||
|
||||
hasWarpLineOfSight(board, from, to, blockedCells);
|
||||
}
|
||||
|
||||
/**
|
||||
* AROUND THE CORNER's full reach: "around one corner (up to 180 degrees)".
|
||||
* A hairpin around the end of a wall pivots IN the wall's gap, not at any
|
||||
* cell's center — so try the midpoint of every open edge as the bend point,
|
||||
* with a clear straight segment from caster to pivot and pivot to target.
|
||||
*/
|
||||
export function bentSightThroughGap(
|
||||
board: AssembledBoard,
|
||||
from: Cell,
|
||||
to: Cell,
|
||||
blockedCells?: Record<string, true>,
|
||||
): boolean {
|
||||
const fx = from.x + 0.5, fy = from.y + 0.5;
|
||||
const tx = to.x + 0.5, ty = to.y + 0.5;
|
||||
const skip = [cellKey(from), cellKey(to)];
|
||||
for (const key of Object.keys(board.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
const c = { x, y };
|
||||
for (const side of ["E", "S"] as Side[]) {
|
||||
if (!board.cells[cellKey(neighbor(c, side))]) continue;
|
||||
if (edgeState(board, c, side) !== "open") continue;
|
||||
const [px, py] = side === "E" ? [x + 1, y + 0.5] : [x + 0.5, y + 1];
|
||||
if (segmentClear(board, fx, fy, px, py, blockedCells, skip) &&
|
||||
segmentClear(board, px, py, tx, ty, blockedCells, skip)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import cardsData from "../data/cards.json";
|
||||
|
||||
export type CardSet = "basic" | "expansion1" | "expansion2";
|
||||
export type CardSet = "basic" | "expansion1";
|
||||
export type CardType =
|
||||
| "attack"
|
||||
| "neutral"
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// The server sends this after every state change; clients never see the
|
||||
// deck order or other players' hands.
|
||||
|
||||
import { sightBetween, type AssembledBoard } from "./board";
|
||||
import { type CardInstance } from "./cards";
|
||||
import { SIDES, edgeKey, sightBetween, bentSightThroughGap, traceSight, type AssembledBoard, type Cell, type SightTrace } from "./board";
|
||||
import { cardDef, type CardInstance } from "./cards";
|
||||
import {
|
||||
boardView,
|
||||
LOS_BLOCKING_CONTENT,
|
||||
@@ -28,6 +28,8 @@ export interface PlayerPublicView {
|
||||
carriedTreasureId: string | null;
|
||||
lostTurns: number;
|
||||
extraTurns: number;
|
||||
/** Banked PASS THROUGH WALL crossings — cast openly, so public knowledge. */
|
||||
passWallCharges: number;
|
||||
displayed: CardInstance[];
|
||||
/** Which of the six physical wizard colors this player plays. */
|
||||
colorIndex: number;
|
||||
@@ -40,8 +42,6 @@ export interface GameView {
|
||||
winReason: "treasures" | "lastStanding" | null;
|
||||
turn: TurnState;
|
||||
activePlayerId: PlayerId;
|
||||
/** The game's rules revision — the client mirrors rev-gated legality. */
|
||||
deckRev: number;
|
||||
/** Board with dynamic wall changes already merged in. */
|
||||
board: AssembledBoard;
|
||||
players: PlayerPublicView[];
|
||||
@@ -57,13 +57,26 @@ export interface GameView {
|
||||
/** Duration spells in play (public knowledge). */
|
||||
sustained: SustainedEffect[];
|
||||
squareContents: Record<string, SquareContent>;
|
||||
/** Cells whose contents are glued down (public: the cast was seen). */
|
||||
gluedCells: Record<string, true>;
|
||||
/** Safes standing open (their combination entered this turn). */
|
||||
openSafes: string[];
|
||||
groundObjects: Record<string, CardInstance[]>;
|
||||
/** The rules revision this game was dealt under. */
|
||||
deckRev: number;
|
||||
doorStates: Record<string, "jammed" | "removed">;
|
||||
/** Accumulated attack damage per edge (public — cracks show). */
|
||||
wallDamage: Record<string, number>;
|
||||
openDoorEdges: string[];
|
||||
/** Door edges held open by a standing wizard. */
|
||||
heldDoorEdges: string[];
|
||||
/** Edges conjured into being (walls, doors, firewalls) - dispellable. */
|
||||
createdEdges: string[];
|
||||
/** Illusion edges YOU know are fake (creator or saw through); others see walls. */
|
||||
knownIllusionEdges: string[];
|
||||
/** Every illusion edge and YOUR verdict on it: untested
|
||||
* shimmers, believes renders solid, mine/seesThrough are ghosts. */
|
||||
illusionEdges: Record<string, "untested" | "believes" | "seesThrough" | "mine">;
|
||||
creatures: CreatureState[];
|
||||
/** Charges left on displayed wands (public), by card instance id. */
|
||||
wandCharges: Record<string, number>;
|
||||
@@ -73,8 +86,8 @@ export interface GameView {
|
||||
outOfTurnWindow: { playerId: PlayerId; kind: "interrupt" | "opportunity-fire" } | null;
|
||||
/** CHAOS shield windows in progress (public: everyone sees it coming). */
|
||||
chaosPending: { casterId: PlayerId; queue: PlayerId[] } | null;
|
||||
/** Whether YOUR ward is set to spring. */
|
||||
yourWardArmed: boolean;
|
||||
/** A grab hangs while the treasure's owner decides their Ward. */
|
||||
wardPending: { ownerId: PlayerId; takerId: PlayerId } | null;
|
||||
/** YOUR armed ambushes. Other players' ambushes are invisible. */
|
||||
yourAmbushes: AmbushState[];
|
||||
/** Once the game is finished, every hand goes face-up on the table. */
|
||||
@@ -84,11 +97,17 @@ export interface GameView {
|
||||
export function viewFor(state: GameState, playerId: PlayerId): GameView {
|
||||
const you = state.players.find((p) => p.id === playerId);
|
||||
// Illusion walls render as real walls unless this viewer knows better.
|
||||
// Their locations are open knowledge (the cast is public at a table) —
|
||||
// what stays personal is each player's verdict.
|
||||
const base = boardView(state);
|
||||
const knownIllusionEdges: string[] = [];
|
||||
const illusionEdges: Record<string, "untested" | "believes" | "seesThrough" | "mine"> = {};
|
||||
let edges = base.edges;
|
||||
for (const [key, wall] of Object.entries(state.illusionWalls)) {
|
||||
const knows = wall.createdBy === playerId || wall.belief[playerId] === "seesThrough";
|
||||
illusionEdges[key] =
|
||||
wall.createdBy === playerId ? "mine"
|
||||
: wall.belief[playerId] ?? "untested";
|
||||
if (knows) {
|
||||
knownIllusionEdges.push(key);
|
||||
} else {
|
||||
@@ -116,13 +135,13 @@ export function viewFor(state: GameState, playerId: PlayerId): GameView {
|
||||
carriedTreasureId: p.carriedTreasureId,
|
||||
lostTurns: p.lostTurns,
|
||||
extraTurns: p.extraTurns,
|
||||
passWallCharges: p.passWallCharges,
|
||||
displayed: p.hand.filter((c) => p.displayed.includes(c.instanceId)),
|
||||
})),
|
||||
yourHand: you ? [...you.hand] : [],
|
||||
revealedHands: state.phase === "finished"
|
||||
? Object.fromEntries(state.players.map((p) => [p.id, p.alive ? [...p.hand] : [...(p.finalHand ?? p.hand)]]))
|
||||
: null,
|
||||
deckRev: state.config.deckRev ?? 1,
|
||||
treasures: state.treasures.map((t) => ({ ...t })),
|
||||
deckCount: state.deck.length,
|
||||
discardCount: state.discard.length,
|
||||
@@ -131,13 +150,19 @@ export function viewFor(state: GameState, playerId: PlayerId): GameView {
|
||||
pendingDiscard: state.pendingDiscard,
|
||||
sustained: state.sustained.map((s) => ({ ...s })),
|
||||
squareContents: { ...state.squareContents },
|
||||
gluedCells: { ...state.gluedCells },
|
||||
openSafes: [...state.openSafes],
|
||||
groundObjects: Object.fromEntries(
|
||||
Object.entries(state.groundObjects).map(([k, v]) => [k, [...v]]),
|
||||
),
|
||||
deckRev: state.config.deckRev ?? 1,
|
||||
doorStates: { ...state.doorStates },
|
||||
wallDamage: { ...state.wallDamage },
|
||||
openDoorEdges: [...state.openDoorEdges],
|
||||
heldDoorEdges: state.heldDoors.map((h) => h.key),
|
||||
createdEdges: Object.keys(state.createdEdges),
|
||||
knownIllusionEdges,
|
||||
illusionEdges,
|
||||
creatures: state.creatures.map((c) => ({ ...c, scorchedThisTurn: [...c.scorchedThisTurn] })),
|
||||
wandCharges: { ...state.wandCharges },
|
||||
dimWarps: state.dimWarps.map((w) => ({ a: { ...w.a }, b: { ...w.b } })),
|
||||
@@ -145,7 +170,7 @@ export function viewFor(state: GameState, playerId: PlayerId): GameView {
|
||||
chaosPending: state.chaosPending
|
||||
? { casterId: state.chaosPending.casterId, queue: [...state.chaosPending.queue] }
|
||||
: null,
|
||||
yourWardArmed: state.wardArmed.includes(playerId),
|
||||
wardPending: state.wardPending ? { ...state.wardPending } : null,
|
||||
yourAmbushes: state.ambushes
|
||||
.filter((a) => a.ownerId === playerId)
|
||||
.map((a) => ({ ...a, numbers: [...a.numbers] })),
|
||||
@@ -170,6 +195,83 @@ export function sightedCellsFor(view: GameView): Set<string> {
|
||||
const out = new Set<string>();
|
||||
const me = view.players.find((p) => p.id === view.you);
|
||||
if (!me) return out;
|
||||
const { board, blockers } = sightBasis(view);
|
||||
for (const key of Object.keys(board.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
if (sightBetween(board, me.position, { x, y }, blockers)) out.add(key);
|
||||
}
|
||||
// VISIONSTONE lets its bearer see through exactly one wall or door —
|
||||
// any one — so a square is also sighted if removing a single edge
|
||||
// reveals it, mirroring the engine's casterLos.
|
||||
if (me.displayed.some((c) => c.cardId === "visionstone")) {
|
||||
const unseen = Object.keys(board.cells).filter((k) => !out.has(k));
|
||||
for (const edgeK of Object.keys(board.edges)) {
|
||||
if (unseen.length === 0) break;
|
||||
if ((board.edges[edgeK] ?? "open") === "open") continue;
|
||||
const edges = { ...board.edges };
|
||||
delete edges[edgeK];
|
||||
const opened = { ...board, edges };
|
||||
for (let i = unseen.length - 1; i >= 0; i--) {
|
||||
const [x, y] = unseen[i]!.split(",").map(Number) as [number, number];
|
||||
if (sightBetween(opened, me.position, { x, y }, blockers)) {
|
||||
out.add(unseen[i]!);
|
||||
unseen.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sight with an AROUND THE CORNER attached: every square straightly sighted,
|
||||
* plus every square visible from one of those — the caster looks to a middle
|
||||
* cell and the spell turns there, mirroring the engine's bentLos.
|
||||
*/
|
||||
export function bentSightedCellsFor(view: GameView): Set<string> {
|
||||
const out = sightedCellsFor(view);
|
||||
const me = view.players.find((p) => p.id === view.you);
|
||||
if (!me) return out;
|
||||
const mids = [...out].map((k) => {
|
||||
const [x, y] = k.split(",").map(Number) as [number, number];
|
||||
return { x, y };
|
||||
});
|
||||
const { board, blockers } = sightBasis(view);
|
||||
for (const key of Object.keys(board.cells)) {
|
||||
if (out.has(key)) continue;
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
const cell = { x, y };
|
||||
if (mids.some((mid) => sightBetween(board, mid, cell, blockers)) ||
|
||||
bentSightThroughGap(board, me.position, cell, blockers)) {
|
||||
out.add(key);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The board-as-seen and sight blockers this view's sight rules run against. */
|
||||
function sightBasis(view: GameView): { board: GameView["board"]; blockers: Record<string, true> } {
|
||||
// Held-open doors are open doorways to every eye. Beyond them, the
|
||||
// viewer at a door's threshold may pull it open and peek (rules rev 2):
|
||||
// lock removed, door unlocked this turn, or PICK LOCK / MASTER KEY in
|
||||
// hand — mirroring the engine's doorsAjar.
|
||||
let board = view.board;
|
||||
const openKeys = new Set(view.heldDoorEdges);
|
||||
const me = view.players.find((p) => p.id === view.you);
|
||||
if (view.deckRev >= 2 && me?.alive) {
|
||||
const carriesKey = view.yourHand.some((c) => c.cardId === "pick-lock" || c.cardId === "master-key");
|
||||
for (const side of SIDES) {
|
||||
const key = edgeKey(me.position, side);
|
||||
if (board.edges[key] !== "door") continue;
|
||||
const workable = carriesKey && view.doorStates[key] !== "jammed";
|
||||
if (workable || view.doorStates[key] === "removed" || view.openDoorEdges.includes(key)) openKeys.add(key);
|
||||
}
|
||||
}
|
||||
if (openKeys.size > 0) {
|
||||
const edges = { ...board.edges };
|
||||
for (const k of openKeys) delete edges[k];
|
||||
board = { ...board, edges };
|
||||
}
|
||||
const blockers: Record<string, true> = {};
|
||||
for (const [key, content] of Object.entries(view.squareContents)) {
|
||||
if (LOS_BLOCKING_CONTENT[content.kind]) blockers[key] = true;
|
||||
@@ -179,11 +281,93 @@ export function sightedCellsFor(view: GameView): Set<string> {
|
||||
blockers[`${p.position.x},${p.position.y}`] = true;
|
||||
}
|
||||
}
|
||||
for (const key of Object.keys(view.board.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
if (sightBetween(view.board, me.position, { x, y }, blockers)) out.add(key);
|
||||
return { board, blockers };
|
||||
}
|
||||
return out;
|
||||
|
||||
/**
|
||||
* How one square sees another under this viewer's knowledge of the board
|
||||
* (believed illusion walls block; held doors admit). Null when no sight
|
||||
* exists — the renderer's material for drawing the line an attack traveled.
|
||||
*/
|
||||
export function traceSightFor(view: GameView, from: Cell, to: Cell): SightTrace | null {
|
||||
const { board, blockers } = sightBasis(view);
|
||||
return traceSight(board, from, to, blockers);
|
||||
}
|
||||
|
||||
/**
|
||||
* AROUND THE CORNER's bent sight, from this viewer's knowledge: the caster
|
||||
* sees a middle square which sees the target — mirroring the engine's
|
||||
* bentLos so a client can predict whether the modifier will land.
|
||||
*/
|
||||
export function bentSightFor(view: GameView, from: Cell, to: Cell): boolean {
|
||||
const { board, blockers } = sightBasis(view);
|
||||
if (sightBetween(board, from, to, blockers)) return true;
|
||||
for (const key of Object.keys(board.cells)) {
|
||||
if (blockers[key]) continue;
|
||||
const [mx, my] = key.split(",").map(Number) as [number, number];
|
||||
const mid = { x: mx, y: my };
|
||||
if (sightBetween(board, from, mid, blockers) && sightBetween(board, mid, to, blockers)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The sight line behind the attack currently on the stack — the board's
|
||||
* answer to "how can he even see me?". Null when nothing should draw:
|
||||
* no stack, a creature's or physical attack, a non-LOS card, attacker and
|
||||
* defender sharing a square, or no sight under this viewer's knowledge
|
||||
* (a believed illusion wall can honestly hide the line).
|
||||
*/
|
||||
export function stackSightTrace(
|
||||
view: GameView,
|
||||
): {
|
||||
from: Cell;
|
||||
to: Cell;
|
||||
trace: SightTrace;
|
||||
bend?: { mid: Cell; trace: SightTrace };
|
||||
/** VISIONSTONE: the one wall or door the bearer's sight dissolved (edge key). */
|
||||
pierced?: string;
|
||||
} | null {
|
||||
const stack = view.stack;
|
||||
if (!stack || stack.creatureId) return null;
|
||||
if (!stack.attackCard || cardDef(stack.attackCard.cardId).los !== true) return null;
|
||||
const a = view.players.find((p) => p.id === stack.attackerId);
|
||||
const d = view.players.find((p) => p.id === stack.defenderId);
|
||||
if (!a || !d) return null;
|
||||
if (a.position.x === d.position.x && a.position.y === d.position.y) return null;
|
||||
const trace = traceSightFor(view, a.position, d.position);
|
||||
if (trace) return { from: a.position, to: d.position, trace };
|
||||
// VISIONSTONE: the bearer sees through exactly one wall or door. When no
|
||||
// plain line exists, find the single edge whose removal opens one and draw
|
||||
// the ray straight through it, marking the pierced wall for the table.
|
||||
if (a.displayed.some((c) => c.cardId === "visionstone")) {
|
||||
const { board, blockers } = sightBasis(view);
|
||||
for (const [key, edge] of Object.entries(board.edges)) {
|
||||
if (edge === "open") continue;
|
||||
const edges = { ...board.edges };
|
||||
delete edges[key];
|
||||
const t = traceSight({ ...board, edges }, a.position, d.position, blockers);
|
||||
if (t) return { from: a.position, to: d.position, trace: t, pierced: key };
|
||||
}
|
||||
}
|
||||
// AROUND THE CORNER: no straight line exists — find a middle square both
|
||||
// ends can see and draw the sight leg by leg, so the table can audit the
|
||||
// needle instead of doubting it.
|
||||
if (stack.bentCorner) {
|
||||
for (const key of Object.keys(view.board.cells)) {
|
||||
const [mx, my] = key.split(",").map(Number) as [number, number];
|
||||
const mid = { x: mx, y: my };
|
||||
if ((mid.x === a.position.x && mid.y === a.position.y) ||
|
||||
(mid.x === d.position.x && mid.y === d.position.y)) continue;
|
||||
const leg1 = traceSightFor(view, a.position, mid);
|
||||
if (!leg1) continue;
|
||||
const leg2 = traceSightFor(view, mid, d.position);
|
||||
if (leg2) return { from: a.position, to: d.position, trace: leg1, bend: { mid, trace: leg2 } };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const CREATION_CARD_IDS = new Set([
|
||||
@@ -199,12 +383,12 @@ const SUMMON_CARD_IDS = new Set([
|
||||
* aid — mirroring the engine's own validation from the viewer's knowledge.
|
||||
* Null = this card's eligibility is not modeled; light everything.
|
||||
*/
|
||||
export function eligibleCellsFor(view: GameView, cardId: string): Set<string> | null {
|
||||
export function eligibleCellsFor(view: GameView, cardId: string, bentCorner = false): Set<string> | null {
|
||||
const me = view.players.find((p) => p.id === view.you);
|
||||
if (!me) return null;
|
||||
const cells = Object.keys(view.board.cells);
|
||||
const key = (x: number, y: number) => `${x},${y}`;
|
||||
const sighted = sightedCellsFor(view);
|
||||
const sighted = bentCorner ? bentSightedCellsFor(view) : sightedCellsFor(view);
|
||||
|
||||
if (CREATION_CARD_IDS.has(cardId)) {
|
||||
// emptySquareTarget: on the board, unoccupied by content, home, wizard,
|
||||
@@ -280,8 +464,19 @@ export function eligibleCellsFor(view: GameView, cardId: string): Set<string> |
|
||||
return out;
|
||||
}
|
||||
|
||||
if (cardId === "thumb-of-god") {
|
||||
// The die is aimed by sight; where it lands after drifting is fate's.
|
||||
return sighted;
|
||||
}
|
||||
if (cardId === "stone-to-water") {
|
||||
return new Set(cells.filter((k) => view.squareContents[k]?.kind === "stone"));
|
||||
// The cast demands sight of the stone block, so only sighted ones light.
|
||||
// The card equally targets stone WALLS — edges the cell-shadow cannot
|
||||
// express — so with no stone square in view, dimming would shroud the
|
||||
// true targets: light everything instead.
|
||||
const out = new Set(
|
||||
cells.filter((k) => view.squareContents[k]?.kind === "stone" && sighted.has(k)),
|
||||
);
|
||||
return out.size > 0 ? out : null;
|
||||
}
|
||||
if (cardId === "dispel-creation") {
|
||||
// Anything created — terrain or creature, whoever made it — in sight.
|
||||
|
||||
@@ -2,15 +2,19 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
applyCommand,
|
||||
createGame,
|
||||
sustainedOn,
|
||||
type GameState,
|
||||
type PlayerId,
|
||||
} from "../src/game";
|
||||
import { viewFor } from "../src/view";
|
||||
import { cellKey, edgeKey } from "../src/board";
|
||||
import { sightedCellsFor, viewFor } from "../src/view";
|
||||
import { automatonCommand, automatonFallback, type AutomatonStyle, type AutomatonTier } from "../src/automaton";
|
||||
import { pushSustained } from "./helpers";
|
||||
|
||||
/** Whose input does the maze want right now? */
|
||||
function actingSeat(state: GameState): PlayerId {
|
||||
return (
|
||||
state.wardPending?.ownerId ??
|
||||
state.stack?.waitingOn ??
|
||||
state.pendingDiscard ??
|
||||
state.chaosPending?.queue[0] ??
|
||||
@@ -31,7 +35,6 @@ function playOut(
|
||||
playerIds: ids,
|
||||
seed,
|
||||
sets: expansion ? ["basic", "expansion1"] : ["basic"],
|
||||
deckRev: 8,
|
||||
});
|
||||
let commands = 0;
|
||||
let stuck = 0;
|
||||
@@ -117,9 +120,8 @@ describe("automaton vs automaton", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
function underAttack(attackId: string, defenderHand: { instanceId: string; cardId: string }[], rig?: (s: any, defender: string) => void) {
|
||||
let { state } = createGame({ playerIds: ["human", "bot"], seed: 42, sets: ["basic", "expansion1"], deckRev: 13 });
|
||||
function underAttack(attackId: string, defenderHand: { instanceId: string; cardId: string }[], rig?: (s: GameState, defender: string) => void) {
|
||||
let { state } = createGame({ playerIds: ["human", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
// burn round 1
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
@@ -131,8 +133,8 @@ describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
if (!r.ok) throw new Error(`setup: ${r.error}`);
|
||||
state = r.state;
|
||||
}
|
||||
const human = state.players.find((p: { id: string }) => p.id === "human")!;
|
||||
const bot = state.players.find((p: { id: string }) => p.id === "bot")!;
|
||||
const human = state.players.find((p) => p.id === "human")!;
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.position = { ...human.position };
|
||||
defenderHand.forEach((c, i) => { bot.hand[i] = c; });
|
||||
human.hand[0] = { instanceId: `${attackId}#A`, cardId: attackId };
|
||||
@@ -145,6 +147,7 @@ describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
return r.state;
|
||||
}
|
||||
|
||||
describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
it("passes on drop-object rather than absorbing nothing", () => {
|
||||
const state = underAttack("drop-object", [
|
||||
{ instanceId: "absorb#T", cardId: "absorb" },
|
||||
@@ -160,8 +163,8 @@ describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
{ instanceId: "full-shield#T", cardId: "full-shield" },
|
||||
{ instanceId: "dagger#T", cardId: "dagger" },
|
||||
], (s, defender) => {
|
||||
const d = s.players.find((p: { id: string }) => p.id === defender)!;
|
||||
const t = s.treasures.find((t: { owner: string }) => t.owner !== defender)!;
|
||||
const d = s.players.find((p) => p.id === defender)!;
|
||||
const t = s.treasures.find((t) => t.owner !== defender)!;
|
||||
t.position = null; t.carriedBy = defender; d.carriedTreasureId = t.id;
|
||||
});
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
@@ -169,9 +172,195 @@ describe("the clockwork does not waste counters on pointless targets", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork guards gold only within sight", () => {
|
||||
// A refused cast forfeits the bot's whole turn (the fallback is endTurn),
|
||||
// so SAFE must only ever be offered where the engine's sight rule allows it.
|
||||
function goldOnTheFloor() {
|
||||
let { state } = createGame({ playerIds: ["bot", "foe"], seed: 7, sets: ["basic", "expansion1"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
foe.position = { ...bot.position };
|
||||
bot.hand = [{ instanceId: "safe#T", cardId: "safe" }];
|
||||
const gold = state.treasures.find((t) => t.owner === "bot")!;
|
||||
gold.carriedBy = null;
|
||||
return { state, bot, gold };
|
||||
}
|
||||
|
||||
it("never blind-casts SAFE at a treasure out of sight", () => {
|
||||
const { state, bot, gold } = goldOnTheFloor();
|
||||
const sighted = sightedCellsFor(viewFor(state, "bot"));
|
||||
const hidden = Object.keys(state.board.cells).find(
|
||||
(k) => !sighted.has(k) && !state.squareContents[k],
|
||||
)!;
|
||||
const [x, y] = hidden.split(",").map(Number);
|
||||
gold.position = { x: x!, y: y! };
|
||||
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
// Whatever the brain picks, the engine must accept it — a refusal
|
||||
// forfeits the bot's turn.
|
||||
const chosen = cmd ?? automatonFallback(viewFor(state, "bot"), "archmage");
|
||||
expect(applyCommand(state, "bot", chosen).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("still locks up gold it can see", () => {
|
||||
const { state, bot, gold } = goldOnTheFloor();
|
||||
const sighted = sightedCellsFor(viewFor(state, "bot"));
|
||||
const seen = [...sighted].find(
|
||||
(k) => k !== cellKey(bot.position) && !state.squareContents[k],
|
||||
)!;
|
||||
const [x, y] = seen.split(",").map(Number);
|
||||
gold.position = { x: x!, y: y! };
|
||||
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({
|
||||
type: "cast", instanceId: "safe#T",
|
||||
target: { kind: "cell", cell: gold.position },
|
||||
});
|
||||
expect(applyCommand(state, "bot", cmd!).ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork honors IDIOT's march", () => {
|
||||
// The engine never steers a cursed wizard's feet; the duty is the brain's.
|
||||
function cursedBot() {
|
||||
let { state } = createGame({ playerIds: ["bot", "foe"], seed: 7, sets: ["basic", "expansion1"] });
|
||||
// Past round 1 (no combat) and around to the bot's turn.
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
pushSustained(state, {
|
||||
id: "fx-idiot", cardId: "idiot", casterId: "foe", targetId: "bot",
|
||||
remainingTurns: 9999, data: {},
|
||||
});
|
||||
return state;
|
||||
}
|
||||
|
||||
it("marches to its own gold until the curse lifts", () => {
|
||||
let state = cursedBot();
|
||||
state.players.find((p) => p.id === "bot")!.hand = [];
|
||||
// A walled route can cost more steps than one turn's allowance; the
|
||||
// march may span turns (the foe just passes).
|
||||
for (let i = 0; i < 30 && sustainedOn(state, "bot", "idiot").length > 0; i++) {
|
||||
const seat = actingSeat(state);
|
||||
const cmd = seat === "bot"
|
||||
? automatonCommand(viewFor(state, "bot"), "hunter", "archmage")
|
||||
?? automatonFallback(viewFor(state, "bot"), "archmage")
|
||||
: { type: "endTurn", draw: 0 } as const;
|
||||
const r = applyCommand(state, seat, cmd);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
expect(sustainedOn(state, "bot", "idiot").length).toBe(0);
|
||||
});
|
||||
|
||||
it("shakes its gold from a thief's arms with DROP OBJECT", () => {
|
||||
const state = cursedBot();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const thief = state.players.find((p) => p.id === "foe")!;
|
||||
thief.position = { ...bot.position };
|
||||
const own = state.treasures.find((t) => t.owner === "bot")!;
|
||||
own.carriedBy = "foe";
|
||||
own.position = null;
|
||||
thief.carriedTreasureId = own.id;
|
||||
bot.hand = [{ instanceId: "drop-object#T", cardId: "drop-object" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({
|
||||
type: "cast", instanceId: "drop-object#T",
|
||||
target: { kind: "player", playerId: "foe" }, params: { cardId: "treasure" },
|
||||
});
|
||||
expect(applyCommand(state, "bot", cmd!).ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork wades hazards rather than surrender", () => {
|
||||
it("takes the slime road when no clean path to anything exists", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "foe"], seed: 7, sets: ["basic", "expansion1"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.hand = [];
|
||||
// Wall the bot into its square except one side; slime that one exit.
|
||||
const sides = ["N", "S", "E", "W"] as const;
|
||||
const board = state.board;
|
||||
const open = sides.filter((s) => {
|
||||
const n = { x: bot.position.x + (s === "E" ? 1 : s === "W" ? -1 : 0),
|
||||
y: bot.position.y + (s === "S" ? 1 : s === "N" ? -1 : 0) };
|
||||
return board.cells[cellKey(n)] !== undefined;
|
||||
});
|
||||
const exit = open[0]!;
|
||||
for (const s2 of sides) {
|
||||
if (s2 !== exit) state.edgeOverrides[edgeKey(bot.position, s2)] = "wall";
|
||||
else state.edgeOverrides[edgeKey(bot.position, s2)] = "open";
|
||||
}
|
||||
const beyond = { x: bot.position.x + (exit === "E" ? 1 : exit === "W" ? -1 : 0),
|
||||
y: bot.position.y + (exit === "S" ? 1 : exit === "N" ? -1 : 0) };
|
||||
state.squareContents[cellKey(beyond)] = { kind: "slime", damage: 0, createdBy: "foe" };
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({ type: "move", direction: exit });
|
||||
expect(applyCommand(state, "bot", cmd!).ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork respects the bush's shelter", () => {
|
||||
function faceOffWithFireball() {
|
||||
let { state } = createGame({ playerIds: ["bot", "foe"], seed: 7, sets: ["basic", "expansion1"] });
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
foe.position = { ...bot.position };
|
||||
bot.hand = [{ instanceId: "fireball#T", cardId: "fireball" }];
|
||||
return { state, bot, foe };
|
||||
}
|
||||
|
||||
it("never aims at a wizard sheltered in a thornbush", () => {
|
||||
const { state, foe } = faceOffWithFireball();
|
||||
state.squareContents[cellKey(foe.position)] = { kind: "thornbush", damage: 0, createdBy: "foe" };
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage")
|
||||
?? automatonFallback(viewFor(state, "bot"), "archmage");
|
||||
// Whatever it picks, the engine must accept it — and it must not be
|
||||
// the refused fireball that would burn the whole turn.
|
||||
expect(cmd).not.toMatchObject({ type: "cast", instanceId: "fireball#T" });
|
||||
expect(applyCommand(state, "bot", cmd).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("never attacks out of its own bush", () => {
|
||||
const { state, bot, foe } = faceOffWithFireball();
|
||||
foe.position = { ...bot.position };
|
||||
state.squareContents[cellKey(bot.position)] = { kind: "thornbush", damage: 0, createdBy: "foe" };
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage")
|
||||
?? automatonFallback(viewFor(state, "bot"), "archmage");
|
||||
expect(cmd).not.toMatchObject({ type: "cast", instanceId: "fireball#T" });
|
||||
expect(applyCommand(state, "bot", cmd).ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a clogged hand gets shed, not hoarded", () => {
|
||||
it("the bot discards dead weight so the end-of-turn draw has room", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"], deckRev: 13 });
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
@@ -180,7 +369,7 @@ describe("a clogged hand gets shed, not hoarded", () => {
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
// Seven situational neutrals the brain has no play for: a dead hand.
|
||||
bot.hand = Array.from({ length: 7 }, (_, i) => (
|
||||
{ instanceId: `illusion-wall#${i}`, cardId: "illusion-wall" }
|
||||
{ instanceId: `rotate-sector#${i}`, cardId: "rotate-sector" }
|
||||
));
|
||||
// Walk the bot's turn until it wants to end: it must shed before drawing.
|
||||
for (let guard = 0; guard < 30; guard++) {
|
||||
@@ -203,3 +392,673 @@ describe("a clogged hand gets shed, not hoarded", () => {
|
||||
throw new Error("never reached the end of the turn");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork honors absorb's fine print", () => {
|
||||
it("answers NO SPELL with blunt, never absorb — durations soak no points", () => {
|
||||
const state = underAttack("no-spell", [
|
||||
{ instanceId: "absorb#T", cardId: "absorb" },
|
||||
{ instanceId: "blunt#T", cardId: "blunt" },
|
||||
]);
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({ type: "counteract", instanceId: "blunt#T" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork wields destroy wall", () => {
|
||||
it("blasts its way out when no road leads to the gold", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
// Brick the bot into a one-square cell far from everything.
|
||||
bot.position = { x: 4, y: 4 };
|
||||
for (const side of ["N", "S", "E", "W"] as const) {
|
||||
state.edgeOverrides[edgeKey(bot.position, side)] = "wall";
|
||||
}
|
||||
state.players.find((p) => p.id === "other")!.position = { x: 0, y: 0 };
|
||||
bot.hand[0] = { instanceId: "destroy-wall#T", cardId: "destroy-wall" };
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "destroy-wall#T" });
|
||||
// And the engine accepts the blast it chose.
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
expect(r.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("values destroy wall above the chaff when forced to discard", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"] });
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.hand = [
|
||||
{ instanceId: "destroy-wall#T", cardId: "destroy-wall" },
|
||||
{ instanceId: "trader#T", cardId: "trader" },
|
||||
{ instanceId: "strength#T", cardId: "strength" },
|
||||
{ instanceId: "adrenaline#T", cardId: "adrenaline" },
|
||||
{ instanceId: "full-shield#T", cardId: "full-shield" },
|
||||
{ instanceId: "fireball#T", cardId: "fireball" },
|
||||
{ instanceId: "number-3#T", cardId: "number-3" },
|
||||
{ instanceId: "troll#T", cardId: "troll" },
|
||||
];
|
||||
state.pendingDiscard = "bot";
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd?.type).toBe("discard");
|
||||
if (cmd?.type === "discard") {
|
||||
expect(cmd.instanceIds).not.toContain("destroy-wall#T");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork wields pass through wall", () => {
|
||||
it("banks a crossing when bricked in, then steps through the wall", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.position = { x: 4, y: 4 };
|
||||
for (const side of ["N", "S", "E", "W"] as const) {
|
||||
state.edgeOverrides[edgeKey(bot.position, side)] = "wall";
|
||||
}
|
||||
state.players.find((p) => p.id === "other")!.position = { x: 0, y: 0 };
|
||||
bot.hand[0] = { instanceId: "pass-through-wall#T", cardId: "pass-through-wall" };
|
||||
const cast = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cast).toMatchObject({ type: "cast", instanceId: "pass-through-wall#T" });
|
||||
let r = applyCommand(state, "bot", cast!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.players.find((p) => p.id === "bot")!.passWallCharges).toBe(1);
|
||||
// The charge is spent on a step through the bricks.
|
||||
const step = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(step?.type).toBe("move");
|
||||
r = applyCommand(state, "bot", step!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const after = r.state.players.find((p) => p.id === "bot")!;
|
||||
expect(cellKey(after.position)).not.toBe(cellKey({ x: 4, y: 4 }));
|
||||
expect(after.passWallCharges).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork denies the road", () => {
|
||||
it("walls a thief's corridor when its treasure is being carried home", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const thief = state.players.find((p) => p.id === "other")!;
|
||||
// The thief carries the bot's treasure down a one-lane tube to its home.
|
||||
const t = state.treasures.find((t) => t.owner === "bot")!;
|
||||
t.position = null;
|
||||
t.carriedBy = "other";
|
||||
thief.carriedTreasureId = t.id;
|
||||
thief.position = { x: 4, y: 2 };
|
||||
thief.home = { x: 4, y: 6 };
|
||||
for (let y = 2; y <= 6; y++) {
|
||||
state.edgeOverrides[edgeKey({ x: 4, y }, "E")] = "wall";
|
||||
state.edgeOverrides[edgeKey({ x: 4, y }, "W")] = "wall";
|
||||
}
|
||||
state.edgeOverrides[edgeKey({ x: 4, y: 6 }, "S")] = "wall";
|
||||
for (let y = 2; y <= 5; y++) {
|
||||
state.edgeOverrides[edgeKey({ x: 4, y }, "S")] = "open";
|
||||
}
|
||||
bot.position = { x: 4, y: 4 };
|
||||
bot.hand = [{ instanceId: "create-wall#T", cardId: "create-wall" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "create-wall#T" });
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// The blockade must actually sever the thief's road home.
|
||||
const target = (cmd as { target: { cell: { x: number; y: number }; side: string } }).target;
|
||||
expect(["N", "S"]).toContain(target.side);
|
||||
expect(target.cell.x).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the widened spellbook", () => {
|
||||
it("dispels a conjured wall standing between it and the only road", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.position = { x: 4, y: 4 };
|
||||
for (const side of ["N", "S", "E", "W"] as const) {
|
||||
const k = edgeKey(bot.position, side);
|
||||
state.edgeOverrides[k] = "wall";
|
||||
state.createdEdges[k] = true;
|
||||
}
|
||||
state.players.find((p) => p.id === "other")!.position = { x: 0, y: 0 };
|
||||
bot.hand = [{ instanceId: "dispel-creation#T", cardId: "dispel-creation" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "dispel-creation#T" });
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
});
|
||||
|
||||
it("offers a buddy pact to the hound at its heels", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
while (actingSeat(state) !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const hound = state.players.find((p) => p.id === "other")!;
|
||||
hound.position = { ...bot.position };
|
||||
bot.hand = [{ instanceId: "buddy#T", cardId: "buddy" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "worrier", "archmage");
|
||||
expect(cmd).toEqual({
|
||||
type: "cast", instanceId: "buddy#T",
|
||||
target: { kind: "player", playerId: "other" },
|
||||
});
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("finishing tactics: exile and adrenaline", () => {
|
||||
it("exiles a thief carrying its gold to the far end of nowhere", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
// burn round 1 and reach the bot's turn
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const thief = state.players.find((p) => p.id === "other")!;
|
||||
const t = state.treasures.find((t) => t.owner === "bot")!;
|
||||
t.position = null;
|
||||
t.carriedBy = "other";
|
||||
thief.carriedTreasureId = t.id;
|
||||
// The thief is a step from delivering; the bot watches from beside them.
|
||||
thief.position = { x: thief.home.x, y: thief.home.y === 0 ? 1 : thief.home.y - 1 };
|
||||
bot.position = { ...thief.position };
|
||||
bot.hand = [{ instanceId: "teleport-opponent#T", cardId: "teleport-opponent" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "teleport-opponent#T" });
|
||||
const dest = (cmd as { params: { cell: { x: number; y: number } } }).params.cell;
|
||||
// The chosen square is a long march from the thief's own home.
|
||||
const d = Math.abs(dest.x - thief.home.x) + Math.abs(dest.y - thief.home.y);
|
||||
expect(d).toBeGreaterThanOrEqual(5);
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
});
|
||||
|
||||
it("casts adrenaline when two blows finish what one cannot", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const prey = state.players.find((p) => p.id === "other")!;
|
||||
prey.position = { ...bot.position };
|
||||
prey.life = 7; // fireball (5) alone cannot; fireball + dagger (3) can
|
||||
bot.hand = [
|
||||
{ instanceId: "adrenaline#T", cardId: "adrenaline" },
|
||||
{ instanceId: "fireball#T", cardId: "fireball" },
|
||||
{ instanceId: "dagger#T", cardId: "dagger" },
|
||||
{ instanceId: "number-2#T", cardId: "number-2" },
|
||||
];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "berserker", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "adrenaline#T" });
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the fireball-then-buddy lockout", () => {
|
||||
it("burns the target, then signs the pact so they cannot hit back", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const prey = state.players.find((p) => p.id === "other")!;
|
||||
prey.position = { ...bot.position };
|
||||
bot.life = 8; // bleeding: the clockwork wants out of this fight
|
||||
bot.hand = [
|
||||
{ instanceId: "fireball#T", cardId: "fireball" },
|
||||
{ instanceId: "buddy#T", cardId: "buddy" },
|
||||
];
|
||||
// First: the blow.
|
||||
let cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "fireball#T" });
|
||||
let r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
r = applyCommand(state, "other", { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
// Then: the pact.
|
||||
cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({
|
||||
type: "cast", instanceId: "buddy#T",
|
||||
target: { kind: "player", playerId: "other" },
|
||||
});
|
||||
r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
// The pact holds: the victim cannot strike their tormentor.
|
||||
expect(state.sustained.some(
|
||||
(s) => s.cardId === "buddy" && s.casterId === "bot" && s.targetId === "other",
|
||||
)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a pact once signed is honored", () => {
|
||||
it("will not attack the wizard it just buddied", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const prey = state.players.find((p) => p.id === "other")!;
|
||||
prey.position = { ...bot.position };
|
||||
// The pact already stands; a fireball waits in hand as temptation.
|
||||
pushSustained(state, {
|
||||
id: "fx-test", cardId: "buddy", casterId: "bot", targetId: "other",
|
||||
remainingTurns: 1000, data: {},
|
||||
});
|
||||
bot.hand = [{ instanceId: "fireball#T", cardId: "fireball" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
// Anything but an attack on the pacted wizard: no cast at them, no punch.
|
||||
expect(cmd?.type === "punch").toBe(false);
|
||||
if (cmd?.type === "cast") {
|
||||
expect((cmd as { target?: { playerId?: string } }).target?.playerId).not.toBe("other");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("no number is wasted on a turn that ends at a grab", () => {
|
||||
it("gold two free steps away: the berserker charges without spending its 5", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "other"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const prey = state.players.find((p) => p.id === "other")!;
|
||||
// Enemy far across the maze; their treasure lies one step from the bot.
|
||||
prey.position = { x: 0, y: 0 };
|
||||
bot.position = { x: 5, y: 5 };
|
||||
const t = state.treasures.find((t) => t.owner === "other")!;
|
||||
t.position = { x: 5, y: 6 };
|
||||
t.carriedBy = null;
|
||||
state.edgeOverrides[edgeKey({ x: 5, y: 5 }, "S")] = "open";
|
||||
bot.hand = [
|
||||
{ instanceId: "number-5#T", cardId: "number-5" },
|
||||
{ instanceId: "number-2#T", cardId: "number-2" },
|
||||
];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "berserker", "archmage");
|
||||
expect(cmd?.type).not.toBe("playNumberForMovement");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the clockwork flees the dread", () => {
|
||||
it("caught in FEAR's bubble, it spends its legs moving away", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "grim"], seed: 42, sets: ["basic"] });
|
||||
for (let guard = 0; guard < 10 && !(actingSeat(state) === "bot" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const grim = state.players.find((p) => p.id === "grim")!;
|
||||
grim.position = { x: 2, y: 5 };
|
||||
bot.position = { x: 2, y: 7 }; // two spaces inside the dread
|
||||
pushSustained(state, {
|
||||
id: "fx-fear", cardId: "fear", casterId: "grim", targetId: "grim",
|
||||
remainingTurns: 5, data: {},
|
||||
});
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "berserker", "archmage");
|
||||
expect(cmd?.type).toBe("move");
|
||||
if (cmd?.type === "move") {
|
||||
const r = applyCommand(state, "bot", cmd);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const after = r.state.players.find((p) => p.id === "bot")!;
|
||||
const d = Math.abs(after.position.x - grim.position.x) + Math.abs(after.position.y - grim.position.y);
|
||||
expect(d).toBeGreaterThan(2);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the thief-chase holds one goal per turn", () => {
|
||||
it("a clockwork beside its thief never shuttles on and off their square", () => {
|
||||
let { state } = createGame({ playerIds: ["thief", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
// Round 2, thief's turn burned; the bot acts with a full allowance.
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const thief = state.players.find((p) => p.id === "thief")!;
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
// The thief carries the bot's gold and stands one step away.
|
||||
const mine = state.treasures.find((t) => t.owner === "bot")!;
|
||||
mine.carriedBy = "thief";
|
||||
mine.position = null;
|
||||
thief.position = { x: 2, y: 4 };
|
||||
bot.position = { x: 2, y: 5 };
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 4 }, "S")] = "open";
|
||||
// A number card and no attacks: the blow the chase serves cannot land.
|
||||
bot.hand = [];
|
||||
bot.hand.push({ cardId: "number-2", instanceId: "N2" });
|
||||
const visited = [cellKey(bot.position)];
|
||||
for (let guard = 0; guard < 40; guard++) {
|
||||
const view = viewFor(state, "bot");
|
||||
const cmd = automatonCommand(view, "hunter", "archmage") ?? automatonFallback(view, "archmage");
|
||||
if (cmd.type === "endTurn") break;
|
||||
const r = applyCommand(state, "bot", cmd);
|
||||
if (!r.ok) break;
|
||||
state = r.state;
|
||||
const at = cellKey(state.players.find((p) => p.id === "bot")!.position);
|
||||
if (cmd.type === "move" && at !== visited[visited.length - 1]) visited.push(at);
|
||||
}
|
||||
// No step may return to the square just departed: A-B-A is the shuttle.
|
||||
for (let i = 2; i < visited.length; i++) {
|
||||
expect(visited[i]).not.toBe(visited[i - 2]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the archmage's key, shield, and race discipline", () => {
|
||||
function botTurn() {
|
||||
const seed = 42;
|
||||
let { state } = createGame({ playerIds: ["foe", "bot"], seed, sets: ["basic", "expansion1"] });
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
it("a MASTER KEY drawn goes straight on display", () => {
|
||||
const state = botTurn();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.hand.push({ cardId: "master-key", instanceId: "MK" });
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({ type: "cast", instanceId: "MK" });
|
||||
});
|
||||
|
||||
it("a lethal small blow is countered, thrift be damned", () => {
|
||||
let { state } = createGame({ playerIds: ["foe", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "foe") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.position = { ...foe.position };
|
||||
bot.life = 2;
|
||||
bot.hand = [{ cardId: "full-shield", instanceId: "FS" }];
|
||||
foe.hand.push({ cardId: "fireball", instanceId: "FB" });
|
||||
const r = applyCommand(state, "foe", {
|
||||
type: "cast", instanceId: "FB", target: { kind: "player", playerId: "bot" },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// Base fireball, 2 points: below every thrift threshold, but fatal at
|
||||
// 2 life — the shield comes out.
|
||||
const cmd = automatonCommand(viewFor(r.state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({ type: "counteract", instanceId: "FS" });
|
||||
});
|
||||
|
||||
it("no number is hoarded against the delivery that wins the game", () => {
|
||||
let state = botTurn();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
// One of the foe's treasures already rests at the bot's home; the bot
|
||||
// carries the second, four squares out with three legs — only the
|
||||
// number bridges it home this turn.
|
||||
const gold = state.treasures.filter((t) => t.owner === "foe");
|
||||
expect(gold.length).toBeGreaterThanOrEqual(2);
|
||||
gold[0]!.position = { ...bot.home };
|
||||
gold[0]!.carriedBy = null;
|
||||
gold[1]!.carriedBy = "bot";
|
||||
gold[1]!.position = null;
|
||||
bot.carriedTreasureId = gold[1]!.id;
|
||||
foe.position = { ...bot.home }; // a foe in sight: the war chest would hoard
|
||||
// Legs only: an attack in hand would fire at the foe in sight and
|
||||
// open a stack this single-seat loop cannot answer.
|
||||
bot.hand = [{ cardId: "number-3", instanceId: "N3" }];
|
||||
// Carve a straight, open four-square run to home; the rig owns its
|
||||
// geometry rather than praying the seed provides it.
|
||||
const home = bot.home;
|
||||
const column = [4, 3, 2, 1, 0].map((d) => ({ x: home.x, y: home.y - d }));
|
||||
for (const c of column) {
|
||||
if (!viewFor(state, "bot").board.cells[cellKey(c)]) {
|
||||
throw new Error("setup: the column north of home runs off the board");
|
||||
}
|
||||
delete state.squareContents[cellKey(c)];
|
||||
}
|
||||
bot.position = { ...column[0]! };
|
||||
for (const c of column.slice(0, 4)) state.edgeOverrides[edgeKey(c, "S")] = "open";
|
||||
for (let guard = 0; guard < 12; guard++) {
|
||||
const view = viewFor(state, "bot");
|
||||
const cmd = automatonCommand(view, "hunter", "archmage") ?? automatonFallback(view, "archmage");
|
||||
if (cmd.type === "playNumberForMovement") return; // the chest opened for the win
|
||||
if (cmd.type === "endTurn") break;
|
||||
const r = applyCommand(state, "bot", cmd);
|
||||
if (!r.ok) break;
|
||||
state = r.state;
|
||||
if (state.phase !== "playing") return; // delivered and won outright
|
||||
}
|
||||
throw new Error("the clockwork hoarded its number instead of winning");
|
||||
});
|
||||
});
|
||||
|
||||
describe("bank guarding, teleport delivery, and turn theft", () => {
|
||||
function rig() {
|
||||
const players = ["foe", "bot"];
|
||||
let { state } = createGame({ playerIds: players, seed: 42, sets: ["basic", "expansion1"] });
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
it("a raider at the stocked bank's gates pulls the clockwork home", () => {
|
||||
const state = rig();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
const gold = state.treasures.find((t) => t.owner === "foe")!;
|
||||
gold.position = { ...bot.home };
|
||||
gold.carriedBy = null;
|
||||
foe.position = { x: bot.home.x, y: bot.home.y + 1 };
|
||||
bot.position = { ...foe.home };
|
||||
bot.hand = [];
|
||||
// The march may wind through the maze; what matters is that it ENDS
|
||||
// at the threatened bank, not out on the gold map.
|
||||
let cur = state;
|
||||
for (let guard = 0; guard < 60; guard++) {
|
||||
const seat = actingSeat(cur);
|
||||
if (seat !== "bot") {
|
||||
// The foe answers stacks with a pass and burns its turns.
|
||||
let r2 = applyCommand(cur, seat, { type: "pass" });
|
||||
if (!r2.ok) r2 = applyCommand(cur, seat, { type: "endTurn", draw: 0 });
|
||||
if (!r2.ok) throw new Error(`foe stuck: ${r2.error}`);
|
||||
cur = r2.state;
|
||||
continue;
|
||||
}
|
||||
const view = viewFor(cur, "bot");
|
||||
const cmd = automatonCommand(view, "hunter", "archmage") ?? automatonFallback(view, "archmage");
|
||||
const r = applyCommand(cur, "bot", cmd);
|
||||
if (!r.ok) throw new Error(`refused: ${JSON.stringify(cmd)} — ${r.error}`);
|
||||
cur = r.state;
|
||||
const at = cur.players.find((p) => p.id === "bot")!;
|
||||
if (cellKey(at.position) === cellKey(bot.home)) return;
|
||||
}
|
||||
throw new Error("the clockwork never came home to its threatened bank");
|
||||
});
|
||||
|
||||
it("carrying with home a blink away, it teleports the delivery", () => {
|
||||
const state = rig();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const prize = state.treasures.find((t) => t.owner === "foe")!;
|
||||
prize.carriedBy = "bot";
|
||||
prize.position = null;
|
||||
bot.carriedTreasureId = prize.id;
|
||||
// Two squares from home as the spell flies, but walled off on foot.
|
||||
bot.position = { x: bot.home.x, y: bot.home.y + 2 };
|
||||
for (const side of ["N", "S", "E", "W"] as const) {
|
||||
state.edgeOverrides[edgeKey(bot.position, side)] = "wall";
|
||||
}
|
||||
bot.hand = [{ cardId: "teleport", instanceId: "TP" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toEqual({ type: "cast", instanceId: "TP", target: { kind: "cell", cell: { ...bot.home } } });
|
||||
});
|
||||
|
||||
it("a would-win carrier eats the lightning, not the fireball", () => {
|
||||
let state = rig();
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
// Foe has one banked and carries the second: one delivery from winning.
|
||||
const banked = state.treasures.find((t) => t.owner === "bot")!;
|
||||
banked.position = { ...foe.home };
|
||||
const carried = state.treasures.filter((t) => t.owner === "bot")[1];
|
||||
if (!carried) throw new Error("setup: the bot owns fewer than two treasures");
|
||||
carried.carriedBy = "foe";
|
||||
carried.position = null;
|
||||
foe.carriedTreasureId = carried.id;
|
||||
foe.position = { ...bot.position };
|
||||
bot.hand = [
|
||||
{ cardId: "fireball", instanceId: "FB" },
|
||||
{ cardId: "lightning-blast", instanceId: "LB" },
|
||||
{ cardId: "number-4", instanceId: "N4" },
|
||||
];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "LB" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("the denial planner offers only castable blocks", () => {
|
||||
it("tacks are offered only at the caster's feet", () => {
|
||||
// TACKS demand adjacency; a planner that proposes them at range has
|
||||
// its cast refused every turn, and the refusal-fallback loop reads
|
||||
// as an idle bot.
|
||||
let { state } = createGame({ playerIds: ["foe", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
// The bot's floor gold with a raider closing on it, and only TACKS
|
||||
// in hand to deny the road — from a stand-off distance.
|
||||
const gold = state.treasures.find((t) => t.owner === "bot" && t.position)!;
|
||||
foe.position = { ...gold.position! };
|
||||
bot.position = { ...bot.home };
|
||||
bot.hand = [{ cardId: "handful-of-tacks", instanceId: "HT" }];
|
||||
for (let guard = 0; guard < 6; guard++) {
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
if (!cmd) break;
|
||||
const r = applyCommand(state, "bot", cmd);
|
||||
// Whatever the brain proposes, the engine must accept it.
|
||||
if (!r.ok) throw new Error(`brain proposed a refused command: ${JSON.stringify(cmd)} — ${r.error}`);
|
||||
state = r.state;
|
||||
if (cmd.type === "endTurn") break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("interception, escape, and hazard sense", () => {
|
||||
function toBot(state: GameState): GameState {
|
||||
while (state.turn.round < 2 || state.players[state.turn.activeIndex]!.id !== "bot") {
|
||||
const r = applyCommand(state, actingSeat(state), { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
it("roots a carrier closing on home with LOCK IN PLACE", () => {
|
||||
let { state } = createGame({ playerIds: ["foe", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toBot(state);
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
// The foe stands beside the bot, laden, a short walk from banking.
|
||||
foe.position = { x: bot.position.x, y: bot.position.y };
|
||||
const gold = state.treasures.find((t) => t.owner === "bot" && t.position)!;
|
||||
gold.position = null;
|
||||
gold.carriedBy = "foe";
|
||||
foe.carriedTreasureId = gold.id;
|
||||
foe.home = { ...bot.position };
|
||||
bot.hand = [{ cardId: "lock-in-place", instanceId: "LK" }];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "LK", target: { kind: "player", playerId: "foe" } });
|
||||
expect(applyCommand(state, "bot", cmd!).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("a pressed carrier of any temperament turns to mist", () => {
|
||||
let { state } = createGame({ playerIds: ["foe", "bot"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toBot(state);
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
const foe = state.players.find((p) => p.id === "foe")!;
|
||||
// Bot hauls the foe's gold mid-journey with the foe breathing down its neck.
|
||||
const gold = state.treasures.find((t) => t.owner === "foe" && t.position)!;
|
||||
gold.position = null;
|
||||
gold.carriedBy = "bot";
|
||||
bot.carriedTreasureId = gold.id;
|
||||
bot.position = { ...foe.home };
|
||||
foe.position = { ...bot.position };
|
||||
bot.hand = [
|
||||
{ cardId: "mist-body", instanceId: "MB" },
|
||||
{ cardId: "number-3", instanceId: "N3" },
|
||||
{ cardId: "number-5", instanceId: "N5" },
|
||||
];
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "berserker", "archmage");
|
||||
expect(cmd).toMatchObject({ type: "cast", instanceId: "MB", numberInstanceIds: ["N5"] });
|
||||
const r = applyCommand(state, "bot", cmd!);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.sustained.some((s) => s.cardId === "mist-body" && s.targetId === "bot")).toBe(true);
|
||||
});
|
||||
|
||||
it("detours around a thornbush jail rather than diving in", () => {
|
||||
let { state } = createGame({ playerIds: ["bot", "foe"], seed: 7, sets: ["basic", "expansion1"] });
|
||||
state = toBot(state);
|
||||
const bot = state.players.find((p) => p.id === "bot")!;
|
||||
bot.hand = [];
|
||||
// Two exits from the bot's square: the short road east holds a
|
||||
// thornbush, the long road stays clean. A jail is not a shortcut.
|
||||
const sides = ["N", "S", "E", "W"] as const;
|
||||
const open = sides.filter((s) => {
|
||||
const n = { x: bot.position.x + (s === "E" ? 1 : s === "W" ? -1 : 0),
|
||||
y: bot.position.y + (s === "S" ? 1 : s === "N" ? -1 : 0) };
|
||||
return state.board.cells[cellKey(n)] !== undefined;
|
||||
});
|
||||
expect(open.length).toBeGreaterThanOrEqual(2);
|
||||
const bushSide = open[0]!;
|
||||
const freeSide = open[1]!;
|
||||
for (const s2 of sides) {
|
||||
state.edgeOverrides[edgeKey(bot.position, s2)] =
|
||||
s2 === bushSide || s2 === freeSide ? "open" : "wall";
|
||||
}
|
||||
const bushCell = { x: bot.position.x + (bushSide === "E" ? 1 : bushSide === "W" ? -1 : 0),
|
||||
y: bot.position.y + (bushSide === "S" ? 1 : bushSide === "N" ? -1 : 0) };
|
||||
state.squareContents[cellKey(bushCell)] = { kind: "thornbush", damage: 0, createdBy: "foe" };
|
||||
const cmd = automatonCommand(viewFor(state, "bot"), "hunter", "archmage");
|
||||
// Whatever goal it picks, the first stride must not be into the bush.
|
||||
expect(cmd).toMatchObject({ type: "move" });
|
||||
expect((cmd as { direction: string }).direction).not.toBe(bushSide);
|
||||
expect(applyCommand(state, "bot", cmd!).ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
type SectorPlacement,
|
||||
} from "../src/board";
|
||||
import { buildDeck } from "../src/cards";
|
||||
import { activePlayer, applyCommand, createGame } from "../src/game";
|
||||
import { edgeKey, type Side } from "../src/board";
|
||||
import { activePlayer, applyCommand, boardView, createGame, gameLos } from "../src/game";
|
||||
import { createRng } from "../src/rng";
|
||||
import { setupBoard } from "../src/setups";
|
||||
import { giveCard } from "./helpers";
|
||||
@@ -200,7 +201,7 @@ describe("setup diagram pairings (rulebook Set-Up Diagram)", () => {
|
||||
});
|
||||
|
||||
it("relocation discards the aisle warp: only opposite edges connect after", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 7, sets: ["basic"], deckRev: 5 });
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 7, sets: ["basic"] });
|
||||
const bent = (warps: typeof state.board.warps) =>
|
||||
warps.filter((w) => w.from.cell.x !== w.to.cell.x && w.from.cell.y !== w.to.cell.y);
|
||||
expect(bent(state.board.warps).length).toBeGreaterThan(0); // the arc exists
|
||||
@@ -240,3 +241,77 @@ describe("the aisle warp treats its corner as adjacent — sight included", () =
|
||||
expect(offAxis).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bricking over a warp mouth", () => {
|
||||
it("create wall seals a lettered opening: no passage, no sight", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
// round 1 passes
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = applyCommand(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const w = state.board.warps[0]!;
|
||||
const caster = activePlayer(state);
|
||||
caster.position = { ...w.from.cell };
|
||||
caster.hand[0] = { instanceId: "cw#1", cardId: "create-wall" };
|
||||
const r = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: "cw#1",
|
||||
target: { kind: "edge", cell: w.from.cell, side: w.from.side },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
// Passage: stepping into the warp is now a wall.
|
||||
const step = stepTarget(boardView(state), w.from.cell, w.from.side);
|
||||
expect(step.kind).toBe("blocked");
|
||||
// Sight: the far mouth no longer carries warp sight.
|
||||
expect(gameLos(state, w.from.cell, w.to.cell)).toBe(false);
|
||||
// One tunnel: the FAR mouth is walled too, and unwalling it reopens both.
|
||||
const farStep = stepTarget(boardView(state), w.to.cell, w.to.side);
|
||||
expect(farStep.kind).toBe("blocked");
|
||||
const caster2 = activePlayer(state);
|
||||
caster2.position = { ...w.to.cell };
|
||||
caster2.hand[0] = { instanceId: "dw#1", cardId: "destroy-wall" };
|
||||
const r2 = applyCommand(state, caster2.id, {
|
||||
type: "cast", instanceId: "dw#1",
|
||||
target: { kind: "edge", cell: w.to.cell, side: w.to.side },
|
||||
});
|
||||
if (!r2.ok) throw new Error(r2.error);
|
||||
expect(stepTarget(boardView(r2.state), w.from.cell, w.from.side).kind).toBe("warp");
|
||||
});
|
||||
});
|
||||
|
||||
describe("breaching the rim", () => {
|
||||
it("destroying a perimeter wall opens both sides as a new warp", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const r = applyCommand(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
// Find a rim wall with a wrap counterpart that is NOT already an opening.
|
||||
const view = boardView(state);
|
||||
for (const key of Object.keys(view.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
for (const side of ["N", "E", "S", "W"] as Side[]) {
|
||||
const n = { x: x + (side === "E" ? 1 : side === "W" ? -1 : 0), y: y + (side === "S" ? 1 : side === "N" ? -1 : 0) };
|
||||
if (view.cells[`${n.x},${n.y}`]) continue;
|
||||
if ((view.edges[edgeKey({ x, y }, side)] ?? "open") !== "wall") continue;
|
||||
const caster = activePlayer(state);
|
||||
caster.position = { x, y };
|
||||
caster.hand[0] = { instanceId: "dw#1", cardId: "destroy-wall" };
|
||||
const warpsBefore = state.board.warps.length;
|
||||
const r = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: "dw#1", target: { kind: "edge", cell: { x, y }, side },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
if (r.state.board.warps.length === warpsBefore) continue; // no counterpart in this row
|
||||
expect(r.state.board.warps.length).toBe(warpsBefore + 2);
|
||||
const w = r.state.board.warps[warpsBefore]!;
|
||||
expect(stepTarget(boardView(r.state), w.from.cell, w.from.side).kind).toBe("warp");
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error("setup: no breachable rim wall found");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, createGame, type GameState } from "../src/game";
|
||||
import { cellKey, edgeKey, hasLineOfSight, neighbor, type Cell, type Side, SIDES, stepTarget } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { viewFor } from "../src/view";
|
||||
import { newGame, must, giveCard, toRound2, faceOff } from "./helpers";
|
||||
import { sightedCellsFor, stackSightTrace, viewFor } from "../src/view";
|
||||
import { newGame, must, drain, giveCard, toRound2, faceOff } from "./helpers";
|
||||
|
||||
/** Test surgery: put a specific card into a player's hand (swapping one out). */
|
||||
/** Advance past round 1 (both players just end their turns). */
|
||||
@@ -31,10 +31,10 @@ describe("attack spells", () => {
|
||||
d.hand[1] = { instanceId: "full-shield#T", cardId: "full-shield" };
|
||||
|
||||
state = must(state, attacker, { type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender } });
|
||||
// Full shield stops everything -> stones survive.
|
||||
// Full shield stops everything -> stones survive. (A total stop
|
||||
// resolves on the attacker's pass; no bounce back.)
|
||||
state = must(state, defender, { type: "counteract", instanceId: "full-shield#T" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
expect(after.life).toBe(15);
|
||||
expect(after.hand.some((c) => c.cardId === "powerstone")).toBe(true);
|
||||
@@ -111,7 +111,8 @@ describe("attack spells", () => {
|
||||
state = must(state, attacker, { type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender } });
|
||||
state = must(state, defender, { type: "counteract", instanceId: "full-reflection#T" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
// The returned spell is a fresh attack on its caster: their window.
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(15);
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(10);
|
||||
});
|
||||
@@ -250,14 +251,6 @@ describe("stack discipline", () => {
|
||||
expect(applyCommand(state, defender, { type: "move", direction: "N" }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it("unimplemented cards refuse to cast with a clear error", () => {
|
||||
let { state } = newGame();
|
||||
const caster = activePlayer(state);
|
||||
const card = giveCard(state, caster.id, "bomb"); // expansion2: historical, never implemented
|
||||
const result = applyCommand(state, caster.id, { type: "cast", instanceId: card.instanceId });
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.error).toMatch(/not implemented/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("speedstone", () => {
|
||||
@@ -315,17 +308,15 @@ describe("stored-log compatibility", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("deck revisions", () => {
|
||||
it("revision 2 removes LIFESAVER at two players, and only there", () => {
|
||||
const two = createGame({ playerIds: ["a", "b"], seed: 9, sets: ["basic", "expansion1"], deckRev: 2 });
|
||||
describe("the two-player deck", () => {
|
||||
it("two-player games shed LIFESAVER; bigger tables keep it", () => {
|
||||
const two = createGame({ playerIds: ["a", "b"], seed: 9, sets: ["basic", "expansion1"] });
|
||||
const inGame = (s: typeof two.state) =>
|
||||
[...s.deck, ...s.discard, ...s.players.flatMap((p) => p.hand)].some((c) => c.cardId === "lifesaver");
|
||||
expect(inGame(two.state)).toBe(false);
|
||||
// Three players keep it; old two-player games (no deckRev) keep it too.
|
||||
const three = createGame({ playerIds: ["a", "b", "c"], seed: 9, sets: ["basic", "expansion1"], deckRev: 2 });
|
||||
// Three players keep it.
|
||||
const three = createGame({ playerIds: ["a", "b", "c"], seed: 9, sets: ["basic", "expansion1"] });
|
||||
expect(inGame(three.state)).toBe(true);
|
||||
const legacy = createGame({ playerIds: ["a", "b"], seed: 9, sets: ["basic", "expansion1"] });
|
||||
expect(inGame(legacy.state)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -388,42 +379,61 @@ describe("attacking walls and doors", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("ward arming and chaos shields (rules rev 3)", () => {
|
||||
function rev3Game(seed = 42) {
|
||||
return createGame({ playerIds: ["alice", "bob", "cara"], seed, sets: ["basic", "expansion1"], deckRev: 3 });
|
||||
describe("the ward window and chaos shields", () => {
|
||||
function threeGame(seed = 42) {
|
||||
return createGame({ playerIds: ["alice", "bob", "cara"], seed, sets: ["basic", "expansion1"] });
|
||||
}
|
||||
|
||||
it("ward springs only when its owner armed it", () => {
|
||||
let { state } = rev3Game();
|
||||
it("the grab hangs while the ward's owner decides — and arming ahead is refused", () => {
|
||||
let { state } = threeGame();
|
||||
state = toRound2(state);
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
const thief = activePlayer(state);
|
||||
const owner = state.players.find((p) => p.id !== thief.id)!;
|
||||
giveCard(state, owner.id, "ward", "W", 0);
|
||||
expect(applyCommand(state, owner.id, { type: "armWard" }).ok).toBe(false);
|
||||
const treasure = state.treasures.find((t) => t.owner === owner.id)!;
|
||||
|
||||
// Unarmed: the grab goes unpunished.
|
||||
thief.position = { ...treasure.position! };
|
||||
let s2 = must(state, thief.id, { type: "pickUpTreasure" });
|
||||
expect(s2.players.find((p) => p.id === thief.id)!.life).toBe(15);
|
||||
expect(s2.players.find((p) => p.id === owner.id)!.hand.some((c) => c.cardId === "ward")).toBe(true);
|
||||
state = must(state, thief.id, { type: "pickUpTreasure" });
|
||||
expect(state.wardPending).toEqual({ ownerId: owner.id, takerId: thief.id });
|
||||
// Spring it: the thief bleeds 3 and the ward is spent.
|
||||
state = must(state, owner.id, { type: "wardChoice", play: true });
|
||||
state = drain(state);
|
||||
expect(state.players.find((p) => p.id === thief.id)!.life).toBe(12);
|
||||
expect(state.players.find((p) => p.id === owner.id)!.hand.some((c) => c.cardId === "ward")).toBe(false);
|
||||
});
|
||||
|
||||
// Armed (on the owner's own turn): the trap bites for 3.
|
||||
const ownerTurnState = (() => {
|
||||
let s = state;
|
||||
while (activePlayer(s).id !== owner.id) s = must(s, activePlayer(s).id, { type: "endTurn", draw: 0 });
|
||||
return s;
|
||||
})();
|
||||
let s3 = must(ownerTurnState, owner.id, { type: "armWard", armed: true });
|
||||
while (activePlayer(s3).id !== thief.id) s3 = must(s3, activePlayer(s3).id, { type: "endTurn", draw: 0 });
|
||||
s3.players.find((p) => p.id === thief.id)!.position = { ...treasure.position! };
|
||||
s3 = must(s3, thief.id, { type: "pickUpTreasure" });
|
||||
expect(s3.players.find((p) => p.id === thief.id)!.life).toBe(12);
|
||||
expect(s3.wardArmed).not.toContain(owner.id);
|
||||
it("chaos casts bare — no target, every other wizard queued for a shield", () => {
|
||||
let { state } = threeGame();
|
||||
state = toRound2(state);
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
const caster = activePlayer(state);
|
||||
const others = state.players.filter((p) => p.id !== caster.id).map((p) => p.id);
|
||||
const chaos = giveCard(state, caster.id, "chaos", "C", 0);
|
||||
const shielder = others[0]!;
|
||||
giveCard(state, shielder, "full-shield", "S", 0);
|
||||
const shielderHand = () => state.players.find((p) => p.id === shielder)!.hand.map((c) => c.instanceId).sort();
|
||||
const kept = shielderHand().filter((id) => id !== "full-shield#S").sort();
|
||||
|
||||
state = must(state, caster.id, { type: "cast", instanceId: chaos.instanceId });
|
||||
// No stack: the queue opens at once, in turn order from the caster.
|
||||
expect(state.stack).toBeNull();
|
||||
expect(state.chaosPending?.queue.length).toBe(2);
|
||||
const first = state.chaosPending!.queue[0]!;
|
||||
state = first === shielder
|
||||
? must(state, first, { type: "counteract", instanceId: "full-shield#S" })
|
||||
: must(state, first, { type: "pass" });
|
||||
const second = state.chaosPending!.queue[0]!;
|
||||
state = second === shielder
|
||||
? must(state, second, { type: "counteract", instanceId: "full-shield#S" })
|
||||
: must(state, second, { type: "pass" });
|
||||
expect(state.chaosPending).toBeNull();
|
||||
// The shielded hand rode out the storm untouched.
|
||||
expect(shielderHand()).toEqual(kept);
|
||||
});
|
||||
|
||||
it("chaos: bystanders may shield out, reflections are refused", () => {
|
||||
let { state } = rev3Game();
|
||||
let { state } = threeGame();
|
||||
state = toRound2(state);
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
const caster = activePlayer(state);
|
||||
@@ -450,7 +460,7 @@ describe("ward arming and chaos shields (rules rev 3)", () => {
|
||||
});
|
||||
|
||||
it("chaos: the defender's full shield sits them out without stopping it", () => {
|
||||
let { state } = rev3Game();
|
||||
let { state } = threeGame();
|
||||
state = toRound2(state);
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
const caster = activePlayer(state);
|
||||
@@ -466,25 +476,12 @@ describe("ward arming and chaos shields (rules rev 3)", () => {
|
||||
});
|
||||
state = must(state, defender.id, { type: "counteract", instanceId: "full-shield#S" });
|
||||
state = must(state, caster.id, { type: "pass" }); // caster declines to anti-anti
|
||||
state = must(state, defender.id, { type: "pass" }); // defender rests on the shield
|
||||
// Bystander declines; the scramble happens without the defender.
|
||||
expect(state.chaosPending?.queue[0]).toBe(bystander.id);
|
||||
state = must(state, bystander.id, { type: "pass" });
|
||||
expect(state.chaosPending).toBeNull();
|
||||
expect(defenderHand()).toEqual(kept);
|
||||
});
|
||||
|
||||
it("legacy games (rev < 3) keep the automatic ward", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const thief = activePlayer(state);
|
||||
const owner = state.players.find((p) => p.id !== thief.id)!;
|
||||
giveCard(state, owner.id, "ward", "W", 0);
|
||||
const treasure = state.treasures.find((t) => t.owner === owner.id)!;
|
||||
thief.position = { ...treasure.position! };
|
||||
state = must(state, thief.id, { type: "pickUpTreasure" });
|
||||
expect(state.players.find((p) => p.id === thief.id)!.life).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("zero-damage utility attacks", () => {
|
||||
@@ -525,8 +522,7 @@ describe("zero-damage utility attacks", () => {
|
||||
target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: "full-shield#FS" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
const result = applyCommand(state, defender, { type: "pass" });
|
||||
const result = applyCommand(state, attacker, { type: "pass" });
|
||||
if (!result.ok) throw new Error(result.error);
|
||||
const resolved = result.events.find((e) => e.type === "attackResolved");
|
||||
expect(resolved && "fullyStopped" in resolved && resolved.fullyStopped).toBe(true);
|
||||
@@ -534,6 +530,83 @@ describe("zero-damage utility attacks", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the VISIONSTONE pierces one wall", () => {
|
||||
function stoneRig() {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const a = activePlayer(state);
|
||||
const b = state.players.find((p) => p.id !== a.id)!;
|
||||
a.position = { x: 2, y: 4 };
|
||||
b.position = { x: 2, y: 5 };
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 4 }, "S")] = "wall";
|
||||
return { state, a, b };
|
||||
}
|
||||
|
||||
it("its bearer casts an attack straight through the wall", () => {
|
||||
const { state, a, b } = stoneRig();
|
||||
const fb = giveCard(state, a.id, "fireball", "FB", 1);
|
||||
const refused = applyCommand(state, a.id, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: b.id },
|
||||
});
|
||||
expect(refused.ok).toBe(false);
|
||||
const stone = giveCard(state, a.id, "visionstone", "VS");
|
||||
a.displayed.push(stone.instanceId);
|
||||
const cast = applyCommand(state, a.id, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: b.id },
|
||||
});
|
||||
expect(cast.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("its bearer plants a THORNBUSH through the wall", () => {
|
||||
const { state, a } = stoneRig();
|
||||
// The square past the wall must be bare ground for a creation.
|
||||
const cell = { x: 2, y: 5 };
|
||||
for (const p of state.players) if (cellKey(p.position) === cellKey(cell)) p.position = { x: 0, y: 0 };
|
||||
const bush = giveCard(state, a.id, "thornbush", "TB");
|
||||
const refused = applyCommand(state, a.id, {
|
||||
type: "cast", instanceId: bush.instanceId, target: { kind: "cell", cell },
|
||||
});
|
||||
expect(refused.ok).toBe(false);
|
||||
if (!refused.ok) expect(refused.error).toContain("line of sight");
|
||||
const stone = giveCard(state, a.id, "visionstone", "VS", 1);
|
||||
a.displayed.push(stone.instanceId);
|
||||
const cast = applyCommand(state, a.id, {
|
||||
type: "cast", instanceId: bush.instanceId, target: { kind: "cell", cell },
|
||||
});
|
||||
expect(cast.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("the client's sighted squares agree with the stone", () => {
|
||||
const { state, a, b } = stoneRig();
|
||||
expect(sightedCellsFor(viewFor(state, a.id)).has(cellKey(b.position))).toBe(false);
|
||||
const stone = giveCard(state, a.id, "visionstone", "VS");
|
||||
a.displayed.push(stone.instanceId);
|
||||
expect(sightedCellsFor(viewFor(state, a.id)).has(cellKey(b.position))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("teleport wraps the maze's rim", () => {
|
||||
it("four spaces counted through a warp mouth reach the far side", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
// Stand the active wizard at a wraparound mouth; the paired cell is
|
||||
// ONE teleport step away, exactly as it is one walking step.
|
||||
const active = activePlayer(state);
|
||||
const warp = boardView(state).warps[0]!;
|
||||
active.position = { ...warp.from.cell };
|
||||
const tp = giveCard(state, active.id, "teleport", "TP", 0);
|
||||
const r = applyCommand(state, active.id, {
|
||||
type: "cast", instanceId: tp.instanceId,
|
||||
target: { kind: "cell", cell: { ...warp.to.cell } },
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (r.ok) {
|
||||
const after = r.state.players.find((p) => p.id === active.id)!;
|
||||
expect(cellKey(after.position)).toBe(cellKey(warp.to.cell));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("teleport as a counteraction", () => {
|
||||
it("the attack has no chance of hitting you — you are simply elsewhere", () => {
|
||||
let { state } = newGame();
|
||||
@@ -548,32 +621,11 @@ describe("teleport as a counteraction", () => {
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: tp.instanceId, params: { cell: escape } });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
expect(after.life).toBe(15);
|
||||
expect(cellKey(after.position)).toBe(cellKey(escape));
|
||||
});
|
||||
|
||||
it("ANTI-ANTI pins the boots in pre-rev-6 games (their stored chains replay)", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const aa = giveCard(state, attacker, "anti-anti", "AA", 1);
|
||||
const tp = giveCard(state, defender, "teleport", "TP", 0);
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const home = { ...d.position };
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: tp.instanceId, params: { cell: { x: home.x, y: home.y + 1 } } });
|
||||
state = must(state, attacker, { type: "counteract", instanceId: aa.instanceId });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
expect(cellKey(after.position)).toBe(cellKey(home));
|
||||
expect(after.life).toBe(10);
|
||||
});
|
||||
|
||||
it("reaches at most four spaces", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
@@ -593,7 +645,7 @@ describe("teleport as a counteraction", () => {
|
||||
|
||||
describe("slime holds spells", () => {
|
||||
function slimeRig() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev: 5 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
const victim = state.players.find((p) => p.id !== caster.id)!;
|
||||
@@ -646,7 +698,6 @@ describe("slime holds spells", () => {
|
||||
state = must(state, rig.victim, { type: "move", direction: rig.slimeAt.side });
|
||||
state = must(state, rig.victim, { type: "counteract", instanceId: "full-reflection#FR" });
|
||||
state = must(state, rig.caster, { type: "pass" });
|
||||
state = must(state, rig.victim, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === rig.caster)!.life).toBe(15);
|
||||
expect(state.players.find((p) => p.id === rig.victim)!.life).toBe(15);
|
||||
});
|
||||
@@ -671,12 +722,12 @@ describe("slime holds spells", () => {
|
||||
});
|
||||
|
||||
describe("answering counteractions (FAQ rulings)", () => {
|
||||
function rev6() {
|
||||
return createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 6 });
|
||||
function freshGame() {
|
||||
return createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
}
|
||||
|
||||
it("ABSORB SPELL steals a FULL REFLECTION out of the air", () => {
|
||||
let { state } = rev6();
|
||||
let { state } = freshGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
@@ -696,7 +747,7 @@ describe("answering counteractions (FAQ rulings)", () => {
|
||||
});
|
||||
|
||||
it("FULL SHIELD cannot be absorbed — it is not cast at you", () => {
|
||||
let { state } = rev6();
|
||||
let { state } = freshGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
@@ -711,8 +762,8 @@ describe("answering counteractions (FAQ rulings)", () => {
|
||||
if (!r.ok) expect(r.error).toMatch(/cannot be absorbed/);
|
||||
});
|
||||
|
||||
it("ANTI-ANTI does not work against a teleport escape (rev 6)", () => {
|
||||
let { state } = rev6();
|
||||
it("ANTI-ANTI does not work against a teleport escape", () => {
|
||||
let { state } = freshGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
@@ -727,16 +778,15 @@ describe("answering counteractions (FAQ rulings)", () => {
|
||||
const r = applyCommand(state, attacker, { type: "counteract", instanceId: aa.instanceId });
|
||||
expect(r.ok).toBe(false);
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
expect(after.life).toBe(15);
|
||||
expect(cellKey(after.position)).toBe(cellKey(escape));
|
||||
});
|
||||
});
|
||||
|
||||
describe("speed and warp-token creation (rules rev 8)", () => {
|
||||
describe("speed and warp-token creation", () => {
|
||||
it("a SPEED bonus turn burns a turn of durations on the hastened wizard", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 8 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const me = activePlayer(state);
|
||||
const other = state.players.find((p) => p.id !== me.id)!;
|
||||
@@ -755,7 +805,7 @@ describe("speed and warp-token creation (rules rev 8)", () => {
|
||||
});
|
||||
|
||||
it("nothing can be created on a dimensional warp token", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev: 8 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const me = activePlayer(state);
|
||||
const spot = { x: me.position.x + 1, y: me.position.y };
|
||||
@@ -769,9 +819,9 @@ describe("speed and warp-token creation (rules rev 8)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("redirection (rules rev 9)", () => {
|
||||
describe("redirection", () => {
|
||||
it("the two chosen exits connect; their old partners pair with each other", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 9 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const me = activePlayer(state);
|
||||
// Pick two exits that are NOT already partners.
|
||||
@@ -794,16 +844,16 @@ describe("redirection (rules rev 9)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("total stops end the exchange (rules rev 10)", () => {
|
||||
function rev10Game() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 10 });
|
||||
describe("total stops end the exchange", () => {
|
||||
function faceOffRig() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
return { state, attacker, defender };
|
||||
}
|
||||
|
||||
it("a declined answer to Force Field resolves at once — no goading re-prompt", () => {
|
||||
let { state, attacker, defender } = rev10Game();
|
||||
let { state, attacker, defender } = faceOffRig();
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const lifeBefore = d.life;
|
||||
@@ -817,7 +867,7 @@ describe("total stops end the exchange (rules rev 10)", () => {
|
||||
});
|
||||
|
||||
it("a partial counter still invites the defender to stack more", () => {
|
||||
let { state, attacker, defender } = rev10Game();
|
||||
let { state, attacker, defender } = faceOffRig();
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
d.hand[0] = { instanceId: "blunt#T", cardId: "blunt" };
|
||||
@@ -830,7 +880,7 @@ describe("total stops end the exchange (rules rev 10)", () => {
|
||||
});
|
||||
|
||||
it("a nullified shield is no stop — the exchange returns to the defender", () => {
|
||||
let { state, attacker, defender } = rev10Game();
|
||||
let { state, attacker, defender } = faceOffRig();
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
@@ -847,7 +897,7 @@ describe("total stops end the exchange (rules rev 10)", () => {
|
||||
|
||||
describe("escapes and elemental walls as counteractions", () => {
|
||||
function rigged(attackId: string, defenderCards: { instanceId: string; cardId: string }[]) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 12 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const atk = giveCard(state, attacker, attackId);
|
||||
@@ -893,7 +943,7 @@ describe("escapes and elemental walls as counteractions", () => {
|
||||
const lifeBefore = state.players.find((p) => p.id === defender)!.life;
|
||||
state = must(state, defender, { type: "counteract", instanceId: "waterwall#T" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
// A total stop: the attacker's declined answer resolves at once (rev 10+).
|
||||
// A total stop: the attacker's declined answer resolves at once.
|
||||
expect(state.stack).toBeNull();
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(lifeBefore);
|
||||
});
|
||||
@@ -906,3 +956,399 @@ describe("escapes and elemental walls as counteractions", () => {
|
||||
expect(refused.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("empathy as a counteraction", () => {
|
||||
function empathyRig() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
d.hand[0] = { instanceId: "empathy#T", cardId: "empathy" };
|
||||
d.hand[1] = { instanceId: "number-3#T", cardId: "number-3" };
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
return { state, attacker, defender };
|
||||
}
|
||||
|
||||
it("the blow lands on both — and the link lingers its number's turns", () => {
|
||||
let { state, attacker, defender } = empathyRig();
|
||||
state = must(state, defender, {
|
||||
type: "counteract", instanceId: "empathy#T", numberInstanceIds: ["number-3#T"],
|
||||
});
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(10);
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(10);
|
||||
const fx = state.sustained.find((f) => f.cardId === "empathy" && f.targetId === defender);
|
||||
expect(fx?.remainingTurns).toBe(3);
|
||||
});
|
||||
|
||||
it("anti-anti severs the link: no mirror, no lingering spell", () => {
|
||||
let { state, attacker, defender } = empathyRig();
|
||||
state = must(state, defender, { type: "counteract", instanceId: "empathy#T" });
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
a.hand[1] = { instanceId: "anti-anti#T", cardId: "anti-anti" };
|
||||
state = must(state, attacker, { type: "counteract", instanceId: "anti-anti#T" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(10);
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(15);
|
||||
expect(state.sustained.some((f) => f.cardId === "empathy" && f.targetId === defender)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("empathy mirrors resolution-hook blows", () => {
|
||||
it("a believed illusion bites both wizards", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const ill = giveCard(state, attacker, "illusionary-attack");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
d.hand[0] = { instanceId: "empathy#T", cardId: "empathy" };
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: ill.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: "fireball" },
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: "empathy#T" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const dAfter = state.players.find((p) => p.id === defender)!;
|
||||
const aAfter = state.players.find((p) => p.id === attacker)!;
|
||||
// Whichever way belief rolled, the two lives moved in lockstep.
|
||||
expect(15 - aAfter.life).toBe(15 - dAfter.life);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the reflected-attack window", () => {
|
||||
function reflectRig() {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sd = giveCard(state, attacker, "sudden-death");
|
||||
giveCard(state, defender, "full-reflection", "FR", 0);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sd.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: "full-reflection#FR" });
|
||||
// The attacker's pass meets the total stop and settles the reflection —
|
||||
// which opens the returned spell's window, waiting on the caster.
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
return { state, attacker, defender };
|
||||
}
|
||||
|
||||
it("the returned spell opens a window: absorb soaks the reflected blast", () => {
|
||||
let { state, attacker, defender } = reflectRig();
|
||||
// The reflection settled into a NEW stack: the caster now defends.
|
||||
expect(state.stack).not.toBeNull();
|
||||
expect(state.stack!.defenderId).toBe(attacker);
|
||||
expect(state.stack!.reflectedBase).toEqual({ damage: 10, duration: 0 });
|
||||
giveCard(state, attacker, "absorb", "AB", 0);
|
||||
state = must(state, attacker, { type: "counteract", instanceId: "absorb#AB" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
// 10 reflected minus absorb's 3.
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(8);
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(15);
|
||||
});
|
||||
|
||||
it("a second full reflection turns it around again — the ping-pong war", () => {
|
||||
let { state, attacker, defender } = reflectRig();
|
||||
giveCard(state, attacker, "full-reflection", "FR2", 0);
|
||||
state = must(state, attacker, { type: "counteract", instanceId: "full-reflection#FR2" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
// Turned around again: now the original defender must answer it.
|
||||
expect(state.stack).not.toBeNull();
|
||||
expect(state.stack!.defenderId).toBe(defender);
|
||||
state = must(state, defender, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(5);
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(15);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a reflected lightning blast ends the caster's turn", () => {
|
||||
function boltRig() {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const lb = giveCard(state, attacker, "lightning-blast");
|
||||
giveCard(state, attacker, "number-3", "N", 1);
|
||||
giveCard(state, defender, "full-reflection", "FR", 0);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: lb.instanceId, numberInstanceIds: ["number-3#N"],
|
||||
target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: "full-reflection#FR" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
// rev 25+: the returned bolt opens its window; the caster declines to answer.
|
||||
if (state.stack) state = must(state, attacker, { type: "pass" });
|
||||
return { state, attacker, defender };
|
||||
}
|
||||
|
||||
it("FAQ: 'you lose the rest of your turn and can't draw cards'", () => {
|
||||
let { state, attacker } = boltRig();
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(12);
|
||||
expect(state.turn.actionsEnded).toBe(true);
|
||||
// No more marching, and the end-of-turn draw comes up empty.
|
||||
expect(applyCommand(state, attacker, { type: "move", direction: "N" }).ok).toBe(false);
|
||||
const before = state.players.find((p) => p.id === attacker)!.hand.length;
|
||||
state = must(state, attacker, { type: "endTurn", draw: 2 });
|
||||
expect(state.players.find((p) => p.id === attacker)!.hand.length).toBe(before);
|
||||
// And the stun still costs the next turn.
|
||||
expect(state.players.find((p) => p.id === attacker)!.lostTurns
|
||||
+ (activePlayer(state).id === attacker ? 1 : 0)).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fireball burns only the stones in play", () => {
|
||||
it("a displayed stone dies; a hidden one stays secret and safe", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const fb = giveCard(state, attacker, "fireball");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
d.hand[0] = { instanceId: "powerstone#T", cardId: "powerstone" };
|
||||
d.hand[1] = { instanceId: "speedstone#T", cardId: "speedstone" };
|
||||
d.displayed = ["powerstone#T"]; // only the powerstone is on the table
|
||||
state = must(state, attacker, { type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender } });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
expect(after.hand.some((c) => c.instanceId === "powerstone#T")).toBe(false);
|
||||
expect(after.hand.some((c) => c.instanceId === "speedstone#T")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stone dead counts only the stones in play", () => {
|
||||
it("hidden stones neither add damage nor betray their count", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sd = giveCard(state, attacker, "stone-dead");
|
||||
giveCard(state, attacker, "number-3", "N", 1);
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
d.hand[0] = { instanceId: "powerstone#T", cardId: "powerstone" };
|
||||
d.hand[1] = { instanceId: "speedstone#T", cardId: "speedstone" };
|
||||
d.hand[2] = { instanceId: "bloodstone#T", cardId: "bloodstone" };
|
||||
d.displayed = ["powerstone#T"]; // one on the table, two secret
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sd.instanceId, numberInstanceIds: ["number-3#N"],
|
||||
target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
// 3 x 1 displayed stone = 3; the bloodstone is hidden, so it soaks
|
||||
// nothing: 15 - 3 = 12.
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MENTAL FORCE respects the victim's three walked spaces", () => {
|
||||
it("a destination beyond the walls is refused up front, card kept", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
const victim = state.players.find((p) => p.id !== caster.id)!;
|
||||
caster.position = { x: 0, y: 0 };
|
||||
victim.position = { x: 2, y: 4 };
|
||||
// Seal the victim into their square: every walked space is out of
|
||||
// reach, so ANY other destination is beyond three moved spaces.
|
||||
for (const side of SIDES) {
|
||||
state.edgeOverrides[edgeKey(victim.position, side)] = "wall";
|
||||
}
|
||||
const mf = giveCard(state, caster.id, "mental-force", "MF");
|
||||
const far = { x: 4, y: 9 };
|
||||
const refused = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: mf.instanceId,
|
||||
target: { kind: "player", playerId: victim.id }, params: { cell: far },
|
||||
});
|
||||
expect(refused.ok).toBe(false);
|
||||
if (!refused.ok) expect(refused.error).toContain("three moved spaces");
|
||||
// The card is still in hand — nothing was spent on the refusal.
|
||||
expect(state.players.find((p) => p.id === caster.id)!.hand.some((c) => c.instanceId === mf.instanceId)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the bent sight-trace shows AROUND THE CORNER's legs", () => {
|
||||
it("a bentCorner stack yields two auditable legs through a midpoint", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const a = activePlayer(state);
|
||||
const d = state.players.find((p) => p.id !== a.id)!;
|
||||
// Diagonal neighbors: center-to-center sight grazes the shared corner
|
||||
// (blocked, strict reading), but the legs through (3,2) are opened.
|
||||
a.position = { x: 2, y: 2 };
|
||||
d.position = { x: 3, y: 3 };
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 2 }, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 3, y: 2 }, "S")] = "open";
|
||||
state.stack = {
|
||||
attackerId: a.id, defenderId: d.id,
|
||||
attackCard: { instanceId: "fireball#T", cardId: "fireball" },
|
||||
numberValue: null, amplifyFactor: 1, extendFactor: 1,
|
||||
powerAttackPoints: 0, params: null, kind: "spell",
|
||||
counters: [], waitingOn: d.id, bentCorner: true,
|
||||
};
|
||||
// Wall the straight diagonal shut so only the bend can answer.
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 2 }, "S")] = "wall";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 3 }, "E")] = "wall";
|
||||
const traced = stackSightTrace(viewFor(state, d.id));
|
||||
expect(traced).not.toBeNull();
|
||||
// The engine promises A workable corner, not which one.
|
||||
expect(traced?.bend).toBeDefined();
|
||||
expect(traced?.bend?.mid).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("the tear is an attack (rev 6)", () => {
|
||||
function tearRig(deckRev?: number) {
|
||||
let { state } = createGame({
|
||||
playerIds: ["att", "def"], seed: 42, sets: ["basic", "expansion1"],
|
||||
...(deckRev != null ? { deckRev } : {}),
|
||||
});
|
||||
state = toRound2(state);
|
||||
while (activePlayer(state).id !== "att") {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const att = state.players.find((p) => p.id === "att")!;
|
||||
const def = state.players.find((p) => p.id === "def")!;
|
||||
def.position = { ...att.position };
|
||||
const gold = state.treasures.find((t) => t.owner === "att" && t.position)!;
|
||||
gold.position = null;
|
||||
gold.carriedBy = "def";
|
||||
def.carriedTreasureId = gold.id;
|
||||
state.sustained.push({
|
||||
id: "fx-t", cardId: "strength", casterId: "att", targetId: "att",
|
||||
remainingTurns: 3, data: {},
|
||||
});
|
||||
return { state, att, def, gold };
|
||||
}
|
||||
|
||||
it("opens a counteraction window; a TELEPORT escape keeps the chest", () => {
|
||||
let { state, gold } = tearRig();
|
||||
const r = applyCommand(state, "att", { type: "tearTreasure", targetId: "def" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.stack?.tearTreasure).toBe(true);
|
||||
expect(state.stack?.waitingOn).toBe("def");
|
||||
const def = state.players.find((p) => p.id === "def")!;
|
||||
const view = boardView(state);
|
||||
const away = SIDES.map((s) => stepTarget(view, def.position, s))
|
||||
.find((t) => t.kind === "step")!;
|
||||
giveCard(state, "def", "teleport", "TP", 0);
|
||||
state = must(state, "def", { type: "counteract", instanceId: "teleport#TP", params: { cell: (away as { to: Cell }).to } });
|
||||
state = must(state, "att", { type: "pass" });
|
||||
if (state.stack) state = must(state, state.stack.waitingOn, { type: "pass" });
|
||||
expect(state.stack).toBeNull();
|
||||
expect(state.players.find((p) => p.id === "def")!.carriedTreasureId).toBe(gold.id);
|
||||
});
|
||||
|
||||
it("an uncountered tear wrestles after the window closes", () => {
|
||||
let { state, gold } = tearRig();
|
||||
const r = applyCommand(state, "att", { type: "tearTreasure", targetId: "def" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
const res = applyCommand(state, "def", { type: "pass" });
|
||||
if (!res.ok) throw new Error(res.error);
|
||||
state = res.state;
|
||||
const rolled = res.events.find((e) => e.type === "dieRolled");
|
||||
expect(rolled).toBeTruthy();
|
||||
const kept = rolled!.type === "dieRolled" && rolled!.roll === 1;
|
||||
const att = state.players.find((p) => p.id === "att")!;
|
||||
const def = state.players.find((p) => p.id === "def")!;
|
||||
if (kept) expect(def.carriedTreasureId).toBe(gold.id);
|
||||
else expect(att.carriedTreasureId).toBe(gold.id);
|
||||
});
|
||||
|
||||
it("rev 5 games keep the instant tear, no stack", () => {
|
||||
let { state } = tearRig(5);
|
||||
const r = applyCommand(state, "att", { type: "tearTreasure", targetId: "def" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.stack).toBeNull();
|
||||
expect(r.events.some((e) => e.type === "treasureTorn" || e.type === "tearResisted")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a forced drop lands like any drop", () => {
|
||||
it("DROP OBJECT onto a home square reports the banking and checks victory", () => {
|
||||
let { state } = createGame({ playerIds: ["att", "def"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
while (activePlayer(state).id !== "att") {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const att = state.players.find((p) => p.id === "att")!;
|
||||
const def = state.players.find((p) => p.id === "def")!;
|
||||
// The defender stands on their OWN home carrying the attacker's gold —
|
||||
// the forced drop banks it for them, cruel as that is for the caster.
|
||||
def.position = { ...def.home };
|
||||
att.position = { ...def.home };
|
||||
const gold = state.treasures.find((t) => t.owner === "att" && t.position)!;
|
||||
gold.position = null;
|
||||
gold.carriedBy = "def";
|
||||
def.carriedTreasureId = gold.id;
|
||||
const dob = giveCard(state, "att", "drop-object", "D", 0);
|
||||
let r = applyCommand(state, "att", {
|
||||
type: "cast", instanceId: dob.instanceId,
|
||||
target: { kind: "player", playerId: "def" }, params: { cardId: "treasure" },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
r = applyCommand(r.state, "def", { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const drop = r.events.find((e) => e.type === "treasureDropped");
|
||||
expect(drop).toBeTruthy();
|
||||
if (drop?.type === "treasureDropped") expect(drop.onHomeOf).toBe("def");
|
||||
});
|
||||
});
|
||||
|
||||
describe("disease makes the caster the carrier (rev 7)", () => {
|
||||
it("self-casts with no target; sharing a square bites both directions", () => {
|
||||
let { state } = createGame({ playerIds: ["carrier", "mark"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
while (activePlayer(state).id !== "carrier") {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const carrier = state.players.find((p) => p.id === "carrier")!;
|
||||
const mark = state.players.find((p) => p.id === "mark")!;
|
||||
const dz = giveCard(state, "carrier", "disease", "D", 0);
|
||||
giveCard(state, "carrier", "number-3", "N", 1);
|
||||
let r = applyCommand(state, "carrier", {
|
||||
type: "cast", instanceId: dz.instanceId, numberInstanceIds: ["number-3#N"],
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.stack).toBeNull();
|
||||
expect(state.sustained.some((s) => s.cardId === "disease" && s.targetId === "carrier")).toBe(true);
|
||||
|
||||
// The carrier walks INTO the mark's square: the mark takes 3.
|
||||
const view = boardView(state);
|
||||
const carrierNow = state.players.find((p) => p.id === "carrier")!;
|
||||
const markNow = state.players.find((p) => p.id === "mark")!;
|
||||
for (const side of SIDES) {
|
||||
const t = stepTarget(view, carrierNow.position, side);
|
||||
if (t.kind !== "step") continue;
|
||||
markNow.position = { ...t.to };
|
||||
const before = markNow.life;
|
||||
r = applyCommand(state, "carrier", { type: "move", direction: side });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.players.find((p) => p.id === "mark")!.life).toBe(before - 3);
|
||||
break;
|
||||
}
|
||||
state = must(state, "carrier", { type: "endTurn", draw: 0 });
|
||||
|
||||
// The mark walks INTO the carrier's square: the mark takes 3 again.
|
||||
const m2 = state.players.find((p) => p.id === "mark")!;
|
||||
const c2 = state.players.find((p) => p.id === "carrier")!;
|
||||
const view2 = boardView(state);
|
||||
for (const side of SIDES) {
|
||||
const t = stepTarget(view2, c2.position, side);
|
||||
if (t.kind !== "step") continue;
|
||||
m2.position = { ...t.to };
|
||||
const back = side === "N" ? "S" : side === "S" ? "N" : side === "E" ? "W" : "E";
|
||||
const before = m2.life;
|
||||
r = applyCommand(state, "mark", { type: "move", direction: back as "N" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.players.find((p) => p.id === "mark")!.life).toBe(before - 3);
|
||||
return;
|
||||
}
|
||||
throw new Error("no adjacent step for the return walk");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, creatureAt, type GameState, type PlayerId, createGame } from "../src/game";
|
||||
import { cellKey, SIDES, stepTarget, type Cell, type Side } from "../src/board";
|
||||
import {
|
||||
type CreatureState, applyCommand, activePlayer, boardView, creatureAt, type GameState, type PlayerId, createGame } from "../src/game";
|
||||
import { cellKey, edgeKey, SIDES, stepTarget, type Cell, type Side } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newExpansionGame as newGame, must, giveCard, toRound2, emptyNeighborCell } from "./helpers";
|
||||
import { newExpansionGame as newGame, must, drain, giveCard, toRound2, emptyNeighborCell, pushSustained } from "./helpers";
|
||||
|
||||
/** Summon a creature next to its creator (round 2+, consumes the attack). */
|
||||
function summon(state: GameState, playerId: PlayerId, kind: string, tag = "S") {
|
||||
@@ -17,7 +18,8 @@ function summon(state: GameState, playerId: PlayerId, kind: string, tag = "S") {
|
||||
|
||||
describe("expansion deck", () => {
|
||||
it("basic + expansion1 builds the full 200-card game", () => {
|
||||
const { state } = newGame();
|
||||
// Three seats: two-player games shed LIFESAVER from the build.
|
||||
const { state } = newGame(42, ["a", "b", "c"]);
|
||||
const total = state.deck.length + state.discard.length +
|
||||
state.players.reduce((s, p) => s + p.hand.length, 0);
|
||||
expect(total).toBe(200);
|
||||
@@ -59,6 +61,8 @@ describe("monsters", () => {
|
||||
state = must(state, me, {
|
||||
type: "creatureAttack", creatureId: state.creatures[0]!.id, targetId: victim.id,
|
||||
});
|
||||
// The blow opens the victim's counteraction window; they take it raw.
|
||||
state = must(state, victim.id, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id !== me)!.life).toBe(13);
|
||||
});
|
||||
|
||||
@@ -136,6 +140,7 @@ describe("monsters", () => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
state = must(state, enemy2.id, { type: "pass" });
|
||||
const bitten = state.players.find((p) => p.id !== me)!;
|
||||
expect(bitten.life).toBe(13);
|
||||
expect(bitten.hand.length).toBe(6);
|
||||
@@ -146,24 +151,24 @@ describe("monsters", () => {
|
||||
state = toRound2(state);
|
||||
const me = activePlayer(state).id;
|
||||
const r = summon(state, me, "fire-imp");
|
||||
state = r.state;
|
||||
state = drain(r.state);
|
||||
const imp = state.creatures[0]!;
|
||||
|
||||
// Fireball cannot destroy it...
|
||||
state = must(state, me, { type: "endTurn", draw: 0 });
|
||||
state = drain(must(state, me, { type: "endTurn", draw: 0 }));
|
||||
const enemy = state.players.find((p) => p.id !== me)!;
|
||||
// (enemy may have been scorched at turn start if in LOS — note life)
|
||||
const enemyNow = state.players.find((p) => p.id !== me)!;
|
||||
enemyNow.position = { ...imp.position }; // stand at the imp for clear sight
|
||||
const fb = giveCard(state, enemy.id, "fireball", "F", 0);
|
||||
state = must(state, enemy.id, {
|
||||
state = drain(must(state, enemy.id, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "creature", creatureId: imp.id },
|
||||
});
|
||||
}));
|
||||
expect(state.creatures.length).toBe(1);
|
||||
|
||||
// ...but a waterbolt douses it instantly.
|
||||
state = must(state, enemy.id, { type: "endTurn", draw: 0 });
|
||||
state = must(state, me, { type: "endTurn", draw: 0 });
|
||||
state = drain(must(state, enemy.id, { type: "endTurn", draw: 0 }));
|
||||
state = drain(must(state, me, { type: "endTurn", draw: 0 }));
|
||||
state.players.find((p) => p.id !== me)!.position = { ...state.creatures[0]!.position };
|
||||
const wb = giveCard(state, enemy.id, "waterbolt", "W", 0);
|
||||
state = must(state, enemy.id, {
|
||||
@@ -293,9 +298,9 @@ describe("expansion support cards", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("counteracting a creature's blow (rules rev 4)", () => {
|
||||
function rev4() {
|
||||
return createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev: 4 });
|
||||
describe("counteracting a creature's blow", () => {
|
||||
function freshGame() {
|
||||
return createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
}
|
||||
function wraithOnVictim(state: GameState) {
|
||||
state = toRound2(state);
|
||||
@@ -312,7 +317,7 @@ describe("counteracting a creature's blow (rules rev 4)", () => {
|
||||
}
|
||||
|
||||
it("BLUNT halves the wraith's touch; the card theft still lands", () => {
|
||||
let { state } = rev4();
|
||||
let { state } = freshGame();
|
||||
const rig = wraithOnVictim(state);
|
||||
state = rig.state;
|
||||
giveCard(state, rig.victim, "blunt", "B", 0);
|
||||
@@ -328,7 +333,7 @@ describe("counteracting a creature's blow (rules rev 4)", () => {
|
||||
});
|
||||
|
||||
it("FULL REFLECTION turns the touch back on the wraith, theft and all", () => {
|
||||
let { state } = rev4();
|
||||
let { state } = freshGame();
|
||||
const rig = wraithOnVictim(state);
|
||||
state = rig.state;
|
||||
giveCard(state, rig.victim, "full-reflection", "FR", 0);
|
||||
@@ -341,20 +346,11 @@ describe("counteracting a creature's blow (rules rev 4)", () => {
|
||||
const wraith = state.creatures.find((c) => c.id === "w1")!;
|
||||
expect(wraith.damage).toBe(2);
|
||||
});
|
||||
|
||||
it("legacy games (rev < 4) keep the instant touch", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const rig = wraithOnVictim(state);
|
||||
state = rig.state;
|
||||
state = must(state, rig.controller, { type: "moveCreature", creatureId: "w1", direction: rig.side });
|
||||
expect(state.stack).toBeNull();
|
||||
expect(state.players.find((p) => p.id === rig.victim)!.life).toBe(13);
|
||||
});
|
||||
});
|
||||
|
||||
describe("big man (rules rev 5)", () => {
|
||||
describe("big man", () => {
|
||||
function bigRig() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev: 5 });
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const giant = activePlayer(state);
|
||||
state.sustained.push({
|
||||
@@ -415,6 +411,33 @@ describe("big man (rules rev 5)", () => {
|
||||
throw new Error("setup: seed offered no walled pocket beside the home");
|
||||
});
|
||||
|
||||
it("a shrunk wizard slips between the giant's boots", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const mover = activePlayer(state);
|
||||
const giant = state.players.find((p) => p.id !== mover.id)!;
|
||||
state.sustained.push({
|
||||
id: "fx-big", cardId: "big-man", casterId: giant.id, targetId: giant.id,
|
||||
remainingTurns: 9, data: {},
|
||||
});
|
||||
const view = boardView(state);
|
||||
const side = SIDES.find((s) => stepTarget(view, mover.position, s).kind === "step");
|
||||
if (!side) throw new Error("setup: no open step beside the mover");
|
||||
const t = stepTarget(view, mover.position, side);
|
||||
if (t.kind !== "step") throw new Error("unreachable");
|
||||
giant.position = { ...t.to };
|
||||
// Full-size, the corridor is filled.
|
||||
expect(applyCommand(state, mover.id, { type: "move", direction: side }).ok).toBe(false);
|
||||
// Shrunk, the same step slips through.
|
||||
state.sustained.push({
|
||||
id: "fx-small", cardId: "shrink", casterId: mover.id, targetId: mover.id,
|
||||
remainingTurns: 1, data: {},
|
||||
});
|
||||
const r = applyCommand(state, mover.id, { type: "move", direction: side });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(cellKey(r.state.players.find((p) => p.id === mover.id)!.position)).toBe(cellKey(giant.position));
|
||||
});
|
||||
|
||||
it("monsters cannot enter the giant's square", () => {
|
||||
const rig = bigRig();
|
||||
let state = rig.state;
|
||||
@@ -450,9 +473,9 @@ describe("big man (rules rev 5)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("monsters roll to hit the hidden (rules rev 13)", () => {
|
||||
function creatureVsInvisible(deckRev: number) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev });
|
||||
describe("monsters roll to hit the hidden", () => {
|
||||
function creatureVsInvisible() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const me = activePlayer(state).id;
|
||||
const victim = state.players.find((p) => p.id !== me)!;
|
||||
@@ -466,38 +489,22 @@ describe("monsters roll to hit the hidden (rules rev 13)", () => {
|
||||
id: "fx1", cardId: "invisible", casterId: victim.id, targetId: victim.id,
|
||||
remainingTurns: 3, data: {},
|
||||
});
|
||||
return { state, me, victim, trollId: bones.id };
|
||||
return { state, me, victim, skeletonId: bones.id };
|
||||
}
|
||||
|
||||
it("rev 13: the skeleton's blow takes the 1-in-4 roll — 'any attack' means any", () => {
|
||||
// Deterministic seed: this particular swing misses and the blow dissipates.
|
||||
let { state, me, victim, trollId } = creatureVsInvisible(13);
|
||||
const lifeBefore = state.players.find((p) => p.id === victim.id)!.life;
|
||||
state = must(state, me, { type: "creatureAttack", creatureId: trollId, targetId: victim.id });
|
||||
state = must(state, victim.id, { type: "pass" });
|
||||
const rolled = state.rng;
|
||||
expect(rolled).toBeDefined();
|
||||
const after = state.players.find((p) => p.id === victim.id)!;
|
||||
const missed = after.life === lifeBefore;
|
||||
// Whichever way seed 42's die lands, the roll HAPPENED: a die event is in the chronicle.
|
||||
expect(missed || after.life < lifeBefore).toBe(true);
|
||||
});
|
||||
|
||||
it("earlier revisions keep the old certainty: no roll, the blow just lands", () => {
|
||||
let { state, me, victim, trollId } = creatureVsInvisible(12);
|
||||
const lifeBefore = state.players.find((p) => p.id === victim.id)!.life;
|
||||
it("the skeleton's blow takes the 1-in-4 roll — 'any attack' means any", () => {
|
||||
let { state, me, victim, skeletonId } = creatureVsInvisible();
|
||||
const rngBefore = JSON.stringify(state.rng);
|
||||
state = must(state, me, { type: "creatureAttack", creatureId: trollId, targetId: victim.id });
|
||||
state = must(state, me, { type: "creatureAttack", creatureId: skeletonId, targetId: victim.id });
|
||||
state = must(state, victim.id, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === victim.id)!.life).toBeLessThan(lifeBefore);
|
||||
// No die was consumed on the way.
|
||||
expect(JSON.stringify(state.rng)).toBe(rngBefore);
|
||||
// The die was consumed, whichever way it landed.
|
||||
expect(JSON.stringify(state.rng)).not.toBe(rngBefore);
|
||||
});
|
||||
});
|
||||
|
||||
describe("elimination sweeps the board either way (rules rev 14)", () => {
|
||||
describe("elimination sweeps the board either way", () => {
|
||||
it("a treasure-eliminated wizard's fire imp vanishes with them", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 42, sets: ["basic", "expansion1"], deckRev: 14 });
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const victim = state.players.find((p) => p.id === "c")!;
|
||||
state.creatures.push({
|
||||
id: "imp1", kind: "fire-imp", controllerId: "c",
|
||||
@@ -526,3 +533,340 @@ describe("elimination sweeps the board either way (rules rev 14)", () => {
|
||||
expect(state.sustained.some((s) => s.targetId === "c")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("creatures walk open doorways", () => {
|
||||
it("a skeleton passes a door whose lock was removed", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "door") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
const side = kind === "V" ? ("E" as Side) : ("S" as Side);
|
||||
state.doorStates[key] = "removed";
|
||||
state.creatures.push({
|
||||
id: "sk1", kind: "skeleton", controllerId: activePlayer(state).id,
|
||||
position: { x, y }, damage: 0, maxDamage: 4, movesPerTurn: 3,
|
||||
movementUsed: 0, attackUsed: false, justCreated: false,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
const r = applyCommand(state, activePlayer(state).id, {
|
||||
type: "moveCreature", creatureId: "sk1", direction: side,
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const sk = r.state.creatures.find((c) => c.id === "sk1")!;
|
||||
expect(cellKey(sk.position)).toBe(cellKey({ x: x + (side === "E" ? 1 : 0), y: y + (side === "S" ? 1 : 0) }));
|
||||
return;
|
||||
}
|
||||
throw new Error("setup: seed 42 grew a maze with no doors");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the wave carries monsters", () => {
|
||||
it("a cornered skeleton takes the waterwall crush", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
// A skeleton pinned against solid stone, one square from the wave's edge.
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "wall") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
if (kind !== "H") continue;
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
// Wave from this wall southward washes the square below.
|
||||
const below = { x, y: y + 1 };
|
||||
if (!view.cells[cellKey(below)]) continue;
|
||||
state.creatures.push({
|
||||
id: "sk1", kind: "skeleton", controllerId: caster.id,
|
||||
position: { ...below }, damage: 0, maxDamage: 4, movesPerTurn: 3,
|
||||
movementUsed: 0, attackUsed: false, justCreated: false,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
// Pin it: stone directly south of it.
|
||||
state.squareContents[cellKey({ x, y: y + 2 })] = { kind: "stone", damage: 0, createdBy: caster.id };
|
||||
caster.position = { x, y };
|
||||
const stw = giveCard(state, caster.id, "stone-to-water");
|
||||
const r = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: stw.instanceId,
|
||||
target: { kind: "edge", cell: { x, y }, side: "S" },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const sk = r.state.creatures.find((c) => c.id === "sk1");
|
||||
// Washed against the stone: it took crush damage (or died of it).
|
||||
if (sk) expect(sk.damage).toBeGreaterThan(0);
|
||||
return;
|
||||
}
|
||||
throw new Error("setup: no horizontal wall with a floor below");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the democratic monster's claw survives the first wizard's death", () => {
|
||||
it("refreshes each round even with the roll-off winner dead", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const firstId = state.players[state.turn.firstIndex]!.id;
|
||||
const dm = {
|
||||
id: "dm1", kind: "democratic-monster" as const, controllerId: state.players[0]!.id,
|
||||
position: { x: 0, y: 0 }, damage: 0, maxDamage: 5, movesPerTurn: 3,
|
||||
movementUsed: 0, attackUsed: true, justCreated: false,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [] as string[],
|
||||
};
|
||||
state.creatures.push(dm);
|
||||
// The roll-off winner falls.
|
||||
const first = state.players.find((p) => p.id === firstId)!;
|
||||
first.alive = false;
|
||||
first.finalHand = [...first.hand];
|
||||
// Walk a full round of the survivors: the claw must refresh.
|
||||
for (let i = 0; i < 4 && state.creatures[0]!.attackUsed; i++) {
|
||||
const active = activePlayer(state);
|
||||
const r = applyCommand(state, active.id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
expect(state.creatures[0]!.attackUsed).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a mid-round democratic monster claws on the next turn", () => {
|
||||
it("creation spends the turn, not the round", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const creator = activePlayer(state);
|
||||
const r0 = summon(state, creator.id, "democratic-monster");
|
||||
state = r0.state;
|
||||
const dm = state.creatures.find((c) => c.kind === "democratic-monster")!;
|
||||
expect(dm.attackUsed).toBe(false);
|
||||
expect(dm.justCreated).toBe(true);
|
||||
// Next player's turn: justCreated clears; the claw is live.
|
||||
state = must(state, creator.id, { type: "endTurn", draw: 0 });
|
||||
const mover = activePlayer(state);
|
||||
const victim = state.players.find((p) => p.id !== mover.id)!;
|
||||
const fresh = state.creatures.find((c) => c.kind === "democratic-monster")!;
|
||||
expect(fresh.justCreated).toBe(false);
|
||||
// March it onto the victim: the touch must open.
|
||||
fresh.position = { x: victim.position.x - 1, y: victim.position.y };
|
||||
const r = applyCommand(state, mover.id, { type: "moveCreature", creatureId: fresh.id, direction: "E" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.stack?.creatureId ?? null).toBe(fresh.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("collapsing walls crush monsters too", () => {
|
||||
function wallRig() {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "wall") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
const side = kind === "V" ? ("E" as Side) : ("S" as Side);
|
||||
const other = { x: x + (side === "E" ? 1 : 0), y: y + (side === "S" ? 1 : 0) };
|
||||
if (!view.cells[cellKey(other)]) continue;
|
||||
const caster = activePlayer(state);
|
||||
caster.position = { x, y };
|
||||
state.creatures.push({
|
||||
id: "tr1", kind: "troll", controllerId: caster.id,
|
||||
position: { ...other }, damage: 0, maxDamage: 6, movesPerTurn: 3,
|
||||
movementUsed: 0, attackUsed: false, justCreated: false,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
const dw = giveCard(state, caster.id, "destroy-wall");
|
||||
const r = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: dw.instanceId, target: { kind: "edge", cell: { x, y }, side },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
return r.state;
|
||||
}
|
||||
throw new Error("setup: no interior wall found");
|
||||
}
|
||||
|
||||
it("the adjacent troll takes the four points", () => {
|
||||
const state = wallRig();
|
||||
const troll = state.creatures.find((c) => c.id === "tr1");
|
||||
// Four points on a six-point troll: hurt but standing (or regenerating).
|
||||
expect(troll?.damage).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the self-stack resolves on a pass", () => {
|
||||
function selfTouch() {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const creator = activePlayer(state);
|
||||
state.creatures.push({
|
||||
id: "dm1", kind: "democratic-monster", controllerId: creator.id,
|
||||
position: { x: creator.position.x - 1, y: creator.position.y },
|
||||
damage: 0, maxDamage: 5, movesPerTurn: 3, movementUsed: 0,
|
||||
attackUsed: false, justCreated: false,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
const r = applyCommand(state, creator.id, { type: "moveCreature", creatureId: "dm1", direction: "E" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
return { state: r.state, creator: creator.id };
|
||||
}
|
||||
|
||||
it("passing your own monster's touch takes the claw and moves on", () => {
|
||||
const { state, creator } = selfTouch();
|
||||
if (!state.stack) return; // a wall between: the touch never opened
|
||||
expect(state.stack.attackerId).toBe(creator);
|
||||
expect(state.stack.defenderId).toBe(creator);
|
||||
const r = applyCommand(state, creator, { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.stack).toBeNull();
|
||||
expect(r.state.players.find((p) => p.id === creator)!.life).toBe(13);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fear holds off monsters and unwilling feet alike", () => {
|
||||
it("a commanded monster cannot close within three of the fearsome", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const a = state.players.find((p) => p.id === "a")!;
|
||||
const b = state.players.find((p) => p.id === "b")!;
|
||||
// b radiates fear; a's troll stands exactly four away, aimed straight at b.
|
||||
pushSustained(state, {
|
||||
id: "fx-fear", cardId: "fear", casterId: "b", targetId: "b",
|
||||
remainingTurns: 5, data: {},
|
||||
});
|
||||
b.position = { x: 2, y: 5 };
|
||||
a.position = { x: 0, y: 0 };
|
||||
state.creatures.push({
|
||||
id: "troll-1", kind: "troll", controllerId: "a", position: { x: 2, y: 9 },
|
||||
damage: 0, maxDamage: 6, movesPerTurn: 3, movementUsed: 0,
|
||||
wallPassesPerTurn: 0, wallPassUsed: 0, attackUsed: false, justCreated: false,
|
||||
scorchedThisTurn: [],
|
||||
});
|
||||
for (const y of [5, 6, 7, 8]) state.edgeOverrides[edgeKey({ x: 2, y }, "S")] = "open";
|
||||
while (state.players[state.turn.activeIndex]!.id !== "a") {
|
||||
const r = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const r = applyCommand(state, "a", { type: "moveCreature", creatureId: "troll-1", direction: "N" });
|
||||
expect(r.ok).toBe(false);
|
||||
if (!r.ok) expect(r.error).toContain("dread");
|
||||
});
|
||||
|
||||
it("a wizard caged inside the dread may round a corner to escape", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const a = state.players.find((p) => p.id === "a")!;
|
||||
const b = state.players.find((p) => p.id === "b")!;
|
||||
pushSustained(state, {
|
||||
id: "fx-fear", cardId: "fear", casterId: "b", targetId: "b",
|
||||
remainingTurns: 5, data: {},
|
||||
});
|
||||
// b radiates dread from (2,5). a stands in a dead-end pocket at
|
||||
// (2,3): walls on three sides, so the only way out steps SOUTH —
|
||||
// closer to b — before the corridor east leads clear of the dread.
|
||||
b.position = { x: 2, y: 5 };
|
||||
a.position = { x: 2, y: 3 };
|
||||
for (const side of ["N", "E", "W"] as const) {
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 3 }, side)] = "wall";
|
||||
}
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 3 }, "S")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 4 }, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 3, y: 4 }, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 4, y: 4 }, "N")] = "open";
|
||||
while (state.players[state.turn.activeIndex]!.id !== "a") {
|
||||
const r0 = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "endTurn", draw: 0 });
|
||||
if (!r0.ok) throw new Error(r0.error);
|
||||
state = r0.state;
|
||||
}
|
||||
// The closer step is the only way out: permitted.
|
||||
const r = applyCommand(state, "a", { type: "move", direction: "S" });
|
||||
if (!r.ok) throw new Error("escape step refused: " + r.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("creatures and the dimensional warp", () => {
|
||||
it("a commanded troll steps through the warp tokens", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const you = state.players[state.turn.activeIndex]!.id;
|
||||
state.dimWarps.push({ a: { x: 1, y: 1 }, b: { x: 3, y: 8 } });
|
||||
state.creatures.push({
|
||||
id: "troll-w", kind: "troll", controllerId: you, position: { x: 1, y: 1 },
|
||||
damage: 0, maxDamage: 6, movesPerTurn: 2, movementUsed: 0, attackUsed: false,
|
||||
justCreated: false, wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
const r = applyCommand(state, you, { type: "creatureWarpStep", creatureId: "troll-w" });
|
||||
expect(r.ok).toBe(true);
|
||||
if (r.ok) {
|
||||
const troll = r.state.creatures.find((c) => c.id === "troll-w")!;
|
||||
expect(cellKey(troll.position)).toBe(cellKey({ x: 3, y: 8 }));
|
||||
expect(troll.movementUsed).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
it("solid stone on the far side refuses the beast", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const you = state.players[state.turn.activeIndex]!.id;
|
||||
state.dimWarps.push({ a: { x: 1, y: 1 }, b: { x: 3, y: 8 } });
|
||||
state.squareContents[cellKey({ x: 3, y: 8 })] = { kind: "stone", damage: 0, createdBy: "b" };
|
||||
state.creatures.push({
|
||||
id: "troll-w", kind: "troll", controllerId: you, position: { x: 1, y: 1 },
|
||||
damage: 0, maxDamage: 6, movesPerTurn: 2, movementUsed: 0, attackUsed: false,
|
||||
justCreated: false, wallPassesPerTurn: 0, wallPassUsed: 0, scorchedThisTurn: [],
|
||||
});
|
||||
const r = applyCommand(state, you, { type: "creatureWarpStep", creatureId: "troll-w" });
|
||||
expect(r.ok).toBe(false);
|
||||
if (!r.ok) expect(r.error).toContain("stone");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the imp's fire is a spell (rev 8)", () => {
|
||||
function impRig() {
|
||||
let { state } = createGame({ playerIds: ["imp-owner", "mark"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
while (activePlayer(state).id !== "imp-owner") {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
it("scorch opens a counteraction window and FULL SHIELD stops it", () => {
|
||||
let state = impRig();
|
||||
const owner = state.players.find((p) => p.id === "imp-owner")!;
|
||||
const mark = state.players.find((p) => p.id === "mark")!;
|
||||
mark.position = { ...owner.position };
|
||||
const impCard = giveCard(state, "imp-owner", "fire-imp", "FI", 0);
|
||||
const spot = emptyNeighborCell(state, owner.position);
|
||||
let r = applyCommand(state, "imp-owner", {
|
||||
type: "cast", instanceId: impCard.instanceId, target: { kind: "cell", cell: spot.cell },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
if (!state.stack) state = must(state, "imp-owner", { type: "endTurn", draw: 0 });
|
||||
// The scorch rides the stack now: a counteraction window, spell-kind.
|
||||
expect(state.stack?.creatureId).toBeTruthy();
|
||||
expect(state.stack?.kind).toBe("spell");
|
||||
giveCard(state, "mark", "full-shield", "FS", 0);
|
||||
state = must(state, "mark", { type: "counteract", instanceId: "full-shield#FS" });
|
||||
state = drain(state);
|
||||
expect(state.players.find((p) => p.id === "mark")!.life).toBe(15);
|
||||
});
|
||||
|
||||
it("soulstone's floor holds from below: a bearer at 2 takes nothing from the flame", () => {
|
||||
let state = impRig();
|
||||
const owner = state.players.find((p) => p.id === "imp-owner")!;
|
||||
const mark = state.players.find((p) => p.id === "mark")!;
|
||||
mark.position = { ...owner.position };
|
||||
mark.life = 2;
|
||||
mark.displayed.push("SS");
|
||||
mark.hand[0] = { instanceId: "SS", cardId: "soulstone" };
|
||||
const impCard = giveCard(state, "imp-owner", "fire-imp", "FI", 1);
|
||||
const spot = emptyNeighborCell(state, owner.position);
|
||||
let r = applyCommand(state, "imp-owner", {
|
||||
type: "cast", instanceId: impCard.instanceId, target: { kind: "cell", cell: spot.cell },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
if (!state.stack) state = must(state, "imp-owner", { type: "endTurn", draw: 0 });
|
||||
expect(state.stack?.kind).toBe("spell");
|
||||
state = drain(state);
|
||||
const after = state.players.find((p) => p.id === "mark")!;
|
||||
expect(after.life).toBe(2);
|
||||
expect(after.alive).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, sustainedOn, type GameState } from "../src/game";
|
||||
import { cellKey, edgeKey, neighbor, type Side } from "../src/board";
|
||||
import { applyCommand, activePlayer, boardView, createGame, sustainedOn, type GameState } from "../src/game";
|
||||
import { cellKey, edgeKey, neighbor, opposite, type Side } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newGame, must, giveCard, toRound2, faceOff, castAt } from "./helpers";
|
||||
|
||||
@@ -111,7 +111,7 @@ describe("doors", () => {
|
||||
throw new Error("no door on this board");
|
||||
}
|
||||
|
||||
it("pick lock opens an adjacent door until end of turn", () => {
|
||||
it("pick lock opens an adjacent door — and it relocks behind the walker", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const door = findDoor(state);
|
||||
@@ -130,9 +130,8 @@ describe("doors", () => {
|
||||
state = must(state, me.id, { type: "move", direction: dir });
|
||||
expect(cellKey(activePlayer(state).position)).toBe(cellKey(other));
|
||||
|
||||
// Relocks when the turn ends.
|
||||
state = must(state, me.id, { type: "endTurn", draw: 0 });
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
// "It will relock behind you": shut at the walker's back at once —
|
||||
// the way back is barred without another pick.
|
||||
expect(state.openDoorEdges.length).toBe(0);
|
||||
expect(applyCommand(state, me.id, { type: "move", direction: dir === "E" ? "W" : "N" }).ok).toBe(false);
|
||||
});
|
||||
@@ -340,9 +339,231 @@ describe("cast modifiers", () => {
|
||||
});
|
||||
state = must(state, defender, { type: "counteract", instanceId: "reverse#R" });
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
expect(d.life).toBe(19); // gained 4 instead of losing it
|
||||
expect(d.lostTurns).toBe(1); // the stun still applies
|
||||
});
|
||||
});
|
||||
|
||||
describe("holding the door open (Pick Lock / Master Key)", () => {
|
||||
function doorRig() {
|
||||
let { state } = createGame({ playerIds: ["holder", "guest"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
// Find a door edge; stand the acting player beside it.
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "door") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
const cell = { x, y };
|
||||
const side = kind === "V" ? ("E" as Side) : ("S" as Side);
|
||||
const holder = activePlayer(state);
|
||||
holder.position = { ...cell };
|
||||
return { state, key, cell, side, holder: holder.id };
|
||||
}
|
||||
throw new Error("setup: seed 42 grew a maze with no doors");
|
||||
}
|
||||
|
||||
it("a held door outlives the turn and admits another wizard", () => {
|
||||
let { state, key, cell, side, holder } = doorRig();
|
||||
const pick = giveCard(state, holder, "pick-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: pick.instanceId,
|
||||
target: { kind: "edge", cell, side }, params: { hold: true },
|
||||
});
|
||||
state = must(state, holder, { type: "endTurn", draw: 0 });
|
||||
expect(state.heldDoors.some((h) => h.key === key)).toBe(true);
|
||||
const guest = state.players.find((p) => p.id !== holder)!;
|
||||
guest.position = { ...cell };
|
||||
const r = applyCommand(state, guest.id, { type: "move", direction: side });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const through = r.state.players.find((p) => p.id === guest.id)!;
|
||||
expect(cellKey(through.position)).toBe(cellKey(neighbor(cell, side)));
|
||||
});
|
||||
|
||||
it("the door swings shut the moment the holder steps away", () => {
|
||||
let { state, key, cell, side, holder } = doorRig();
|
||||
const pick = giveCard(state, holder, "pick-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: pick.instanceId,
|
||||
target: { kind: "edge", cell, side }, params: { hold: true },
|
||||
});
|
||||
expect(state.heldDoors.some((h) => h.key === key)).toBe(true);
|
||||
// March the holder until adjacency breaks; the sweep must release.
|
||||
let walked = state;
|
||||
let released = false;
|
||||
const dirs: Side[] = ["N", "E", "S", "W"];
|
||||
for (const d1 of dirs) {
|
||||
const r1 = applyCommand(walked, holder, { type: "move", direction: d1 });
|
||||
if (!r1.ok) continue;
|
||||
if (!r1.state.heldDoors.some((h) => h.key === key)) { released = true; break; }
|
||||
for (const d2 of dirs) {
|
||||
const r2 = applyCommand(r1.state, holder, { type: "move", direction: d2 });
|
||||
if (!r2.ok) continue;
|
||||
if (!r2.state.heldDoors.some((h) => h.key === key)) { released = true; break; }
|
||||
}
|
||||
if (released) break;
|
||||
}
|
||||
expect(released).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a held door is an open doorway to the eye", () => {
|
||||
function sightRig() {
|
||||
let { state } = createGame({ playerIds: ["holder", "pursuer"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "door") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
const cell = { x, y };
|
||||
const side = kind === "V" ? ("E" as Side) : ("S" as Side);
|
||||
const holder = activePlayer(state);
|
||||
const pursuer = state.players.find((p) => p.id !== holder.id)!;
|
||||
holder.position = { ...cell };
|
||||
pursuer.position = neighbor(cell, side);
|
||||
return { state, cell, side, holder: holder.id, pursuer: pursuer.id };
|
||||
}
|
||||
throw new Error("setup: seed 42 grew a maze with no doors");
|
||||
}
|
||||
|
||||
it("the holder blasts the pursuer through the held doorway", () => {
|
||||
let { state, cell, side, holder, pursuer } = sightRig();
|
||||
const pick = giveCard(state, holder, "pick-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: pick.instanceId,
|
||||
target: { kind: "edge", cell, side }, params: { hold: true },
|
||||
});
|
||||
const fb = giveCard(state, holder, "fireball", "FB", 1);
|
||||
const lifeBefore = state.players.find((p) => p.id === pursuer)!.life;
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: pursuer },
|
||||
});
|
||||
state = must(state, pursuer, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === pursuer)!.life).toBeLessThan(lifeBefore);
|
||||
});
|
||||
|
||||
it("an unlocked door is an open doorway to the wizard at its threshold", () => {
|
||||
let { state, cell, side, holder, pursuer } = sightRig();
|
||||
const pick = giveCard(state, holder, "pick-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: pick.instanceId,
|
||||
target: { kind: "edge", cell, side },
|
||||
});
|
||||
const fb = giveCard(state, holder, "fireball", "FB", 1);
|
||||
const cast = applyCommand(state, holder, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: pursuer },
|
||||
});
|
||||
expect(cast.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("a lock REMOVED lets any wizard beside the door peek through", () => {
|
||||
let { state, cell, side, holder, pursuer } = sightRig();
|
||||
const rm = giveCard(state, holder, "remove-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: rm.instanceId,
|
||||
target: { kind: "edge", cell, side },
|
||||
});
|
||||
const fb = giveCard(state, holder, "fireball", "FB", 1);
|
||||
const cast = applyCommand(state, holder, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: pursuer },
|
||||
});
|
||||
expect(cast.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("PICK LOCK in hand is enough to ease a locked door open a crack", () => {
|
||||
let { state, cell, side, holder, pursuer } = sightRig();
|
||||
giveCard(state, holder, "pick-lock");
|
||||
const fb = giveCard(state, holder, "fireball", "FB", 1);
|
||||
const cast = applyCommand(state, holder, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: pursuer },
|
||||
});
|
||||
expect(cast.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("the wizard down the hallway sees no further than the shut door", () => {
|
||||
let { state, cell, side, holder, pursuer } = sightRig();
|
||||
// Pull the pursuer one square further down the hall, so the door is
|
||||
// no longer on their threshold; clear their path to the doorway.
|
||||
const near = neighbor(cell, side);
|
||||
const far = neighbor(near, side);
|
||||
if (!boardView(state).cells[cellKey(far)]) {
|
||||
throw new Error("setup: seed 42 lost the hallway this rig stands in");
|
||||
}
|
||||
state.players.find((p) => p.id === pursuer)!.position = far;
|
||||
state.edgeOverrides[edgeKey(near, side)] = "open";
|
||||
const rm = giveCard(state, holder, "remove-lock");
|
||||
state = must(state, holder, {
|
||||
type: "cast", instanceId: rm.instanceId,
|
||||
target: { kind: "edge", cell, side },
|
||||
});
|
||||
state = must(state, holder, { type: "endTurn", draw: 0 });
|
||||
const fb = giveCard(state, pursuer, "fireball", "FB", 1);
|
||||
const refused = applyCommand(state, pursuer, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: holder },
|
||||
});
|
||||
expect(refused.ok).toBe(false);
|
||||
if (!refused.ok) expect(refused.error).toContain("line of sight");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the displayed MASTER KEY", () => {
|
||||
function keyRig() {
|
||||
let { state } = createGame({ playerIds: ["keeper", "watcher"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const view = boardView(state);
|
||||
for (const [key, edge] of Object.entries(view.edges)) {
|
||||
if (edge !== "door") continue;
|
||||
const [kind, coords] = key.split(":") as [string, string];
|
||||
const [x, y] = coords.split(",").map(Number) as [number, number];
|
||||
const cell = { x, y };
|
||||
const side = kind === "V" ? ("E" as Side) : ("S" as Side);
|
||||
const keeper = activePlayer(state);
|
||||
keeper.position = { ...cell };
|
||||
return { state, cell, side, key, keeper };
|
||||
}
|
||||
throw new Error("setup: seed 42 grew a maze with no doors");
|
||||
}
|
||||
|
||||
it("cast bare, the key goes on display — once", () => {
|
||||
const { state, keeper } = keyRig();
|
||||
const mk = giveCard(state, keeper.id, "master-key", "MK");
|
||||
const cast = applyCommand(state, keeper.id, { type: "cast", instanceId: mk.instanceId });
|
||||
expect(cast.ok).toBe(true);
|
||||
if (cast.ok) {
|
||||
const after = cast.state.players.find((p) => p.id === keeper.id)!;
|
||||
expect(after.displayed).toContain(mk.instanceId);
|
||||
expect(after.hand.some((c) => c.instanceId === mk.instanceId)).toBe(true);
|
||||
const again = applyCommand(cast.state, keeper.id, { type: "cast", instanceId: mk.instanceId });
|
||||
expect(again.ok).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("its bearer walks through locked doors, which relock at their back", () => {
|
||||
const { state, cell, side, key, keeper } = keyRig();
|
||||
const mk = giveCard(state, keeper.id, "master-key", "MK");
|
||||
keeper.displayed.push(mk.instanceId);
|
||||
const r = applyCommand(state, keeper.id, { type: "move", direction: side });
|
||||
expect(r.ok).toBe(true);
|
||||
if (r.ok) {
|
||||
const after = r.state.players.find((p) => p.id === keeper.id)!;
|
||||
expect(cellKey(after.position)).toBe(cellKey(neighbor(cell, side)));
|
||||
// "Door relocks behind you": no lingering opening for bystanders.
|
||||
expect(r.state.openDoorEdges).not.toContain(key);
|
||||
expect(r.events.some((e) => e.type === "doorUnlocked")).toBe(true);
|
||||
// The key turns again on the way back.
|
||||
const back = applyCommand(r.state, keeper.id, { type: "move", direction: opposite(side) });
|
||||
expect(back.ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("a JAMmed LOCK refuses even the master key", () => {
|
||||
const { state, side, key, keeper } = keyRig();
|
||||
const mk = giveCard(state, keeper.id, "master-key", "MK");
|
||||
keeper.displayed.push(mk.instanceId);
|
||||
state.doorStates[key] = "jammed";
|
||||
const r = applyCommand(state, keeper.id, { type: "move", direction: side });
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, gameLos, sustainedOn } from "../src/game";
|
||||
import { cellKey, stepTarget } from "../src/board";
|
||||
import { applyCommand, activePlayer, boardView, createGame, gameLos, sustainedOn } from "../src/game";
|
||||
import { cellKey, edgeKey, stepTarget } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newExpansionGame as newGame, must, giveCard, toRound2, faceOff, castAt } from "./helpers";
|
||||
import { newExpansionGame as newGame, must, drain, giveCard, toRound2, faceOff, castAt } from "./helpers";
|
||||
|
||||
describe("expansion combat cards", () => {
|
||||
it("power attack burns life for extra damage", () => {
|
||||
@@ -73,8 +73,8 @@ describe("expansion combat cards", () => {
|
||||
.toEqual(aCards.filter((id) => id !== ms.instanceId));
|
||||
});
|
||||
|
||||
it("butt-head rams for the distance charged", () => {
|
||||
let { state } = newGame();
|
||||
it("butt-head rams for the distance charged (legacy rev 9 rules)", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"], deckRev: 9 });
|
||||
state = toRound2(state);
|
||||
const attacker = activePlayer(state);
|
||||
const defender = state.players.find((p) => p.id !== attacker.id)!;
|
||||
@@ -106,7 +106,7 @@ describe("expansion combat cards", () => {
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(10);
|
||||
});
|
||||
|
||||
it("ward springs when a trapped treasure is grabbed", () => {
|
||||
it("ward springs in the moment: the grab hangs on the owner's choice", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const enemy = state.players.find((p) => p.id !== me.id)!;
|
||||
@@ -114,6 +114,9 @@ describe("expansion combat cards", () => {
|
||||
const treasure = state.treasures.find((t) => t.owner === enemy.id && t.position)!;
|
||||
me.position = { ...treasure.position! };
|
||||
state = must(state, me.id, { type: "pickUpTreasure" });
|
||||
expect(state.wardPending).toEqual({ ownerId: enemy.id, takerId: me.id });
|
||||
state = must(state, enemy.id, { type: "wardChoice", play: true });
|
||||
state = drain(state);
|
||||
expect(state.players.find((p) => p.id === me.id)!.life).toBe(12);
|
||||
expect(state.players.find((p) => p.id === enemy.id)!.hand.some((c) => c.cardId === "ward")).toBe(false);
|
||||
});
|
||||
@@ -161,6 +164,142 @@ describe("expansion combat cards", () => {
|
||||
expect(r.error).toMatch(/blocked/);
|
||||
}
|
||||
});
|
||||
|
||||
it("idiot lifts the moment the victim's last floor treasure is carried off", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob", "carol"], seed: 42, sets: ["basic"] });
|
||||
while (state.turn.round < 2) {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const third = state.players.find((p) => p.id !== attacker && p.id !== defender)!;
|
||||
const id = giveCard(state, attacker, "idiot");
|
||||
state = castAt(state, attacker, defender, id);
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(1);
|
||||
|
||||
// A third wizard hauls off one of the victim's chests: one destination
|
||||
// remains, so the march goes on.
|
||||
const [first, second] = state.treasures.filter((t) => t.owner === defender);
|
||||
const hauler = state.players.find((p) => p.id === third.id)!;
|
||||
first!.carriedBy = hauler.id;
|
||||
first!.position = null;
|
||||
hauler.carriedTreasureId = first!.id;
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(1);
|
||||
|
||||
// The caster takes the last one off the floor — nothing left to march
|
||||
// to, and the curse lifts on the spot.
|
||||
const att = state.players.find((p) => p.id === attacker)!;
|
||||
att.position = { ...second!.position! };
|
||||
state = must(state, attacker, { type: "pickUpTreasure", treasureId: second!.id });
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(0);
|
||||
});
|
||||
|
||||
it("idiot forbids item handling and punches but allows counteractions", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
// The victim carries an OPPONENT'S treasure into the spell.
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const stolen = state.treasures.find((t) => t.owner === attacker)!;
|
||||
stolen.carriedBy = defender;
|
||||
stolen.position = null;
|
||||
d.carriedTreasureId = stolen.id;
|
||||
const id = giveCard(state, attacker, "idiot");
|
||||
state = castAt(state, attacker, defender, id);
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(1);
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
|
||||
// No dropping the carried treasure (no capturing it on your home, either).
|
||||
const drop = applyCommand(state, defender, { type: "dropTreasure" });
|
||||
expect(drop.ok).toBe(false);
|
||||
if (!drop.ok) expect(drop.error).toMatch(/treasure/);
|
||||
// No punching the tormentor.
|
||||
expect(applyCommand(state, defender, { type: "punch", targetId: attacker }).ok).toBe(false);
|
||||
// Goal-aiding spells stay castable (FAQ: "You could, however, destroy a wall").
|
||||
const sp = giveCard(state, defender, "speed", "SP", 0);
|
||||
expect(applyCommand(state, defender, { type: "cast", instanceId: sp.instanceId }).ok).toBe(true);
|
||||
// Counteractions are expressly allowed: absorb an incoming fireball.
|
||||
state = must(state, defender, { type: "endTurn", draw: 0 });
|
||||
const fb = giveCard(state, attacker, "fireball", "F", 0);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
giveCard(state, defender, "absorb-spell", "AB", 1);
|
||||
expect(applyCommand(state, defender, { type: "counteract", instanceId: "absorb-spell#AB" }).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("idiot never steers the march — the step goes where asked", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const id = giveCard(state, attacker, "idiot");
|
||||
state = castAt(state, attacker, defender, id);
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(1);
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const board = boardView(state);
|
||||
const open = (["N", "S", "E", "W"] as const)
|
||||
.filter((s) => stepTarget(board, d.position, s).kind === "step");
|
||||
expect(open.length).toBeGreaterThanOrEqual(2);
|
||||
// Plant the victim's own gold one step out one way; walk the other way.
|
||||
|
||||
const toward = stepTarget(board, d.position, open[0]!);
|
||||
const away = stepTarget(board, d.position, open[1]!);
|
||||
if (toward.kind === "blocked" || away.kind === "blocked") throw new Error("unreachable");
|
||||
const own = state.treasures.find((t) => t.owner === defender)!;
|
||||
own.carriedBy = null;
|
||||
own.position = toward.to;
|
||||
state = must(state, defender, { type: "move", direction: open[1]! });
|
||||
expect(cellKey(state.players.find((p) => p.id === defender)!.position)).toBe(cellKey(away.to));
|
||||
});
|
||||
|
||||
it("idiot permits DROP OBJECT that frees the victim's own treasure", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const thief = state.players.find((p) => p.id === attacker)!;
|
||||
const own = state.treasures.find((t) => t.owner === defender)!;
|
||||
own.carriedBy = attacker;
|
||||
own.position = null;
|
||||
thief.carriedTreasureId = own.id;
|
||||
const id = giveCard(state, attacker, "idiot");
|
||||
state = castAt(state, attacker, defender, id);
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
// An attack for its own sake stays forbidden.
|
||||
const fb = giveCard(state, defender, "fireball", "F", 0);
|
||||
expect(applyCommand(state, defender, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: attacker },
|
||||
}).ok).toBe(false);
|
||||
// Shaking YOUR OWN gold out of the thief's arms serves the march —
|
||||
// while carried it cannot be stood upon.
|
||||
const dr = giveCard(state, defender, "drop-object", "D", 1);
|
||||
const r = applyCommand(state, defender, {
|
||||
type: "cast", instanceId: dr.instanceId,
|
||||
target: { kind: "player", playerId: attacker }, params: { cardId: "treasure" },
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("idiot has no effect on a victim carrying their own treasure", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const own = state.treasures.find((t) => t.owner === defender)!;
|
||||
own.carriedBy = defender;
|
||||
own.position = null;
|
||||
d.carriedTreasureId = own.id;
|
||||
const id = giveCard(state, attacker, "idiot");
|
||||
state = castAt(state, attacker, defender, id);
|
||||
expect(sustainedOn(state, defender, "idiot").length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("swap home bases", () => {
|
||||
@@ -283,3 +422,324 @@ describe("ambushes (async interrupts)", () => {
|
||||
expect(state.ambushes.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("strength tears treasures from wizards' arms", () => {
|
||||
function grip(seed: number) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
// The defender carries the ATTACKER's own treasure (no ward window).
|
||||
const stolen = state.treasures.find((t) => t.owner === attacker)!;
|
||||
stolen.carriedBy = defender;
|
||||
stolen.position = null;
|
||||
d.carriedTreasureId = stolen.id;
|
||||
const st = giveCard(state, attacker, "strength");
|
||||
giveCard(state, attacker, "number-2", "N", 1);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: st.instanceId, numberInstanceIds: ["number-2#N"],
|
||||
});
|
||||
return { state, attacker, defender, treasure: stolen.id };
|
||||
}
|
||||
|
||||
it("the grip is an attack: the victim keeps the treasure only on a 1", () => {
|
||||
let torn = 0, kept = 0;
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
const { state, attacker, defender, treasure } = grip(seed);
|
||||
let r = applyCommand(state, attacker, { type: "tearTreasure", targetId: defender });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// Rev 6: the grab waits out its counteraction window first.
|
||||
expect(r.state.stack?.tearTreasure).toBe(true);
|
||||
r = applyCommand(r.state, defender, { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.turn.attackUsed).toBe(true);
|
||||
// FAQ: tearing is not picking up — the turn's actions continue.
|
||||
expect(r.state.turn.actionsEnded).toBe(false);
|
||||
const a = r.state.players.find((p) => p.id === attacker)!;
|
||||
const d = r.state.players.find((p) => p.id === defender)!;
|
||||
if (a.carriedTreasureId === treasure) {
|
||||
torn++;
|
||||
expect(d.carriedTreasureId).toBeNull();
|
||||
} else {
|
||||
kept++;
|
||||
expect(d.carriedTreasureId).toBe(treasure);
|
||||
}
|
||||
// One attack per turn: a second wrench is refused.
|
||||
expect(applyCommand(r.state, attacker, { type: "tearTreasure", targetId: defender }).ok).toBe(false);
|
||||
}
|
||||
expect(torn).toBeGreaterThan(0);
|
||||
expect(kept).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("without STRENGTH the grip is refused", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const t = state.treasures.find((t) => t.owner === attacker)!;
|
||||
t.carriedBy = defender;
|
||||
t.position = null;
|
||||
d.carriedTreasureId = t.id;
|
||||
const r = applyCommand(state, attacker, { type: "tearTreasure", targetId: defender });
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("laden arms tear it loose onto the floor — and the ward's owner gets their window", () => {
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob", "cara"], seed, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
while (activePlayer(state).id !== "alice") {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const alice = state.players.find((p) => p.id === "alice")!;
|
||||
const bob = state.players.find((p) => p.id === "bob")!;
|
||||
bob.position = { ...alice.position };
|
||||
// Alice already hauls her own gold; Bob carries CARA's — and Cara
|
||||
// holds a WARD over it.
|
||||
const mine = state.treasures.find((t) => t.owner === "alice")!;
|
||||
mine.carriedBy = "alice";
|
||||
mine.position = null;
|
||||
alice.carriedTreasureId = mine.id;
|
||||
const caras = state.treasures.find((t) => t.owner === "cara")!;
|
||||
caras.carriedBy = "bob";
|
||||
caras.position = null;
|
||||
bob.carriedTreasureId = caras.id;
|
||||
giveCard(state, "cara", "ward", "W", 0);
|
||||
const st = giveCard(state, "alice", "strength");
|
||||
giveCard(state, "alice", "number-2", "N", 1);
|
||||
state = must(state, "alice", {
|
||||
type: "cast", instanceId: st.instanceId, numberInstanceIds: ["number-2#N"],
|
||||
});
|
||||
let r = applyCommand(state, "alice", { type: "tearTreasure", targetId: "bob" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// Rev 6: the grab waits out its counteraction window first.
|
||||
r = applyCommand(r.state, "bob", { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const after = r.state.treasures.find((t) => t.id === caras.id)!;
|
||||
if (after.carriedBy === "bob") continue; // Bob rolled his 1 — try again
|
||||
// Torn loose: Alice's arms are full, so it lands at her feet…
|
||||
expect(after.position).toEqual(alice.position);
|
||||
expect(r.state.players.find((p) => p.id === "alice")!.carriedTreasureId).toBe(mine.id);
|
||||
// …and the seizure hangs on Cara's ward.
|
||||
expect(r.state.wardPending).toEqual({ ownerId: "cara", takerId: "alice" });
|
||||
return;
|
||||
}
|
||||
throw new Error("every seed rolled a 1 — the rig is wrong");
|
||||
});
|
||||
});
|
||||
|
||||
describe("swap meet trades carried items", () => {
|
||||
function rig() {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sm = giveCard(state, attacker, "swap-meet");
|
||||
giveCard(state, attacker, "dagger", "D", 1);
|
||||
giveCard(state, defender, "blaster-wand", "W", 0);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sm.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: "dagger;blaster-wand" },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
return { state, attacker, defender };
|
||||
}
|
||||
|
||||
it("a dagger trades for a wand — both are carried items", () => {
|
||||
const { state, attacker, defender } = rig();
|
||||
expect(state.players.find((p) => p.id === attacker)!.hand.some((c) => c.cardId === "blaster-wand")).toBe(true);
|
||||
expect(state.players.find((p) => p.id === defender)!.hand.some((c) => c.cardId === "dagger")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("swap meet trades treasures too", () => {
|
||||
function treasureRig(theirsToken: string, mineToken: string) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
// The defender hauls one of the attacker's own treasures.
|
||||
const stolen = state.treasures.find((t) => t.owner === attacker)!;
|
||||
stolen.position = null; stolen.carriedBy = defender; d.carriedTreasureId = stolen.id;
|
||||
const sm = giveCard(state, attacker, "swap-meet");
|
||||
giveCard(state, attacker, "dagger", "D", 1);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sm.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: `${mineToken};${theirsToken}` },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
return { state, attacker, defender, a, d, stolen };
|
||||
}
|
||||
|
||||
it("a dagger buys back the treasure in the thief's arms", () => {
|
||||
const { state, attacker, defender } = treasureRig("treasure", "dagger");
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const t = state.treasures.find((tr) => tr.owner === attacker && tr.carriedBy)!;
|
||||
expect(a.carriedTreasureId).toBe(t.id);
|
||||
expect(t.carriedBy).toBe(attacker);
|
||||
expect(d.carriedTreasureId).toBeNull();
|
||||
expect(d.hand.some((c) => c.cardId === "dagger")).toBe(true);
|
||||
});
|
||||
|
||||
it("the trade refuses to overload full arms", () => {
|
||||
// The attacker also carries a treasure: claiming theirs with a dagger
|
||||
// would mean two in hand — the swap quietly cannot happen.
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const t1 = state.treasures.find((t) => t.owner === attacker)!;
|
||||
t1.position = null; t1.carriedBy = attacker; a.carriedTreasureId = t1.id;
|
||||
const t2 = state.treasures.find((t) => t.owner === defender)!;
|
||||
t2.position = null; t2.carriedBy = defender; d.carriedTreasureId = t2.id;
|
||||
const sm = giveCard(state, attacker, "swap-meet");
|
||||
giveCard(state, attacker, "dagger", "D", 1);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sm.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: "dagger;treasure" },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === attacker)!.carriedTreasureId).toBe(t1.id);
|
||||
expect(state.players.find((p) => p.id === defender)!.carriedTreasureId).toBe(t2.id);
|
||||
});
|
||||
|
||||
it("treasure for treasure trades both armfuls", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const t1 = state.treasures.find((t) => t.owner === attacker)!;
|
||||
t1.position = null; t1.carriedBy = attacker; a.carriedTreasureId = t1.id;
|
||||
const t2 = state.treasures.find((t) => t.owner === defender)!;
|
||||
t2.position = null; t2.carriedBy = defender; d.carriedTreasureId = t2.id;
|
||||
const sm = giveCard(state, attacker, "swap-meet");
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sm.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: "treasure;treasure" },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === attacker)!.carriedTreasureId).toBe(t2.id);
|
||||
expect(state.players.find((p) => p.id === defender)!.carriedTreasureId).toBe(t1.id);
|
||||
expect(state.treasures.find((t) => t.id === t1.id)!.carriedBy).toBe(defender);
|
||||
expect(state.treasures.find((t) => t.id === t2.id)!.carriedBy).toBe(attacker);
|
||||
});
|
||||
});
|
||||
|
||||
describe("full reflection hands the swap meet choice to the reflector", () => {
|
||||
function reflectedSwapRig(reflectorChoice?: string) {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
// The caster carries a treasure and offers a dagger; the reflector may
|
||||
// instead demand the trade of their own choosing.
|
||||
const t = state.treasures.find((t) => t.owner === attacker)!;
|
||||
t.position = null; t.carriedBy = attacker; a.carriedTreasureId = t.id;
|
||||
const sm = giveCard(state, attacker, "swap-meet");
|
||||
giveCard(state, attacker, "dagger", "D", 1);
|
||||
giveCard(state, defender, "full-reflection", "FR", 0);
|
||||
giveCard(state, defender, "large-rock", "R", 1);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: sm.instanceId,
|
||||
target: { kind: "player", playerId: defender },
|
||||
params: { cardId: "dagger;large-rock" },
|
||||
});
|
||||
state = must(state, defender, {
|
||||
type: "counteract", instanceId: "full-reflection#FR",
|
||||
...(reflectorChoice ? { params: { cardId: reflectorChoice } } : {}),
|
||||
});
|
||||
state = must(state, attacker, { type: "pass" });
|
||||
return { state, attacker, defender, treasureId: t.id };
|
||||
}
|
||||
|
||||
it("the reflector rewrites the trade: their rock for the caster's treasure", () => {
|
||||
const { state, attacker, defender, treasureId } = reflectedSwapRig("large-rock;treasure");
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
expect(d.carriedTreasureId).toBe(treasureId);
|
||||
expect(state.players.find((p) => p.id === attacker)!.hand.some((c) => c.cardId === "large-rock")).toBe(true);
|
||||
expect(state.players.find((p) => p.id === attacker)!.carriedTreasureId).toBeNull();
|
||||
});
|
||||
|
||||
it("the reflector may decline: 'none' trades nothing", () => {
|
||||
const { state, attacker, defender, treasureId } = reflectedSwapRig("none");
|
||||
expect(state.players.find((p) => p.id === attacker)!.carriedTreasureId).toBe(treasureId);
|
||||
expect(state.players.find((p) => p.id === defender)!.hand.some((c) => c.cardId === "large-rock")).toBe(true);
|
||||
});
|
||||
|
||||
it("a bare full reflection with no choice trades nothing", () => {
|
||||
const { state, attacker } = reflectedSwapRig(undefined);
|
||||
expect(state.players.find((p) => p.id === attacker)!.hand.some((c) => c.cardId === "dagger")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("go away routs around walls", () => {
|
||||
it("a victim against a wall bends the line instead of standing still", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const a = state.players.find((p) => p.id === attacker)!;
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
// Attacker west of the victim, a wall hard against the victim's east:
|
||||
// the straight line away is blocked from the first step.
|
||||
a.position = { x: 1, y: 5 };
|
||||
d.position = { x: 2, y: 5 };
|
||||
state.edgeOverrides[edgeKey({ x: 1, y: 5 }, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 5 }, "E")] = "wall";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 5 }, "N")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 5 }, "S")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 4 }, "N")] = "open";
|
||||
state.edgeOverrides[edgeKey({ x: 2, y: 6 }, "S")] = "open";
|
||||
const ga = giveCard(state, attacker, "go-away");
|
||||
giveCard(state, attacker, "number-3", "N3", 1);
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: ga.instanceId, numberInstanceIds: ["number-3#N3"],
|
||||
target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
const after = state.players.find((p) => p.id === defender)!;
|
||||
const dist = Math.abs(after.position.x - 1) + Math.abs(after.position.y - 5);
|
||||
// Three routed spaces: strictly farther than where they stood.
|
||||
expect(dist).toBeGreaterThanOrEqual(3);
|
||||
expect(after.lostTurns).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the goat charges on legs, not wings (rev 10)", () => {
|
||||
it("the charge walks real corridors: in reach it spends legs, beyond them it is refused", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const attacker = activePlayer(state);
|
||||
const defender = state.players.find((p) => p.id !== attacker.id)!;
|
||||
const bh = giveCard(state, attacker.id, "butt-head");
|
||||
// The engine is the oracle: every other square is either within the
|
||||
// turn's legal movement or beyond it, and this maze holds both kinds.
|
||||
let refusals = 0;
|
||||
let rams = 0;
|
||||
for (const key of Object.keys(boardView(state).cells)) {
|
||||
if (key === cellKey(attacker.position)) continue;
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
defender.position = { x, y };
|
||||
const r = applyCommand(state, attacker.id, {
|
||||
type: "cast", instanceId: bh.instanceId, target: { kind: "player", playerId: defender.id },
|
||||
});
|
||||
if (!r.ok) {
|
||||
if (/legs, not wings/.test(r.error)) refusals += 1;
|
||||
continue;
|
||||
}
|
||||
const st = drain(r.state);
|
||||
const a = st.players.find((p) => p.id === attacker.id)!;
|
||||
expect(a.position).toEqual(st.players.find((p) => p.id === defender.id)!.position);
|
||||
expect(st.turn.movementUsed).toBeGreaterThan(0);
|
||||
rams += 1;
|
||||
}
|
||||
expect(refusals).toBeGreaterThan(0);
|
||||
expect(rams).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, gameLos } from "../src/game";
|
||||
import { cellKey, SIDES, stepTarget, type Cell } from "../src/board";
|
||||
import { applyCommand, activePlayer, boardView, createGame, gameLos } from "../src/game";
|
||||
import { cellKey, edgeKey, SIDES, stepTarget, type Cell, type Side } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { eligibleCellsFor, sightedCellsFor, viewFor } from "../src/view";
|
||||
import { newExpansionGame as newGame, must, giveCard, emptyNeighborCell } from "./helpers";
|
||||
import { newExpansionGame as newGame, must, giveCard, emptyNeighborCell, plainRimWall } from "./helpers";
|
||||
|
||||
describe("expansion terrain", () => {
|
||||
it("killer ooze burns on entry and can drop you on your face", () => {
|
||||
@@ -161,6 +161,136 @@ describe("expansion terrain", () => {
|
||||
expect(state.squareContents[cellKey(spot.cell)]).toBeUndefined();
|
||||
// Wave side effects vary by geometry; the melt itself is the pinned behavior.
|
||||
});
|
||||
|
||||
it("wall of fire takes a rim warp — both mouths burn the crossing", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const warp = state.board.warps[0]!;
|
||||
me.position = { ...warp.from.cell };
|
||||
const wof = giveCard(state, me.id, "wall-of-fire", "WF", 0);
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: wof.instanceId,
|
||||
target: { kind: "edge", cell: warp.from.cell, side: warp.from.side },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
const nearKey = edgeKey(warp.from.cell, warp.from.side);
|
||||
const farKey = edgeKey(warp.to.cell, warp.to.side);
|
||||
expect(boardView(state).edges[nearKey]).toBe("firewall");
|
||||
expect(boardView(state).edges[farKey]).toBe("firewall");
|
||||
// The corridor still runs — through flame: the crossing lands on the
|
||||
// far rim and burns for 4.
|
||||
state = must(state, me.id, { type: "move", direction: warp.from.side });
|
||||
const after = state.players.find((p) => p.id === me.id)!;
|
||||
expect(cellKey(after.position)).toBe(cellKey(warp.to.cell));
|
||||
expect(after.life).toBe(11);
|
||||
});
|
||||
|
||||
it("waterwall takes a rim warp — the collapse washes both rims", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const other = state.players.find((p) => p.id !== me.id)!;
|
||||
const warp = state.board.warps[0]!;
|
||||
me.position = { ...warp.from.cell };
|
||||
other.position = { ...warp.to.cell };
|
||||
const ww = giveCard(state, me.id, "waterwall", "WW", 0);
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: ww.instanceId,
|
||||
target: { kind: "edge", cell: warp.from.cell, side: warp.from.side },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// Both wizards stood in the mouths; the collapse washed both inward.
|
||||
const meAfter = r.state.players.find((p) => p.id === me.id)!;
|
||||
const otherAfter = r.state.players.find((p) => p.id === other.id)!;
|
||||
expect(cellKey(meAfter.position)).not.toBe(cellKey(warp.from.cell));
|
||||
expect(cellKey(otherAfter.position)).not.toBe(cellKey(warp.to.cell));
|
||||
});
|
||||
|
||||
it("illusion wall hangs on a rim warp mouth", () => {
|
||||
const { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const warp = state.board.warps[0]!;
|
||||
me.position = { ...warp.from.cell };
|
||||
const il = giveCard(state, me.id, "illusion-wall", "IL", 0);
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: il.instanceId,
|
||||
target: { kind: "edge", cell: warp.from.cell, side: warp.from.side },
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (r.ok) {
|
||||
expect(r.state.illusionWalls[edgeKey(warp.from.cell, warp.from.side)]).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("stone to water breaches the outer rim, opening a warp", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const rim = plainRimWall(state);
|
||||
me.position = { ...rim.cell };
|
||||
const warpsBefore = state.board.warps.length;
|
||||
const stw = giveCard(state, me.id, "stone-to-water", "SW", 0);
|
||||
state = must(state, me.id, {
|
||||
type: "cast", instanceId: stw.instanceId,
|
||||
target: { kind: "edge", cell: rim.cell, side: rim.side },
|
||||
});
|
||||
// The far rim melted with it and the wraparound now runs.
|
||||
expect(state.board.warps.length).toBe(warpsBefore + 2);
|
||||
});
|
||||
|
||||
it("no doors through the rim", () => {
|
||||
const { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const rim = plainRimWall(state);
|
||||
me.position = { ...rim.cell };
|
||||
const cd = giveCard(state, me.id, "create-door", "CD", 0);
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: cd.instanceId,
|
||||
target: { kind: "edge", cell: rim.cell, side: rim.side },
|
||||
});
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("stone to water melts a door — a small entryway in a stone wall", () => {
|
||||
const { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const board = boardView(state);
|
||||
// Stand the caster at some door and melt it point-blank.
|
||||
let doorAt: { cell: Cell; side: Side } | null = null;
|
||||
outer: for (const k of Object.keys(board.cells)) {
|
||||
const [x, y] = k.split(",").map(Number) as [number, number];
|
||||
for (const side of SIDES) {
|
||||
if (board.edges[edgeKey({ x, y }, side)] === "door") {
|
||||
doorAt = { cell: { x, y }, side };
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!doorAt) throw new Error("setup: no door on this board");
|
||||
me.position = { ...doorAt.cell };
|
||||
const stw = giveCard(state, me.id, "stone-to-water", "SW", 0);
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: stw.instanceId,
|
||||
target: { kind: "edge", cell: doorAt.cell, side: doorAt.side },
|
||||
});
|
||||
expect(r.ok).toBe(true);
|
||||
if (r.ok) {
|
||||
const key = edgeKey(doorAt.cell, doorAt.side);
|
||||
expect(boardView(r.state).edges[key] ?? "open").toBe("open");
|
||||
expect(r.state.doorStates[key]).toBeUndefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("eligibility dimming mirrors the engine", () => {
|
||||
@@ -212,3 +342,116 @@ describe("eligibility dimming mirrors the engine", () => {
|
||||
for (const k of lit) expect(seen.has(k)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a wave's force is spent as it travels", () => {
|
||||
/** Caster at B, one cell above A; the target wall is A's south edge, so
|
||||
* the range-2 wave covers A (dist 0) and B (dist 1). */
|
||||
function rig(behind: "open" | "wall") {
|
||||
const { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
const me = activePlayer(state);
|
||||
const A = { x: 4, y: 5 }, B = { x: 4, y: 4 }, Bn = { x: 4, y: 3 }, Bnn = { x: 4, y: 2 };
|
||||
for (const c of [A, B, Bn, Bnn]) expect(boardView(state).cells[cellKey(c)]).toBeTruthy();
|
||||
state.edgeOverrides[edgeKey(A, "S")] = "wall";
|
||||
state.edgeOverrides[edgeKey(A, "N")] = "open";
|
||||
state.edgeOverrides[edgeKey(B, "N")] = behind;
|
||||
state.edgeOverrides[edgeKey(Bn, "N")] = "open";
|
||||
me.position = { ...B };
|
||||
// The other wizard waits far outside the wave.
|
||||
state.players.find((p) => p.id !== me.id)!.position = { x: 0, y: 9 };
|
||||
const stw = giveCard(state, me.id, "stone-to-water", "SW", 0);
|
||||
const after = must(state, me.id, {
|
||||
type: "cast", instanceId: stw.instanceId, target: { kind: "edge", cell: A, side: "S" },
|
||||
});
|
||||
return { me: after.players.find((p) => p.id === me.id)!, B, Bn, Bnn };
|
||||
}
|
||||
|
||||
it("a victim at the wave's far edge is carried one space, unhurt", () => {
|
||||
const { me, Bn } = rig("open");
|
||||
expect(cellKey(me.position)).toBe(cellKey(Bn));
|
||||
expect(me.life).toBe(15);
|
||||
});
|
||||
|
||||
it("only unspent force crushes: one space of push blocked is one damage", () => {
|
||||
const { me, B } = rig("wall");
|
||||
expect(cellKey(me.position)).toBe(cellKey(B));
|
||||
expect(me.life).toBe(14);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("boobytrap decoys die their own deaths", () => {
|
||||
it("a stepped-on blank token vanishes alone; the real one still waits", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const enemy = state.players.find((p) => p.id !== me.id)!;
|
||||
const view = boardView(state);
|
||||
const open: Cell[] = [];
|
||||
for (const key of Object.keys(view.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
if (state.squareContents[key]) continue;
|
||||
open.push({ x, y });
|
||||
if (open.length === 4) break;
|
||||
}
|
||||
const bt = giveCard(state, me.id, "boobytrap");
|
||||
state = must(state, me.id, {
|
||||
type: "cast", instanceId: bt.instanceId, params: { cells: open },
|
||||
});
|
||||
state = must(state, me.id, { type: "endTurn", draw: 0 });
|
||||
// The enemy steps onto a BLANK (open[1] — the real trap is open[0]).
|
||||
const e = state.players.find((p) => p.id === enemy.id)!;
|
||||
const blank = open[1]!;
|
||||
for (const side of SIDES) {
|
||||
const from = { x: blank.x + (side === "E" ? -1 : side === "W" ? 1 : 0),
|
||||
y: blank.y + (side === "S" ? -1 : side === "N" ? 1 : 0) };
|
||||
if (!view.cells[cellKey(from)]) continue;
|
||||
const t = stepTarget(view, from, side);
|
||||
if (t.kind === "step" && cellKey(t.to) === cellKey(blank)) {
|
||||
e.position = from;
|
||||
const before = e.life;
|
||||
const r = applyCommand(state, enemy.id, { type: "move", direction: side });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(r.events.some((ev) => ev.type === "boobytrapBlank")).toBe(true);
|
||||
const after = state.players.find((p) => p.id === enemy.id)!;
|
||||
expect(after.life).toBe(before);
|
||||
const trap = state.boobytraps[0]!;
|
||||
expect(trap.cells.length).toBe(3);
|
||||
expect(trap.cells.some((c) => cellKey(c) === cellKey(blank))).toBe(false);
|
||||
expect(trap.realKey).toBe(cellKey(open[0]!));
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new Error("setup: no approach to the blank token");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the boobytrap keeps its secret", () => {
|
||||
it("stored and broadcast cells are canonically ordered — position tells nothing", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const view = boardView(state);
|
||||
const open: Cell[] = [];
|
||||
for (const key of Object.keys(view.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
if (state.squareContents[key]) continue;
|
||||
open.push({ x, y });
|
||||
if (open.length === 4) break;
|
||||
}
|
||||
// Cast with the REAL trap deliberately last-sorting: reverse order.
|
||||
const reversed = [...open].reverse();
|
||||
const bt = giveCard(state, me.id, "boobytrap");
|
||||
const r = applyCommand(state, me.id, {
|
||||
type: "cast", instanceId: bt.instanceId, params: { cells: reversed },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
const trap = r.state.boobytraps[0]!;
|
||||
const keys = trap.cells.map((c) => cellKey(c));
|
||||
expect([...keys].sort()).toEqual(keys); // canonical order, not casting order
|
||||
expect(trap.realKey).toBe(cellKey(reversed[0]!)); // the truth survives aside
|
||||
const placed = r.events.find((e) => e.type === "boobytrapPlaced");
|
||||
if (placed?.type === "boobytrapPlaced") {
|
||||
const evKeys = placed.cells.map((c) => cellKey(c));
|
||||
expect([...evKeys].sort()).toEqual(evKeys);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { drain, giveCard } from "./helpers";
|
||||
import { edgeKey } from "../src/board";
|
||||
import {
|
||||
applyCommand,
|
||||
activePlayer,
|
||||
@@ -224,3 +226,146 @@ describe("treasures and victory", () => {
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("elimination by lost treasures drops what the fallen carried", () => {
|
||||
it("the carried treasure lands where the wizard stood", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b", "c"], seed: 42, sets: ["basic"] });
|
||||
const A = state.players.find((p) => p.id === "a")!;
|
||||
const B = state.players.find((p) => p.id === "b")!;
|
||||
const C = state.players.find((p) => p.id === "c")!;
|
||||
// C's first treasure already sits captured on B's home...
|
||||
const c1 = state.treasures.filter((t) => t.owner === "c")[0]!;
|
||||
c1.position = { ...B.home };
|
||||
// ...C carries one of B's treasures...
|
||||
const bt = state.treasures.filter((t) => t.owner === "b")[0]!;
|
||||
bt.position = null;
|
||||
bt.carriedBy = "c";
|
||||
C.carriedTreasureId = bt.id;
|
||||
// ...and A, standing on their own home, drops C's second treasure there.
|
||||
const c2 = state.treasures.filter((t) => t.owner === "c")[1]!;
|
||||
c2.position = null;
|
||||
c2.carriedBy = "a";
|
||||
A.carriedTreasureId = c2.id;
|
||||
A.position = { ...A.home };
|
||||
while (state.players[state.turn.activeIndex]!.id !== "a") {
|
||||
const r = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const r = applyCommand(state, "a", { type: "dropTreasure" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
// C is eliminated by lost treasures — and B's treasure lies where C stood.
|
||||
const cAfter = state.players.find((p) => p.id === "c")!;
|
||||
expect(cAfter.alive).toBe(false);
|
||||
expect(cAfter.carriedTreasureId).toBeNull();
|
||||
const btAfter = state.treasures.find((t) => t.id === bt.id)!;
|
||||
expect(btAfter.carriedBy).toBeNull();
|
||||
expect(btAfter.position).toEqual(cAfter.position);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the Ward is played in the moment", () => {
|
||||
function grabRig() {
|
||||
let { state } = createGame({ playerIds: ["thief", "owner"], seed: 42, sets: ["basic"] });
|
||||
const thief = state.players.find((p) => p.id === "thief")!;
|
||||
const owner = state.players.find((p) => p.id === "owner")!;
|
||||
giveCard(state, "owner", "ward", "W", 0);
|
||||
const t = state.treasures.find((t) => t.owner === "owner" && t.position)!;
|
||||
thief.position = { ...t.position! };
|
||||
while (state.players[state.turn.activeIndex]!.id !== "thief") {
|
||||
const r = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const r = applyCommand(state, "thief", { type: "pickUpTreasure" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
return { state: r.state, owner, thief };
|
||||
}
|
||||
|
||||
it("the grab hangs on the owner; springing costs the thief 3 and the card", () => {
|
||||
let { state } = grabRig();
|
||||
expect(state.wardPending).toEqual({ ownerId: "owner", takerId: "thief" });
|
||||
// Nobody else may act while it hangs.
|
||||
expect(applyCommand(state, "thief", { type: "endTurn", draw: 0 }).ok).toBe(false);
|
||||
const r = applyCommand(state, "owner", { type: "wardChoice", play: true });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
// The bite rides the stack: a counteraction window opens for the thief.
|
||||
expect(r.state.stack).toBeTruthy();
|
||||
const bite = applyCommand(r.state, r.state.stack!.waitingOn, { type: "pass" });
|
||||
if (!bite.ok) throw new Error(bite.error);
|
||||
// The chronicle names the bite for what it is, not a punch.
|
||||
expect(bite.events.some(
|
||||
(e) => e.type === "damaged" && e.source === "warded treasure",
|
||||
)).toBe(true);
|
||||
state = drain(bite.state);
|
||||
expect(state.wardPending).toBeNull();
|
||||
expect(state.players.find((p) => p.id === "thief")!.life).toBe(12);
|
||||
expect(state.players.find((p) => p.id === "owner")!.hand.some((c) => c.cardId === "ward")).toBe(false);
|
||||
});
|
||||
|
||||
it("declining lets the thief go, Ward still in hand", () => {
|
||||
let { state } = grabRig();
|
||||
const r = applyCommand(state, "owner", { type: "wardChoice", play: false });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.players.find((p) => p.id === "thief")!.life).toBe(15);
|
||||
expect(state.players.find((p) => p.id === "owner")!.hand.some((c) => c.cardId === "ward")).toBe(true);
|
||||
expect(applyCommand(state, "thief", { type: "endTurn", draw: 0 }).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("arming ahead is refused — the ward waits for the grab", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
giveCard(state, state.players[state.turn.activeIndex]!.id, "ward", "W", 0);
|
||||
const r = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "armWard" });
|
||||
expect(r.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("an ambushed teleport carries its destination", () => {
|
||||
it("the trap springs and the victim lands where the trapper said", () => {
|
||||
let { state } = createGame({ playerIds: ["trapper", "prey"], seed: 42, sets: ["basic", "expansion1"] });
|
||||
for (let guard = 0; guard < 10 && !(state.players[state.turn.activeIndex]!.id === "trapper" && state.turn.round > 1); guard++) {
|
||||
const r = applyCommand(state, state.players[state.turn.activeIndex]!.id, { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
}
|
||||
const trapper = state.players.find((p) => p.id === "trapper")!;
|
||||
const prey = state.players.find((p) => p.id === "prey")!;
|
||||
giveCard(state, "trapper", "interrupt", "I", 0);
|
||||
giveCard(state, "trapper", "teleport-opponent", "TO", 1);
|
||||
// Arming without a destination is refused; with one it is stored.
|
||||
const bad = applyCommand(state, "trapper", {
|
||||
type: "setAmbush", instanceId: "interrupt#I", trigger: { kind: "near" },
|
||||
spellInstanceId: "teleport-opponent#TO",
|
||||
});
|
||||
expect(bad.ok).toBe(false);
|
||||
const dest = { x: trapper.home.x, y: trapper.home.y === 0 ? 1 : trapper.home.y - 1 };
|
||||
let r = applyCommand(state, "trapper", {
|
||||
type: "setAmbush", instanceId: "interrupt#I", trigger: { kind: "near" },
|
||||
spellInstanceId: "teleport-opponent#TO", cell: dest,
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
r = applyCommand(state, "trapper", { type: "endTurn", draw: 0 });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
// The prey walks adjacent; the trap springs; the prey passes; they land
|
||||
// at dest. (Re-find both: applyCommand clones made the handles stale.)
|
||||
const trapperNow = state.players.find((p) => p.id === "trapper")!;
|
||||
const preyNow = state.players.find((p) => p.id === "prey")!;
|
||||
const below = trapperNow.position.y >= 2;
|
||||
preyNow.position = { x: trapperNow.position.x, y: trapperNow.position.y + (below ? -2 : 2) };
|
||||
const dir = below ? "S" : "N";
|
||||
state.edgeOverrides[edgeKey(preyNow.position, dir)] = "open";
|
||||
r = applyCommand(state, "prey", { type: "move", direction: dir });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.stack?.attackCard?.cardId).toBe("teleport-opponent");
|
||||
expect(state.stack?.params?.cell).toEqual(dest);
|
||||
r = applyCommand(state, "prey", { type: "pass" });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = r.state;
|
||||
expect(state.players.find((p) => p.id === "prey")!.position).toEqual(dest);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,8 +11,9 @@ import {
|
||||
type GameState,
|
||||
type PlayerId,
|
||||
} from "../src/game";
|
||||
import { cellKey, SIDES, stepTarget, type Cell, type Side } from "../src/board";
|
||||
import { cellKey, edgeKey, neighbor, SIDES, stepTarget, type Cell, type Side } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import type { SustainedEffect } from "../src/game";
|
||||
|
||||
export function newGame(seed = 42, players: PlayerId[] = ["alice", "bob"]) {
|
||||
return createGame({ playerIds: players, seed, sets: ["basic"] });
|
||||
@@ -28,6 +29,14 @@ export function must(state: GameState, player: PlayerId, command: Command): Game
|
||||
return result.state;
|
||||
}
|
||||
|
||||
/** Wave every pending counteraction window through unanswered. */
|
||||
export function drain(state: GameState): GameState {
|
||||
while (state.stack) {
|
||||
state = must(state, state.stack.waitingOn, { type: "pass" });
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
export function giveCard(state: GameState, playerId: PlayerId, cardId: string, tag = "T", slot = 0): CardInstance {
|
||||
const p = state.players.find((p) => p.id === playerId)!;
|
||||
const instance = { instanceId: `${cardId}#${tag}`, cardId };
|
||||
@@ -76,3 +85,26 @@ export function emptyNeighborCell(state: GameState, of: Cell): { cell: Cell; sid
|
||||
}
|
||||
throw new Error("no empty neighbor");
|
||||
}
|
||||
|
||||
/** Some off-board edge that is a bare stone wall — no warp behind it. */
|
||||
export function plainRimWall(state: GameState): { cell: Cell; side: Side } {
|
||||
const board = boardView(state);
|
||||
for (const k of Object.keys(board.cells)) {
|
||||
const [x, y] = k.split(",").map(Number) as [number, number];
|
||||
for (const side of SIDES) {
|
||||
if (board.cells[cellKey(neighbor({ x, y }, side))]) continue;
|
||||
if (board.edges[edgeKey({ x, y }, side)] !== "wall") continue;
|
||||
if (board.warps.some((w) => cellKey(w.from.cell) === k && w.from.side === side)) continue;
|
||||
return { cell: { x, y }, side };
|
||||
}
|
||||
}
|
||||
throw new Error("setup: no plain rim wall on this board");
|
||||
}
|
||||
|
||||
/** Rig a duration spell directly, sparing the cast ceremony. */
|
||||
export function pushSustained(
|
||||
state: GameState,
|
||||
fx: Omit<SustainedEffect, "data"> & { data?: SustainedEffect["data"] },
|
||||
): void {
|
||||
state.sustained.push({ data: {}, ...fx });
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, createGame, gameLos, sustainedOn, viewFor } from "../src";
|
||||
import { cellKey, edgeKey, type Cell } from "../src/board";
|
||||
import { cellKey, edgeKey, hasLineOfSight, sightBetween, traceSight, type Cell } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newGame, must, giveCard, toRound2, emptyNeighborCell } from "./helpers";
|
||||
import { newGame, newExpansionGame, must, giveCard, toRound2, emptyNeighborCell } from "./helpers";
|
||||
|
||||
describe("around the corner", () => {
|
||||
it("bends line of sight past a wall that blocks a straight cast", () => {
|
||||
@@ -44,6 +44,130 @@ describe("around the corner", () => {
|
||||
state = must(state, defender.id, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender.id)!.life).toBe(10);
|
||||
});
|
||||
|
||||
it("hairpins 180 degrees around a wall's end — the pivot sits in the gap", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const attacker = activePlayer(state);
|
||||
const defender = state.players.find((p) => p.id !== attacker.id)!;
|
||||
const view0 = boardView(state);
|
||||
// Carve a 2x2 block: attacker at A, defender at C directly north behind a
|
||||
// wall that ends beside the B/D gap. C is sealed on every other side, so
|
||||
// no cell-centered bend reaches it — only the pivot in the gap itself.
|
||||
// +---+---+ C = target D = gap's far cell
|
||||
// # C D # A = caster B = gap's near cell
|
||||
// +###+ +
|
||||
// A B
|
||||
let A: Cell | null = null;
|
||||
for (const k of Object.keys(view0.cells)) {
|
||||
const [x, y] = k.split(",").map(Number) as [number, number];
|
||||
if (view0.cells[`${x + 1},${y}`] && view0.cells[`${x},${y - 1}`] && view0.cells[`${x + 1},${y - 1}`]) {
|
||||
A = { x, y };
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(A).not.toBeNull();
|
||||
const B = { x: A!.x + 1, y: A!.y };
|
||||
const C = { x: A!.x, y: A!.y - 1 };
|
||||
const D = { x: A!.x + 1, y: A!.y - 1 };
|
||||
state.edgeOverrides[edgeKey(A!, "N")] = "wall"; // the wall to double back around
|
||||
state.edgeOverrides[edgeKey(A!, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey(B, "N")] = "open"; // the gap past the wall's end
|
||||
state.edgeOverrides[edgeKey(C, "E")] = "open";
|
||||
state.edgeOverrides[edgeKey(C, "N")] = "wall";
|
||||
state.edgeOverrides[edgeKey(C, "W")] = "wall";
|
||||
state.edgeOverrides[edgeKey(D, "E")] = "wall";
|
||||
attacker.position = { ...A! };
|
||||
defender.position = { ...C };
|
||||
|
||||
const fb = giveCard(state, attacker.id, "fireball", "F", 0);
|
||||
giveCard(state, attacker.id, "around-the-corner", "ATC", 1);
|
||||
const straight = applyCommand(state, attacker.id, {
|
||||
type: "cast", instanceId: fb.instanceId, target: { kind: "player", playerId: defender.id },
|
||||
});
|
||||
expect(straight.ok).toBe(false);
|
||||
|
||||
const lifeBefore = defender.life;
|
||||
state = must(state, attacker.id, {
|
||||
type: "cast", instanceId: fb.instanceId, aroundCornerInstanceId: "around-the-corner#ATC",
|
||||
target: { kind: "player", playerId: defender.id },
|
||||
});
|
||||
state = must(state, defender.id, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender.id)!.life).toBeLessThan(lifeBefore);
|
||||
});
|
||||
|
||||
// A cell out of straight sight but reachable with one bend, clear enough
|
||||
// to create on: no contents, home, wizard, treasure, object, or warp.
|
||||
function hiddenEmptyCell(state: ReturnType<typeof newGame>["state"]): Cell {
|
||||
const caster = activePlayer(state);
|
||||
const view = boardView(state);
|
||||
for (const key of Object.keys(view.cells)) {
|
||||
const [x, y] = key.split(",").map(Number) as [number, number];
|
||||
const cell = { x, y };
|
||||
if (gameLos(state, caster.position, cell, caster.id)) continue;
|
||||
if (state.squareContents[key]) continue;
|
||||
if (view.homes.some((h) => cellKey(h) === key)) continue;
|
||||
if (state.players.some((p) => p.alive && cellKey(p.position) === key)) continue;
|
||||
if (state.treasures.some((t) => t.position && cellKey(t.position) === key)) continue;
|
||||
if ((state.groundObjects[key] ?? []).length > 0) continue;
|
||||
for (const midKey of Object.keys(view.cells)) {
|
||||
const [mx, my] = midKey.split(",").map(Number) as [number, number];
|
||||
const mid = { x: mx, y: my };
|
||||
if (gameLos(state, caster.position, mid, caster.id) && gameLos(state, mid, cell, caster.id)) {
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error("no hidden-but-bendable cell on this board");
|
||||
}
|
||||
|
||||
it("bends a neutral spell too — SAFE locks up a treasure around the corner", () => {
|
||||
let { state } = newExpansionGame();
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
const hidden = hiddenEmptyCell(state);
|
||||
const gold = state.treasures.find((t) => t.position)!;
|
||||
gold.position = { ...hidden };
|
||||
|
||||
const safe = giveCard(state, caster.id, "safe", "S", 0);
|
||||
giveCard(state, caster.id, "around-the-corner", "ATC", 1);
|
||||
const straight = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: safe.instanceId, target: { kind: "cell", cell: hidden },
|
||||
});
|
||||
expect(straight.ok).toBe(false);
|
||||
if (!straight.ok) expect(straight.error).toBe("no line of sight");
|
||||
|
||||
const bent = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: safe.instanceId, aroundCornerInstanceId: "around-the-corner#ATC",
|
||||
target: { kind: "cell", cell: hidden },
|
||||
});
|
||||
if (!bent.ok) throw new Error(`bent SAFE refused: ${bent.error}`);
|
||||
expect(bent.state.squareContents[cellKey(hidden)]?.kind).toBe("safe");
|
||||
expect(bent.events.some((e) => e.type === "castAroundCorner")).toBe(true);
|
||||
// Both cards spent: the bend is not free.
|
||||
const after = bent.state.players.find((p) => p.id === caster.id)!;
|
||||
expect(after.hand.some((c) => c?.cardId === "around-the-corner")).toBe(false);
|
||||
});
|
||||
|
||||
it("bends a creation — THORNBUSH grows on a square out of straight sight", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
const hidden = hiddenEmptyCell(state);
|
||||
|
||||
const bush = giveCard(state, caster.id, "thornbush", "TB", 0);
|
||||
giveCard(state, caster.id, "around-the-corner", "ATC", 1);
|
||||
const straight = applyCommand(state, caster.id, {
|
||||
type: "cast", instanceId: bush.instanceId, target: { kind: "cell", cell: hidden },
|
||||
});
|
||||
expect(straight.ok).toBe(false);
|
||||
|
||||
state = must(state, caster.id, {
|
||||
type: "cast", instanceId: bush.instanceId, aroundCornerInstanceId: "around-the-corner#ATC",
|
||||
target: { kind: "cell", cell: hidden },
|
||||
});
|
||||
expect(state.squareContents[cellKey(hidden)]?.kind).toBe("thornbush");
|
||||
});
|
||||
});
|
||||
|
||||
describe("blind", () => {
|
||||
@@ -143,13 +267,16 @@ describe("illusion wall", () => {
|
||||
expect(after.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("opponents test the illusion when they bump it — some see through, some believe", () => {
|
||||
it("an untested illusion blocks the bump; a tested eye rolls its verdict", () => {
|
||||
let believed = 0, sawThrough = 0;
|
||||
for (let seed = 1; seed <= 12; seed++) {
|
||||
const { state, caster, side } = setupIllusion(seed);
|
||||
const other = state.players.find((p) => p.id !== caster)!;
|
||||
other.position = { ...state.players.find((p) => p.id === caster)!.position };
|
||||
let s = must(state, caster, { type: "endTurn", draw: 0 });
|
||||
// Bumping blind is refused: eyes must be tested first.
|
||||
expect(applyCommand(s, other.id, { type: "move", direction: side }).ok).toBe(false);
|
||||
s = must(s, other.id, { type: "testIllusion", cell: other.position, side });
|
||||
const result = applyCommand(s, other.id, { type: "move", direction: side });
|
||||
if (result.ok) sawThrough++;
|
||||
else believed++;
|
||||
@@ -223,11 +350,16 @@ describe("sector manipulation", () => {
|
||||
type: "cast", instanceId: rel.instanceId,
|
||||
target: { kind: "cell", cell: dest }, params: { cell: me.position },
|
||||
});
|
||||
// The maze zero-anchors after the move; measure against the sector's
|
||||
// origin as it settled, not the requested landing.
|
||||
const after = state.players.find((p) => p.id === me.id)!;
|
||||
const dx = dest.x - myOrigin.x, dy = dest.y - myOrigin.y;
|
||||
const newOrigin = state.board.placements[idx]!.origin;
|
||||
const dx = newOrigin.x - myOrigin.x, dy = newOrigin.y - myOrigin.y;
|
||||
expect(after.position).toEqual({ x: posBefore.x + dx, y: posBefore.y + dy });
|
||||
expect(after.home).toEqual({ x: homeBefore.x + dx, y: homeBefore.y + dy });
|
||||
expect(state.board.placements[idx]!.origin).toEqual(dest);
|
||||
// My sector sits east of the other, as asked.
|
||||
const otherAfter = state.board.placements[idx === 0 ? 1 : 0]!.origin;
|
||||
expect(newOrigin).toEqual({ x: otherAfter.x + 5, y: otherAfter.y });
|
||||
// The map reassembled: every treasure/wizard cell exists on the new board.
|
||||
for (const t of state.treasures) {
|
||||
if (t.position) expect(state.board.cells[cellKey(t.position)]).toBe(true);
|
||||
@@ -320,7 +452,6 @@ describe("6e card-face corrections", () => {
|
||||
});
|
||||
state = must(state, defender.id, { type: "counteract", instanceId: "wall-of-fire#WOF" });
|
||||
state = must(state, attacker.id, { type: "pass" });
|
||||
state = must(state, defender.id, { type: "pass" });
|
||||
expect(state.players.find((p) => p.id === defender.id)!.life).toBe(15);
|
||||
|
||||
// But it cannot counter a fireball.
|
||||
@@ -335,14 +466,14 @@ describe("6e card-face corrections", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("relocation past the origin (rules rev 11)", () => {
|
||||
function rev11Game() {
|
||||
const { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 11 });
|
||||
describe("relocation past the origin", () => {
|
||||
function freshGame() {
|
||||
const { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"] });
|
||||
return state;
|
||||
}
|
||||
|
||||
it("a sector may land at negative coordinates — the maze renormalizes", () => {
|
||||
let state = rev11Game();
|
||||
let state = freshGame();
|
||||
const me = activePlayer(state);
|
||||
const other = state.players.find((p) => p.id !== me.id)!;
|
||||
const idx = state.board.placements.findIndex(
|
||||
@@ -376,8 +507,8 @@ describe("relocation past the origin (rules rev 11)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("older revisions still refuse the negative landing", () => {
|
||||
let { state } = newGame(); // helper default: rev-ungated (1)
|
||||
it("a diagonal landing breaks adjacency and is refused", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
const idx = state.board.placements.findIndex(
|
||||
(p) => me.position.y >= p.origin.y && me.position.y < p.origin.y + 5,
|
||||
@@ -393,7 +524,7 @@ describe("relocation past the origin (rules rev 11)", () => {
|
||||
});
|
||||
|
||||
it("a moving sector carries its creature, glue, warp tokens, and traps", () => {
|
||||
let state = rev11Game();
|
||||
let state = freshGame();
|
||||
const me = activePlayer(state);
|
||||
const idx = state.board.placements.findIndex(
|
||||
(p) => me.position.y >= p.origin.y && me.position.y < p.origin.y + 5,
|
||||
@@ -435,3 +566,126 @@ describe("relocation past the origin (rules rev 11)", () => {
|
||||
expect(state.boobytraps[0]!.realKey).toBe(cellKey(moved));
|
||||
});
|
||||
});
|
||||
|
||||
describe("junction alterations roll for their sector", () => {
|
||||
it("a conjured wall on the seam obeys the die: 1-2 stays, 3-4 travels", () => {
|
||||
const { state: fresh } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
let state = toRound2(fresh);
|
||||
// The 2p board is two sectors stacked: the seam runs between them.
|
||||
const [p0, p1] = state.board.placements;
|
||||
const seamY = Math.max(p0!.origin.y, p1!.origin.y) - 1;
|
||||
const seamCell = { x: p0!.origin.x + 2, y: seamY };
|
||||
const key = edgeKey(seamCell, "S");
|
||||
// Conjure a wall on the seam (state surgery: the cast needs LOS we may lack).
|
||||
state.edgeOverrides[key] = "wall";
|
||||
state.createdEdges[key] = true;
|
||||
const caster = activePlayer(state);
|
||||
const rot = giveCard(state, caster.id, "rotate-sector");
|
||||
const rngBefore = JSON.stringify(state.rng);
|
||||
state = must(state, caster.id, {
|
||||
type: "cast", instanceId: rot.instanceId,
|
||||
target: { kind: "cell", cell: { x: p1!.origin.x + 2, y: p1!.origin.y + 2 } },
|
||||
params: { clockwise: true },
|
||||
});
|
||||
// A die was consumed for the seam wall.
|
||||
expect(JSON.stringify(state.rng)).not.toBe(rngBefore);
|
||||
// The wall is somewhere: either the old seam key or a remapped edge.
|
||||
const createdKeys = Object.keys(state.createdEdges);
|
||||
expect(createdKeys.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sight tracing", () => {
|
||||
it("agrees with sightBetween on every pair and pins entry/exit to the mouths", () => {
|
||||
const { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
const board = boardView(state);
|
||||
const cells = Object.keys(board.cells).map((k) => {
|
||||
const [x, y] = k.split(",").map(Number) as [number, number];
|
||||
return { x, y };
|
||||
});
|
||||
let warped = 0;
|
||||
for (const from of cells) {
|
||||
for (const to of cells) {
|
||||
const t = traceSight(board, from, to);
|
||||
expect(t !== null).toBe(sightBetween(board, from, to));
|
||||
if (!t) continue;
|
||||
if (hasLineOfSight(board, from, to)) {
|
||||
expect(t.kind).toBe("direct");
|
||||
} else {
|
||||
expect(t.kind).toBe("warp");
|
||||
if (t.kind === "warp") {
|
||||
warped++;
|
||||
// Each crossing point lies on its mouth's one-cell rim segment.
|
||||
const onRim = (p: { x: number; y: number }, m: { cell: Cell; side: string }) => {
|
||||
if (m.side === "N") return p.y === m.cell.y && p.x > m.cell.x && p.x < m.cell.x + 1;
|
||||
if (m.side === "S") return p.y === m.cell.y + 1 && p.x > m.cell.x && p.x < m.cell.x + 1;
|
||||
if (m.side === "W") return p.x === m.cell.x && p.y > m.cell.y && p.y < m.cell.y + 1;
|
||||
return p.x === m.cell.x + 1 && p.y > m.cell.y && p.y < m.cell.y + 1;
|
||||
};
|
||||
expect(onRim(t.entry, t.mouthA)).toBe(true);
|
||||
expect(onRim(t.exit, t.mouthB)).toBe(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(warped).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("illusions are tested by choice", () => {
|
||||
function shimmerRig() {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const caster = activePlayer(state);
|
||||
const mark = state.players.find((p) => p.id !== caster.id)!;
|
||||
// Conjure the illusion on an OPEN edge beside the victim (state surgery
|
||||
// for a deterministic spot; the cast itself is tested elsewhere).
|
||||
const spot = emptyNeighborCell(state, mark.position);
|
||||
const key = edgeKey(mark.position, spot.side);
|
||||
state.illusionWalls[key] = { createdBy: caster.id, belief: {} };
|
||||
state = must(state, caster.id, { type: "endTurn", draw: 0 });
|
||||
return {
|
||||
state, caster: caster.id, victim: mark.id, side: spot.side,
|
||||
cell: { ...state.players.find((p) => p.id === mark.id)!.position },
|
||||
};
|
||||
}
|
||||
|
||||
it("an untested shimmer blocks the walker with its own message, no die rolled", () => {
|
||||
const { state, victim, side } = shimmerRig();
|
||||
const rngBefore = JSON.stringify(state.rng);
|
||||
const r = applyCommand(state, victim, { type: "move", direction: side });
|
||||
expect(r.ok).toBe(false);
|
||||
if (!r.ok) expect(r.error).toContain("shimmers");
|
||||
expect(JSON.stringify(state.rng)).toBe(rngBefore);
|
||||
});
|
||||
|
||||
it("the belief test is an explicit roll; the verdict then governs the wall", () => {
|
||||
let { state, victim, cell, side } = shimmerRig();
|
||||
state = must(state, victim, { type: "testIllusion", cell, side });
|
||||
const verdict = state.illusionWalls[edgeKey(cell, side)]!.belief[victim];
|
||||
expect(verdict === "believes" || verdict === "seesThrough").toBe(true);
|
||||
const r = applyCommand(state, victim, { type: "move", direction: side });
|
||||
if (verdict === "seesThrough") {
|
||||
expect(r.ok).toBe(true);
|
||||
} else {
|
||||
expect(r.ok).toBe(false);
|
||||
if (!r.ok) expect(r.error).toBe("blocked by wall");
|
||||
}
|
||||
// A second test is refused: eyes rule once.
|
||||
expect(applyCommand(state, victim, { type: "testIllusion", cell, side }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it("the creator strolls through their own fake without any test", () => {
|
||||
let { state, caster } = shimmerRig();
|
||||
// Skip to the caster's turn; the wall never blocks its maker.
|
||||
while (activePlayer(state).id !== caster) {
|
||||
state = must(state, activePlayer(state).id, { type: "endTurn", draw: 0 });
|
||||
}
|
||||
const me = state.players.find((p) => p.id === caster)!;
|
||||
const other = state.players.find((p) => p.id !== caster)!;
|
||||
me.position = { ...other.position };
|
||||
const r = applyCommand(state, caster, { type: "move", direction: "E" });
|
||||
// Blocked only if some REAL edge stands there; the illusion itself never objects.
|
||||
if (!r.ok) expect(r.error).not.toContain("shimmers");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, displays, handLimit, sustainedOn, type GameState, type PlayerId } from "../src/game";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newGame, must, giveCard, toRound2, faceOff, castAt } from "./helpers";
|
||||
import { createGame } from "../src/game";
|
||||
import { newGame, must, drain, giveCard, toRound2, faceOff, castAt } from "./helpers";
|
||||
|
||||
/** Display a stone for a player during their turn. */
|
||||
function displayStone(state: GameState, playerId: PlayerId, stoneId: string, slot = 0): GameState {
|
||||
@@ -147,6 +148,95 @@ describe("slow death", () => {
|
||||
expect(sustainedOn(state, defender, "slow-death").length).toBe(1);
|
||||
});
|
||||
|
||||
it("a reverse at the casting turns the curse: a point gained per draw (rev 11)", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sd = giveCard(state, attacker, "slow-death");
|
||||
giveCard(state, defender, "reverse", "RV", 0);
|
||||
const r = applyCommand(state, attacker, {
|
||||
type: "cast", instanceId: sd.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = must(r.state, defender, { type: "counteract", instanceId: "reverse#RV" });
|
||||
state = drain(state);
|
||||
expect(sustainedOn(state, defender, "slow-death").length).toBe(1);
|
||||
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const toDiscard = d.hand.slice(0, 2).map((c) => c.instanceId);
|
||||
state = must(state, defender, { type: "discard", instanceIds: toDiscard });
|
||||
state = must(state, defender, { type: "endTurn", draw: 2 });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(17);
|
||||
});
|
||||
|
||||
it("a reversed walking dead heals half a point per space walked (rev 11)", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const wd = giveCard(state, attacker, "walking-dead");
|
||||
giveCard(state, defender, "reverse", "RV", 0);
|
||||
const r = applyCommand(state, attacker, {
|
||||
type: "cast", instanceId: wd.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = must(r.state, defender, { type: "counteract", instanceId: "reverse#RV" });
|
||||
state = drain(state);
|
||||
expect(sustainedOn(state, defender, "walking-dead").length).toBe(1);
|
||||
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
// Two spaces walked: one point gained, not bled.
|
||||
let steps = 0;
|
||||
for (const dir of ["N", "S", "E", "W", "N", "S", "E", "W"] as const) {
|
||||
if (steps >= 2) break;
|
||||
const mv = applyCommand(state, defender, { type: "move", direction: dir });
|
||||
if (mv.ok) { state = mv.state; steps++; }
|
||||
}
|
||||
expect(steps).toBe(2);
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(16);
|
||||
});
|
||||
|
||||
it("a full reflection returns the curse onto its caster (rev 11)", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sd = giveCard(state, attacker, "slow-death");
|
||||
giveCard(state, defender, "full-reflection", "FR", 0);
|
||||
const r = applyCommand(state, attacker, {
|
||||
type: "cast", instanceId: sd.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = must(r.state, defender, { type: "counteract", instanceId: "full-reflection#FR" });
|
||||
state = drain(state);
|
||||
expect(sustainedOn(state, defender, "slow-death").length).toBe(0);
|
||||
expect(sustainedOn(state, attacker, "slow-death").length).toBe(1);
|
||||
|
||||
// The caster now bleeds for their own draws.
|
||||
state = must(state, attacker, { type: "endTurn", draw: 1 });
|
||||
expect(state.players.find((p) => p.id === attacker)!.life).toBe(14);
|
||||
});
|
||||
|
||||
it("older decks attach the biting curse through a reverse (rev ≤10)", () => {
|
||||
let { state } = createGame({ playerIds: ["alice", "bob"], seed: 42, sets: ["basic"], deckRev: 10 });
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const sd = giveCard(state, attacker, "slow-death");
|
||||
giveCard(state, defender, "reverse", "RV", 0);
|
||||
const r = applyCommand(state, attacker, {
|
||||
type: "cast", instanceId: sd.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
state = must(r.state, defender, { type: "counteract", instanceId: "reverse#RV" });
|
||||
state = drain(state);
|
||||
|
||||
state = must(state, attacker, { type: "endTurn", draw: 0 });
|
||||
const d = state.players.find((p) => p.id === defender)!;
|
||||
const toDiscard = d.hand.slice(0, 2).map((c) => c.instanceId);
|
||||
state = must(state, defender, { type: "discard", instanceIds: toDiscard });
|
||||
state = must(state, defender, { type: "endTurn", draw: 2 });
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(13);
|
||||
});
|
||||
|
||||
it("bloodstone cancels slow death's per-draw point", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView, gameLos, sustainedOn } from "../src/game";
|
||||
import { applyCommand, activePlayer, boardView, createGame, gameLos, sustainedOn } from "../src/game";
|
||||
import { cellKey, edgeKey, neighbor, SIDES } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newGame, must, giveCard, toRound2, faceOff, castAt, emptyNeighborCell } from "./helpers";
|
||||
@@ -277,3 +277,17 @@ describe("control effects", () => {
|
||||
expect(state.players.find((p) => p.id === me.id)!.hand.some((c) => c.cardId === "create-wall")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("picking one of two treasures", () => {
|
||||
it("a named treasure is the one taken", () => {
|
||||
let { state } = createGame({ playerIds: ["a", "b"], seed: 42, sets: ["basic"] });
|
||||
state = toRound2(state);
|
||||
const p = activePlayer(state);
|
||||
const [t1, t2] = state.treasures.filter((t) => t.owner !== p.id);
|
||||
t1!.position = { ...p.position }; t1!.carriedBy = null;
|
||||
t2!.position = { ...p.position }; t2!.carriedBy = null;
|
||||
const r = applyCommand(state, p.id, { type: "pickUpTreasure", treasureId: t2!.id });
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
expect(r.state.players.find((q) => q.id === p.id)!.carriedTreasureId).toBe(t2!.id);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// The telepath guard: every event the engine emits must reach the player —
|
||||
// a log line, an effect, or a modal — and every targeted cast must be
|
||||
// aimable on the board. A new event or card that slips past the client
|
||||
// fails here, instead of surfacing one puzzled bug report at a time.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const ENGINE = join(__dirname, "..", "src");
|
||||
const WEB = join(__dirname, "..", "..", "web", "src");
|
||||
const game = readFileSync(join(ENGINE, "game.ts"), "utf8");
|
||||
const app = readFileSync(join(WEB, "App.svelte"), "utf8");
|
||||
const clientSources = ["net.svelte.ts", "fx.ts", "local.svelte.ts", "Replay.svelte", "hints.ts"]
|
||||
.map((f) => readFileSync(join(WEB, f), "utf8"))
|
||||
.concat(app)
|
||||
.join("\n");
|
||||
|
||||
/** Events whose information reaches the player another way — each with the
|
||||
* reason. Add here ONLY with a reason; "I'll wire it later" is not one. */
|
||||
const SILENT_BY_DESIGN: Record<string, string> = {
|
||||
cardsDealt: "the opening deal: the hand tray is the reveal",
|
||||
cardsDealtPrivate: "same — your opening hand appears in the tray",
|
||||
boobytrapPlacedPrivate: "the board marks the caster's real token from the view",
|
||||
};
|
||||
|
||||
function eventTypes(): string[] {
|
||||
const start = game.indexOf("export type GameEvent =");
|
||||
const block = game.slice(start, game.indexOf("\nexport ", start + 10));
|
||||
return [...new Set([...block.matchAll(/\| \{ type: "([a-zA-Z]+)"/g)].map((m) => m[1]!))];
|
||||
}
|
||||
|
||||
describe("every engine event reaches the player", () => {
|
||||
it("is humanized, animated, handled in a modal, or silent by design", () => {
|
||||
const handled = new Set<string>();
|
||||
for (const m of clientSources.matchAll(/case "([a-zA-Z]+)"/g)) handled.add(m[1]!);
|
||||
for (const m of clientSources.matchAll(/type === "([a-zA-Z]+)"/g)) handled.add(m[1]!);
|
||||
const orphans = eventTypes().filter((e) => !handled.has(e) && !(e in SILENT_BY_DESIGN));
|
||||
expect(orphans, `events no client code touches: ${orphans.join(", ")}`).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the silent-by-design list honest (no stale entries)", () => {
|
||||
const known = new Set(eventTypes());
|
||||
const stale = Object.keys(SILENT_BY_DESIGN).filter((e) => !known.has(e));
|
||||
expect(stale, `allowlisted events the engine no longer emits: ${stale.join(", ")}`).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("every targeted cast is aimable on the board", () => {
|
||||
/** A card's resolver demanding a cell/edge target must appear in App's
|
||||
* click-targeting sets, or selecting the card leaves it uncastable. */
|
||||
it("cell- and edge-demanding resolvers appear in CELL_CARDS / EDGE_CARDS", () => {
|
||||
const start = game.indexOf("const CARD_EFFECTS");
|
||||
const end = game.indexOf("\n};", start); // the table's own closing brace
|
||||
const entries = game.slice(start, end).split(/\n (?="?[a-z][a-z0-9-]*"?: \{)/);
|
||||
const appSet = (name: string) =>
|
||||
new Set([...(app.match(new RegExp(`${name} = new Set\\(\\[([^\\]]*)\\]`))?.[1] ?? "")
|
||||
.matchAll(/"([a-z-]+)"/g)].map((m) => m[1]!));
|
||||
const cellCards = appSet("CELL_CARDS");
|
||||
const edgeCards = appSet("EDGE_CARDS");
|
||||
const missing: string[] = [];
|
||||
for (const entry of entries) {
|
||||
const id = entry.match(/^"?([a-z][a-z0-9-]*)"?: \{/)?.[1];
|
||||
if (!id) continue;
|
||||
// Only demands stated as refusals bind: `target.kind !== "cell"` etc.
|
||||
// (an optional `target?.kind === ...` branch is not a requirement).
|
||||
if (/target \|\| cmd\.target\.kind !== "cell"/.test(entry) &&
|
||||
!cellCards.has(id)) missing.push(`${id} (cell)`);
|
||||
if (/target \|\| cmd\.target\.kind !== "edge"/.test(entry) &&
|
||||
!edgeCards.has(id)) missing.push(`${id} (edge)`);
|
||||
}
|
||||
expect(missing, `casts the board cannot aim: ${missing.join(", ")}`).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyCommand, activePlayer, boardView } from "../src/game";
|
||||
import { applyCommand, activePlayer, boardView, createGame } from "../src/game";
|
||||
import { cellKey, edgeKey, SIDES, type Cell, type Side } from "../src/board";
|
||||
import type { CardInstance } from "../src/cards";
|
||||
import { newExpansionGame as newGame, must, giveCard, toRound2, faceOff } from "./helpers";
|
||||
import { newExpansionGame as newGame, must, giveCard, toRound2, faceOff, plainRimWall } from "./helpers";
|
||||
|
||||
describe("magic wands", () => {
|
||||
it("blaster wand: charges on first use, once per turn, discards when spent", () => {
|
||||
@@ -12,11 +12,6 @@ describe("magic wands", () => {
|
||||
const wand = giveCard(state, attacker, "blaster-wand");
|
||||
giveCard(state, attacker, "number-2", "N", 1);
|
||||
|
||||
// First use without a number card is refused.
|
||||
expect(applyCommand(state, attacker, {
|
||||
type: "cast", instanceId: wand.instanceId, target: { kind: "player", playerId: defender },
|
||||
}).ok).toBe(false);
|
||||
|
||||
// Charged with a 2: fires (3 damage), one charge left, wand displayed.
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: wand.instanceId, numberInstanceIds: ["number-2#N"],
|
||||
@@ -148,6 +143,31 @@ describe("magic wands", () => {
|
||||
expect(boardView(state).edges[key]).toBe("wall");
|
||||
});
|
||||
|
||||
it("warp wand bores the rim: a wraparound that closes at turn's end", () => {
|
||||
let { state } = createGame({
|
||||
playerIds: ["alice", "bob"], seed: 42, sets: ["basic", "expansion1"],
|
||||
});
|
||||
const me = activePlayer(state);
|
||||
const rim = plainRimWall(state);
|
||||
me.position = { ...rim.cell };
|
||||
const warpsBefore = state.board.warps.length;
|
||||
const wand = giveCard(state, me.id, "warp-wand");
|
||||
giveCard(state, me.id, "number-2", "N", 1);
|
||||
state = must(state, me.id, {
|
||||
type: "cast", instanceId: wand.instanceId, numberInstanceIds: ["number-2#N"],
|
||||
target: { kind: "edge", cell: rim.cell, side: rim.side },
|
||||
});
|
||||
expect(state.board.warps.length).toBe(warpsBefore + 2);
|
||||
// The wraparound runs: step off the rim and land on the opposite edge.
|
||||
state = must(state, me.id, { type: "move", direction: rim.side });
|
||||
const across = state.players.find((p) => p.id === me.id)!.position;
|
||||
expect(cellKey(across)).not.toBe(cellKey(rim.cell));
|
||||
// Turn's end: the walls return and the warp closes with them.
|
||||
state = must(state, me.id, { type: "endTurn", draw: 0 });
|
||||
expect(boardView(state).edges[edgeKey(rim.cell, rim.side)]).toBe("wall");
|
||||
expect(state.board.warps.length).toBe(warpsBefore);
|
||||
});
|
||||
|
||||
it("deja-vu retrieves from the discard, but never a wand", () => {
|
||||
let { state } = newGame();
|
||||
const me = activePlayer(state);
|
||||
@@ -210,3 +230,20 @@ describe("dropping objects", () => {
|
||||
expect(refused.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a bare wand lights a single charge", () => {
|
||||
it("'played without a number card, its power is only 1': one shot, then dust", () => {
|
||||
let { state } = newGame();
|
||||
state = toRound2(state);
|
||||
const { attacker, defender } = faceOff(state);
|
||||
const bw = giveCard(state, attacker, "blaster-wand");
|
||||
state = must(state, attacker, {
|
||||
type: "cast", instanceId: bw.instanceId, target: { kind: "player", playerId: defender },
|
||||
});
|
||||
state = must(state, defender, { type: "pass" });
|
||||
// The single charge fired (3 flat damage) and the wand crumbled.
|
||||
expect(state.players.find((p) => p.id === defender)!.life).toBe(12);
|
||||
expect(state.players.find((p) => p.id === attacker)!.hand.some((c) => c.cardId === "blaster-wand")).toBe(false);
|
||||
expect(state.wandCharges[bw.instanceId]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,16 +9,22 @@
|
||||
// {type:"claimTransfer", code} claim a seat on a new device
|
||||
// {type:"catchUp", sinceSeq} replay of moves missed while away
|
||||
// {type:"chat", text} table talk to the room
|
||||
// {type:"rollDie"} the tabletop D4, published as talk
|
||||
// {type:"addBot", style?, tier?} host seats an automaton
|
||||
// {type:"watch", roomId} join the Peanut Gallery: nameless, read-only
|
||||
// {type:"leave"} detach this socket from table or gallery
|
||||
// {type:"myGames", seats} summaries for held seats
|
||||
// {type:"stats"} the engagement tally
|
||||
// {type:"hotseatReport", ...} anonymous hotseat game counts
|
||||
// server -> client:
|
||||
// {type:"welcome"} on connect
|
||||
// {type:"seat", playerId, token} your seat secret — keep it
|
||||
// {type:"room", roomId, players, hostId, started, colors}
|
||||
// {type:"events", events} redacted for this recipient
|
||||
// {type:"room", roomId, players, hostId, started, audience, colors, bots}
|
||||
// {type:"events", events, replayed?} redacted for this recipient
|
||||
// {type:"state", view, seq} redacted full view (after every change)
|
||||
// {type:"chat", player, text, at} one line of table talk
|
||||
// {type:"watching", roomId} you are seated in the gallery
|
||||
// {type:"audience", count} how many watch from the gallery
|
||||
// {type:"transferCode"|"transferClaimed"|"catchUp"|"games"|"stats"}
|
||||
// {type:"error", message}
|
||||
|
||||
@@ -29,12 +35,14 @@ import { WebSocketServer, WebSocket } from "ws";
|
||||
import type { Command, PlayerId } from "@wizwar/engine";
|
||||
import {
|
||||
catchUpSteps,
|
||||
momentSteps,
|
||||
claimTransferCode,
|
||||
createRoom,
|
||||
pickColor,
|
||||
getRoom,
|
||||
joinRoom,
|
||||
loadPersistedRooms,
|
||||
runningRooms,
|
||||
addAutomaton,
|
||||
addChat,
|
||||
driveOneAutomaton,
|
||||
@@ -43,12 +51,18 @@ import {
|
||||
roomCount,
|
||||
runCommand,
|
||||
seatTokenValid,
|
||||
SPECTATOR,
|
||||
type CatchUpStep,
|
||||
startGame,
|
||||
summarize,
|
||||
viewForPlayer,
|
||||
type Room,
|
||||
kickSeat,
|
||||
abandonRoom,
|
||||
} from "./rooms";
|
||||
import { engagementStats, recordHotseat } from "./stats";
|
||||
import { getShare, loadShares, mintShare } from "./shares";
|
||||
import { renderSharePng } from "./ogimage";
|
||||
import { BOT_LINES, type BanterTrigger } from "./banter";
|
||||
|
||||
// --- Abuse limits: this is a public server on a small box. -----------------
|
||||
@@ -58,6 +72,7 @@ const MAX_ROOMS_PER_CONN = 10; // rooms one connection may create
|
||||
const MAX_COMMAND_BYTES = 16384; // serialized game command
|
||||
const MAX_MYGAMES_SEATS = 50; // seats checked per myGames request
|
||||
const CATCHUP_COOLDOWN_MS = 3000; // full-game replays are CPU-heavy
|
||||
const MAX_AUDIENCE = 30; // gallery seats per room
|
||||
const NAME_MAX = 24;
|
||||
|
||||
/** Player/room names: printable, trimmed, bounded. */
|
||||
@@ -70,6 +85,12 @@ const port = Number(process.env.PORT ?? 8787);
|
||||
// is not reachable from the internet. Dev default stays LAN-friendly.
|
||||
const host = process.env.HOST ?? "0.0.0.0";
|
||||
loadPersistedRooms();
|
||||
loadShares();
|
||||
// A restart can land mid-bot-turn: without a kick, a restored room whose
|
||||
// current actor is an automaton waits forever for a human to poke it.
|
||||
setTimeout(() => {
|
||||
for (const room of runningRooms()) runBots(room);
|
||||
}, 2000); // a beat for clients to reconnect before the clockwork stirs
|
||||
|
||||
// One process serves both the built client and the websocket, so production
|
||||
// needs only a TLS proxy in front (or nothing, on a LAN).
|
||||
@@ -82,6 +103,120 @@ const MIME: Record<string, string> = {
|
||||
// The client build may be absent in development (vite serves it instead);
|
||||
// serve a 404 for static requests in that case rather than dying on boot.
|
||||
const staticRoot = existsSync(STATIC_DIR) ? realpathSync(normalize(STATIC_DIR)) : null;
|
||||
|
||||
// --- Share pages: one turn, rebuilt for the nameless viewer. ---------------
|
||||
// Every lookup is a full-game replay, so results rest briefly in memory.
|
||||
|
||||
interface ShareData {
|
||||
steps: CatchUpStep[];
|
||||
actor: string;
|
||||
round: number;
|
||||
/** A whole finished game rather than one turn. */
|
||||
whole?: boolean;
|
||||
}
|
||||
const shareCache = new Map<string, { at: number; data: ShareData | null }>();
|
||||
function shareData(id: string): ShareData | null {
|
||||
const hit = shareCache.get(id);
|
||||
if (hit && Date.now() - hit.at < 30_000) return hit.data;
|
||||
let data: ShareData | null = null;
|
||||
const share = getShare(id);
|
||||
const room = share ? getRoom(share.roomId) : undefined;
|
||||
if (share && room?.state) {
|
||||
if (share.turn < 0) {
|
||||
// The whole tale: a finished game from the deal to the crown.
|
||||
const steps = catchUpSteps(room, SPECTATOR, 0, true);
|
||||
if (!("error" in steps) && steps.length > 0) {
|
||||
let winner = "";
|
||||
for (const st of steps) {
|
||||
for (const e of st.events) if (e.type === "gameWon" && "player" in e) winner = e.player;
|
||||
}
|
||||
data = { steps, actor: winner, round: 0, whole: true };
|
||||
}
|
||||
} else {
|
||||
const reel = momentSteps(room, SPECTATOR, share.turn);
|
||||
if (!("error" in reel) && reel.steps.length > 0) {
|
||||
data = { steps: reel.steps, actor: reel.owner, round: reel.round };
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shareCache.size > 50) shareCache.clear();
|
||||
shareCache.set(id, { at: Date.now(), data });
|
||||
return data;
|
||||
}
|
||||
|
||||
const escapeHtml = (t: string) =>
|
||||
t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
|
||||
/** index.html with a bespoke OpenGraph card folded into its head —
|
||||
* crawlers never run the app, so the unfurl must arrive pre-baked. The
|
||||
* stock page carries its own generic card; strip it, or crawlers (which
|
||||
* take the FIRST tag they meet) never see this page's. */
|
||||
function ogPage(metas: string[]): string {
|
||||
return readFileSync(join(staticRoot!, "index.html"), "utf8")
|
||||
.replace(/<meta (?:property="og:|name="twitter:)[^>]*>\s*/g, "")
|
||||
.replace(/<title>[^<]*<\/title>\s*/, "")
|
||||
.replace("</head>", ` ${metas.join("\n ")}\n </head>`);
|
||||
}
|
||||
|
||||
/** Host and proto arrive from request headers — attacker-writable text
|
||||
* that must never reach an HTML attribute raw. */
|
||||
function safeBase(rawHost: string, rawProto: string): string {
|
||||
const proto = /^https?$/.test(rawProto) ? rawProto : "https";
|
||||
return `${proto}://${escapeHtml(rawHost)}`;
|
||||
}
|
||||
|
||||
function shareHtml(id: string, data: ShareData, rawHost: string, rawProto: string): string {
|
||||
const base = safeBase(rawHost, rawProto);
|
||||
const title = data.whole
|
||||
? "The whole tale — a game of Wiz-War, replayed"
|
||||
: `${escapeHtml(data.actor)}'s turn — a Wiz-War instant replay`;
|
||||
const desc = data.whole
|
||||
? `A full game of Wiz-War, magical combat in a stone labyrinth — every turn through its wizard's own eyes${data.actor ? `, to ${escapeHtml(data.actor)}'s triumph` : ""}. Watch it all, then deal yourself in.`
|
||||
: `Round ${data.round || "?"} of a game of Wiz-War, magical combat in a stone labyrinth. ` +
|
||||
`Watch the turn through ${escapeHtml(data.actor)}'s own eyes, then deal yourself in.`;
|
||||
const metas = [
|
||||
`<title>${title}</title>`,
|
||||
`<meta property="og:type" content="website"/>`,
|
||||
`<meta property="og:site_name" content="Wiz-War"/>`,
|
||||
`<meta property="og:title" content="${title}"/>`,
|
||||
`<meta property="og:description" content="${desc}"/>`,
|
||||
`<meta property="og:url" content="${base}/watch/${id}"/>`,
|
||||
`<meta property="og:image" content="${base}/watch/${id}/og.png"/>`,
|
||||
`<meta property="og:image:width" content="1200"/>`,
|
||||
`<meta property="og:image:height" content="630"/>`,
|
||||
`<meta name="twitter:card" content="summary_large_image"/>`,
|
||||
`<meta name="twitter:image" content="${base}/watch/${id}/og.png"/>`,
|
||||
];
|
||||
return ogPage(metas);
|
||||
}
|
||||
|
||||
/** The recruiting card for a /join/<code> link: an invitation while the
|
||||
* room waits to start, a summons to the gallery once it has. */
|
||||
function inviteHtml(room: Room, rawHost: string, rawProto: string): string {
|
||||
const base = safeBase(rawHost, rawProto);
|
||||
const seats = room.players.length;
|
||||
const wizards = `${seats} wizard${seats === 1 ? "" : "s"}`;
|
||||
const title = `You're summoned — Wiz-War room ${room.id}`;
|
||||
const desc = room.state?.phase === "finished"
|
||||
? `The tale is told — ${wizards} fought in this labyrinth. Follow the link to see how it ended.`
|
||||
: room.state
|
||||
? `The duel is underway, ${wizards} in the labyrinth. Follow the link to watch it live from the Peanut Gallery.`
|
||||
: `${wizards} at the table, waiting to flip the boards. Follow the link, pick a name, and take a seat.`;
|
||||
const metas = [
|
||||
`<title>${title}</title>`,
|
||||
`<meta property="og:type" content="website"/>`,
|
||||
`<meta property="og:site_name" content="Wiz-War"/>`,
|
||||
`<meta property="og:title" content="${title}"/>`,
|
||||
`<meta property="og:description" content="${desc}"/>`,
|
||||
`<meta property="og:url" content="${base}/join/${room.id}"/>`,
|
||||
`<meta property="og:image" content="${base}/og.png"/>`,
|
||||
`<meta property="og:image:width" content="1200"/>`,
|
||||
`<meta property="og:image:height" content="630"/>`,
|
||||
`<meta name="twitter:card" content="summary_large_image"/>`,
|
||||
`<meta name="twitter:image" content="${base}/og.png"/>`,
|
||||
];
|
||||
return ogPage(metas);
|
||||
}
|
||||
const httpServer = createServer((req, res) => {
|
||||
try {
|
||||
if (req.method !== "GET" && req.method !== "HEAD") {
|
||||
@@ -104,6 +239,48 @@ const httpServer = createServer((req, res) => {
|
||||
res.writeHead(400).end();
|
||||
return;
|
||||
}
|
||||
// Share pages: the turn's data, its card image, and its chrome.
|
||||
const api = url.match(/^\/api\/share\/([a-z0-9]{4,20})$/);
|
||||
if (api) {
|
||||
const data = shareData(api[1]!);
|
||||
if (!data) { res.writeHead(404, { "content-type": "application/json" }).end('{"error":"no such replay"}'); return; }
|
||||
res.writeHead(200, {
|
||||
"content-type": "application/json",
|
||||
"cache-control": "public, max-age=60",
|
||||
"access-control-allow-origin": "*",
|
||||
});
|
||||
res.end(JSON.stringify({ steps: data.steps, actor: data.actor, round: data.round, whole: data.whole === true }));
|
||||
return;
|
||||
}
|
||||
const watch = url.match(/^\/watch\/([a-z0-9]{4,20})(\/og\.png)?$/);
|
||||
if (watch) {
|
||||
const data = shareData(watch[1]!);
|
||||
if (!data) { res.writeHead(404).end("no such replay"); return; }
|
||||
if (watch[2]) {
|
||||
const png = renderSharePng(data.steps[data.steps.length - 1]!.view);
|
||||
res.writeHead(200, { "content-type": "image/png", "cache-control": "public, max-age=300" });
|
||||
res.end(png);
|
||||
return;
|
||||
}
|
||||
const proto = String(req.headers["x-forwarded-proto"] ?? "http").split(",")[0]!.trim();
|
||||
const hostname = String(req.headers.host ?? `localhost:${port}`);
|
||||
res.writeHead(200, { "content-type": "text/html", "cache-control": "no-cache" });
|
||||
res.end(shareHtml(watch[1]!, data, hostname, proto));
|
||||
return;
|
||||
}
|
||||
// Room invitations: a living room gets its recruiting card; a dead
|
||||
// code falls through to the app, which reports it in the lobby.
|
||||
const invite = url.match(/^\/join\/([A-Za-z0-9]{4})$/);
|
||||
if (invite) {
|
||||
const room = getRoom(invite[1]!);
|
||||
if (room) {
|
||||
const proto = String(req.headers["x-forwarded-proto"] ?? "http").split(",")[0]!.trim();
|
||||
const hostname = String(req.headers.host ?? `localhost:${port}`);
|
||||
res.writeHead(200, { "content-type": "text/html", "cache-control": "no-cache" });
|
||||
res.end(inviteHtml(room, hostname, proto));
|
||||
return;
|
||||
}
|
||||
}
|
||||
let file = normalize(join(staticRoot, url === "/" ? "index.html" : url));
|
||||
if (file !== staticRoot && !file.startsWith(staticRoot + sep)) {
|
||||
res.writeHead(403).end();
|
||||
@@ -138,6 +315,9 @@ interface Session {
|
||||
socket: WebSocket;
|
||||
playerId: PlayerId | null;
|
||||
roomId: string | null;
|
||||
/** In the Peanut Gallery: spectator implies playerId === null, so every
|
||||
* handler that requires a seat refuses this session by construction. */
|
||||
spectator: boolean;
|
||||
/** The raw seat token this connection authenticated with (memory only). */
|
||||
token: string | null;
|
||||
claimFails: number;
|
||||
@@ -165,6 +345,25 @@ function send(socket: WebSocket, message: unknown): void {
|
||||
if (socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
function audienceCount(room: Room): number {
|
||||
let n = 0;
|
||||
for (const s of sessions) if (s.roomId === room.id && s.spectator) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
function broadcastAudience(room: Room): void {
|
||||
broadcast(room, () => ({ type: "audience", count: audienceCount(room) }));
|
||||
}
|
||||
|
||||
/** A watcher leaves the gallery (to sit down, watch elsewhere, or vanish). */
|
||||
function leaveGallery(session: Session): void {
|
||||
if (!session.spectator) return;
|
||||
session.spectator = false;
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
session.roomId = null;
|
||||
if (room) broadcastAudience(room);
|
||||
}
|
||||
|
||||
function roomInfo(room: Room) {
|
||||
return {
|
||||
type: "room",
|
||||
@@ -172,18 +371,27 @@ function roomInfo(room: Room) {
|
||||
players: room.players,
|
||||
hostId: room.hostId,
|
||||
started: room.state !== null,
|
||||
audience: audienceCount(room),
|
||||
colors: Object.fromEntries(room.colorChoices),
|
||||
bots: Object.fromEntries(
|
||||
[...room.bots].map(([name, b]) => [name, `${b.tier} ${b.secret ? "mystery" : b.style}`]),
|
||||
// A mystery machine keeps its mood only while the game lives: once it
|
||||
// ends, the hands go face-up and so does the temperament.
|
||||
[...room.bots].map(([name, b]) => [
|
||||
name,
|
||||
room.state?.phase === "finished"
|
||||
? `${b.tier} ${b.style}${b.secret ? " 🎭" : ""}`
|
||||
: `${b.tier} ${b.secret ? "mystery" : b.style}`,
|
||||
]),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function broadcast(room: Room, makeMessage: (playerId: PlayerId) => unknown): void {
|
||||
for (const s of sessions) {
|
||||
if (s.roomId === room.id && s.playerId) {
|
||||
send(s.socket, makeMessage(s.playerId));
|
||||
}
|
||||
if (s.roomId !== room.id) continue;
|
||||
// The gallery hears everything too, redacted for the nameless viewer.
|
||||
if (s.playerId) send(s.socket, makeMessage(s.playerId));
|
||||
else if (s.spectator) send(s.socket, makeMessage(SPECTATOR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,24 +399,27 @@ function broadcast(room: Room, makeMessage: (playerId: PlayerId) => unknown): vo
|
||||
* The clockwork plays at a watchable pace: one command every beat, each
|
||||
* broadcast as it lands, until the maze wants a human again.
|
||||
*/
|
||||
const BOT_STEP_MS = 1500;
|
||||
const BOT_STEP_MS = 1000;
|
||||
|
||||
/** What a step's event means to this bot — its own deed when it acted,
|
||||
* its own suffering when somebody else did. Null: nothing worth a word. */
|
||||
/** What a step's event means to this bot — its own deeds when it acted,
|
||||
* its own suffering whoever caused it. Null: nothing worth a word. */
|
||||
function banterTrigger(
|
||||
e: { type: string; [k: string]: unknown }, seat: string, actor: string,
|
||||
): BanterTrigger | null {
|
||||
if (actor === seat) {
|
||||
if (e.type === "treasurePickedUp" && e.player === seat) return "grabGold";
|
||||
if (e.type === "treasureDropped" && e.player === seat) return "deliverGold";
|
||||
if (e.type === "treasureDropped" && e.player === seat && e.onHomeOf != null) return "deliverGold";
|
||||
if (e.type === "damaged" && e.player !== seat) return "dealPain";
|
||||
if (e.type === "died" && e.killedBy === seat && e.player !== seat) return "kill";
|
||||
if (e.type === "creatureCreated" && e.controller === seat) return "summon";
|
||||
if (e.type === "wallCreated" && e.caster === seat) return "buildWall";
|
||||
if (e.type === "teleported" && e.player === seat && e.by === seat) return "escape";
|
||||
if (e.type === "trapSprung" && e.player === seat) return "springTrap";
|
||||
if (e.type === "gameWon" && e.player === seat) return "win";
|
||||
}
|
||||
// A counter-teleport escape resolves during the ATTACKER's step, and a
|
||||
// last-standing win can land on the victim's turn: self-referential
|
||||
// triggers hold whoever acted.
|
||||
if (e.type === "teleported" && e.player === seat && e.by === seat) return "escape";
|
||||
if (e.type === "gameWon" && e.player === seat) return "win";
|
||||
if (e.type === "damaged" && e.player === seat) return "takePain";
|
||||
if (e.type === "died" && e.player === seat) return "die";
|
||||
if (e.type === "attackMissed" && e.defender === seat) return "dodge";
|
||||
@@ -233,6 +444,17 @@ function botRemark(room: Room, actor: string, events: { type: string; [k: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Spoken when a clockwork's chosen command was refused by the engine —
|
||||
* the table sees a stumble instead of an unexplained idle turn. */
|
||||
const HESITATION_LINES = [
|
||||
"RECALCULATING.",
|
||||
"TACTICAL PAUSE. INTENTIONAL. PROBABLY.",
|
||||
"THE MAZE REFUSES MY GENIUS.",
|
||||
"ERROR LOGGED. DIGNITY INTACT.",
|
||||
"I MEANT TO DO THAT.",
|
||||
];
|
||||
|
||||
const pumping = new Set<string>();
|
||||
function runBots(room: Room): void {
|
||||
if (pumping.has(room.id)) return;
|
||||
@@ -245,6 +467,16 @@ function runBots(room: Room): void {
|
||||
}
|
||||
broadcast(room, (playerId) => ({ type: "events", events: redactFor(step.events, playerId) }));
|
||||
broadcast(room, (playerId) => ({ type: "state", view: viewForPlayer(room, playerId), seq: room.log.length }));
|
||||
// The game's end unmasks the mystery machines in the roster.
|
||||
if (room.state?.phase === "finished") broadcast(room, () => roomInfo(room));
|
||||
// A refused brain-choice becomes a visible stumble, in character —
|
||||
// an idle bot turn should read as hesitation, never as nothing.
|
||||
if (step.hesitated) {
|
||||
const said = addChat(room, step.seat, HESITATION_LINES[Math.floor(Math.random() * HESITATION_LINES.length)]!);
|
||||
if (!("error" in said)) {
|
||||
broadcast(room, () => ({ type: "chat", player: step.seat, text: said.text, at: said.at }));
|
||||
}
|
||||
}
|
||||
botRemark(room, step.seat, step.events as { type: string }[]);
|
||||
setTimeout(tick, BOT_STEP_MS);
|
||||
};
|
||||
@@ -265,14 +497,17 @@ wss.on("connection", (socket) => {
|
||||
return;
|
||||
}
|
||||
const session: Session = {
|
||||
socket, playerId: null, roomId: null, token: null, claimFails: 0,
|
||||
socket, playerId: null, roomId: null, spectator: false, token: null, claimFails: 0,
|
||||
bucket: 30, lastRefill: Date.now(), overLimitStrikes: 0,
|
||||
roomsCreated: 0, lastCatchUpAt: 0, hotseatReports: 0,
|
||||
};
|
||||
sessions.add(session);
|
||||
send(socket, { type: "welcome", game: "wizwar" });
|
||||
|
||||
socket.on("close", () => sessions.delete(session));
|
||||
socket.on("close", () => {
|
||||
sessions.delete(session);
|
||||
leaveGallery(session); // an emptier gallery is news to the table
|
||||
});
|
||||
|
||||
socket.on("message", (data) => {
|
||||
if (!underRateLimit(session)) {
|
||||
@@ -288,6 +523,12 @@ wss.on("connection", (socket) => {
|
||||
|
||||
try {
|
||||
switch (msg.type) {
|
||||
case "ping":
|
||||
// Liveness probe: the reply is the point. A restart can leave
|
||||
// browsers holding half-dead sockets that never fire onclose;
|
||||
// silence answered by silence is how the client finds out.
|
||||
send(socket, { type: "pong" });
|
||||
break;
|
||||
case "create": {
|
||||
const name = cleanName(msg.name);
|
||||
if (!name) return send(socket, { type: "error", message: "name required" });
|
||||
@@ -295,6 +536,7 @@ wss.on("connection", (socket) => {
|
||||
return send(socket, { type: "error", message: "no new rooms right now — try again later" });
|
||||
}
|
||||
session.roomsCreated++;
|
||||
leaveGallery(session);
|
||||
const { room, token } = createRoom(name);
|
||||
session.playerId = name;
|
||||
session.roomId = room.id;
|
||||
@@ -311,6 +553,7 @@ wss.on("connection", (socket) => {
|
||||
if (!room) return send(socket, { type: "error", message: "no such room" });
|
||||
const result = joinRoom(room, name, typeof msg.token === "string" ? msg.token : null);
|
||||
if ("error" in result) return send(socket, { type: "error", message: result.error });
|
||||
leaveGallery(session);
|
||||
session.playerId = name;
|
||||
session.roomId = room.id;
|
||||
session.token = result.token;
|
||||
@@ -325,6 +568,72 @@ wss.on("connection", (socket) => {
|
||||
runBots(room);
|
||||
break;
|
||||
}
|
||||
case "watch": {
|
||||
// The Peanut Gallery: no name, no seat, no ledger line — a pure
|
||||
// reader of the public broadcast, counted but never identified.
|
||||
const roomId = String(msg.roomId ?? "").trim().slice(0, 8);
|
||||
if (!roomId) return send(socket, { type: "error", message: "roomId required" });
|
||||
const room = getRoom(roomId);
|
||||
if (!room) return send(socket, { type: "error", message: "no such room" });
|
||||
if (audienceCount(room) >= MAX_AUDIENCE) {
|
||||
return send(socket, { type: "error", message: "the gallery is packed — try again later" });
|
||||
}
|
||||
leaveGallery(session); // switching galleries updates the old room's count
|
||||
session.playerId = null;
|
||||
session.token = null;
|
||||
session.spectator = true;
|
||||
session.roomId = room.id;
|
||||
send(socket, { type: "watching", roomId: room.id });
|
||||
send(socket, roomInfo(room));
|
||||
if (room.state) {
|
||||
send(socket, { type: "events", events: redactFor(room.events, SPECTATOR), replayed: true });
|
||||
send(socket, { type: "state", view: viewForPlayer(room, SPECTATOR), seq: room.log.length });
|
||||
}
|
||||
broadcastAudience(room);
|
||||
break;
|
||||
}
|
||||
case "leave": {
|
||||
// Walk away from the table or the gallery: the seat itself (and
|
||||
// its token) survives for a later resume; only this socket detaches.
|
||||
leaveGallery(session);
|
||||
session.playerId = null;
|
||||
session.roomId = null;
|
||||
session.token = null;
|
||||
break;
|
||||
}
|
||||
case "kickSeat": {
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
const kickName = String(msg.name ?? "");
|
||||
const problem = kickSeat(room, session.playerId, kickName);
|
||||
if (problem) return send(socket, { type: "error", message: problem });
|
||||
// A kicked live socket is set adrift so it cannot act on a seat it lost.
|
||||
for (const other of sessions) {
|
||||
if (other.roomId === room.id && other.playerId === kickName) {
|
||||
other.playerId = null;
|
||||
other.roomId = null;
|
||||
other.token = null;
|
||||
send(other.socket, { type: "kicked", roomId: room.id });
|
||||
}
|
||||
}
|
||||
broadcastRoomState(room);
|
||||
break;
|
||||
}
|
||||
case "abandonRoom": {
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
const problem = abandonRoom(room, session.playerId);
|
||||
if (problem) return send(socket, { type: "error", message: problem });
|
||||
for (const other of sessions) {
|
||||
if (other.roomId === room.id) {
|
||||
other.playerId = null;
|
||||
other.roomId = null;
|
||||
other.token = null;
|
||||
send(other.socket, { type: "roomAbandoned", roomId: room.id });
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "addBot": {
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
@@ -359,6 +668,8 @@ wss.on("connection", (socket) => {
|
||||
if ("error" in result) return send(socket, { type: "error", message: result.error });
|
||||
broadcast(room, (playerId) => ({ type: "events", events: redactFor(result.events, playerId) }));
|
||||
broadcast(room, (playerId) => ({ type: "state", view: viewForPlayer(room, playerId), seq: room.log.length }));
|
||||
// The game's end unmasks the mystery machines in the roster.
|
||||
if (room.state?.phase === "finished") broadcast(room, () => roomInfo(room));
|
||||
botRemark(room, session.playerId, result.events as { type: string }[]);
|
||||
runBots(room);
|
||||
break;
|
||||
@@ -417,6 +728,40 @@ wss.on("connection", (socket) => {
|
||||
send(socket, { type: "catchUp", steps });
|
||||
break;
|
||||
}
|
||||
case "share": {
|
||||
// Mint (or re-find) the public link for one turn's replay.
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
const turn = Number(msg.turn);
|
||||
if (!Number.isInteger(turn) || turn < -1) return send(socket, { type: "error", message: "no such turn" });
|
||||
const now = Date.now();
|
||||
if (now - session.lastCatchUpAt < CATCHUP_COOLDOWN_MS) {
|
||||
return send(socket, { type: "error", message: "catching up already — one moment" });
|
||||
}
|
||||
session.lastCatchUpAt = now;
|
||||
// turn -1 shares the whole finished game; anything else, one turn.
|
||||
const check = turn === -1
|
||||
? catchUpSteps(room, session.playerId, 0, true)
|
||||
: momentSteps(room, session.playerId, turn);
|
||||
if ("error" in check) return send(socket, { type: "error", message: check.error });
|
||||
const share = mintShare(room.id, turn);
|
||||
send(socket, { type: "share", id: share.id, turn });
|
||||
break;
|
||||
}
|
||||
case "moment": {
|
||||
// A chronicle line's instant-replay eye: one turn's reel.
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
const now = Date.now();
|
||||
if (now - session.lastCatchUpAt < CATCHUP_COOLDOWN_MS) {
|
||||
return send(socket, { type: "error", message: "catching up already — one moment" });
|
||||
}
|
||||
session.lastCatchUpAt = now;
|
||||
const reel = momentSteps(room, session.playerId, Number(msg.turn ?? -1));
|
||||
if ("error" in reel) return send(socket, { type: "error", message: reel.error });
|
||||
send(socket, { type: "moment", steps: reel.steps, owner: reel.owner });
|
||||
break;
|
||||
}
|
||||
case "pickColor": {
|
||||
const room = session.roomId ? getRoom(session.roomId) : undefined;
|
||||
if (!room || !session.playerId) return send(socket, { type: "error", message: "not in a room" });
|
||||
@@ -443,18 +788,26 @@ wss.on("connection", (socket) => {
|
||||
break;
|
||||
}
|
||||
case "myGames": {
|
||||
// {seats: [{roomId, name, token}]} -> summaries for valid seats.
|
||||
// {seats: [{roomId, name, token}]} -> summaries for valid seats,
|
||||
// plus explicit verdicts on seats PROVEN dead: the room exists
|
||||
// and refused this exact token. A room this server simply does
|
||||
// not know earns no verdict — absence is not evidence (a
|
||||
// restarting or wrong server knows nothing about anything).
|
||||
const seats = Array.isArray(msg.seats) ? msg.seats.slice(0, MAX_MYGAMES_SEATS) : [];
|
||||
const games = [];
|
||||
const voided: string[] = [];
|
||||
for (const seat of seats) {
|
||||
if (typeof seat !== "object" || seat === null) continue;
|
||||
const room = getRoom(String(seat.roomId ?? ""));
|
||||
if (!room) continue;
|
||||
const name = String(seat.name ?? "");
|
||||
if (!seatTokenValid(room, name, typeof seat.token === "string" ? seat.token : null)) continue;
|
||||
if (!seatTokenValid(room, name, typeof seat.token === "string" ? seat.token : null)) {
|
||||
voided.push(`${room.id}:${name}`);
|
||||
continue;
|
||||
}
|
||||
games.push(summarize(room, name));
|
||||
}
|
||||
send(socket, { type: "games", games });
|
||||
send(socket, { type: "games", games, voided });
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
// The share card: a 1200x630 OpenGraph image of the shared turn's maze,
|
||||
// painted from a spectator view and encoded as PNG with nothing but
|
||||
// node's own zlib — no image libraries on this small box. The unfurl
|
||||
// text carries the words; this carries the board.
|
||||
|
||||
import { deflateSync } from "node:zlib";
|
||||
import type { GameView } from "@wizwar/engine";
|
||||
|
||||
// --- Minimal PNG encoding (truecolor, filter 0) ----------------------------
|
||||
|
||||
const CRC_TABLE = new Int32Array(256);
|
||||
for (let n = 0; n < 256; n++) {
|
||||
let c = n;
|
||||
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
||||
CRC_TABLE[n] = c;
|
||||
}
|
||||
function crc32(buf: Uint8Array): number {
|
||||
let c = ~0;
|
||||
for (const b of buf) c = CRC_TABLE[(c ^ b) & 0xff]! ^ (c >>> 8);
|
||||
return ~c >>> 0;
|
||||
}
|
||||
function chunk(type: string, data: Uint8Array): Uint8Array {
|
||||
const out = new Uint8Array(12 + data.length);
|
||||
const dv = new DataView(out.buffer);
|
||||
dv.setUint32(0, data.length);
|
||||
for (let i = 0; i < 4; i++) out[4 + i] = type.charCodeAt(i);
|
||||
out.set(data, 8);
|
||||
dv.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
||||
return out;
|
||||
}
|
||||
function encodePng(width: number, height: number, rgb: Uint8Array): Buffer {
|
||||
const ihdr = new Uint8Array(13);
|
||||
const dv = new DataView(ihdr.buffer);
|
||||
dv.setUint32(0, width);
|
||||
dv.setUint32(4, height);
|
||||
ihdr[8] = 8; // bit depth
|
||||
ihdr[9] = 2; // truecolor
|
||||
const raw = new Uint8Array(height * (1 + width * 3));
|
||||
for (let y = 0; y < height; y++) {
|
||||
raw.set(rgb.subarray(y * width * 3, (y + 1) * width * 3), y * (1 + width * 3) + 1);
|
||||
}
|
||||
return Buffer.concat([
|
||||
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
||||
chunk("IHDR", ihdr),
|
||||
chunk("IDAT", deflateSync(raw)),
|
||||
chunk("IEND", new Uint8Array(0)),
|
||||
]);
|
||||
}
|
||||
|
||||
// --- The painting ----------------------------------------------------------
|
||||
|
||||
type Rgb = [number, number, number];
|
||||
const hex = (s: string): Rgb => [
|
||||
parseInt(s.slice(1, 3), 16), parseInt(s.slice(3, 5), 16), parseInt(s.slice(5, 7), 16),
|
||||
];
|
||||
const BG = hex("#171a20");
|
||||
const CELL = hex("#e9e1cb");
|
||||
const CELL_LINE = hex("#cfc4a8");
|
||||
const WALL = hex("#43331f");
|
||||
const DOOR = hex("#a2703a");
|
||||
const FIRE = hex("#d65c1c");
|
||||
const STONE = hex("#8a8a94");
|
||||
const WARP = hex("#7a4ccc");
|
||||
const CREATURE = hex("#4a4438");
|
||||
const TREASURE = hex("#c9a72a");
|
||||
const HAZARD = hex("#7c8a4a");
|
||||
/** Standee colors, mirroring the client's PLAYER_COLORS. */
|
||||
const PLAYER: Rgb[] = [
|
||||
hex("#1a9c46"), hex("#d3352b"), hex("#c9308f"),
|
||||
hex("#3a3ac0"), hex("#2ab0c9"), hex("#c9a72a"),
|
||||
];
|
||||
|
||||
export function renderSharePng(view: GameView): Buffer {
|
||||
const W = 1200, H = 630;
|
||||
const img = new Uint8Array(W * H * 3);
|
||||
const rect = (x: number, y: number, w: number, h: number, c: Rgb) => {
|
||||
const x0 = Math.max(0, Math.round(x)), y0 = Math.max(0, Math.round(y));
|
||||
const x1 = Math.min(W, Math.round(x + w)), y1 = Math.min(H, Math.round(y + h));
|
||||
for (let yy = y0; yy < y1; yy++) {
|
||||
let o = (yy * W + x0) * 3;
|
||||
for (let xx = x0; xx < x1; xx++) {
|
||||
img[o] = c[0]; img[o + 1] = c[1]; img[o + 2] = c[2];
|
||||
o += 3;
|
||||
}
|
||||
}
|
||||
};
|
||||
const disc = (cx: number, cy: number, r: number, c: Rgb) => {
|
||||
for (let yy = Math.round(cy - r); yy <= cy + r; yy++) {
|
||||
for (let xx = Math.round(cx - r); xx <= cx + r; xx++) {
|
||||
if (xx < 0 || yy < 0 || xx >= W || yy >= H) continue;
|
||||
if ((xx - cx) ** 2 + (yy - cy) ** 2 > r * r) continue;
|
||||
const o = (yy * W + xx) * 3;
|
||||
img[o] = c[0]; img[o + 1] = c[1]; img[o + 2] = c[2];
|
||||
}
|
||||
}
|
||||
};
|
||||
rect(0, 0, W, H, BG);
|
||||
|
||||
const bw = view.board.width, bh = view.board.height;
|
||||
const cell = Math.floor(Math.min((W - 120) / bw, (H - 80) / bh));
|
||||
const ox = Math.round((W - bw * cell) / 2);
|
||||
const oy = Math.round((H - bh * cell) / 2);
|
||||
const px = (cx: number, cy: number) => [ox + cx * cell, oy + cy * cell] as const;
|
||||
const line = Math.max(3, Math.round(cell * 0.1));
|
||||
|
||||
// The rooms of the maze.
|
||||
const has = (cx: number, cy: number) => !!view.board.cells[`${cx},${cy}`];
|
||||
for (const k of Object.keys(view.board.cells)) {
|
||||
const [cx, cy] = k.split(",").map(Number) as [number, number];
|
||||
const [x, y] = px(cx, cy);
|
||||
rect(x, y, cell, cell, CELL);
|
||||
rect(x, y, cell, 1, CELL_LINE);
|
||||
rect(x, y, 1, cell, CELL_LINE);
|
||||
}
|
||||
|
||||
// Home bases wear their owner's color as a floor border.
|
||||
for (const p of view.players) {
|
||||
if (!p.home) continue;
|
||||
const [x, y] = px(p.home.x, p.home.y);
|
||||
const c = PLAYER[p.colorIndex] ?? WALL;
|
||||
const t = Math.max(2, Math.round(cell * 0.08));
|
||||
rect(x + 2, y + 2, cell - 4, t, c);
|
||||
rect(x + 2, y + cell - 2 - t, cell - 4, t, c);
|
||||
rect(x + 2, y + 2, t, cell - 4, c);
|
||||
rect(x + cell - 2 - t, y + 2, t, cell - 4, c);
|
||||
}
|
||||
|
||||
// The floor's furniture: filled stone reads solid; other hazards dot.
|
||||
for (const [k, content] of Object.entries(view.squareContents)) {
|
||||
const [cx, cy] = k.split(",").map(Number) as [number, number];
|
||||
const [x, y] = px(cx, cy);
|
||||
if (content.kind === "stone") rect(x + 1, y + 1, cell - 2, cell - 2, STONE);
|
||||
else disc(x + cell / 2, y + cell / 2, cell * 0.16, HAZARD);
|
||||
}
|
||||
|
||||
// Interior walls, doors, and fire, on their edges.
|
||||
for (const [k, e] of Object.entries(view.board.edges)) {
|
||||
if (e === "open") continue;
|
||||
const [kind, coords] = k.split(":") as [string, string];
|
||||
const [ex, ey] = coords.split(",").map(Number) as [number, number];
|
||||
const c = e === "door" ? DOOR : e === "firewall" ? FIRE : WALL;
|
||||
if (kind === "V") {
|
||||
const [x, y] = px(ex + 1, ey);
|
||||
rect(x - line / 2, y, line, cell, c);
|
||||
} else {
|
||||
const [x, y] = px(ex, ey + 1);
|
||||
rect(x, y - line / 2, cell, line, c);
|
||||
}
|
||||
}
|
||||
|
||||
// The rim: every open side facing nothing is a wall, except warp mouths.
|
||||
const mouth = new Set(view.board.warps.map((w) => `${w.from.cell.x},${w.from.cell.y}:${w.from.side}`));
|
||||
for (const k of Object.keys(view.board.cells)) {
|
||||
const [cx, cy] = k.split(",").map(Number) as [number, number];
|
||||
const [x, y] = px(cx, cy);
|
||||
const side = (missing: boolean, sx: number, sy: number, w: number, h: number, s: string) => {
|
||||
if (!missing) return;
|
||||
rect(sx, sy, w, h, mouth.has(`${cx},${cy}:${s}`) ? WARP : WALL);
|
||||
};
|
||||
side(!has(cx + 1, cy), x + cell - line / 2, y, line, cell, "E");
|
||||
side(!has(cx - 1, cy), x - line / 2, y, line, cell, "W");
|
||||
side(!has(cx, cy + 1), x, y + cell - line / 2, cell, line, "S");
|
||||
side(!has(cx, cy - 1), x, y - line / 2, cell, line, "N");
|
||||
}
|
||||
|
||||
// Loose treasures glint gold.
|
||||
for (const t of view.treasures) {
|
||||
if (!t.position || t.carriedBy) continue;
|
||||
const [x, y] = px(t.position.x, t.position.y);
|
||||
rect(x + cell * 0.6, y + cell * 0.6, cell * 0.25, cell * 0.25, TREASURE);
|
||||
}
|
||||
|
||||
// Creatures crouch dark; wizards stand in their colors.
|
||||
for (const c of view.creatures) {
|
||||
const [x, y] = px(c.position.x, c.position.y);
|
||||
disc(x + cell * 0.3, y + cell * 0.68, cell * 0.18, CREATURE);
|
||||
}
|
||||
const standing = new Map<string, number>();
|
||||
for (const p of view.players) {
|
||||
if (!p.alive) continue;
|
||||
const key = `${p.position.x},${p.position.y}`;
|
||||
const n = standing.get(key) ?? 0;
|
||||
standing.set(key, n + 1);
|
||||
const [x, y] = px(p.position.x, p.position.y);
|
||||
const cx = x + cell / 2 + (n - 0.5) * cell * 0.16;
|
||||
disc(cx, y + cell * 0.42, cell * 0.26, PLAYER[p.colorIndex] ?? WALL);
|
||||
disc(cx, y + cell * 0.42, cell * 0.26 - 2, PLAYER[p.colorIndex] ?? WALL);
|
||||
}
|
||||
|
||||
return encodePng(W, H, img);
|
||||
}
|
||||
@@ -20,8 +20,9 @@ import {
|
||||
type GameState,
|
||||
type GameView,
|
||||
type PlayerId,
|
||||
CURRENT_RULES_REV,
|
||||
} from "@wizwar/engine";
|
||||
import { appendLine, ensureDataDir, readAllRooms, roomFileExists, type RoomLine } from "./store";
|
||||
import { appendLine, archiveRoomFile, ensureDataDir, readAllRooms, roomFileExists, type RoomLine } from "./store";
|
||||
import { recordRoom } from "./stats";
|
||||
|
||||
export interface LoggedCommand {
|
||||
@@ -53,9 +54,6 @@ export interface Room {
|
||||
|
||||
const rooms = new Map<string, Room>();
|
||||
|
||||
/** Rules revision new games are dealt under (stored games keep their own). */
|
||||
const RULES_REV = 14;
|
||||
|
||||
const ROOM_CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
|
||||
/** Tokens live hashed at rest (memory and disk); clients hold the raw form. */
|
||||
@@ -91,6 +89,11 @@ export function roomCount(): number {
|
||||
return rooms.size;
|
||||
}
|
||||
|
||||
/** Every restored, still-running room — so boot can wake their bot pumps. */
|
||||
export function runningRooms(): Room[] {
|
||||
return [...rooms.values()].filter((r) => r.state && r.state.phase === "playing");
|
||||
}
|
||||
|
||||
export function createRoom(hostId: PlayerId): { room: Room; token: string } {
|
||||
const token = randomBytes(16).toString("hex");
|
||||
const room: Room = {
|
||||
@@ -145,6 +148,33 @@ export function joinRoom(
|
||||
return { token: fresh };
|
||||
}
|
||||
|
||||
/** The host shows an unclaimed (or unwanted) seat the door — lobby only:
|
||||
* once the deal happens, every seat is a player in the game's record. */
|
||||
export function kickSeat(room: Room, byId: PlayerId, name: PlayerId): string | null {
|
||||
if (byId !== room.hostId) return "only the host may clear a seat";
|
||||
if (room.state) return "the game has started — seats are settled";
|
||||
if (name === room.hostId) return "the host cannot kick themselves — abandon the room instead";
|
||||
if (!room.players.includes(name)) return "no such seat";
|
||||
room.players = room.players.filter((p) => p !== name);
|
||||
room.tokens.delete(name);
|
||||
room.bots.delete(name);
|
||||
room.colorChoices.delete(name);
|
||||
appendLine(room.id, { kind: "kick", name, at: new Date().toISOString() });
|
||||
recordRoom(room);
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The host dissolves the room: a lobby that never dealt, or a finished
|
||||
* game done being remembered. The ledger is archived, never deleted. */
|
||||
export function abandonRoom(room: Room, byId: PlayerId): string | null {
|
||||
if (byId !== room.hostId) return "only the host may abandon the room";
|
||||
if (room.state && room.state.phase === "playing") return "the game is still being played";
|
||||
appendLine(room.id, { kind: "abandon", by: byId, at: new Date().toISOString() });
|
||||
archiveRoomFile(room.id);
|
||||
rooms.delete(room.id);
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Everyone gets their chosen standee; the undecided get the first free one. */
|
||||
export function resolveColors(room: Room): number[] {
|
||||
const taken = new Set<number>();
|
||||
@@ -193,9 +223,9 @@ function startInMemory(room: Room, expansion: boolean, colors?: number[], deckRe
|
||||
export function startGame(room: Room, expansion: boolean): { events: GameEvent[] } | { error: string } {
|
||||
if (room.state) return { error: "already started" };
|
||||
const colors = resolveColors(room);
|
||||
const result = startInMemory(room, expansion, colors, RULES_REV);
|
||||
const result = startInMemory(room, expansion, colors, CURRENT_RULES_REV);
|
||||
if ("error" in result) return result;
|
||||
appendLine(room.id, { kind: "start", expansion, colors, deckRev: RULES_REV });
|
||||
appendLine(room.id, { kind: "start", expansion, colors, deckRev: CURRENT_RULES_REV });
|
||||
recordRoom(room);
|
||||
return result;
|
||||
}
|
||||
@@ -270,6 +300,7 @@ function actingSeat(room: Room): PlayerId | null {
|
||||
const s = room.state;
|
||||
if (!s || s.phase !== "playing") return null;
|
||||
return (
|
||||
s.wardPending?.ownerId ??
|
||||
s.stack?.waitingOn ??
|
||||
s.pendingDiscard ??
|
||||
s.chaosPending?.queue[0] ??
|
||||
@@ -282,17 +313,28 @@ function actingSeat(room: Room): PlayerId | null {
|
||||
* One automaton command, if the maze is waiting on clockwork. Null when a
|
||||
* human holds the floor (or the game is over, or the clockwork is wedged).
|
||||
*/
|
||||
export function driveOneAutomaton(room: Room): { seat: PlayerId; events: GameEvent[] } | null {
|
||||
export function driveOneAutomaton(
|
||||
room: Room,
|
||||
): { seat: PlayerId; events: GameEvent[]; hesitated?: true } | null {
|
||||
const seat = actingSeat(room);
|
||||
if (!seat || !room.bots.has(seat)) return null;
|
||||
const view = viewFor(room.state!, seat);
|
||||
const bot = room.bots.get(seat);
|
||||
const chosen = automatonCommand(view, bot?.style, bot?.tier);
|
||||
let hesitated: true | undefined;
|
||||
let r = runCommand(room, seat, chosen ?? automatonFallback(view, bot?.tier));
|
||||
if ("error" in r) {
|
||||
// A refused choice retries with the fallback — unless the fallback IS
|
||||
// what just failed — then burns down the ladder to endTurn and pass.
|
||||
if (chosen) r = runCommand(room, seat, automatonFallback(view, bot?.tier));
|
||||
// The refusal is remembered: a brain whose choice the engine rejects
|
||||
// is a bug in the brain, and the table deserves to see the stumble
|
||||
// rather than an unexplained idle turn.
|
||||
if (chosen) {
|
||||
hesitated = true;
|
||||
console.warn(
|
||||
`automaton ${seat} hesitated in ${room.id}: ${JSON.stringify(chosen)} refused (${r.error})`);
|
||||
r = runCommand(room, seat, automatonFallback(view, bot?.tier));
|
||||
}
|
||||
if ("error" in r) r = runCommand(room, seat, { type: "endTurn", draw: 0 });
|
||||
if ("error" in r) r = runCommand(room, seat, { type: "pass" });
|
||||
if ("error" in r) {
|
||||
@@ -300,7 +342,7 @@ export function driveOneAutomaton(room: Room): { seat: PlayerId; events: GameEve
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return { seat, events: r.events };
|
||||
return { seat, events: r.events, ...(hesitated ? { hesitated } : {}) };
|
||||
}
|
||||
|
||||
export interface GameSummary {
|
||||
@@ -355,6 +397,12 @@ export function viewForPlayer(room: Room, playerId: PlayerId): GameView | null {
|
||||
return room.state ? viewFor(room.state, playerId) : null;
|
||||
}
|
||||
|
||||
/** The Peanut Gallery's viewer id: the empty name can never hold a seat
|
||||
* (joins reject blank names), so a view built for it shows public knowledge
|
||||
* only — no hand, no ward, no ambushes, no boobytrap truths — and event
|
||||
* redaction drops everything marked visibleTo a player. */
|
||||
export const SPECTATOR: PlayerId = "";
|
||||
|
||||
export interface CatchUpStep {
|
||||
seq: number;
|
||||
actor: PlayerId;
|
||||
@@ -370,7 +418,10 @@ export interface CatchUpStep {
|
||||
*/
|
||||
export function catchUpSteps(room: Room, playerId: PlayerId, sinceSeq: number, full = false): CatchUpStep[] | { error: string } {
|
||||
if (!room.state) return { error: "game not started" };
|
||||
if (!room.players.includes(playerId)) return { error: "you hold no seat in this room" };
|
||||
// The SPECTATOR builds whole-game share pages: public knowledge, no seat.
|
||||
if (playerId !== SPECTATOR && !room.players.includes(playerId)) {
|
||||
return { error: "you hold no seat in this room" };
|
||||
}
|
||||
if (full && room.state.phase !== "finished") return { error: "full replays wait for the game to finish" };
|
||||
const MAX_STEPS = 200;
|
||||
const from = full ? 0 : Math.max(sinceSeq, room.log.length - MAX_STEPS);
|
||||
@@ -402,6 +453,87 @@ export function redactFor(events: GameEvent[], playerId: PlayerId): GameEvent[]
|
||||
return events.map((e) => redactEvent(e, playerId)).filter((e): e is GameEvent => e !== null);
|
||||
}
|
||||
|
||||
/** The events that begin a turn — the client's chronicle counts these
|
||||
* identically, so a turn number names the same stretch on both ends. */
|
||||
const TURN_BOUNDARY = new Set(["turnStarted", "extraTurnStarted", "turnSkipped"]);
|
||||
|
||||
export interface MomentReel {
|
||||
steps: CatchUpStep[];
|
||||
/** The wizard whose turn this is — the reel's eyes. */
|
||||
owner: PlayerId;
|
||||
round: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* One turn's reel: every command whose events touch turn `turnIndex`
|
||||
* (0-counted across boundary events). A command that ends one turn and
|
||||
* starts the next belongs to both, so a reel opens with the blow that
|
||||
* began it and closes on the handover. The owner comes from the very
|
||||
* boundary that opened the turn — which for turn 0 lives in the DEAL,
|
||||
* before any command, so no scan of the steps could find it.
|
||||
*/
|
||||
export function momentSteps(room: Room, playerId: PlayerId, turnIndex: number): MomentReel | { error: string } {
|
||||
if (!room.state) return { error: "game not started" };
|
||||
// The SPECTATOR builds share pages: public knowledge only, no seat.
|
||||
if (playerId !== SPECTATOR && !room.players.includes(playerId)) {
|
||||
return { error: "you hold no seat in this room" };
|
||||
}
|
||||
const MAX_STEPS = 80;
|
||||
const { state: fresh, events: dealt } = createGame(room.state.config);
|
||||
let current = fresh;
|
||||
// The deal's own events open the first turn — count them so turn
|
||||
// numbers match the client chronicle's.
|
||||
let counter = -1;
|
||||
let owner: PlayerId | null = null;
|
||||
let round = 0;
|
||||
const bump = (e: GameEvent) => {
|
||||
if (!TURN_BOUNDARY.has(e.type)) return;
|
||||
counter++;
|
||||
if (counter === turnIndex && owner === null && "player" in e) {
|
||||
owner = (e as { player: PlayerId }).player;
|
||||
if ("round" in e) round = (e as { round: number }).round;
|
||||
}
|
||||
};
|
||||
for (const e of dealt) bump(e);
|
||||
const steps: CatchUpStep[] = [];
|
||||
for (const entry of room.log) {
|
||||
const result = applyCommand(current, entry.playerId, entry.command);
|
||||
if (!result.ok) return { error: `replay diverged at seq ${entry.seq}` };
|
||||
current = result.state;
|
||||
const before = counter;
|
||||
// The straddle commands hold more than this turn: the opener carries
|
||||
// the previous wizard's last breaths, the closer the NEXT wizard's
|
||||
// first. Trim both so the reel is exactly one turn — it opens on
|
||||
// "X's turn begins" and stops at X's turnEnded.
|
||||
let sliceStart = 0;
|
||||
let sliceEnd = result.events.length;
|
||||
result.events.forEach((e, i) => {
|
||||
if (!TURN_BOUNDARY.has(e.type)) return;
|
||||
bump(e);
|
||||
if (counter === turnIndex && before < turnIndex) sliceStart = i;
|
||||
if (counter === turnIndex + 1 && sliceEnd === result.events.length) sliceEnd = i;
|
||||
});
|
||||
if (before > turnIndex) break;
|
||||
if (before <= turnIndex && turnIndex <= counter) {
|
||||
const kept = result.events.slice(sliceStart, sliceEnd);
|
||||
const prevAt = entry.seq > 0 ? room.log[entry.seq - 1]!.at : "";
|
||||
const said = room.chat
|
||||
.filter((c) => c.at > prevAt && c.at <= entry.at)
|
||||
.map((c) => ({ player: c.player, text: c.text }));
|
||||
steps.push({
|
||||
seq: entry.seq,
|
||||
actor: entry.playerId,
|
||||
events: redactFor(kept, playerId),
|
||||
view: viewFor(current, playerId),
|
||||
...(said.length > 0 ? { chat: said } : {}),
|
||||
});
|
||||
if (steps.length >= MAX_STEPS) break;
|
||||
}
|
||||
}
|
||||
if (steps.length === 0) return { error: "no such turn yet" };
|
||||
return { steps, owner: owner ?? steps[steps.length - 1]!.actor, round };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Seat transfers: a spoken-word one-time code hands a seat to another device.
|
||||
// Ephemeral by design — a server restart voids pending codes, never seats.
|
||||
@@ -502,8 +634,14 @@ export function loadPersistedRooms(): void {
|
||||
chat: [],
|
||||
bots: new Map(),
|
||||
};
|
||||
if (lines.some((l) => l.kind === "abandon")) continue;
|
||||
for (const line of lines.slice(1)) {
|
||||
if (line.kind === "join") {
|
||||
if (line.kind === "kick") {
|
||||
room.players = room.players.filter((p) => p !== line.name);
|
||||
room.tokens.delete(line.name);
|
||||
room.bots.delete(line.name);
|
||||
room.colorChoices.delete(line.name);
|
||||
} else if (line.kind === "join") {
|
||||
if (line.bot) {
|
||||
room.players.push(line.name);
|
||||
room.bots.set(line.name, {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// Share links: a minted slug names one turn of one game, and anyone
|
||||
// holding it may watch that turn — spectator-redacted, nothing else of
|
||||
// the game visible. Shares persist beside the rooms and survive restarts.
|
||||
|
||||
import { appendFileSync, existsSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { randomInt } from "node:crypto";
|
||||
import { statsDir } from "./store";
|
||||
|
||||
export interface Share {
|
||||
id: string;
|
||||
roomId: string;
|
||||
turn: number;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
const SHARE_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
|
||||
const SHARE_ID_LENGTH = 10; // 31^10 ≈ 8×10^14 — unguessable, typeable
|
||||
|
||||
const shares = new Map<string, Share>();
|
||||
|
||||
function sharesFile(): string {
|
||||
return join(statsDir(), "shares.jsonl");
|
||||
}
|
||||
|
||||
export function loadShares(): void {
|
||||
const file = sharesFile();
|
||||
if (!existsSync(file)) return;
|
||||
for (const line of readFileSync(file, "utf8").trim().split("\n")) {
|
||||
if (!line) continue;
|
||||
try {
|
||||
const s = JSON.parse(line) as Share;
|
||||
if (s.id) shares.set(s.id, s);
|
||||
} catch {
|
||||
// A torn tail line loses one share, never the server.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function mintShare(roomId: string, turn: number): Share {
|
||||
// One link per (room, turn): sharing the same turn twice hands back
|
||||
// the same slug, so a re-share never splits an audience.
|
||||
for (const s of shares.values()) {
|
||||
if (s.roomId === roomId && s.turn === turn) return s;
|
||||
}
|
||||
let id = "";
|
||||
for (let i = 0; i < SHARE_ID_LENGTH; i++) {
|
||||
id += SHARE_ALPHABET[randomInt(SHARE_ALPHABET.length)];
|
||||
}
|
||||
const share: Share = { id, roomId, turn, createdAt: new Date().toISOString() };
|
||||
shares.set(id, share);
|
||||
appendFileSync(sharesFile(), JSON.stringify(share) + "\n", "utf8");
|
||||
return share;
|
||||
}
|
||||
|
||||
export function getShare(id: string): Share | undefined {
|
||||
return shares.get(id);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
// command. Because the engine is deterministic, replaying a file rebuilds
|
||||
// the exact game state — server restarts lose nothing.
|
||||
|
||||
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface RoomMetaLine {
|
||||
@@ -58,7 +58,20 @@ export interface ChatLine {
|
||||
at: string;
|
||||
}
|
||||
|
||||
export type RoomLine = RoomMetaLine | JoinLine | StartLine | CommandLine | ChatLine;
|
||||
export interface KickLine {
|
||||
kind: "kick";
|
||||
/** The seat the host removed from an unstarted room. */
|
||||
name: string;
|
||||
at: string;
|
||||
}
|
||||
|
||||
export interface AbandonLine {
|
||||
kind: "abandon";
|
||||
by: string;
|
||||
at: string;
|
||||
}
|
||||
|
||||
export type RoomLine = RoomMetaLine | JoinLine | StartLine | CommandLine | ChatLine | KickLine | AbandonLine;
|
||||
|
||||
const DATA_DIR = process.env.WIZWAR_DATA_DIR ?? join(process.cwd(), "data", "rooms");
|
||||
|
||||
@@ -103,3 +116,13 @@ export function readAllRooms(): Map<string, RoomLine[]> {
|
||||
}
|
||||
return rooms;
|
||||
}
|
||||
|
||||
/** Retire an abandoned room's ledger to the graveyard — never deleted,
|
||||
* only moved out of the living rooms directory. */
|
||||
export function archiveRoomFile(roomId: string): void {
|
||||
const src = fileFor(roomId);
|
||||
if (!existsSync(src)) return;
|
||||
const graveyard = join(DATA_DIR, "..", "rooms-abandoned");
|
||||
mkdirSync(graveyard, { recursive: true });
|
||||
renameSync(src, join(graveyard, `${roomId}.${Date.now()}.jsonl`));
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 81 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 237 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 111 KiB |
@@ -0,0 +1,12 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Alter Ego token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Alter Ego</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 52 Q65 40 80 66 Q86 88 67 105 Q45 111 31 90Z" fill="#e7c3a1"/>
|
||||
<path d="M40 73q9 -10 19 0M62 70q8 -7 15 1" fill="none"/><circle cx="53" cy="75" r="2.4" fill="#20251f" stroke="none"/><path d="M64 78q-8 8 3 11q-9 9 -19 2" fill="none"/><path d="M111 52 Q81 40 66 66 Q60 88 79 105 Q101 111 115 90Z" fill="#d9b08e"/>
|
||||
<path d="M106 73q9 -10 19 0M84 70q8 -7 15 1" fill="none"/><circle cx="93" cy="75" r="2.4" fill="#20251f" stroke="none"/><path d="M82 78q8 8 3 11q9 9 19 2" fill="none"/><path d="M69 48q4-12 8 0M47 115q25-14 51 0" fill="none"/><path d="M24 67l-10-6m108 5l9-8" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Boobytrap token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Boobytrap</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M28 105L70 49l43 56Z" fill="#f2ca4f"/><path d="M44 96l26-35 25 35Z" fill="#df5b36"/><path d="M71 70v14m0 7v2" stroke="#fff8da" stroke-width="5"/><path d="M25 62l12 5-9 8m92-11l-11 4 8 9" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Dagger token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Dagger</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M34 111L90 48l12 12-57 60Z" fill="#c9d5d2"/><path d="M87 51l10-13 13 13-10 10Z" fill="#6c5641"/><path d="M75 58l22 22"/><path d="M30 70l-13-5 10-8m82 36l15 3-9 9" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Democratic Monster token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="12" fill="#20251f">Democratic Monster</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M71 120Q28 108 44 72q-18-14 1-25 17-8 26 8 12-23 29-10 14 13-2 29 20 29-27 46Z" fill="#df3f37"/><path d="M43 83l-20 8 18 7m57-16l23 10-21 8" fill="#df3f37"/><circle cx="62" cy="65" r="7" fill="#fff"/><circle cx="82" cy="63" r="7" fill="#fff"/><circle cx="64" cy="66" r="2"/><circle cx="80" cy="64" r="2"/><path d="M56 87q17 13 31-2" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Dimensional Warp token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Dimensional Warp</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="72" cy="80" rx="47" ry="22" fill="#5c369b"/><ellipse cx="72" cy="80" rx="34" ry="14" fill="#e4bdff"/><ellipse cx="72" cy="80" rx="20" ry="7" fill="#252036"/><path d="M22 52q13-14 26-17m72 18q-13-14-27-17M22 108q13 14 27 17m71-17q-13 14-27 17" fill="none" stroke="#7849b1"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Dustcloud token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Dustcloud</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M27 105q-15-17 7-27-9-24 18-24 8-23 30-9 19-10 28 9 24 2 16 25 17 18-5 30-35 15-74-4Z" fill="#68675d"/><path d="M42 80q15-14 27 1m12-12q15-9 26 5m-61 20q17-12 31 2" fill="none" stroke="#989383"/><circle cx="31" cy="117" r="3"/><circle cx="117" cy="118" r="2"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Fire Imp token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Fire Imp</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M71 119q-29-9-26-42-14-16 5-21-2-23 19-12 18-20 24 7 22 8 7 27 8 32-29 41Z" fill="#e8494a"/><path d="M52 52L39 34l23 12m29 4l16-18-6 25" fill="#e8494a"/><circle cx="63" cy="70" r="5" fill="#ffe15a"/><circle cx="84" cy="68" r="5" fill="#ffe15a"/><path d="M59 91q14 10 28-3" fill="none"/><path d="M42 102l-20 13m79-14l20 13" fill="none" stroke="#e8494a" stroke-width="7"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Killer Ooze token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Killer Ooze</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M26 115q-2-24 15-27-10-29 12-33 7-29 26-5 26-15 30 17 21 14 4 37 3 21-25 14-19 13-32-2-17 11-30-1Z" fill="#16834f"/><ellipse cx="60" cy="73" rx="10" ry="14" fill="#fff"/><ellipse cx="86" cy="72" rx="10" ry="14" fill="#fff"/><circle cx="64" cy="78" r="3"/><circle cx="82" cy="78" r="3"/><path d="M48 96q25-18 48 1l-8 15-8-11-9 12-8-12-8 11Z" fill="#173b2a"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Magic Stone token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Magic Stone</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M72 46l25 23-11 37-32 6-18-31 14-30Z" fill="#d72e78"/><path d="M50 51l20 31 27-13M70 82l16 24M37 81l33 1" fill="none" stroke="#ff83b5"/><path d="M28 55l-12-13m95 16l15-12M25 109l-13 12m100-13l14 12" fill="none" stroke="#29252d" stroke-width="5"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Magic Wand token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Magic Wand</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M37 111L94 50" stroke="#4a3a2a" stroke-width="9"/><path d="M34 114L91 53" stroke="#d8c6a7" stroke-width="3"/><circle cx="99" cy="43" r="14" fill="#f0c83e"/><path d="M99 23v-9m0 58v-9M79 43h-9m58 0h-9M85 29l-7-7m42 42l-7-7m0-28l7-7M85 57l-7 7" fill="none" stroke="#e7a81f"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Master Key token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Master Key</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="91" cy="63" r="27" fill="#d6d4c8"/><circle cx="91" cy="63" r="11" fill="#f4efd9"/><path d="M72 79L32 119" stroke="#c9c7bc" stroke-width="11"/><path d="M42 109l-13-13m24 2l-12-12"/><path d="M76 45l30 31M75 78l33-31" fill="none" stroke="#83857e"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Pit token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Pit</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M24 77l55-28 43 28-52 42Z" fill="#45484b"/><path d="M35 77l43-19 32 19-40 29Z" fill="#171b20"/><path d="M35 77l35 29m8-48l-8 48m40-29l-40 29" fill="none" stroke="#737980"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Rock token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Rock</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M30 112l8-46 26-22 34 10 18 38-22 28-43 1Z" fill="#666c68"/><path d="M38 66l30 12 30-24M68 78l-17 43m17-43l26 42" fill="none" stroke="#929994"/><ellipse cx="73" cy="122" rx="46" ry="6" fill="#252923" opacity=".25" stroke="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Rosebush token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Rosebush</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M29 114q8-47 40-40-4-31 19-16 29-5 29 28 21 24-11 34Z" fill="#237148"/><path d="M42 111l52-47M50 72l45 39" fill="none" stroke="#174e32" stroke-width="5"/><g fill="#d6336c"><circle cx="45" cy="83" r="8"/><circle cx="78" cy="61" r="8"/><circle cx="102" cy="88" r="9"/><circle cx="75" cy="103" r="7"/></g></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Safe token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Safe</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M38 53l61-12 14 71-66 11Z" fill="#767e80"/><path d="M51 62l40-7 8 49-43 8Z" fill="#aab1b0"/><circle cx="74" cy="82" r="13" fill="none"/><path d="M74 69v26M61 82h26m-13 0l11-8m-11 8l-9 10" fill="none"/><path d="M45 121l-2 8m62-18l4 9"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Shadow token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Shadow</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M34 116q8-33 26-39-11-28 13-37 23 8 14 34 23 12 25 41Z" fill="#172a27"/><path d="M37 88L17 75m25 26l-23 8m88-20l20-13m-17 26l20 8" fill="none" stroke="#172a27" stroke-width="8"/><path d="M65 61l7-4 7 4" fill="none" stroke="#d6f2cb"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Skeleton token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Skeleton</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="72" cy="62" r="22" fill="#eee8d5"/><circle cx="64" cy="58" r="6"/><circle cx="81" cy="58" r="6"/><path d="M69 71l3-6 4 6m-14 8h21M72 84v33M53 94l19 9 20-10M72 117l-17 13m17-13l18 13" fill="none"/><path d="M30 62l-10-9m94 10l11-11M29 98l-13 7m99-7l14 8" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Slime token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Slime</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M25 56q23-14 48-3 24-12 47 4v46q-8 19-22 3-12 26-27 1-14 19-25 0-13 13-21-3Z" fill="#0e754a"/><path d="M25 56q23 9 48-3 24 10 47 4" fill="none" stroke="#55ac76"/><path d="M43 103v18m34-15v25m27-29v17" fill="none" stroke="#0e754a" stroke-width="8"/><ellipse cx="73" cy="129" rx="51" ry="7" fill="#3a9667" opacity=".6"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Solid Stone token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Solid Stone</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M24 111l9-48 19-17 47 2 20 18-5 48Z" fill="#9da09a"/><path d="M33 63l28 9 38-24M61 72l-7 41m7-41l29 42m9-66l-9 66" fill="none" stroke="#666a66"/><path d="M25 111q44 8 89 3" fill="none"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Tacks token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Tacks</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><g fill="#c9c7b9"><path d="M35 60l15 7-11 5 2 28-7-26-12 1Z"/><path d="M82 50l16 8-12 5 2 28-7-26-12 1Z"/><path d="M61 91l15 7-11 5 2 27-7-25-12 1Z"/><path d="M108 84l14 7-10 5 1 25-6-23-11 1Z"/></g><path d="M21 112q50 12 107 1" fill="none" stroke="#9b7d4b"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Thorn Bush token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Thorn Bush</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M27 111q4-43 34-35-2-31 19-16 27-11 27 19 26 15 8 39Z" fill="#247348"/><path d="M39 106l55-41M47 73l51 40" fill="none" stroke="#174b31" stroke-width="5"/><path d="M41 90l-13-8m28 3l-5-16m33 11l8-16m-2 34l18-4m-50 17l-7 16" fill="none" stroke="#eee8d5"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#329664"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/><circle cx="72" cy="78" r="7" fill="#ffd84d"/><path d="M43 91l-12 17m69-17l13 16M56 91l-5 24m37-24l6 23" fill="none" stroke="#d69d23"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#e34a44"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#b72d6b"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#6c3eae"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/><circle cx="72" cy="78" r="7" fill="#ffd84d"/><path d="M43 91l-12 17m69-17l13 16M56 91l-5 24m37-24l6 23" fill="none" stroke="#d69d23"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#2389a9"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/><circle cx="72" cy="78" r="7" fill="#ffd84d"/><path d="M43 91l-12 17m69-17l13 16M56 91l-5 24m37-24l6 23" fill="none" stroke="#d69d23"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Treasure token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Treasure</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M35 67q37-25 74 0v20H35Z" fill="#e3bd26"/><path d="M31 87h82v34H31Z" fill="#6d4a2b"/><path d="M35 93h74M51 88v32m42-32v32" fill="none" stroke="#e8c068"/><rect x="65" y="84" width="14" height="18" rx="2" fill="#f1c64d"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Troll token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Troll</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M30 112q8-46 30-45-9-25 14-31 27 3 18 31 24 3 25 44Z" fill="#d4d5b8"/><path d="M49 53l-17-15 7 27m56-12l18-15-8 28" fill="#d4d5b8"/><circle cx="62" cy="71" r="4"/><circle cx="85" cy="71" r="4"/><path d="M49 91q24 16 48 0" fill="none"/><path d="M52 94l7 11 7-8 8 12 8-12 8 9 7-13" fill="#fff"/><path d="M48 47q24-25 50 0" fill="none" stroke="#64328f" stroke-width="10"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#23764b"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L38 25 38 61Z" fill="#23764b"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 5 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#e9e2c8" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#23764b"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#d54835"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L45 25 38 61Z" fill="#d54835"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 6 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#7e2b1f" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#d54835"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#b62f75"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L52 25 38 61Z" fill="#b62f75"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 7 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#9c235d" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#b62f75"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#29345f"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L38 25 38 61Z" fill="#29345f"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 5 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#25282b" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#29345f"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#1683a6"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L45 25 38 61Z" fill="#1683a6"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 6 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#e7e2cf" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#1683a6"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wizard token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wizard</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M41 124q31-28 62 0" fill="#e0a733"/><ellipse cx="72" cy="76" rx="25" ry="30" fill="#edc9a8"/>
|
||||
<path d="M46 66q25-32 51 0v-8L52 25 38 61Z" fill="#e0a733"/><path d="M49 69q23-14 47 0" fill="none" stroke="#f4d467" stroke-width="4"/>
|
||||
<path d="M52 74q8-11 16 0m9 0q8-11 15 0" fill="none"/><circle cx="63" cy="78" r="2.3"/><circle cx="84" cy="78" r="2.3"/>
|
||||
<path d="M73 81q-7 9 2 11m-12 8q11 7 22-1" fill="none"/><path d="M48 73q-7 21 8 35M96 71q8 23-9 38" fill="none" stroke="#292723" stroke-width="8"/>
|
||||
<path d="M40 56l-10-7m72 9l12-7M35 84l-13 3m83-2l15 4" fill="none" stroke="#e0a733"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 144 150" role="img" aria-label="Wraith token">
|
||||
<defs>
|
||||
<filter id="w"><feTurbulence baseFrequency=".035" numOctaves="2" seed="4" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale=".65"/></filter>
|
||||
<filter id="s"><feGaussianBlur stdDeviation="2"/></filter>
|
||||
<pattern id="paper" width="12" height="12" patternUnits="userSpaceOnUse"><rect width="12" height="12" fill="#f4efd9"/><circle cx="2" cy="4" r=".45" fill="#c8bfa4" opacity=".28"/><path d="M1 10l7-1" stroke="#d8cfb8" stroke-width=".35" opacity=".35"/></pattern>
|
||||
</defs>
|
||||
<rect x="2" y="2" width="140" height="146" rx="3" fill="url(#paper)" stroke="#242822" stroke-width="2"/>
|
||||
<text x="72" y="19" text-anchor="middle" font-family="Trebuchet MS,Arial,sans-serif" font-weight="700" font-size="14" fill="#20251f">Wraith</text>
|
||||
<g filter="url(#w)" stroke="#252923" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M72 38q24 2 25 30 22 9 18 32-13-7-20 7-9 25-23 30-15-7-22-30-8-15-22-7-4-23 19-32 0-27 25-30Z" fill="#172521"/><circle cx="64" cy="63" r="4" fill="#f5edc4" stroke="none"/><circle cx="81" cy="63" r="4" fill="#f5edc4" stroke="none"/><path d="M46 83L20 96m79-13l25 13" fill="none" stroke="#172521" stroke-width="13"/></g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 73 KiB |