files-tcg/app/README.md
2026-10-01 17:20:33 -04:00

115 lines
6.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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.