93 lines
5.6 KiB
Markdown
93 lines
5.6 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 -- --rule secondPlayer.cards=2 # try a rule variant (see src/rules.ts)
|
||
npm run sim -- --rule board=grid4 # the 4×4 test board (win with 12 of 16)
|
||
npm run sim -- --rule board=lanes # three lanes, linked only across the middle (11 of 15)
|
||
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, rounds of alternating commands (or whole turns, with
|
||
`--rule commands.on=false`), placement, recall and advancing, attacks, combat with Health and
|
||
damage (or one-roll combats with tie rerolls, with `--rule health.on=false`; `health.override=8`
|
||
gives every Anomaly the same Health), captures, levels and Bandwidth, Anomaly unlocks, Firewalls,
|
||
Salvage, response windows and chains, and the win condition.
|
||
- **Every card:** all 83 set 1 cards in `../decks/files-deck-1/cards.csv` have a script, including
|
||
Anomaly Abilities. The 52 set 2 cards (`Set` = 2) have none yet, so they're skipped unless you pass
|
||
`--set 2` or `--set all`; the bots never play an unscripted card. Unclear card text follows the readings in `rules.md` → Card Rules; the ones marked ⚠
|
||
are guesses waiting for a decision.
|
||
- **Card edits:** stats (Bandwidth, Cores, Health, 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.
|
||
|
||
The browser app in `../app` plays on this engine directly. For it:
|
||
|
||
- `parseCards(csvText)` in `cards.ts` reads the card CSV without Node; `loadCards()` in `load.ts`
|
||
reads the file from disk for the CLI and tests.
|
||
- `describeAction(s, a)` in `describe.ts` labels every action for people, e.g.
|
||
`Play Execute: Force Reboot on D2: Anomaly 2 (Glitch) (5 Gb)`.
|
||
- Log lines carry a tag (combat, capture, card, move…) and what they're about. A line naming a card
|
||
only one player may see goes to that player, and `logFor(s, p)` gives the other player its public
|
||
version. Choices marked `secret` (Callable Server, Diagnostic Module, Race Condition) log that way,
|
||
and `viewFor` hides their prompt from the opponent.
|
||
- `coresOf` can list where an Anomaly's Cores come from, `rollOdds` in `odds.ts` gives a roll's win,
|
||
tie and loss chances with the average damage, and `combatWatch` in `flow.ts` lets an app see
|
||
every stage of a combat, even one that starts and ends inside a single `applyAction`.
|
||
|
||
## 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`, `anomalies` |
|
||
| `src/scripts.ts` | The script interface and registry, and the stale-text check |
|
||
| `src/map.ts`, `src/rules.ts` | Playmats (the rules.md one plus 4×4 and three-lane test boards), lines and levels; every rules number, for testing variants |
|
||
| `src/bots/` | `greedy` (with style presets), `random`, and the combat math they share |
|
||
| `src/describe.ts` | Readable labels for actions and their arguments |
|
||
| `src/cli.ts`, `src/stats.ts`, `src/load.ts` | Batch runner, summary and card report; reading the card CSV from disk |
|
||
| `test/` | Rules tests, one test per card, and fuzz games that check invariants after every action |
|
||
|
||
## Bots
|
||
|
||
- **greedy** plans each command: takes the best single advance or attack (open locations first,
|
||
rushing the ones that unlock Anomalies; attacks at 60%+ odds), guards threatened locations, installs
|
||
Hardware and Programs where they help, walls off undefended locations, and keeps Bandwidth for tricks.
|
||
With whole turns it plans every Anomaly's move at once. On the opponent's commands 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.
|