diff --git a/QUICKSTART.md b/QUICKSTART.md index 358216e..34c24ab 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -5,9 +5,9 @@ ruling, are in [rules.md](rules.md). ## The Idea -You and your opponent are hackers fighting over a network. Your **Avatars** move out from your -starting Server and capture **Server locations** on a shared grid. Every capture earns **RAM**, which -you spend on cards that upgrade your Avatars, trap your locations and disrupt your opponent. +You and your opponent are hackers fighting over a network. Your **Anomalies** move out from your +starting Server and capture **Server locations** on a shared grid. Every capture earns **Bandwidth**, which +you spend on cards that upgrade your Anomalies, trap your locations and disrupt your opponent. **Win by controlling 10 Server locations.** Your starting Server doesn't count. @@ -15,10 +15,10 @@ you spend on cards that upgrade your Avatars, trap your locations and disrupt yo Each player needs: -- **4 Avatars** +- **4 Anomalies** - **20 Servers**, kept as a separate pile - A **45-card deck** of Executions, Hardware and Programs, with at most 2 copies of any card -- A few **d6**, and something to track RAM +- A few **d6**, and something to track Bandwidth (counted in **Gb**) You'll also need the **playmat**, which has 13 locations plus the two starting Servers. @@ -26,22 +26,22 @@ You'll also need the **playmat**, which has 13 locations plus the two starting S | Card | What it is | Where it goes | When you play it | |---|---|---|---| -| **Avatar** | Your units. **Cores** = dice in combat. **Health** = damage it takes to destroy it. **Expansion Slots** = how much Hardware it can hold. Its **Ability** can be used once per round by paying its RAM cost. | Your Avatar slots, then onto locations you control | Free, at the start of your command | +| **Anomaly** | Your units. **Cores** = dice in combat. **Health** = damage it takes to destroy it. **Expansion Slots** = how much Hardware it can hold. Its **Ability** can be used once per round by paying its Bandwidth cost. | Your Anomaly slots, then onto locations you control | Free, at the start of your command | | **Server** | The locations you capture. Each has an ability that helps whoever holds it. | Onto a location when you capture it | Automatically | | **Program** | Buffs and traps for a location | A location you control, 2 at most | During your command | -| **Hardware** | Upgrades for an Avatar | An Avatar in play, up to its Expansion Slots | During your command | +| **Hardware** | Upgrades for an Anomaly | An Anomaly in play, up to its Expansion Slots | During your command | | **Execution** | One-shot tricks, then discarded | Wherever the card says | **Any time**, even in your opponent's command | -Every card except Avatars and Servers costs the **RAM** printed on it. +Every card except Anomalies and Servers costs the **Bandwidth** printed on it. ## Setup -1. Shuffle your 4 Avatars and put them **face down** in your Avatar slots 1–4. Flip **Avatar 1** +1. Shuffle your 4 Anomalies and put them **face down** in your Anomaly slots 1–4. Flip **Anomaly 1** face up. 2. Shuffle your Servers into a face-down pile. Put the top one face down on your starting Server, and reveal it when the game starts. 3. Shuffle your deck and draw **7 cards**. -4. Start with **4 RAM**. +4. Start with **4 Gb**. 5. Pick a first player at random. They lead every round. ## The Board @@ -73,11 +73,11 @@ A1 -----o------ A2 -----o----- A3 - Lines connect the locations. Each `o` is a **gateway**, where Firewalls go. - Each row is a **level**, counted from your side: your first row is Lv 1, the middle row (C) is Lv 3, and the enemy's first row is Lv 5. -- **Unlocking Avatars:** the first time you capture a location of level N, flip Avatar N face up. - Take your second row for Avatar 2, the middle row for Avatar 3, and the enemy's second row for - Avatar 4. A new Avatar can enter play from the next round. +- **Unlocking Anomalies:** the first time you capture a location of level N, flip Anomaly N face up. + Take your second row for Anomaly 2, the middle row for Anomaly 3, and the enemy's second row for + Anomaly 4. A new Anomaly can enter play from the next round. -More Avatars means more actions each round, so pushing forward early matters. +More Anomalies means more actions each round, so pushing forward early matters. ## How a Round Works @@ -87,44 +87,44 @@ Each round, each player gets **2 commands**, and the order snakes the same way e |---|---| | every round | P1, P2, P2, P1 | -**At your first command of each round:** draw a card, then **refresh** your Avatars so they can +**At your first command of each round:** draw a card, then **refresh** your Anomalies so they can act again. **Each command has five steps:** -1. **Place and advance.** Put any of your face-up Avatars on any locations you control, for free. - A damaged Avatar can instead be **recalled** to its slot to heal (it keeps its Hardware, but - that's its placement for the round). Then you may **advance** one Avatar into an **empty or +1. **Place and advance.** Put any of your face-up Anomalies on any locations you control, for free. + A damaged Anomaly can instead be **recalled** to its slot to heal (it keeps its Hardware, but + that's its placement for the round). Then you may **advance** one Anomaly into an **empty or undefended** location next to your territory. 2. **Play cards** from your hand. -3. **Attack.** If you didn't advance, one Avatar may attack a **defended** enemy location next to +3. **Attack.** If you didn't advance, one Anomaly may attack a **defended** enemy location next to the location it's standing on. 4. **Resolve** the capture or combat right away. -5. **Play more cards**, including with the RAM you just earned. +5. **Play more cards**, including with the Bandwidth you just earned. **The key limits:** - Each command gets **one advance or one attack**, not both. -- Each Avatar can advance or attack **once per round**. -- Each location holds 1 of your Avatars. +- Each Anomaly can advance or attack **once per round**. +- Each location holds 1 of your Anomalies. -Your Avatars don't have to walk. Each round you can place them on any location you hold, then +Your Anomalies don't have to walk. Each round you can place them on any location you hold, then step out from your territory. ## Capturing and Combat **Taking an empty or undefended location** needs no fight. Move in, flip the top Server from your -pile onto it, and **gain 4 RAM**, plus any RAM bonus the Server card gives. If the location was the +pile onto it, and **gain 4 Gb**, plus any Bandwidth bonus the Server card gives. If the location was the enemy's, their Server goes to the bottom of their pile and their Programs there are discarded. **Attacking a defended location** means a fight: -1. Each side rolls **1d6 per Core**. Count the Avatar, its Hardware, Programs, effects, and the +1. Each side rolls **1d6 per Core**. Count the Anomaly, its Hardware, Programs, effects, and the Server it's on. 2. **The higher total wins the roll.** The loser takes **damage equal to the difference**. On a tie, nothing happens. -3. Damage stays on an Avatar. When it reaches its **Health**, the Avatar is **destroyed**: it goes - back to its Avatar slot at full Health and discards its Hardware. +3. Damage stays on an Anomaly. When it reaches its **Health**, the Anomaly is **destroyed**: it goes + back to its Anomaly slot at full Health and discards its Hardware. 4. **The location falls** only when its last defender is destroyed. Then the attacker moves in and captures it. Otherwise everyone stays where they are, so a defended location usually takes two or three attacks to take. @@ -137,24 +137,24 @@ Starting Servers can never be attacked. | +1 Core | 75–90% | 5–8 | | +2 Cores | 90–99% | 7–11 | -## RAM +## Bandwidth -- **Earn it** by capturing, which pays 4 RAM every time, including recaptures. -- **Salvage:** discard any card from your hand to gain its printed RAM. You can do this whenever you +- **Earn it** by capturing, which pays 4 Gb every time, including recaptures. +- **Salvage:** discard any card from your hand to gain its printed Bandwidth. You can do this whenever you need to pay for something. -- **Spend it** on cards, Avatar Abilities and Firewalls. +- **Spend it** on cards, Anomaly Abilities and Firewalls. - It carries over between rounds, and there's no cap. ## Firewalls -Firewalls aren't cards. You buy them with RAM and put them on a gateway (`o`) on a line touching one +Firewalls aren't cards. You buy them with Bandwidth and put them on a gateway (`o`) on a line touching one of your locations. A Firewall **blocks all movement and attacks** along its line, for both players. | Level | Cost to place or clear | |---|---| -| Lv 1 | 2 RAM | -| Lv 2 | 4 RAM | -| Lv 3 | 8 RAM | +| Lv 1 | 2 Gb | +| Lv 2 | 4 Gb | +| Lv 3 | 8 Gb | - **Place** Firewalls in steps 2 and 5. Upgrading one costs the full price of the new level. - **Clear** a Firewall before you advance or attack, by paying its current level. The player who @@ -165,27 +165,27 @@ of your locations. A Firewall **blocks all movement and attacks** along its line Say you're the first player, starting at S1: -1. **Your first command.** You don't draw, because you're first in round 1. Place Avatar 1 on S1 and - advance it to **A2**, the only way out. Flip a Server onto A2 and gain 4 RAM, which gives you 8. +1. **Your first command.** You don't draw, because you're first in round 1. Place Anomaly 1 on S1 and + advance it to **A2**, the only way out. Flip a Server onto A2 and gain 4 Gb, which gives you 8. Play a card if you like. -2. **Their two commands.** They draw, place their Avatar on S2, and advance it to E2. Their second - command can play cards, but their only Avatar has already acted this round. -3. **Your second command.** Your Avatar has also acted, so you can only play cards or Firewalls. - Or pass, and save your RAM. +2. **Their two commands.** They draw, place their Anomaly on S2, and advance it to E2. Their second + command can play cards, but their only Anomaly has already acted this round. +3. **Your second command.** Your Anomaly has also acted, so you can only play cards or Firewalls. + Or pass, and save your Bandwidth. 4. **Round 2.** Your opponent leads. When your turn comes, you draw, refresh, and advance into A1, - A3, B1 or B2. **B1 and B2 unlock Avatar 2.** + A3, B1 or B2. **B1 and B2 unlock Anomaly 2.** ## Tips for New Players -- **Grab empty locations early.** They cost nothing to take and pay 4 RAM each. -- **Head for your second row.** Avatar 2 doubles what you can do each round, and it's the biggest +- **Grab empty locations early.** They cost nothing to take and pay 4 Gb each. +- **Head for your second row.** Anomaly 2 doubles what you can do each round, and it's the biggest early swing. -- **Plan both commands.** With one Avatar, your second command can only play cards. Use it to buy +- **Plan both commands.** With one Anomaly, your second command can only play cards. Use it to buy Hardware or set Programs and Firewalls. - **Don't leave fronts empty.** An undefended enemy location can be taken without a fight. Stand - your Avatars where the opponent can reach. + your Anomalies where the opponent can reach. - **Attack with an edge.** One extra Core wins most fights, and Hardware is the easiest way to get it. -- **Salvage freely.** A card you won't use soon is RAM in your hand. +- **Salvage freely.** A card you won't use soon is Bandwidth in your hand. - **Keep an Execution back.** They work in your opponent's command too, often during a fight. ## Reading "Turn" on Cards diff --git a/app-plan.md b/app-plan.md new file mode 100644 index 0000000..e18d8e3 --- /dev/null +++ b/app-plan.md @@ -0,0 +1,318 @@ +# App Plan: Play Files TCG Against the Bot + +_Prepared 2026-09-30 against rules v0.9 and the simulator in `sim/`._ + +> **Status, 2026-09-30: built.** Levels 1 and 2 are in `app/`; see [app/README.md](app/README.md). +> The open decisions in section 7 were given defaults for now: the app runs locally (the build is a +> static site, so it can be hosted later), undo is on only in playtest mode, and the odds preview is +> on, with a setting to turn it off. + +This plan covers a browser app where one person plays a full game of Files TCG against the +simulator's greedy bot. It comes in two levels: + +- **Level 1, the playtest prototype.** Every rule and card works, and the screen is plain. It + replaces paper playtests. +- **Level 2, properly playable.** You act by clicking the board and your cards, which look like the + printed cards. Combat is easy to read, and games can be saved, undone and replayed. Someone who has + read [QUICKSTART.md](QUICKSTART.md) can play without help. + +Online play between two people, sound, mobile layouts and a tutorial are out of scope. Those are +level 3. + +## 1. What the Simulator Already Provides + +The engine in `sim/src/engine.ts` is already built the way a game app needs: + +| Function | What the app uses it for | +| --- | --- | +| `createGame({ pool, decks, seed, rules })` | Starts a game. The same seed always gives the same game. | +| `decider(s)` | Whose decision it is: the human or the bot. | +| `legalActions(s)` | Every legal move right now. The UI only ever picks from this list. | +| `applyAction(s, a)` | Makes the move, then runs the game until the next decision. | +| `viewFor(s, p)` | Player `p`'s view: the opponent's hand, deck, Server pile and face-down Anomalies are hidden. | +| `actionCost(s, a)` | The Gb cost to show on a move. | +| `greedyBot(DEFAULT_GREEDY)` | The opponent. It already only sees its own `viewFor`, so it can't cheat. | +| `winChance(atk, def)` in `odds.ts` | The odds of winning one combat roll, for the attack preview. | +| `checkInvariants(s)` | Catches engine bugs during play. | + +Response windows only stop for a player who actually has an Execution or Ability they could use. +The engine already passes automatically for everyone else. + +**Measured numbers.** These come from 50 greedy-vs-greedy games, counting South as the human: + +| Measure | Value | +| --- | --- | +| Decisions per game for one player | 367, about 10 per command | +| Decisions where the only options are End, Pass or Salvage | 55 | +| Legal moves per decision | 23 on average, 112 at most | +| Response windows reaching you in the bot's command | 43 per game | +| Combat windows (before and after the roll) | 28 when you attack, 26 when the bot attacks | +| Card prompts ("pick one") | 16 per game | +| Bot's slowest move | 1.3 ms | + +What this means for the design: + +- **Speed is not a concern.** The bot can run in the browser, and no server is needed. +- **Click count is the main design problem.** The large number of decisions is why both levels + include step skipping. Level 2 adds settings for when the game stops to let you respond. + +## 2. Architecture + +``` +files-tcg/ + sim/ engine, card scripts, bots (unchanged, apart from section 3) + app/ + index.html + src/ + main.tsx start screen and page shell + match.ts game controller: real state, bot loop, undo stack + describe.ts re-export of sim/src/describe.ts + ui/ board, hand, panels, prompts + vite.config.ts + package.json +``` + +- **Stack: Vite, TypeScript and Preact.** Preact is the only runtime dependency. It's a small React + equivalent, and it's worth having because level 2 has a lot of selection and highlighting state. + Vite serves the sim's `.ts` imports as they are. +- **The app imports the engine from `../sim/src`, and nothing is copied.** Rule changes you test in + the sim appear in the app automatically. The app only breaks if the `Action` or `GameState` shapes + change. +- **Card data is imported live.** The app loads `cards.csv` with Vite's `?raw` import, so card edits + appear on reload. +- **The controller in `match.ts` holds the real state.** Components only receive `viewFor(s, human)`, + so the UI can't show the bot's hand by mistake. +- **Every move is one of the actions from `legalActions`.** The UI filters and labels that list and + never builds an `Action` itself. Illegal moves are therefore impossible, and the rules stay in one + place. + +## 3. Sim Changes Needed First + +These are small, and each keeps `npm test` passing. + +1. **Browser-safe card loading.** `loadCards` reads the file with `node:fs`. Split it into + `parseCards(csvText, sets)` in `cards.ts`, and move the file-reading wrapper into a Node-only + module used by the CLI and tests. +2. **`describeAction(s, a)` in a new `sim/src/describe.ts`.** It gives a readable label for every + action type, for example `Play Execute: Force Reboot on D2 (5 Gb)` or + `Place Firewall Lv 2 on B1–C2 (4 Gb)`. Execution and Ability arguments (target Anomaly, cards, + mode) need labels too. `describeArgs` in `cards/hardware.ts` is a starting point and can be + generalized. Add a test: across fuzz games, every legal action gets a label, and no two actions in + the same decision share one. +3. **Private log lines.** `say()` writes a single public log, and some lines name hidden cards. For + example, "North chooses: Bottom Undefined Behavior and draw again" names a card in North's hand. + Give `say` an optional audience and a public version of the message. Then audit the 92 `say` + calls. + +## 4. Level 1: Playtest Prototype + +**Goal:** a full game against the bot in a browser, on the classic board. Every card works, and the +look is plain. + +``` ++--------------------------------------------------------------------------+ +| NORTH (bot) 12 Gb 6 cards 4/10 locations Anomalies [1][2][■][■] | ++-----------------------------------------------+--------------------------+ +| | Log | +| board (SVG) | - Round 4, command 13 - | +| locations, Servers, Anomalies, gateways | South captures B2 with | +| | Server Farm: +8 Gb | +| hover a location for details | North places a Firewall | +| | ... | ++-----------------------------------------------+--------------------------+ +| SOUTH (you) 16 Gb 5/10 locations Anomalies [1][2][3][■] | +| Hand: [Overclocked CPU 6][Execute: Packet Flood 5][Resource Leech 5] ... | +| Step: Deploy > Play > Attack > Play again [End step] | +| Moves: Place > | Advance > | Play > | Install > | Firewall > | Salvage > | ++--------------------------------------------------------------------------+ +``` + +### Features + +1. **Start screen.** Pick your side (South, North or random) and a seed, which is random by default. + Both decks are random legal decks from `randomDeck`. +2. **Board.** An SVG of the 13 locations and 2 starts, with fixed coordinates for the classic board. + - Each location shows its owner color, level, Server name and Program count. + - Anomalies appear as tokens showing slot, Cores and damage/Health. + - Gateways show their Firewall level. + - Hovering a location shows a details panel: Server text, Programs, and the Anomalies there with + their Hardware. +3. **Player panels** for both sides: + - Gb, cards in hand, deck, discard and Server pile. + - Locations held out of 10. + - The four Anomaly slots: face down or up, in the slot or on a location, damage, Hardware. + - The bot's hand shows only as a count. Its discard pile can be opened. +4. **Hand.** Text cards showing name, kind, type, Gb and text. +5. **Moves panel.** The legal actions are grouped by kind and then by card, and labelled with + `describeAction` and their cost. Clicking one plays it. + - A step bar shows Deploy, Play, Attack, Play again, with an **End step** button. + - An **End command** button repeats End step. It stops early if a prompt or response window comes + up for you. +6. **Prompts.** + - A card prompt (`s.choice` for you) opens a dialog with the prompt and its options. + - A response window shows a banner such as "North attacks D1 — respond?". It lists your possible + responses and a Pass button. +7. **Bot turns.** The bot's moves play one at a time with an adjustable delay from 0 to 1 s, and the + log scrolls with them. +8. **Auto-skip.** Steps where you can only end or salvage are ended for you. This is a setting and + on by default. It saves about 55 clicks a game. +9. **Combat readout.** While a combat is live, it shows attacker and defenders, each side's Cores, + the dice once rolled, the totals and the damage. +10. **Game over.** Shows the winner, the reason and the game stats from `stats.ts`, with **New game** + and **Rematch** (same seed) buttons. +11. **Dev tools.** + - Show the seed. + - Copy the log. + - A toggle that runs `checkInvariants` after every move and shows any errors. + +### Tests + +- A headless test drives `match.ts` with a random "human" for a few hundred games. It checks that no + game gets stuck and the loop always hands control back. +- The `describeAction` label test from section 3. + +### Done when + +You can play a full game on the classic board, start to finish, without opening the browser +console, and both tests pass. + +### Not in level 1 + +Art and card templates, acting by clicking the board, animations, undo, save, other boards, rule +variants and deck choice. + +### Effort + +| Work | Days | +| --- | --- | +| Sim changes (section 3) | 0.5–1 | +| App scaffold, controller, bot loop | 0.5 | +| Board, panels, hand | 1 | +| Moves panel, prompts, windows, combat readout, game over | 0.5–1 | +| Controller test and fixes from the first playtests | 0.5 | +| **Total** | **3–4** | + +## 5. Level 2: Properly Playable + +**Goal:** it feels like a digital card game. Each workstream below can ship on its own, in the order +listed. + +### A. Click to act (2–3 days) + +- **Select, then target.** Select a source: a card in hand, an Anomaly, a gateway or an Anomaly + Ability. Its legal targets then light up on the board, and clicking a target plays the move. + - This works by filtering `legalActions` by source, then by target. + - When several moves share a source and target, a small popover picks between them. Examples are + Firewall levels, Sabotage's destroy or disable, and Bit Flip's number. +- **Keep the full move list.** The level 1 moves panel becomes an "All moves" drawer, so anything + the click UI misses is still reachable. +- **Keyboard:** + + | Key | Action | + | --- | --- | + | Space | End step, or Pass | + | Enter | End command | + | Z | Undo | + | Esc | Cancel the selection | + +### B. Real cards (2 days) + +- Render cards in the browser from the Cider templates in `decks/files-deck-1`. + - Use Handlebars with each template's CSS, scoped per template. + - Include the art from the Image column. + - Provide the helpers the templates use (`lowercase`, `eq`, `index`). `index` must return a + SafeString. +- Templates are 750×1050, so show them scaled down, with a hover zoom and right-click to pin. +- On the board, Servers, Programs and Anomalies use compact tokens, and the full card appears on hover. +- Cards without art show a placeholder in the art window. + +### C. Combat and dice (1–2 days) + +- A combat panel breaks down each Anomaly's Cores by source: Anomaly, Hardware, Programs, Server and + temporary modifiers. This needs a breakdown version of `anomalyCores`. +- **Before you attack,** it shows your chance to win the roll from `winChance` and the expected + damage. +- **After the roll,** it shows the dice, totals, damage and any Anomaly destroyed. +- A short dice animation, which can be turned off. + +### D. Stops and pacing (1 day) + +- **Stops setting.** This decides when the game waits for your response: + + | Setting | Behavior | + | --- | --- | + | In combat only | The default. The bot's Executions and Ability uses outside combat pass automatically, which skips about 43 windows a game. | + | Every opponent move | Stops for every response window. | + | Never | Passes every response automatically. | + + A held key overrides the setting for one window. +- Bot speed slider, pause, and step-one-move. +- A status banner shows whose command it is, the step, and any Executions waiting to resolve. + +### E. Information (2 days) + +- **Structured events.** Add events next to the text log, such as capture, damage, card played and + Firewall placed. They drive animations and a filterable log (Combat, Captures, Cards). + - The hooks already fired through `emit()` are a starting point. +- **Status icons** on Anomalies and cards, with tooltips: + - Infection and Bug counters + - disabled, rooted, copies, temporary Core modifiers +- Viewable discard piles and Server pile counts for both sides. + +### F. Setup, saving and replays (2–3 days) + +- **Decks.** + - Choose a random deck, a preset from `app/decks/*.json`, or paste a list. + - Every list is checked with `validateDeck` and errors are shown. +- **Rule variants.** An advanced panel takes the same `K=V` overrides as the CLI's `--rule`, for + playtesting variants in the app. +- **Save and resume.** + - The game saves to local storage after every move and resumes on reload. + - The state is plain data, apart from the card definitions, which are rebuilt from the CSV. +- **Undo.** + - The app snapshots the state with `structuredClone` before each of your moves. Undo goes back to + your previous decision. + - The dice RNG is part of the snapshot, so undoing and trying again doesn't reroll the dice. + - A playtest mode turns undo on. It's off for a normal game. +- **Replays.** + - A game record is the seed, both decks, the rules and the list of `actionKey`s. + - The engine is deterministic, so a record replays exactly. You can export and import records. + - Attach a record to any bug report, so the bug can be reproduced. + +### G. Layout and finish (2 days) + +- Targets 1280×720 and up, not phones. +- Owner colors that stay distinct for color-blind players, with a pattern as a second cue. +- Fixes from playtests. + +### Effort + +| Workstream | Days | +| --- | --- | +| A. Click to act | 2–3 | +| B. Real cards | 2 | +| C. Combat and dice | 1–2 | +| D. Stops and pacing | 1 | +| E. Information | 2 | +| F. Setup, saving and replays | 2–3 | +| G. Layout and finish | 2 | +| **Total** | **12–15, about 3 weeks** | + +## 6. Risks + +- **Human play reaches paths the bots never take.** The invariant toggle and replay records turn + these into bugs that can be reproduced. Expect the first playtests to find a few engine bugs. +- **The greedy bot is tuned for balance testing, not for fun.** Players may spot patterns it falls + for. Changing `GreedyParams` could give difficulty levels without writing a new bot. +- **The 4×4 boards need their own coordinates.** The app starts with the classic board only. +- **Set 2 cards have no scripts yet.** The app loads set 1 only, as the CLI does by default. +- **Hidden information.** The log audit in section 3 is the main risk. The engine's view and the + bot's view are already correct. + +## 7. Open Decisions for the Owner + +1. **Local or public.** Is the app local-only for now, or should the level 2 build go on a static + host such as itch.io or GitHub Pages for outside playtesters? +2. **Undo in normal games.** Is undo allowed outside playtest mode? +3. **Odds preview.** Should the win odds for a roll show before attacking? It helps playtesting, but + takes some tension out of the choice. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/app/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/app/README.md b/app/README.md new file mode 100644 index 0000000..6fe7dd1 --- /dev/null +++ b/app/README.md @@ -0,0 +1,115 @@ +# Files TCG App + +Play a full game of Files TCG in the browser against the simulator's greedy bot. It runs on the +same engine as `../sim`, so a rule you change there shows up here, and cards come straight from +`../decks/files-deck-1/cards.csv` and its Cider templates. + +## Running it + +```sh +cd app +npm install +npm run dev # http://localhost:5173 +npm test # headless games through the controller +npm run typecheck +npm run build # static site in dist/, openable from any static host +``` + +## Playing + +Pick your side, a seed (blank is random), both decks, the bot's style and any rule variants, then +**Start game**. Read [QUICKSTART.md](../QUICKSTART.md) first if you haven't played. + +- **To act, pick a source, then a target.** Things you can use glow: a card in your hand, one of + your Anomalies (on the board, or in its slot in your panel), a gateway, or a location with an + Ability. Its targets then light up: teal for moves, red for attacks. Click one to play it. If + several moves share a target (Sabotage's destroy or disable, say), a small menu asks which. Moves + with no target, such as Salvage, Recall, Firewall levels and most Abilities, are in the menu at + the bottom right of the board. +- **The Moves tab lists every legal move,** grouped and searchable, for anything the clicks miss. +- **Response windows** show a banner over the board ("North plays Execute: Kill Process on C2: + respond?"). Answer with a glowing card or Ability, or pass. +- **Cards:** hover any card, or a card name, to see it large. Right-click pins it until you close + it (or press Esc). Settings can switch to plain text cards. +- **Combat tab:** each side's Cores by source (the Anomaly, Hardware, Programs, Servers, + temporary effects), the dice, totals, damage and anything destroyed. Before a roll it shows the + odds and the average damage each way. While you have an Anomaly picked, pointing at an attack + target shows your odds for that attack. +- **Info tab:** details of whatever you point at: a location's Server and Programs, the Anomalies + there with their Hardware, counters and temporary Cores. +- **Log tab:** the play-by-play, filterable by Combat, Captures, Cards and Moves. Lines that name + the bot's hidden cards (Callable Server, Diagnostic Module, Race Condition picks) show only that + it made a choice. + +| Key | Action | +| --- | --- | +| Space | End the step, or pass | +| Enter | End command: ends steps until your command is over, stopping if a prompt or response window comes up | +| Z | Undo (playtest mode only) | +| Esc | Cancel the selection, close a dialog or a pinned card | +| Shift (held) | Stop at the next response window, whatever the stops setting says | + +### Settings + +- **Stops** decide when the game waits for you to respond to the bot: + - **In combat only** (the default): the bot's Executions, Abilities, installs and declarations + outside combat pass for you. + - **Every opponent move** stops at every window where you could respond. + - **Never** passes everything. + + The engine already skips windows where you have nothing you could play. +- **Skip empty steps** ends your steps for you when End and Salvage are the only moves. +- **Bot speed** runs from instant to 1 s per move. The top bar also has pause and step-one-move. +- **Dice animation**, **odds preview** and **text cards** can each be turned off. +- **Playtest tools:** the seed, copying the log, exporting the game record, and a rule-invariant + check after every move that reports any engine bug it finds. + +### Saving, undo and replays + +- The game saves to local storage after every move, and the start screen offers to resume it. + Resuming replays the saved moves, so if the cards or rules have changed since and a saved move + stops being legal, the game can't be resumed. +- **Undo** is on in playtest mode (a checkbox on the start screen) and off otherwise. It goes back + to your previous decision. The dice are part of the game state, so trying the same move again + rolls the same dice. +- **A game record** is the seed, both decks, the rules, the bot style and every move. The engine is + deterministic, so a record replays exactly. Export one from Settings or the game-over screen, + and open it with **Open a game record…** on the start screen. The replay viewer steps through the + game with hidden cards shown or not, and **Play on from here** takes over your side from any + move, in playtest mode. Attach a record to a bug report and the bug can be reproduced. + +### Decks and rules + +- Each deck is a random legal deck, a preset from `decks/*.json`, or a pasted list. A pasted list + is one card per line (`2 RAM Expansion`, lines starting with `#` are ignored) or JSON + (`{ "anomalies": [...], "servers": [...], "main": [...] }`). Picking **Paste a list…** while a + preset is selected starts from that preset's list. Every deck is checked with the sim's + `validateDeck`, and problems are listed. +- **Rule variants** take the same `K=V` lines as the CLI's `--rule`, one per line, for example + `secondPlayer.bandwidth=4` or `board=grid4` (the 4×4 boards lay out too). +- **Bot styles** are presets of the greedy bot's `GreedyParams`: Greedy (the sim's standard), + Cautious (attacks at 75%+), Bold (50%+), Wall builder (Lv 3 Firewalls) and Easy (no cards but + Core Hardware). + +## How it's built + +Vite, TypeScript and Preact, plus Handlebars for the card templates. The app imports the engine +from `../sim/src`; nothing is copied. + +| Path | What it holds | +| --- | --- | +| `src/match.ts` | The game controller: real state, bot moves, automatic moves (skips, stops, End command), undo, records, the combat readout's data. No DOM, so tests drive it headlessly. | +| `src/moves.ts` | Legal actions as moves: label, cost, group, and a source and target for click-to-act. The UI never builds an Action. | +| `src/replay.ts` | Rebuilds any move of a game record, with checkpoints for fast seeking. | +| `src/render-card.ts` | Renders cards from the Cider templates as Cider does (`{ card, assets }`, kebab-case keys, the same helpers), inside shadow roots so each template's CSS stays scoped. Cards with no art get a placeholder. | +| `src/cards.ts`, `src/decks.ts` | The card pool (the CSV via `?raw`, so edits show on reload) and deck choices. | +| `src/layout.ts` | Board coordinates, worked out from the board's rows, so the 4×4 boards fit too. | +| `src/storage.ts` | Settings, the saved game and the last setup, in local storage. | +| `src/ui/` | Board (SVG), player panels and hand, side column (combat, info, log, moves), game screen, start screen, replay viewer. | +| `test/` | A random and a greedy "human" play hundreds of games through the controller; records replay exactly; undo restores the dice; End command stops where it should; every legal move is reachable by clicking. | + +The UI only sees `viewFor(state, you)`, so it can't show the bot's hand by mistake, and the bot +only sees its own view. + +Dev builds expose `globalThis.__files` (the current match, and a greedy bot to play your side) for +scripted browser tests. diff --git a/app/decks/glitch-tricks.json b/app/decks/glitch-tricks.json new file mode 100644 index 0000000..b545ccb --- /dev/null +++ b/app/decks/glitch-tricks.json @@ -0,0 +1,79 @@ +{ + "name": "Glitch Tricks", + "about": "Every kind of Anomaly and a toolbox of Executions and copies: Fork, Remote Access, Process Clone and Ghost Process.", + "anomalies": [ + "Data Leaker", + "Pixelated Picture", + "Code Zero", + "Beta Version 1.0" + ], + "servers": [ + "Duplicate Server", + "Duplicate Server", + "Server Farm", + "Server Farm", + "High Bandwidth Server", + "High Bandwidth Server", + "Power Server", + "Power Server", + "MultiCore Server", + "MultiCore Server", + "Upgraded Hardware", + "Upgraded Hardware", + "Cloud Compute", + "Cloud Compute", + "Callable Server", + "Callable Server", + "Protected Server", + "Protected Server", + "Cluster Server", + "Cluster Server" + ], + "main": [ + "Ghost Process", + "Ghost Process", + "Packet Loss", + "Packet Loss", + "Fragmentation", + "Fragmentation", + "Race Condition", + "Race Condition", + "Undefined Behavior", + "Undefined Behavior", + "Garbage Collection", + "Garbage Collection", + "Compatibility Layer", + "Compatibility Layer", + "Dedicated GPU", + "Dedicated GPU", + "Quantum Coprocessor", + "Quantum Coprocessor", + "Hot-Swap Bay", + "Hot-Swap Bay", + "Additional Core", + "Additional Core", + "Diagnostic Module", + "Diagnostic Module", + "Execute: Fork", + "Execute: Fork", + "Execute: Remote Access", + "Execute: Remote Access", + "Execute: Process Clone", + "Execute: Process Clone", + "Execute: Override", + "Execute: Override", + "Execute: Memory Dump", + "Execute: Memory Dump", + "Execute: Root Access", + "Latency Spike", + "Latency Spike", + "Visual Artifact", + "Visual Artifact", + "RAM Expansion", + "RAM Expansion", + "Execute: Trace Route", + "Execute: Trace Route", + "Execute: Ping Sweep", + "Execute: Ping Sweep" + ] +} \ No newline at end of file diff --git a/app/decks/patch-wall.json b/app/decks/patch-wall.json new file mode 100644 index 0000000..1cf163a --- /dev/null +++ b/app/decks/patch-wall.json @@ -0,0 +1,79 @@ +{ + "name": "Patch Wall", + "about": "Patch and Glitch Anomalies that dig in: protective Programs, Hardware that survives defeat, and Executions that break attacks.", + "anomalies": [ + "Backup Machine", + "Beta Version 1.0", + "Pixelated Picture", + "Data Leaker" + ], + "servers": [ + "Protected Server", + "Protected Server", + "Cluster Server", + "Cluster Server", + "Backup Server", + "Backup Server", + "Callable Server", + "Callable Server", + "Duplicate Server", + "Duplicate Server", + "High Bandwidth Server", + "High Bandwidth Server", + "Power Server", + "Power Server", + "Server Farm", + "Server Farm", + "MultiCore Server", + "MultiCore Server", + "Pingable Server", + "Pingable Server" + ], + "main": [ + "Hotfix", + "Hotfix", + "Error Correction", + "Error Correction", + "Version Control", + "Version Control", + "Rollback Routine", + "Rollback Routine", + "Latency Spike", + "Latency Spike", + "Visual Artifact", + "Visual Artifact", + "Desynchronization", + "Desynchronization", + "False Positive", + "False Positive", + "Firewall Appliance", + "Firewall Appliance", + "Redundant Power Supply", + "Redundant Power Supply", + "RAID Array", + "RAID Array", + "ECC Memory", + "ECC Memory", + "Additional Core", + "Additional Core", + "RAM Expansion", + "RAM Expansion", + "Execute: Emergency Shutdown", + "Execute: Emergency Shutdown", + "Execute: Disconnect", + "Execute: Disconnect", + "Execute: Force Reboot", + "Execute: Force Reboot", + "Execute: Kill Process", + "Execute: Kill Process", + "Execute: Defragment", + "Garbage Collection", + "Garbage Collection", + "Compatibility Layer", + "Compatibility Layer", + "Hardware Sandbox", + "Hardware Sandbox", + "Execute: Purge", + "Execute: Purge" + ] +} \ No newline at end of file diff --git a/app/decks/virus-swarm.json b/app/decks/virus-swarm.json new file mode 100644 index 0000000..f232bee --- /dev/null +++ b/app/decks/virus-swarm.json @@ -0,0 +1,79 @@ +{ + "name": "Virus Swarm", + "about": "Virus and Bug Anomalies that stack Infection counters and Core-draining Programs, backed by raw Core Hardware.", + "anomalies": [ + "Code Zero", + "Corrupt Driver", + "Carbon NanoBots", + "Broken Bits" + ], + "servers": [ + "MultiCore Server", + "MultiCore Server", + "Power Server", + "Power Server", + "Server Farm", + "Server Farm", + "High Bandwidth Server", + "High Bandwidth Server", + "Cluster Server", + "Cluster Server", + "Upgraded Hardware", + "Upgraded Hardware", + "Cloud Compute", + "Cloud Compute", + "Backup Server", + "Backup Server", + "Pingable Server", + "Pingable Server", + "Network Throttle", + "Network Throttle" + ], + "main": [ + "Recursive Infection", + "Recursive Infection", + "Memory Parasite", + "Memory Parasite", + "Resource Leech", + "Resource Leech", + "Worm Protocol", + "Worm Protocol", + "Persistent Infection", + "Persistent Infection", + "Payload Injector", + "Payload Injector", + "Stack Overflow", + "Stack Overflow", + "Bloatware", + "Bloatware", + "Infinite Loop", + "Infinite Loop", + "Additional Core", + "Additional Core", + "RAM Expansion", + "RAM Expansion", + "Overclocked CPU", + "Overclocked CPU", + "Packet Accelerator", + "Packet Accelerator", + "Solid-State Cache", + "Solid-State Cache", + "Execute: Trace Route", + "Execute: Trace Route", + "Execute: Packet Flood", + "Execute: Packet Flood", + "Execute: Purge", + "Execute: Purge", + "Execute: Sabotage", + "Execute: Sabotage", + "Execute: Ping Sweep", + "Replication Routine", + "Replication Routine", + "Execute: Kill Process", + "Execute: Kill Process", + "Execute: Disconnect", + "Execute: Disconnect", + "Cooling System", + "Cooling System" + ] +} \ No newline at end of file diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..2d76134 --- /dev/null +++ b/app/index.html @@ -0,0 +1,12 @@ + + +
+ + +Not enough Gb for: {blocked.map((o) => `${o.label} (${o.cost} Gb)`).join(', ')}. Salvage a card first.
} + {salvage.length > 0 && blocked.length > 0 && ( ++ {reason} Round {roundOf(s, s.turn)}, seed {match.setup.seed}. +
+| + | {PLAYER_NAMES[me]} (you) | +{PLAYER_NAMES[match.botSide]} (bot) | +
|---|---|---|
| {STAT_LABELS[k]} | +{s.stats[k][me]} | +{s.stats[k][match.botSide]} | +
Empty.
} + {[...pile].reverse().map((id) => ( +Newest first. {p !== me && `${PLAYER_NAMES[p]} has ${view.players[p].hand.length} cards in hand and ${view.players[p].serverPile.length} Servers in the pile.`}
+ +{level ? `A Lv ${level} Firewall blocks this line. Clearing it costs ${view.rules.firewallCost[level - 1]} Gb.` : 'Open: no Firewall.'}
+{def.text}
+{view.defs[name].text}
++ Firewalls: {walls.map((l) => `${otherEnd(l, loc)} (Lv ${view.firewalls[l.id]})`).join(', ')} +
+ )} ++ {inPlay ? anomalyCores(view, r.player, r.slot, 'defend') : def.cores} Cores · {inPlay ? `${healthLeft(view, r)}/${healthOf(view, r)}` : healthOf(view, r)} Health + {r.slot <= 4 && ` · Hardware ${av.hardware.length}/${slotsTotal(view, r)}`} +
+ {!compact && def.ability && ( ++ {def.ability.name} + {def.ability.cost ? ` (${def.ability.cost} Gb)` : ''}: {def.ability.text} +
+ )} + {av.hardware.map((h) => ( +{view.defs[view.cards[h].name].text}
} ++ New to the game? Read QUICKSTART.md first. In play: pick a glowing card or Anomaly, then a highlighted target. Space ends a step or passes, Enter + ends your command, right-click a card to pin it. +
+{{card.description}}
+ +{{card.description}}
+{{card.description}}
+