files-tcg/sim/README.md
2026-09-28 01:56:25 -04:00

71 lines
3.7 KiB
Markdown

# Files TCG Simulator
Plays Files TCG games between bots, following `../rules.md`, and reports what happened.
## Running it
Node 23.6 or newer runs the TypeScript directly, so there's no build step. `npm install` is only
needed for type checking.
```sh
cd sim
npm run sim -- -n 5000 # 5,000 greedy-vs-greedy games
npm run sim -- -n 5000 --card-report # plus how each card did
npm run sim -- --south greedy --north nocards # does playing cards help?
npm run sim -- --log --seed 7 # watch one game, play by play
npm run sim -- --json out/run.json # also save every game's result
npm run sim -- --help # all options and bots
npm test
npm run typecheck
```
Every game is reproducible: the same seed always plays out the same way. Decks are random legal
decks, so the card report's "win rate" (for the player whose deck held the card) is a fair measure
of how much a card helps.
## What's simulated
- **Rules:** everything in `rules.md`: setup, the turn steps, placement and advancing, attacks,
combat with tie rerolls, captures, levels and RAM, Avatar unlocks, Firewalls, Salvage, response
windows and chains, and the win condition.
- **Every card:** all 83 cards in `../decks/files-deck-1/cards.csv` have a script, including Avatar
Abilities. Unclear card text follows the readings in `rules.md` → Card Rules; the ones marked ⚠
are guesses waiting for a decision.
- **Card edits:** stats (RAM, Cores, slots) come straight from the CSV. Each script records the text
it was written for, so if you reword a card the sim warns you, and `npm test` fails until the
script is updated.
## How the engine works
The state is plain data. `decider(s)` says who must act, `legalActions(s)` lists their options, and
`applyAction(s, a)` does one. Between decisions the engine runs a queue of tasks (combat stages,
captures, card triggers) until it needs a player again: a turn step, a response window, or a choice
a card asks for. Each card's effect lives in one script (`src/cards/`), which the engine calls at
fixed hooks: Core totals, costs, combat start, defeat, capture, draws, installs, and so on.
## Layout
| Path | What it holds |
|---|---|
| `src/engine.ts` | Decisions, legal actions, response windows, the turn loop, player views |
| `src/flow.ts` | Combat, defeat, capture, drawing, copies |
| `src/query.ts` | What's in play, Cores, costs, capacity, protection |
| `src/cards/` | One script per card: `servers`, `programs`, `hardware`, `executions`, `avatars` |
| `src/scripts.ts` | The script interface and registry, and the stale-text check |
| `src/map.ts`, `src/rules.ts` | Playmat lines and levels; every rules number, for testing variants |
| `src/bots/` | `greedy` (with style presets), `random`, and the combat math they share |
| `src/cli.ts`, `src/stats.ts` | Batch runner, summary and card report |
| `test/` | Rules tests, one test per card, and fuzz games that check invariants after every action |
## Bots
- **greedy** plans each turn: grabs open locations, attacks at 60%+ odds, guards threatened
locations, installs Hardware and Programs where they help, walls off undefended locations, and
keeps RAM for tricks. On the opponent's turn it answers after the dice are rolled with whichever
Execution or Ability most improves the combat, and tries to stop advances into its locations.
- **nocards** is greedy but only uses Core Hardware, like the first version of the sim.
- **bold / cautious / nowall / wall3** change one greedy setting each; **random** picks any legal
action.
The bots are heuristic. A card they rarely play may be weak or narrow, or they may just not know
how to use it; the card report's "played" column shows which.