updates
This commit is contained in:
parent
5368464042
commit
937f44defe
100 changed files with 10185 additions and 2042 deletions
|
|
@ -13,6 +13,8 @@ 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
|
||||
|
|
@ -29,13 +31,13 @@ of how much a card helps.
|
|||
- **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 Avatar the same Health), captures, levels and RAM, Avatar unlocks, Firewalls,
|
||||
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
|
||||
Avatar Abilities. The 52 set 2 cards (`Set` = 2) have none yet, so they're skipped unless you pass
|
||||
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 (RAM, Cores, Health, slots) come straight from the CSV. Each script records the text
|
||||
- **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.
|
||||
|
||||
|
|
@ -47,6 +49,20 @@ captures, card triggers) until it needs a player again: a turn step, a response
|
|||
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 |
|
||||
|
|
@ -54,19 +70,20 @@ fixed hooks: Core totals, costs, combat start, defeat, capture, draws, installs,
|
|||
| `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/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` | Playmat lines and levels; every rules number, for testing variants |
|
||||
| `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/cli.ts`, `src/stats.ts` | Batch runner, summary and card report |
|
||||
| `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 Avatars; attacks at 60%+ odds), guards threatened locations, installs
|
||||
Hardware and Programs where they help, walls off undefended locations, and keeps RAM for tricks.
|
||||
With whole turns it plans every Avatar's move at once. On the opponent's commands it answers after the dice are rolled with whichever
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,34 +3,34 @@ import { isStart, levelFor, type LocId } from '../map.ts';
|
|||
import { winChance } from '../odds.ts';
|
||||
import { bugImmune, coresOf, fighterOf, hardwareActive, healthLeft, sources } from '../query.ts';
|
||||
import { scriptOf } from '../scripts.ts';
|
||||
import { avatar, defOf, defendersAt, fightersOf, hardwareOf, refKey } from '../state.ts';
|
||||
import type { AvatarRef, GameState, PlayerId } from '../types.ts';
|
||||
import { anomaly, defOf, defendersAt, fightersOf, hardwareOf, refKey } from '../state.ts';
|
||||
import type { AnomalyRef, GameState, PlayerId } from '../types.ts';
|
||||
|
||||
// A location is worth about 10 points, plus 8 more when it's taken from the opponent. RAM counts
|
||||
// half a point per RAM, a card in hand about 2.
|
||||
// A location is worth about 10 points, plus 8 more when it's taken from the opponent. Bandwidth counts
|
||||
// half a point per Bandwidth, a card in hand about 2.
|
||||
export const LOCATION_POINTS = 10;
|
||||
export const ENEMY_LOCATION_POINTS = 8;
|
||||
export const RAM_POINTS = 0.5;
|
||||
export const BANDWIDTH_POINTS = 0.5;
|
||||
export const LOSS_POINTS = 4;
|
||||
export const CARD_POINTS = 2;
|
||||
|
||||
export function locationValue(v: GameState, p: PlayerId, loc: LocId): number {
|
||||
if (isStart(loc)) return 0; // starting Servers can't be captured
|
||||
const taken = v.locations[loc].owner === null ? 0 : ENEMY_LOCATION_POINTS;
|
||||
return LOCATION_POINTS + taken + v.rules.levelRam[levelFor(p, loc)] * RAM_POINTS;
|
||||
return LOCATION_POINTS + taken + v.rules.levelBandwidth[levelFor(p, loc)] * BANDWIDTH_POINTS;
|
||||
}
|
||||
|
||||
/** How many Avatars capturing `loc` would unlock for `p` (level unlocks only). */
|
||||
/** How many Anomalies capturing `loc` would unlock for `p` (level unlocks only). */
|
||||
export function unlocksAt(v: GameState, p: PlayerId, loc: LocId): number {
|
||||
if (v.rules.recruit.on || v.rules.buyAvatars.on || isStart(loc)) return 0;
|
||||
if (v.rules.recruit.on || v.rules.buyAnomalies.on || isStart(loc)) return 0;
|
||||
const level = levelFor(p, loc);
|
||||
if (level <= v.players[p].unlockedLevel) return 0;
|
||||
return v.players[p].avatars.slice(0, Math.min(level, 4)).filter((a) => !a.faceUp).length;
|
||||
return v.players[p].anomalies.slice(0, Math.min(level, 4)).filter((a) => !a.faceUp).length;
|
||||
}
|
||||
|
||||
/** What losing an Avatar costs: the tempo, plus its Hardware. */
|
||||
export function avatarStake(v: GameState, r: AvatarRef): number {
|
||||
return LOSS_POINTS + hardwareOf(v, r).reduce((t, h) => t + (h < 0 ? 0 : defOf(v, h).ram), 0) * RAM_POINTS;
|
||||
/** What losing an Anomaly costs: the tempo, plus its Hardware. */
|
||||
export function anomalyStake(v: GameState, r: AnomalyRef): number {
|
||||
return LOSS_POINTS + hardwareOf(v, r).reduce((t, h) => t + (h < 0 ? 0 : defOf(v, h).bandwidth), 0) * BANDWIDTH_POINTS;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
@ -93,7 +93,7 @@ function mixDist(...dists: Map<number, number>[]): Map<number, number> {
|
|||
}
|
||||
|
||||
/** The dice each side of the current combat still has to roll (or has rolled), for the odds. */
|
||||
function combatDice(v: GameState, reroll?: { ref: AvatarRef; k: number }): { fa: number; ka: number; fd: number; kd: number } {
|
||||
function combatDice(v: GameState, reroll?: { ref: AnomalyRef; k: number }): { fa: number; ka: number; fd: number; kd: number } {
|
||||
const c = v.combat!;
|
||||
let fa = 0;
|
||||
let ka = 0;
|
||||
|
|
@ -125,7 +125,7 @@ function combatDice(v: GameState, reroll?: { ref: AvatarRef; k: number }): { fa:
|
|||
* the dice on the table count: Core changes add dice or drop the highest ones, and `reroll` lets a
|
||||
* fighter reroll its dice showing k or less (Bit Flip).
|
||||
*/
|
||||
export function combatOdds(v: GameState, reroll?: { ref: AvatarRef; k: number }): number {
|
||||
export function combatOdds(v: GameState, reroll?: { ref: AnomalyRef; k: number }): number {
|
||||
const c = v.combat!;
|
||||
let atk = 0;
|
||||
let def = 0;
|
||||
|
|
@ -141,17 +141,17 @@ export function combatOdds(v: GameState, reroll?: { ref: AvatarRef; k: number })
|
|||
}
|
||||
|
||||
/** Health rule: the margin distribution of the current combat, given the dice on the table. */
|
||||
export function combatDist(v: GameState, reroll?: { ref: AvatarRef; k: number }): Map<number, number> {
|
||||
export function combatDist(v: GameState, reroll?: { ref: AnomalyRef; k: number }): Map<number, number> {
|
||||
const { fa, ka, fd, kd } = combatDice(v, reroll);
|
||||
return marginDist(fa, ka, fd, kd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cores each side would have if `ref` attacked `target` from `origin` now, counting what the
|
||||
* target's Programs do when a combat starts there (Memory Leak, Visual Artifact, Memory Parasite),
|
||||
* target's Programs do when a combat starts there (Bloatware, Visual Artifact, Memory Parasite),
|
||||
* and whether Race Condition may add +2 to the defence.
|
||||
*/
|
||||
function attackCores(v: GameState, ref: AvatarRef, origin: LocId, target: LocId, bonus: number): { atk: number; def: number; race: boolean } {
|
||||
function attackCores(v: GameState, ref: AnomalyRef, origin: LocId, target: LocId, bonus: number): { atk: number; def: number; race: boolean } {
|
||||
let atk = coresOf(v, { ref, role: 'attack', at: origin, loc: target, combat: null }) + bonus;
|
||||
const defs = defendersAt(v, target);
|
||||
let def = defs.reduce((t, d) => t + coresOf(v, { ref: d, role: 'defend', at: target, loc: target, combat: null }), 0);
|
||||
|
|
@ -159,7 +159,7 @@ function attackCores(v: GameState, ref: AvatarRef, origin: LocId, target: LocId,
|
|||
for (const x of sources(v)) {
|
||||
if (x.at !== target || x.controller === ref.player) continue;
|
||||
const hw = hardwareOf(v, ref);
|
||||
if (x.name === 'Memory Leak' && !bugImmune(v, ref, x.controller)) atk -= hw.length;
|
||||
if (x.name === 'Bloatware' && !bugImmune(v, ref, x.controller)) atk -= hw.length;
|
||||
if (x.name === 'Visual Artifact' && !v.cards[x.id].spent) atk -= 1;
|
||||
if (x.name === 'Race Condition') race = true;
|
||||
if (x.name === 'Memory Parasite') {
|
||||
|
|
@ -171,13 +171,13 @@ function attackCores(v: GameState, ref: AvatarRef, origin: LocId, target: LocId,
|
|||
}
|
||||
|
||||
/** Chance an attack would win the roll if declared now. */
|
||||
export function attackOdds(v: GameState, ref: AvatarRef, origin: LocId, target: LocId, bonus = 0): number {
|
||||
export function attackOdds(v: GameState, ref: AnomalyRef, origin: LocId, target: LocId, bonus = 0): number {
|
||||
const { atk, def, race } = attackCores(v, ref, origin, target, bonus);
|
||||
return race ? (winChance(atk, def) + winChance(atk, def + 2)) / 2 : winChance(atk, def);
|
||||
}
|
||||
|
||||
/** Health rule: margin distribution of an attack declared now. */
|
||||
export function attackDist(v: GameState, ref: AvatarRef, origin: LocId, target: LocId, bonus = 0): Map<number, number> {
|
||||
export function attackDist(v: GameState, ref: AnomalyRef, origin: LocId, target: LocId, bonus = 0): Map<number, number> {
|
||||
const { atk, def, race } = attackCores(v, ref, origin, target, bonus);
|
||||
const plain = marginDist(0, atk, 0, def);
|
||||
return race ? mixDist(plain, marginDist(0, atk, 0, def + 2)) : plain;
|
||||
|
|
@ -192,14 +192,14 @@ export function attackDist(v: GameState, ref: AvatarRef, origin: LocId, target:
|
|||
export function damageValue(
|
||||
v: GameState,
|
||||
me: PlayerId,
|
||||
attacker: AvatarRef,
|
||||
defenders: AvatarRef[],
|
||||
attacker: AnomalyRef,
|
||||
defenders: AnomalyRef[],
|
||||
dist: Map<number, number>,
|
||||
locValue: number,
|
||||
): number {
|
||||
const sumLeft = Math.max(1, defenders.reduce((t, d) => t + healthLeft(v, d), 0));
|
||||
const stakeD = defenders.reduce((t, d) => t + avatarStake(v, d), 0);
|
||||
const stakeA = avatarStake(v, attacker);
|
||||
const stakeD = defenders.reduce((t, d) => t + anomalyStake(v, d), 0);
|
||||
const stakeA = anomalyStake(v, attacker);
|
||||
const leftA = Math.max(1, healthLeft(v, attacker));
|
||||
let total = 0;
|
||||
for (const [m, p] of dist) {
|
||||
|
|
@ -211,18 +211,18 @@ export function damageValue(
|
|||
|
||||
/**
|
||||
* Points for the attacking player from declaring an attack now: under the health rule the expected
|
||||
* damage value, otherwise the odds of taking the location against losing the Avatar.
|
||||
* damage value, otherwise the odds of taking the location against losing the Anomaly.
|
||||
*/
|
||||
export function attackValue(v: GameState, ref: AvatarRef, origin: LocId, target: LocId, locValue: number, bonus = 0): number {
|
||||
export function attackValue(v: GameState, ref: AnomalyRef, origin: LocId, target: LocId, locValue: number, bonus = 0): number {
|
||||
if (!v.rules.health.on) {
|
||||
const chance = attackOdds(v, ref, origin, target, bonus);
|
||||
return chance * locValue - (1 - chance) * avatarStake(v, ref);
|
||||
return chance * locValue - (1 - chance) * anomalyStake(v, ref);
|
||||
}
|
||||
return damageValue(v, ref.player, ref, defendersAt(v, target), attackDist(v, ref, origin, target, bonus), locValue);
|
||||
}
|
||||
|
||||
/** Chance `target` falls to this attack: the win odds, or under the health rule the odds of destroying every defender. */
|
||||
export function fallChance(v: GameState, ref: AvatarRef, origin: LocId, target: LocId, bonus = 0): number {
|
||||
export function fallChance(v: GameState, ref: AnomalyRef, origin: LocId, target: LocId, bonus = 0): number {
|
||||
if (!v.rules.health.on) return attackOdds(v, ref, origin, target, bonus);
|
||||
const need = defendersAt(v, target).reduce((t, d) => t + healthLeft(v, d), 0);
|
||||
let p = 0;
|
||||
|
|
@ -248,8 +248,8 @@ export function hardwareHealth(v: GameState, hw: number): number {
|
|||
export function stakes(v: GameState, me: PlayerId): { win: number; lose: number } {
|
||||
const c = v.combat!;
|
||||
const loc = locationValue(v, c.attacker.player, c.loc);
|
||||
const atk = avatarStake(v, c.attacker);
|
||||
const def = c.defenders.reduce((t, d) => t + avatarStake(v, d), 0);
|
||||
const atk = anomalyStake(v, c.attacker);
|
||||
const def = c.defenders.reduce((t, d) => t + anomalyStake(v, d), 0);
|
||||
return c.attacker.player === me
|
||||
? { win: loc + def / 2, lose: -atk }
|
||||
: { win: atk / 2, lose: -(loc + def) };
|
||||
|
|
@ -259,13 +259,13 @@ export function stakes(v: GameState, me: PlayerId): { win: number; lose: number
|
|||
* Expected points for `me` from the current combat, or from how it ended. `reroll` values a Bit
|
||||
* Flip of one fighter's dice showing k or less.
|
||||
*/
|
||||
export function combatValue(v: GameState, me: PlayerId, reroll?: { ref: AvatarRef; k: number }): number {
|
||||
export function combatValue(v: GameState, me: PlayerId, reroll?: { ref: AnomalyRef; k: number }): number {
|
||||
const c = v.combat;
|
||||
if (!c) return 0;
|
||||
const iAttack = c.attacker.player === me;
|
||||
if (c.ended) {
|
||||
// Ended early: the attacker takes the location only if every defender left.
|
||||
const taken = c.defenders.length === 0 && avatar(v, c.attacker).at !== null;
|
||||
const taken = c.defenders.length === 0 && anomaly(v, c.attacker).at !== null;
|
||||
if (!taken) return 0;
|
||||
return iAttack ? locationValue(v, me, c.loc) : -locationValue(v, c.attacker.player, c.loc);
|
||||
}
|
||||
|
|
@ -279,5 +279,5 @@ export function combatValue(v: GameState, me: PlayerId, reroll?: { ref: AvatarRe
|
|||
}
|
||||
|
||||
export const cardName = (v: GameState, id: number): string => (id < 0 ? '' : v.cards[id].name);
|
||||
export const printedRam = (v: GameState, id: number): number => (id < 0 ? 0 : defOf(v, id).ram);
|
||||
export const printedBandwidth = (v: GameState, id: number): number => (id < 0 ? 0 : defOf(v, id).bandwidth);
|
||||
export const scriptFor = (v: GameState, id: number) => scriptOf(cardName(v, id));
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@ import {
|
|||
firewallCost,
|
||||
hardwareCost,
|
||||
openWindow,
|
||||
avatarForSale,
|
||||
anomalyForSale,
|
||||
programCost,
|
||||
recruitSlots,
|
||||
} from '../engine.ts';
|
||||
import { GRID, LINES_AT, LOCATIONS, otherEnd, type LocId } from '../map.ts';
|
||||
import { avatarRoom, coresOf, hardwareActive, hasRoom, healthLeft, healthOf, portsFree, programSlots, sources } from '../query.ts';
|
||||
import { anomalyRoom, coresOf, hardwareActive, hasRoom, healthLeft, healthOf, slotsFree, programSlots, sources } from '../query.ts';
|
||||
import { scriptOf } from '../scripts.ts';
|
||||
import {
|
||||
avatar,
|
||||
anomaly,
|
||||
canAct,
|
||||
controls,
|
||||
defendersAt,
|
||||
|
|
@ -30,11 +30,11 @@ import {
|
|||
refsInPlay,
|
||||
removeFrom,
|
||||
} from '../state.ts';
|
||||
import type { Action, AvatarRef, Choice, GameState, PlayerId, StackItem } from '../types.ts';
|
||||
import type { Action, AnomalyRef, Choice, GameState, PlayerId, StackItem } from '../types.ts';
|
||||
import type { Bot } from './bot.ts';
|
||||
import {
|
||||
CARD_POINTS,
|
||||
RAM_POINTS,
|
||||
BANDWIDTH_POINTS,
|
||||
attackOdds,
|
||||
attackValue,
|
||||
cardName,
|
||||
|
|
@ -43,7 +43,7 @@ import {
|
|||
hardwareCores,
|
||||
hardwareHealth,
|
||||
locationValue,
|
||||
printedRam,
|
||||
printedBandwidth,
|
||||
unlocksAt,
|
||||
} from './eval.ts';
|
||||
|
||||
|
|
@ -53,11 +53,11 @@ export interface GreedyParams {
|
|||
/** Firewall level used to wall off undefended frontier locations; 0 = never place Firewalls. */
|
||||
firewallLevel: number;
|
||||
maxFirewallsPerTurn: number;
|
||||
/** RAM, counting salvageable cards, kept back after spending in step 6. */
|
||||
ramReserve: number;
|
||||
/** Bandwidth, counting salvageable cards, kept back after spending in step 6. */
|
||||
bandwidthReserve: number;
|
||||
/** Play Programs, Executions and Abilities. Off plays like the Phase 2 bot: Core Hardware only. */
|
||||
useCards: boolean;
|
||||
/** Extra value of a capture per Avatar it unlocks (a location is worth about 12). 0 ignores unlocks. */
|
||||
/** Extra value of a capture per Anomaly it unlocks (a location is worth about 12). 0 ignores unlocks. */
|
||||
unlockPoints: number;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ export const DEFAULT_GREEDY: GreedyParams = {
|
|||
minWinChance: 0.6,
|
||||
firewallLevel: 1,
|
||||
maxFirewallsPerTurn: 2,
|
||||
ramReserve: 6,
|
||||
bandwidthReserve: 6,
|
||||
useCards: true,
|
||||
unlockPoints: 15,
|
||||
};
|
||||
|
|
@ -74,17 +74,15 @@ export const DEFAULT_GREEDY: GreedyParams = {
|
|||
* Board order as seen from `me`'s side. North gets South's order rotated 180°, which maps the
|
||||
* board onto itself, so tie-breaks never favor a seat.
|
||||
*/
|
||||
const REVERSED_GRID = [...GRID].reverse();
|
||||
const REVERSED_LOCATIONS = [...LOCATIONS].reverse();
|
||||
const gridFrom = (me: PlayerId) => (me === 0 ? GRID : REVERSED_GRID);
|
||||
const locationsFrom = (me: PlayerId) => (me === 0 ? LOCATIONS : REVERSED_LOCATIONS);
|
||||
const gridFrom = (me: PlayerId) => (me === 0 ? GRID : [...GRID].reverse());
|
||||
const locationsFrom = (me: PlayerId) => (me === 0 ? LOCATIONS : [...LOCATIONS].reverse());
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// How much the bot wants each card
|
||||
|
||||
/** Programs by how much they help where they're installed, roughly in points per turn. */
|
||||
const PROGRAM_WEIGHT: Record<string, number> = {
|
||||
'Stack Overflow': 4, 'Race Condition': 3, 'Memory Leak': 3, 'Visual Artifact': 2, 'Memory Parasite': 2,
|
||||
'Stack Overflow': 4, 'Race Condition': 3, 'Bloatware': 3, 'Visual Artifact': 2, 'Memory Parasite': 2,
|
||||
'Recursive Infection': 2, 'Resource Leech': 2, 'Overflow Error': 2, 'Persistent Infection': 1, 'Stock Rice': 1.5,
|
||||
'Packet Loss': 1.5, 'Null Pointer': 1.5, Fragmentation: 1, 'Latency Spike': 1, Desynchronization: 0.5,
|
||||
'False Positive': 0.5, Hotfix: 0.5, 'Version Control': 1.5, 'Compatibility Layer': 1.5, 'Replication Routine': 1,
|
||||
|
|
@ -93,7 +91,7 @@ const PROGRAM_WEIGHT: Record<string, number> = {
|
|||
};
|
||||
/** Programs that only matter when an enemy attacks their location. */
|
||||
const DEFENSIVE = new Set([
|
||||
'Stack Overflow', 'Race Condition', 'Memory Leak', 'Visual Artifact', 'Memory Parasite', 'Recursive Infection',
|
||||
'Stack Overflow', 'Race Condition', 'Bloatware', 'Visual Artifact', 'Memory Parasite', 'Recursive Infection',
|
||||
'Resource Leech', 'Overflow Error', 'Persistent Infection', 'Stock Rice', 'Packet Loss', 'Null Pointer',
|
||||
'Fragmentation', 'Latency Spike', 'Desynchronization', 'False Positive', 'Version Control', 'Undefined Behavior',
|
||||
]);
|
||||
|
|
@ -115,7 +113,7 @@ const COMBAT_TRICKS = new Set([
|
|||
/** How much the bot wants to keep a card rather than salvage it. Below 3 is fodder. */
|
||||
function keepScore(v: GameState, id: number): number {
|
||||
const def = defOf(v, id);
|
||||
if (def.kind === 'avatar') return recruitSlot(v, v.cards[id].owner, id) === null ? 1 : 7;
|
||||
if (def.kind === 'anomaly') return recruitSlot(v, v.cards[id].owner, id) === null ? 1 : 7;
|
||||
if (def.kind === 'hardware') {
|
||||
if (hardwareCores(v, id) > 0 || hardwareHealth(v, id) > 0) return 6;
|
||||
return (UTILITY_HARDWARE[def.name] ?? 0) * 2;
|
||||
|
|
@ -125,23 +123,23 @@ function keepScore(v: GameState, id: number): number {
|
|||
return 1.5;
|
||||
}
|
||||
|
||||
/** RAM available this turn, counting cards the bot is willing to salvage. */
|
||||
/** Bandwidth available this turn, counting cards the bot is willing to salvage. */
|
||||
function spendable(v: GameState, me: PlayerId): number {
|
||||
const pl = v.players[me];
|
||||
return pl.ram + pl.hand.filter((id) => keepScore(v, id) < 3).reduce((t, id) => t + printedRam(v, id), 0);
|
||||
return pl.bandwidth + pl.hand.filter((id) => keepScore(v, id) < 3).reduce((t, id) => t + printedBandwidth(v, id), 0);
|
||||
}
|
||||
|
||||
/** The salvage that best covers `cost`, never the card being paid for. Null if none is needed or possible. */
|
||||
function salvageFor(v: GameState, me: PlayerId, cost: number, except: number | null = null): Action | null {
|
||||
const pl = v.players[me];
|
||||
const need = cost - pl.ram;
|
||||
const need = cost - pl.bandwidth;
|
||||
if (need <= 0) return null;
|
||||
const hand = pl.hand.filter((id) => id !== except && id >= 0);
|
||||
if (hand.reduce((t, id) => t + printedRam(v, id), 0) < need) return null;
|
||||
const order = [...hand].sort((a, b) => keepScore(v, a) - keepScore(v, b) || printedRam(v, b) - printedRam(v, a));
|
||||
if (hand.reduce((t, id) => t + printedBandwidth(v, id), 0) < need) return null;
|
||||
const order = [...hand].sort((a, b) => keepScore(v, a) - keepScore(v, b) || printedBandwidth(v, b) - printedBandwidth(v, a));
|
||||
const fodder = order.filter((id) => keepScore(v, id) < 3);
|
||||
const from = fodder.reduce((t, id) => t + printedRam(v, id), 0) >= need ? fodder : order;
|
||||
const card = from.find((id) => printedRam(v, id) >= need) ?? from[0];
|
||||
const from = fodder.reduce((t, id) => t + printedBandwidth(v, id), 0) >= need ? fodder : order;
|
||||
const card = from.find((id) => printedBandwidth(v, id) >= need) ?? from[0];
|
||||
return { type: 'salvage', card };
|
||||
}
|
||||
|
||||
|
|
@ -153,18 +151,18 @@ const spentCard = (a: Action): number | null =>
|
|||
// Recruiting (recruit rule)
|
||||
|
||||
/**
|
||||
* Where the bot would recruit Avatar `id`: an empty slot while there's room, otherwise over a
|
||||
* weaker Avatar (fewer Cores) that carries no Hardware, preferring one sitting in its slot.
|
||||
* Where the bot would recruit Anomaly `id`: an empty slot while there's room, otherwise over a
|
||||
* weaker Anomaly (fewer Cores) that carries no Hardware, preferring one sitting in its slot.
|
||||
* `taken` are slots already planned this step.
|
||||
*/
|
||||
function recruitSlot(v: GameState, me: PlayerId, id: number, taken: number[] = []): number | null {
|
||||
if (!v.rules.recruit.on) return null;
|
||||
const avs = v.players[me].avatars;
|
||||
const avs = v.players[me].anomalies;
|
||||
const cores = (card: number) => defOf(v, card).cores;
|
||||
const empty = avs.findIndex((a, i) => i < 4 && a.card < 0 && !taken.includes(i + 1));
|
||||
const planned = taken.filter((slot) => avs[slot - 1].card < 0).length;
|
||||
const inUse = avs.filter((a, i) => (i < 4 ? a.card >= 0 : a.at !== null)).length;
|
||||
if (empty >= 0 && avatarRoom(v, me) && inUse + planned < 4) return empty + 1;
|
||||
if (empty >= 0 && anomalyRoom(v, me) && inUse + planned < 4) return empty + 1;
|
||||
const weaker = recruitSlots(v, me)
|
||||
.filter((slot) => !taken.includes(slot) && avs[slot - 1].card >= 0 && avs[slot - 1].hardware.length === 0)
|
||||
.filter((slot) => cores(avs[slot - 1].card) < cores(id))
|
||||
|
|
@ -172,15 +170,15 @@ function recruitSlot(v: GameState, me: PlayerId, id: number, taken: number[] = [
|
|||
return weaker[0] ?? null;
|
||||
}
|
||||
|
||||
/** Recruit the strongest Avatars in hand that fit, within `budget`. */
|
||||
/** Recruit the strongest Anomalies in hand that fit, within `budget`. */
|
||||
function recruitPlan(v: GameState, me: PlayerId, budget: number): Action[] {
|
||||
if (!v.rules.recruit.on) return [];
|
||||
const hand = v.players[me].hand
|
||||
.filter((id) => id >= 0 && defOf(v, id).kind === 'avatar')
|
||||
.filter((id) => id >= 0 && defOf(v, id).kind === 'anomaly')
|
||||
.sort((a, b) => defOf(v, b).cores - defOf(v, a).cores);
|
||||
const out: Extract<Action, { type: 'recruit' }>[] = [];
|
||||
for (const card of hand) {
|
||||
const price = printedRam(v, card);
|
||||
const price = printedBandwidth(v, card);
|
||||
const slot = price <= budget ? recruitSlot(v, me, card, out.map((a) => a.slot)) : null;
|
||||
if (slot === null) continue;
|
||||
out.push({ type: 'recruit', card, slot });
|
||||
|
|
@ -190,7 +188,7 @@ function recruitPlan(v: GameState, me: PlayerId, budget: number): Action[] {
|
|||
}
|
||||
|
||||
const reach = (v: GameState, me: PlayerId) =>
|
||||
v.players[me].ram + v.players[me].hand.reduce((t, id) => t + printedRam(v, id), 0);
|
||||
v.players[me].bandwidth + v.players[me].hand.reduce((t, id) => t + printedBandwidth(v, id), 0);
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// The board
|
||||
|
|
@ -204,9 +202,9 @@ function threatened(v: GameState, me: PlayerId): LocId[] {
|
|||
).sort((a, b) => worth(b) - worth(a));
|
||||
}
|
||||
|
||||
/** Avatars `me` can place, advance or attack with this turn. */
|
||||
function readyAvatars(v: GameState, me: PlayerId): { at: LocId | null; slot: number }[] {
|
||||
return v.players[me].avatars
|
||||
/** Anomalies `me` can place, advance or attack with this turn. */
|
||||
function readyAnomalies(v: GameState, me: PlayerId): { at: LocId | null; slot: number }[] {
|
||||
return v.players[me].anomalies
|
||||
.map((a, i) => ({ a, slot: i + 1 }))
|
||||
.filter(({ a, slot }) => a.faceUp && !a.advanced && a.attacks === 0 &&
|
||||
(a.at === null || canAct(v, { player: me, slot })))
|
||||
|
|
@ -235,20 +233,20 @@ interface TurnPlan {
|
|||
attackers: Set<number>;
|
||||
}
|
||||
|
||||
/** Infinite Loop: extra attacks for my Avatars attacking from `loc`. */
|
||||
/** Infinite Loop: extra attacks for my Anomalies attacking from `loc`. */
|
||||
const extraAttacksAt = (v: GameState, me: PlayerId, loc: LocId): number =>
|
||||
Math.max(0, ...sources(v).filter((x) => x.at === loc && x.controller === me).map((x) => scriptOf(x.name)?.extraAttacks ?? 0));
|
||||
|
||||
/**
|
||||
* Deploy-step plan for the whole turn: which Avatars advance, which attack and from where, and
|
||||
* Deploy-step plan for the whole turn: which Anomalies advance, which attack and from where, and
|
||||
* where the rest stand guard.
|
||||
*/
|
||||
function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
|
||||
const pl = v.players[me];
|
||||
const mine = locationsFrom(me).filter((l) => controls(v, me, l));
|
||||
const ready = readyAvatars(v, me);
|
||||
const ready = readyAnomalies(v, me);
|
||||
const occupant = new Map<LocId, number>();
|
||||
pl.avatars.forEach((a, i) => {
|
||||
pl.anomalies.forEach((a, i) => {
|
||||
if (a.at) occupant.set(a.at, i + 1);
|
||||
});
|
||||
for (const { at, slot } of ready) if (at) occupant.set(at, slot);
|
||||
|
|
@ -271,23 +269,23 @@ function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
|
|||
const ref = { player: me, slot };
|
||||
if (freshCopy(v, ref)) continue;
|
||||
if (!defended) {
|
||||
// Advancing needs no dice, so prefer weak Avatars and save strong ones for attacks.
|
||||
// Advancing needs no dice, so prefer weak Anomalies and save strong ones for attacks.
|
||||
const weakness = 0.01 * coresOf(v, { ref, role: 'attack', at: null, loc: null, combat: null });
|
||||
options.push({ kind: 'advance', slot, to, clear, score: value - clearCost * RAM_POINTS - weakness });
|
||||
options.push({ kind: 'advance', slot, to, clear, score: value - clearCost * BANDWIDTH_POINTS - weakness });
|
||||
continue;
|
||||
}
|
||||
const holder = occupant.get(from);
|
||||
if (holder !== undefined && holder !== slot) continue;
|
||||
const chance = attackOdds(v, ref, from, to);
|
||||
if (chance < params.minWinChance) {
|
||||
// Health rule: a lost roll only costs damage, so a healthy Avatar keeps a long shot in
|
||||
// Health rule: a lost roll only costs damage, so a healthy Anomaly keeps a long shot in
|
||||
// reserve for when there's nothing better to do (see below).
|
||||
if (v.rules.health.on && chance >= 0.25 && healthLeft(v, ref) * 2 >= healthOf(v, ref)) {
|
||||
longShots.push({ kind: 'attack', slot, to, origin: from, clear, score: chance });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const score = attackValue(v, ref, from, to, value) - clearCost * RAM_POINTS;
|
||||
const score = attackValue(v, ref, from, to, value) - clearCost * BANDWIDTH_POINTS;
|
||||
options.push({ kind: 'attack', slot, to, origin: from, clear, score });
|
||||
}
|
||||
}
|
||||
|
|
@ -371,7 +369,7 @@ function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
|
|||
}
|
||||
}
|
||||
const busy = new Set(final.map((o) => o.slot));
|
||||
// Health rule: a badly hurt Avatar with nothing to do goes back to its slot to heal.
|
||||
// Health rule: a badly hurt Anomaly with nothing to do goes back to its slot to heal.
|
||||
if (v.rules.health.on && v.rules.health.recall) {
|
||||
for (const { slot } of ready) {
|
||||
const cur = pos.get(slot) ?? null;
|
||||
|
|
@ -410,12 +408,12 @@ const inHand = (v: GameState, me: PlayerId, name: string): number | undefined =>
|
|||
/** How much a performing Server adds: Dedicated GPU power, and a Quantum Coprocessor copy. */
|
||||
function fromValue(v: GameState, me: PlayerId, from: LocId | null): number {
|
||||
if (from === null) return 0;
|
||||
const qc = refsInPlay(v, me).some((r) => avatar(v, r).at === from &&
|
||||
const qc = refsInPlay(v, me).some((r) => anomaly(v, r).at === from &&
|
||||
hardwareOf(v, r).some((h) => cardName(v, h) === 'Quantum Coprocessor' && hardwareActive(v, h)));
|
||||
return executionPower(v, me, from) + (qc ? 0.5 : 0);
|
||||
}
|
||||
|
||||
/** A legal play of a named Execution matching `pick`, ignoring RAM, from the best Server. */
|
||||
/** A legal play of a named Execution matching `pick`, ignoring Bandwidth, from the best Server. */
|
||||
function findPlay(v: GameState, me: PlayerId, name: string, pick: (a: Extract<Action, { type: 'play' }>) => boolean): Action | null {
|
||||
if (inHand(v, me, name) === undefined) return null;
|
||||
let best: Extract<Action, { type: 'play' }> | null = null;
|
||||
|
|
@ -426,7 +424,7 @@ function findPlay(v: GameState, me: PlayerId, name: string, pick: (a: Extract<Ac
|
|||
return best;
|
||||
}
|
||||
|
||||
/** A legal use of a named card's Ability matching `pick`, ignoring RAM. */
|
||||
/** A legal use of a named card's Ability matching `pick`, ignoring Bandwidth. */
|
||||
function findUse(v: GameState, me: PlayerId, name: string, pick: (a: Extract<Action, { type: 'activate' }>) => boolean = () => true): Action | null {
|
||||
for (const a of abilityActions(v, me, 'any')) if (a.type === 'activate' && a.name === name && pick(a)) return a;
|
||||
return null;
|
||||
|
|
@ -453,42 +451,42 @@ function hardwarePlan(v: GameState, me: PlayerId, attackers: Set<number>, budget
|
|||
const out: Action[] = [];
|
||||
const wearers = refsInPlay(v, me).filter((r) => !isCopy(r))
|
||||
.sort((x, y) => Number(attackers.has(y.slot)) - Number(attackers.has(x.slot)));
|
||||
const ports = new Map(wearers.map((r) => [r.slot, portsFree(v, r)]));
|
||||
const fights = (r: AvatarRef) => attackers.has(r.slot) || risky.includes(avatar(v, r).at!);
|
||||
const freeSlots = new Map(wearers.map((r) => [r.slot, slotsFree(v, r)]));
|
||||
const fights = (r: AnomalyRef) => attackers.has(r.slot) || risky.includes(anomaly(v, r).at!);
|
||||
const hasExecutions = pl.hand.some((id) => defOf(v, id).kind === 'execution');
|
||||
// Network Interface Upgrade first, since it opens a port for the rest.
|
||||
// Network Interface Upgrade first, since it opens an Expansion Slot for the rest.
|
||||
const niuFirst = (id: number) => (cardName(v, id) === 'Network Interface Upgrade' ? 1 : 0);
|
||||
const hand = [...pl.hand].sort((a, b) => niuFirst(b) - niuFirst(a) || hardwareCores(v, b) - hardwareCores(v, a));
|
||||
for (const card of hand) {
|
||||
const def = defOf(v, card);
|
||||
if (def.kind !== 'hardware') continue;
|
||||
const cores = hardwareCores(v, card) + hardwareHealth(v, card);
|
||||
let target: AvatarRef | undefined;
|
||||
let target: AnomalyRef | undefined;
|
||||
if (cores > 0) {
|
||||
// Core Hardware, and Health Hardware (RAM Expansion), go on Avatars that fight.
|
||||
// Core Hardware, and Health Hardware (RAM Expansion), go on Anomalies that fight.
|
||||
const attackOnly = def.name === 'Packet Accelerator';
|
||||
target = wearers.find((r) => ports.get(r.slot)! > 0 && fights(r) && (!attackOnly || attackers.has(r.slot)));
|
||||
target = wearers.find((r) => freeSlots.get(r.slot)! > 0 && fights(r) && (!attackOnly || attackers.has(r.slot)));
|
||||
} else if (def.name === 'Network Interface Upgrade') {
|
||||
// Adds a port: best on a fighter whose ports are full.
|
||||
target = [...wearers].sort((x, y) => ports.get(x.slot)! - ports.get(y.slot)!).find((r) => fights(r)) ?? wearers[0];
|
||||
// Adds an Expansion Slot: best on a fighter whose slots are full.
|
||||
target = [...wearers].sort((x, y) => freeSlots.get(x.slot)! - freeSlots.get(y.slot)!).find((r) => fights(r)) ?? wearers[0];
|
||||
} else if (useCards && (UTILITY_HARDWARE[def.name] ?? 0) > 0) {
|
||||
if (['Dedicated GPU', 'Quantum Coprocessor'].includes(def.name) && !hasExecutions) continue;
|
||||
const protects = ['Redundant Power Supply', 'RAID Array'].includes(def.name);
|
||||
target = wearers.find((r) => (protects ? avatar(v, r).hardware.length > 0 && ports.get(r.slot)! > 0 : ports.get(r.slot)! > 1));
|
||||
target = wearers.find((r) => (protects ? anomaly(v, r).hardware.length > 0 && freeSlots.get(r.slot)! > 0 : freeSlots.get(r.slot)! > 1));
|
||||
}
|
||||
if (!target) continue;
|
||||
const cost = hardwareCost(v, card, target);
|
||||
if (cost > budget) continue;
|
||||
budget -= cost;
|
||||
ports.set(target.slot, ports.get(target.slot)! + (def.name === 'Network Interface Upgrade' ? 1 : -1));
|
||||
freeSlots.set(target.slot, freeSlots.get(target.slot)! + (def.name === 'Network Interface Upgrade' ? 1 : -1));
|
||||
out.push({ type: 'installHardware', card, slot: target.slot });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Negative effects on an Avatar that Error Correction or Purge could clear. */
|
||||
const afflicted = (v: GameState, r: AvatarRef): boolean => {
|
||||
const av = avatar(v, r);
|
||||
/** Negative effects on an Anomaly that Error Correction or Purge could clear. */
|
||||
const afflicted = (v: GameState, r: AnomalyRef): boolean => {
|
||||
const av = anomaly(v, r);
|
||||
return av.infection + av.permanentInfection > 0 || hardwareOf(v, r).some((h) => !hardwareActive(v, h));
|
||||
};
|
||||
|
||||
|
|
@ -516,10 +514,10 @@ function programValue(v: GameState, me: PlayerId, name: string, at: LocId, risky
|
|||
case 'Hotfix':
|
||||
return here.length > 0 ? w * threat : 0;
|
||||
case 'Error Correction':
|
||||
return refsInPlay(v, me).some((r) => avatar(v, r).at === at && afflicted(v, r)) ? 2 : 0;
|
||||
return refsInPlay(v, me).some((r) => anomaly(v, r).at === at && afflicted(v, r)) ? 2 : 0;
|
||||
case 'Rollback Routine': {
|
||||
// Helps my Avatars attacking from here into Programs that cut Cores.
|
||||
const cutters = enemyNear.some((l) => v.locations[l].programs.some((id) => ['Memory Leak', 'Visual Artifact'].includes(cardName(v, id))));
|
||||
// Helps my Anomalies attacking from here into Programs that cut Cores.
|
||||
const cutters = enemyNear.some((l) => v.locations[l].programs.some((id) => ['Bloatware', 'Visual Artifact'].includes(cardName(v, id))));
|
||||
return guarded && cutters ? w * 1.5 : 0;
|
||||
}
|
||||
case 'Payload Injector':
|
||||
|
|
@ -552,7 +550,7 @@ function programPlan(v: GameState, me: PlayerId, budget: number): Action[] {
|
|||
for (const at of mine) {
|
||||
if (room.get(at)! <= 0 || v.locations[at].programs.some((id) => cardName(v, id) === name)) continue;
|
||||
const value = programValue(v, me, name, at, risky);
|
||||
picks.push({ card, at, value: value - programCost(v, me, card, at) * RAM_POINTS * 0.3 });
|
||||
picks.push({ card, at, value: value - programCost(v, me, card, at) * BANDWIDTH_POINTS * 0.3 });
|
||||
}
|
||||
}
|
||||
picks.sort((a, b) => b.value - a.value);
|
||||
|
|
@ -571,7 +569,7 @@ function programPlan(v: GameState, me: PlayerId, budget: number): Action[] {
|
|||
}
|
||||
|
||||
/** Enemy Programs that make an attack on `target` harder. */
|
||||
const HARD_TARGET = new Set(['Stack Overflow', 'Race Condition', 'Memory Leak', 'Visual Artifact', 'Memory Parasite', 'Stock Rice']);
|
||||
const HARD_TARGET = new Set(['Stack Overflow', 'Race Condition', 'Bloatware', 'Visual Artifact', 'Memory Parasite', 'Stock Rice']);
|
||||
|
||||
/** Step 3: switch off a Program that guards a location I'm about to attack, when it's worth it. */
|
||||
function clearTheWay(v: GameState, me: PlayerId, plan: TurnPlan | null): Action[] {
|
||||
|
|
@ -580,9 +578,9 @@ function clearTheWay(v: GameState, me: PlayerId, plan: TurnPlan | null): Action[
|
|||
for (const a of plan.attacks) {
|
||||
if (a.type !== 'attack') continue;
|
||||
const ref = { player: me, slot: a.slot };
|
||||
if (avatar(v, ref).at === null) continue; // the planned attacker left play (a copy removed by a recall)
|
||||
if (anomaly(v, ref).at === null) continue; // the planned attacker left play (a copy removed by a recall)
|
||||
const origin = [...plan.deploy].reverse().find((d) => d.type === 'place' && d.slot === a.slot);
|
||||
const from = origin?.type === 'place' ? origin.to : avatar(v, ref).at;
|
||||
const from = origin?.type === 'place' ? origin.to : anomaly(v, ref).at;
|
||||
if (!from) continue;
|
||||
const before = attackOdds(v, ref, from, a.to);
|
||||
let best: { play: Action; gain: number } | null = null;
|
||||
|
|
@ -603,7 +601,7 @@ function clearTheWay(v: GameState, me: PlayerId, plan: TurnPlan | null): Action[
|
|||
return out;
|
||||
}
|
||||
|
||||
/** Step 3: extra captures with Trace Route, and cleaning up Avatars before they fight. */
|
||||
/** Step 3: extra captures with Trace Route, and cleaning up Anomalies before they fight. */
|
||||
function preAttackPlays(v: GameState, me: PlayerId, plan: TurnPlan | null): Action[] {
|
||||
const out: Action[] = [];
|
||||
const planned = new Set(plan?.turn === v.turn ? [...plan.attackers] : []);
|
||||
|
|
@ -613,7 +611,7 @@ function preAttackPlays(v: GameState, me: PlayerId, plan: TurnPlan | null): Acti
|
|||
for (const a of executionActions(v, me, 'any')) {
|
||||
if (a.type !== 'play' || a.card !== trace) continue;
|
||||
const ref = a.args.ref!;
|
||||
const av = avatar(v, ref);
|
||||
const av = anomaly(v, ref);
|
||||
const t = a.target!;
|
||||
if (planned.has(ref.slot) || av.advanced || av.attacks > 0 || controls(v, me, t)) continue;
|
||||
// Don't pull a guard off a threatened location.
|
||||
|
|
@ -623,14 +621,14 @@ function preAttackPlays(v: GameState, me: PlayerId, plan: TurnPlan | null): Acti
|
|||
const bonus = 1 + executionPower(v, me, a.from);
|
||||
const defended = defendersAt(v, t).length > 0;
|
||||
const chance = defended ? attackOdds(v, ref, av.at!, t, bonus) : 1;
|
||||
const score = (defended ? attackValue(v, ref, av.at!, t, value, bonus) : value) - 5 * RAM_POINTS - CARD_POINTS;
|
||||
const score = (defended ? attackValue(v, ref, av.at!, t, value, bonus) : value) - 5 * BANDWIDTH_POINTS - CARD_POINTS;
|
||||
if (chance >= 0.6 && score > 0 && (!best || score > best.score)) best = { a, score };
|
||||
}
|
||||
if (best) out.push(best.a);
|
||||
}
|
||||
// Clean up Avatars carrying Infection or disabled Hardware.
|
||||
// Clean up Anomalies carrying Infection or disabled Hardware.
|
||||
for (const r of refsInPlay(v, me)) {
|
||||
const av = avatar(v, r);
|
||||
const av = anomaly(v, r);
|
||||
const disabled = hardwareOf(v, r).filter((h) => !hardwareActive(v, h));
|
||||
if (av.infection + av.permanentInfection < 2 && disabled.length === 0) continue;
|
||||
const purge = findPlay(v, me, 'Execute: Purge', (a) => (a.args.to ?? a.target) === av.at);
|
||||
|
|
@ -643,7 +641,7 @@ function preAttackPlays(v: GameState, me: PlayerId, plan: TurnPlan | null): Acti
|
|||
return out;
|
||||
}
|
||||
|
||||
/** Step 6: card draw, Exfiltrate, Restore Point and Undefined Behavior, when RAM is spare. */
|
||||
/** Step 6: card draw, Exfiltrate, Restore Point and Undefined Behavior, when Bandwidth is spare. */
|
||||
function utilityPlays(v: GameState, me: PlayerId, budget: number): Action[] {
|
||||
const out: Action[] = [];
|
||||
const add = (a: Action | null, cost: number) => {
|
||||
|
|
@ -658,8 +656,8 @@ function utilityPlays(v: GameState, me: PlayerId, budget: number): Action[] {
|
|||
// Restore Point: heal a wounded Backup Machine first, otherwise recover a good card.
|
||||
add(findUse(v, me, 'Backup Machine', (a) => {
|
||||
if (!a.args.heal) return false;
|
||||
const ref = refsInPlay(v, me).find((r) => avatar(v, r).card === a.card && !isCopy(r));
|
||||
return !!ref && avatar(v, ref).damage >= 3;
|
||||
const ref = refsInPlay(v, me).find((r) => anomaly(v, r).card === a.card && !isCopy(r));
|
||||
return !!ref && anomaly(v, ref).damage >= 3;
|
||||
}), 5);
|
||||
add(findUse(v, me, 'Backup Machine', (a) => {
|
||||
if (a.args.heal) return false;
|
||||
|
|
@ -668,7 +666,7 @@ function utilityPlays(v: GameState, me: PlayerId, budget: number): Action[] {
|
|||
}), 5);
|
||||
// Undefined Behavior: copy a strong defensive Program onto its own location.
|
||||
add(findUse(v, me, 'Undefined Behavior', (a) =>
|
||||
['Stack Overflow', 'Race Condition', 'Memory Leak'].includes(cardName(v, a.args.card!))), 0);
|
||||
['Stack Overflow', 'Race Condition', 'Bloatware'].includes(cardName(v, a.args.card!))), 0);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -681,11 +679,11 @@ function firewallPlan(v: GameState, me: PlayerId, params: GreedyParams, budget:
|
|||
const cost = firewallCost(v, params.firewallLevel);
|
||||
let left = params.maxFirewallsPerTurn;
|
||||
for (const loc of threatened(v, me)) {
|
||||
if (pl.avatars.some((a) => a.at === loc)) continue;
|
||||
if (pl.anomalies.some((a) => a.at === loc)) continue;
|
||||
const exposed = LINES_AT.get(loc)!.filter((l) => isOpen(v, l) && controls(v, opp, otherEnd(l, loc)));
|
||||
// A location reachable along a gateway-free line can't be walled off.
|
||||
if (exposed.some((l) => !l.gateway) || exposed.length > left) continue;
|
||||
if (budget - cost * exposed.length < params.ramReserve) break;
|
||||
if (budget - cost * exposed.length < params.bandwidthReserve) break;
|
||||
for (const line of exposed) out.push({ type: 'firewall', line: line.id, level: params.firewallLevel });
|
||||
budget -= cost * exposed.length;
|
||||
left -= exposed.length;
|
||||
|
|
@ -693,10 +691,10 @@ function firewallPlan(v: GameState, me: PlayerId, params: GreedyParams, budget:
|
|||
return out;
|
||||
}
|
||||
|
||||
/** RAM to keep for the opponent's turn: enough for the best trick held. */
|
||||
/** Bandwidth to keep for the opponent's turn: enough for the best trick held. */
|
||||
function heldReserve(v: GameState, me: PlayerId, params: GreedyParams): number {
|
||||
if (!params.useCards) return 0;
|
||||
const held = v.players[me].hand.filter((id) => HELD.has(cardName(v, id))).map((id) => printedRam(v, id));
|
||||
const held = v.players[me].hand.filter((id) => HELD.has(cardName(v, id))).map((id) => printedBandwidth(v, id));
|
||||
return Math.max(0, ...held);
|
||||
}
|
||||
|
||||
|
|
@ -705,8 +703,8 @@ const totalCost = (v: GameState, list: Action[]) => list.reduce((t, a) => t + ac
|
|||
function planPlay(v: GameState, me: PlayerId, params: GreedyParams, plan: TurnPlan | null): Action[] {
|
||||
const budget = spendable(v, me);
|
||||
const attackers = v.step === 'play' && plan?.turn === v.turn ? plan.attackers : new Set<number>();
|
||||
const sale = avatarForSale(v, me);
|
||||
const recruits = [...recruitPlan(v, me, budget), ...(sale && sale.price <= budget ? [{ type: 'buyAvatar', slot: sale.slot } as const] : [])];
|
||||
const sale = anomalyForSale(v, me);
|
||||
const recruits = [...recruitPlan(v, me, budget), ...(sale && sale.price <= budget ? [{ type: 'buyAnomaly', slot: sale.slot } as const] : [])];
|
||||
if (v.step === 'play') {
|
||||
const early = params.useCards ? [...clearTheWay(v, me, plan), ...preAttackPlays(v, me, plan)] : [];
|
||||
return [...recruits, ...early, ...hardwarePlan(v, me, attackers, budget - totalCost(v, [...recruits, ...early]), params.useCards)];
|
||||
|
|
@ -714,11 +712,11 @@ function planPlay(v: GameState, me: PlayerId, params: GreedyParams, plan: TurnPl
|
|||
const keep = heldReserve(v, me, params);
|
||||
const hw = hardwarePlan(v, me, attackers, budget - keep - totalCost(v, recruits), params.useCards);
|
||||
let left = budget - keep - totalCost(v, [...recruits, ...hw]);
|
||||
const progs = params.useCards ? programPlan(v, me, left - params.ramReserve) : [];
|
||||
const progs = params.useCards ? programPlan(v, me, left - params.bandwidthReserve) : [];
|
||||
left -= totalCost(v, progs);
|
||||
const walls = firewallPlan(v, me, params, left);
|
||||
left -= totalCost(v, walls);
|
||||
const extra = params.useCards ? utilityPlays(v, me, left - params.ramReserve) : [];
|
||||
const extra = params.useCards ? utilityPlays(v, me, left - params.bandwidthReserve) : [];
|
||||
return [...recruits, ...hw, ...progs, ...walls, ...extra];
|
||||
}
|
||||
|
||||
|
|
@ -784,7 +782,7 @@ function combatTrick(v: GameState, me: PlayerId): Action | null {
|
|||
const c = v.combat!;
|
||||
if (!c.rolled) return null;
|
||||
const base = combatValue(v, me);
|
||||
const price = (a: Action) => actionCost(v, a) * RAM_POINTS +
|
||||
const price = (a: Action) => actionCost(v, a) * BANDWIDTH_POINTS +
|
||||
(a.type === 'play' || (a.type === 'activate' && a.name === 'Beta Version 1.0') ? CARD_POINTS : 0);
|
||||
let best: Action | null = null;
|
||||
let bestGain = 0.25;
|
||||
|
|
@ -798,7 +796,7 @@ function combatTrick(v: GameState, me: PlayerId): Action | null {
|
|||
for (const a of [...executionActions(v, me, 'reachable'), ...abilityActions(v, me, 'reachable')]) {
|
||||
if (!touchesCombat(v, a)) continue;
|
||||
if (a.type === 'activate' && a.name === 'Broken Bits') {
|
||||
const ref = refsInPlay(v, me).find((r) => avatar(v, r).card === a.card && !isCopy(r))!;
|
||||
const ref = refsInPlay(v, me).find((r) => anomaly(v, r).card === a.card && !isCopy(r))!;
|
||||
consider(a, combatValue(v, me, { ref, k: a.args.k! }));
|
||||
continue;
|
||||
}
|
||||
|
|
@ -812,14 +810,14 @@ function combatTrick(v: GameState, me: PlayerId): Action | null {
|
|||
function stopDeclaration(v: GameState, me: PlayerId): Action | null {
|
||||
const d = v.declarations[v.declarations.length - 1];
|
||||
if (!d || d.ref.player === me || !controls(v, me, d.to)) return null;
|
||||
const at = avatar(v, d.ref).at;
|
||||
const at = anomaly(v, d.ref).at;
|
||||
if (at === null) return null;
|
||||
const defended = defendersAt(v, d.to).length > 0;
|
||||
const risk = defended ? fallChance(v, d.ref, d.from, d.to) : 1;
|
||||
const stake = risk * locationValue(v, d.ref.player, d.to);
|
||||
// Root the Avatar that declared, so it can't move.
|
||||
// Root the Anomaly that declared, so it can't move.
|
||||
const flood = findPlay(v, me, 'Execute: Packet Flood', (a) => (a.args.to ?? a.target) === at);
|
||||
if (flood && stake > 5 * RAM_POINTS + CARD_POINTS + 2) return flood;
|
||||
if (flood && stake > 5 * BANDWIDTH_POINTS + CARD_POINTS + 2) return flood;
|
||||
if (defended) return null;
|
||||
// Put a copy in the way.
|
||||
const replicate = findUse(v, me, 'Carbon NanoBots', (a) => a.args.to === d.to);
|
||||
|
|
@ -829,16 +827,16 @@ function stopDeclaration(v: GameState, me: PlayerId): Action | null {
|
|||
// Or cash in the Programs there before they're lost.
|
||||
const progs = v.locations[d.to].programs;
|
||||
if (progs.length === 0) return null;
|
||||
const top = Math.max(...progs.map((p) => printedRam(v, p)));
|
||||
const gc = findUse(v, me, 'Garbage Collection', (a) => programLocation(v, a.args.card!) === d.to && printedRam(v, a.args.card!) === top);
|
||||
const top = Math.max(...progs.map((p) => printedBandwidth(v, p)));
|
||||
const gc = findUse(v, me, 'Garbage Collection', (a) => programLocation(v, a.args.card!) === d.to && printedBandwidth(v, a.args.card!) === top);
|
||||
if (gc) return gc;
|
||||
const reset = findPlay(v, me, 'Execute: Hard Reset', (a) => a.target === d.to && a.args.cards!.length === progs.length);
|
||||
return reset && progs.reduce((t, p) => t + printedRam(v, p), 0) >= 8 ? reset : null;
|
||||
return reset && progs.reduce((t, p) => t + printedBandwidth(v, p), 0) >= 8 ? reset : null;
|
||||
}
|
||||
|
||||
/** Sends back an expensive enemy Program or Hardware installed this turn. */
|
||||
function rollbackInstall(v: GameState, me: PlayerId): Action | null {
|
||||
return findPlay(v, me, 'Execute: Rollback', (a) => v.cards[a.args.card!].owner !== me && printedRam(v, a.args.card!) >= 7);
|
||||
return findPlay(v, me, 'Execute: Rollback', (a) => v.cards[a.args.card!].owner !== me && printedBandwidth(v, a.args.card!) >= 7);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
@ -852,22 +850,24 @@ function choose(v: GameState, me: PlayerId, ch: Choice): number {
|
|||
for (let i = 1; i < opts.length; i++) if (score(i) > score(b)) b = i;
|
||||
return b;
|
||||
};
|
||||
const cardVal = (id: number) => keepScore(v, id) + printedRam(v, id) * 0.2;
|
||||
const cardVal = (id: number) => keepScore(v, id) + printedBandwidth(v, id) * 0.2;
|
||||
const yesIfAffordable = (yes: unknown) => {
|
||||
const i = opts.findIndex((o) => o.value === yes);
|
||||
return i >= 0 && (opts[i].cost ?? 0) <= v.players[me].ram ? i : opts.findIndex((o) => o.value !== yes);
|
||||
return i >= 0 && (opts[i].cost ?? 0) <= v.players[me].bandwidth ? i : opts.findIndex((o) => o.value !== yes);
|
||||
};
|
||||
switch (ch.kind) {
|
||||
case 'Callable Server:redraw': {
|
||||
const card = v.players[me].hand[v.players[me].hand.length - 1];
|
||||
return opts.findIndex((o) => o.value === (keepScore(v, card) < 2));
|
||||
// The drawn card, unless it has left the hand since (salvaged while choosing).
|
||||
const card = (ch.resume.data as { card: number }).card;
|
||||
const redraw = v.players[me].hand.includes(card) && keepScore(v, card) < 2;
|
||||
return opts.findIndex((o) => o.value === redraw);
|
||||
}
|
||||
case 'Diagnostic Module:bottom': {
|
||||
const weak = opts.some((o) => /Network Interface|Root Access|Execute: Rollback|Ping Sweep/.test(o.label));
|
||||
return opts.findIndex((o) => o.value === weak);
|
||||
}
|
||||
case 'Duplicate Server:copy': {
|
||||
const rank = ['Cloud Compute', 'Server Farm', 'MultiCore Server', 'High Efficiency RAM Server', 'Power Server',
|
||||
const rank = ['Cloud Compute', 'Server Farm', 'MultiCore Server', 'High Bandwidth Server', 'Power Server',
|
||||
'Cluster Server', 'Pingable Server', 'Backup Server', 'Protected Server'];
|
||||
return best((i) => -((rank.indexOf(String(val(i))) + 1) || 99));
|
||||
}
|
||||
|
|
@ -885,7 +885,7 @@ function choose(v: GameState, me: PlayerId, ch: Choice): number {
|
|||
case 'Overflow Error:hit':
|
||||
return best((i) => {
|
||||
const x = val(i) as { card: number; mode: string };
|
||||
return printedRam(v, x.card) + (x.mode === 'destroy' ? 0.5 : 0);
|
||||
return printedBandwidth(v, x.card) + (x.mode === 'destroy' ? 0.5 : 0);
|
||||
});
|
||||
case 'Error Correction:remove':
|
||||
return best((i) => {
|
||||
|
|
@ -895,7 +895,7 @@ function choose(v: GameState, me: PlayerId, ch: Choice): number {
|
|||
});
|
||||
case 'Version Control:save':
|
||||
case 'Hardware Sandbox:protect':
|
||||
return best((i) => printedRam(v, val(i) as number) + (PROGRAM_WEIGHT[cardName(v, val(i) as number)] ?? 0));
|
||||
return best((i) => printedBandwidth(v, val(i) as number) + (PROGRAM_WEIGHT[cardName(v, val(i) as number)] ?? 0));
|
||||
case 'RAID Array:keep':
|
||||
return yesIfAffordable(true);
|
||||
case 'Backup Machine:install':
|
||||
|
|
@ -906,7 +906,7 @@ function choose(v: GameState, me: PlayerId, ch: Choice): number {
|
|||
case 'Execute: Memory Dump:discard':
|
||||
return best((i) => -cardVal(val(i) as number));
|
||||
case 'Data Leaker:discard':
|
||||
return best((i) => printedRam(v, val(i) as number));
|
||||
return best((i) => printedBandwidth(v, val(i) as number));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -932,7 +932,7 @@ export function greedyBot(params: GreedyParams = DEFAULT_GREEDY): Bot {
|
|||
/** The next action toward `a`: a Salvage to afford it, or `a` itself. Null if it can't happen. */
|
||||
function toward(v: GameState, me: PlayerId, a: Action, legal: Map<string, Action>): Action | null {
|
||||
const cost = actionCost(v, a);
|
||||
if (cost > v.players[me].ram) return salvageFor(v, me, cost, spentCard(a));
|
||||
if (cost > v.players[me].bandwidth) return salvageFor(v, me, cost, spentCard(a));
|
||||
return legal.get(actionKey(a)) ?? null;
|
||||
}
|
||||
|
||||
|
|
@ -995,7 +995,7 @@ export function greedyBot(params: GreedyParams = DEFAULT_GREEDY): Bot {
|
|||
while (queue.length > 0) {
|
||||
const next = queue[0];
|
||||
const cost = actionCost(v, next);
|
||||
if (cost > v.players[me].ram) {
|
||||
if (cost > v.players[me].bandwidth) {
|
||||
const salvage = salvageFor(v, me, cost, spentCard(next));
|
||||
if (salvage) return salvage;
|
||||
queue.shift();
|
||||
|
|
|
|||
|
|
@ -1,22 +1,20 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { parseCsvObjects } from './csv.ts';
|
||||
|
||||
export type CardKind = 'avatar' | 'server' | 'program' | 'hardware' | 'execution';
|
||||
export type CardKind = 'anomaly' | 'server' | 'program' | 'hardware' | 'execution';
|
||||
|
||||
export interface CardDef {
|
||||
name: string;
|
||||
kind: CardKind;
|
||||
/** Printed RAM: play cost and salvage value. Avatars and Servers print none. */
|
||||
ram: number;
|
||||
/** Printed Bandwidth: play cost and salvage value. Anomalies and Servers print none. */
|
||||
bandwidth: number;
|
||||
cores: number;
|
||||
/** Avatar Health: the damage that destroys it (health rule). 0 when not printed. */
|
||||
/** Anomaly Health: the damage that destroys it (health rule). 0 when not printed. */
|
||||
health: number;
|
||||
/** Expansion Slots (Hardware ports). */
|
||||
/** Expansion Slots (how much Hardware an Anomaly holds). */
|
||||
slots: number;
|
||||
/** V / B / G / P, when printed. */
|
||||
type: string;
|
||||
/** Card text; flavor text for Avatars. */
|
||||
/** Card text; flavor text for Anomalies. */
|
||||
text: string;
|
||||
ability?: { name: string; cost: number; text: string };
|
||||
/** Card set: 1 is the base game, 2 the expansion. Rows without a Set column are set 1. */
|
||||
|
|
@ -29,7 +27,7 @@ export interface CardPool {
|
|||
}
|
||||
|
||||
const KIND_BY_TEMPLATE: Record<string, CardKind> = {
|
||||
'Avatar Front': 'avatar',
|
||||
'Anomaly Front': 'anomaly',
|
||||
'Server Front': 'server',
|
||||
'Server Front Alt': 'server',
|
||||
'Program Front': 'program',
|
||||
|
|
@ -37,20 +35,17 @@ const KIND_BY_TEMPLATE: Record<string, CardKind> = {
|
|||
'Execution Front': 'execution',
|
||||
};
|
||||
|
||||
export const DEFAULT_CARDS_CSV = fileURLToPath(
|
||||
new URL('../../decks/files-deck-1/cards.csv', import.meta.url),
|
||||
);
|
||||
|
||||
const num = (s: string | undefined): number => (s ? Number(s) : 0);
|
||||
|
||||
/**
|
||||
* Loads the Cider deck CSV. Reference cards (Turn Sequence) are skipped. By default only set 1 (the
|
||||
* base game) is loaded; `sets` picks others, or 'all'. Set 2 cards have no scripts yet.
|
||||
* Reads the Cider deck CSV's text. Reference cards (Turn Sequence) are skipped. By default only set
|
||||
* 1 (the base game) is loaded; `sets` picks others, or 'all'. Set 2 cards have no scripts yet.
|
||||
* `source` names the file in errors. Node code can use `loadCards` in load.ts to read the file.
|
||||
*/
|
||||
export function loadCards(path = DEFAULT_CARDS_CSV, sets: number[] | 'all' = [1]): CardPool {
|
||||
export function parseCards(csv: string, sets: number[] | 'all' = [1], source = 'cards.csv'): CardPool {
|
||||
const all: CardDef[] = [];
|
||||
const byName = new Map<string, CardDef>();
|
||||
for (const row of parseCsvObjects(readFileSync(path, 'utf8'))) {
|
||||
for (const row of parseCsvObjects(csv)) {
|
||||
const kind = KIND_BY_TEMPLATE[row['Front Template']];
|
||||
if (!kind) continue;
|
||||
const set = row['Set'] ? Number(row['Set']) : 1;
|
||||
|
|
@ -58,7 +53,7 @@ export function loadCards(path = DEFAULT_CARDS_CSV, sets: number[] | 'all' = [1]
|
|||
const card: CardDef = {
|
||||
name: row['Name'],
|
||||
kind,
|
||||
ram: num(row['RAM']),
|
||||
bandwidth: num(row['Bandwidth']),
|
||||
cores: num(row['Cores']),
|
||||
health: num(row['Health']),
|
||||
slots: num(row['Expansion Slots']),
|
||||
|
|
@ -73,7 +68,7 @@ export function loadCards(path = DEFAULT_CARDS_CSV, sets: number[] | 'all' = [1]
|
|||
text: row['Ability Description'],
|
||||
};
|
||||
}
|
||||
if (byName.has(card.name)) throw new Error(`Duplicate card name in ${path}: ${card.name}`);
|
||||
if (byName.has(card.name)) throw new Error(`Duplicate card name in ${source}: ${card.name}`);
|
||||
all.push(card);
|
||||
byName.set(card.name, card);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
/**
|
||||
* Avatar Abilities. Each costs the RAM printed on the card, can be used once per turn at
|
||||
* Execution timing, and only while the Avatar is in play. For Abilities, "a combat at this
|
||||
* Server" means any combat the Avatar is fighting in, attacking or defending.
|
||||
* Anomaly Abilities. Each costs the Bandwidth printed on the card, can be used once per turn at
|
||||
* Execution timing, and only while the Anomaly is in play. For Abilities, "a combat at this
|
||||
* Server" means any combat the Anomaly is fighting in, attacking or defending.
|
||||
*/
|
||||
import { createCopy, drawCards } from '../flow.ts';
|
||||
import { LOCATIONS } from '../map.ts';
|
||||
import { canCopy, costOf, hardwareActive, hasRoom, portsFree } from '../query.ts';
|
||||
import { canCopy, costOf, hardwareActive, hasRoom, slotsFree } from '../query.ts';
|
||||
import type { Script } from '../scripts.ts';
|
||||
import {
|
||||
addMod,
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
copyOf,
|
||||
defOf,
|
||||
endOf,
|
||||
|
|
@ -31,27 +31,27 @@ import {
|
|||
toDiscard,
|
||||
toHand,
|
||||
} from '../state.ts';
|
||||
import type { AvatarRef, GameState } from '../types.ts';
|
||||
import type { AnomalyRef, GameState } from '../types.ts';
|
||||
import { attachHardware } from './hardware.ts';
|
||||
import { cardOptions } from './util.ts';
|
||||
|
||||
/** Hardware cost after discounts (Upgraded Hardware), for Abilities that install Hardware. */
|
||||
const installCost = (s: GameState, card: number, ref: AvatarRef) =>
|
||||
costOf(s, { kind: 'hardware', player: ref.player, card, ref, at: avatar(s, ref).at });
|
||||
const installCost = (s: GameState, card: number, ref: AnomalyRef) =>
|
||||
costOf(s, { kind: 'hardware', player: ref.player, card, ref, at: anomaly(s, ref).at });
|
||||
|
||||
export const AVATARS: Record<string, Script> = {
|
||||
export const ANOMALIES: Record<string, Script> = {
|
||||
// The copy has the same Cores and uses the original's Hardware bonuses, but no Hardware or
|
||||
// Ability of its own. It enters play on a location you control with room.
|
||||
'Carbon NanoBots': {
|
||||
text: 'Avatar may create a copy of itself. Only one copy is allowed at a time. If the copy is defeated the original does not lose any hardware upgrades. If the original is defeated the replicate is as well.',
|
||||
text: 'Anomaly may create a copy of itself. Only one copy is allowed at a time. If the copy is defeated the original does not lose any hardware upgrades. If the original is defeated the replicate is as well.',
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
if (avatar(s, copyOf(src.ref!)).at !== null || !canCopy(s, src.controller)) return [];
|
||||
if (anomaly(s, copyOf(src.ref!)).at !== null || !canCopy(s, src.controller)) return [];
|
||||
return LOCATIONS.filter((l) => hasRoom(s, src.controller, l)).map((to) => ({ to }));
|
||||
},
|
||||
resolve(s, item, src) {
|
||||
const to = item.args.to!;
|
||||
if (avatar(s, copyOf(src.ref!)).at !== null || !canCopy(s, src.controller) || !hasRoom(s, src.controller, to)) return;
|
||||
if (anomaly(s, copyOf(src.ref!)).at !== null || !canCopy(s, src.controller) || !hasRoom(s, src.controller, to)) return;
|
||||
fired(s, 'Carbon NanoBots', src.controller);
|
||||
createCopy(s, src.ref!, to);
|
||||
},
|
||||
|
|
@ -59,7 +59,7 @@ export const AVATARS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Corrupt Driver': {
|
||||
text: 'Choose one Hardware on an enemy Avatar in combat with this Avatar. It is disabled until the end of your next command.',
|
||||
text: 'Choose one Hardware on an enemy Anomaly in combat with this Anomaly. It is disabled until the end of your next command.',
|
||||
ability: {
|
||||
uses: (s, src) =>
|
||||
[...new Set(opponentsInCombat(s, src.ref!).flatMap((r) => hardwareOf(s, r)))]
|
||||
|
|
@ -75,7 +75,7 @@ export const AVATARS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Pixelated Picture': {
|
||||
text: 'Attacking Avatars have -1 cores against this Avatar.',
|
||||
text: 'Attacking Anomalies have -1 cores against this Anomaly.',
|
||||
ability: {
|
||||
uses: (s, src) => (inCombat(s, src.ref!) && s.combat!.defenders.some((d) => refKey(d) === refKey(src.ref!)) ? [{}] : []),
|
||||
resolve(s, _item, src) {
|
||||
|
|
@ -83,15 +83,15 @@ export const AVATARS: Record<string, Script> = {
|
|||
if (!c || c.ended) return;
|
||||
addMod(s, c.attacker, -1, 'Low Resolution', src.controller, { combat: c.id });
|
||||
fired(s, 'Pixelated Picture', src.controller);
|
||||
say(s, `Low Resolution: ${avatarName(s, c.attacker)} gets -1 Core.`);
|
||||
say(s, `Low Resolution: ${anomalyName(s, c.attacker)} gets -1 Core.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: during a combat it's in, install one Hardware from hand on it (paying its cost),
|
||||
// ignoring ports. That Hardware is discarded at the end of your turn.
|
||||
// ignoring Expansion Slots. That Hardware is discarded at the end of your turn.
|
||||
'Beta Version 1.0': {
|
||||
text: 'While in combat an additional piece of hardware can be placed on this avatar until the end of your command. If there no ports available this can still be attached.',
|
||||
text: 'While in combat an additional piece of hardware can be placed on this anomaly until the end of your command. If there are no Expansion Slots available this can still be attached.',
|
||||
ability: {
|
||||
uses: (s, src) =>
|
||||
inCombat(s, src.ref!)
|
||||
|
|
@ -105,28 +105,28 @@ export const AVATARS: Record<string, Script> = {
|
|||
const turn = s.active === src.controller ? s.turn : nextTurnOf(s, src.controller);
|
||||
s.cards[card].pushedUntil = endOf(turn);
|
||||
fired(s, 'Beta Version 1.0', src.controller);
|
||||
say(s, `Push Update attaches ${nameOf(s, card)} to ${avatarName(s, src.ref!)} until the end of ${playerName(src.controller)}'s turn.`);
|
||||
say(s, `Push Update attaches ${nameOf(s, card)} to ${anomalyName(s, src.ref!)} until the end of ${playerName(src.controller)}'s turn.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Code Zero': {
|
||||
text: 'Place an Infection counter on every enemy Avatar in combat at this Server. While this Avatar is in play, an Avatar with 1+ Infection counters has -1 Core.',
|
||||
globalCores: (s, f) => (infectionOf(avatar(s, f.ref)) >= 1 ? -1 : 0),
|
||||
text: 'Place an Infection counter on every enemy Anomaly in combat at this Server. While this Anomaly is in play, an Anomaly with 1+ Infection counters has -1 Core.',
|
||||
globalCores: (s, f) => (infectionOf(anomaly(s, f.ref)) >= 1 ? -1 : 0),
|
||||
ability: {
|
||||
uses: (s, src) => (opponentsInCombat(s, src.ref!).length ? [{}] : []),
|
||||
resolve(s, _item, src) {
|
||||
const foes = opponentsInCombat(s, src.ref!);
|
||||
for (const r of foes) avatar(s, r).infection++;
|
||||
for (const r of foes) anomaly(s, r).infection++;
|
||||
fired(s, 'Code Zero', src.controller);
|
||||
say(s, `Patient Zero infects ${foes.map((r) => `${avatarName(s, r)} (${infectionOf(avatar(s, r))})`).join(', ')}.`);
|
||||
say(s, `Patient Zero infects ${foes.map((r) => `${anomalyName(s, r)} (${infectionOf(anomaly(s, r))})`).join(', ')}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// "Breached a Server" = captured an enemy location this turn.
|
||||
'Data Leaker': {
|
||||
text: "Look at your opponent's hand and choose one card in it. They must discard that card without gaining RAM. If this Avatar breached a Server this command, draw a card.",
|
||||
text: "Look at your opponent's hand and choose one card in it. They must discard that card without gaining Bandwidth. If this Anomaly breached a Server this command, draw a card.",
|
||||
ability: {
|
||||
uses: (s, src) => (s.players[other(src.controller)].hand.length ? [{}] : []),
|
||||
resolve(s, _item, src) {
|
||||
|
|
@ -143,35 +143,35 @@ export const AVATARS: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
resume: {
|
||||
discard(s, data: { ref: AvatarRef }, card: number) {
|
||||
discard(s, data: { ref: AnomalyRef }, card: number) {
|
||||
const p = data.ref.player;
|
||||
if (removeFrom(s.players[other(p)].hand, card)) {
|
||||
toDiscard(s, card);
|
||||
say(s, `Exfiltrate: ${playerName(other(p))} discards ${nameOf(s, card)}.`);
|
||||
}
|
||||
if (avatar(s, data.ref).breachedTurn === s.turn) drawCards(s, p, 1);
|
||||
if (anomaly(s, data.ref).breachedTurn === s.turn) drawCards(s, p, 1);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Restore Point either heals 3 damage (health rule) or recovers a card from the discard pile.
|
||||
'Backup Machine': {
|
||||
text: 'Remove 3 damage from this Avatar, or return one Hardware or Program from your discard pile to your hand. If it is a Hardware and this Avatar has an open port, you may install it immediately for 2 less RAM.',
|
||||
text: 'Remove 3 damage from this Anomaly, or return one Hardware or Program from your discard pile to your hand. If it is a Hardware and this Anomaly has an open Expansion Slot, you may install it immediately for 2 less Gb.',
|
||||
ability: {
|
||||
uses: (s, src) => [
|
||||
...(s.rules.health.on && avatar(s, src.ref!).damage > 0 ? [{ heal: true }] : []),
|
||||
...(s.rules.health.on && anomaly(s, src.ref!).damage > 0 ? [{ heal: true }] : []),
|
||||
...cardOptions(s, s.players[src.controller].discard.filter((id) => ['hardware', 'program'].includes(defOf(s, id).kind)))
|
||||
.map((o) => ({ card: o.value as number })),
|
||||
],
|
||||
resolve(s, item, src) {
|
||||
const p = src.controller;
|
||||
if (item.args.heal) {
|
||||
const av = avatar(s, src.ref!);
|
||||
const av = anomaly(s, src.ref!);
|
||||
if (av.at === null || av.damage === 0) return;
|
||||
const healed = Math.min(3, av.damage);
|
||||
av.damage -= healed;
|
||||
fired(s, 'Backup Machine', p);
|
||||
say(s, `Restore Point heals ${healed} damage on ${avatarName(s, src.ref!)}.`);
|
||||
say(s, `Restore Point heals ${healed} damage on ${anomalyName(s, src.ref!)}.`);
|
||||
return;
|
||||
}
|
||||
const card = item.args.card!;
|
||||
|
|
@ -179,34 +179,34 @@ export const AVATARS: Record<string, Script> = {
|
|||
toHand(s, card);
|
||||
fired(s, 'Backup Machine', p);
|
||||
say(s, `Restore Point returns ${nameOf(s, card)} to ${playerName(p)}'s hand.`);
|
||||
if (defOf(s, card).kind !== 'hardware' || portsFree(s, src.ref!) <= 0) return;
|
||||
if (defOf(s, card).kind !== 'hardware' || slotsFree(s, src.ref!) <= 0) return;
|
||||
const cost = Math.max(0, installCost(s, card, src.ref!) - 2);
|
||||
ask(s, {
|
||||
player: p,
|
||||
kind: 'Backup Machine:install',
|
||||
prompt: `Restore Point: install ${nameOf(s, card)} on ${avatarName(s, src.ref!)} now for ${cost} RAM?`,
|
||||
prompt: `Restore Point: install ${nameOf(s, card)} on ${anomalyName(s, src.ref!)} now for ${cost} Gb?`,
|
||||
options: [
|
||||
{ label: 'Keep it in hand', value: false },
|
||||
{ label: `Install it for ${cost} RAM`, value: true, cost },
|
||||
{ label: `Install it for ${cost} Gb`, value: true, cost },
|
||||
],
|
||||
resume: { name: 'Backup Machine', fn: 'install', data: { card, ref: src.ref! as never, cost } },
|
||||
});
|
||||
},
|
||||
},
|
||||
resume: {
|
||||
install(s, data: { card: number; ref: AvatarRef; cost: number }, yes: boolean) {
|
||||
if (!yes || avatar(s, data.ref).at === null || !s.players[data.ref.player].hand.includes(data.card)) return;
|
||||
s.players[data.ref.player].ram -= data.cost;
|
||||
s.stats.ramOnCards[data.ref.player] += data.cost;
|
||||
install(s, data: { card: number; ref: AnomalyRef; cost: number }, yes: boolean) {
|
||||
if (!yes || anomaly(s, data.ref).at === null || !s.players[data.ref.player].hand.includes(data.card)) return;
|
||||
s.players[data.ref.player].bandwidth -= data.cost;
|
||||
s.stats.bandwidthOnCards[data.ref.player] += data.cost;
|
||||
attachHardware(s, data.card, data.ref);
|
||||
say(s, `${nameOf(s, data.card)} is installed on ${avatarName(s, data.ref)}.`);
|
||||
say(s, `${nameOf(s, data.card)} is installed on ${anomalyName(s, data.ref)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Rerolls this Avatar's dice showing k or less; that's always the best way to pick dice.
|
||||
// Rerolls this Anomaly's dice showing k or less; that's always the best way to pick dice.
|
||||
'Broken Bits': {
|
||||
text: "During a combat at this Server, reroll any number of this Avatar's Core dice.",
|
||||
text: "During a combat at this Server, reroll any number of this Anomaly's Core dice.",
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
const c = s.combat;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Executions. Each targets a location (the "target Server") and resolves there, then goes to the
|
||||
* discard pile. Ghost Process lets its controller's Executions reach one adjacent location too.
|
||||
*/
|
||||
import { dropFromCombat, endCombat, moveAvatar } from '../flow.ts';
|
||||
import { dropFromCombat, endCombat, moveAnomaly } from '../flow.ts';
|
||||
import { LOCATIONS, isStart } from '../map.ts';
|
||||
import { canTargetProgram, emit, hardwareActive, hasRoom, programActive } from '../query.ts';
|
||||
import type { Play, Script } from '../scripts.ts';
|
||||
|
|
@ -11,16 +11,16 @@ import {
|
|||
addMod,
|
||||
adjacent,
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
avatarsAt,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
anomaliesAt,
|
||||
canAct,
|
||||
controls,
|
||||
defendersAt,
|
||||
endOfTurn,
|
||||
fightersOf,
|
||||
fired,
|
||||
gainRam,
|
||||
gainBandwidth,
|
||||
hardwareOf,
|
||||
inCombat,
|
||||
later,
|
||||
|
|
@ -47,14 +47,14 @@ import {
|
|||
uninstallProgram,
|
||||
wearerOf,
|
||||
} from '../state.ts';
|
||||
import { FOREVER, type AvatarRef, type GameState, type PlayerId, type Task } from '../types.ts';
|
||||
import { FOREVER, type AnomalyRef, type GameState, type PlayerId, type Task } from '../types.ts';
|
||||
import { shedHardware } from './hardware.ts';
|
||||
import { cardOptions, ghostsOf, mine, programsOn, scopeOf, subsets } from './util.ts';
|
||||
|
||||
const liveCombat = (s: GameState) => (s.combat && !s.combat.ended ? s.combat : null);
|
||||
|
||||
/** Unique Avatar refs. */
|
||||
function uniq(refs: AvatarRef[]): AvatarRef[] {
|
||||
/** Unique Anomaly refs. */
|
||||
function uniq(refs: AnomalyRef[]): AnomalyRef[] {
|
||||
const seen = new Set<string>();
|
||||
return refs.filter((r) => !seen.has(refKey(r)) && !!seen.add(refKey(r)));
|
||||
}
|
||||
|
|
@ -73,42 +73,42 @@ function acrossScope(s: GameState, p: PlayerId, argsAt: (loc: string) => Play['a
|
|||
return out;
|
||||
}
|
||||
|
||||
const wearerList = (s: GameState, hw: number | undefined): AvatarRef[] => {
|
||||
const wearerList = (s: GameState, hw: number | undefined): AnomalyRef[] => {
|
||||
const r = hw === undefined ? null : wearerOf(s, hw);
|
||||
return r ? [r] : [];
|
||||
};
|
||||
|
||||
export const EXECUTIONS: Record<string, Script> = {
|
||||
// Reading: the Avatar moves to a location you control with room. An attacker "at" the target
|
||||
// Reading: the Anomaly moves to a location you control with room. An attacker "at" the target
|
||||
// (attacking it) can retreat back to where it stands.
|
||||
'Execute: Disconnect': {
|
||||
text: 'Move one Avatar you control at the target Server to an adjacent Server, removing it from any combat there.',
|
||||
text: 'Move one Anomaly you control at the target Server to an adjacent Server, removing it from any combat there.',
|
||||
execution: {
|
||||
plays: (s, p) =>
|
||||
acrossScope(s, p, (loc) =>
|
||||
mine(s, p, loc)
|
||||
.filter((ref) => canAct(s, ref))
|
||||
.flatMap((ref) => {
|
||||
const at = avatar(s, ref).at!;
|
||||
const at = anomaly(s, ref).at!;
|
||||
const dests = neighbors(s, loc).filter((d) => d !== at && hasRoom(s, p, d));
|
||||
if (inCombat(s, ref) && at !== loc) dests.push(at);
|
||||
return dests.map((to) => ({ ref, to }));
|
||||
})),
|
||||
targetsAvatars: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
targetsAnomalies: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
resolve(s, item) {
|
||||
const { ref, to } = item.args as { ref: AvatarRef; to: string };
|
||||
const av = avatar(s, ref);
|
||||
const { ref, to } = item.args as { ref: AnomalyRef; to: string };
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null || !canAct(s, ref) || (to !== av.at && !hasRoom(s, ref.player, to))) return;
|
||||
fired(s, item.name, item.player);
|
||||
if (inCombat(s, ref)) dropFromCombat(s, ref);
|
||||
if (to !== av.at) moveAvatar(s, ref, to);
|
||||
if (to !== av.at) moveAnomaly(s, ref, to);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: an unspecified disable lasts until something re-enables it (Execute: Defragment).
|
||||
'Execute: Sabotage': {
|
||||
text: 'Destroy or disable one Hardware on an enemy Avatar in combat at the target Server.',
|
||||
text: 'Destroy or disable one Hardware on an enemy Anomaly in combat at the target Server.',
|
||||
execution: {
|
||||
plays(s, p) {
|
||||
const c = liveCombat(s);
|
||||
|
|
@ -120,7 +120,7 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
...(hardwareActive(s, card) ? [{ target, args: { card, mode: 'disable' as const } }] : []),
|
||||
]));
|
||||
},
|
||||
targetsAvatars: (s, item) => wearerList(s, item.args.card),
|
||||
targetsAnomalies: (s, item) => wearerList(s, item.args.card),
|
||||
resolve(s, item) {
|
||||
const hw = item.args.card!;
|
||||
const owner = wearerOf(s, hw);
|
||||
|
|
@ -156,10 +156,10 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
|
||||
// Ruling: Servers perform Executions, so "that Avatar cannot play another Execution" stops the
|
||||
// Ruling: Servers perform Executions, so "that Anomaly cannot play another Execution" stops the
|
||||
// Server it stands on from performing Executions for the rest of the turn.
|
||||
'Execute: Force Reboot': {
|
||||
text: 'Remove all temporary bonuses and penalties from one Avatar you control at the target Server, or one Avatar attacking it. That Avatar cannot play another Execution until end of current command.',
|
||||
text: 'Remove all temporary bonuses and penalties from one Anomaly you control at the target Server, or one Anomaly attacking it. That Anomaly cannot play another Execution until end of current command.',
|
||||
execution: {
|
||||
plays: (s, p) =>
|
||||
acrossScope(s, p, (loc) => {
|
||||
|
|
@ -167,17 +167,17 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
const attacker = c && c.loc === loc ? [c.attacker] : [];
|
||||
return uniq([...mine(s, p, loc), ...attacker]).map((ref) => ({ ref }));
|
||||
}),
|
||||
targetsAvatars: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
targetsAnomalies: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
resolve(s, item) {
|
||||
const ref = item.args.ref!;
|
||||
const av = avatar(s, ref);
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null) return;
|
||||
const live = activeMods(s, av);
|
||||
av.mods = av.mods.filter((m) => !live.includes(m));
|
||||
// Servers perform Executions: the Server this Avatar stands on can't for the rest of the turn.
|
||||
// Servers perform Executions: the Server this Anomaly stands on can't for the rest of the turn.
|
||||
markUsed(s, `noExec:${av.at}`);
|
||||
fired(s, item.name, item.player);
|
||||
say(s, `Force Reboot clears ${live.length} temporary effect(s) from ${avatarName(s, ref)}.`);
|
||||
say(s, `Force Reboot clears ${live.length} temporary effect(s) from ${anomalyName(s, ref)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -213,7 +213,7 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
// Reading: resolves right away, only while no combat is going on. Into your own location it's a
|
||||
// move; into an unowned or undefended one it's a capture; into a defended one it's an attack.
|
||||
'Execute: Trace Route': {
|
||||
text: 'Move one Avatar you control from an adjacent Server to the target Server. If the target Server is enemy-controlled, your Avatar attacks it with +1 Core for the resulting combat.',
|
||||
text: 'Move one Anomaly you control from an adjacent Server to the target Server. If the target Server is enemy-controlled, your Anomaly attacks it with +1 Core for the resulting combat.',
|
||||
execution: {
|
||||
plays(s, p) {
|
||||
if (liveCombat(s)) return [];
|
||||
|
|
@ -223,22 +223,22 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
const mineThere = controls(s, p, target);
|
||||
if (mineThere && !hasRoom(s, p, target)) continue;
|
||||
for (const ref of refsInPlay(s, p)) {
|
||||
const at = avatar(s, ref).at!;
|
||||
const at = anomaly(s, ref).at!;
|
||||
if (at !== target && canAct(s, ref) && adjacent(s, at, target)) out.push({ target, args: { ref } });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
},
|
||||
targetsAvatars: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
targetsAnomalies: (_s, item) => (item.args.ref ? [item.args.ref] : []),
|
||||
resolve(s, item) {
|
||||
const ref = item.args.ref!;
|
||||
const t = item.target!;
|
||||
const av = avatar(s, ref);
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null || !canAct(s, ref) || !adjacent(s, av.at, t) || liveCombat(s)) return;
|
||||
const owner = s.locations[t].owner;
|
||||
fired(s, item.name, item.player);
|
||||
if (owner === item.player) {
|
||||
if (hasRoom(s, item.player, t)) moveAvatar(s, ref, t);
|
||||
if (hasRoom(s, item.player, t)) moveAnomaly(s, ref, t);
|
||||
} else if (owner === null) {
|
||||
pushCapture(s, ref, t, 'capturesUnowned');
|
||||
} else if (defendersAt(s, t).length === 0) {
|
||||
|
|
@ -307,10 +307,10 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
plays: (s, p) =>
|
||||
acrossScope(s, p, (loc) => {
|
||||
const progs = s.locations[loc].programs.filter((id) => s.cards[id].installedTurn === s.turn && canTargetProgram(s, id, p));
|
||||
const hws = [...new Set(avatarsAt(s, loc).flatMap((r) => avatar(s, r).hardware))].filter((id) => s.cards[id].installedTurn === s.turn);
|
||||
const hws = [...new Set(anomaliesAt(s, loc).flatMap((r) => anomaly(s, r).hardware))].filter((id) => s.cards[id].installedTurn === s.turn);
|
||||
return [...progs, ...hws].map((card) => ({ card }));
|
||||
}),
|
||||
targetsAvatars: (s, item) => wearerList(s, item.args.card),
|
||||
targetsAnomalies: (s, item) => wearerList(s, item.args.card),
|
||||
resolve(s, item) {
|
||||
const card = item.args.card!;
|
||||
const wearer = wearerOf(s, card);
|
||||
|
|
@ -335,28 +335,28 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
|
||||
// Rooted Avatars can't advance, attack, reposition, or be moved; their declared moves fail.
|
||||
// Rooted Anomalies can't advance, attack, reposition, or be moved; their declared moves fail.
|
||||
'Execute: Packet Flood': {
|
||||
text: "Avatars based at the target Server cannot move or retreat until the start of their controller's next command.",
|
||||
text: "Anomalies based at the target Server cannot move or retreat until the start of their controller's next command.",
|
||||
execution: {
|
||||
plays: (s, p) => acrossScope(s, p, (loc) => (avatarsAt(s, loc).length ? [{ to: loc }] : [])),
|
||||
plays: (s, p) => acrossScope(s, p, (loc) => (anomaliesAt(s, loc).length ? [{ to: loc }] : [])),
|
||||
resolve(s, item) {
|
||||
const loc = item.args.to ?? item.target!;
|
||||
const here = avatarsAt(s, loc);
|
||||
const here = anomaliesAt(s, loc);
|
||||
if (here.length === 0) return;
|
||||
for (const r of here) {
|
||||
const av = avatar(s, r);
|
||||
const av = anomaly(s, r);
|
||||
av.rootedUntil = Math.max(av.rootedUntil, startOf(nextTurnOf(s, r.player)));
|
||||
}
|
||||
fired(s, item.name, item.player);
|
||||
say(s, `Packet Flood: ${here.map((r) => avatarName(s, r)).join(', ')} can't move.`);
|
||||
say(s, `Packet Flood: ${here.map((r) => anomalyName(s, r)).join(', ')} can't move.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: Disabled Avatars still defend, but can't advance, attack, move or use Abilities.
|
||||
// Reading: Disabled Anomalies still defend, but can't advance, attack, move or use Abilities.
|
||||
'Execute: Emergency Shutdown': {
|
||||
text: 'End any combat at the target Server immediately. All Avatars there remain and become Disabled until end of current command.',
|
||||
text: 'End any combat at the target Server immediately. All Anomalies there remain and become Disabled until end of current command.',
|
||||
execution: {
|
||||
plays(s, p) {
|
||||
const c = liveCombat(s);
|
||||
|
|
@ -365,9 +365,9 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
resolve(s, item) {
|
||||
const c = liveCombat(s);
|
||||
if (!c || !scopeOf(s, item.player, item.target!).includes(c.loc)) return;
|
||||
const everyone = uniq([...fightersOf(c), ...avatarsAt(s, c.loc)]);
|
||||
const everyone = uniq([...fightersOf(c), ...anomaliesAt(s, c.loc)]);
|
||||
endCombat(s, 'Emergency Shutdown');
|
||||
for (const r of everyone) avatar(s, r).disabledUntil = Math.max(avatar(s, r).disabledUntil, endOfTurn(s));
|
||||
for (const r of everyone) anomaly(s, r).disabledUntil = Math.max(anomaly(s, r).disabledUntil, endOfTurn(s));
|
||||
fired(s, item.name, item.player);
|
||||
},
|
||||
},
|
||||
|
|
@ -392,12 +392,12 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Execute: Defragment': {
|
||||
text: 'Re-enable one Disabled Program on the target Server, or one Disabled Hardware on an Avatar there.',
|
||||
text: 'Re-enable one Disabled Program on the target Server, or one Disabled Hardware on an Anomaly there.',
|
||||
execution: {
|
||||
plays: (s, p) =>
|
||||
acrossScope(s, p, (loc) => {
|
||||
const progs = s.locations[loc].programs.filter((id) => running(s, s.cards[id].disabledUntil));
|
||||
const hws = [...new Set(avatarsAt(s, loc).flatMap((r) => hardwareOf(s, r)))].filter((id) => !hardwareActive(s, id));
|
||||
const hws = [...new Set(anomaliesAt(s, loc).flatMap((r) => hardwareOf(s, r)))].filter((id) => !hardwareActive(s, id));
|
||||
return [...progs, ...hws].map((card) => ({ card }));
|
||||
}),
|
||||
resolve(s, item) {
|
||||
|
|
@ -430,7 +430,7 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Execute: Purge': {
|
||||
text: 'Remove all Virus/Infection counters and hostile persistent effects from every Avatar you control at the target Server.',
|
||||
text: 'Remove all Virus/Infection counters and hostile persistent effects from every Anomaly you control at the target Server.',
|
||||
execution: {
|
||||
plays: (s, p) =>
|
||||
acrossScope(s, p, (loc) => (mine(s, p, loc).some((r) => hasNegatives(s, r)) ? [{ to: loc }] : [])),
|
||||
|
|
@ -438,7 +438,7 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
const loc = item.args.to ?? item.target!;
|
||||
const here = mine(s, item.player, loc);
|
||||
for (const r of here) {
|
||||
const av = avatar(s, r);
|
||||
const av = anomaly(s, r);
|
||||
av.infection = 0;
|
||||
av.permanentInfection = 0;
|
||||
av.mods = av.mods.filter((m) => m.cores >= 0 || m.by === item.player);
|
||||
|
|
@ -447,13 +447,13 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
for (const hw of hardwareOf(s, r)) s.cards[hw].disabledUntil = 0;
|
||||
}
|
||||
fired(s, item.name, item.player);
|
||||
say(s, `Purge cleans ${here.map((r) => avatarName(s, r)).join(', ')}.`);
|
||||
say(s, `Purge cleans ${here.map((r) => anomalyName(s, r)).join(', ')}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Execute: Hard Reset': {
|
||||
text: 'Uninstall any number of Programs from the target Server you control. For each card returned to your hand this way, recover 1 RAM.',
|
||||
text: 'Uninstall any number of Programs from the target Server you control. For each card returned to your hand this way, recover 1 Gb.',
|
||||
execution: {
|
||||
plays: (s, p) =>
|
||||
LOCATIONS.filter((t) => controls(s, p, t) && s.locations[t].programs.length > 0).flatMap((target) =>
|
||||
|
|
@ -464,9 +464,9 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
uninstallProgram(s, id);
|
||||
toHand(s, id);
|
||||
}
|
||||
gainRam(s, item.player, back.length * (1 + item.power));
|
||||
gainBandwidth(s, item.player, back.length * (1 + item.power));
|
||||
fired(s, item.name, item.player);
|
||||
say(s, `Hard Reset returns ${back.map((id) => nameOf(s, id)).join(', ')} to hand (+${back.length * (1 + item.power)} RAM).`);
|
||||
say(s, `Hard Reset returns ${back.map((id) => nameOf(s, id)).join(', ')} to hand (+${back.length * (1 + item.power)} Gb).`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -476,8 +476,8 @@ function drawN(s: GameState, p: PlayerId, n: number): void {
|
|||
pushTasks(s, ...Array.from({ length: n }, (): Task => ({ t: 'draw', player: p })));
|
||||
}
|
||||
|
||||
function hasNegatives(s: GameState, r: AvatarRef): boolean {
|
||||
const av = avatar(s, r);
|
||||
function hasNegatives(s: GameState, r: AnomalyRef): boolean {
|
||||
const av = anomaly(s, r);
|
||||
return av.infection > 0 || av.permanentInfection > 0 || running(s, av.rootedUntil) || running(s, av.disabledUntil) ||
|
||||
activeMods(s, av).some((m) => m.cores < 0) || hardwareOf(s, r).some((hw) => !hardwareActive(s, hw));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
* Hardware. It works while its wearer is in play. "The occupied Server" is the location the
|
||||
* wearer stands on.
|
||||
*/
|
||||
import { describeArgs } from '../describe.ts';
|
||||
import { knockOut } from '../flow.ts';
|
||||
import { desynced, hardwareActive, portsFit, takesPort } from '../query.ts';
|
||||
import { desynced, hardwareActive, slotsFit, takesSlot } from '../query.ts';
|
||||
import { scriptOf, type Script } from '../scripts.ts';
|
||||
import {
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
defOf,
|
||||
fired,
|
||||
isCopy,
|
||||
|
|
@ -30,12 +31,12 @@ import {
|
|||
usedThisTurn,
|
||||
wearerOf,
|
||||
} from '../state.ts';
|
||||
import type { AvatarRef, GameState, LocationState, PlayerId, StackItem } from '../types.ts';
|
||||
import type { AnomalyRef, GameState, LocationState, PlayerId, StackItem } from '../types.ts';
|
||||
import { cardOptions, programsOn } from './util.ts';
|
||||
|
||||
/**
|
||||
* Uses a Hardware card has left this turn. Its "once per turn" or "first ... each turn" effect gets
|
||||
* one use, or two when Cooling System on the same Avatar picks it (Cooling helps one Hardware a turn).
|
||||
* one use, or two when Cooling System on the same Anomaly picks it (Cooling helps one Hardware a turn).
|
||||
*/
|
||||
export function hardwareUsesLeft(s: GameState, hw: number): number {
|
||||
const used = usedThisTurn(s, `hw:${hw}`);
|
||||
|
|
@ -46,7 +47,7 @@ export function hardwareUsesLeft(s: GameState, hw: number): number {
|
|||
function coolerFor(s: GameState, hw: number): number | null {
|
||||
const ref = wearerOf(s, hw);
|
||||
if (!ref) return null;
|
||||
for (const id of avatar(s, ref).hardware) {
|
||||
for (const id of anomaly(s, ref).hardware) {
|
||||
if (id === hw || s.cards[id].name !== 'Cooling System' || !hardwareActive(s, id)) continue;
|
||||
const pickedFor = s.used[`cool:${id}`];
|
||||
if (pickedFor === undefined || pickedFor === hw) return id;
|
||||
|
|
@ -55,16 +56,16 @@ function coolerFor(s: GameState, hw: number): number | null {
|
|||
}
|
||||
|
||||
/**
|
||||
* Reading: an Avatar that loses a port (Network Interface Upgrade removed) discards Hardware until it
|
||||
* Reading: an Anomaly that loses an Expansion Slot (Network Interface Upgrade removed) discards Hardware until it
|
||||
* fits, the most recently installed first.
|
||||
*/
|
||||
export function shedHardware(s: GameState, r: AvatarRef): void {
|
||||
while (!portsFit(s, r)) {
|
||||
const hw = avatar(s, r).hardware.findLast((id) => takesPort(s, id))!;
|
||||
export function shedHardware(s: GameState, r: AnomalyRef): void {
|
||||
while (!slotsFit(s, r)) {
|
||||
const hw = anomaly(s, r).hardware.findLast((id) => takesSlot(s, id))!;
|
||||
uninstallHardware(s, hw);
|
||||
toDiscard(s, hw);
|
||||
stat(s, 'hardwareLost', r.player);
|
||||
say(s, `${avatarName(s, r)} is out of ports and discards ${nameOf(s, hw)}.`);
|
||||
say(s, `${anomalyName(s, r)} is out of Expansion Slots and discards ${nameOf(s, hw)}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,13 +78,13 @@ export function useHardware(s: GameState, hw: number): void {
|
|||
}
|
||||
}
|
||||
|
||||
const wearing = (ref: AvatarRef | undefined, f: { ref: AvatarRef }) =>
|
||||
const wearing = (ref: AnomalyRef | undefined, f: { ref: AnomalyRef }) =>
|
||||
!!ref && ref.player === f.ref.player && (ref.slot === f.ref.slot || ref.slot + 4 === f.ref.slot);
|
||||
|
||||
/** Installs a Hardware card from its owner's hand onto an Avatar, without paying. */
|
||||
export function attachHardware(s: GameState, card: number, ref: AvatarRef): void {
|
||||
/** Installs a Hardware card from its owner's hand onto an Anomaly, without paying. */
|
||||
export function attachHardware(s: GameState, card: number, ref: AnomalyRef): void {
|
||||
removeFrom(s.players[ref.player].hand, card);
|
||||
avatar(s, ref).hardware.push(card);
|
||||
anomaly(s, ref).hardware.push(card);
|
||||
s.cards[card].installedTurn = s.turn;
|
||||
stat(s, 'hardwareInstalled', ref.player);
|
||||
played(s, nameOf(s, card), ref.player);
|
||||
|
|
@ -92,18 +93,18 @@ export function attachHardware(s: GameState, card: number, ref: AvatarRef): void
|
|||
export const HARDWARE: Record<string, Script> = {
|
||||
// Health rule: the wearer's Health goes up by 2 (query.ts healthOf). Without the rule it does nothing.
|
||||
'RAM Expansion': {
|
||||
text: 'Avatar gains +2 Health.',
|
||||
text: 'Anomaly gains +2 Health.',
|
||||
health: 2,
|
||||
},
|
||||
'Additional Core': {
|
||||
text: 'Avatar gains +1 Core.',
|
||||
text: 'Anomaly gains +1 Core.',
|
||||
cores: () => 1,
|
||||
},
|
||||
|
||||
// Reading: the Program is one on the location the wearer fought from, the owner picks it, and it
|
||||
// stays disabled through the end of the next turn.
|
||||
'Overclocked CPU': {
|
||||
text: 'Avatar gains +2 Cores during combat, but one installed Program at the current server becomes disabled afterward for 2 commands.',
|
||||
text: 'Anomaly gains +2 Cores during combat, but one installed Program at the current server becomes disabled afterward for 2 commands.',
|
||||
cores: (_s, _src, f) => (f.role !== null ? 2 : 0),
|
||||
onCombatEnd(s, src) {
|
||||
const c = s.combat!;
|
||||
|
|
@ -132,7 +133,7 @@ export const HARDWARE: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Solid-State Cache': {
|
||||
text: 'The first Program installed on the occupied Server each round costs 3 less RAM.',
|
||||
text: 'The first Program installed on the occupied Server each round costs 3 less Gb.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'program' && pay.player === src.controller && pay.at === src.at && hardwareUsesLeft(s, src.id) > 0 ? -3 : 0,
|
||||
onPaid(s, src) {
|
||||
|
|
@ -144,36 +145,36 @@ export const HARDWARE: Record<string, Script> = {
|
|||
// Reading: the first time the wearer is defeated with this installed, all its Hardware stays on
|
||||
// it (in its slot) instead of being discarded.
|
||||
'Redundant Power Supply': {
|
||||
text: 'The first time this Avatar would be destroyed, do not destroy the Hardware.',
|
||||
text: 'The first time this Anomaly would be destroyed, do not destroy the Hardware.',
|
||||
savePriority: 0,
|
||||
onWearerDefeated(s, hw, ev) {
|
||||
if (s.cards[hw].spent) return false;
|
||||
s.cards[hw].spent = true;
|
||||
fired(s, 'Redundant Power Supply', ev.ref.player);
|
||||
say(s, `Redundant Power Supply: ${avatarName(s, ev.ref)} keeps its Hardware.`);
|
||||
say(s, `Redundant Power Supply: ${anomalyName(s, ev.ref)} keeps its Hardware.`);
|
||||
knockOut(s, ev.ref, ev.loc, ev.role, true);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
||||
// Ruling: it takes no port and adds one, so the wearer nets +1 Expansion Slot.
|
||||
// Ruling: it takes no Expansion Slot and adds one, so the wearer nets +1 Expansion Slot.
|
||||
'Network Interface Upgrade': {
|
||||
text: 'This Hardware can be played without taking an upgrade port on the Avatar.',
|
||||
noPort: true,
|
||||
text: 'This Hardware can be played without taking an Expansion Slot on the Anomaly.',
|
||||
noSlot: true,
|
||||
extraSlots: 1,
|
||||
},
|
||||
|
||||
// Ruling: Servers perform Executions, so this works for Executions performed by the Server the
|
||||
// wearer stands on. +1 to the number the Execution uses (cards drawn, Cores, RAM recovered).
|
||||
// wearer stands on. +1 to the number the Execution uses (cards drawn, Cores, Bandwidth recovered).
|
||||
'Dedicated GPU': {
|
||||
text: 'Executions performed by this Avatar receive +1 effectiveness or combat strength.',
|
||||
text: 'Executions performed by this Anomaly receive +1 effectiveness or combat strength.',
|
||||
executionPower: 1,
|
||||
},
|
||||
|
||||
// Blocks opponents' Bug counters (see addBugs in util.ts; no card places them yet) and their
|
||||
// Bug Program effects on the wearer (Memory Leak, Stock Rice).
|
||||
// Bug Program effects on the wearer (Bloatware, Stock Rice).
|
||||
'ECC Memory': {
|
||||
text: 'Opponents cannot place Bug counters or Bug status effects on this Avatar.',
|
||||
text: 'Opponents cannot place Bug counters or Bug status effects on this Anomaly.',
|
||||
bugImmunity: true,
|
||||
},
|
||||
|
||||
|
|
@ -182,19 +183,19 @@ export const HARDWARE: Record<string, Script> = {
|
|||
text: 'Allow one Hardware to activate twice per round.',
|
||||
},
|
||||
|
||||
// Reading: half the combined printed RAM of its Hardware, rounded up.
|
||||
// Reading: half the combined printed Bandwidth of its Hardware, rounded up.
|
||||
'RAID Array': {
|
||||
text: 'When this Avatar is destroyed, all hardware can be kept by paying half the RAM cost.',
|
||||
text: 'When this Anomaly is destroyed, all hardware can be kept by paying half the Bandwidth cost.',
|
||||
savePriority: 1,
|
||||
onWearerDefeated(s, hw, ev) {
|
||||
const av = avatar(s, ev.ref);
|
||||
const cost = Math.ceil(av.hardware.reduce((t, h) => t + defOf(s, h).ram, 0) / 2);
|
||||
const av = anomaly(s, ev.ref);
|
||||
const cost = Math.ceil(av.hardware.reduce((t, h) => t + defOf(s, h).bandwidth, 0) / 2);
|
||||
ask(s, {
|
||||
player: ev.ref.player,
|
||||
kind: 'RAID Array:keep',
|
||||
prompt: `RAID Array: pay ${cost} RAM to keep ${av.hardware.map((h) => nameOf(s, h)).join(', ')}?`,
|
||||
prompt: `RAID Array: pay ${cost} Gb to keep ${av.hardware.map((h) => nameOf(s, h)).join(', ')}?`,
|
||||
options: [
|
||||
{ label: `Keep all Hardware for ${cost} RAM`, value: true, cost },
|
||||
{ label: `Keep all Hardware for ${cost} Gb`, value: true, cost },
|
||||
{ label: 'Lose the Hardware', value: false },
|
||||
],
|
||||
resume: { name: 'RAID Array', fn: 'keep', data: { ref: ev.ref as never, loc: ev.loc, role: ev.role, cost } },
|
||||
|
|
@ -202,10 +203,10 @@ export const HARDWARE: Record<string, Script> = {
|
|||
return true;
|
||||
},
|
||||
resume: {
|
||||
keep(s, data: { ref: AvatarRef; loc: string; role: 'attack' | 'defend'; cost: number }, keep: boolean) {
|
||||
keep(s, data: { ref: AnomalyRef; loc: string; role: 'attack' | 'defend'; cost: number }, keep: boolean) {
|
||||
if (keep) {
|
||||
s.players[data.ref.player].ram -= data.cost;
|
||||
stat(s, 'ramOnCards', data.ref.player, data.cost);
|
||||
s.players[data.ref.player].bandwidth -= data.cost;
|
||||
stat(s, 'bandwidthOnCards', data.ref.player, data.cost);
|
||||
fired(s, 'RAID Array', data.ref.player);
|
||||
}
|
||||
knockOut(s, data.ref, data.loc, data.role, keep);
|
||||
|
|
@ -214,13 +215,13 @@ export const HARDWARE: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Packet Accelerator': {
|
||||
text: 'This Avatar gains +1 Core hen attacking.',
|
||||
text: 'This Anomaly gains +1 Core hen attacking.',
|
||||
cores: (_s, _src, f) => (f.role === 'attack' ? 1 : 0),
|
||||
},
|
||||
|
||||
// Programs never target Avatars, so this taxes Executions (and Hardware they hit).
|
||||
// Programs never target Anomalies, so this taxes Executions (and Hardware they hit).
|
||||
'Firewall Appliance': {
|
||||
text: 'The first hostile Program or Execution targeting this Avatar each round costs the opponent +3 RAM.',
|
||||
text: 'The first hostile Program or Execution targeting this Anomaly each round costs the opponent +3 Gb.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'execution' && pay.player !== src.controller && hardwareUsesLeft(s, src.id) > 0 &&
|
||||
(pay.hostile ?? []).some((r) => wearing(src.ref, { ref: r })) ? 3 : 0,
|
||||
|
|
@ -262,6 +263,7 @@ export const HARDWARE: Record<string, Script> = {
|
|||
ask(s, {
|
||||
player: src.controller,
|
||||
kind: 'Diagnostic Module:bottom',
|
||||
secret: true,
|
||||
prompt: `Diagnostic Module: the top card of your deck is ${nameOf(s, deck[0])}. Put it on the bottom?`,
|
||||
options: [
|
||||
{ label: `Keep ${nameOf(s, deck[0])} on top`, value: false },
|
||||
|
|
@ -278,44 +280,44 @@ export const HARDWARE: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
|
||||
// Reading: swap Hardware on this Avatar, paying the difference in printed RAM (no refund).
|
||||
// Reading: swap Hardware on this Anomaly, paying the difference in printed Bandwidth (no refund).
|
||||
'Hot-Swap Bay': {
|
||||
text: 'Once per round, return one Hardware to your hand and install another Hardware from your hand, paying the difference in cost.',
|
||||
ability: {
|
||||
hardwareOncePerTurn: true,
|
||||
uses(s, src) {
|
||||
const av = avatar(s, src.ref!);
|
||||
const av = anomaly(s, src.ref!);
|
||||
const hand = s.players[src.controller].hand.filter((id) => defOf(s, id).kind === 'hardware');
|
||||
return av.hardware.flatMap((out) => cardOptions(s, hand)
|
||||
.filter((o) => portsFit(s, src.ref!, out, o.value as number))
|
||||
.filter((o) => slotsFit(s, src.ref!, out, o.value as number))
|
||||
.map((o) => ({ card: out, cards: [o.value as number] })));
|
||||
},
|
||||
extraCost: (s, _src, args) => Math.max(0, defOf(s, args.cards![0]).ram - defOf(s, args.card!).ram),
|
||||
extraCost: (s, _src, args) => Math.max(0, defOf(s, args.cards![0]).bandwidth - defOf(s, args.card!).bandwidth),
|
||||
resolve(s, item, src) {
|
||||
const out = item.args.card!;
|
||||
const into = item.args.cards![0];
|
||||
const ref = src.ref!;
|
||||
if (!avatar(s, ref).hardware.includes(out) || !s.players[src.controller].hand.includes(into)) return;
|
||||
if (!portsFit(s, ref, out, into)) return;
|
||||
if (!anomaly(s, ref).hardware.includes(out) || !s.players[src.controller].hand.includes(into)) return;
|
||||
if (!slotsFit(s, ref, out, into)) return;
|
||||
uninstallHardware(s, out);
|
||||
toHand(s, out);
|
||||
attachHardware(s, into, ref);
|
||||
fired(s, 'Hot-Swap Bay', src.controller);
|
||||
say(s, `Hot-Swap Bay swaps ${nameOf(s, out)} for ${nameOf(s, into)} on ${avatarName(s, ref)}.`);
|
||||
say(s, `Hot-Swap Bay swaps ${nameOf(s, out)} for ${nameOf(s, into)} on ${anomalyName(s, ref)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Ruling: Servers perform Executions, so "this Avatar uses an Execution" means one performed by
|
||||
// Ruling: Servers perform Executions, so "this Anomaly uses an Execution" means one performed by
|
||||
// the Server the wearer stands on. "Disable this Hardware" lasts until your next turn.
|
||||
'Quantum Coprocessor': {
|
||||
text: "Once per round when this Avatar uses an Execution, you may copy that Execution's effect with a different legal target, then disable this Hardware.",
|
||||
text: "Once per round when this Anomaly uses an Execution, you may copy that Execution's effect with a different legal target, then disable this Hardware.",
|
||||
copiesExecutions: true,
|
||||
resume: {
|
||||
offer(s, data: { item: StackItem }) {
|
||||
const item = data.item;
|
||||
const wearers = refsInPlay(s, item.player).filter((r) => !isCopy(r) && avatar(s, r).at === item.from && !desynced(s, r));
|
||||
const qc = wearers.flatMap((r) => avatar(s, r).hardware)
|
||||
const wearers = refsInPlay(s, item.player).filter((r) => !isCopy(r) && anomaly(s, r).at === item.from && !desynced(s, r));
|
||||
const qc = wearers.flatMap((r) => anomaly(s, r).hardware)
|
||||
.find((hw) => s.cards[hw].name === 'Quantum Coprocessor' && hardwareActive(s, hw) && hardwareUsesLeft(s, hw) > 0);
|
||||
if (qc === undefined) return;
|
||||
const ex = scriptOf(item.name)?.execution;
|
||||
|
|
@ -329,7 +331,7 @@ export const HARDWARE: Record<string, Script> = {
|
|||
prompt: `Quantum Coprocessor: copy ${item.name} with a different target?`,
|
||||
options: [
|
||||
{ label: "Don't copy", value: null },
|
||||
...plays.map((p) => ({ label: `${p.target ?? 'no target'} ${describeArgs(s, p.args)}`, value: { target: p.target, args: p.args as never } })),
|
||||
...plays.map((p) => ({ label: `${p.target ?? 'no target'} ${describeArgs(s, p.args, item.player)}`, value: { target: p.target, args: p.args as never } })),
|
||||
],
|
||||
resume: { name: 'Quantum Coprocessor', fn: 'copy', data: { item: item as never, qc } },
|
||||
});
|
||||
|
|
@ -346,15 +348,6 @@ export const HARDWARE: Record<string, Script> = {
|
|||
},
|
||||
};
|
||||
|
||||
function describeArgs(s: GameState, a: StackItem['args']): string {
|
||||
const parts: string[] = [];
|
||||
if (a.ref) parts.push(avatarName(s, a.ref));
|
||||
if (a.card !== undefined) parts.push(nameOf(s, a.card));
|
||||
if (a.to) parts.push(`→ ${a.to}`);
|
||||
if (a.mode) parts.push(a.mode);
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
function disableForTwoTurns(s: GameState, id: number): void {
|
||||
s.cards[id].disabledUntil = Math.max(s.cards[id].disabledUntil, endOf(s.turn + 1));
|
||||
say(s, `Overclocked CPU: ${nameOf(s, id)} is disabled for 2 turns.`);
|
||||
|
|
@ -362,7 +355,7 @@ function disableForTwoTurns(s: GameState, id: number): void {
|
|||
|
||||
function askSandbox(s: GameState, card: number): void {
|
||||
const ref = wearerOf(s, card);
|
||||
const at = ref ? avatar(s, ref).at : null;
|
||||
const at = ref ? anomaly(s, ref).at : null;
|
||||
if (!ref || !at) return;
|
||||
const progs = (s.locations[at] as LocationState).programs.filter((id) => ownerOf(s, id) === ref.player);
|
||||
if (progs.length === 0) return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* Programs. A Program sits on a location its owner controls and its effect is local: "this
|
||||
* Server" is the location it's on (or where Worm Protocol spreads it). Enemy Avatars are only
|
||||
* Server" is the location it's on (or where Worm Protocol spreads it). Enemy Anomalies are only
|
||||
* ever "at" your location while attacking or capturing it.
|
||||
*/
|
||||
import { LOCATIONS, type LocId } from '../map.ts';
|
||||
|
|
@ -20,12 +20,12 @@ import {
|
|||
activeMods,
|
||||
addMod,
|
||||
ask,
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
controls,
|
||||
defOf,
|
||||
fired,
|
||||
gainRam,
|
||||
gainBandwidth,
|
||||
hardwareOf,
|
||||
infectionOf,
|
||||
isCopy,
|
||||
|
|
@ -52,10 +52,10 @@ import {
|
|||
usedThisTurn,
|
||||
} from '../state.ts';
|
||||
import { randInt } from '../rng.ts';
|
||||
import { type AvatarRef, type GameState, type PlayerId, type Source, type Task } from '../types.ts';
|
||||
import { type AnomalyRef, type GameState, type PlayerId, type Source, type Task } from '../types.ts';
|
||||
import { cardOptions, infect, isPatch, isVirus, programsOn } from './util.ts';
|
||||
|
||||
const enemyOf = (src: Source, ref: AvatarRef) => ref.player !== src.controller;
|
||||
const enemyOf = (src: Source, ref: AnomalyRef) => ref.player !== src.controller;
|
||||
/** The first active source with this name at the location, so duplicates don't double up. */
|
||||
const firstHere = (s: GameState, src: Source, loc: LocId) => {
|
||||
const first = sourcesNamed(s, src.name, loc)[0];
|
||||
|
|
@ -103,9 +103,9 @@ function installFree(s: GameState, card: number, at: LocId): void {
|
|||
emit(s, 'onInstall', { card, at, ref: null });
|
||||
}
|
||||
|
||||
/** Negative things on an Avatar that Error Correction can remove, one at a time. */
|
||||
function negatives(s: GameState, ref: AvatarRef): { label: string; value: string }[] {
|
||||
const av = avatar(s, ref);
|
||||
/** Negative things on an Anomaly that Error Correction can remove, one at a time. */
|
||||
function negatives(s: GameState, ref: AnomalyRef): { label: string; value: string }[] {
|
||||
const av = anomaly(s, ref);
|
||||
const out: { label: string; value: string }[] = [];
|
||||
if (av.infection > 0) out.push({ label: 'an Infection counter', value: 'infection' });
|
||||
if (av.bugs > 0) out.push({ label: 'a Bug counter', value: 'bug' });
|
||||
|
|
@ -120,8 +120,8 @@ function negatives(s: GameState, ref: AvatarRef): { label: string; value: string
|
|||
return out;
|
||||
}
|
||||
|
||||
function removeNegative(s: GameState, ref: AvatarRef, what: string): void {
|
||||
const av = avatar(s, ref);
|
||||
function removeNegative(s: GameState, ref: AnomalyRef, what: string): void {
|
||||
const av = anomaly(s, ref);
|
||||
if (what === 'infection') av.infection--;
|
||||
else if (what === 'bug') av.bugs--;
|
||||
else if (what === 'permanent') av.permanentInfection--;
|
||||
|
|
@ -135,22 +135,22 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
// Reading: one counter per attack declared on this Server, or per capture of it that wasn't an
|
||||
// attack. The -2 applies anywhere while this Program is in play, and doesn't stack with copies.
|
||||
'Recursive Infection': {
|
||||
text: 'Whenever an enemy Avatar attacks or breaches this Server, place an Infection counter on it. An Avatar with 3+ Infection counters has -2 Core.',
|
||||
onAttackDeclared(s, src, ev: { ref: AvatarRef; to: LocId }) {
|
||||
text: 'Whenever an enemy Anomaly attacks or breaches this Server, place an Infection counter on it. An Anomaly with 3+ Infection counters has -2 Core.',
|
||||
onAttackDeclared(s, src, ev: { ref: AnomalyRef; to: LocId }) {
|
||||
if (ev.to === src.at && enemyOf(src, ev.ref)) infect(s, ev.ref, 1, 'Recursive Infection', src.controller);
|
||||
},
|
||||
onBreach(s, src, ev: { ref: AvatarRef; loc: LocId }) {
|
||||
onBreach(s, src, ev: { ref: AnomalyRef; loc: LocId }) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref)) return;
|
||||
const attacked = s.declarations.some((d) => d.kind === 'attack' && sameRef(d.ref, ev.ref) && d.to === ev.loc);
|
||||
if (!attacked) infect(s, ev.ref, 1, 'Recursive Infection', src.controller);
|
||||
},
|
||||
globalCores: (s, f) => (infectionOf(avatar(s, f.ref)) >= 3 ? -2 : 0),
|
||||
globalCores: (s, f) => (infectionOf(anomaly(s, f.ref)) >= 3 ? -2 : 0),
|
||||
},
|
||||
|
||||
// Reading: "owner" is the attacking Avatar's owner, who picks which of its Hardware is disabled
|
||||
// Reading: "owner" is the attacking Anomaly's owner, who picks which of its Hardware is disabled
|
||||
// for that combat.
|
||||
'Memory Parasite': {
|
||||
text: "Enemy Avatars attacking this Server have 1 hardware component disabled of the owners choosing.",
|
||||
text: "Enemy Anomalies attacking this Server have 1 hardware component disabled of the owners choosing.",
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || !enemyOf(src, c.attacker)) return;
|
||||
|
|
@ -179,7 +179,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
// Reading: installing this card counts, so it can bring a second Virus with it.
|
||||
'Replication Routine': {
|
||||
text: 'When you install a Virus Program on this Server, you may install a second Virus Program from your hand here for no RAM cost.',
|
||||
text: 'When you install a Virus Program on this Server, you may install a second Virus Program from your hand here for no Bandwidth cost.',
|
||||
onInstall(s, src, ev: { card: number; at: LocId | null }) {
|
||||
if (!src.at || ev.at !== src.at || src.virtual !== undefined || !isVirus(s, ev.card)) return;
|
||||
if (s.locations[src.at].programs.length >= programSlots(s, src.at)) return;
|
||||
|
|
@ -205,12 +205,12 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
// Fires on every roll the attacker loses here (with the health rule off, that's every defeat).
|
||||
'Resource Leech': {
|
||||
text: 'Whenever an enemy Avatar takes damage while attacking this Server, gain 3 RAM.',
|
||||
text: 'Whenever an enemy Anomaly takes damage while attacking this Server, gain 3 Gb.',
|
||||
onDamage(s, src, ev) {
|
||||
if (ev.loc !== src.at || ev.role !== 'attack' || !enemyOf(src, ev.ref)) return;
|
||||
gainRam(s, src.controller, 3);
|
||||
gainBandwidth(s, src.controller, 3);
|
||||
fired(s, 'Resource Leech', src.controller);
|
||||
say(s, `Resource Leech: ${playerName(src.controller)} gains 3 RAM.`);
|
||||
say(s, `Resource Leech: ${playerName(src.controller)} gains 3 Gb.`);
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -237,7 +237,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Payload Injector': {
|
||||
text: 'The first Execution you play targeting this Server each round costs 2 less RAM.',
|
||||
text: 'The first Execution you play targeting this Server each round costs 2 less Gb.',
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'execution' && pay.player === src.controller && pay.at === src.at &&
|
||||
usedThisTurn(s, `payload:${src.id}`) === 0 ? -2 : 0,
|
||||
|
|
@ -247,24 +247,24 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
|
||||
// Enemy Avatars are only ever at this location while attacking it. The counter survives defeat.
|
||||
// Enemy Anomalies are only ever at this location while attacking it. The counter survives defeat.
|
||||
'Persistent Infection': {
|
||||
text: 'Whenever an enemy Avatar takes damage at this Server, place an Infection counter on it permanently.',
|
||||
text: 'Whenever an enemy Anomaly takes damage at this Server, place an Infection counter on it permanently.',
|
||||
onDamage(s, src, ev) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref) || isCopy(ev.ref)) return;
|
||||
infect(s, ev.ref, 1, 'Persistent Infection', src.controller, true);
|
||||
},
|
||||
},
|
||||
|
||||
// Reading: your Avatar attacking from this Server may declare a second attack on another
|
||||
// Reading: your Anomaly attacking from this Server may declare a second attack on another
|
||||
// adjacent location. Both come from this Server, even if the first one moved it.
|
||||
'Infinite Loop': {
|
||||
text: 'If the attacking Avatar is controlled by the owner of this Program, it may attack a second adjacent Server in the same command.',
|
||||
text: 'If the attacking Anomaly is controlled by the owner of this Program, it may attack a second adjacent Server in the same command.',
|
||||
extraAttacks: 1,
|
||||
},
|
||||
|
||||
'Stack Overflow': {
|
||||
text: 'Avatars you control defending this Server gain +1 Core for each Program installed on this Server (including this one).',
|
||||
text: 'Anomalies you control defending this Server gain +1 Core for each Program installed on this Server (including this one).',
|
||||
cores: (s, src, f) =>
|
||||
f.role === 'defend' && f.at === src.at && f.ref.player === src.controller ? installedCount(s, src.at!) : 0,
|
||||
},
|
||||
|
|
@ -298,16 +298,16 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
},
|
||||
|
||||
'Memory Leak': {
|
||||
text: 'At the start of any combat at this Server, the attacking Avatar loses 1 Core for each Hardware installed on it.',
|
||||
'Bloatware': {
|
||||
text: 'At the start of any combat at this Server, the attacking Anomaly loses 1 Core for each Hardware installed on it.',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || !enemyOf(src, c.attacker) || bugImmune(s, c.attacker, src.controller)) return;
|
||||
const n = hardwareOf(s, c.attacker).length;
|
||||
if (n === 0) return;
|
||||
addMod(s, c.attacker, -n, 'Memory Leak', src.controller, { combat: c.id });
|
||||
fired(s, 'Memory Leak', src.controller);
|
||||
say(s, `Memory Leak: ${avatarName(s, c.attacker)} loses ${n} Core${n === 1 ? '' : 's'}.`);
|
||||
addMod(s, c.attacker, -n, 'Bloatware', src.controller, { combat: c.id });
|
||||
fired(s, 'Bloatware', src.controller);
|
||||
say(s, `Bloatware: ${anomalyName(s, c.attacker)} loses ${n} Core${n === 1 ? '' : 's'}.`);
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -324,7 +324,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
// Reading: "Hardware bonuses" are the Cores Hardware adds.
|
||||
'Stock Rice': {
|
||||
text: 'Neither Avatar in a combat that takes place at this Server may use any Hardware bonuses.',
|
||||
text: 'Neither Anomaly in a combat that takes place at this Server may use any Hardware bonuses.',
|
||||
blocksHardwareInCombat: true,
|
||||
onCombatStart(s, src) {
|
||||
if (s.combat!.loc === src.at) fired(s, 'Stock Rice', src.controller);
|
||||
|
|
@ -334,7 +334,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
// Every lost roll disables a Program until its controller's next command; a destroyed attacker
|
||||
// lets the owner destroy it instead.
|
||||
'Overflow Error': {
|
||||
text: 'When an enemy Avatar takes damage while attacking this Server, disable one Program its controller has in play until their next command. If the Avatar was destroyed, you may destroy that Program instead.',
|
||||
text: 'When an enemy Anomaly takes damage while attacking this Server, disable one Program its controller has in play until their next command. If the Anomaly was destroyed, you may destroy that Program instead.',
|
||||
onDamage(s, src, ev) {
|
||||
if (ev.loc !== src.at || ev.role !== 'attack' || !enemyOf(src, ev.ref)) return;
|
||||
const theirs = LOCATIONS.flatMap((l) => (controls(s, ev.ref.player, l) ? programsOn(s, l) : []))
|
||||
|
|
@ -389,7 +389,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
'Packet Loss': {
|
||||
text: 'When an enemy successfully breaches this Server, its controller discards a card at random.',
|
||||
onBreach(s, src, ev: { ref: AvatarRef; loc: LocId }) {
|
||||
onBreach(s, src, ev: { ref: AnomalyRef; loc: LocId }) {
|
||||
if (ev.loc !== src.at || !enemyOf(src, ev.ref)) return;
|
||||
const hand = s.players[ev.ref.player].hand;
|
||||
if (hand.length === 0) return;
|
||||
|
|
@ -403,57 +403,57 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
// The once-per-turn Hardware abilities are Hot-Swap Bay's and Quantum Coprocessor's.
|
||||
Desynchronization: {
|
||||
text: 'Enemy Avatars attacking this Server cannot use their Hardware\'s "once per round" abilities during that combat.',
|
||||
text: 'Enemy Anomalies attacking this Server cannot use their Hardware\'s "once per round" abilities during that combat.',
|
||||
blocksHardwareAbilities: true,
|
||||
},
|
||||
|
||||
// Reading: "each turn" was removed from the card, so this works once per installation.
|
||||
'Visual Artifact': {
|
||||
text: 'The first attack made against an Avatar you control at this Server suffers -1 Core.',
|
||||
text: 'The first attack made against an Anomaly you control at this Server suffers -1 Core.',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || s.cards[src.id].spent || c.defenders.every((d) => d.player !== src.controller)) return;
|
||||
s.cards[src.id].spent = true;
|
||||
addMod(s, c.attacker, -1, 'Visual Artifact', src.controller, { combat: c.id });
|
||||
fired(s, 'Visual Artifact', src.controller);
|
||||
say(s, `Visual Artifact: ${avatarName(s, c.attacker)} gets -1 Core.`);
|
||||
say(s, `Visual Artifact: ${anomalyName(s, c.attacker)} gets -1 Core.`);
|
||||
},
|
||||
},
|
||||
|
||||
// Executions check for this through scopeOf() in util.ts.
|
||||
'Ghost Process': {
|
||||
text: 'Your Executions played targeting this Server may also affect Avatars, Programs, and Hardware at one adjacent Server.',
|
||||
text: 'Your Executions played targeting this Server may also affect Anomalies, Programs, and Hardware at one adjacent Server.',
|
||||
},
|
||||
|
||||
// Runs from the engine right after an enemy Execution that targets an Avatar is played.
|
||||
// Runs from the engine right after an enemy Execution that targets an Anomaly is played.
|
||||
'False Positive': {
|
||||
text: 'When an enemy Execution targets an Avatar you control at this Server, you may redirect it to another legal Avatar at another Server.',
|
||||
text: 'When an enemy Execution targets an Anomaly you control at this Server, you may redirect it to another legal Anomaly at another Server.',
|
||||
resume: {
|
||||
offer(s, data: { index: number }) {
|
||||
const item = s.stack[data.index];
|
||||
if (!item) return;
|
||||
const ex = scriptOf(item.name)?.execution;
|
||||
const hit = ex?.targetsAvatars?.(s, item) ?? [];
|
||||
const hit = ex?.targetsAnomalies?.(s, item) ?? [];
|
||||
const guarded = hit.find((r) => {
|
||||
if (r.player === item.player) return false;
|
||||
const at = avatar(s, r).at;
|
||||
const at = anomaly(s, r).at;
|
||||
return sources(s).some((x) => x.name === 'False Positive' && x.at === at && x.controller === r.player);
|
||||
});
|
||||
if (!ex || !guarded) return;
|
||||
const from = avatar(s, guarded).at;
|
||||
const from = anomaly(s, guarded).at;
|
||||
const options = ex.plays(s, item.player).filter((play) => {
|
||||
const refs = ex.targetsAvatars?.(s, { player: item.player, target: play.target, args: play.args }) ?? [];
|
||||
return refs.length > 0 && refs.every((r) => avatar(s, r).at !== from && !sameRef(r, guarded));
|
||||
const refs = ex.targetsAnomalies?.(s, { player: item.player, target: play.target, args: play.args }) ?? [];
|
||||
return refs.length > 0 && refs.every((r) => anomaly(s, r).at !== from && !sameRef(r, guarded));
|
||||
});
|
||||
if (options.length === 0) return;
|
||||
ask(s, {
|
||||
player: guarded.player,
|
||||
kind: 'False Positive:redirect',
|
||||
prompt: `False Positive: redirect ${item.name} away from ${avatarName(s, guarded)}?`,
|
||||
prompt: `False Positive: redirect ${item.name} away from ${anomalyName(s, guarded)}?`,
|
||||
options: [
|
||||
{ label: 'Leave it', value: null },
|
||||
...options.map((play) => ({
|
||||
label: `Redirect to ${play.args.ref ? avatarName(s, play.args.ref) : nameOf(s, play.args.card ?? -1)} on ${play.target}`,
|
||||
label: `Redirect to ${play.args.ref ? anomalyName(s, play.args.ref) : nameOf(s, play.args.card ?? -1)} on ${play.target}`,
|
||||
value: { index: data.index, target: play.target, args: play.args as never },
|
||||
})),
|
||||
],
|
||||
|
|
@ -472,7 +472,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
Fragmentation: {
|
||||
text: 'Executions your opponents play targeting this Server cost +2 RAM.',
|
||||
text: 'Executions your opponents play targeting this Server cost +2 Gb.',
|
||||
costMod: (s, src, pay) => (pay.kind === 'execution' && pay.player !== src.controller && pay.at === src.at ? 2 : 0),
|
||||
onPaid: (s, src) => fired(s, 'Fragmentation', src.controller),
|
||||
},
|
||||
|
|
@ -489,33 +489,33 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Error Correction': {
|
||||
text: 'At the beginning of your first command each round, remove one negative counter or status from each Avatar you control at this Server.',
|
||||
text: 'At the beginning of your first command each round, remove one negative counter or status from each Anomaly you control at this Server.',
|
||||
onTurnStart(s, src) {
|
||||
if (s.active !== src.controller) return;
|
||||
const tasks: Task[] = refsInPlay(s, src.controller)
|
||||
.filter((r) => avatar(s, r).at === src.at)
|
||||
.filter((r) => anomaly(s, r).at === src.at)
|
||||
.map((r) => later('Error Correction', 'fix', { ref: r as never }));
|
||||
pushTasks(s, ...tasks);
|
||||
},
|
||||
resume: {
|
||||
fix(s, data: { ref: AvatarRef }) {
|
||||
fix(s, data: { ref: AnomalyRef }) {
|
||||
const list = negatives(s, data.ref);
|
||||
if (list.length === 0) return;
|
||||
fired(s, 'Error Correction', data.ref.player);
|
||||
if (list.length === 1) {
|
||||
removeNegative(s, data.ref, list[0].value);
|
||||
say(s, `Error Correction removes ${list[0].label} from ${avatarName(s, data.ref)}.`);
|
||||
say(s, `Error Correction removes ${list[0].label} from ${anomalyName(s, data.ref)}.`);
|
||||
return;
|
||||
}
|
||||
ask(s, {
|
||||
player: data.ref.player,
|
||||
kind: 'Error Correction:remove',
|
||||
prompt: `Error Correction: remove what from ${avatarName(s, data.ref)}?`,
|
||||
prompt: `Error Correction: remove what from ${anomalyName(s, data.ref)}?`,
|
||||
options: list,
|
||||
resume: { name: 'Error Correction', fn: 'remove', data: { ref: data.ref as never } },
|
||||
});
|
||||
},
|
||||
remove(s, data: { ref: AvatarRef }, what: string) {
|
||||
remove(s, data: { ref: AnomalyRef }, what: string) {
|
||||
removeNegative(s, data.ref, what);
|
||||
},
|
||||
},
|
||||
|
|
@ -523,7 +523,7 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
|
||||
// Reading: it can sacrifice itself.
|
||||
'Garbage Collection': {
|
||||
text: 'Once per round, sacrifice one Program installed on this Server to recover its printed RAM value.',
|
||||
text: 'Once per round, sacrifice one Program installed on this Server to recover its printed Bandwidth value.',
|
||||
ability: {
|
||||
uses: (s, src) => (src.kind === 'program' ? s.locations[src.at!].programs.map((card) => ({ card })) : []),
|
||||
resolve(s, item, src) {
|
||||
|
|
@ -532,9 +532,9 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
uninstallProgram(s, card);
|
||||
toDiscard(s, card);
|
||||
stat(s, 'programsLost', src.controller);
|
||||
gainRam(s, src.controller, defOf(s, card).ram);
|
||||
gainBandwidth(s, src.controller, defOf(s, card).bandwidth);
|
||||
fired(s, 'Garbage Collection', src.controller);
|
||||
say(s, `Garbage Collection sacrifices ${nameOf(s, card)} for ${defOf(s, card).ram} RAM.`);
|
||||
say(s, `Garbage Collection sacrifices ${nameOf(s, card)} for ${defOf(s, card).bandwidth} Gb.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -564,28 +564,28 @@ export const PROGRAMS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Rollback Routine': {
|
||||
text: 'Once per round, undo the most recent temporary stat reduction applied to an Avatar you control at this Server.',
|
||||
text: 'Once per round, undo the most recent temporary stat reduction applied to an Anomaly you control at this Server.',
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
if (src.kind !== 'program') return [];
|
||||
return refsInPlay(s, src.controller)
|
||||
.filter((r) => avatar(s, r).at === src.at && activeMods(s, avatar(s, r)).some((m) => m.cores < 0))
|
||||
.filter((r) => anomaly(s, r).at === src.at && activeMods(s, anomaly(s, r)).some((m) => m.cores < 0))
|
||||
.map((ref) => ({ ref }));
|
||||
},
|
||||
resolve(s, item, src) {
|
||||
const av = avatar(s, item.args.ref!);
|
||||
const av = anomaly(s, item.args.ref!);
|
||||
if (av.at !== src.at) return;
|
||||
const last = activeMods(s, av).filter((m) => m.cores < 0).sort((a, b) => b.seq - a.seq)[0];
|
||||
if (!last) return;
|
||||
av.mods = av.mods.filter((m) => m !== last);
|
||||
fired(s, 'Rollback Routine', src.controller);
|
||||
say(s, `Rollback Routine undoes ${last.cores} Cores from ${last.source} on ${avatarName(s, item.args.ref!)}.`);
|
||||
say(s, `Rollback Routine undoes ${last.cores} Cores from ${last.source} on ${anomalyName(s, item.args.ref!)}.`);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Compatibility Layer': {
|
||||
text: 'This Server may hold one additional Program beyond the normal limit, and Patch Programs installed here cost 2 less RAM.',
|
||||
text: 'This Server may hold one additional Program beyond the normal limit, and Patch Programs installed here cost 2 less Gb.',
|
||||
programSlots: 1,
|
||||
costMod: (s, src, pay) =>
|
||||
pay.kind === 'program' && pay.player === src.controller && pay.at === src.at && isPatch(s, pay.card!) ? -2 : 0,
|
||||
|
|
@ -597,6 +597,7 @@ function askRace(s: GameState, player: PlayerId): void {
|
|||
ask(s, {
|
||||
player,
|
||||
kind: 'Race Condition:pick',
|
||||
secret: true,
|
||||
prompt: 'Race Condition: secretly choose Attack or Defend.',
|
||||
options: [{ label: 'Attack', value: 'attack' }, { label: 'Defend', value: 'defend' }],
|
||||
resume: { name: 'Race Condition', fn: 'pick', data: { player } },
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ import { canCopy, hasRoom, sameSource, sourcesNamed } from '../query.ts';
|
|||
import type { Fighter, Script } from '../scripts.ts';
|
||||
import {
|
||||
ask,
|
||||
avatar,
|
||||
anomaly,
|
||||
copyOf,
|
||||
defendersAt,
|
||||
fired,
|
||||
gainRam,
|
||||
gainBandwidth,
|
||||
isCopy,
|
||||
nameOf,
|
||||
neighbors,
|
||||
|
|
@ -24,40 +24,40 @@ import {
|
|||
import { LOCATIONS } from '../map.ts';
|
||||
import type { GameState, PlayerId, Source } from '../types.ts';
|
||||
|
||||
/** Core bonus for the controller's Avatar standing on this Server (attacking from it or defending it). */
|
||||
/** Core bonus for the controller's Anomaly standing on this Server (attacking from it or defending it). */
|
||||
const coreBonus = (n: number) => (s: GameState, src: Source, f: Fighter) =>
|
||||
f.at === src.at && f.ref.player === src.controller ? n : 0;
|
||||
|
||||
export const SERVERS: Record<string, Script> = {
|
||||
'High Efficiency RAM Server': { text: 'Add additional 4 RAM to resource total', ramOnPlace: 4 },
|
||||
'Power Server': { text: 'Add additional 4 RAM to resource total', ramOnPlace: 4 },
|
||||
'High Bandwidth Server': { text: 'Add additional 4 Gb to resource total', bandwidthOnPlace: 4 },
|
||||
'Power Server': { text: 'Add additional 4 Gb to resource total', bandwidthOnPlace: 4 },
|
||||
'Server Farm': {
|
||||
text: 'Add 4 RAM to resource total and 2 Cores to any Avatar',
|
||||
ramOnPlace: 4,
|
||||
text: 'Add 4 Gb to resource total and 2 Cores to any Anomaly',
|
||||
bandwidthOnPlace: 4,
|
||||
cores: coreBonus(2),
|
||||
},
|
||||
'MultiCore Server': { text: 'Add 2 Cores to any Avatars', cores: coreBonus(2) },
|
||||
'Cloud Compute': { text: 'Add 4 Cores to any Avatars', cores: coreBonus(4) },
|
||||
'Cluster Server': { text: 'Up to 2 Avatars can defend this Server', capacity: 2 },
|
||||
'Pingable Server': { text: 'Up to 2 Avatars can defend this Server', capacity: 2 },
|
||||
'MultiCore Server': { text: 'Add 2 Cores to any Anomalies', cores: coreBonus(2) },
|
||||
'Cloud Compute': { text: 'Add 4 Cores to any Anomalies', cores: coreBonus(4) },
|
||||
'Cluster Server': { text: 'Up to 2 Anomalies can defend this Server', capacity: 2 },
|
||||
'Pingable Server': { text: 'Up to 2 Anomalies can defend this Server', capacity: 2 },
|
||||
|
||||
// Reading: once per turn, at any time, make a copy of your Avatar based here (Carbon NanoBots'
|
||||
// Reading: once per turn, at any time, make a copy of your Anomaly based here (Carbon NanoBots'
|
||||
// copy rules). The copy enters play on any location you control with room.
|
||||
'Backup Server': {
|
||||
text: 'Duplicate Avatar based at this Server',
|
||||
text: 'Duplicate Anomaly based at this Server',
|
||||
ability: {
|
||||
uses(s, src) {
|
||||
const p = src.controller;
|
||||
if (!canCopy(s, p)) return [];
|
||||
const spots = LOCATIONS.filter((l) => hasRoom(s, p, l));
|
||||
return refsInPlay(s, p)
|
||||
.filter((r) => !isCopy(r) && avatar(s, r).at === src.at && avatar(s, copyOf(r)).at === null)
|
||||
.filter((r) => !isCopy(r) && anomaly(s, r).at === src.at && anomaly(s, copyOf(r)).at === null)
|
||||
.flatMap((r) => spots.map((to) => ({ ref: r, to })));
|
||||
},
|
||||
resolve(s, item) {
|
||||
const r = item.args.ref!;
|
||||
const to = item.args.to!;
|
||||
if (avatar(s, r).at === null || avatar(s, copyOf(r)).at !== null || !canCopy(s, r.player) || !hasRoom(s, r.player, to)) return;
|
||||
if (anomaly(s, r).at === null || anomaly(s, copyOf(r)).at !== null || !canCopy(s, r.player) || !hasRoom(s, r.player, to)) return;
|
||||
fired(s, 'Backup Server', r.player);
|
||||
createCopy(s, r, to);
|
||||
},
|
||||
|
|
@ -65,13 +65,13 @@ export const SERVERS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
'Upgraded Hardware': {
|
||||
text: 'Hardware upgrades cost 2 less RAM to install',
|
||||
text: 'Hardware upgrades cost 2 less Gb to install',
|
||||
costMod: (s, src, pay) => (pay.kind === 'hardware' && pay.player === src.controller && pay.at === src.at ? -2 : 0),
|
||||
onPaid: (s, src) => fired(s, 'Upgraded Hardware', src.controller),
|
||||
},
|
||||
|
||||
'Network Throttle': {
|
||||
text: 'Firewalls cost 1 less RAM to install',
|
||||
text: 'Firewalls cost 1 less Gb to install',
|
||||
costMod(s, src, pay) {
|
||||
if (pay.kind !== 'firewall' || pay.player !== src.controller) return 0;
|
||||
const line = LINE_BY_ID.get(pay.line!)!;
|
||||
|
|
@ -81,7 +81,7 @@ export const SERVERS: Record<string, Script> = {
|
|||
},
|
||||
|
||||
// Reading: when placed, pick one adjacent Server (either player's) and gain its ability for as
|
||||
// long as this card stays. A copied RAM bonus is paid right away.
|
||||
// long as this card stays. A copied Bandwidth bonus is paid right away.
|
||||
'Duplicate Server': {
|
||||
text: 'Copy one adjacent Server ability',
|
||||
onPlaced(s, src, ev: { card: number }) {
|
||||
|
|
@ -106,23 +106,23 @@ export const SERVERS: Record<string, Script> = {
|
|||
const p = data.player;
|
||||
fired(s, 'Duplicate Server', p);
|
||||
say(s, `Duplicate Server copies ${name}.`);
|
||||
const bonus = SERVERS[name]?.ramOnPlace ?? 0;
|
||||
const bonus = SERVERS[name]?.bandwidthOnPlace ?? 0;
|
||||
if (bonus) {
|
||||
gainRam(s, p, bonus, 'ramFromCaptures');
|
||||
say(s, `${playerName(p)} gains ${bonus} RAM from the copied ability.`);
|
||||
gainBandwidth(s, p, bonus, 'bandwidthFromCaptures');
|
||||
say(s, `${playerName(p)} gains ${bonus} Gb from the copied ability.`);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
'Protected Server': {
|
||||
text: 'Add 2 RAM if defending this Server',
|
||||
text: 'Add 2 Gb if defending this Server',
|
||||
onCombatStart(s, src) {
|
||||
const c = s.combat!;
|
||||
if (c.loc !== src.at || defendersAt(s, c.loc).every((d) => d.player !== src.controller)) return;
|
||||
gainRam(s, src.controller, 2);
|
||||
gainBandwidth(s, src.controller, 2);
|
||||
fired(s, 'Protected Server', src.controller);
|
||||
say(s, `Protected Server: ${playerName(src.controller)} gains 2 RAM for defending.`);
|
||||
say(s, `Protected Server: ${playerName(src.controller)} gains 2 Gb for defending.`);
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -137,6 +137,7 @@ export const SERVERS: Record<string, Script> = {
|
|||
ask(s, {
|
||||
player: ev.player,
|
||||
kind: 'Callable Server:redraw',
|
||||
secret: true,
|
||||
prompt: `Callable Server: keep ${nameOf(s, ev.card)}, or put it on the bottom and draw another?`,
|
||||
options: [
|
||||
{ label: `Keep ${nameOf(s, ev.card)}`, value: false },
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import type { LocId } from '../map.ts';
|
|||
import { bugImmune, hardwareActive, programActive, sources } from '../query.ts';
|
||||
import {
|
||||
atServer,
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
defOf,
|
||||
fired,
|
||||
nameOf,
|
||||
|
|
@ -13,7 +13,7 @@ import {
|
|||
refsInPlay,
|
||||
say,
|
||||
} from '../state.ts';
|
||||
import type { AvatarRef, ChoiceOption, GameState, PlayerId, Source } from '../types.ts';
|
||||
import type { AnomalyRef, ChoiceOption, GameState, PlayerId, Source } from '../types.ts';
|
||||
|
||||
/** Locations where `p` has Ghost Process working. */
|
||||
export const ghostsOf = (s: GameState, p: PlayerId): Set<LocId> =>
|
||||
|
|
@ -24,7 +24,7 @@ export function scopeOf(s: GameState, p: PlayerId, target: LocId, ghosts = ghost
|
|||
return ghosts.has(target) ? [target, ...neighbors(s, target)] : [target];
|
||||
}
|
||||
|
||||
export const mine = (s: GameState, p: PlayerId, loc: LocId): AvatarRef[] =>
|
||||
export const mine = (s: GameState, p: PlayerId, loc: LocId): AnomalyRef[] =>
|
||||
atServer(s, loc).filter((r) => r.player === p);
|
||||
|
||||
/** Active, installed Programs on a location. */
|
||||
|
|
@ -37,24 +37,24 @@ export const activeHardware = (s: GameState, ids: number[]): number[] => ids.fil
|
|||
* Places Bug counters: like Infection counters, for Bug cards. No card places them yet. ECC Memory
|
||||
* stops opponents from placing them.
|
||||
*/
|
||||
export function addBugs(s: GameState, ref: AvatarRef, n: number, source: string, by: PlayerId): boolean {
|
||||
export function addBugs(s: GameState, ref: AnomalyRef, n: number, source: string, by: PlayerId): boolean {
|
||||
if (bugImmune(s, ref, by)) {
|
||||
say(s, `ECC Memory blocks ${source}'s Bug counters on ${avatarName(s, ref)}.`);
|
||||
say(s, `ECC Memory blocks ${source}'s Bug counters on ${anomalyName(s, ref)}.`);
|
||||
fired(s, 'ECC Memory', ref.player);
|
||||
return false;
|
||||
}
|
||||
avatar(s, ref).bugs += n;
|
||||
anomaly(s, ref).bugs += n;
|
||||
fired(s, source, by);
|
||||
say(s, `${source}: ${avatarName(s, ref)} gets ${n} Bug counter${n === 1 ? '' : 's'} (${avatar(s, ref).bugs} total).`);
|
||||
say(s, `${source}: ${anomalyName(s, ref)} gets ${n} Bug counter${n === 1 ? '' : 's'} (${anomaly(s, ref).bugs} total).`);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function infect(s: GameState, ref: AvatarRef, n: number, source: string, by: PlayerId, permanent = false): void {
|
||||
const av = avatar(s, ref);
|
||||
export function infect(s: GameState, ref: AnomalyRef, n: number, source: string, by: PlayerId, permanent = false): void {
|
||||
const av = anomaly(s, ref);
|
||||
if (permanent) av.permanentInfection += n;
|
||||
else av.infection += n;
|
||||
fired(s, source, by);
|
||||
say(s, `${source}: ${avatarName(s, ref)} gets ${n === 1 ? 'an' : n} ${permanent ? 'permanent ' : ''}Infection counter${n === 1 ? '' : 's'} (${av.infection + av.permanentInfection} total).`);
|
||||
say(s, `${source}: ${anomalyName(s, ref)} gets ${n === 1 ? 'an' : n} ${permanent ? 'permanent ' : ''}Infection counter${n === 1 ? '' : 's'} (${av.infection + av.permanentInfection} total).`);
|
||||
}
|
||||
|
||||
/** One option per distinct card name. */
|
||||
|
|
@ -84,6 +84,6 @@ export function subsets<T>(items: T[]): T[][] {
|
|||
}
|
||||
|
||||
export const srcLabel = (s: GameState, src: Source): string =>
|
||||
src.kind === 'avatar' ? `${defOf(s, src.id).ability?.name} (${src.name})` : src.name;
|
||||
src.kind === 'anomaly' ? `${defOf(s, src.id).ability?.name} (${src.name})` : src.name;
|
||||
|
||||
export const everyAvatarInPlay = (s: GameState): AvatarRef[] => [...refsInPlay(s, 0), ...refsInPlay(s, 1)];
|
||||
export const everyAnomalyInPlay = (s: GameState): AnomalyRef[] => [...refsInPlay(s, 0), ...refsInPlay(s, 1)];
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import { parseArgs } from 'node:util';
|
|||
import type { BotFactory } from './bots/bot.ts';
|
||||
import { DEFAULT_GREEDY, greedyBot } from './bots/greedy.ts';
|
||||
import { randomBot } from './bots/random.ts';
|
||||
import { DEFAULT_CARDS_CSV, loadCards, type CardKind } from './cards.ts';
|
||||
import type { CardKind } from './cards.ts';
|
||||
import { DEFAULT_CARDS_CSV, loadCards } from './load.ts';
|
||||
import { playGame } from './play.ts';
|
||||
import { DEFAULT_RULES, withRule } from './rules.ts';
|
||||
import { isImplemented, staleScripts } from './scripts.ts';
|
||||
import { cardReport, formatCardReport, formatSummary, recordOf, summarize, type GameRecord } from './stats.ts';
|
||||
import { logFor } from './state.ts';
|
||||
import { PLAYER_NAMES } from './types.ts';
|
||||
|
||||
const BOTS: Record<string, { about: string; make: BotFactory }> = {
|
||||
|
|
@ -31,17 +33,19 @@ const USAGE = `Files TCG simulator
|
|||
--north BOT North's bot (default greedy)
|
||||
--max-turns N rounds × 2 before a draw (default ${DEFAULT_RULES.maxTurns}, i.e. ${DEFAULT_RULES.maxTurns / 2} rounds)
|
||||
--rule K=V change a rule in src/rules.ts; repeatable. Examples: winLocations=9,
|
||||
levelRam=4,4,6,8,10, startingAvatars=4, firstTurn.draw=true, firstTurn.advance=false,
|
||||
firstTurn.captureRam=false, firstTurn.unlock=false, firstTurn.cards=false,
|
||||
secondPlayer.ram=4, secondPlayer.avatars=1, secondPlayer.cards=2, secondPlayer.firstDraw=1,
|
||||
levelBandwidth=4,4,6,8,10, startingAnomalies=4, firstTurn.draw=true, firstTurn.advance=false,
|
||||
firstTurn.captureBandwidth=false, firstTurn.unlock=false, firstTurn.cards=false,
|
||||
secondPlayer.bandwidth=4, secondPlayer.anomalies=1, secondPlayer.cards=2, secondPlayer.firstDraw=1,
|
||||
secondPlayer.locations=1, drawPerTurn=2, deck.main=60,
|
||||
recruit.on=true (Avatars in the deck; also recruit.avatarsInDeck=5, recruit.price=8),
|
||||
buyAvatars.on=true (buy Avatars 2-4 instead of unlocking; buyAvatars.prices=8,12,16),
|
||||
copies.waitATurn=true, copies.needAvatar2=true, copies.allowed=false,
|
||||
board=grid4 (4×4 squares, win with 12 of 16; also grid4-wide, grid4-one),
|
||||
board=lanes (three lanes linked across the middle row, win with 11 of 15; also lanes-open),
|
||||
recruit.on=true (Anomalies in the deck; also recruit.anomaliesInDeck=5, recruit.price=8),
|
||||
buyAnomalies.on=true (buy Anomalies 2-4 instead of unlocking; buyAnomalies.prices=8,12,16),
|
||||
copies.waitATurn=true, copies.needAnomaly2=true, copies.allowed=false,
|
||||
commands.on=false (whole turns instead of rounds of commands),
|
||||
commands.perPlayer=3, commands.leads=F|FS|FFSS|thue, commands.snake=false,
|
||||
health.on=false (one roll decides a combat, as before v0.9),
|
||||
health.override=8 (every Avatar has this Health), health.recall=false
|
||||
health.override=8 (every Anomaly has this Health), health.recall=false
|
||||
--log play one game and print the play-by-play
|
||||
--check check rule invariants after every action (slow)
|
||||
--json FILE also write the summary and every game's result as JSON
|
||||
|
|
@ -108,7 +112,7 @@ const bots: [BotFactory, BotFactory] = [BOTS[opt.south].make, BOTS[opt.north].ma
|
|||
|
||||
for (const warning of staleScripts(pool)) console.warn(`warning: ${warning}`);
|
||||
const KIND_LABELS: [CardKind, string][] = [
|
||||
['avatar', 'Avatars'], ['server', 'Servers'], ['hardware', 'Hardware'], ['program', 'Programs'], ['execution', 'Executions'],
|
||||
['anomaly', 'Anomalies'], ['server', 'Servers'], ['hardware', 'Hardware'], ['program', 'Programs'], ['execution', 'Executions'],
|
||||
];
|
||||
const coverage = KIND_LABELS.map(([kind, label]) => {
|
||||
const cards = pool.all.filter((c) => c.kind === kind);
|
||||
|
|
@ -118,7 +122,7 @@ console.log(`Card effects simulated: ${coverage.join(', ')}.\n`);
|
|||
|
||||
if (opt.log) {
|
||||
const s = playGame({ pool, bots, seed, rules, log: true, check: opt.check });
|
||||
console.log(s.log!.join('\n'));
|
||||
console.log(logFor(s, null).join('\n'));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import type { CardDef, CardKind, CardPool } from './cards.ts';
|
||||
import { shuffle, type Rng } from './rng.ts';
|
||||
import { avatarsOutside, type RulesConfig } from './rules.ts';
|
||||
import { anomaliesOutside, type RulesConfig } from './rules.ts';
|
||||
|
||||
export interface DeckList {
|
||||
avatars: string[];
|
||||
anomalies: string[];
|
||||
servers: string[];
|
||||
/** Executions, Hardware and Programs (and Avatars, when recruiting). */
|
||||
/** Executions, Hardware and Programs (and Anomalies, when recruiting). */
|
||||
main: string[];
|
||||
}
|
||||
|
||||
|
|
@ -22,11 +22,11 @@ export function validateDeck(pool: CardPool, deck: DeckList, rules: RulesConfig)
|
|||
else if (!kinds.includes(card.kind)) errors.push(`${label}: "${name}" is a ${card.kind}`);
|
||||
}
|
||||
};
|
||||
part('Avatars', deck.avatars, ['avatar'], avatarsOutside(rules));
|
||||
part('Anomalies', deck.anomalies, ['anomaly'], anomaliesOutside(rules));
|
||||
part('Servers', deck.servers, ['server'], rules.deck.servers);
|
||||
part('Deck', deck.main, rules.recruit.on ? [...MAIN_KINDS, 'avatar'] : MAIN_KINDS, rules.deck.main);
|
||||
part('Deck', deck.main, rules.recruit.on ? [...MAIN_KINDS, 'anomaly'] : MAIN_KINDS, rules.deck.main);
|
||||
const copies = new Map<string, number>();
|
||||
for (const name of [...deck.avatars, ...deck.servers, ...deck.main]) {
|
||||
for (const name of [...deck.anomalies, ...deck.servers, ...deck.main]) {
|
||||
copies.set(name, (copies.get(name) ?? 0) + 1);
|
||||
}
|
||||
for (const [name, n] of copies) {
|
||||
|
|
@ -50,13 +50,13 @@ export function randomDeck(
|
|||
return shuffle(rng, names).slice(0, size);
|
||||
};
|
||||
if (rules.recruit.on) {
|
||||
const k = rules.recruit.avatarsInDeck;
|
||||
const avatars = sample(['avatar'], 1 + k);
|
||||
const k = rules.recruit.anomaliesInDeck;
|
||||
const anomalies = sample(['anomaly'], 1 + k);
|
||||
const servers = sample(['server'], rules.deck.servers);
|
||||
return { avatars: avatars.slice(0, 1), servers, main: shuffle(rng, [...avatars.slice(1), ...sample(MAIN_KINDS, rules.deck.main - k)]) };
|
||||
return { anomalies: anomalies.slice(0, 1), servers, main: shuffle(rng, [...anomalies.slice(1), ...sample(MAIN_KINDS, rules.deck.main - k)]) };
|
||||
}
|
||||
return {
|
||||
avatars: sample(['avatar'], rules.deck.avatars),
|
||||
anomalies: sample(['anomaly'], rules.deck.anomalies),
|
||||
servers: sample(['server'], rules.deck.servers),
|
||||
main: sample(MAIN_KINDS, rules.deck.main),
|
||||
};
|
||||
|
|
|
|||
129
sim/src/describe.ts
Normal file
129
sim/src/describe.ts
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* Readable labels for actions, for people choosing them (the app's move list, prompts). Labels are
|
||||
* written for the deciding player: "your" things are unmarked, the opponent's say whose they are.
|
||||
* Nothing here names a card the decider can't see.
|
||||
*/
|
||||
import { abilitySource, actionCost, anomalyForSale, decider } from './engine.ts';
|
||||
import { LINE_BY_ID } from './map.ts';
|
||||
import { healthLeft, healthOf } from './query.ts';
|
||||
import { anomaly, defOf, nameOf, originalOf, playerName, programLocation, wearerOf } from './state.ts';
|
||||
import type { Action, Args, AnomalyRef, GameState, PlayerId } from './types.ts';
|
||||
|
||||
const STEP_NAMES = { deploy: 'Deploy', play: 'Play', attack: 'Attack', resolve: 'Resolve', playAgain: 'Play again' } as const;
|
||||
|
||||
/** "A2–B1" for a line id like "A2-B1". */
|
||||
export const lineName = (line: string): string => {
|
||||
const l = LINE_BY_ID.get(line);
|
||||
return l ? `${l.a}–${l.b}` : line;
|
||||
};
|
||||
|
||||
/** "Anomaly 2 (Glitch)", or "the copy of Anomaly 2 (Glitch)"; the opponent's say "North's". */
|
||||
export function refName(s: GameState, r: AnomalyRef, me: PlayerId | null = decider(s)): string {
|
||||
const n = originalOf(r).slot;
|
||||
const card = anomaly(s, r).card;
|
||||
const name = card < 0 || !anomaly(s, originalOf(r)).faceUp ? 'face down' : nameOf(s, card);
|
||||
const whose = me !== null && r.player !== me ? `${playerName(r.player)}'s ` : '';
|
||||
return r.slot > 4 ? `${whose}copy of Anomaly ${n} (${name})` : `${whose}Anomaly ${n} (${name})`;
|
||||
}
|
||||
|
||||
/** Where a card is, for telling two same-named cards apart: "on C2", "on Anomaly 1 (Glitch)", "from hand". */
|
||||
function cardWhere(s: GameState, id: number, me: PlayerId | null): string {
|
||||
const loc = programLocation(s, id);
|
||||
if (loc) return ` on ${loc}`;
|
||||
const r = wearerOf(s, id);
|
||||
if (r) return ` on ${refName(s, r, me)}`;
|
||||
const pl = s.players[s.cards[id].owner];
|
||||
if (pl.hand.includes(id)) return ' from hand';
|
||||
if (pl.discard.includes(id)) return ' from the discard pile';
|
||||
return '';
|
||||
}
|
||||
|
||||
function cardName(s: GameState, id: number, me: PlayerId | null): string {
|
||||
const owner = s.cards[id]?.owner;
|
||||
const whose = me !== null && owner !== undefined && owner !== me ? `${playerName(owner)}'s ` : '';
|
||||
return `${whose}${nameOf(s, id)}${cardWhere(s, id, me)}`;
|
||||
}
|
||||
|
||||
/** Execution and Ability arguments: "Anomaly 2 (Glitch) → C1", "destroy Overclocked CPU on …". */
|
||||
export function describeArgs(s: GameState, a: Args, me: PlayerId | null = decider(s), toWord = 'at'): string {
|
||||
const parts: string[] = [];
|
||||
if (a.heal) parts.push('heal this Anomaly');
|
||||
if (a.ref) parts.push(refName(s, a.ref, me));
|
||||
if (a.card !== undefined) {
|
||||
const name = cardName(s, a.card, me);
|
||||
parts.push(a.mode ? `${a.mode} ${name}` : a.cards ? `swap out ${name}` : name);
|
||||
}
|
||||
if (a.cards?.length) parts.push(`${a.card !== undefined ? 'for ' : ''}${a.cards.map((id) => cardName(s, id, me)).join(', ')}`);
|
||||
if (a.to) parts.push(a.ref ? `→ ${a.to}` : `${toWord} ${a.to}`);
|
||||
if (a.k !== undefined) parts.push(`reroll dice showing ${a.k} or less`);
|
||||
return parts.join(' ');
|
||||
}
|
||||
|
||||
const gb = (n: number): string => ` (${n} Gb)`;
|
||||
|
||||
/** A label for one of the current legal actions, e.g. "Play Execute: Force Reboot on D2 (5 Gb)". */
|
||||
export function describeAction(s: GameState, a: Action): string {
|
||||
const me = decider(s) ?? s.active;
|
||||
const ref = (slot: number): AnomalyRef => ({ player: me, slot });
|
||||
const cost = actionCost(s, a);
|
||||
switch (a.type) {
|
||||
case 'end':
|
||||
if (s.step === 'playAgain') return s.rules.commands.on ? 'End command' : 'End turn';
|
||||
if (s.step === 'attack') return 'End Attack step and resolve';
|
||||
return `End ${STEP_NAMES[s.step]} step`;
|
||||
case 'pass':
|
||||
return 'Pass';
|
||||
case 'choose': {
|
||||
const o = s.choice?.options[a.index];
|
||||
return `${o?.label ?? `Option ${a.index + 1}`}${o?.cost ? gb(o.cost) : ''}`;
|
||||
}
|
||||
case 'place': {
|
||||
const av = anomaly(s, ref(a.slot));
|
||||
return av.at === null ? `Place ${refName(s, ref(a.slot), me)} on ${a.to}` : `Move ${refName(s, ref(a.slot), me)} ${av.at} → ${a.to}`;
|
||||
}
|
||||
case 'recall': {
|
||||
const r = ref(a.slot);
|
||||
const hurt = s.rules.health.on ? healthOf(s, r) - healthLeft(s, r) : 0;
|
||||
return `Recall ${refName(s, r, me)} from ${anomaly(s, r).at}${hurt ? `, healing ${hurt}` : ''}`;
|
||||
}
|
||||
case 'advance':
|
||||
return `Advance ${refName(s, ref(a.slot), me)} ${anomaly(s, ref(a.slot)).at} → ${a.to}`;
|
||||
case 'attack':
|
||||
return `Attack ${a.to} with ${refName(s, ref(a.slot), me)} from ${anomaly(s, ref(a.slot)).at}`;
|
||||
case 'clearFirewall':
|
||||
return `Clear the Lv ${s.firewalls[a.line]} Firewall on ${lineName(a.line)}${gb(cost)}`;
|
||||
case 'firewall':
|
||||
return s.firewalls[a.line]
|
||||
? `Upgrade the Firewall on ${lineName(a.line)} to Lv ${a.level}${gb(cost)}`
|
||||
: `Place a Lv ${a.level} Firewall on ${lineName(a.line)}${gb(cost)}`;
|
||||
case 'salvage':
|
||||
return `Salvage ${nameOf(s, a.card)} (+${defOf(s, a.card).bandwidth} Gb)`;
|
||||
case 'installHardware':
|
||||
return `Install ${nameOf(s, a.card)} on ${refName(s, ref(a.slot), me)}${gb(cost)}`;
|
||||
case 'recruit': {
|
||||
const old = anomaly(s, ref(a.slot));
|
||||
return `Recruit ${nameOf(s, a.card)} as Anomaly ${a.slot}${old.card >= 0 ? `, retiring ${nameOf(s, old.card)}` : ''}${gb(cost)}`;
|
||||
}
|
||||
case 'buyAnomaly':
|
||||
return `Buy Anomaly ${a.slot} (face down)${gb(anomalyForSale(s, me)?.price ?? cost)}`;
|
||||
case 'installProgram':
|
||||
return `Install ${nameOf(s, a.card)} on ${a.at}${gb(cost)}`;
|
||||
case 'play': {
|
||||
// Packet Flood and Purge name the location they hit; it's the target unless Ghost Process widens it.
|
||||
const args = a.args.to === a.target && !a.args.ref ? describeArgs(s, { ...a.args, to: undefined }, me) : describeArgs(s, a.args, me);
|
||||
const on = a.target ? ` on ${a.target}` : '';
|
||||
const from = a.from ? `, performed by ${a.from}` : '';
|
||||
return `Play ${nameOf(s, a.card)}${on}${args ? `: ${args}` : ''}${from}${gb(cost)}`;
|
||||
}
|
||||
case 'activate': {
|
||||
const src = abilitySource(s, a.card, a.name);
|
||||
const def = defOf(s, a.card);
|
||||
const label = src?.kind === 'anomaly' && src.ref
|
||||
? `${def.ability?.name ?? a.name} (${refName(s, src.ref, me).replace(/ \((.*)\)$/, ', $1')})`
|
||||
: a.name !== def.name ? `${a.name} (copied by ${def.name})` : a.name;
|
||||
const where = src?.kind === 'hardware' && src.ref ? ` on ${refName(s, src.ref, me)}` : src?.kind !== 'anomaly' && src?.at ? ` on ${src.at}` : '';
|
||||
const args = describeArgs(s, a.args, me, '→');
|
||||
return `Use ${label}${where}${args ? `${args.startsWith('→') ? ' ' : ': '}${args}` : ''}${cost ? gb(cost) : ''}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,13 +14,13 @@ import {
|
|||
defeat,
|
||||
drawNow,
|
||||
drawTask,
|
||||
recallAvatar,
|
||||
recallAnomaly,
|
||||
resolveDeclaration,
|
||||
retireAvatar,
|
||||
retireAnomaly,
|
||||
} from './flow.ts';
|
||||
import { GRID, LINES, LINES_AT, LINE_BY_ID, LOCATIONS, START_LOC, isStart, otherEnd, type LocId } from './map.ts';
|
||||
import { GRID, LINES, LINES_AT, LINE_BY_ID, LOCATIONS, START_LOC, isStart, otherEnd, useBoard, type LocId } from './map.ts';
|
||||
import {
|
||||
avatarRoom,
|
||||
anomalyRoom,
|
||||
costOf,
|
||||
coresOf,
|
||||
desynced,
|
||||
|
|
@ -28,9 +28,9 @@ import {
|
|||
enemyFlagAt,
|
||||
hasRoom,
|
||||
pay,
|
||||
portsFree,
|
||||
slotsFree,
|
||||
programSlots,
|
||||
reachableRam,
|
||||
reachableBandwidth,
|
||||
sources,
|
||||
stillActive,
|
||||
wears,
|
||||
|
|
@ -39,8 +39,8 @@ import { makeRng, randInt, shuffle } from './rng.ts';
|
|||
import { DEFAULT_RULES, type RulesConfig } from './rules.ts';
|
||||
import { scriptOf, type Fighter } from './scripts.ts';
|
||||
import {
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
canAct,
|
||||
controls,
|
||||
defOf,
|
||||
|
|
@ -76,8 +76,8 @@ import {
|
|||
STAT_KEYS,
|
||||
type Action,
|
||||
type Args,
|
||||
type AvatarRef,
|
||||
type AvatarState,
|
||||
type AnomalyRef,
|
||||
type AnomalyState,
|
||||
type GameState,
|
||||
type GameStats,
|
||||
type LocationState,
|
||||
|
|
@ -98,13 +98,13 @@ export interface NewGame {
|
|||
|
||||
export { controls, defOf, firewallCost, gridCount, isOpen, nameOf, other } from './state.ts';
|
||||
|
||||
/** Combat Cores for an Avatar standing on `at`, outside any combat. For bots pricing an attack. */
|
||||
export function avatarCores(
|
||||
/** Combat Cores for an Anomaly standing on `at`, outside any combat. For bots pricing an attack. */
|
||||
export function anomalyCores(
|
||||
s: GameState,
|
||||
p: PlayerId,
|
||||
slot: number,
|
||||
role: 'attack' | 'defend',
|
||||
at: LocId | null = s.players[p].avatars[slot - 1].at,
|
||||
at: LocId | null = s.players[p].anomalies[slot - 1].at,
|
||||
loc: LocId | null = role === 'defend' ? at : null,
|
||||
): number {
|
||||
const f: Fighter = { ref: { player: p, slot }, role, at, loc, combat: null };
|
||||
|
|
@ -123,18 +123,18 @@ function newStats(): GameStats {
|
|||
return Object.fromEntries(STAT_KEYS.map((k) => [k, [0, 0]])) as GameStats;
|
||||
}
|
||||
|
||||
/** Recruit rule: an Avatar's printed RAM is its price, which is also what it salvages for. */
|
||||
/** Recruit rule: an Anomaly's printed Bandwidth is its price, which is also what it salvages for. */
|
||||
function withPrice(def: CardDef, rules: RulesConfig): CardDef {
|
||||
if (!rules.recruit.on || def.kind !== 'avatar') return def;
|
||||
return { ...def, ram: rules.recruit.price + rules.recruit.pricePerCore * def.cores };
|
||||
if (!rules.recruit.on || def.kind !== 'anomaly') return def;
|
||||
return { ...def, bandwidth: rules.recruit.price + rules.recruit.pricePerCore * def.cores };
|
||||
}
|
||||
|
||||
/** Recruit rule: slots `p` can recruit into. The first empty one while there's room, or any Avatar to retire. */
|
||||
/** Recruit rule: slots `p` can recruit into. The first empty one while there's room, or any Anomaly to retire. */
|
||||
export function recruitSlots(s: GameState, p: PlayerId): number[] {
|
||||
const avs = s.players[p].avatars.slice(0, 4);
|
||||
const avs = s.players[p].anomalies.slice(0, 4);
|
||||
const out: number[] = [];
|
||||
const empty = avs.findIndex((a) => a.card < 0);
|
||||
if (empty >= 0 && avatarRoom(s, p)) out.push(empty + 1);
|
||||
if (empty >= 0 && anomalyRoom(s, p)) out.push(empty + 1);
|
||||
avs.forEach((a, i) => {
|
||||
const declared = s.declarations.some((d) => d.ref.player === p && originalOf(d.ref).slot === i + 1);
|
||||
if (a.card >= 0 && !declared) out.push(i + 1);
|
||||
|
|
@ -142,14 +142,14 @@ export function recruitSlots(s: GameState, p: PlayerId): number[] {
|
|||
return out;
|
||||
}
|
||||
|
||||
/** Buy-Avatars rule: the next Avatar `p` can buy (its slot) and its price, or null. */
|
||||
export function avatarForSale(s: GameState, p: PlayerId): { slot: number; price: number } | null {
|
||||
if (!s.rules.buyAvatars.on) return null;
|
||||
const i = s.players[p].avatars.slice(0, 4).findIndex((a) => !a.faceUp);
|
||||
return i < 1 ? null : { slot: i + 1, price: s.rules.buyAvatars.prices[i - 1] };
|
||||
/** Buy-Anomalies rule: the next Anomaly `p` can buy (its slot) and its price, or null. */
|
||||
export function anomalyForSale(s: GameState, p: PlayerId): { slot: number; price: number } | null {
|
||||
if (!s.rules.buyAnomalies.on) return null;
|
||||
const i = s.players[p].anomalies.slice(0, 4).findIndex((a) => !a.faceUp);
|
||||
return i < 1 ? null : { slot: i + 1, price: s.rules.buyAnomalies.prices[i - 1] };
|
||||
}
|
||||
|
||||
function newAvatar(card: number, faceUp: boolean, copyOf: number | null): AvatarState {
|
||||
function newAnomaly(card: number, faceUp: boolean, copyOf: number | null): AnomalyState {
|
||||
return {
|
||||
card,
|
||||
faceUp,
|
||||
|
|
@ -177,6 +177,7 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
const errors = validateDeck(pool, deck, rules);
|
||||
if (errors.length) throw new Error(`${playerName(p as PlayerId)} deck is illegal:\n ${errors.join('\n ')}`);
|
||||
});
|
||||
useBoard(rules.board);
|
||||
const rng = makeRng(seed);
|
||||
const s: GameState = {
|
||||
rules,
|
||||
|
|
@ -215,18 +216,18 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
};
|
||||
for (const p of [0, 1] as const) {
|
||||
const deck = decks[p];
|
||||
// Recruit rule: slots after the starting Avatar begin empty (-1).
|
||||
const avatars = shuffle(rng, deck.avatars.map((n) => add(n, p)));
|
||||
const slots = [0, 1, 2, 3].map((i) => avatars[i] ?? -1);
|
||||
// Recruit rule: slots after the starting Anomaly begin empty (-1).
|
||||
const anomalies = shuffle(rng, deck.anomalies.map((n) => add(n, p)));
|
||||
const slots = [0, 1, 2, 3].map((i) => anomalies[i] ?? -1);
|
||||
s.players.push({
|
||||
ram: 0,
|
||||
bandwidth: 0,
|
||||
hand: [],
|
||||
deck: shuffle(rng, deck.main.map((n) => add(n, p))),
|
||||
discard: [],
|
||||
serverPile: shuffle(rng, deck.servers.map((n) => add(n, p))),
|
||||
avatars: [
|
||||
...slots.map((card, i) => newAvatar(card, card >= 0 && i < rules.startingAvatars, null)),
|
||||
...slots.map((card, i) => newAvatar(card, false, i + 1)),
|
||||
anomalies: [
|
||||
...slots.map((card, i) => newAnomaly(card, card >= 0 && i < rules.startingAnomalies, null)),
|
||||
...slots.map((card, i) => newAnomaly(card, false, i + 1)),
|
||||
],
|
||||
unlockedLevel: 1,
|
||||
});
|
||||
|
|
@ -237,20 +238,20 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
const server = me.serverPile.shift()!;
|
||||
start.owner = p;
|
||||
start.server = server;
|
||||
me.ram = rules.startingRam + (scriptOf(s.cards[server].name)?.ramOnPlace ?? 0);
|
||||
me.bandwidth = rules.startingBandwidth + (scriptOf(s.cards[server].name)?.bandwidthOnPlace ?? 0);
|
||||
played(s, s.cards[server].name, p);
|
||||
for (let i = 0; i < rules.openingHand; i++) drawNow(s, p);
|
||||
say(s, `${playerName(p)} starts on ${nameOf(s, server)} with ${me.ram} RAM. Avatar 1: ${nameOf(s, me.avatars[0].card)}.`);
|
||||
say(s, `${playerName(p)} starts on ${nameOf(s, server)} with ${me.bandwidth} Gb. Anomaly 1: ${nameOf(s, me.anomalies[0].card)}.`, { tag: 'game', player: p });
|
||||
}
|
||||
s.firstPlayer = randInt(rng, 2) as PlayerId;
|
||||
s.active = s.firstPlayer;
|
||||
const p2 = other(s.firstPlayer);
|
||||
const second = s.players[p2];
|
||||
second.ram += rules.secondPlayer.ram;
|
||||
second.avatars.slice(0, rules.startingAvatars + rules.secondPlayer.avatars).forEach((av) => (av.faceUp = av.card >= 0));
|
||||
second.bandwidth += rules.secondPlayer.bandwidth;
|
||||
second.anomalies.slice(0, rules.startingAnomalies + rules.secondPlayer.anomalies).forEach((av) => (av.faceUp = av.card >= 0));
|
||||
for (let i = 0; i < rules.secondPlayer.cards; i++) drawNow(s, p2);
|
||||
if (rules.secondPlayer.locations > 0) {
|
||||
// The location next to the starting Server, with a Server from the pile: no RAM, no unlock.
|
||||
// The location next to the starting Server, with a Server from the pile: no Bandwidth, no unlock.
|
||||
const line = LINES_AT.get(START_LOC[p2])![0];
|
||||
const L = s.locations[otherEnd(line, START_LOC[p2])];
|
||||
L.owner = p2;
|
||||
|
|
@ -258,7 +259,7 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
played(s, s.cards[L.server].name, p2);
|
||||
}
|
||||
s.stats.cardsDrawn = [0, 0];
|
||||
say(s, `${playerName(s.firstPlayer)} goes first.`);
|
||||
say(s, `${playerName(s.firstPlayer)} goes first.`, { tag: 'game', player: s.firstPlayer });
|
||||
beginTurn(s, !rules.firstTurn.draw);
|
||||
run(s);
|
||||
return s;
|
||||
|
|
@ -269,7 +270,7 @@ function beginTurn(s: GameState, skipDraw: boolean): void {
|
|||
if (s.turn >= s.rules.maxTurns * (cmd ? s.rules.commands.perPlayer : 1)) {
|
||||
s.over = true;
|
||||
s.endReason = 'turnLimit';
|
||||
say(s, `Turn limit reached: draw (South ${gridCount(s, 0)}, North ${gridCount(s, 1)} locations).`);
|
||||
say(s, `Turn limit reached: draw (South ${gridCount(s, 0)}, North ${gridCount(s, 1)} locations).`, { tag: 'game' });
|
||||
return;
|
||||
}
|
||||
s.turn++;
|
||||
|
|
@ -280,7 +281,7 @@ function beginTurn(s: GameState, skipDraw: boolean): void {
|
|||
tidy(s);
|
||||
const me = s.players[s.active];
|
||||
if (fresh) {
|
||||
for (const av of me.avatars) {
|
||||
for (const av of me.anomalies) {
|
||||
av.placed = false;
|
||||
av.advanced = false;
|
||||
av.attacks = 0;
|
||||
|
|
@ -289,7 +290,7 @@ function beginTurn(s: GameState, skipDraw: boolean): void {
|
|||
s.declarations = [];
|
||||
s.step = 'deploy';
|
||||
const title = cmd ? `Round ${roundOf(s, s.turn)}, command ${s.turn}` : `Turn ${s.turn}`;
|
||||
say(s, `\n— ${title}: ${playerName(s.active)} (${me.ram} RAM, ${me.hand.length} cards, ${gridCount(s, s.active)} locations) —`);
|
||||
say(s, `\n— ${title}: ${playerName(s.active)} (${me.bandwidth} Gb, ${me.hand.length} cards, ${gridCount(s, s.active)} locations) —`, { tag: 'turn', player: s.active });
|
||||
const draws = s.rules.drawPerTurn + (s.turn === 2 ? s.rules.secondPlayer.firstDraw : 0);
|
||||
if (fresh && !skipDraw) pushTasks(s, ...Array.from({ length: draws }, (): Task => ({ t: 'draw', player: s.active })));
|
||||
if (fresh) emit(s, 'onTurnStart', null);
|
||||
|
|
@ -298,15 +299,15 @@ function beginTurn(s: GameState, skipDraw: boolean): void {
|
|||
/** Command rule: this game turn's command is spent (an advance or attack is declared). */
|
||||
const commandSpent = (s: GameState): boolean => s.rules.commands.on && s.declarations.length > 0;
|
||||
|
||||
/** Command rule: an Avatar unlocked this round waits in its slot until the next round. */
|
||||
const waitsForRound = (s: GameState, av: AvatarState): boolean =>
|
||||
/** Command rule: an Anomaly unlocked this round waits in its slot until the next round. */
|
||||
const waitsForRound = (s: GameState, av: AnomalyState): boolean =>
|
||||
s.rules.commands.on && av.at === null && av.unlockedTurn > 0 && roundOf(s, av.unlockedTurn) === roundOf(s, s.turn);
|
||||
|
||||
function endTurn(s: GameState): void {
|
||||
s.clock = endOf(s.turn);
|
||||
// Push Update: the extra Hardware leaves at the end of its controller's turn.
|
||||
for (const pl of s.players) {
|
||||
for (const av of pl.avatars) {
|
||||
for (const av of pl.anomalies) {
|
||||
for (const hw of [...av.hardware]) {
|
||||
const until = s.cards[hw].pushedUntil;
|
||||
if (until !== undefined && !running(s, until)) {
|
||||
|
|
@ -326,7 +327,7 @@ function endTurn(s: GameState): void {
|
|||
function tidy(s: GameState): void {
|
||||
s.virtuals = s.virtuals.filter((v) => running(s, v.until));
|
||||
for (const pl of s.players) {
|
||||
for (const av of pl.avatars) av.mods = av.mods.filter((m) => m.combat !== undefined || running(s, m.until ?? 0));
|
||||
for (const av of pl.anomalies) av.mods = av.mods.filter((m) => m.combat !== undefined || running(s, m.until ?? 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -363,9 +364,9 @@ export function advanceTargets(s: GameState, p: PlayerId): LocId[] {
|
|||
});
|
||||
}
|
||||
|
||||
/** Infinite Loop lets an Avatar attacking from its location attack twice. */
|
||||
export function maxAttacks(s: GameState, ref: AvatarRef): number {
|
||||
const at = avatar(s, ref).at;
|
||||
/** Infinite Loop lets an Anomaly attacking from its location attack twice. */
|
||||
export function maxAttacks(s: GameState, ref: AnomalyRef): number {
|
||||
const at = anomaly(s, ref).at;
|
||||
let extra = 0;
|
||||
for (const x of sources(s)) {
|
||||
if (x.at === at && x.controller === ref.player) extra = Math.max(extra, scriptOf(x.name)?.extraAttacks ?? 0);
|
||||
|
|
@ -373,8 +374,8 @@ export function maxAttacks(s: GameState, ref: AvatarRef): number {
|
|||
return 1 + extra;
|
||||
}
|
||||
|
||||
export function attackTargets(s: GameState, ref: AvatarRef): LocId[] {
|
||||
const av = avatar(s, ref);
|
||||
export function attackTargets(s: GameState, ref: AnomalyRef): LocId[] {
|
||||
const av = anomaly(s, ref);
|
||||
if (!av.faceUp || av.at === null || av.advanced || av.attacks >= maxAttacks(s, ref) || !canAct(s, ref) || freshCopy(s, ref)) return [];
|
||||
const opp = other(ref.player);
|
||||
return LINES_AT.get(av.at)!
|
||||
|
|
@ -386,7 +387,7 @@ export function attackTargets(s: GameState, ref: AvatarRef): LocId[] {
|
|||
function pushClears(s: GameState, p: PlayerId, out: Action[]): void {
|
||||
for (const [line, level] of Object.entries(s.firewalls)) {
|
||||
const l = LINE_BY_ID.get(line)!;
|
||||
if ((controls(s, p, l.a) || controls(s, p, l.b)) && firewallCost(s, level) <= s.players[p].ram) {
|
||||
if ((controls(s, p, l.a) || controls(s, p, l.b)) && firewallCost(s, level) <= s.players[p].bandwidth) {
|
||||
out.push({ type: 'clearFirewall', line });
|
||||
}
|
||||
}
|
||||
|
|
@ -410,31 +411,31 @@ export const execBlocked = (s: GameState, loc: LocId): boolean => usedThisTurn(s
|
|||
|
||||
/**
|
||||
* Servers worth naming as an Execution's performer: null (any of your Servers), plus each Server
|
||||
* where one of your Avatars wears Hardware that cares (Dedicated GPU, Quantum Coprocessor).
|
||||
* where one of your Anomalies wears Hardware that cares (Dedicated GPU, Quantum Coprocessor).
|
||||
*/
|
||||
function performers(s: GameState, p: PlayerId): (LocId | null)[] {
|
||||
const out = new Set<LocId | null>([null]);
|
||||
for (const r of refsInPlay(s, p)) {
|
||||
const at = avatar(s, r).at!;
|
||||
const at = anomaly(s, r).at!;
|
||||
if (isCopy(r) || !controls(s, p, at) || execBlocked(s, at)) continue;
|
||||
if (wears(s, r, (sc) => sc.executionPower || sc.copiesExecutions).length) out.add(at);
|
||||
}
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/** Dedicated GPU: extra effect for Executions performed by `from`, from its Avatars' Hardware. */
|
||||
/** Dedicated GPU: extra effect for Executions performed by `from`, from its Anomalies' Hardware. */
|
||||
export function executionPower(s: GameState, p: PlayerId, from: LocId | null): number {
|
||||
if (from === null) return 0;
|
||||
let n = 0;
|
||||
for (const r of refsInPlay(s, p)) {
|
||||
if (isCopy(r) || avatar(s, r).at !== from) continue;
|
||||
if (isCopy(r) || anomaly(s, r).at !== from) continue;
|
||||
for (const hw of wears(s, r, (sc) => sc.executionPower)) n += scriptOf(s.cards[hw].name)!.executionPower!;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
export const executionHostiles = (s: GameState, item: Pick<StackItem, 'player' | 'target' | 'args' | 'name'>): AvatarRef[] =>
|
||||
(scriptOf(item.name)?.execution?.targetsAvatars?.(s, item) ?? []).filter((r) => r.player !== item.player);
|
||||
export const executionHostiles = (s: GameState, item: Pick<StackItem, 'player' | 'target' | 'args' | 'name'>): AnomalyRef[] =>
|
||||
(scriptOf(item.name)?.execution?.targetsAnomalies?.(s, item) ?? []).filter((r) => r.player !== item.player);
|
||||
|
||||
export function executionCost(s: GameState, p: PlayerId, card: number, target: LocId | null, args: Args, all?: Source[]): number {
|
||||
const hostile = executionHostiles(s, { player: p, target, args, name: s.cards[card].name });
|
||||
|
|
@ -442,8 +443,8 @@ export function executionCost(s: GameState, p: PlayerId, card: number, target: L
|
|||
}
|
||||
|
||||
/**
|
||||
* Execution plays for `p`. `budget` 'now' keeps plays affordable with current RAM; 'reachable'
|
||||
* also counts Salvage; 'any' ignores RAM.
|
||||
* Execution plays for `p`. `budget` 'now' keeps plays affordable with current Bandwidth; 'reachable'
|
||||
* also counts Salvage; 'any' ignores Bandwidth.
|
||||
*/
|
||||
export function executionActions(s: GameState, p: PlayerId, budget: 'now' | 'reachable' | 'any', limit = Infinity): Action[] {
|
||||
const out: Action[] = [];
|
||||
|
|
@ -457,8 +458,8 @@ export function executionActions(s: GameState, p: PlayerId, budget: 'now' | 'rea
|
|||
seen.add(name);
|
||||
const ex = scriptOf(name)?.execution;
|
||||
if (!ex) continue;
|
||||
const cap = budget === 'any' ? Infinity : budget === 'now' ? s.players[p].ram : reachableRam(s, p, card);
|
||||
if (defOf(s, card).ram - 3 > cap && budget !== 'any') continue; // no discount is bigger than 2
|
||||
const cap = budget === 'any' ? Infinity : budget === 'now' ? s.players[p].bandwidth : reachableBandwidth(s, p, card);
|
||||
if (defOf(s, card).bandwidth - 3 > cap && budget !== 'any') continue; // no discount is bigger than 2
|
||||
all ??= sources(s);
|
||||
for (const play of ex.plays(s, p)) {
|
||||
if (executionCost(s, p, card, play.target, play.args, all) > cap) continue;
|
||||
|
|
@ -477,7 +478,7 @@ export const abilitySource = (s: GameState, card: number, name: string): Source
|
|||
|
||||
export function abilityCost(s: GameState, src: Source): number {
|
||||
const script = scriptOf(src.name)!;
|
||||
if (src.kind === 'avatar') return defOf(s, src.id).ability?.cost ?? 0;
|
||||
if (src.kind === 'anomaly') return defOf(s, src.id).ability?.cost ?? 0;
|
||||
return script.ability?.cost ?? 0;
|
||||
}
|
||||
|
||||
|
|
@ -489,7 +490,7 @@ export const abilityKey = (src: Source): string => `ability:${src.id}:${src.name
|
|||
export function abilityReady(s: GameState, src: Source): boolean {
|
||||
const ab = scriptOf(src.name)?.ability;
|
||||
if (!ab || !activatable(src)) return false;
|
||||
if (src.kind === 'avatar' && !canAct(s, src.ref!)) return false;
|
||||
if (src.kind === 'anomaly' && !canAct(s, src.ref!)) return false;
|
||||
if (src.kind === 'hardware') {
|
||||
if (hardwareUsesLeft(s, src.id) <= 0) return false;
|
||||
return !(ab.hardwareOncePerTurn && desynced(s, src.ref!));
|
||||
|
|
@ -499,7 +500,7 @@ export function abilityReady(s: GameState, src: Source): boolean {
|
|||
|
||||
export function abilityActions(s: GameState, p: PlayerId, budget: 'now' | 'reachable' | 'any', limit = Infinity): Action[] {
|
||||
const out: Action[] = [];
|
||||
const cap = budget === 'any' ? Infinity : budget === 'now' ? s.players[p].ram : reachableRam(s, p);
|
||||
const cap = budget === 'any' ? Infinity : budget === 'now' ? s.players[p].bandwidth : reachableBandwidth(s, p);
|
||||
for (const src of sources(s)) {
|
||||
if (src.controller !== p || !scriptOf(src.name)?.ability || !abilityReady(s, src)) continue;
|
||||
const ab = scriptOf(src.name)!.ability!;
|
||||
|
|
@ -518,8 +519,8 @@ function hasResponse(s: GameState, p: PlayerId): boolean {
|
|||
return executionActions(s, p, 'reachable', 1).length > 0 || abilityActions(s, p, 'reachable', 1).length > 0;
|
||||
}
|
||||
|
||||
export function hardwareCost(s: GameState, card: number, ref: AvatarRef, all?: Source[]): number {
|
||||
return costOf(s, { kind: 'hardware', player: ref.player, card, ref, at: avatar(s, ref).at }, all);
|
||||
export function hardwareCost(s: GameState, card: number, ref: AnomalyRef, all?: Source[]): number {
|
||||
return costOf(s, { kind: 'hardware', player: ref.player, card, ref, at: anomaly(s, ref).at }, all);
|
||||
}
|
||||
export function programCost(s: GameState, p: PlayerId, card: number, at: LocId, all?: Source[]): number {
|
||||
return costOf(s, { kind: 'program', player: p, card, at }, all);
|
||||
|
|
@ -528,10 +529,10 @@ export function placeFirewallCost(s: GameState, p: PlayerId, line: string, level
|
|||
return costOf(s, { kind: 'firewall', player: p, line, level }, all);
|
||||
}
|
||||
|
||||
/** Whether Hardware can go on an Avatar now (ports permitting). */
|
||||
export function canWear(s: GameState, card: number, ref: AvatarRef): boolean {
|
||||
if (isCopy(ref) || avatar(s, ref).at === null) return false;
|
||||
return !!scriptOf(s.cards[card].name)?.noPort || portsFree(s, ref) > 0;
|
||||
/** Whether Hardware can go on an Anomaly now (Expansion Slots permitting). */
|
||||
export function canWear(s: GameState, card: number, ref: AnomalyRef): boolean {
|
||||
if (isCopy(ref) || anomaly(s, ref).at === null) return false;
|
||||
return !!scriptOf(s.cards[card].name)?.noSlot || slotsFree(s, ref) > 0;
|
||||
}
|
||||
|
||||
export function legalActions(s: GameState): Action[] {
|
||||
|
|
@ -542,7 +543,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
|
||||
if (s.choice) {
|
||||
const options = s.choice.options.flatMap((o, index): Action[] =>
|
||||
(o.cost ?? 0) <= me.ram ? [{ type: 'choose', index }] : []);
|
||||
(o.cost ?? 0) <= me.bandwidth ? [{ type: 'choose', index }] : []);
|
||||
return [...options, ...salvage];
|
||||
}
|
||||
if (openWindow(s)) {
|
||||
|
|
@ -557,7 +558,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
if (s.step === 'deploy') {
|
||||
const placementOpen = s.declarations.length === 0;
|
||||
const targets = s.turn === 1 && !s.rules.firstTurn.advance ? [] : advanceTargets(s, p);
|
||||
me.avatars.forEach((av, i) => {
|
||||
me.anomalies.forEach((av, i) => {
|
||||
const ref = { player: p, slot: i + 1 };
|
||||
if (!av.faceUp || av.advanced || av.attacks > 0) return;
|
||||
if (av.at !== null && !canAct(s, ref)) return;
|
||||
|
|
@ -569,7 +570,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
});
|
||||
pushClears(s, p, out);
|
||||
} else if (s.step === 'attack') {
|
||||
me.avatars.forEach((_, i) => {
|
||||
me.anomalies.forEach((_, i) => {
|
||||
if (commandSpent(s)) return;
|
||||
for (const to of attackTargets(s, { player: p, slot: i + 1 })) out.push({ type: 'attack', slot: i + 1, to });
|
||||
});
|
||||
|
|
@ -583,26 +584,26 @@ export function legalActions(s: GameState): Action[] {
|
|||
seen.add(def.name);
|
||||
if (def.kind === 'hardware') {
|
||||
for (const ref of refsInPlay(s, p)) {
|
||||
if (canWear(s, card, ref) && hardwareCost(s, card, ref, all) <= me.ram) {
|
||||
if (canWear(s, card, ref) && hardwareCost(s, card, ref, all) <= me.bandwidth) {
|
||||
out.push({ type: 'installHardware', card, slot: ref.slot });
|
||||
}
|
||||
}
|
||||
} else if (def.kind === 'avatar' && s.rules.recruit.on) {
|
||||
if (def.ram <= me.ram) for (const slot of recruitSlots(s, p)) out.push({ type: 'recruit', card, slot });
|
||||
} else if (def.kind === 'anomaly' && s.rules.recruit.on) {
|
||||
if (def.bandwidth <= me.bandwidth) for (const slot of recruitSlots(s, p)) out.push({ type: 'recruit', card, slot });
|
||||
} else if (def.kind === 'program') {
|
||||
for (const at of LOCATIONS) {
|
||||
if (controls(s, p, at) && s.locations[at].programs.length < programSlots(s, at) && programCost(s, p, card, at, all) <= me.ram) {
|
||||
if (controls(s, p, at) && s.locations[at].programs.length < programSlots(s, at) && programCost(s, p, card, at, all) <= me.bandwidth) {
|
||||
out.push({ type: 'installProgram', card, at });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const sale = avatarForSale(s, p);
|
||||
if (sale && sale.price <= me.ram) out.push({ type: 'buyAvatar', slot: sale.slot });
|
||||
const sale = anomalyForSale(s, p);
|
||||
if (sale && sale.price <= me.bandwidth) out.push({ type: 'buyAnomaly', slot: sale.slot });
|
||||
for (const line of LINES) {
|
||||
if (!line.gateway || !(controls(s, p, line.a) || controls(s, p, line.b))) continue;
|
||||
for (let level = (s.firewalls[line.id] ?? 0) + 1; level <= s.rules.firewallCost.length; level++) {
|
||||
if (placeFirewallCost(s, p, line.id, level, all) <= me.ram) out.push({ type: 'firewall', line: line.id, level });
|
||||
if (placeFirewallCost(s, p, line.id, level, all) <= me.bandwidth) out.push({ type: 'firewall', line: line.id, level });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -610,7 +611,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
return out;
|
||||
}
|
||||
|
||||
/** RAM an action costs, before any Salvage. */
|
||||
/** Bandwidth an action costs, before any Salvage. */
|
||||
export function actionCost(s: GameState, a: Action): number {
|
||||
const p = decider(s) ?? s.active;
|
||||
switch (a.type) {
|
||||
|
|
@ -621,9 +622,9 @@ export function actionCost(s: GameState, a: Action): number {
|
|||
case 'installHardware':
|
||||
return hardwareCost(s, a.card, { player: p, slot: a.slot });
|
||||
case 'recruit':
|
||||
return defOf(s, a.card).ram;
|
||||
case 'buyAvatar':
|
||||
return avatarForSale(s, p)?.price ?? 0;
|
||||
return defOf(s, a.card).bandwidth;
|
||||
case 'buyAnomaly':
|
||||
return anomalyForSale(s, p)?.price ?? 0;
|
||||
case 'installProgram':
|
||||
return programCost(s, p, a.card, a.at);
|
||||
case 'play':
|
||||
|
|
@ -666,7 +667,7 @@ export function actionKey(a: Action): string {
|
|||
return `hw:${a.card}:${a.slot}`;
|
||||
case 'recruit':
|
||||
return `recruit:${a.card}:${a.slot}`;
|
||||
case 'buyAvatar':
|
||||
case 'buyAnomaly':
|
||||
return `buy:${a.slot}`;
|
||||
case 'installProgram':
|
||||
return `prog:${a.card}:${a.at}`;
|
||||
|
|
@ -701,7 +702,7 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
const p = decider(s)!;
|
||||
const me = s.players[p];
|
||||
const who = playerName(p);
|
||||
const ref = (slot: number): AvatarRef => ({ player: p, slot });
|
||||
const ref = (slot: number): AnomalyRef => ({ player: p, slot });
|
||||
|
||||
switch (a.type) {
|
||||
case 'end':
|
||||
|
|
@ -717,69 +718,70 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
const ch = s.choice!;
|
||||
const option = ch.options[a.index];
|
||||
s.choice = null;
|
||||
say(s, `${who} chooses: ${option.label}.`);
|
||||
const secret = ch.secret ? { to: p, public: `${who} makes a secret choice (${ch.kind.split(':')[0]}).` } : {};
|
||||
say(s, `${who} chooses: ${option.label}.`, { tag: 'choice', player: p, ...secret });
|
||||
const fn = scriptOf(ch.resume.name)?.resume?.[ch.resume.fn];
|
||||
if (!fn) throw new Error(`No resume ${ch.resume.name}.${ch.resume.fn}`);
|
||||
fn(s, ch.resume.data, option.value);
|
||||
break;
|
||||
}
|
||||
case 'buyAvatar': {
|
||||
const { price } = avatarForSale(s, p)!;
|
||||
const av = me.avatars[a.slot - 1];
|
||||
me.ram -= price;
|
||||
stat(s, 'ramOnAvatars', p, price);
|
||||
stat(s, 'avatarsBought', p);
|
||||
case 'buyAnomaly': {
|
||||
const { price } = anomalyForSale(s, p)!;
|
||||
const av = me.anomalies[a.slot - 1];
|
||||
me.bandwidth -= price;
|
||||
stat(s, 'bandwidthOnAnomalies', p, price);
|
||||
stat(s, 'anomaliesBought', p);
|
||||
av.faceUp = true;
|
||||
say(s, `${who} buys Avatar ${a.slot}: ${nameOf(s, av.card)} (-${price} RAM, now ${me.ram}).`);
|
||||
say(s, `${who} buys Anomaly ${a.slot}: ${nameOf(s, av.card)} (-${price} Gb, now ${me.bandwidth}).`, { tag: 'card', player: p });
|
||||
break;
|
||||
}
|
||||
case 'recruit': {
|
||||
const cost = defOf(s, a.card).ram;
|
||||
const av = me.avatars[a.slot - 1];
|
||||
if (av.card >= 0) retireAvatar(s, ref(a.slot));
|
||||
const cost = defOf(s, a.card).bandwidth;
|
||||
const av = me.anomalies[a.slot - 1];
|
||||
if (av.card >= 0) retireAnomaly(s, ref(a.slot));
|
||||
removeFrom(me.hand, a.card);
|
||||
me.ram -= cost;
|
||||
stat(s, 'ramOnCards', p, cost);
|
||||
stat(s, 'avatarsRecruited', p);
|
||||
me.bandwidth -= cost;
|
||||
stat(s, 'bandwidthOnCards', p, cost);
|
||||
stat(s, 'anomaliesRecruited', p);
|
||||
played(s, nameOf(s, a.card), p);
|
||||
Object.assign(av, newAvatar(a.card, true, null));
|
||||
me.avatars[a.slot + 3].card = a.card;
|
||||
say(s, `${who} recruits ${nameOf(s, a.card)} as Avatar ${a.slot} (-${cost} RAM, now ${me.ram}).`);
|
||||
Object.assign(av, newAnomaly(a.card, true, null));
|
||||
me.anomalies[a.slot + 3].card = a.card;
|
||||
say(s, `${who} recruits ${nameOf(s, a.card)} as Anomaly ${a.slot} (-${cost} Gb, now ${me.bandwidth}).`, { tag: 'card', player: p });
|
||||
break;
|
||||
}
|
||||
case 'salvage': {
|
||||
const gain = defOf(s, a.card).ram;
|
||||
const gain = defOf(s, a.card).bandwidth;
|
||||
removeFrom(me.hand, a.card);
|
||||
toDiscard(s, a.card);
|
||||
me.ram += gain;
|
||||
stat(s, 'ramFromSalvage', p, gain);
|
||||
me.bandwidth += gain;
|
||||
stat(s, 'bandwidthFromSalvage', p, gain);
|
||||
stat(s, 'cardsSalvaged', p);
|
||||
say(s, `${who} salvages ${nameOf(s, a.card)} (+${gain} RAM, now ${me.ram}).`);
|
||||
say(s, `${who} salvages ${nameOf(s, a.card)} (+${gain} Gb, now ${me.bandwidth}).`, { tag: 'card', player: p });
|
||||
break;
|
||||
}
|
||||
case 'place': {
|
||||
const av = me.avatars[a.slot - 1];
|
||||
const av = me.anomalies[a.slot - 1];
|
||||
say(s, av.at === null
|
||||
? `${who} places ${avatarName(s, ref(a.slot))} on ${a.to}.`
|
||||
: `${who} moves ${avatarName(s, ref(a.slot))} ${av.at} → ${a.to}.`);
|
||||
? `${who} places ${anomalyName(s, ref(a.slot))} on ${a.to}.`
|
||||
: `${who} moves ${anomalyName(s, ref(a.slot))} ${av.at} → ${a.to}.`, { tag: 'move', player: p, loc: a.to, ref: ref(a.slot) });
|
||||
av.at = a.to;
|
||||
av.placed = true;
|
||||
break;
|
||||
}
|
||||
case 'recall':
|
||||
recallAvatar(s, ref(a.slot));
|
||||
recallAnomaly(s, ref(a.slot));
|
||||
break;
|
||||
case 'advance':
|
||||
case 'attack': {
|
||||
const r = ref(a.slot);
|
||||
const av = avatar(s, r);
|
||||
const av = anomaly(s, r);
|
||||
const second = a.type === 'attack' && av.attacks > 0;
|
||||
if (a.type === 'advance') av.advanced = true;
|
||||
else av.attacks++;
|
||||
s.declarations.push({ kind: a.type, ref: r, to: a.to, from: av.at!, second });
|
||||
say(s, a.type === 'advance'
|
||||
? `${who}: ${avatarName(s, r)} advances to ${a.to}.`
|
||||
: `${who}: ${avatarName(s, r)} attacks ${a.to} from ${av.at}${second ? ' (Infinite Loop)' : ''}.`);
|
||||
? `${who}: ${anomalyName(s, r)} advances to ${a.to}.`
|
||||
: `${who}: ${anomalyName(s, r)} attacks ${a.to} from ${av.at}${second ? ' (Infinite Loop)' : ''}.`, { tag: 'move', player: p, loc: a.to, ref: r });
|
||||
respondTo(s, p, s.stack.length);
|
||||
if (a.type === 'attack') emit(s, 'onAttackDeclared', { ref: r, to: a.to });
|
||||
break;
|
||||
|
|
@ -787,44 +789,44 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
case 'clearFirewall': {
|
||||
const level = s.firewalls[a.line];
|
||||
const cost = firewallCost(s, level);
|
||||
me.ram -= cost;
|
||||
stat(s, 'ramOnFirewalls', p, cost);
|
||||
me.bandwidth -= cost;
|
||||
stat(s, 'bandwidthOnFirewalls', p, cost);
|
||||
delete s.firewalls[a.line];
|
||||
stat(s, 'firewallsCleared', p);
|
||||
say(s, `${who} clears the Lv ${level} Firewall on ${a.line} (-${cost} RAM).`);
|
||||
say(s, `${who} clears the Lv ${level} Firewall on ${a.line} (-${cost} Gb).`, { tag: 'firewall', player: p });
|
||||
break;
|
||||
}
|
||||
case 'firewall': {
|
||||
const before = s.firewalls[a.line] ?? 0;
|
||||
const cost = pay(s, { kind: 'firewall', player: p, line: a.line, level: a.level }, 'ramOnFirewalls');
|
||||
const cost = pay(s, { kind: 'firewall', player: p, line: a.line, level: a.level }, 'bandwidthOnFirewalls');
|
||||
s.firewalls[a.line] = a.level;
|
||||
stat(s, before ? 'firewallsUpgraded' : 'firewallsPlaced', p);
|
||||
say(s, before
|
||||
? `${who} upgrades the Firewall on ${a.line} to Lv ${a.level} (-${cost} RAM).`
|
||||
: `${who} places a Lv ${a.level} Firewall on ${a.line} (-${cost} RAM).`);
|
||||
? `${who} upgrades the Firewall on ${a.line} to Lv ${a.level} (-${cost} Gb).`
|
||||
: `${who} places a Lv ${a.level} Firewall on ${a.line} (-${cost} Gb).`, { tag: 'firewall', player: p });
|
||||
break;
|
||||
}
|
||||
case 'installHardware': {
|
||||
const r = ref(a.slot);
|
||||
const cost = pay(s, { kind: 'hardware', player: p, card: a.card, ref: r, at: avatar(s, r).at }, 'ramOnCards');
|
||||
const cost = pay(s, { kind: 'hardware', player: p, card: a.card, ref: r, at: anomaly(s, r).at }, 'bandwidthOnCards');
|
||||
removeFrom(me.hand, a.card);
|
||||
avatar(s, r).hardware.push(a.card);
|
||||
anomaly(s, r).hardware.push(a.card);
|
||||
s.cards[a.card].installedTurn = s.turn;
|
||||
stat(s, 'hardwareInstalled', p);
|
||||
played(s, nameOf(s, a.card), p);
|
||||
say(s, `${who} installs ${nameOf(s, a.card)} on ${avatarName(s, r)} (-${cost} RAM).`);
|
||||
say(s, `${who} installs ${nameOf(s, a.card)} on ${anomalyName(s, r)} (-${cost} Gb).`, { tag: 'card', player: p, ref: r, loc: anomaly(s, r).at ?? undefined });
|
||||
respondTo(s, p, s.stack.length);
|
||||
emit(s, 'onInstall', { card: a.card, at: avatar(s, r).at, ref: r });
|
||||
emit(s, 'onInstall', { card: a.card, at: anomaly(s, r).at, ref: r });
|
||||
break;
|
||||
}
|
||||
case 'installProgram': {
|
||||
const cost = pay(s, { kind: 'program', player: p, card: a.card, at: a.at }, 'ramOnCards');
|
||||
const cost = pay(s, { kind: 'program', player: p, card: a.card, at: a.at }, 'bandwidthOnCards');
|
||||
removeFrom(me.hand, a.card);
|
||||
s.locations[a.at].programs.push(a.card);
|
||||
s.cards[a.card].installedTurn = s.turn;
|
||||
stat(s, 'programsInstalled', p);
|
||||
played(s, nameOf(s, a.card), p);
|
||||
say(s, `${who} installs ${nameOf(s, a.card)} on ${a.at} (-${cost} RAM).`);
|
||||
say(s, `${who} installs ${nameOf(s, a.card)} on ${a.at} (-${cost} Gb).`, { tag: 'card', player: p, loc: a.at });
|
||||
respondTo(s, p, s.stack.length);
|
||||
emit(s, 'onInstall', { card: a.card, at: a.at, ref: null });
|
||||
break;
|
||||
|
|
@ -832,7 +834,7 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
case 'play': {
|
||||
const name = nameOf(s, a.card);
|
||||
const hostile = executionHostiles(s, { player: p, target: a.target, args: a.args, name });
|
||||
const cost = pay(s, { kind: 'execution', player: p, card: a.card, at: a.target, hostile }, 'ramOnCards');
|
||||
const cost = pay(s, { kind: 'execution', player: p, card: a.card, at: a.target, hostile }, 'bandwidthOnCards');
|
||||
removeFrom(me.hand, a.card);
|
||||
const item: StackItem = {
|
||||
kind: 'execution', player: p, card: a.card, name, target: a.target, args: a.args, from: a.from,
|
||||
|
|
@ -842,7 +844,7 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
if (item.power > 0) fired(s, 'Dedicated GPU', p);
|
||||
stat(s, 'executionsPlayed', p);
|
||||
played(s, name, p);
|
||||
say(s, `${who} plays ${name}${a.target ? ` on ${a.target}` : ''}${a.from ? ` from ${a.from}` : ''} (-${cost} RAM).`);
|
||||
say(s, `${who} plays ${name}${a.target ? ` on ${a.target}` : ''}${a.from ? ` from ${a.from}` : ''} (-${cost} Gb).`, { tag: 'card', player: p, loc: a.target ?? undefined });
|
||||
respondTo(s, p, s.stack.length - 1);
|
||||
if (hostile.length) pushTasks(s, { t: 'call', name: 'False Positive', fn: 'offer', data: { index: s.stack.length - 1 } });
|
||||
break;
|
||||
|
|
@ -850,15 +852,15 @@ export function applyAction(s: GameState, a: Action, legal: Action[] = legalActi
|
|||
case 'activate': {
|
||||
const src = abilitySource(s, a.card, a.name)!;
|
||||
const cost = abilityCost(s, src) + (scriptOf(src.name)!.ability!.extraCost?.(s, src, a.args) ?? 0);
|
||||
me.ram -= cost;
|
||||
stat(s, 'ramOnAbilities', p, cost);
|
||||
me.bandwidth -= cost;
|
||||
stat(s, 'bandwidthOnAbilities', p, cost);
|
||||
if (src.kind === 'hardware') useHardware(s, src.id);
|
||||
else markUsed(s, abilityKey(src));
|
||||
const label = src.kind === 'avatar' ? `${defOf(s, src.id).ability!.name} (${src.name})` : src.name;
|
||||
const label = src.kind === 'anomaly' ? `${defOf(s, src.id).ability!.name} (${src.name})` : src.name;
|
||||
s.stack.push({ kind: 'ability', player: p, card: src.id, name: src.name, target: null, args: a.args, from: null, power: 0 });
|
||||
stat(s, 'abilitiesUsed', p);
|
||||
if (src.kind === 'avatar') played(s, src.name, p);
|
||||
say(s, `${who} uses ${label}${cost ? ` (-${cost} RAM)` : ''}.`);
|
||||
if (src.kind === 'anomaly') played(s, src.name, p);
|
||||
say(s, `${who} uses ${label}${cost ? ` (-${cost} Gb)` : ''}.`, { tag: 'card', player: p, loc: src.at ?? undefined, ref: src.ref });
|
||||
respondTo(s, p, s.stack.length - 1);
|
||||
break;
|
||||
}
|
||||
|
|
@ -999,7 +1001,7 @@ function execute(s: GameState, task: Task): void {
|
|||
|
||||
/**
|
||||
* What player `p` can see. Hidden cards become -1: the opponent's hand, both decks and Server
|
||||
* piles, and face-down Avatars. The RNG is blanked so bots can't predict dice, the opponent's
|
||||
* piles, and face-down Anomalies. The RNG is blanked so bots can't predict dice, the opponent's
|
||||
* choices are hidden, and only open windows are kept from the task queue. Everything else is
|
||||
* shared with the real state, so treat a view as read-only.
|
||||
*/
|
||||
|
|
@ -1011,9 +1013,15 @@ export function viewFor(s: GameState, p: PlayerId): GameState {
|
|||
deck: hide(pl.deck),
|
||||
serverPile: hide(pl.serverPile),
|
||||
discard: [...pl.discard],
|
||||
avatars: pl.avatars.map((av) => ({ ...av, hardware: [...av.hardware], card: av.faceUp ? av.card : -1 })),
|
||||
anomalies: pl.anomalies.map((av) => ({ ...av, hardware: [...av.hardware], card: av.faceUp ? av.card : -1 })),
|
||||
}));
|
||||
const choice = s.choice && s.choice.player !== p ? { ...s.choice, options: s.choice.options.map(() => ({ label: '?', value: null })) } : s.choice;
|
||||
const choice = s.choice && s.choice.player !== p
|
||||
? {
|
||||
...s.choice,
|
||||
prompt: s.choice.secret ? `${s.choice.kind.split(':')[0]}: ${playerName(s.choice.player)} is choosing.` : s.choice.prompt,
|
||||
options: s.choice.options.map(() => ({ label: '?', value: null })),
|
||||
}
|
||||
: s.choice;
|
||||
const combat = s.combat ? { ...s.combat, race: s.combat.race.map((r, i) => (i === p ? r : null)) as typeof s.combat.race } : null;
|
||||
return {
|
||||
...s,
|
||||
|
|
|
|||
191
sim/src/flow.ts
191
sim/src/flow.ts
|
|
@ -1,24 +1,24 @@
|
|||
/**
|
||||
* The parts of a turn that run on their own once started: resolving declarations, combat,
|
||||
* defeat, capture and drawing. Card scripts call into these too (Trace Route starts a combat,
|
||||
* Disconnect pulls an Avatar out of one).
|
||||
* Disconnect pulls an Anomaly out of one).
|
||||
*/
|
||||
import { isStart, levelFor, type LocId } from './map.ts';
|
||||
import { scriptOf } from './scripts.ts';
|
||||
import { coresOf, emit, fighterOf, hardwareActive, healthLeft, healthOf, sideCores } from './query.ts';
|
||||
import {
|
||||
adjacent,
|
||||
avatar,
|
||||
avatarName,
|
||||
anomaly,
|
||||
anomalyName,
|
||||
controls,
|
||||
copyOf,
|
||||
defendersAt,
|
||||
fightersOf,
|
||||
fired,
|
||||
gainRam,
|
||||
gainBandwidth,
|
||||
gridCount,
|
||||
isCopy,
|
||||
isDisabledAvatar,
|
||||
isDisabledAnomaly,
|
||||
isRooted,
|
||||
nameOf,
|
||||
neighbors,
|
||||
|
|
@ -35,7 +35,7 @@ import {
|
|||
stat,
|
||||
toDiscard,
|
||||
} from './state.ts';
|
||||
import type { AvatarRef, AvatarState, CaptureStat, Combat, GameState, PlayerId, Task } from './types.ts';
|
||||
import type { AnomalyRef, AnomalyState, CaptureStat, Combat, GameState, PlayerId, Task } from './types.ts';
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Drawing
|
||||
|
|
@ -60,9 +60,9 @@ export function drawTask(s: GameState, p: PlayerId): void {
|
|||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Avatars leaving and entering play
|
||||
// Anomalies leaving and entering play
|
||||
|
||||
function clearStatus(av: AvatarState): void {
|
||||
function clearStatus(av: AnomalyState): void {
|
||||
av.infection = 0;
|
||||
av.bugs = 0;
|
||||
av.mods = [];
|
||||
|
|
@ -72,10 +72,10 @@ function clearStatus(av: AvatarState): void {
|
|||
}
|
||||
|
||||
/** A copy leaves play. It has no Hardware of its own. */
|
||||
export function removeCopy(s: GameState, ref: AvatarRef): void {
|
||||
const cp = avatar(s, ref);
|
||||
export function removeCopy(s: GameState, ref: AnomalyRef): void {
|
||||
const cp = anomaly(s, ref);
|
||||
if (cp.at === null) return;
|
||||
say(s, `${avatarName(s, ref)} is removed.`);
|
||||
say(s, `${anomalyName(s, ref)} is removed.`, { tag: 'move', player: ref.player, ref });
|
||||
clearStatus(cp);
|
||||
cp.permanentInfection = 0;
|
||||
cp.at = null;
|
||||
|
|
@ -83,53 +83,53 @@ export function removeCopy(s: GameState, ref: AvatarRef): void {
|
|||
dropFromCombat(s, ref);
|
||||
}
|
||||
|
||||
/** Recruit rule: an Avatar recruited over leaves for the discard pile with its Hardware, and its copy leaves play. */
|
||||
export function retireAvatar(s: GameState, ref: AvatarRef): void {
|
||||
const av = avatar(s, ref);
|
||||
/** Recruit rule: an Anomaly recruited over leaves for the discard pile with its Hardware, and its copy leaves play. */
|
||||
export function retireAnomaly(s: GameState, ref: AnomalyRef): void {
|
||||
const av = anomaly(s, ref);
|
||||
removeCopy(s, copyOf(ref));
|
||||
if (av.hardware.length) stat(s, 'hardwareLost', ref.player, av.hardware.length);
|
||||
for (const hw of av.hardware) toDiscard(s, hw);
|
||||
say(s, `${playerName(ref.player)} retires ${avatarName(s, ref)}${av.at ? ` from ${av.at}` : ''}.`);
|
||||
say(s, `${playerName(ref.player)} retires ${anomalyName(s, ref)}${av.at ? ` from ${av.at}` : ''}.`, { tag: 'card', player: ref.player, ref });
|
||||
dropFromCombat(s, ref);
|
||||
toDiscard(s, av.card);
|
||||
stat(s, 'avatarsRetired', ref.player);
|
||||
stat(s, 'anomaliesRetired', ref.player);
|
||||
}
|
||||
|
||||
/**
|
||||
* The loser of a combat goes back to its slot. Its Hardware is discarded unless `keepHardware`,
|
||||
* and its counters and effects are removed (Persistent Infection's counters stay).
|
||||
*/
|
||||
export function knockOut(s: GameState, ref: AvatarRef, loc: LocId, role: 'attack' | 'defend', keepHardware: boolean): void {
|
||||
const av = avatar(s, ref);
|
||||
export function knockOut(s: GameState, ref: AnomalyRef, loc: LocId, role: 'attack' | 'defend', keepHardware: boolean): void {
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null) return;
|
||||
if (isCopy(ref)) {
|
||||
removeCopy(s, ref);
|
||||
} else {
|
||||
if (!keepHardware && av.hardware.length) {
|
||||
say(s, `${playerName(ref.player)} loses ${av.hardware.map((h) => nameOf(s, h)).join(', ')}.`);
|
||||
say(s, `${playerName(ref.player)} loses ${av.hardware.map((h) => nameOf(s, h)).join(', ')}.`, { tag: 'combat', player: ref.player, ref, loc });
|
||||
stat(s, 'hardwareLost', ref.player, av.hardware.length);
|
||||
for (const hw of av.hardware) toDiscard(s, hw);
|
||||
av.hardware = [];
|
||||
}
|
||||
clearStatus(av);
|
||||
av.at = null;
|
||||
say(s, `${avatarName(s, ref)} returns to its slot.`);
|
||||
say(s, `${anomalyName(s, ref)} returns to its slot.`, { tag: 'combat', player: ref.player, ref, loc });
|
||||
removeCopy(s, copyOf(ref));
|
||||
}
|
||||
stat(s, 'avatarsDestroyed', ref.player);
|
||||
stat(s, 'anomaliesDestroyed', ref.player);
|
||||
emit(s, 'onDefeat', { ref, loc, role });
|
||||
}
|
||||
|
||||
/**
|
||||
* Health rule: an Avatar returns to its slot by its owner's choice, as its placement for the
|
||||
* Health rule: an Anomaly returns to its slot by its owner's choice, as its placement for the
|
||||
* round. It heals fully and keeps its Hardware; like a defeat, its counters and effects come off
|
||||
* (Persistent Infection's stay) and its copy leaves play.
|
||||
*/
|
||||
export function recallAvatar(s: GameState, ref: AvatarRef): void {
|
||||
const av = avatar(s, ref);
|
||||
export function recallAnomaly(s: GameState, ref: AnomalyRef): void {
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null) return;
|
||||
const healed = av.damage;
|
||||
say(s, `${playerName(ref.player)} recalls ${avatarName(s, ref)} from ${av.at} to its slot${healed ? `, healing ${healed} damage` : ''}.`);
|
||||
say(s, `${playerName(ref.player)} recalls ${anomalyName(s, ref)} from ${av.at} to its slot${healed ? `, healing ${healed} damage` : ''}.`, { tag: 'move', player: ref.player, ref, loc: av.at });
|
||||
clearStatus(av);
|
||||
av.at = null;
|
||||
av.placed = true;
|
||||
|
|
@ -138,11 +138,11 @@ export function recallAvatar(s: GameState, ref: AvatarRef): void {
|
|||
}
|
||||
|
||||
/** Places a copy of `original` on `to`. */
|
||||
export function createCopy(s: GameState, original: AvatarRef, to: LocId): void {
|
||||
export function createCopy(s: GameState, original: AnomalyRef, to: LocId): void {
|
||||
const ref = copyOf(original);
|
||||
const cp = avatar(s, ref);
|
||||
const cp = anomaly(s, ref);
|
||||
Object.assign(cp, {
|
||||
card: avatar(s, original).card,
|
||||
card: anomaly(s, original).card,
|
||||
faceUp: true,
|
||||
at: to,
|
||||
hardware: [],
|
||||
|
|
@ -158,14 +158,14 @@ export function createCopy(s: GameState, original: AvatarRef, to: LocId): void {
|
|||
rootedUntil: 0,
|
||||
breachedTurn: 0,
|
||||
createdTurn: s.turn,
|
||||
} satisfies Partial<AvatarState>);
|
||||
say(s, `${playerName(ref.player)} creates ${avatarName(s, ref)} on ${to}.`);
|
||||
} satisfies Partial<AnomalyState>);
|
||||
say(s, `${playerName(ref.player)} creates ${anomalyName(s, ref)} on ${to}.`, { tag: 'card', player: ref.player, ref, loc: to });
|
||||
}
|
||||
|
||||
/** Moves an Avatar by a card effect. Callers check the move is legal. */
|
||||
export function moveAvatar(s: GameState, ref: AvatarRef, to: LocId): void {
|
||||
const av = avatar(s, ref);
|
||||
say(s, `${avatarName(s, ref)} moves ${av.at} → ${to}.`);
|
||||
/** Moves an Anomaly by a card effect. Callers check the move is legal. */
|
||||
export function moveAnomaly(s: GameState, ref: AnomalyRef, to: LocId): void {
|
||||
const av = anomaly(s, ref);
|
||||
say(s, `${anomalyName(s, ref)} moves ${av.at} → ${to}.`, { tag: 'move', player: ref.player, ref, loc: to });
|
||||
av.at = to;
|
||||
}
|
||||
|
||||
|
|
@ -175,11 +175,11 @@ export function moveAvatar(s: GameState, ref: AvatarRef, to: LocId): void {
|
|||
export function resolveDeclaration(s: GameState, index: number): void {
|
||||
const d = s.declarations[index];
|
||||
const p = d.ref.player;
|
||||
const av = avatar(s, d.ref);
|
||||
const who = avatarName(s, d.ref);
|
||||
const av = anomaly(s, d.ref);
|
||||
const who = anomalyName(s, d.ref);
|
||||
if (av.at === null) return;
|
||||
if (isRooted(s, d.ref) || isDisabledAvatar(s, d.ref)) {
|
||||
say(s, `${who} can't move, so its ${d.kind} on ${d.to} fails.`);
|
||||
if (isRooted(s, d.ref) || isDisabledAnomaly(s, d.ref)) {
|
||||
say(s, `${who} can't move, so its ${d.kind} on ${d.to} fails.`, { tag: 'move', player: p, ref: d.ref, loc: d.to });
|
||||
return;
|
||||
}
|
||||
if (controls(s, p, d.to)) return;
|
||||
|
|
@ -187,7 +187,7 @@ export function resolveDeclaration(s: GameState, index: number): void {
|
|||
const how: CaptureStat = s.locations[d.to].owner === null ? 'capturesUnowned' : 'capturesUndefended';
|
||||
if (d.kind === 'advance') {
|
||||
if (!neighbors(s, d.to).some((n) => controls(s, p, n))) {
|
||||
say(s, `${who} can no longer reach ${d.to}.`);
|
||||
say(s, `${who} can no longer reach ${d.to}.`, { tag: 'move', player: p, ref: d.ref, loc: d.to });
|
||||
return;
|
||||
}
|
||||
if (defended) startCombat(s, d.ref, av.at, d.to, 'advance');
|
||||
|
|
@ -195,7 +195,7 @@ export function resolveDeclaration(s: GameState, index: number): void {
|
|||
return;
|
||||
}
|
||||
if ((!d.second && av.at !== d.from) || !controls(s, p, d.from) || !adjacent(s, d.from, d.to)) {
|
||||
say(s, `${who}'s attack on ${d.to} fails: it's no longer in position.`);
|
||||
say(s, `${who}'s attack on ${d.to} fails: it's no longer in position.`, { tag: 'move', player: p, ref: d.ref, loc: d.to });
|
||||
return;
|
||||
}
|
||||
if (defended) startCombat(s, d.ref, d.from, d.to, 'attack');
|
||||
|
|
@ -216,7 +216,7 @@ function sideTotals(c: Combat): { atk: number; def: number } {
|
|||
}
|
||||
|
||||
function diceText(s: GameState, c: Combat): string {
|
||||
const one = (r: AvatarRef) => `${nameOf(s, avatar(s, r).card)} [${(c.dice[refKey(r)] ?? []).join(',')}]`;
|
||||
const one = (r: AnomalyRef) => `${nameOf(s, anomaly(s, r).card)} [${(c.dice[refKey(r)] ?? []).join(',')}]`;
|
||||
const t = sideTotals(c);
|
||||
return `${one(c.attacker)}=${t.atk} vs ${c.defenders.map(one).join(' + ')}=${t.def}`;
|
||||
}
|
||||
|
|
@ -236,15 +236,15 @@ function rollAll(s: GameState, c: Combat): void {
|
|||
// Damage (health rule)
|
||||
|
||||
/** Health text for the combat log, e.g. "7/10 Health". */
|
||||
export const healthText = (s: GameState, r: AvatarRef): string => `${healthLeft(s, r)}/${healthOf(s, r)} Health`;
|
||||
export const healthText = (s: GameState, r: AnomalyRef): string => `${healthLeft(s, r)}/${healthOf(s, r)} Health`;
|
||||
|
||||
/** Deals `n` damage to an Avatar. Returns true if that destroys it (its damage reaches its Health). */
|
||||
export function damageAvatar(s: GameState, ref: AvatarRef, n: number): boolean {
|
||||
const av = avatar(s, ref);
|
||||
/** Deals `n` damage to an Anomaly. Returns true if that destroys it (its damage reaches its Health). */
|
||||
export function damageAnomaly(s: GameState, ref: AnomalyRef, n: number): boolean {
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null || n <= 0) return false;
|
||||
av.damage += n;
|
||||
const dead = av.damage >= healthOf(s, ref);
|
||||
say(s, `${avatarName(s, ref)} takes ${n} damage${dead ? ' and is destroyed' : ` (${healthText(s, ref)})`}.`);
|
||||
say(s, `${anomalyName(s, ref)} takes ${n} damage${dead ? ' and is destroyed' : ` (${healthText(s, ref)})`}.`, { tag: 'combat', player: ref.player, ref, amount: n, loc: av.at });
|
||||
return dead;
|
||||
}
|
||||
|
||||
|
|
@ -253,9 +253,9 @@ export function damageAvatar(s: GameState, ref: AvatarRef, n: number): boolean {
|
|||
* most defenders, weakest first, and puts what's left on the weakest survivor. Returns the
|
||||
* destroyed defenders.
|
||||
*/
|
||||
function allocateDamage(s: GameState, defenders: AvatarRef[], n: number): { ref: AvatarRef; amount: number; destroyed: boolean }[] {
|
||||
function allocateDamage(s: GameState, defenders: AnomalyRef[], n: number): { ref: AnomalyRef; amount: number; destroyed: boolean }[] {
|
||||
const order = [...defenders].sort((a, b) => healthLeft(s, a) - healthLeft(s, b));
|
||||
const hits: { ref: AvatarRef; amount: number; destroyed: boolean }[] = [];
|
||||
const hits: { ref: AnomalyRef; amount: number; destroyed: boolean }[] = [];
|
||||
for (const [i, d] of order.entries()) {
|
||||
if (n <= 0) break;
|
||||
const left = healthLeft(s, d);
|
||||
|
|
@ -263,35 +263,35 @@ function allocateDamage(s: GameState, defenders: AvatarRef[], n: number): { ref:
|
|||
if (hit === 0) {
|
||||
// Can't destroy this one: dump the rest on the weakest.
|
||||
const first = hits.find((h) => refKey(h.ref) === refKey(order[0]));
|
||||
damageAvatar(s, order[0], n);
|
||||
damageAnomaly(s, order[0], n);
|
||||
if (first) first.amount += n;
|
||||
else hits.push({ ref: order[0], amount: n, destroyed: false });
|
||||
break;
|
||||
}
|
||||
n -= hit;
|
||||
hits.push({ ref: d, amount: hit, destroyed: damageAvatar(s, d, hit) });
|
||||
hits.push({ ref: d, amount: hit, destroyed: damageAnomaly(s, d, hit) });
|
||||
}
|
||||
return hits;
|
||||
}
|
||||
|
||||
/** Tells the cards that an Avatar lost a roll (Resource Leech, Overflow Error, Persistent Infection). */
|
||||
function emitDamage(s: GameState, ref: AvatarRef, loc: LocId, role: 'attack' | 'defend', amount: number, destroyed: boolean): void {
|
||||
/** Tells the cards that an Anomaly lost a roll (Resource Leech, Overflow Error, Persistent Infection). */
|
||||
function emitDamage(s: GameState, ref: AnomalyRef, loc: LocId, role: 'attack' | 'defend', amount: number, destroyed: boolean): void {
|
||||
emit(s, 'onDamage', { ref, loc, role, amount, destroyed });
|
||||
}
|
||||
|
||||
/** Health rule: the loser of the roll takes the difference as damage; destroyed Avatars are defeated. */
|
||||
/** Health rule: the loser of the roll takes the difference as damage; destroyed Anomalies are defeated. */
|
||||
function resolveDamage(s: GameState, c: Combat, t: { atk: number; def: number }): void {
|
||||
if (t.atk === t.def) {
|
||||
c.ties++;
|
||||
stat(s, 'combatsTied', c.attacker.player);
|
||||
say(s, `Tie, ${t.atk} to ${t.def}: a stalemate. Nobody takes damage.`);
|
||||
say(s, `Tie, ${t.atk} to ${t.def}: a stalemate. Nobody takes damage.`, { tag: 'combat', loc: c.loc });
|
||||
return;
|
||||
}
|
||||
const margin = Math.abs(t.atk - t.def);
|
||||
const attackerWins = t.atk > t.def;
|
||||
const defender = s.locations[c.loc].owner!;
|
||||
const winner = attackerWins ? c.attacker.player : defender;
|
||||
say(s, `${playerName(winner)} wins the roll, ${t.atk} to ${t.def}: ${margin} damage.`);
|
||||
say(s, `${playerName(winner)} wins the roll, ${t.atk} to ${t.def}: ${margin} damage.`, { tag: 'combat', player: winner, loc: c.loc });
|
||||
stat(s, 'damageDealt', winner, margin);
|
||||
if (attackerWins) {
|
||||
stat(s, 'attacksWon', c.attacker.player);
|
||||
|
|
@ -300,12 +300,12 @@ function resolveDamage(s: GameState, c: Combat, t: { atk: number; def: number })
|
|||
const tasks: Task[] = destroyed.map((ref): Task => ({ t: 'defeat', ref, loc: c.loc, role: 'defend' }));
|
||||
if (destroyed.length === c.defenders.length) {
|
||||
tasks.push({ t: 'capture', ref: c.attacker, loc: c.loc, stage: 'hooks', how: 'capturesInCombat' });
|
||||
} else say(s, `${c.loc} holds.`);
|
||||
} else say(s, `${c.loc} holds.`, { tag: 'combat', player: defender, loc: c.loc });
|
||||
pushTasks(s, ...tasks);
|
||||
// Pushed last, so the damage hooks run before the defeats.
|
||||
for (const h of hits) emitDamage(s, h.ref, c.loc, 'defend', h.amount, h.destroyed);
|
||||
} else {
|
||||
const dead = damageAvatar(s, c.attacker, margin);
|
||||
const dead = damageAnomaly(s, c.attacker, margin);
|
||||
if (dead) pushTasks(s, { t: 'defeat', ref: c.attacker, loc: c.loc, role: 'attack' });
|
||||
emitDamage(s, c.attacker, c.loc, 'attack', margin, dead);
|
||||
}
|
||||
|
|
@ -313,7 +313,7 @@ function resolveDamage(s: GameState, c: Combat, t: { atk: number; def: number })
|
|||
|
||||
/**
|
||||
* Cores that change after the roll change the dice: each Core gained rolls one more die, and each
|
||||
* Core lost removes that Avatar's highest die.
|
||||
* Core lost removes that Anomaly's highest die.
|
||||
*/
|
||||
export function syncDice(s: GameState, c: Combat): void {
|
||||
if (!c.rolled) return;
|
||||
|
|
@ -343,18 +343,18 @@ export function endCombat(s: GameState, why: string): void {
|
|||
if (!c || c.ended) return;
|
||||
c.ended = true;
|
||||
stat(s, 'combatsEnded', c.attacker.player);
|
||||
say(s, `The combat at ${c.loc} ends: ${why}.`);
|
||||
say(s, `The combat at ${c.loc} ends: ${why}.`, { tag: 'combat', loc: c.loc });
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an Avatar out of the current combat. If the attacker leaves, the combat ends. If the last
|
||||
* Takes an Anomaly out of the current combat. If the attacker leaves, the combat ends. If the last
|
||||
* defender leaves, the attacker takes the location as undefended.
|
||||
*/
|
||||
export function dropFromCombat(s: GameState, ref: AvatarRef): void {
|
||||
export function dropFromCombat(s: GameState, ref: AnomalyRef): void {
|
||||
const c = s.combat;
|
||||
if (!c || c.ended) return;
|
||||
if (sameRef(c.attacker, ref)) {
|
||||
endCombat(s, `${avatarName(s, ref)} left it`);
|
||||
endCombat(s, `${anomalyName(s, ref)} left it`);
|
||||
return;
|
||||
}
|
||||
const i = c.defenders.findIndex((d) => sameRef(d, ref));
|
||||
|
|
@ -363,16 +363,32 @@ export function dropFromCombat(s: GameState, ref: AvatarRef): void {
|
|||
delete c.dice[refKey(ref)];
|
||||
if (c.defenders.length === 0) {
|
||||
endCombat(s, 'no defender is left');
|
||||
if (avatar(s, c.attacker).at !== null) pushCapture(s, c.attacker, c.loc, 'capturesUndefended');
|
||||
if (anomaly(s, c.attacker).at !== null) pushCapture(s, c.attacker, c.loc, 'capturesUndefended');
|
||||
}
|
||||
}
|
||||
|
||||
export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | 'end' | 'cleanup'): void {
|
||||
/** Combat stages an app can watch. */
|
||||
export type CombatStage = 'start' | 'roll' | 'result' | 'end';
|
||||
|
||||
/**
|
||||
* Lets an app see each combat as it happens, since a whole combat can run inside one applyAction.
|
||||
* Called after a combat starts, after the roll, before the result is applied (with the final dice),
|
||||
* and when it ends. Null in the sim.
|
||||
*/
|
||||
export const combatWatch: { fn: ((s: GameState, stage: CombatStage) => void) | null } = { fn: null };
|
||||
|
||||
export function combatStage(s: GameState, stage: CombatStage | 'cleanup'): void {
|
||||
const c = s.combat;
|
||||
if (!c) return;
|
||||
runStage(s, c, stage);
|
||||
// 'result' is watched inside runStage, before the damage.
|
||||
if (stage === 'start' || stage === 'roll' || stage === 'end') combatWatch.fn?.(s, stage);
|
||||
}
|
||||
|
||||
function runStage(s: GameState, c: Combat, stage: CombatStage | 'cleanup'): void {
|
||||
if (stage === 'cleanup') {
|
||||
for (const r of fightersOf(c)) {
|
||||
const av = avatar(s, r);
|
||||
const av = anomaly(s, r);
|
||||
av.mods = av.mods.filter((m) => m.combat !== c.id);
|
||||
}
|
||||
s.combat = null;
|
||||
|
|
@ -387,9 +403,9 @@ export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | '
|
|||
if (stage === 'start') {
|
||||
stat(s, 'attacks', c.attacker.player);
|
||||
const { atk, def } = sideCores(s);
|
||||
const hp = (r: AvatarRef) => (s.rules.health.on ? `, ${healthText(s, r)}` : '');
|
||||
const defs = c.defenders.map((d) => `${avatarName(s, d)}${hp(d)}`).join(' and ');
|
||||
say(s, `Combat at ${c.loc}: ${avatarName(s, c.attacker)} (${atk} Cores, from ${c.origin}${hp(c.attacker)}) vs ${defs} (${def} Cores).`);
|
||||
const hp = (r: AnomalyRef) => (s.rules.health.on ? `, ${healthText(s, r)}` : '');
|
||||
const defs = c.defenders.map((d) => `${anomalyName(s, d)}${hp(d)}`).join(' and ');
|
||||
say(s, `Combat at ${c.loc}: ${anomalyName(s, c.attacker)} (${atk} Cores, from ${c.origin}${hp(c.attacker)}) vs ${defs} (${def} Cores).`, { tag: 'combat', player: c.attacker.player, loc: c.loc, ref: c.attacker });
|
||||
emit(s, 'onCombatStart', null);
|
||||
return;
|
||||
}
|
||||
|
|
@ -405,16 +421,17 @@ export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | '
|
|||
});
|
||||
}
|
||||
rollAll(s, c);
|
||||
say(s, `Roll: ${diceText(s, c)}${c.ties ? ` after ${c.ties} tie reroll(s)` : ''}.`);
|
||||
say(s, `Roll: ${diceText(s, c)}${c.ties ? ` after ${c.ties} tie reroll(s)` : ''}.`, { tag: 'combat', loc: c.loc });
|
||||
return;
|
||||
}
|
||||
// result
|
||||
const t = combatTotals(s);
|
||||
combatWatch.fn?.(s, 'result');
|
||||
if (s.rules.health.on) return resolveDamage(s, c, t);
|
||||
if (t.atk === t.def) {
|
||||
c.ties++;
|
||||
rollAll(s, c);
|
||||
say(s, `Tie, so both sides reroll: ${diceText(s, c)}.`);
|
||||
say(s, `Tie, so both sides reroll: ${diceText(s, c)}.`, { tag: 'combat', loc: c.loc });
|
||||
pushTasks(
|
||||
s,
|
||||
{ t: 'window', kind: 'postRoll', priority: c.attacker.player, passes: 0, base: s.stack.length, resolving: false },
|
||||
|
|
@ -424,7 +441,7 @@ export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | '
|
|||
}
|
||||
const attackerWins = t.atk > t.def;
|
||||
const winner = attackerWins ? c.attacker.player : s.locations[c.loc].owner!;
|
||||
say(s, `${playerName(winner)} wins the combat, ${t.atk} to ${t.def}.`);
|
||||
say(s, `${playerName(winner)} wins the combat, ${t.atk} to ${t.def}.`, { tag: 'combat', player: winner, loc: c.loc });
|
||||
if (attackerWins) {
|
||||
stat(s, 'attacksWon', c.attacker.player);
|
||||
pushTasks(
|
||||
|
|
@ -443,8 +460,8 @@ export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | '
|
|||
// ---------------------------------------------------------------------------------------------
|
||||
// Defeat
|
||||
|
||||
export function defeat(s: GameState, ref: AvatarRef, loc: LocId, role: 'attack' | 'defend'): void {
|
||||
const av = avatar(s, ref);
|
||||
export function defeat(s: GameState, ref: AnomalyRef, loc: LocId, role: 'attack' | 'defend'): void {
|
||||
const av = anomaly(s, ref);
|
||||
if (av.at === null) return;
|
||||
if (!isCopy(ref)) {
|
||||
// Redundant Power Supply, then RAID Array, may save the Hardware.
|
||||
|
|
@ -461,23 +478,23 @@ export function defeat(s: GameState, ref: AvatarRef, loc: LocId, role: 'attack'
|
|||
// ---------------------------------------------------------------------------------------------
|
||||
// Capture
|
||||
|
||||
export function captureHooks(s: GameState, ref: AvatarRef, loc: LocId, how: CaptureStat): void {
|
||||
export function captureHooks(s: GameState, ref: AnomalyRef, loc: LocId, how: CaptureStat): void {
|
||||
const p = ref.player;
|
||||
if (avatar(s, ref).at === null || controls(s, p, loc) || isStart(loc)) return;
|
||||
if (anomaly(s, ref).at === null || controls(s, p, loc) || isStart(loc)) return;
|
||||
pushTasks(s, { t: 'capture', ref, loc, stage: 'main', how });
|
||||
const prev = s.locations[loc].owner;
|
||||
if (prev !== null && prev !== p) {
|
||||
avatar(s, ref).breachedTurn = s.turn;
|
||||
anomaly(s, ref).breachedTurn = s.turn;
|
||||
emit(s, 'onCaptured', { ref, loc });
|
||||
emit(s, 'onBreach', { ref, loc });
|
||||
}
|
||||
}
|
||||
|
||||
export function captureMain(s: GameState, ref: AvatarRef, loc: LocId, how: CaptureStat): void {
|
||||
export function captureMain(s: GameState, ref: AnomalyRef, loc: LocId, how: CaptureStat): void {
|
||||
const p = ref.player;
|
||||
const me = s.players[p];
|
||||
const L = s.locations[loc];
|
||||
if (avatar(s, ref).at === null || controls(s, p, loc)) return;
|
||||
if (anomaly(s, ref).at === null || controls(s, p, loc)) return;
|
||||
const previous = L.owner;
|
||||
if (L.server !== null) {
|
||||
resetCard(s, L.server);
|
||||
|
|
@ -488,25 +505,25 @@ export function captureMain(s: GameState, ref: AvatarRef, loc: LocId, how: Captu
|
|||
L.programs = [];
|
||||
L.owner = p;
|
||||
L.server = me.serverPile.shift() ?? null;
|
||||
avatar(s, ref).at = loc;
|
||||
anomaly(s, ref).at = loc;
|
||||
|
||||
const level = levelFor(p, loc);
|
||||
const turn1 = s.turn === 1 ? s.rules.firstTurn : null;
|
||||
const bonus = L.server === null ? 0 : (scriptOf(s.cards[L.server].name)?.ramOnPlace ?? 0);
|
||||
const ram = (turn1?.captureRam === false ? 0 : s.rules.levelRam[level]) + bonus;
|
||||
gainRam(s, p, ram, 'ramFromCaptures');
|
||||
const bonus = L.server === null ? 0 : (scriptOf(s.cards[L.server].name)?.bandwidthOnPlace ?? 0);
|
||||
const bandwidth = (turn1?.captureBandwidth === false ? 0 : s.rules.levelBandwidth[level]) + bonus;
|
||||
gainBandwidth(s, p, bandwidth, 'bandwidthFromCaptures');
|
||||
stat(s, how, p);
|
||||
const from = previous === null ? '' : ` from ${playerName(previous)}`;
|
||||
say(s, `${playerName(p)} captures ${loc}${from} (Lv ${level}) with ${L.server === null ? 'no Server' : nameOf(s, L.server)}: +${ram} RAM (now ${me.ram}).`);
|
||||
say(s, `${playerName(p)} captures ${loc}${from} (Lv ${level}) with ${L.server === null ? 'no Server' : nameOf(s, L.server)}: +${bandwidth} Gb (now ${me.bandwidth}).`, { tag: 'capture', player: p, loc });
|
||||
|
||||
const unlocks = !s.rules.recruit.on && !s.rules.buyAvatars.on;
|
||||
const unlocks = !s.rules.recruit.on && !s.rules.buyAnomalies.on;
|
||||
if (unlocks && level > me.unlockedLevel && turn1?.unlock !== false) {
|
||||
me.unlockedLevel = level;
|
||||
me.avatars.slice(0, 4).forEach((av, i) => {
|
||||
me.anomalies.slice(0, 4).forEach((av, i) => {
|
||||
if (i < level && !av.faceUp) {
|
||||
av.faceUp = true;
|
||||
av.unlockedTurn = s.turn;
|
||||
say(s, `${playerName(p)} unlocks Avatar ${i + 1}: ${nameOf(s, av.card)}.`);
|
||||
say(s, `${playerName(p)} unlocks Anomaly ${i + 1}: ${nameOf(s, av.card)}.`, { tag: 'capture', player: p, loc });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -514,7 +531,7 @@ export function captureMain(s: GameState, ref: AvatarRef, loc: LocId, how: Captu
|
|||
s.over = true;
|
||||
s.winner = p;
|
||||
s.endReason = 'win';
|
||||
say(s, `${playerName(p)} wins with ${gridCount(s, p)} locations.`);
|
||||
say(s, `${playerName(p)} wins with ${gridCount(s, p)} locations.`, { tag: 'game', player: p });
|
||||
return;
|
||||
}
|
||||
if (L.server !== null) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { LOCATIONS } from './map.ts';
|
||||
import { capacity, healthOf, portsTotal } from './query.ts';
|
||||
import { capacity, healthOf, slotsTotal } from './query.ts';
|
||||
import { scriptOf } from './scripts.ts';
|
||||
import { controls } from './state.ts';
|
||||
import type { GameState } from './types.ts';
|
||||
|
|
@ -25,37 +25,37 @@ export function checkInvariants(s: GameState): string[] {
|
|||
own(pl.deck, 'deck');
|
||||
own(pl.discard, 'discard');
|
||||
own(pl.serverPile, 'serverPile');
|
||||
if (pl.ram < 0) errors.push(`p${p} has ${pl.ram} RAM`);
|
||||
if (pl.bandwidth < 0) errors.push(`p${p} has ${pl.bandwidth} Gb`);
|
||||
const count = new Map<string, number>();
|
||||
pl.avatars.forEach((av, i) => {
|
||||
pl.anomalies.forEach((av, i) => {
|
||||
const slot = i + 1;
|
||||
const copy = slot > 4;
|
||||
if (!copy) {
|
||||
if (av.card >= 0 || !s.rules.recruit.on) own([av.card], `avatar${slot}`);
|
||||
if (av.card >= 0 || !s.rules.recruit.on) own([av.card], `anomaly${slot}`);
|
||||
else if (av.at !== null || av.hardware.length) errors.push(`p${p} empty slot ${slot} is in use`);
|
||||
own(av.hardware, `avatar${slot}.hardware`);
|
||||
const ported = av.hardware.filter((h) => !scriptOf(s.cards[h].name)?.noPort && s.cards[h].pushedUntil === undefined);
|
||||
if (av.card >= 0 && ported.length > portsTotal(s, { player: p as 0 | 1, slot })) errors.push(`p${p} Avatar ${slot} is over its slots`);
|
||||
own(av.hardware, `anomaly${slot}.hardware`);
|
||||
const ported = av.hardware.filter((h) => !scriptOf(s.cards[h].name)?.noSlot && s.cards[h].pushedUntil === undefined);
|
||||
if (av.card >= 0 && ported.length > slotsTotal(s, { player: p as 0 | 1, slot })) errors.push(`p${p} Anomaly ${slot} is over its slots`);
|
||||
} else {
|
||||
if (av.hardware.length) errors.push(`p${p} copy ${slot - 4} has Hardware of its own`);
|
||||
if (av.at !== null && pl.avatars[i - 4].at === null) errors.push(`p${p} copy ${slot - 4} is in play without its original`);
|
||||
if (av.card !== pl.avatars[i - 4].card) errors.push(`p${p} copy ${slot - 4} doesn't match its original`);
|
||||
if (av.at !== null && pl.anomalies[i - 4].at === null) errors.push(`p${p} copy ${slot - 4} is in play without its original`);
|
||||
if (av.card !== pl.anomalies[i - 4].card) errors.push(`p${p} copy ${slot - 4} doesn't match its original`);
|
||||
}
|
||||
if (av.damage < 0) errors.push(`p${p} Avatar ${slot} has negative damage`);
|
||||
if (av.damage < 0) errors.push(`p${p} Anomaly ${slot} has negative damage`);
|
||||
if (av.at === null) {
|
||||
if (av.damage !== 0) errors.push(`p${p} Avatar ${slot} is in its slot with ${av.damage} damage`);
|
||||
if (av.damage !== 0) errors.push(`p${p} Anomaly ${slot} is in its slot with ${av.damage} damage`);
|
||||
return;
|
||||
}
|
||||
if (!av.faceUp) errors.push(`p${p} Avatar ${slot} is in play face down`);
|
||||
// A destroyed Avatar may still stand there while its defeat is being resolved (RAID Array's choice).
|
||||
if (!av.faceUp) errors.push(`p${p} Anomaly ${slot} is in play face down`);
|
||||
// A destroyed Anomaly may still stand there while its defeat is being resolved (RAID Array's choice).
|
||||
const dying = s.choice !== null || s.tasks.some((t) => t.t === 'defeat' && t.ref.player === p && t.ref.slot === slot);
|
||||
if (s.rules.health.on && !dying && av.damage >= healthOf(s, { player: p as 0 | 1, slot })) errors.push(`p${p} Avatar ${slot} is in play with no Health left`);
|
||||
if (!controls(s, p as 0 | 1, av.at)) errors.push(`p${p} Avatar ${slot} is on ${av.at}, which it doesn't control`);
|
||||
if (s.rules.health.on && !dying && av.damage >= healthOf(s, { player: p as 0 | 1, slot })) errors.push(`p${p} Anomaly ${slot} is in play with no Health left`);
|
||||
if (!controls(s, p as 0 | 1, av.at)) errors.push(`p${p} Anomaly ${slot} is on ${av.at}, which it doesn't control`);
|
||||
count.set(av.at, (count.get(av.at) ?? 0) + 1);
|
||||
});
|
||||
for (const [loc, n] of count) if (n > capacity(s, loc)) errors.push(`p${p} has ${n} Avatars on ${loc}`);
|
||||
const total = pl.avatars.filter((av, i) => (i < 4 ? av.card >= 0 : av.at !== null)).length;
|
||||
if (s.rules.recruit.on && total > 4) errors.push(`p${p} has ${total} Avatars, counting copies`);
|
||||
for (const [loc, n] of count) if (n > capacity(s, loc)) errors.push(`p${p} has ${n} Anomalies on ${loc}`);
|
||||
const total = pl.anomalies.filter((av, i) => (i < 4 ? av.card >= 0 : av.at !== null)).length;
|
||||
if (s.rules.recruit.on && total > 4) errors.push(`p${p} has ${total} Anomalies, counting copies`);
|
||||
});
|
||||
|
||||
for (const loc of LOCATIONS) {
|
||||
|
|
|
|||
11
sim/src/load.ts
Normal file
11
sim/src/load.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/** Node-only card loading, for the CLI and tests. Browser code reads the CSV itself and calls parseCards. */
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { parseCards, type CardPool } from './cards.ts';
|
||||
|
||||
export const DEFAULT_CARDS_CSV = fileURLToPath(new URL('../../decks/files-deck-1/cards.csv', import.meta.url));
|
||||
|
||||
/** Loads the Cider deck CSV from disk. See parseCards for `sets`. */
|
||||
export function loadCards(path = DEFAULT_CARDS_CSV, sets: number[] | 'all' = [1]): CardPool {
|
||||
return parseCards(readFileSync(path, 'utf8'), sets, path);
|
||||
}
|
||||
132
sim/src/map.ts
132
sim/src/map.ts
|
|
@ -4,10 +4,6 @@ import type { PlayerId } from './types.ts';
|
|||
export type LocId = string;
|
||||
|
||||
export const START_LOC: readonly [LocId, LocId] = ['S1', 'S2'];
|
||||
export const GRID: readonly LocId[] = [
|
||||
'A1', 'A2', 'A3', 'B1', 'B2', 'C1', 'C2', 'C3', 'D1', 'D2', 'E1', 'E2', 'E3',
|
||||
];
|
||||
export const LOCATIONS: readonly LocId[] = [START_LOC[0], ...GRID, START_LOC[1]];
|
||||
|
||||
export interface Line {
|
||||
id: string;
|
||||
|
|
@ -17,44 +13,112 @@ export interface Line {
|
|||
gateway: boolean;
|
||||
}
|
||||
|
||||
const LINE_DEFS: [LocId, LocId, boolean][] = [
|
||||
['S1', 'A2', false],
|
||||
['A1', 'A2', true], ['A2', 'A3', true],
|
||||
['A1', 'B1', true], ['A2', 'B1', true], ['A2', 'B2', true], ['A3', 'B2', true],
|
||||
['B1', 'C1', true], ['B1', 'C2', true], ['B2', 'C2', true], ['B2', 'C3', true],
|
||||
['C1', 'D1', true], ['C2', 'D1', true], ['C2', 'D2', true], ['C3', 'D2', true],
|
||||
['D1', 'E1', true], ['D1', 'E2', true], ['D2', 'E2', true], ['D2', 'E3', true],
|
||||
['E1', 'E2', true], ['E2', 'E3', true],
|
||||
['S2', 'E2', false],
|
||||
];
|
||||
interface Board {
|
||||
/** Grid locations, row by row from South's side. The row is the letter: A is South's first row. */
|
||||
grid: LocId[];
|
||||
lines: [LocId, LocId, boolean][];
|
||||
/** Grid locations needed to win; `board=` sets winLocations to this. */
|
||||
win: number;
|
||||
}
|
||||
|
||||
export const LINES: readonly Line[] = LINE_DEFS.map(([a, b, gateway]) => ({
|
||||
id: `${a}-${b}`,
|
||||
a,
|
||||
b,
|
||||
gateway,
|
||||
}));
|
||||
/** The playmat in rules.md: rows of 3, 2, 3, 2, 3, entered from the middle of each end row. */
|
||||
const CLASSIC: Board = {
|
||||
grid: ['A1', 'A2', 'A3', 'B1', 'B2', 'C1', 'C2', 'C3', 'D1', 'D2', 'E1', 'E2', 'E3'],
|
||||
lines: [
|
||||
['S1', 'A2', false],
|
||||
['A1', 'A2', true], ['A2', 'A3', true],
|
||||
['A1', 'B1', true], ['A2', 'B1', true], ['A2', 'B2', true], ['A3', 'B2', true],
|
||||
['B1', 'C1', true], ['B1', 'C2', true], ['B2', 'C2', true], ['B2', 'C3', true],
|
||||
['C1', 'D1', true], ['C2', 'D1', true], ['C2', 'D2', true], ['C3', 'D2', true],
|
||||
['D1', 'E1', true], ['D1', 'E2', true], ['D2', 'E2', true], ['D2', 'E3', true],
|
||||
['E1', 'E2', true], ['E2', 'E3', true],
|
||||
['S2', 'E2', false],
|
||||
],
|
||||
win: 10,
|
||||
};
|
||||
|
||||
export const LINE_BY_ID: ReadonlyMap<string, Line> = new Map(LINES.map((l) => [l.id, l]));
|
||||
/**
|
||||
* A 4×4 grid of squares, rows A–D, columns 1–4, joined side to side (not diagonally), with a
|
||||
* gateway on every line between squares. Each start joins the listed squares of its first row;
|
||||
* North's are South's rotated 180°. Win with 12 of the 16.
|
||||
*/
|
||||
function squares(southEntries: number[]): Board {
|
||||
const rows = ['A', 'B', 'C', 'D'];
|
||||
const grid = rows.flatMap((r) => [1, 2, 3, 4].map((c) => `${r}${c}`));
|
||||
const lines: [LocId, LocId, boolean][] = southEntries.map((c) => ['S1', `A${c}`, false]);
|
||||
rows.forEach((r, i) => {
|
||||
for (let c = 1; c <= 4; c++) {
|
||||
if (c < 4) lines.push([`${r}${c}`, `${r}${c + 1}`, true]);
|
||||
if (i < 3) lines.push([`${r}${c}`, `${rows[i + 1]}${c}`, true]);
|
||||
}
|
||||
});
|
||||
for (const c of southEntries) lines.push(['S2', `D${5 - c}`, false]);
|
||||
return { grid, lines, win: 12 };
|
||||
}
|
||||
|
||||
export const LINES_AT: ReadonlyMap<LocId, readonly Line[]> = new Map(
|
||||
LOCATIONS.map((loc) => [loc, LINES.filter((l) => l.a === loc || l.b === loc)]),
|
||||
);
|
||||
/**
|
||||
* Three lanes of five rows, A–E, joined to each other only across the middle row (C1–C2–C3). Each
|
||||
* start joins the first location of every lane. With `laneGateways` false the lane lines can't be
|
||||
* firewalled, so only the two middle cross-links can. Win with 11 of the 15.
|
||||
*/
|
||||
function lanes(laneGateways: boolean): Board {
|
||||
const rows = ['A', 'B', 'C', 'D', 'E'];
|
||||
const grid = rows.flatMap((r) => [1, 2, 3].map((c) => `${r}${c}`));
|
||||
const lines: [LocId, LocId, boolean][] = [1, 2, 3].map((c) => ['S1', `A${c}`, false]);
|
||||
rows.slice(0, -1).forEach((r, i) => {
|
||||
for (let c = 1; c <= 3; c++) lines.push([`${r}${c}`, `${rows[i + 1]}${c}`, laneGateways]);
|
||||
});
|
||||
lines.push(['C1', 'C2', true], ['C2', 'C3', true]);
|
||||
for (let c = 1; c <= 3; c++) lines.push(['S2', `E${c}`, false]);
|
||||
return { grid, lines, win: 11 };
|
||||
}
|
||||
|
||||
export const BOARDS = {
|
||||
classic: CLASSIC,
|
||||
/** 4×4, each start joins the middle two squares of its first row. */
|
||||
grid4: squares([2, 3]),
|
||||
/** 4×4, each start joins all four squares of its first row. */
|
||||
'grid4-wide': squares([1, 2, 3, 4]),
|
||||
/** 4×4, each start joins one square: A2 for South, D3 for North. */
|
||||
'grid4-one': squares([2]),
|
||||
/** Three lanes, linked only across the middle row; every line between locations has a gateway. */
|
||||
lanes: lanes(true),
|
||||
/** Three lanes, but only the two middle cross-links can be firewalled. */
|
||||
'lanes-open': lanes(false),
|
||||
} satisfies Record<string, Board>;
|
||||
export type BoardName = keyof typeof BOARDS;
|
||||
|
||||
// The current board. createGame switches it with useBoard, so a process plays one board at a time.
|
||||
export let GRID: readonly LocId[];
|
||||
export let LOCATIONS: readonly LocId[];
|
||||
export let LINES: readonly Line[];
|
||||
export let LINE_BY_ID: ReadonlyMap<string, Line>;
|
||||
export let LINES_AT: ReadonlyMap<LocId, readonly Line[]>;
|
||||
let rowCount = 0;
|
||||
|
||||
export function useBoard(name: BoardName): void {
|
||||
const board: Board | undefined = BOARDS[name];
|
||||
if (!board) throw new Error(`Unknown board "${name}". Boards: ${Object.keys(BOARDS).join(', ')}`);
|
||||
GRID = board.grid;
|
||||
LOCATIONS = [START_LOC[0], ...GRID, START_LOC[1]];
|
||||
LINES = board.lines.map(([a, b, gateway]) => ({ id: `${a}-${b}`, a, b, gateway }));
|
||||
LINE_BY_ID = new Map(LINES.map((l) => [l.id, l]));
|
||||
LINES_AT = new Map(LOCATIONS.map((loc) => [loc, LINES.filter((l) => l.a === loc || l.b === loc)]));
|
||||
rowCount = new Set(GRID.map((loc) => loc[0])).size;
|
||||
}
|
||||
useBoard('classic');
|
||||
|
||||
export const otherEnd = (line: Line, loc: LocId): LocId => (line.a === loc ? line.b : line.a);
|
||||
|
||||
export const isStart = (loc: LocId): boolean => loc === START_LOC[0] || loc === START_LOC[1];
|
||||
|
||||
/** Level by row letter, from each player's side of the mat: your first row is Lv 1, the far row Lv 5. */
|
||||
const LEVEL_BY_ROW: readonly [Record<string, number>, Record<string, number>] = [
|
||||
{ A: 1, B: 2, C: 3, D: 4, E: 5 },
|
||||
{ A: 5, B: 4, C: 3, D: 2, E: 1 },
|
||||
];
|
||||
|
||||
/** A location's level for the player capturing it. Your own start is Lv 1. */
|
||||
/**
|
||||
* A location's level for the player capturing it: your first row is Lv 1, counting up to the far
|
||||
* row (Lv 5 on the classic board, Lv 4 on the 4×4 ones). Your own start is Lv 1.
|
||||
*/
|
||||
export function levelFor(p: PlayerId, loc: LocId): number {
|
||||
if (loc === START_LOC[p]) return 1;
|
||||
const level = LEVEL_BY_ROW[p][loc[0]];
|
||||
if (level === undefined) throw new Error(`No level for ${loc} from player ${p}`);
|
||||
return level;
|
||||
const row = 'ABCDE'.indexOf(loc[0]);
|
||||
if (row < 0 || row >= rowCount) throw new Error(`No level for ${loc} from player ${p}`);
|
||||
return p === 0 ? row + 1 : rowCount - row;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,3 +34,39 @@ export function winChance(atk: number, def: number): number {
|
|||
cache.set(key, chance);
|
||||
return chance;
|
||||
}
|
||||
|
||||
export interface RollOdds {
|
||||
/** Chances the attacker's total is higher, equal, or lower (no rerolls). */
|
||||
win: number;
|
||||
tie: number;
|
||||
lose: number;
|
||||
/** Expected damage to the defenders and to the attacker under the health rule (margin = damage). */
|
||||
damageDealt: number;
|
||||
damageTaken: number;
|
||||
}
|
||||
|
||||
const rollCache = new Map<string, RollOdds>();
|
||||
|
||||
/** One roll of `atk` Cores against `def` Cores: win, tie and loss chances, and expected damage. */
|
||||
export function rollOdds(atk: number, def: number): RollOdds {
|
||||
const key = `${atk}:${def}`;
|
||||
const hit = rollCache.get(key);
|
||||
if (hit) return hit;
|
||||
const out: RollOdds = { win: 0, tie: 0, lose: 0, damageDealt: 0, damageTaken: 0 };
|
||||
const a = sumDistribution(Math.max(1, atk));
|
||||
const d = sumDistribution(Math.max(1, def));
|
||||
for (const [sa, pa] of a) {
|
||||
for (const [sd, pd] of d) {
|
||||
const p = pa * pd;
|
||||
if (sa > sd) {
|
||||
out.win += p;
|
||||
out.damageDealt += p * (sa - sd);
|
||||
} else if (sa < sd) {
|
||||
out.lose += p;
|
||||
out.damageTaken += p * (sd - sa);
|
||||
} else out.tie += p;
|
||||
}
|
||||
}
|
||||
rollCache.set(key, out);
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
133
sim/src/query.ts
133
sim/src/query.ts
|
|
@ -6,7 +6,7 @@ import { LOCATIONS, type LocId } from './map.ts';
|
|||
import { scriptOf, type Fighter, type Payment, type Script } from './scripts.ts';
|
||||
import {
|
||||
activeMods,
|
||||
avatar,
|
||||
anomaly,
|
||||
controls,
|
||||
defOf,
|
||||
firewallCost,
|
||||
|
|
@ -18,23 +18,23 @@ import {
|
|||
sameRef,
|
||||
stat,
|
||||
} from './state.ts';
|
||||
import type { AvatarRef, GameState, HookName, Json, PlayerId, Source, Task } from './types.ts';
|
||||
import type { AnomalyRef, GameState, HookName, Json, PlayerId, Source, Task } from './types.ts';
|
||||
|
||||
export const programActive = (s: GameState, id: number): boolean =>
|
||||
!running(s, s.cards[id].disabledUntil) && !running(s, s.cards[id].ignoredUntil);
|
||||
export const hardwareActive = (s: GameState, id: number): boolean => !running(s, s.cards[id].disabledUntil);
|
||||
|
||||
/** Recruit rule: `p` has fewer than 4 Avatars, counting copies. Always true without the rule. */
|
||||
export function avatarRoom(s: GameState, p: PlayerId): boolean {
|
||||
/** Recruit rule: `p` has fewer than 4 Anomalies, counting copies. Always true without the rule. */
|
||||
export function anomalyRoom(s: GameState, p: PlayerId): boolean {
|
||||
if (!s.rules.recruit.on) return true;
|
||||
const avs = s.players[p].avatars;
|
||||
const avs = s.players[p].anomalies;
|
||||
return avs.slice(0, 4).filter((a) => a.card >= 0).length + avs.slice(4).filter((a) => a.at !== null).length < 4;
|
||||
}
|
||||
|
||||
/** Whether `p` may make a copy now: the copy-rule switches, and room under the recruit rule. */
|
||||
export function canCopy(s: GameState, p: PlayerId): boolean {
|
||||
const c = s.rules.copies;
|
||||
return c.allowed && (!c.needAvatar2 || s.players[p].avatars[1].faceUp) && avatarRoom(s, p);
|
||||
return c.allowed && (!c.needAnomaly2 || s.players[p].anomalies[1].faceUp) && anomalyRoom(s, p);
|
||||
}
|
||||
|
||||
/** Everything with an effect in play right now. */
|
||||
|
|
@ -66,8 +66,8 @@ export function sources(s: GameState): Source[] {
|
|||
for (const p of [0, 1] as const) {
|
||||
for (const r of refsInPlay(s, p)) {
|
||||
if (isCopy(r)) continue;
|
||||
const av = avatar(s, r);
|
||||
out.push({ kind: 'avatar', id: av.card, name: s.cards[av.card].name, controller: p, at: av.at, ref: r });
|
||||
const av = anomaly(s, r);
|
||||
out.push({ kind: 'anomaly', id: av.card, name: s.cards[av.card].name, controller: p, at: av.at, ref: r });
|
||||
for (const hw of av.hardware) {
|
||||
if (hardwareActive(s, hw)) out.push({ kind: 'hardware', id: hw, name: s.cards[hw].name, controller: p, at: av.at, ref: r });
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ export function sources(s: GameState): Source[] {
|
|||
|
||||
export const sameSource = (a: Source, b: Source): boolean =>
|
||||
a.id === b.id && a.name === b.name && a.at === b.at && a.virtual === b.virtual && sameRefOrNone(a.ref, b.ref);
|
||||
const sameRefOrNone = (a?: AvatarRef, b?: AvatarRef) => (!a && !b) || sameRef(a, b);
|
||||
const sameRefOrNone = (a?: AnomalyRef, b?: AnomalyRef) => (!a && !b) || sameRef(a, b);
|
||||
|
||||
export const stillActive = (s: GameState, src: Source): boolean => sources(s).some((x) => sameSource(x, src));
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ export function emit(s: GameState, hook: HookName, data: Json): void {
|
|||
// ---------------------------------------------------------------------------------------------
|
||||
// Capacity
|
||||
|
||||
/** How many of its owner's Avatars a location holds (Cluster Server, Pingable Server: 2). */
|
||||
/** How many of its owner's Anomalies a location holds (Cluster Server, Pingable Server: 2). */
|
||||
export function capacity(s: GameState, loc: LocId): number {
|
||||
const sv = s.locations[loc].server;
|
||||
if (sv === null || s.locations[loc].owner === null) return 1;
|
||||
|
|
@ -105,12 +105,12 @@ export function capacity(s: GameState, loc: LocId): number {
|
|||
return Math.max(1, scriptOf(c.name)?.capacity ?? 1, c.copies ? scriptOf(c.copies)?.capacity ?? 1 : 1);
|
||||
}
|
||||
|
||||
/** Whether `p` can put another Avatar on `loc`. */
|
||||
/** Whether `p` can put another Anomaly on `loc`. */
|
||||
export function hasRoom(s: GameState, p: PlayerId, loc: LocId): boolean {
|
||||
if (!controls(s, p, loc)) return false;
|
||||
// Nothing enters a location mid-combat (a copy, or an Avatar moved by Disconnect).
|
||||
// Nothing enters a location mid-combat (a copy, or an Anomaly moved by Disconnect).
|
||||
if (s.combat && !s.combat.ended && s.combat.loc === loc) return false;
|
||||
return refsInPlay(s, p).filter((r) => avatar(s, r).at === loc).length < capacity(s, loc);
|
||||
return refsInPlay(s, p).filter((r) => anomaly(s, r).at === loc).length < capacity(s, loc);
|
||||
}
|
||||
|
||||
/** Program slots on a location: 2, plus active Programs that add slots (Compatibility Layer). */
|
||||
|
|
@ -126,36 +126,36 @@ export function installedCount(s: GameState, loc: LocId): number {
|
|||
s.virtuals.filter((v) => v.installed && v.at === loc && running(s, v.until)).length;
|
||||
}
|
||||
|
||||
export function portsUsed(s: GameState, r: AvatarRef): number {
|
||||
return avatar(s, r).hardware.filter((id) => !scriptOf(s.cards[id].name)?.noPort).length;
|
||||
export function slotsUsed(s: GameState, r: AnomalyRef): number {
|
||||
return anomaly(s, r).hardware.filter((id) => !scriptOf(s.cards[id].name)?.noSlot).length;
|
||||
}
|
||||
|
||||
/** Expansion Slots an Avatar has: printed, plus Hardware that adds ports (Network Interface Upgrade). */
|
||||
export const portsTotal = (s: GameState, r: AvatarRef): number =>
|
||||
defOf(s, avatar(s, r).card).slots +
|
||||
avatar(s, r).hardware.reduce((t, id) => t + (scriptOf(s.cards[id].name)?.extraSlots ?? 0), 0);
|
||||
/** Expansion Slots an Anomaly has: printed, plus Hardware that adds some (Network Interface Upgrade). */
|
||||
export const slotsTotal = (s: GameState, r: AnomalyRef): number =>
|
||||
defOf(s, anomaly(s, r).card).slots +
|
||||
anomaly(s, r).hardware.reduce((t, id) => t + (scriptOf(s.cards[id].name)?.extraSlots ?? 0), 0);
|
||||
|
||||
export const portsFree = (s: GameState, r: AvatarRef): number => portsTotal(s, r) - portsUsed(s, r);
|
||||
export const slotsFree = (s: GameState, r: AnomalyRef): number => slotsTotal(s, r) - slotsUsed(s, r);
|
||||
|
||||
/** Whether a Hardware takes a port: Network Interface Upgrade and Hardware pushed on over the limit don't. */
|
||||
export const takesPort = (s: GameState, id: number): boolean =>
|
||||
!scriptOf(s.cards[id].name)?.noPort && s.cards[id].pushedUntil === undefined;
|
||||
/** Whether a Hardware takes an Expansion Slot: Network Interface Upgrade and Hardware pushed on over the limit don't. */
|
||||
export const takesSlot = (s: GameState, id: number): boolean =>
|
||||
!scriptOf(s.cards[id].name)?.noSlot && s.cards[id].pushedUntil === undefined;
|
||||
|
||||
/** Whether an Avatar's Hardware fits its ports, with `out` taken off and `into` put on. */
|
||||
export function portsFit(s: GameState, r: AvatarRef, out: number | null = null, into: number | null = null): boolean {
|
||||
const hw = avatar(s, r).hardware.filter((id) => id !== out);
|
||||
/** Whether an Anomaly's Hardware fits its Expansion Slots, with `out` taken off and `into` put on. */
|
||||
export function slotsFit(s: GameState, r: AnomalyRef, out: number | null = null, into: number | null = null): boolean {
|
||||
const hw = anomaly(s, r).hardware.filter((id) => id !== out);
|
||||
if (into !== null) hw.push(into);
|
||||
const total = defOf(s, avatar(s, r).card).slots + hw.reduce((t, id) => t + (scriptOf(s.cards[id].name)?.extraSlots ?? 0), 0);
|
||||
return hw.filter((id) => takesPort(s, id)).length <= total;
|
||||
const total = defOf(s, anomaly(s, r).card).slots + hw.reduce((t, id) => t + (scriptOf(s.cards[id].name)?.extraSlots ?? 0), 0);
|
||||
return hw.filter((id) => takesSlot(s, id)).length <= total;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Cores
|
||||
|
||||
/** Where an Avatar would fight from, as a fighter. `combat` is the current one, if it's in it. */
|
||||
export function fighterOf(s: GameState, ref: AvatarRef): Fighter {
|
||||
/** Where an Anomaly would fight from, as a fighter. `combat` is the current one, if it's in it. */
|
||||
export function fighterOf(s: GameState, ref: AnomalyRef): Fighter {
|
||||
const c = s.combat;
|
||||
const av = avatar(s, ref);
|
||||
const av = anomaly(s, ref);
|
||||
if (c && !c.ended) {
|
||||
if (sameRef(c.attacker, ref)) return { ref, role: 'attack', at: c.origin, loc: c.loc, combat: c };
|
||||
if (c.defenders.some((d) => sameRef(d, ref))) return { ref, role: 'defend', at: c.loc, loc: c.loc, combat: c };
|
||||
|
|
@ -163,12 +163,12 @@ export function fighterOf(s: GameState, ref: AvatarRef): Fighter {
|
|||
return { ref, role: null, at: av.at, loc: null, combat: null };
|
||||
}
|
||||
|
||||
/** Hardware on an Avatar (a copy uses its original's) with a script flag, if active. */
|
||||
export const wears = (s: GameState, ref: AvatarRef, flag: (sc: Script) => unknown): number[] =>
|
||||
/** Hardware on an Anomaly (a copy uses its original's) with a script flag, if active. */
|
||||
export const wears = (s: GameState, ref: AnomalyRef, flag: (sc: Script) => unknown): number[] =>
|
||||
hardwareOf(s, ref).filter((hw) => hardwareActive(s, hw) && flag(scriptOf(s.cards[hw].name) ?? { text: '' }));
|
||||
|
||||
/** Opponents' Bug effects can't touch an Avatar wearing ECC Memory. */
|
||||
export const bugImmune = (s: GameState, ref: AvatarRef, by: PlayerId): boolean =>
|
||||
/** Opponents' Bug effects can't touch an Anomaly wearing ECC Memory. */
|
||||
export const bugImmune = (s: GameState, ref: AnomalyRef, by: PlayerId): boolean =>
|
||||
by !== ref.player && wears(s, ref, (sc) => sc.bugImmunity).length > 0;
|
||||
|
||||
/** An active Program flag at a location, from a player other than `p`. */
|
||||
|
|
@ -182,7 +182,7 @@ function hardwareBlocked(s: GameState, f: Fighter, all: Source[]): boolean {
|
|||
}
|
||||
|
||||
/** Desynchronization: an attacker can't use once-per-turn Hardware abilities in a combat there. */
|
||||
export function desynced(s: GameState, ref: AvatarRef): boolean {
|
||||
export function desynced(s: GameState, ref: AnomalyRef): boolean {
|
||||
const c = s.combat;
|
||||
if (!c || c.ended || !sameRef(c.attacker, ref)) return false;
|
||||
return enemyFlagAt(s, c.loc, ref.player, (sc) => sc.blocksHardwareAbilities).length > 0;
|
||||
|
|
@ -195,50 +195,67 @@ export function desynced(s: GameState, ref: AvatarRef): boolean {
|
|||
export const FALLBACK_HEALTH = 10;
|
||||
|
||||
/**
|
||||
* Health rule: the damage that destroys an Avatar. Printed Health (or the rules' override), plus
|
||||
* Health rule: the damage that destroys an Anomaly. Printed Health (or the rules' override), plus
|
||||
* active Hardware that adds Health. A copy has its original's Health.
|
||||
*/
|
||||
export function healthOf(s: GameState, r: AvatarRef): number {
|
||||
const av = avatar(s, r);
|
||||
export function healthOf(s: GameState, r: AnomalyRef): number {
|
||||
const av = anomaly(s, r);
|
||||
let n = s.rules.health.override || (av.card < 0 ? 0 : defOf(s, av.card).health) || FALLBACK_HEALTH;
|
||||
for (const hw of hardwareOf(s, r)) if (hardwareActive(s, hw)) n += scriptOf(s.cards[hw].name)?.health ?? 0;
|
||||
return Math.max(1, n);
|
||||
}
|
||||
|
||||
/** Health rule: Health an Avatar has left. */
|
||||
export const healthLeft = (s: GameState, r: AvatarRef): number => healthOf(s, r) - avatar(s, r).damage;
|
||||
/** Health rule: Health an Anomaly has left. */
|
||||
export const healthLeft = (s: GameState, r: AnomalyRef): number => healthOf(s, r) - anomaly(s, r).damage;
|
||||
|
||||
/** One source of an Anomaly's Cores, for showing where a total comes from. */
|
||||
export interface CorePart {
|
||||
/** The card (or effect) that adds or removes Cores. */
|
||||
source: string;
|
||||
kind: 'anomaly' | 'hardware' | 'program' | 'server' | 'modifier';
|
||||
controller: PlayerId;
|
||||
cores: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combat Cores for a fighter. `credit` is told about every card that changed the total, so the
|
||||
* card report can count static effects (Stack Overflow, Server bonuses) as firing.
|
||||
* card report can count static effects (Stack Overflow, Server bonuses) as firing. `detail`, when
|
||||
* given, collects every part of the total (the printed Cores first); the total is at least 1.
|
||||
*/
|
||||
export function coresOf(s: GameState, f: Fighter, credit?: (name: string, p: PlayerId) => void): number {
|
||||
const av = avatar(s, f.ref);
|
||||
export function coresOf(s: GameState, f: Fighter, credit?: (name: string, p: PlayerId) => void, detail?: CorePart[]): number {
|
||||
const av = anomaly(s, f.ref);
|
||||
let n = defOf(s, av.card).cores;
|
||||
detail?.push({ source: defOf(s, av.card).name, kind: 'anomaly', controller: f.ref.player, cores: n });
|
||||
const all = sources(s);
|
||||
const add = (d: number, name: string, p: PlayerId) => {
|
||||
const add = (d: number, name: string, p: PlayerId, kind: CorePart['kind']) => {
|
||||
n += d;
|
||||
if (d !== 0) credit?.(name, p);
|
||||
if (d !== 0) {
|
||||
credit?.(name, p);
|
||||
detail?.push({ source: name, kind, controller: p, cores: d });
|
||||
}
|
||||
};
|
||||
if (!hardwareBlocked(s, f, all)) {
|
||||
for (const hw of hardwareOf(s, f.ref)) {
|
||||
if (!hardwareActive(s, hw) || f.combat?.suppressed.includes(hw)) continue;
|
||||
const name = s.cards[hw].name;
|
||||
const sc = scriptOf(name);
|
||||
if (sc?.cores) add(sc.cores(s, { kind: 'hardware', id: hw, name, controller: f.ref.player, at: f.at, ref: f.ref }, f), name, f.ref.player);
|
||||
if (sc?.cores) add(sc.cores(s, { kind: 'hardware', id: hw, name, controller: f.ref.player, at: f.at, ref: f.ref }, f), name, f.ref.player, 'hardware');
|
||||
}
|
||||
}
|
||||
const counted = new Set<string>();
|
||||
for (const src of all) {
|
||||
if (src.kind === 'hardware') continue;
|
||||
const sc = scriptOf(src.name);
|
||||
if (sc?.cores) add(sc.cores(s, src, f), src.name, src.controller);
|
||||
if (sc?.cores) add(sc.cores(s, src, f), src.name, src.controller, src.kind);
|
||||
if (sc?.globalCores && !counted.has(src.name)) {
|
||||
counted.add(src.name);
|
||||
add(sc.globalCores(s, f), src.name, src.controller);
|
||||
add(sc.globalCores(s, f), src.name, src.controller, src.kind);
|
||||
}
|
||||
}
|
||||
for (const m of activeMods(s, av)) n += m.cores;
|
||||
for (const m of activeMods(s, av)) {
|
||||
n += m.cores;
|
||||
if (m.cores !== 0) detail?.push({ source: m.source, kind: 'modifier', controller: m.by, cores: m.cores });
|
||||
}
|
||||
return Math.max(1, n);
|
||||
}
|
||||
|
||||
|
|
@ -256,11 +273,11 @@ export function sideCores(s: GameState): { atk: number; def: number } {
|
|||
|
||||
function baseCost(s: GameState, pay: Payment): number {
|
||||
if (pay.kind === 'firewall') return firewallCost(s, pay.level ?? 0);
|
||||
return pay.card === undefined ? 0 : defOf(s, pay.card).ram;
|
||||
return pay.card === undefined ? 0 : defOf(s, pay.card).bandwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* RAM a payment costs after every discount and surcharge in play. Pass `all` (the current
|
||||
* Bandwidth a payment costs after every discount and surcharge in play. Pass `all` (the current
|
||||
* sources) when pricing many payments against the same state.
|
||||
*/
|
||||
export function costOf(s: GameState, pay: Payment, all: Source[] = sources(s)): number {
|
||||
|
|
@ -273,7 +290,7 @@ export function costOf(s: GameState, pay: Payment, all: Source[] = sources(s)):
|
|||
}
|
||||
|
||||
/** Pays for something, using up once-per-turn discounts. Returns the amount paid. */
|
||||
export function pay(s: GameState, payment: Payment, statKey: 'ramOnCards' | 'ramOnFirewalls' | 'ramOnAbilities'): number {
|
||||
export function pay(s: GameState, payment: Payment, statKey: 'bandwidthOnCards' | 'bandwidthOnFirewalls' | 'bandwidthOnAbilities'): number {
|
||||
let n = baseCost(s, payment);
|
||||
const touched: Source[] = [];
|
||||
for (const src of sources(s)) {
|
||||
|
|
@ -284,17 +301,17 @@ export function pay(s: GameState, payment: Payment, statKey: 'ramOnCards' | 'ram
|
|||
}
|
||||
}
|
||||
const cost = Math.max(0, n);
|
||||
if (cost > s.players[payment.player].ram) throw new Error(`Can't afford ${cost} RAM`);
|
||||
s.players[payment.player].ram -= cost;
|
||||
if (cost > s.players[payment.player].bandwidth) throw new Error(`Can't afford ${cost} Gb`);
|
||||
s.players[payment.player].bandwidth -= cost;
|
||||
stat(s, statKey, payment.player, cost);
|
||||
for (const src of touched) scriptOf(src.name)?.onPaid?.(s, src, payment);
|
||||
return cost;
|
||||
}
|
||||
|
||||
/** RAM a player could have for a payment: current RAM plus the Salvage value of the rest of the hand. */
|
||||
export function reachableRam(s: GameState, p: PlayerId, except: number | null = null): number {
|
||||
/** Bandwidth a player could have for a payment: current Bandwidth plus the Salvage value of the rest of the hand. */
|
||||
export function reachableBandwidth(s: GameState, p: PlayerId, except: number | null = null): number {
|
||||
const pl = s.players[p];
|
||||
return pl.ram + pl.hand.reduce((t, id) => t + (id === except || id < 0 ? 0 : defOf(s, id).ram), 0);
|
||||
return pl.bandwidth + pl.hand.reduce((t, id) => t + (id === except || id < 0 ? 0 : defOf(s, id).bandwidth), 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import { BOARDS, type BoardName } from './map.ts';
|
||||
|
||||
/**
|
||||
* Every number from rules.md that a rule variant might change. Pass a modified copy to
|
||||
* createGame to A/B test a rule.
|
||||
*/
|
||||
export interface RulesConfig {
|
||||
startingRam: number;
|
||||
/** Which playmat (src/map.ts). Setting it also sets winLocations to the board's own count. */
|
||||
board: BoardName;
|
||||
startingBandwidth: number;
|
||||
openingHand: number;
|
||||
/** Cards drawn in each turn's draw step. */
|
||||
drawPerTurn: number;
|
||||
|
|
@ -11,56 +15,56 @@ export interface RulesConfig {
|
|||
winLocations: number;
|
||||
/** Player turns before the game is called a draw. */
|
||||
maxTurns: number;
|
||||
/** RAM paid on capture, by level. */
|
||||
levelRam: Record<number, number>;
|
||||
/** Bandwidth paid on capture, by level. */
|
||||
levelBandwidth: Record<number, number>;
|
||||
/** Cost to place, upgrade to, or clear a Firewall of each level; index 0 = Lv 1. */
|
||||
firewallCost: readonly number[];
|
||||
maxProgramsPerLocation: number;
|
||||
deck: { avatars: number; servers: number; main: number; maxCopies: number };
|
||||
/** Avatars face up at the start (rules: Avatar 1 only). */
|
||||
startingAvatars: number;
|
||||
deck: { anomalies: number; servers: number; main: number; maxCopies: number };
|
||||
/** Anomalies face up at the start (rules: Anomaly 1 only). */
|
||||
startingAnomalies: number;
|
||||
/** What the first player may do on turn 1 (the rules since v0.9 allow all of it; v0.8 skipped the draw). */
|
||||
firstTurn: {
|
||||
draw: boolean;
|
||||
advance: boolean;
|
||||
/** Captures pay capture RAM. A Server card's own RAM bonus is still paid. */
|
||||
captureRam: boolean;
|
||||
/** Captures unlock Avatars. They unlock on a later capture instead. */
|
||||
/** Captures pay capture Bandwidth. A Server card's own Bandwidth bonus is still paid. */
|
||||
captureBandwidth: boolean;
|
||||
/** Captures unlock Anomalies. They unlock on a later capture instead. */
|
||||
unlock: boolean;
|
||||
/** Playing cards from hand: Hardware, Programs, Executions. */
|
||||
cards: boolean;
|
||||
};
|
||||
/**
|
||||
* Catch-up for whoever goes second: extra starting RAM, extra Avatars face up, extra cards in the
|
||||
* Catch-up for whoever goes second: extra starting Bandwidth, extra Anomalies face up, extra cards in the
|
||||
* opening hand, extra cards in their first draw step, and (0 or 1) owning the location next to
|
||||
* their starting Server at the start.
|
||||
*/
|
||||
secondPlayer: { ram: number; avatars: number; cards: number; firstDraw: number; locations: number };
|
||||
secondPlayer: { bandwidth: number; anomalies: number; cards: number; firstDraw: number; locations: number };
|
||||
/**
|
||||
* Prototype: Avatars in the deck instead of level unlocks. You start with one Avatar; another
|
||||
* `avatarsInDeck` are shuffled into the main deck (inside its size). On your turn (steps 3 and 6)
|
||||
* pay an Avatar's price to recruit it from hand into an empty slot, or retire one of yours
|
||||
* (discarding it and its Hardware) to recruit into its slot. At most 4 Avatars, copies included.
|
||||
* Prototype: Anomalies in the deck instead of level unlocks. You start with one Anomaly; another
|
||||
* `anomaliesInDeck` are shuffled into the main deck (inside its size). On your turn (steps 3 and 6)
|
||||
* pay an Anomaly's price to recruit it from hand into an empty slot, or retire one of yours
|
||||
* (discarding it and its Hardware) to recruit into its slot. At most 4 Anomalies, copies included.
|
||||
* Price = `price` + `pricePerCore` × Cores; it's also the card's salvage value.
|
||||
*/
|
||||
recruit: { on: boolean; avatarsInDeck: number; price: number; pricePerCore: number };
|
||||
recruit: { on: boolean; anomaliesInDeck: number; price: number; pricePerCore: number };
|
||||
/**
|
||||
* Prototype: buy Avatars instead of level unlocks. On your turn (steps 3 and 6) pay RAM to flip
|
||||
* your next face-down Avatar; `prices` are for Avatars 2, 3 and 4.
|
||||
* Prototype: buy Anomalies instead of level unlocks. On your turn (steps 3 and 6) pay Bandwidth to flip
|
||||
* your next face-down Anomaly; `prices` are for Anomalies 2, 3 and 4.
|
||||
*/
|
||||
buyAvatars: { on: boolean; prices: number[] };
|
||||
buyAnomalies: { on: boolean; prices: number[] };
|
||||
/**
|
||||
* Copies (Carbon NanoBots' Replicate, Backup Server), for testing: whether they can be made at
|
||||
* all; whether a new copy must wait for its owner's next turn to advance or attack (it can
|
||||
* defend); whether making one needs Avatar 2 unlocked.
|
||||
* defend); whether making one needs Anomaly 2 unlocked.
|
||||
*/
|
||||
copies: { allowed: boolean; waitATurn: boolean; needAvatar2: boolean };
|
||||
copies: { allowed: boolean; waitATurn: boolean; needAnomaly2: boolean };
|
||||
/**
|
||||
* Rounds of alternating commands (the rules since v0.8; off = the old one-turn-each structure).
|
||||
* Each round both players get `perPlayer` commands, taken in turn. A command is one advance or one attack (or a pass),
|
||||
* with placement and cards before it and cards after it. A player's "turn" is their commands in
|
||||
* a round: the draw, turn-start effects and each Avatar's one action a round refresh at their
|
||||
* first command; once-per-turn effects become once per round. Avatars unlocked during a round
|
||||
* a round: the draw, turn-start effects and each Anomaly's one action a round refresh at their
|
||||
* first command; once-per-turn effects become once per round. Anomalies unlocked during a round
|
||||
* enter play from the next round.
|
||||
* `leads` says who takes a round's first command, round after round (F = first player, S =
|
||||
* second; the pattern repeats; "thue" is the Thue–Morse order F S S F S F F S…). `snake` orders
|
||||
|
|
@ -69,42 +73,44 @@ export interface RulesConfig {
|
|||
commands: { on: boolean; perPlayer: number; leads: string; snake: boolean };
|
||||
/**
|
||||
* Health and damage (the rules since v0.9; off = one roll decides the combat and the loser is
|
||||
* knocked out). Each Avatar has printed Health; `override` (when not 0) gives every Avatar that
|
||||
* knocked out). Each Anomaly has printed Health; `override` (when not 0) gives every Anomaly that
|
||||
* Health instead, for A/B tests. The roll is unchanged, but the loser takes damage equal to the
|
||||
* difference in totals, a tie is a stalemate (no reroll, no damage), and an Avatar is destroyed
|
||||
* difference in totals, a tie is a stalemate (no reroll, no damage), and an Anomaly is destroyed
|
||||
* (knocked out as before) only when its damage reaches its Health. A location is captured only
|
||||
* when its last defender is destroyed. `recall` allows returning an Avatar to its slot in the
|
||||
* when its last defender is destroyed. `recall` allows returning an Anomaly to its slot in the
|
||||
* Deploy step (as its placement for the round) to heal it fully; it keeps its Hardware.
|
||||
*/
|
||||
health: { on: boolean; override: number; recall: boolean };
|
||||
}
|
||||
|
||||
export const DEFAULT_RULES: RulesConfig = {
|
||||
startingRam: 4,
|
||||
board: 'classic',
|
||||
startingBandwidth: 4,
|
||||
openingHand: 7,
|
||||
drawPerTurn: 1,
|
||||
winLocations: 10,
|
||||
maxTurns: 200,
|
||||
levelRam: { 1: 4, 2: 4, 3: 4, 4: 4, 5: 4 },
|
||||
levelBandwidth: { 1: 4, 2: 4, 3: 4, 4: 4, 5: 4 },
|
||||
firewallCost: [2, 4, 8],
|
||||
maxProgramsPerLocation: 2,
|
||||
deck: { avatars: 4, servers: 20, main: 45, maxCopies: 2 },
|
||||
startingAvatars: 1,
|
||||
firstTurn: { draw: true, advance: true, captureRam: true, unlock: true, cards: true },
|
||||
secondPlayer: { ram: 0, avatars: 0, cards: 0, firstDraw: 0, locations: 0 },
|
||||
recruit: { on: false, avatarsInDeck: 3, price: 6, pricePerCore: 0 },
|
||||
buyAvatars: { on: false, prices: [8, 12, 16] },
|
||||
copies: { allowed: true, waitATurn: false, needAvatar2: false },
|
||||
deck: { anomalies: 4, servers: 20, main: 45, maxCopies: 2 },
|
||||
startingAnomalies: 1,
|
||||
firstTurn: { draw: true, advance: true, captureBandwidth: true, unlock: true, cards: true },
|
||||
secondPlayer: { bandwidth: 0, anomalies: 0, cards: 0, firstDraw: 0, locations: 0 },
|
||||
recruit: { on: false, anomaliesInDeck: 3, price: 6, pricePerCore: 0 },
|
||||
buyAnomalies: { on: false, prices: [8, 12, 16] },
|
||||
copies: { allowed: true, waitATurn: false, needAnomaly2: false },
|
||||
commands: { on: true, perPlayer: 2, leads: 'F', snake: true },
|
||||
health: { on: true, override: 0, recall: true },
|
||||
};
|
||||
|
||||
/** Avatars kept outside the main deck: all of them, or just the starting one when recruiting. */
|
||||
export const avatarsOutside = (rules: RulesConfig): number => (rules.recruit.on ? 1 : rules.deck.avatars);
|
||||
/** Anomalies kept outside the main deck: all of them, or just the starting one when recruiting. */
|
||||
export const anomaliesOutside = (rules: RulesConfig): number => (rules.recruit.on ? 1 : rules.deck.anomalies);
|
||||
|
||||
/**
|
||||
* A copy of `rules` with one setting changed, from text like "winLocations=9",
|
||||
* "secondPlayer.ram=4", "firstTurn.advance=false" or "levelRam=4,4,4,4,4" (Lv 1 to 5).
|
||||
* "secondPlayer.bandwidth=4", "firstTurn.advance=false" or "levelBandwidth=4,4,4,4,4" (Lv 1 to 5).
|
||||
* "board=grid4" also sets winLocations to 12, so give a winLocations after it to change that.
|
||||
*/
|
||||
export function withRule(rules: RulesConfig, spec: string): RulesConfig {
|
||||
const m = spec.match(/^([\w.]+)=(.+)$/);
|
||||
|
|
@ -124,12 +130,16 @@ export function withRule(rules: RulesConfig, spec: string): RulesConfig {
|
|||
if (!Number.isFinite(n)) throw new Error(`Rule "${key}" needs numbers, got "${x}"`);
|
||||
return n;
|
||||
};
|
||||
if (typeof old === 'number') obj[last] = num(raw);
|
||||
if (key === 'board') {
|
||||
if (!(raw in BOARDS)) throw new Error(`Unknown board "${raw}". Boards: ${Object.keys(BOARDS).join(', ')}`);
|
||||
obj.board = raw;
|
||||
obj.winLocations = BOARDS[raw as BoardName].win;
|
||||
} else if (typeof old === 'number') obj[last] = num(raw);
|
||||
else if (typeof old === 'string') obj[last] = raw;
|
||||
else if (typeof old === 'boolean') {
|
||||
if (raw !== 'true' && raw !== 'false') throw new Error(`Rule "${key}" needs true or false`);
|
||||
obj[last] = raw === 'true';
|
||||
} else if (key === 'levelRam') {
|
||||
} else if (key === 'levelBandwidth') {
|
||||
obj[last] = Object.fromEntries(raw.split(',').map((x, i) => [i + 1, num(x)]));
|
||||
} else if (Array.isArray(old)) obj[last] = raw.split(',').map(num);
|
||||
else throw new Error(`Unknown rule "${key}"`);
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
* cards.csv is reported instead of silently simulated with the old wording.
|
||||
*/
|
||||
import type { CardDef, CardPool } from './cards.ts';
|
||||
import { AVATARS } from './cards/avatars.ts';
|
||||
import { ANOMALIES } from './cards/anomalies.ts';
|
||||
import { EXECUTIONS } from './cards/executions.ts';
|
||||
import { HARDWARE } from './cards/hardware.ts';
|
||||
import { PROGRAMS } from './cards/programs.ts';
|
||||
import { SERVERS } from './cards/servers.ts';
|
||||
import type { LocId } from './map.ts';
|
||||
import type { Args, AvatarRef, Combat, GameState, PlayerId, Source, StackItem } from './types.ts';
|
||||
import type { Args, AnomalyRef, Combat, GameState, PlayerId, Source, StackItem } from './types.ts';
|
||||
|
||||
/** An Avatar as it fights, or would fight. */
|
||||
/** An Anomaly as it fights, or would fight. */
|
||||
export interface Fighter {
|
||||
ref: AvatarRef;
|
||||
ref: AnomalyRef;
|
||||
role: 'attack' | 'defend' | null;
|
||||
/** Where it stands: an attacker's origin, or the location it defends. */
|
||||
at: LocId | null;
|
||||
|
|
@ -23,7 +23,7 @@ export interface Fighter {
|
|||
combat: Combat | null;
|
||||
}
|
||||
|
||||
/** Something a player is paying RAM for. */
|
||||
/** Something a player is paying Bandwidth for. */
|
||||
export interface Payment {
|
||||
kind: 'program' | 'hardware' | 'execution' | 'firewall' | 'ability';
|
||||
player: PlayerId;
|
||||
|
|
@ -31,11 +31,11 @@ export interface Payment {
|
|||
/** Program: where it's installed. Execution: its target. */
|
||||
at?: LocId | null;
|
||||
/** Hardware: who it's installed on. */
|
||||
ref?: AvatarRef;
|
||||
ref?: AnomalyRef;
|
||||
line?: string;
|
||||
level?: number;
|
||||
/** Execution: enemy Avatars it targets. */
|
||||
hostile?: AvatarRef[];
|
||||
/** Execution: enemy Anomalies it targets. */
|
||||
hostile?: AnomalyRef[];
|
||||
}
|
||||
|
||||
export interface Play {
|
||||
|
|
@ -44,19 +44,19 @@ export interface Play {
|
|||
}
|
||||
|
||||
export interface ExecutionScript {
|
||||
/** Every legal way to play the card now, ignoring RAM. */
|
||||
/** Every legal way to play the card now, ignoring Bandwidth. */
|
||||
plays(s: GameState, p: PlayerId): Play[];
|
||||
resolve(s: GameState, item: StackItem): void;
|
||||
/** Enemy Avatars (or Avatars whose Hardware) the play targets. */
|
||||
targetsAvatars?(s: GameState, item: Pick<StackItem, 'player' | 'target' | 'args'>): AvatarRef[];
|
||||
/** Enemy Anomalies (or Anomalies whose Hardware) the play targets. */
|
||||
targetsAnomalies?(s: GameState, item: Pick<StackItem, 'player' | 'target' | 'args'>): AnomalyRef[];
|
||||
}
|
||||
|
||||
export interface AbilityScript {
|
||||
/** RAM cost. Avatars use the Ability Cost printed on the card. */
|
||||
/** Bandwidth cost. Anomalies use the Ability Cost printed on the card. */
|
||||
cost?: number;
|
||||
/** More RAM paid on activation for this particular use (Hot-Swap Bay, Push Update). */
|
||||
/** More Bandwidth paid on activation for this particular use (Hot-Swap Bay, Push Update). */
|
||||
extraCost?(s: GameState, src: Source, args: Args): number;
|
||||
/** Every legal way to use it now, ignoring RAM; empty when it can't be used. */
|
||||
/** Every legal way to use it now, ignoring Bandwidth; empty when it can't be used. */
|
||||
uses(s: GameState, src: Source): Args[];
|
||||
resolve(s: GameState, item: StackItem, src: Source): void;
|
||||
/** Hardware "once per turn" abilities, which Desynchronization and Cooling System refer to. */
|
||||
|
|
@ -67,19 +67,19 @@ export interface Script {
|
|||
/** The card text this script implements. */
|
||||
text: string;
|
||||
|
||||
/** Server: RAM gained once, when the card is placed. */
|
||||
ramOnPlace?: number;
|
||||
/** Server: Avatars of its controller that fit on the location. */
|
||||
/** Server: Bandwidth gained once, when the card is placed. */
|
||||
bandwidthOnPlace?: number;
|
||||
/** Server: Anomalies of its controller that fit on the location. */
|
||||
capacity?: number;
|
||||
/** Server: extra Program slots on its location. */
|
||||
programSlots?: number;
|
||||
/** Hardware that doesn't use an Expansion Slot. */
|
||||
noPort?: boolean;
|
||||
noSlot?: boolean;
|
||||
/** Hardware: Expansion Slots it adds to its wearer (Network Interface Upgrade). */
|
||||
extraSlots?: number;
|
||||
/** Hardware: Health it adds to its wearer (health rule): RAM Expansion. */
|
||||
health?: number;
|
||||
/** Program: extra attacks for its controller's Avatars attacking from this location (Infinite Loop). */
|
||||
/** Program: extra attacks for its controller's Anomalies attacking from this location (Infinite Loop). */
|
||||
extraAttacks?: number;
|
||||
/** Program: no Hardware Core bonuses in combats here (Stock Rice). */
|
||||
blocksHardwareInCombat?: boolean;
|
||||
|
|
@ -99,36 +99,36 @@ export interface Script {
|
|||
/** Like `cores`, but counted once no matter how many copies are in play. */
|
||||
globalCores?(s: GameState, f: Fighter): number;
|
||||
|
||||
/** RAM added to (or, negative, taken off) a payment. */
|
||||
/** Bandwidth added to (or, negative, taken off) a payment. */
|
||||
costMod?(s: GameState, src: Source, pay: Payment): number;
|
||||
/** Called after a payment that this source changed. */
|
||||
onPaid?(s: GameState, src: Source, pay: Payment): void;
|
||||
|
||||
onTurnStart?(s: GameState, src: Source): void;
|
||||
onDraw?(s: GameState, src: Source, ev: { player: PlayerId; card: number }): void;
|
||||
onAttackDeclared?(s: GameState, src: Source, ev: { ref: AvatarRef; to: LocId }): void;
|
||||
onAttackDeclared?(s: GameState, src: Source, ev: { ref: AnomalyRef; to: LocId }): void;
|
||||
/** An enemy is capturing this source's location. Runs before the location's cards leave. */
|
||||
onBreach?(s: GameState, src: Source, ev: { ref: AvatarRef; loc: LocId }): void;
|
||||
onBreach?(s: GameState, src: Source, ev: { ref: AnomalyRef; loc: LocId }): void;
|
||||
/** Like onBreach, for effects that save cards from the capture. */
|
||||
onCaptured?(s: GameState, src: Source, ev: { ref: AvatarRef; loc: LocId }): void;
|
||||
onCaptured?(s: GameState, src: Source, ev: { ref: AnomalyRef; loc: LocId }): void;
|
||||
/** A Server card was just placed. */
|
||||
onPlaced?(s: GameState, src: Source, ev: { card: number }): void;
|
||||
onInstall?(s: GameState, src: Source, ev: { card: number; at: LocId | null; ref: AvatarRef | null }): void;
|
||||
onInstall?(s: GameState, src: Source, ev: { card: number; at: LocId | null; ref: AnomalyRef | null }): void;
|
||||
/** Reads the combat from s.combat. */
|
||||
onCombatStart?(s: GameState, src: Source): void;
|
||||
/** An Avatar was defeated at `loc`. It's already back in its slot. */
|
||||
onDefeat?(s: GameState, src: Source, ev: { ref: AvatarRef; loc: LocId; role: 'attack' | 'defend' }): void;
|
||||
/** An Anomaly was defeated at `loc`. It's already back in its slot. */
|
||||
onDefeat?(s: GameState, src: Source, ev: { ref: AnomalyRef; loc: LocId; role: 'attack' | 'defend' }): void;
|
||||
/**
|
||||
* An Avatar lost a roll at `loc`: under the health rule it took `amount` damage (and may be
|
||||
* An Anomaly lost a roll at `loc`: under the health rule it took `amount` damage (and may be
|
||||
* `destroyed`); with the rule off, every lost roll destroys it. Runs before the defeat.
|
||||
*/
|
||||
onDamage?(s: GameState, src: Source, ev: { ref: AvatarRef; loc: LocId; role: 'attack' | 'defend'; amount: number; destroyed: boolean }): void;
|
||||
onDamage?(s: GameState, src: Source, ev: { ref: AnomalyRef; loc: LocId; role: 'attack' | 'defend'; amount: number; destroyed: boolean }): void;
|
||||
onCombatEnd?(s: GameState, src: Source): void;
|
||||
/**
|
||||
* Hardware: its wearer was just defeated. Return true to take over what happens to the Hardware
|
||||
* (the script must then knock the Avatar out itself).
|
||||
* (the script must then knock the Anomaly out itself).
|
||||
*/
|
||||
onWearerDefeated?(s: GameState, hw: number, ev: { ref: AvatarRef; loc: LocId; role: 'attack' | 'defend' }): boolean;
|
||||
onWearerDefeated?(s: GameState, hw: number, ev: { ref: AnomalyRef; loc: LocId; role: 'attack' | 'defend' }): boolean;
|
||||
/** Lower goes first among onWearerDefeated Hardware. */
|
||||
savePriority?: number;
|
||||
|
||||
|
|
@ -145,15 +145,15 @@ let registry: Record<string, Script> | null = null;
|
|||
|
||||
/** All scripts by card name. Built on first use, so card modules can import engine helpers. */
|
||||
export function scripts(): Record<string, Script> {
|
||||
return (registry ??= { ...SERVERS, ...PROGRAMS, ...HARDWARE, ...EXECUTIONS, ...AVATARS });
|
||||
return (registry ??= { ...SERVERS, ...PROGRAMS, ...HARDWARE, ...EXECUTIONS, ...ANOMALIES });
|
||||
}
|
||||
|
||||
export const scriptOf = (name: string): Script | undefined => scripts()[name];
|
||||
|
||||
export const isImplemented = (card: CardDef): boolean => card.name in scripts();
|
||||
|
||||
/** The text a card's script checks: the Ability for Avatars, the description for everything else. */
|
||||
export const scriptedText = (card: CardDef): string => (card.kind === 'avatar' ? card.ability?.text ?? '' : card.text).trim();
|
||||
/** The text a card's script checks: the Ability for Anomalies, the description for everything else. */
|
||||
export const scriptedText = (card: CardDef): string => (card.kind === 'anomaly' ? card.ability?.text ?? '' : card.text).trim();
|
||||
|
||||
/** Scripts whose card is missing from, or worded differently in, the CSV; and cards with no script. */
|
||||
export function staleScripts(pool: CardPool): string[] {
|
||||
|
|
|
|||
118
sim/src/state.ts
118
sim/src/state.ts
|
|
@ -7,14 +7,15 @@ import { GRID, LINES_AT, otherEnd, type Line, type LocId } from './map.ts';
|
|||
import { d6 } from './rng.ts';
|
||||
import {
|
||||
PLAYER_NAMES,
|
||||
type AvatarRef,
|
||||
type AvatarState,
|
||||
type AnomalyRef,
|
||||
type AnomalyState,
|
||||
type CaptureStat,
|
||||
type Choice,
|
||||
type Clock,
|
||||
type Combat,
|
||||
type GameState,
|
||||
type Json,
|
||||
type LogLine,
|
||||
type Modifier,
|
||||
type PlayerId,
|
||||
type StatKey,
|
||||
|
|
@ -27,15 +28,24 @@ export const nameOf = (s: GameState, id: number): string => (id < 0 ? 'a hidden
|
|||
export const ownerOf = (s: GameState, id: number): PlayerId => s.cards[id].owner;
|
||||
export const controls = (s: GameState, p: PlayerId, loc: LocId): boolean => s.locations[loc].owner === p;
|
||||
export const isOpen = (s: GameState, line: Line): boolean => !s.firewalls[line.id];
|
||||
/** RAM to place, upgrade to, or clear a Firewall of `level`, before discounts; 0 for no Firewall. */
|
||||
/** Bandwidth to place, upgrade to, or clear a Firewall of `level`, before discounts; 0 for no Firewall. */
|
||||
export const firewallCost = (s: GameState, level: number): number => s.rules.firewallCost[level - 1] ?? 0;
|
||||
export const gridCount = (s: GameState, p: PlayerId): number => GRID.filter((loc) => controls(s, p, loc)).length;
|
||||
|
||||
/** Rolls a d6 (or takes the next rigged result). */
|
||||
export const rollDie = (s: GameState): number => (s.rigged?.length ? s.rigged.shift()! : d6(s.rng));
|
||||
|
||||
export function say(s: GameState, msg: string): void {
|
||||
s.log?.push(msg);
|
||||
/**
|
||||
* Adds a line to the play-by-play. `meta` tags what it's about; give `to` and `public` when the
|
||||
* line names cards only one player may see, and the other player reads `public` instead.
|
||||
*/
|
||||
export function say(s: GameState, msg: string, meta?: Omit<LogLine, 'text'>): void {
|
||||
s.log?.push(meta ? { text: msg, ...meta } : { text: msg });
|
||||
}
|
||||
|
||||
/** The play-by-play as `viewer` may read it, or every line in full for null. */
|
||||
export function logFor(s: GameState, viewer: PlayerId | null): string[] {
|
||||
return (s.log ?? []).map((l) => (viewer === null || l.to === undefined || l.to === viewer ? l.text : l.public ?? ''));
|
||||
}
|
||||
|
||||
export function stat(s: GameState, key: StatKey, p: PlayerId, n = 1): void {
|
||||
|
|
@ -98,89 +108,89 @@ export function markUsed(s: GameState, key: string): void {
|
|||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Avatars
|
||||
// Anomalies
|
||||
|
||||
export const refKey = (r: AvatarRef): string => `${r.player}:${r.slot}`;
|
||||
export const sameRef = (a: AvatarRef | null | undefined, b: AvatarRef | null | undefined): boolean =>
|
||||
export const refKey = (r: AnomalyRef): string => `${r.player}:${r.slot}`;
|
||||
export const sameRef = (a: AnomalyRef | null | undefined, b: AnomalyRef | null | undefined): boolean =>
|
||||
!!a && !!b && a.player === b.player && a.slot === b.slot;
|
||||
export const avatar = (s: GameState, r: AvatarRef): AvatarState => s.players[r.player].avatars[r.slot - 1];
|
||||
export const isCopy = (r: AvatarRef): boolean => r.slot > 4;
|
||||
/** The printed Avatar a ref belongs to (a copy's original). */
|
||||
export const originalOf = (r: AvatarRef): AvatarRef => (r.slot > 4 ? { player: r.player, slot: r.slot - 4 } : r);
|
||||
export const copyOf = (r: AvatarRef): AvatarRef => ({ player: r.player, slot: originalOf(r).slot + 4 });
|
||||
export const inPlay = (s: GameState, r: AvatarRef): boolean => avatar(s, r).at !== null;
|
||||
export const avatarDef = (s: GameState, r: AvatarRef): CardDef => defOf(s, avatar(s, r).card);
|
||||
export const anomaly = (s: GameState, r: AnomalyRef): AnomalyState => s.players[r.player].anomalies[r.slot - 1];
|
||||
export const isCopy = (r: AnomalyRef): boolean => r.slot > 4;
|
||||
/** The printed Anomaly a ref belongs to (a copy's original). */
|
||||
export const originalOf = (r: AnomalyRef): AnomalyRef => (r.slot > 4 ? { player: r.player, slot: r.slot - 4 } : r);
|
||||
export const copyOf = (r: AnomalyRef): AnomalyRef => ({ player: r.player, slot: originalOf(r).slot + 4 });
|
||||
export const inPlay = (s: GameState, r: AnomalyRef): boolean => anomaly(s, r).at !== null;
|
||||
export const anomalyDef = (s: GameState, r: AnomalyRef): CardDef => defOf(s, anomaly(s, r).card);
|
||||
|
||||
export function avatarName(s: GameState, r: AvatarRef): string {
|
||||
export function anomalyName(s: GameState, r: AnomalyRef): string {
|
||||
const n = originalOf(r).slot;
|
||||
const card = avatar(s, r).card;
|
||||
const card = anomaly(s, r).card;
|
||||
const name = card < 0 ? '?' : nameOf(s, card);
|
||||
return isCopy(r) ? `the copy of Avatar ${n} (${name})` : `Avatar ${n} (${name})`;
|
||||
return isCopy(r) ? `the copy of Anomaly ${n} (${name})` : `Anomaly ${n} (${name})`;
|
||||
}
|
||||
|
||||
/** Every Avatar of `p` in play, originals first. */
|
||||
export function refsInPlay(s: GameState, p: PlayerId): AvatarRef[] {
|
||||
const out: AvatarRef[] = [];
|
||||
s.players[p].avatars.forEach((av, i) => {
|
||||
/** Every Anomaly of `p` in play, originals first. */
|
||||
export function refsInPlay(s: GameState, p: PlayerId): AnomalyRef[] {
|
||||
const out: AnomalyRef[] = [];
|
||||
s.players[p].anomalies.forEach((av, i) => {
|
||||
if (av.at !== null) out.push({ player: p, slot: i + 1 });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Avatars standing on `loc`. Only the location's owner can have Avatars there. */
|
||||
export function avatarsAt(s: GameState, loc: LocId): AvatarRef[] {
|
||||
/** Anomalies standing on `loc`. Only the location's owner can have Anomalies there. */
|
||||
export function anomaliesAt(s: GameState, loc: LocId): AnomalyRef[] {
|
||||
const owner = s.locations[loc].owner;
|
||||
return owner === null ? [] : refsInPlay(s, owner).filter((r) => avatar(s, r).at === loc);
|
||||
return owner === null ? [] : refsInPlay(s, owner).filter((r) => anomaly(s, r).at === loc);
|
||||
}
|
||||
export const defendersAt = avatarsAt;
|
||||
export const defendersAt = anomaliesAt;
|
||||
|
||||
/** Hardware that counts for an Avatar. A copy uses its original's Hardware. */
|
||||
export const hardwareOf = (s: GameState, r: AvatarRef): number[] => avatar(s, originalOf(r)).hardware;
|
||||
/** Hardware that counts for an Anomaly. A copy uses its original's Hardware. */
|
||||
export const hardwareOf = (s: GameState, r: AnomalyRef): number[] => anomaly(s, originalOf(r)).hardware;
|
||||
|
||||
/** The Avatar wearing a Hardware card, if it's installed. */
|
||||
export function wearerOf(s: GameState, hw: number): AvatarRef | null {
|
||||
/** The Anomaly wearing a Hardware card, if it's installed. */
|
||||
export function wearerOf(s: GameState, hw: number): AnomalyRef | null {
|
||||
const p = ownerOf(s, hw);
|
||||
const i = s.players[p].avatars.findIndex((a) => a.hardware.includes(hw));
|
||||
const i = s.players[p].anomalies.findIndex((a) => a.hardware.includes(hw));
|
||||
return i < 0 ? null : { player: p, slot: i + 1 };
|
||||
}
|
||||
|
||||
export const isRooted = (s: GameState, r: AvatarRef): boolean => running(s, avatar(s, r).rootedUntil);
|
||||
export const isDisabledAvatar = (s: GameState, r: AvatarRef): boolean => running(s, avatar(s, r).disabledUntil);
|
||||
export const isRooted = (s: GameState, r: AnomalyRef): boolean => running(s, anomaly(s, r).rootedUntil);
|
||||
export const isDisabledAnomaly = (s: GameState, r: AnomalyRef): boolean => running(s, anomaly(s, r).disabledUntil);
|
||||
/** Can act: advance, attack, move, use its Ability. */
|
||||
/** Copy-rule variant: a copy made this player-turn can't advance or attack yet. It can still defend. */
|
||||
export const freshCopy = (s: GameState, r: AvatarRef): boolean =>
|
||||
isCopy(r) && s.rules.copies.waitATurn && avatar(s, r).createdTurn === s.turn;
|
||||
export const freshCopy = (s: GameState, r: AnomalyRef): boolean =>
|
||||
isCopy(r) && s.rules.copies.waitATurn && anomaly(s, r).createdTurn === s.turn;
|
||||
|
||||
export const canAct = (s: GameState, r: AvatarRef): boolean =>
|
||||
inPlay(s, r) && !isRooted(s, r) && !isDisabledAvatar(s, r);
|
||||
export const canAct = (s: GameState, r: AnomalyRef): boolean =>
|
||||
inPlay(s, r) && !isRooted(s, r) && !isDisabledAnomaly(s, r);
|
||||
|
||||
/** Temporary modifiers that currently apply to an Avatar. */
|
||||
export function activeMods(s: GameState, av: AvatarState): Modifier[] {
|
||||
/** Temporary modifiers that currently apply to an Anomaly. */
|
||||
export function activeMods(s: GameState, av: AnomalyState): Modifier[] {
|
||||
return av.mods.filter((m) =>
|
||||
m.combat !== undefined ? s.combat?.id === m.combat : running(s, m.until ?? 0));
|
||||
}
|
||||
|
||||
export function addMod(
|
||||
s: GameState,
|
||||
r: AvatarRef,
|
||||
r: AnomalyRef,
|
||||
cores: number,
|
||||
source: string,
|
||||
by: PlayerId,
|
||||
scope: { combat: number } | { until: Clock },
|
||||
): void {
|
||||
avatar(s, r).mods.push({ seq: ++s.seq, cores, source, by, ...scope });
|
||||
anomaly(s, r).mods.push({ seq: ++s.seq, cores, source, by, ...scope });
|
||||
}
|
||||
|
||||
export const infectionOf = (av: AvatarState): number => av.infection + av.permanentInfection;
|
||||
export const infectionOf = (av: AnomalyState): number => av.infection + av.permanentInfection;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Combat
|
||||
|
||||
export const inCombat = (s: GameState, r: AvatarRef): boolean =>
|
||||
export const inCombat = (s: GameState, r: AnomalyRef): boolean =>
|
||||
!!s.combat && !s.combat.ended && (sameRef(s.combat.attacker, r) || s.combat.defenders.some((d) => sameRef(d, r)));
|
||||
|
||||
/** The other side of the current combat from `r`'s point of view. */
|
||||
export function opponentsInCombat(s: GameState, r: AvatarRef): AvatarRef[] {
|
||||
export function opponentsInCombat(s: GameState, r: AnomalyRef): AnomalyRef[] {
|
||||
const c = s.combat;
|
||||
if (!c || c.ended) return [];
|
||||
if (sameRef(c.attacker, r)) return [...c.defenders];
|
||||
|
|
@ -188,14 +198,14 @@ export function opponentsInCombat(s: GameState, r: AvatarRef): AvatarRef[] {
|
|||
return [];
|
||||
}
|
||||
|
||||
export const fightersOf = (c: Combat): AvatarRef[] => [c.attacker, ...c.defenders];
|
||||
export const fightersOf = (c: Combat): AnomalyRef[] => [c.attacker, ...c.defenders];
|
||||
|
||||
/**
|
||||
* Avatars "at" a location for card text: the ones standing there, plus an enemy attacking it in the
|
||||
* Anomalies "at" a location for card text: the ones standing there, plus an enemy attacking it in the
|
||||
* current combat.
|
||||
*/
|
||||
export function atServer(s: GameState, loc: LocId): AvatarRef[] {
|
||||
const out = avatarsAt(s, loc);
|
||||
export function atServer(s: GameState, loc: LocId): AnomalyRef[] {
|
||||
const out = anomaliesAt(s, loc);
|
||||
const c = s.combat;
|
||||
if (c && !c.ended && c.loc === loc && !out.some((r) => sameRef(r, c.attacker))) out.push(c.attacker);
|
||||
return out;
|
||||
|
|
@ -250,9 +260,9 @@ export function uninstallProgram(s: GameState, id: number): LocId | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
export function uninstallHardware(s: GameState, id: number): AvatarRef | null {
|
||||
export function uninstallHardware(s: GameState, id: number): AnomalyRef | null {
|
||||
const r = wearerOf(s, id);
|
||||
if (r) removeFrom(avatar(s, r).hardware, id);
|
||||
if (r) removeFrom(anomaly(s, r).hardware, id);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -261,9 +271,9 @@ export function programLocation(s: GameState, id: number): LocId | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
export function gainRam(s: GameState, p: PlayerId, n: number, key: StatKey = 'ramFromEffects'): void {
|
||||
export function gainBandwidth(s: GameState, p: PlayerId, n: number, key: StatKey = 'bandwidthFromEffects'): void {
|
||||
if (n <= 0) return;
|
||||
s.players[p].ram += n;
|
||||
s.players[p].bandwidth += n;
|
||||
stat(s, key, p, n);
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +297,7 @@ export const later = (name: string, fn: string, data: Json = null): Task => ({ t
|
|||
|
||||
export function startCombat(
|
||||
s: GameState,
|
||||
attacker: AvatarRef,
|
||||
attacker: AnomalyRef,
|
||||
origin: LocId,
|
||||
loc: LocId,
|
||||
kind: Combat['kind'],
|
||||
|
|
@ -322,7 +332,7 @@ export function startCombat(
|
|||
return combat;
|
||||
}
|
||||
|
||||
export const pushCapture = (s: GameState, ref: AvatarRef, loc: LocId, how: CaptureStat): void =>
|
||||
export const pushCapture = (s: GameState, ref: AnomalyRef, loc: LocId, how: CaptureStat): void =>
|
||||
pushTasks(s, { t: 'capture', ref, loc, stage: 'hooks', how });
|
||||
|
||||
export const playerName = (p: PlayerId): string => PLAYER_NAMES[p];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export interface GameRecord {
|
|||
locations: [number, number];
|
||||
stats: Record<StatKey, [number, number]>;
|
||||
cardUse: Record<string, CardUse>;
|
||||
/** Card names in each player's decks (Avatars, Servers and main deck). */
|
||||
/** Card names in each player's decks (Anomalies, Servers and main deck). */
|
||||
decks: [string[], string[]];
|
||||
}
|
||||
|
||||
|
|
@ -92,15 +92,15 @@ export function formatSummary(sum: BatchSummary, labels: [string, string]): stri
|
|||
row('Attack win rate', pct(g.attacksWon[0], g.attacks[0]), pct(g.attacksWon[1], g.attacks[1])),
|
||||
both('Combats tied (health rule: stalemates)', 'combatsTied'),
|
||||
both('Damage dealt (health rule)', 'damageDealt'),
|
||||
both('Avatars destroyed', 'avatarsDestroyed'),
|
||||
both('Anomalies destroyed', 'anomaliesDestroyed'),
|
||||
both('Recalls (health rule)', 'recalls'),
|
||||
both('Firewalls placed', 'firewallsPlaced'),
|
||||
both('Firewalls upgraded', 'firewallsUpgraded'),
|
||||
both('Firewalls cleared', 'firewallsCleared'),
|
||||
both('RAM from captures', 'ramFromCaptures'),
|
||||
both('RAM from salvage', 'ramFromSalvage'),
|
||||
both('RAM spent on Firewalls', 'ramOnFirewalls'),
|
||||
both('RAM spent on cards', 'ramOnCards'),
|
||||
both('Bandwidth from captures', 'bandwidthFromCaptures'),
|
||||
both('Bandwidth from salvage', 'bandwidthFromSalvage'),
|
||||
both('Bandwidth spent on Firewalls', 'bandwidthOnFirewalls'),
|
||||
both('Bandwidth spent on cards', 'bandwidthOnCards'),
|
||||
both('Cards salvaged', 'cardsSalvaged'),
|
||||
both('Hardware installed', 'hardwareInstalled'),
|
||||
both('Hardware lost in combat', 'hardwareLost'),
|
||||
|
|
@ -109,8 +109,8 @@ export function formatSummary(sum: BatchSummary, labels: [string, string]): stri
|
|||
both('Executions played', 'executionsPlayed'),
|
||||
both('Abilities used', 'abilitiesUsed'),
|
||||
both('Combats ended early', 'combatsEnded'),
|
||||
both('RAM from card effects', 'ramFromEffects'),
|
||||
both('RAM spent on Abilities', 'ramOnAbilities'),
|
||||
both('Bandwidth from card effects', 'bandwidthFromEffects'),
|
||||
both('Bandwidth spent on Abilities', 'bandwidthOnAbilities'),
|
||||
both('Cards drawn', 'cardsDrawn'),
|
||||
row('Locations at game end', fmt(sum.locations[0]), fmt(sum.locations[1])),
|
||||
'',
|
||||
|
|
@ -179,7 +179,7 @@ export function formatCardReport(rows: CardReport[]): string {
|
|||
for (const r of rows) {
|
||||
if (r.kind !== kind) {
|
||||
kind = r.kind;
|
||||
out.push(` ${{ avatar: 'Avatars', server: 'Servers', program: 'Programs', hardware: 'Hardware', execution: 'Executions' }[kind] ?? kind}`);
|
||||
out.push(` ${{ anomaly: 'Anomalies', server: 'Servers', program: 'Programs', hardware: 'Hardware', execution: 'Executions' }[kind] ?? kind}`);
|
||||
}
|
||||
const se = r.inDeck ? Math.sqrt((r.deckWinRate * (1 - r.deckWinRate)) / r.inDeck) : 0;
|
||||
out.push(
|
||||
|
|
|
|||
184
sim/src/trace.ts
Normal file
184
sim/src/trace.ts
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* Conformance traces for the Godot port (godot-plan.md §2). Plays games like the CLI and writes one
|
||||
* JSON file per game: the setup, then a fingerprint of every step. A step is the action taken, the
|
||||
* legal actions it was picked from (in order), the state after it, the log lines it added and the
|
||||
* next decider's view. The Godot runner (tests/conformance.gd) replays each file and stops at the
|
||||
* first step that differs. `--full` also writes every state in full, so the runner can name the
|
||||
* field, and `--labels` adds the move-list labels (describe.ts) of the legal actions.
|
||||
*
|
||||
* node src/trace.ts --out ~/test/tests/traces/stage-a --pool stageA -n 200
|
||||
* node src/trace.ts --out /tmp/one --seed 17 -n 1 --full
|
||||
*/
|
||||
import { createHash } from 'node:crypto';
|
||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
import type { BotFactory } from './bots/bot.ts';
|
||||
import { DEFAULT_GREEDY, greedyBot } from './bots/greedy.ts';
|
||||
import { randomBot } from './bots/random.ts';
|
||||
import type { CardDef } from './cards.ts';
|
||||
import { randomDeck } from './deck.ts';
|
||||
import { describeAction } from './describe.ts';
|
||||
import { actionKey, applyAction, createGame, decider, legalActions, viewFor } from './engine.ts';
|
||||
import { DEFAULT_CARDS_CSV, loadCards } from './load.ts';
|
||||
import { makeRng, nextFloat } from './rng.ts';
|
||||
import { DEFAULT_RULES, withRule, type RulesConfig } from './rules.ts';
|
||||
import type { GameState } from './types.ts';
|
||||
|
||||
const BOTS: Record<string, BotFactory> = {
|
||||
random: randomBot,
|
||||
greedy: () => greedyBot(),
|
||||
nocards: () => greedyBot({ ...DEFAULT_GREEDY, useCards: false }),
|
||||
};
|
||||
|
||||
/**
|
||||
* Card lists for decks dealt from part of the pool, so the port can be checked before every card
|
||||
* script is in. Stage A: every Anomaly, plus the Servers and Hardware with simple or no scripts.
|
||||
*/
|
||||
const POOLS: Record<string, string[]> = {
|
||||
stageA: [
|
||||
'Carbon NanoBots', 'Corrupt Driver', 'Pixelated Picture', 'Beta Version 1.0', 'Code Zero', 'Data Leaker',
|
||||
'Backup Machine', 'Broken Bits',
|
||||
'High Bandwidth Server', 'MultiCore Server', 'Cluster Server', 'Power Server', 'Server Farm',
|
||||
'Network Throttle', 'Cloud Compute', 'Pingable Server', 'Protected Server',
|
||||
'RAM Expansion', 'Additional Core', 'Network Interface Upgrade', 'Packet Accelerator',
|
||||
],
|
||||
};
|
||||
|
||||
const { values: opt } = parseArgs({
|
||||
options: {
|
||||
out: { type: 'string' },
|
||||
games: { type: 'string', short: 'n', default: '100' },
|
||||
seed: { type: 'string', default: '1' },
|
||||
south: { type: 'string', default: 'random' },
|
||||
north: { type: 'string', default: 'random' },
|
||||
rule: { type: 'string', multiple: true, default: [] },
|
||||
pool: { type: 'string', default: 'all' },
|
||||
'max-copies': { type: 'string' },
|
||||
full: { type: 'boolean', default: false },
|
||||
labels: { type: 'boolean', default: false },
|
||||
cards: { type: 'string', default: DEFAULT_CARDS_CSV },
|
||||
},
|
||||
});
|
||||
if (!opt.out) {
|
||||
console.error('trace: --out DIR is required');
|
||||
process.exit(1);
|
||||
}
|
||||
for (const b of [opt.south, opt.north]) {
|
||||
if (!BOTS[b]) {
|
||||
console.error(`trace: unknown bot "${b}". Choose from: ${Object.keys(BOTS).join(', ')}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const pool = loadCards(opt.cards);
|
||||
let include: (c: CardDef) => boolean = () => true;
|
||||
let rules: RulesConfig = DEFAULT_RULES;
|
||||
let poolNames: string[] | 'all' = 'all';
|
||||
if (opt.pool !== 'all') {
|
||||
const names = POOLS[opt.pool] ?? opt.pool.split(',');
|
||||
poolNames = names;
|
||||
for (const n of names) if (!pool.byName.has(n)) throw new Error(`trace: unknown card "${n}"`);
|
||||
const set = new Set(names);
|
||||
include = (c) => set.has(c.name);
|
||||
// A small pool needs more copies of each card to fill a deck.
|
||||
rules = { ...rules, deck: { ...rules.deck, maxCopies: 20 } };
|
||||
}
|
||||
if (opt['max-copies']) rules = { ...rules, deck: { ...rules.deck, maxCopies: Number(opt['max-copies']) } };
|
||||
for (const spec of opt.rule) rules = withRule(rules, spec);
|
||||
|
||||
/** JSON with every object's keys sorted and undefined fields dropped, as Godot's JSON.stringify writes it. */
|
||||
function canon(v: unknown): unknown {
|
||||
if (Array.isArray(v)) return v.map(canon);
|
||||
if (v && typeof v === 'object') {
|
||||
const out: Record<string, unknown> = {};
|
||||
for (const k of Object.keys(v).sort()) {
|
||||
const x = (v as Record<string, unknown>)[k];
|
||||
if (x !== undefined) out[k] = canon(x);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
const md5 = (text: string) => createHash('md5').update(text).digest('hex').slice(0, 12);
|
||||
const hash = (v: unknown) => md5(JSON.stringify(canon(v)));
|
||||
/** The state without its card definitions (fixed for the game) and log (checked line by line). */
|
||||
const body = (s: GameState) => ({ ...s, defs: undefined, log: undefined });
|
||||
|
||||
/** The card CSV the traces were made from, so the runner can tell when Godot's copy is stale. */
|
||||
const cardsMd5 = md5(readFileSync(opt.cards, 'utf8'));
|
||||
|
||||
/** Mulberry32's first 10,000 outputs (as 32-bit ints) for a few seeds, hashed. */
|
||||
const RNG_SEEDS = [1, 42, 0x9e3779b9, 4294967295];
|
||||
const rngCheck = md5(RNG_SEEDS.map((seed) => {
|
||||
const r = makeRng(seed);
|
||||
return Array.from({ length: 10_000 }, () => Math.round(nextFloat(r) * 4294967296)).join(',');
|
||||
}).join('\n'));
|
||||
|
||||
const MAX_ACTIONS = 200_000;
|
||||
const first = Number(opt.seed);
|
||||
const games = Number(opt.games);
|
||||
rmSync(opt.out, { recursive: true, force: true });
|
||||
mkdirSync(opt.out, { recursive: true });
|
||||
const started = performance.now();
|
||||
let totalSteps = 0;
|
||||
|
||||
for (let seed = first; seed < first + games; seed++) {
|
||||
const deckRng = makeRng(seed ^ 0x9e3779b9);
|
||||
const decks = [randomDeck(pool, deckRng, rules, include), randomDeck(pool, deckRng, rules, include)] as const;
|
||||
const s = createGame({ pool, decks: [decks[0], decks[1]], seed, rules, log: true });
|
||||
const bots = [BOTS[opt.south](seed * 2 + 1), BOTS[opt.north](seed * 2 + 2)];
|
||||
const steps: Record<string, string>[] = [];
|
||||
const states: unknown[] = [];
|
||||
let logged = s.log!.length;
|
||||
const initial = {
|
||||
state: hash(body(s)),
|
||||
log: hash(s.log),
|
||||
view: s.over ? '' : hash(body(viewFor(s, decider(s)!))),
|
||||
};
|
||||
if (opt.full) states.push(canon(body(s)));
|
||||
while (!s.over) {
|
||||
if (steps.length > MAX_ACTIONS) throw new Error(`Game ${seed} didn't finish`);
|
||||
const p = decider(s)!;
|
||||
const legal = legalActions(s);
|
||||
const action = bots[p].choose(viewFor(s, p), legal, p);
|
||||
const labels = opt.labels ? md5(legal.map((a) => describeAction(s, a)).join('\n')) : '';
|
||||
applyAction(s, action, legal);
|
||||
const step: Record<string, string> = {
|
||||
a: actionKey(action),
|
||||
l: md5(legal.map(actionKey).join('\n')),
|
||||
s: hash(body(s)),
|
||||
g: hash(s.log!.slice(logged)),
|
||||
};
|
||||
logged = s.log!.length;
|
||||
if (labels) step.d = labels;
|
||||
if (!s.over) step.v = hash(body(viewFor(s, decider(s)!)));
|
||||
steps.push(step);
|
||||
if (opt.full) states.push(canon(body(s)));
|
||||
}
|
||||
totalSteps += steps.length;
|
||||
const trace = {
|
||||
version: 1,
|
||||
seed,
|
||||
bots: [opt.south, opt.north],
|
||||
pool: poolNames,
|
||||
cards: cardsMd5,
|
||||
rules,
|
||||
decks,
|
||||
initial,
|
||||
steps,
|
||||
end: { winner: s.winner, turn: s.turn, endReason: s.endReason },
|
||||
...(opt.full ? { states, defs: s.defs } : {}),
|
||||
};
|
||||
writeFileSync(join(opt.out, `game-${seed}.json`), JSON.stringify(trace));
|
||||
}
|
||||
|
||||
writeFileSync(
|
||||
join(opt.out, 'index.json'),
|
||||
JSON.stringify({
|
||||
games, first, bots: [opt.south, opt.north], pool: opt.pool, rules: opt.rule, full: opt.full, labels: opt.labels,
|
||||
cards: cardsMd5, rngSeeds: RNG_SEEDS, rngCheck,
|
||||
}, null, 2),
|
||||
);
|
||||
const seconds = ((performance.now() - started) / 1000).toFixed(1);
|
||||
console.log(`Wrote ${games} traces (${totalSteps} steps) to ${opt.out} in ${seconds}s`);
|
||||
105
sim/src/types.ts
105
sim/src/types.ts
|
|
@ -36,13 +36,13 @@ export interface CardInstance {
|
|||
pushedUntil?: Clock;
|
||||
}
|
||||
|
||||
/** Slots 1–4 are the printed Avatars; slot k + 4 is a copy of Avatar k. */
|
||||
export interface AvatarRef {
|
||||
/** Slots 1–4 are the printed Anomalies; slot k + 4 is a copy of Anomaly k. */
|
||||
export interface AnomalyRef {
|
||||
player: PlayerId;
|
||||
slot: number;
|
||||
}
|
||||
|
||||
/** A temporary Core bonus or penalty on one Avatar. */
|
||||
/** A temporary Core bonus or penalty on one Anomaly. */
|
||||
export interface Modifier {
|
||||
/** Increases with every new modifier, so "most recent" is the highest. */
|
||||
seq: number;
|
||||
|
|
@ -55,24 +55,24 @@ export interface Modifier {
|
|||
until?: Clock;
|
||||
}
|
||||
|
||||
export interface AvatarState {
|
||||
/** Card id, or -1 in a player view where the Avatar is still face down. */
|
||||
export interface AnomalyState {
|
||||
/** Card id, or -1 in a player view where the Anomaly is still face down. */
|
||||
card: number;
|
||||
/** Face up = unlocked. Copies are face up only while they exist. */
|
||||
faceUp: boolean;
|
||||
/** null while the Avatar is in its slot (or, for a copy, doesn't exist). */
|
||||
/** null while the Anomaly is in its slot (or, for a copy, doesn't exist). */
|
||||
at: LocId | null;
|
||||
hardware: number[];
|
||||
/** Health rule: damage taken so far. Cleared when the Avatar leaves play. */
|
||||
/** Health rule: damage taken so far. Cleared when the Anomaly leaves play. */
|
||||
damage: number;
|
||||
/** Placed (entered play or repositioned) this turn. */
|
||||
placed: boolean;
|
||||
advanced: boolean;
|
||||
/** Attacks declared this turn (Infinite Loop allows 2). */
|
||||
attacks: number;
|
||||
/** Removed when the Avatar is defeated. */
|
||||
/** Removed when the Anomaly is defeated. */
|
||||
infection: number;
|
||||
/** Bug counters: like Infection, for Bug cards. Removed when the Avatar is defeated. */
|
||||
/** Bug counters: like Infection, for Bug cards. Removed when the Anomaly is defeated. */
|
||||
bugs: number;
|
||||
/** Persistent Infection counters survive defeat. */
|
||||
permanentInfection: number;
|
||||
|
|
@ -92,14 +92,14 @@ export interface AvatarState {
|
|||
}
|
||||
|
||||
export interface PlayerState {
|
||||
ram: number;
|
||||
bandwidth: number;
|
||||
hand: number[];
|
||||
deck: number[];
|
||||
discard: number[];
|
||||
serverPile: number[];
|
||||
/** Avatar N is avatars[N - 1]; avatars[N + 3] is its copy slot. */
|
||||
avatars: AvatarState[];
|
||||
/** Highest location level captured so far; unlocks Avatars up to this number. */
|
||||
/** Anomaly N is anomalies[N - 1]; anomalies[N + 3] is its copy slot. */
|
||||
anomalies: AnomalyState[];
|
||||
/** Highest location level captured so far; unlocks Anomalies up to this number. */
|
||||
unlockedLevel: number;
|
||||
}
|
||||
|
||||
|
|
@ -116,17 +116,17 @@ export type Step = 'deploy' | 'play' | 'attack' | 'resolve' | 'playAgain';
|
|||
|
||||
export interface Declaration {
|
||||
kind: 'advance' | 'attack';
|
||||
ref: AvatarRef;
|
||||
ref: AnomalyRef;
|
||||
to: LocId;
|
||||
/** Where the attacker stood when it declared. */
|
||||
from: LocId;
|
||||
/** Infinite Loop: this Avatar's second attack this turn. */
|
||||
/** Infinite Loop: this Anomaly's second attack this turn. */
|
||||
second: boolean;
|
||||
}
|
||||
|
||||
/** Parameters of an Execution or ability. Each card uses the fields it needs. */
|
||||
export interface Args {
|
||||
ref?: AvatarRef;
|
||||
ref?: AnomalyRef;
|
||||
card?: number;
|
||||
cards?: number[];
|
||||
to?: LocId;
|
||||
|
|
@ -168,12 +168,12 @@ export interface Combat {
|
|||
id: number;
|
||||
/** The defended location. */
|
||||
loc: LocId;
|
||||
attacker: AvatarRef;
|
||||
attacker: AnomalyRef;
|
||||
/** Where the attacker stands, for its Server bonus. */
|
||||
origin: LocId;
|
||||
defenders: AvatarRef[];
|
||||
defenders: AnomalyRef[];
|
||||
kind: 'attack' | 'advance' | 'traceRoute';
|
||||
/** Dice by Avatar, keyed `player:slot`. */
|
||||
/** Dice by Anomaly, keyed `player:slot`. */
|
||||
dice: Record<string, number[]>;
|
||||
rolled: boolean;
|
||||
/** Ended early (Emergency Shutdown, Disconnect). */
|
||||
|
|
@ -191,7 +191,7 @@ export type Json = unknown;
|
|||
export interface ChoiceOption {
|
||||
label: string;
|
||||
value: Json;
|
||||
/** RAM needed to pick this option. */
|
||||
/** Bandwidth needed to pick this option. */
|
||||
cost?: number;
|
||||
}
|
||||
|
||||
|
|
@ -202,6 +202,8 @@ export interface Choice {
|
|||
kind: string;
|
||||
prompt: string;
|
||||
options: ChoiceOption[];
|
||||
/** The prompt or options name cards only the chooser may see (their deck, a secret pick). */
|
||||
secret?: boolean;
|
||||
/** Script function that receives the picked value. */
|
||||
resume: { name: string; fn: string; data: Json };
|
||||
}
|
||||
|
|
@ -223,7 +225,7 @@ export type HookName =
|
|||
|
||||
/** Something that has an effect in play. */
|
||||
export interface Source {
|
||||
kind: 'server' | 'program' | 'hardware' | 'avatar';
|
||||
kind: 'server' | 'program' | 'hardware' | 'anomaly';
|
||||
/** The card providing it (the original card for copied effects). */
|
||||
id: number;
|
||||
/** Script that runs. Differs from the card for copies (Duplicate Server, Fork...). */
|
||||
|
|
@ -231,8 +233,8 @@ export interface Source {
|
|||
controller: PlayerId;
|
||||
/** Where the effect applies. */
|
||||
at: LocId | null;
|
||||
/** Hardware: its wearer. Avatar: itself. */
|
||||
ref?: AvatarRef;
|
||||
/** Hardware: its wearer. Anomaly: itself. */
|
||||
ref?: AnomalyRef;
|
||||
/** Virtual copy id, or -1 for a Worm Protocol spread. */
|
||||
virtual?: number;
|
||||
}
|
||||
|
|
@ -243,8 +245,8 @@ export type Task =
|
|||
| { t: 'declaration'; index: number }
|
||||
| { t: 'afterResolve' }
|
||||
| { t: 'combat'; stage: 'start' | 'roll' | 'result' | 'end' | 'cleanup' }
|
||||
| { t: 'defeat'; ref: AvatarRef; loc: LocId; role: 'attack' | 'defend' }
|
||||
| { t: 'capture'; ref: AvatarRef; loc: LocId; stage: 'hooks' | 'main'; how: CaptureStat }
|
||||
| { t: 'defeat'; ref: AnomalyRef; loc: LocId; role: 'attack' | 'defend' }
|
||||
| { t: 'capture'; ref: AnomalyRef; loc: LocId; stage: 'hooks' | 'main'; how: CaptureStat }
|
||||
| { t: 'hook'; hook: HookName; src: Source; data: Json }
|
||||
| { t: 'call'; name: string; fn: string; data: Json }
|
||||
| { t: 'draw'; player: PlayerId }
|
||||
|
|
@ -255,7 +257,7 @@ export type Action =
|
|||
| { type: 'pass' }
|
||||
| { type: 'choose'; index: number }
|
||||
| { type: 'place'; slot: number; to: LocId }
|
||||
/** Health rule: return an Avatar in play to its slot as its placement for the round; it heals. */
|
||||
/** Health rule: return an Anomaly in play to its slot as its placement for the round; it heals. */
|
||||
| { type: 'recall'; slot: number }
|
||||
| { type: 'advance'; slot: number; to: LocId }
|
||||
| { type: 'attack'; slot: number; to: LocId }
|
||||
|
|
@ -263,10 +265,10 @@ export type Action =
|
|||
| { type: 'firewall'; line: string; level: number }
|
||||
| { type: 'salvage'; card: number }
|
||||
| { type: 'installHardware'; card: number; slot: number }
|
||||
/** Recruit rule: an Avatar from hand into `slot`, retiring the Avatar there if there is one. */
|
||||
/** Recruit rule: an Anomaly from hand into `slot`, retiring the Anomaly there if there is one. */
|
||||
| { type: 'recruit'; card: number; slot: number }
|
||||
/** Buy-Avatars rule: flip Avatar `slot`, the next face-down one, for its price. */
|
||||
| { type: 'buyAvatar'; slot: number }
|
||||
/** Buy-Anomalies rule: flip Anomaly `slot`, the next face-down one, for its price. */
|
||||
| { type: 'buyAnomaly'; slot: number }
|
||||
| { type: 'installProgram'; card: number; at: LocId }
|
||||
| { type: 'play'; card: number; target: LocId | null; args: Args; from: LocId | null }
|
||||
| { type: 'activate'; card: number; name: string; args: Args };
|
||||
|
|
@ -279,18 +281,18 @@ export const STAT_KEYS = [
|
|||
'attacksWon',
|
||||
'combatsTied',
|
||||
'damageDealt',
|
||||
'avatarsDestroyed',
|
||||
'anomaliesDestroyed',
|
||||
'recalls',
|
||||
'combatsEnded',
|
||||
'firewallsPlaced',
|
||||
'firewallsUpgraded',
|
||||
'firewallsCleared',
|
||||
'ramFromCaptures',
|
||||
'ramFromSalvage',
|
||||
'ramFromEffects',
|
||||
'ramOnFirewalls',
|
||||
'ramOnCards',
|
||||
'ramOnAbilities',
|
||||
'bandwidthFromCaptures',
|
||||
'bandwidthFromSalvage',
|
||||
'bandwidthFromEffects',
|
||||
'bandwidthOnFirewalls',
|
||||
'bandwidthOnCards',
|
||||
'bandwidthOnAbilities',
|
||||
'cardsSalvaged',
|
||||
'cardsDrawn',
|
||||
'hardwareInstalled',
|
||||
|
|
@ -299,10 +301,10 @@ export const STAT_KEYS = [
|
|||
'programsLost',
|
||||
'executionsPlayed',
|
||||
'abilitiesUsed',
|
||||
'avatarsRecruited',
|
||||
'avatarsRetired',
|
||||
'avatarsBought',
|
||||
'ramOnAvatars',
|
||||
'anomaliesRecruited',
|
||||
'anomaliesRetired',
|
||||
'anomaliesBought',
|
||||
'bandwidthOnAnomalies',
|
||||
] as const;
|
||||
|
||||
export type StatKey = (typeof STAT_KEYS)[number];
|
||||
|
|
@ -315,6 +317,25 @@ export interface CardUse {
|
|||
fired: [number, number];
|
||||
}
|
||||
|
||||
/** What a log line is about, for filtering. Untagged lines are card effects. */
|
||||
export type LogTag = 'game' | 'turn' | 'move' | 'combat' | 'capture' | 'card' | 'firewall' | 'choice';
|
||||
|
||||
/**
|
||||
* A play-by-play line. A line with `to` names cards only that player may see: they read `text`,
|
||||
* and the other player reads `public` instead. The other fields say what it's about, for apps.
|
||||
*/
|
||||
export interface LogLine {
|
||||
text: string;
|
||||
to?: PlayerId;
|
||||
public?: string;
|
||||
tag?: LogTag;
|
||||
player?: PlayerId;
|
||||
loc?: LocId;
|
||||
/** The Anomaly it's about; with `amount`, the damage it took. */
|
||||
ref?: AnomalyRef;
|
||||
amount?: number;
|
||||
}
|
||||
|
||||
export interface GameState {
|
||||
rules: RulesConfig;
|
||||
rng: Rng;
|
||||
|
|
@ -345,8 +366,8 @@ export interface GameState {
|
|||
endReason: 'win' | 'turnLimit' | null;
|
||||
stats: GameStats;
|
||||
cardUse: Record<string, CardUse>;
|
||||
/** Play-by-play text, when logging is on. */
|
||||
log: string[] | null;
|
||||
/** Play-by-play, when logging is on. Read it with logFor. */
|
||||
log: LogLine[] | null;
|
||||
/** Dice results to use before the RNG. Tests set this to script a combat. */
|
||||
rigged?: number[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { avatarCores, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, openWindow } from '../src/engine.ts';
|
||||
import { hasRoom } from '../src/query.ts';
|
||||
import { withRule } from '../src/rules.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
/** South's Avatar 1 (`south`) on B1 attacks North's Avatar 1 (`north`) on C1. */
|
||||
/** South's Anomaly 1 (`south`) on B1 attacks North's Anomaly 1 (`north`) on C1. */
|
||||
function scene(south: string, north: string, o: { south?: Side; north?: Side } = {}) {
|
||||
const others = ['Broken Bits', 'Pixelated Picture', 'Corrupt Driver', 'Code Zero', 'Beta Version 1.0', 'Data Leaker'];
|
||||
const four = (first: string) => [first, ...others.filter((n) => n !== first)].slice(0, 4);
|
||||
const t = new Table({ south: { ...o.south, avatars: four(south) }, north: { ...o.north, avatars: four(north) } });
|
||||
const t = new Table({ south: { ...o.south, anomalies: four(south) }, north: { ...o.north, anomalies: four(north) } });
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.place(0, 1, 'B1');
|
||||
|
|
@ -22,30 +22,30 @@ const dice = (t: Table, side: 'atk' | 'def') => {
|
|||
const m = t.logText().match(/Roll: \S+(?: \S+)* \[([\d,]*)\]=\d+ vs \S+(?: \S+)* \[([\d,]*)\]/)!;
|
||||
return m[side === 'atk' ? 1 : 2].split(',').length;
|
||||
};
|
||||
const avatarCard = (t: Table, p: 0 | 1, slot: number) => t.avatar(p, slot).card;
|
||||
const anomalyCard = (t: Table, p: 0 | 1, slot: number) => t.anomaly(p, slot).card;
|
||||
|
||||
card('Carbon NanoBots', () => {
|
||||
const t = scene('Carbon NanoBots', 'Broken Bits', { south: { main: ['Additional Core'] } });
|
||||
t.own(0, 'A2');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.ram(0, 6).use(avatarCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.avatar(0, 5).at, 'A2', 'the copy is in play');
|
||||
assert.equal(avatarCores(t.s, 0, 5, 'defend'), 3, "2 Cores + the original's Additional Core");
|
||||
t.bandwidth(0, 6).use(anomalyCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.anomaly(0, 5).at, 'A2', 'the copy is in play');
|
||||
assert.equal(anomalyCores(t.s, 0, 5, 'defend'), 3, "2 Cores + the original's Additional Core");
|
||||
// The copy attacks and loses: the original keeps its Hardware.
|
||||
t.place(0, 1, 'S1');
|
||||
t.s.players[0].avatars[4].at = 'B1';
|
||||
t.s.players[0].anomalies[4].at = 'B1';
|
||||
t.to('attack').go({ type: 'attack', slot: 5, to: 'C1' });
|
||||
t.rig(1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 5).at, null);
|
||||
assert.equal(t.avatar(0, 1).hardware.length, 1);
|
||||
assert.equal(t.anomaly(0, 5).at, null);
|
||||
assert.equal(t.anomaly(0, 1).hardware.length, 1);
|
||||
});
|
||||
|
||||
test('copy rule variants: a new copy defends but only advances or attacks from its next turn', () => {
|
||||
const t = scene('Carbon NanoBots', 'Broken Bits');
|
||||
t.s.rules = withRule(t.s.rules, 'copies.waitATurn=true');
|
||||
t.own(0, 'A2');
|
||||
t.ram(0, 6).use(avatarCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.avatar(0, 5).at, 'A2', 'the copy is in play, defending A2');
|
||||
t.bandwidth(0, 6).use(anomalyCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.anomaly(0, 5).at, 'A2', 'the copy is in play, defending A2');
|
||||
const acts = () => t.legal().filter((a) => (a.type === 'advance' || a.type === 'attack') && a.slot === 5);
|
||||
assert.deepEqual(acts(), []);
|
||||
assert.ok(t.legal().some((a) => a.type === 'advance' && a.slot === 1), 'the original still can');
|
||||
|
|
@ -55,15 +55,15 @@ test('copy rule variants: a new copy defends but only advances or attacks from i
|
|||
assert.ok(acts().length > 0, 'next turn it can advance');
|
||||
});
|
||||
|
||||
test('copy rule variants: copies can need Avatar 2 unlocked, or be off', () => {
|
||||
test('copy rule variants: copies can need Anomaly 2 unlocked, or be off', () => {
|
||||
const t = scene('Carbon NanoBots', 'Broken Bits');
|
||||
t.own(0, 'A2');
|
||||
t.ram(0, 6);
|
||||
t.bandwidth(0, 6);
|
||||
const replicate = () => t.legal().some((a) => a.type === 'activate' && a.name === 'Carbon NanoBots');
|
||||
assert.ok(replicate());
|
||||
t.s.rules = withRule(t.s.rules, 'copies.needAvatar2=true');
|
||||
assert.ok(!replicate(), 'Avatar 2 is still face down');
|
||||
t.avatar(0, 2).faceUp = true;
|
||||
t.s.rules = withRule(t.s.rules, 'copies.needAnomaly2=true');
|
||||
assert.ok(!replicate(), 'Anomaly 2 is still face down');
|
||||
t.anomaly(0, 2).faceUp = true;
|
||||
assert.ok(replicate());
|
||||
t.s.rules = withRule(t.s.rules, 'copies.allowed=false');
|
||||
assert.ok(!replicate());
|
||||
|
|
@ -73,7 +73,7 @@ test('no copy can enter a location while a combat is going on there', () => {
|
|||
const t = scene('Broken Bits', 'Carbon NanoBots', { north: { servers: ['Cluster Server'] } });
|
||||
t.own(1, 'C1', 'Cluster Server');
|
||||
assert.ok(hasRoom(t.s, 1, 'C1'), 'the Cluster Server has room for a second defender');
|
||||
t.ram(1, 6);
|
||||
t.bandwidth(1, 6);
|
||||
fight(t);
|
||||
assert.ok(t.s.combat, 'North can Replicate, so the combat stops for a response');
|
||||
assert.ok(!hasRoom(t.s, 1, 'C1'));
|
||||
|
|
@ -82,21 +82,21 @@ test('no copy can enter a location while a combat is going on there', () => {
|
|||
card('Corrupt Driver', () => {
|
||||
const t = scene('Corrupt Driver', 'Broken Bits', { north: { main: ['Additional Core'] } });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
fight(t);
|
||||
t.rig(1, 1, 1, 6, 6, 6, 6);
|
||||
t.use(avatarCard(t, 0, 1), { card: hw }).settle();
|
||||
t.use(anomalyCard(t, 0, 1), { card: hw }).settle();
|
||||
assert.equal(dice(t, 'def'), 4, 'the Additional Core is off');
|
||||
assert.ok(t.s.cards[hw].disabledUntil > t.s.clock);
|
||||
});
|
||||
|
||||
card('Pixelated Picture', () => {
|
||||
const t = scene('Broken Bits', 'Pixelated Picture');
|
||||
t.ram(1, 3);
|
||||
t.bandwidth(1, 3);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.rig(6, 6, 6, 1, 1, 1);
|
||||
t.use(avatarCard(t, 1, 1)).settle();
|
||||
t.use(anomalyCard(t, 1, 1)).settle();
|
||||
assert.equal(dice(t, 'atk'), 3, 'the attacker has -1 Core');
|
||||
});
|
||||
|
||||
|
|
@ -105,23 +105,23 @@ card('Beta Version 1.0', () => {
|
|||
t.hardware(0, 1, 'Overclocked CPU');
|
||||
t.hardware(0, 1, 'Packet Accelerator');
|
||||
const [ac] = t.hand(0, 'Additional Core');
|
||||
t.ram(0, 4 + 5);
|
||||
t.bandwidth(0, 4 + 5);
|
||||
fight(t);
|
||||
t.rig(6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.use(avatarCard(t, 0, 1), { card: ac }).settle();
|
||||
assert.equal(dice(t, 'atk'), 4 + 2 + 1 + 1, 'a third Hardware on a 2-port Avatar');
|
||||
t.use(anomalyCard(t, 0, 1), { card: ac }).settle();
|
||||
assert.equal(dice(t, 'atk'), 4 + 2 + 1 + 1, 'a third Hardware on a 2-slot Anomaly');
|
||||
t.to('playAgain').end();
|
||||
assert.ok(t.s.players[0].discard.includes(ac), 'gone at the end of the turn');
|
||||
});
|
||||
|
||||
card('Code Zero', () => {
|
||||
const t = scene('Broken Bits', 'Code Zero');
|
||||
t.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.rig(6, 6, 6, 1, 1, 1);
|
||||
t.use(avatarCard(t, 1, 1)).settle();
|
||||
assert.equal(t.avatar(0, 1).infection >= 1 || t.avatar(0, 1).at === null, true);
|
||||
t.use(anomalyCard(t, 1, 1)).settle();
|
||||
assert.equal(t.anomaly(0, 1).infection >= 1 || t.anomaly(0, 1).at === null, true);
|
||||
assert.equal(dice(t, 'atk'), 3, '1 Infection counter: -1 Core while Code Zero is in play');
|
||||
assert.equal(dice(t, 'def'), 3, 'Code Zero has 3 Cores');
|
||||
});
|
||||
|
|
@ -130,16 +130,16 @@ card('Data Leaker', () => {
|
|||
const t = scene('Data Leaker', 'Broken Bits', { south: { main: ['Additional Core'] }, north: { main: ['Cooling System', 'Hotfix'] } });
|
||||
const [cool] = t.hand(1, 'Cooling System', 'Hotfix');
|
||||
t.top(0, 'Additional Core');
|
||||
t.ram(0, 3);
|
||||
t.bandwidth(0, 3);
|
||||
// Breach first: take an undefended enemy location this turn.
|
||||
t.own(1, 'C2');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, 0);
|
||||
t.use(avatarCard(t, 0, 1));
|
||||
t.use(anomalyCard(t, 0, 1));
|
||||
assert.equal(t.s.choice?.kind, 'Data Leaker:discard');
|
||||
t.choose('Cooling System').settle();
|
||||
assert.ok(t.s.players[1].discard.includes(cool));
|
||||
assert.equal(t.s.players[1].ram, 0, 'no RAM for the discard');
|
||||
assert.equal(t.s.players[1].bandwidth, 0, 'no Bandwidth for the discard');
|
||||
assert.equal(t.s.players[0].hand.length, 1, 'it breached this turn, so it draws');
|
||||
});
|
||||
|
||||
|
|
@ -147,21 +147,21 @@ card('Backup Machine', () => {
|
|||
const t = scene('Backup Machine', 'Broken Bits', { south: { main: ['Additional Core'] } });
|
||||
const ac = t.take(0, 'Additional Core');
|
||||
t.s.players[0].discard.push(ac);
|
||||
t.ram(0, 5 + 3).use(avatarCard(t, 0, 1), { card: ac });
|
||||
t.bandwidth(0, 5 + 3).use(anomalyCard(t, 0, 1), { card: ac });
|
||||
assert.equal(t.s.choice?.kind, 'Backup Machine:install');
|
||||
t.choose('Install').settle();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [ac]);
|
||||
assert.equal(t.s.players[0].ram, 0, '5 for the Ability, 5 - 2 for the Hardware');
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [ac]);
|
||||
assert.equal(t.s.players[0].bandwidth, 0, '5 for the Ability, 5 - 2 for the Hardware');
|
||||
});
|
||||
|
||||
card('Broken Bits', () => {
|
||||
const t = scene('Broken Bits', 'Broken Bits');
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
t.rig(1, 1, 2, 2, 3, 3, 3, 3);
|
||||
fight(t);
|
||||
assert.equal(openWindow(t.s)?.kind, 'postRoll', 'nothing to do before the roll');
|
||||
t.rig(6, 6, 6, 6);
|
||||
t.use(avatarCard(t, 0, 1), { k: 2 }).settle();
|
||||
t.use(anomalyCard(t, 0, 1), { k: 2 }).settle();
|
||||
assert.match(t.logText(), /Bit Flip rerolls 4 dice/);
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
});
|
||||
103
sim/test/app.test.ts
Normal file
103
sim/test/app.test.ts
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/** What the app needs from the sim: action labels, private log lines, Cores breakdowns. */
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import type { Bot } from '../src/bots/bot.ts';
|
||||
import { greedyBot } from '../src/bots/greedy.ts';
|
||||
import { randomBot } from '../src/bots/random.ts';
|
||||
import { randomDeck } from '../src/deck.ts';
|
||||
import { describeAction } from '../src/describe.ts';
|
||||
import { actionKey, applyAction, createGame, decider, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { coresOf, fighterOf, type CorePart } from '../src/query.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES, withRule, type RulesConfig } from '../src/rules.ts';
|
||||
import { fightersOf, logFor, nameOf, programLocation, wearerOf } from '../src/state.ts';
|
||||
import type { Action, GameState } from '../src/types.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
||||
/** Plays a game, calling `each` at every decision with the legal actions. */
|
||||
function play(seed: number, bots: [Bot, Bot], each: (s: GameState, legal: Action[]) => void, rules: RulesConfig = DEFAULT_RULES): GameState {
|
||||
const rng = makeRng(seed ^ 0x9e3779b9);
|
||||
const s = createGame({ pool, decks: [randomDeck(pool, rng, rules), randomDeck(pool, rng, rules)], seed, rules, log: true });
|
||||
for (let n = 0; !s.over && n < 50_000; n++) {
|
||||
const p = decider(s)!;
|
||||
const legal = legalActions(s);
|
||||
each(s, legal);
|
||||
applyAction(s, bots[p].choose(viewFor(s, p), legal, p), legal);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two actions are the same move when they differ only in which of two same-named cards in the same
|
||||
* place they use: salvaging either copy in hand, swapping out either of two identical Hardware.
|
||||
*/
|
||||
function sameMove(s: GameState, a: Action, b: Action): boolean {
|
||||
const where = (id: number) => {
|
||||
const wearer = wearerOf(s, id);
|
||||
return `${nameOf(s, id)}@${programLocation(s, id) ?? (wearer ? `${wearer.player}:${wearer.slot}` : zoneOf(s, id))}`;
|
||||
};
|
||||
const canon = (x: Action) =>
|
||||
JSON.stringify(x, (k, v) => (['card', 'cards'].includes(k) ? (Array.isArray(v) ? v.map(where) : typeof v === 'number' ? where(v) : v) : v));
|
||||
return canon(a) === canon(b);
|
||||
}
|
||||
|
||||
const zoneOf = (s: GameState, id: number): string => {
|
||||
const pl = s.players[s.cards[id].owner];
|
||||
return pl.hand.includes(id) ? 'hand' : pl.discard.includes(id) ? 'discard' : 'elsewhere';
|
||||
};
|
||||
|
||||
function checkLabels(s: GameState, legal: Action[]): void {
|
||||
const seen = new Map<string, Action>();
|
||||
for (const a of legal) {
|
||||
const label = describeAction(s, a);
|
||||
assert.ok(label.length > 0, `empty label for ${actionKey(a)}`);
|
||||
assert.ok(!label.includes('undefined') && !label.includes('NaN'), `bad label "${label}" for ${actionKey(a)}`);
|
||||
const prev = seen.get(label);
|
||||
if (prev && !sameMove(s, prev, a)) assert.fail(`"${label}" labels both ${actionKey(prev)} and ${actionKey(a)} (turn ${s.turn})`);
|
||||
seen.set(label, a);
|
||||
}
|
||||
}
|
||||
|
||||
test('every legal action gets a label, and no two moves in a decision share one', () => {
|
||||
for (let seed = 1; seed <= 60; seed++) play(seed, [randomBot(seed * 2), randomBot(seed * 2 + 1)], checkLabels);
|
||||
for (let seed = 1; seed <= 30; seed++) play(seed, [greedyBot(), greedyBot()], checkLabels);
|
||||
for (const spec of ['recruit.on=true', 'buyAnomalies.on=true', 'commands.on=false']) {
|
||||
const rules = withRule(DEFAULT_RULES, spec);
|
||||
for (let seed = 1; seed <= 10; seed++) play(seed, [randomBot(seed * 2), randomBot(seed * 2 + 1)], checkLabels, rules);
|
||||
}
|
||||
});
|
||||
|
||||
test("a player's log never names the other player's secret choices", () => {
|
||||
let secrets = 0;
|
||||
for (let seed = 1; seed <= 80; seed++) {
|
||||
const s = play(seed, [greedyBot(), greedyBot()], () => {});
|
||||
for (const l of s.log!) if (l.to !== undefined) secrets++;
|
||||
for (const p of [0, 1] as const) {
|
||||
const mine = logFor(s, p);
|
||||
s.log!.forEach((l, i) => {
|
||||
if (l.to === undefined) assert.equal(mine[i], l.text);
|
||||
else assert.equal(mine[i], l.to === p ? l.text : l.public);
|
||||
});
|
||||
}
|
||||
}
|
||||
assert.ok(secrets > 0, 'no secret lines came up; the check tested nothing');
|
||||
});
|
||||
|
||||
test('a Cores breakdown adds up to the total', () => {
|
||||
let combats = 0;
|
||||
for (let seed = 1; seed <= 20; seed++) {
|
||||
play(seed, [greedyBot(), greedyBot()], (s) => {
|
||||
if (!s.combat || s.combat.ended) return;
|
||||
combats++;
|
||||
for (const r of fightersOf(s.combat)) {
|
||||
const parts: CorePart[] = [];
|
||||
const total = coresOf(s, fighterOf(s, r), undefined, parts);
|
||||
assert.equal(parts[0].kind, 'anomaly');
|
||||
assert.equal(Math.max(1, parts.reduce((t, x) => t + x.cores, 0)), total);
|
||||
}
|
||||
});
|
||||
}
|
||||
assert.ok(combats > 50);
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { randomDeck, validateDeck } from '../src/deck.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES } from '../src/rules.ts';
|
||||
|
|
@ -11,14 +11,14 @@ const pool = loadCards();
|
|||
|
||||
test('cards.csv loads every playable card', () => {
|
||||
const count = (kind: string) => pool.all.filter((c) => c.kind === kind).length;
|
||||
assert.equal(count('avatar'), 8);
|
||||
assert.equal(count('anomaly'), 8);
|
||||
assert.equal(count('server'), 13);
|
||||
assert.equal(count('program'), 28);
|
||||
assert.equal(count('hardware'), 16);
|
||||
assert.equal(count('execution'), 18);
|
||||
assert.equal(pool.byName.get('Broken Bits')?.cores, 4);
|
||||
assert.equal(pool.byName.get('Carbon NanoBots')?.slots, 4);
|
||||
assert.equal(pool.byName.get('Quantum Coprocessor')?.ram, 9);
|
||||
assert.equal(pool.byName.get('Quantum Coprocessor')?.bandwidth, 9);
|
||||
});
|
||||
|
||||
test('every card has a script written for its current text', () => {
|
||||
|
|
@ -37,7 +37,7 @@ test('every card has its own test', () => {
|
|||
test('set 2 loads on request, is well formed, and is unscripted', () => {
|
||||
const two = loadCards(undefined, [2]);
|
||||
const count = (kind: string) => two.all.filter((c) => c.kind === kind).length;
|
||||
assert.equal(count('avatar'), 12);
|
||||
assert.equal(count('anomaly'), 12);
|
||||
assert.equal(count('server'), 7);
|
||||
assert.equal(count('program'), 17);
|
||||
assert.equal(count('hardware'), 8);
|
||||
|
|
@ -46,16 +46,16 @@ test('set 2 loads on request, is well formed, and is unscripted', () => {
|
|||
assert.equal(c.set, 2, c.name);
|
||||
assert.ok(!pool.byName.has(c.name), `${c.name} clashes with a set 1 card`);
|
||||
assert.ok(c.text || c.ability, `${c.name} has text`);
|
||||
if (c.kind === 'avatar') {
|
||||
if (c.kind === 'anomaly') {
|
||||
assert.equal(c.cores + c.slots, 6, `${c.name}: Cores + Slots = 6`);
|
||||
assert.equal(c.health, { 4: 9, 3: 10, 2: 12 }[c.cores], `${c.name}: Health by Cores`);
|
||||
assert.ok(c.type && c.ability && c.ability.cost >= 3 && c.ability.cost <= 5, `${c.name}: typed, Ability 3-5 RAM`);
|
||||
assert.ok(c.type && c.ability && c.ability.cost >= 3 && c.ability.cost <= 5, `${c.name}: typed, Ability 3-5 Gb`);
|
||||
} else if (c.kind === 'program') {
|
||||
assert.ok(c.type && c.ram >= 4 && c.ram <= 6, `${c.name}: typed, 4-6 RAM`);
|
||||
assert.ok(c.type && c.bandwidth >= 4 && c.bandwidth <= 6, `${c.name}: typed, 4-6 Gb`);
|
||||
} else if (c.kind === 'execution') {
|
||||
assert.ok(c.ram >= 3 && c.ram <= 5, `${c.name}: 3-5 RAM`);
|
||||
assert.ok(c.bandwidth >= 3 && c.bandwidth <= 5, `${c.name}: 3-5 Gb`);
|
||||
} else if (c.kind === 'hardware') {
|
||||
assert.ok(c.ram >= 4 && c.ram <= 7, `${c.name}: 4-7 RAM`);
|
||||
assert.ok(c.bandwidth >= 4 && c.bandwidth <= 7, `${c.name}: 4-7 Gb`);
|
||||
}
|
||||
}
|
||||
const all = loadCards(undefined, 'all');
|
||||
|
|
@ -76,7 +76,7 @@ test('deck validation catches size, kind and copy problems', () => {
|
|||
const deck = randomDeck(pool, makeRng(1), DEFAULT_RULES);
|
||||
deck.main[0] = deck.main[1] = deck.main[2] = 'Execute: Fork';
|
||||
deck.servers.pop();
|
||||
deck.avatars[0] = 'Cloud Compute';
|
||||
deck.anomalies[0] = 'Cloud Compute';
|
||||
const errors = validateDeck(pool, deck, DEFAULT_RULES).join('\n');
|
||||
assert.match(errors, /Servers: 19 cards/);
|
||||
assert.match(errors, /"Cloud Compute" is a server/);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { randomDeck } from '../src/deck.ts';
|
||||
import { advanceTargets, avatarCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { advanceTargets, anomalyCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES, withRule, type RulesConfig } from '../src/rules.ts';
|
||||
|
|
@ -19,9 +19,9 @@ test('setup follows rules.md', () => {
|
|||
const pl = s.players[p];
|
||||
assert.ok(pl.hand.length >= 7, 'opening hand');
|
||||
assert.equal(pl.serverPile.length, 19);
|
||||
assert.ok(pl.ram >= 4);
|
||||
assert.deepEqual(pl.avatars.slice(0, 4).map((a) => a.faceUp), [true, false, false, false]);
|
||||
assert.ok(pl.avatars.slice(4).every((a) => !a.faceUp && a.at === null), 'no copies yet');
|
||||
assert.ok(pl.bandwidth >= 4);
|
||||
assert.deepEqual(pl.anomalies.slice(0, 4).map((a) => a.faceUp), [true, false, false, false]);
|
||||
assert.ok(pl.anomalies.slice(4).every((a) => !a.faceUp && a.at === null), 'no copies yet');
|
||||
assert.equal(s.locations[p === 0 ? 'S1' : 'S2'].owner, p);
|
||||
}
|
||||
assert.equal(s.turn, 1);
|
||||
|
|
@ -62,53 +62,53 @@ test('rule variants: more cards per draw step', () => {
|
|||
assert.equal(t.s.players[1].hand.length, 2);
|
||||
});
|
||||
|
||||
test('advancing captures an unowned location in step 5 and pays 4 RAM; Lv 1 unlocks nothing', () => {
|
||||
test('advancing captures an unowned location in step 5 and pays 4 Gb; Lv 1 unlocks nothing', () => {
|
||||
const t = new Table();
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
assert.deepEqual(advanceTargets(t.s, 0), ['A2']);
|
||||
t.go({ type: 'place', slot: 1, to: 'S1' }).go({ type: 'advance', slot: 1, to: 'A2' });
|
||||
t.to('attack');
|
||||
assert.equal(t.s.locations.A2.owner, null);
|
||||
t.end();
|
||||
assert.equal(t.s.locations.A2.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'A2');
|
||||
assert.equal(t.s.players[0].ram, 8, '4 RAM + 4 for the capture');
|
||||
assert.equal(t.avatar(0, 2).faceUp, false, 'A2 is Lv 1 for South');
|
||||
assert.equal(t.anomaly(0, 1).at, 'A2');
|
||||
assert.equal(t.s.players[0].bandwidth, 8, '4 Gb + 4 for the capture');
|
||||
assert.equal(t.anomaly(0, 2).faceUp, false, 'A2 is Lv 1 for South');
|
||||
assert.equal(t.s.step, 'playAgain');
|
||||
});
|
||||
|
||||
test('the second row (Lv 2) unlocks Avatar 2; the middle row (Lv 3) unlocks Avatars 2 and 3', () => {
|
||||
test('the second row (Lv 2) unlocks Anomaly 2; the middle row (Lv 3) unlocks Anomalies 2 and 3', () => {
|
||||
for (const [from, to, unlocked] of [['A2', 'B1', [true, false]], ['B1', 'C2', [true, true]]] as const) {
|
||||
const t = new Table();
|
||||
t.own(0, from);
|
||||
t.place(0, 1, from);
|
||||
t.go({ type: 'advance', slot: 1, to }).to('attack').end();
|
||||
assert.equal(t.s.locations[to].owner, 0);
|
||||
assert.deepEqual([t.avatar(0, 2).faceUp, t.avatar(0, 3).faceUp], unlocked, to);
|
||||
assert.deepEqual([t.anomaly(0, 2).faceUp, t.anomaly(0, 3).faceUp], unlocked, to);
|
||||
}
|
||||
});
|
||||
|
||||
test('rule variants: a turn-1 capture can pay no RAM and unlock nothing', () => {
|
||||
test('rule variants: a turn-1 capture can pay no Bandwidth and unlock nothing', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'firstTurn.captureRam=false'), 'firstTurn.unlock=false');
|
||||
t.ram(0, 4).own(0, 'A2');
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'firstTurn.captureBandwidth=false'), 'firstTurn.unlock=false');
|
||||
t.bandwidth(0, 4).own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
t.go({ type: 'advance', slot: 1, to: 'B1' }).to('attack').end();
|
||||
assert.equal(t.s.locations.B1.owner, 0);
|
||||
assert.equal(t.s.players[0].ram, 4);
|
||||
assert.equal(t.avatar(0, 2).faceUp, false);
|
||||
assert.equal(t.s.players[0].bandwidth, 4);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, false);
|
||||
});
|
||||
|
||||
test('rule variants: the first player can be barred from playing cards on turn 1', () => {
|
||||
const t = new Table({ south: { main: ['Additional Core'] }, north: { main: ['Additional Core'] } });
|
||||
t.s.rules = withRule(t.s.rules, 'firstTurn.cards=false');
|
||||
t.hand(0, 'Additional Core');
|
||||
t.ram(0, 9).place(0, 1, 'S1');
|
||||
t.bandwidth(0, 9).place(0, 1, 'S1');
|
||||
t.to('playAgain');
|
||||
assert.ok(!t.legal().some((a) => a.type === 'installHardware'));
|
||||
t.end();
|
||||
t.hand(1, 'Additional Core');
|
||||
t.ram(1, 9).place(1, 1, 'S2');
|
||||
t.bandwidth(1, 9).place(1, 1, 'S2');
|
||||
t.to('playAgain');
|
||||
assert.ok(t.legal().some((a) => a.type === 'installHardware'), 'the second player can on turn 2');
|
||||
});
|
||||
|
|
@ -136,21 +136,21 @@ test('a Firewall blocks movement until someone pays to clear it', () => {
|
|||
const t = new Table();
|
||||
t.own(0, 'A2');
|
||||
t.s.firewalls['A1-A2'] = 2;
|
||||
t.ram(0, 4).go({ type: 'place', slot: 1, to: 'S1' });
|
||||
t.bandwidth(0, 4).go({ type: 'place', slot: 1, to: 'S1' });
|
||||
assert.ok(!advanceTargets(t.s, 0).includes('A1'));
|
||||
assert.ok(!t.can({ type: 'advance', slot: 1, to: 'A1' }));
|
||||
t.go({ type: 'clearFirewall', line: 'A1-A2' });
|
||||
assert.equal(t.s.players[0].ram, 0, 'clearing a Lv 2 Firewall costs 4');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'clearing a Lv 2 Firewall costs 4');
|
||||
assert.ok(advanceTargets(t.s, 0).includes('A1'));
|
||||
});
|
||||
|
||||
test('Firewalls go only on gateways, and upgrades cost the full price of the new level', () => {
|
||||
const t = new Table({ south: { servers: ['Upgraded Hardware'] } });
|
||||
t.own(0, 'A2', 'Upgraded Hardware');
|
||||
t.ram(0, 20).to('play');
|
||||
t.bandwidth(0, 20).to('play');
|
||||
assert.ok(!t.can({ type: 'firewall', line: 'S1-A2', level: 1 }));
|
||||
t.go({ type: 'firewall', line: 'A1-A2', level: 1 }).go({ type: 'firewall', line: 'A1-A2', level: 2 });
|
||||
assert.equal(t.s.players[0].ram, 20 - 2 - 4);
|
||||
assert.equal(t.s.players[0].bandwidth, 20 - 2 - 4);
|
||||
assert.equal(t.s.firewalls['A1-A2'], 2);
|
||||
});
|
||||
|
||||
|
|
@ -163,21 +163,21 @@ test('combat: the loser goes back to its slot and loses its Hardware; the winner
|
|||
t.place(1, 1, 'C1');
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 4);
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, '4 Cores + Additional Core');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 4);
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, '4 Cores + Additional Core');
|
||||
t.rig(...(attackerWins ? [6, 6, 6, 6, 1, 1, 1, 1, 1] : [1, 1, 1, 1, 6, 6, 6, 6, 6]));
|
||||
t.end();
|
||||
if (attackerWins) {
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.avatar(1, 1).at, null);
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, []);
|
||||
assert.equal(t.anomaly(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, []);
|
||||
assert.ok(t.s.players[1].discard.includes(hw));
|
||||
assert.equal(t.s.stats.attacksWon[0], 1);
|
||||
} else {
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, [hw]);
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, [hw]);
|
||||
}
|
||||
assert.equal(t.s.stats.attacks[0], 1);
|
||||
}
|
||||
|
|
@ -222,15 +222,15 @@ test('reaching the location target wins immediately', () => {
|
|||
assert.deepEqual(legalActions(t.s), []);
|
||||
});
|
||||
|
||||
test('Salvage pays full printed RAM, from hand only', () => {
|
||||
test('Salvage pays full printed Bandwidth, from hand only', () => {
|
||||
const t = new Table({ south: { main: ['Cooling System'] } });
|
||||
const [card] = t.hand(0, 'Cooling System');
|
||||
t.go({ type: 'salvage', card });
|
||||
assert.equal(t.s.players[0].ram, 6);
|
||||
assert.equal(t.s.players[0].bandwidth, 6);
|
||||
assert.ok(t.s.players[0].discard.includes(card));
|
||||
});
|
||||
|
||||
test('views hide the opponent hand, both decks, face-down Avatars and the RNG', () => {
|
||||
test('views hide the opponent hand, both decks, face-down Anomalies and the RNG', () => {
|
||||
const t = new Table({ south: { main: ['Additional Core'] }, north: { main: ['Additional Core'] } });
|
||||
t.hand(0, 'Additional Core');
|
||||
t.hand(1, 'Additional Core');
|
||||
|
|
@ -239,8 +239,8 @@ test('views hide the opponent hand, both decks, face-down Avatars and the RNG',
|
|||
assert.deepEqual(v.players[0].hand, t.s.players[0].hand);
|
||||
assert.ok(v.players[0].deck.every((id) => id === -1));
|
||||
assert.ok(v.players[1].serverPile.every((id) => id === -1));
|
||||
assert.equal(v.players[0].avatars[1].card, -1);
|
||||
assert.equal(v.players[1].avatars[1].card, -1);
|
||||
assert.equal(v.players[0].anomalies[1].card, -1);
|
||||
assert.equal(v.players[1].anomalies[1].card, -1);
|
||||
assert.equal(v.rng.s, 0);
|
||||
assert.notEqual(t.s.rng.s, 0);
|
||||
});
|
||||
|
|
@ -259,9 +259,9 @@ test('an opponent with a response gets a window after a declaration; without one
|
|||
t.place(0, 1, 'S1');
|
||||
t.place(0, 2, 'A2');
|
||||
t.act({ type: 'advance', slot: 1, to: 'A1' });
|
||||
assert.equal(t.decider, 0, 'North has no RAM, so no window');
|
||||
assert.equal(t.decider, 0, 'North has no Bandwidth, so no window');
|
||||
t.hand(1, 'Execute: Ping Sweep');
|
||||
t.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
t.act({ type: 'advance', slot: 2, to: 'A3' });
|
||||
assert.equal(t.decider, 1, 'North may respond');
|
||||
t.act({ type: 'pass' });
|
||||
|
|
@ -269,17 +269,17 @@ test('an opponent with a response gets a window after a declaration; without one
|
|||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Recruit rule (prototype): Avatars in the deck, bought with RAM
|
||||
// Recruit rule (prototype): Anomalies in the deck, bought with Bandwidth
|
||||
|
||||
/** A table under the recruit rule: Avatar 1 stays, Avatars 2–4 move to their owner's hand, priced at 6 RAM. */
|
||||
/** A table under the recruit rule: Anomaly 1 stays, Anomalies 2–4 move to their owner's hand, priced at 6 Gb. */
|
||||
function recruitTable(o: ConstructorParameters<typeof Table>[0] = {}): Table {
|
||||
const t = new Table(o);
|
||||
t.s.rules = withRule(t.s.rules, 'recruit.on=true');
|
||||
for (const p of [0, 1] as const) {
|
||||
const avs = t.s.players[p].avatars;
|
||||
const avs = t.s.players[p].anomalies;
|
||||
for (let i = 1; i < 4; i++) {
|
||||
const name = t.s.cards[avs[i].card].name;
|
||||
t.s.defs[name] = { ...t.s.defs[name], ram: 6 };
|
||||
t.s.defs[name] = { ...t.s.defs[name], bandwidth: 6 };
|
||||
t.s.players[p].hand.push(avs[i].card);
|
||||
avs[i].card = avs[i + 4].card = -1;
|
||||
avs[i].faceUp = false;
|
||||
|
|
@ -290,101 +290,101 @@ function recruitTable(o: ConstructorParameters<typeof Table>[0] = {}): Table {
|
|||
|
||||
const recruits = (t: Table) => t.legal().filter((a) => a.type === 'recruit');
|
||||
|
||||
test('recruit rule: buy an Avatar from hand into an empty slot; it enters play on a later turn', () => {
|
||||
test('recruit rule: buy an Anomaly from hand into an empty slot; it enters play on a later turn', () => {
|
||||
const t = recruitTable();
|
||||
const card = t.s.players[0].hand[0];
|
||||
t.ram(0, 5).to('play');
|
||||
assert.equal(recruits(t).length, 0, "can't afford 6 RAM");
|
||||
t.ram(0, 6);
|
||||
assert.deepEqual(recruits(t).map((a) => a.type === 'recruit' && a.slot), [2, 1, 2, 1, 2, 1], 'first empty slot, or over Avatar 1');
|
||||
t.bandwidth(0, 5).to('play');
|
||||
assert.equal(recruits(t).length, 0, "can't afford 6 Gb");
|
||||
t.bandwidth(0, 6);
|
||||
assert.deepEqual(recruits(t).map((a) => a.type === 'recruit' && a.slot), [2, 1, 2, 1, 2, 1], 'first empty slot, or over Anomaly 1');
|
||||
t.go({ type: 'recruit', card, slot: 2 });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
assert.equal(t.avatar(0, 2).card, card);
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
assert.equal(t.anomaly(0, 2).card, card);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
assert.ok(!t.s.players[0].hand.includes(card));
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.ok(t.can({ type: 'place', slot: 2, to: 'S1' }));
|
||||
});
|
||||
|
||||
test('recruit rule: captures unlock nothing, and a salvaged Avatar pays its price', () => {
|
||||
test('recruit rule: captures unlock nothing, and a salvaged Anomaly pays its price', () => {
|
||||
const t = recruitTable();
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, 0);
|
||||
assert.equal(t.avatar(0, 2).card, -1);
|
||||
const ram = t.s.players[0].ram;
|
||||
assert.equal(t.anomaly(0, 2).card, -1);
|
||||
const bandwidth = t.s.players[0].bandwidth;
|
||||
t.go({ type: 'salvage', card: t.s.players[0].hand[0] });
|
||||
assert.equal(t.s.players[0].ram, ram + 6);
|
||||
assert.equal(t.s.players[0].bandwidth, bandwidth + 6);
|
||||
});
|
||||
|
||||
test('recruit rule: copies count toward the 4 Avatars', () => {
|
||||
const t = recruitTable({ south: { avatars: ['Carbon NanoBots', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
test('recruit rule: copies count toward the 4 Anomalies', () => {
|
||||
const t = recruitTable({ south: { anomalies: ['Carbon NanoBots', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
t.own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
const [a, b] = t.s.players[0].hand;
|
||||
t.ram(0, 30).to('play');
|
||||
t.bandwidth(0, 30).to('play');
|
||||
t.go({ type: 'recruit', card: a, slot: 2 }).go({ type: 'recruit', card: b, slot: 3 });
|
||||
const replicate = t.legal().find((x) => x.type === 'activate' && x.name === 'Carbon NanoBots' && x.args.to === 'S1');
|
||||
assert.ok(replicate, '3 Avatars, so a copy fits');
|
||||
assert.ok(replicate, '3 Anomalies, so a copy fits');
|
||||
t.go(replicate).settle();
|
||||
assert.equal(t.avatar(0, 5).at, 'S1');
|
||||
assert.equal(t.anomaly(0, 5).at, 'S1');
|
||||
assert.ok(!recruits(t).some((r) => r.type === 'recruit' && r.slot === 4), 'no room for a fourth with the copy out');
|
||||
});
|
||||
|
||||
test('recruit rule: recruiting over an Avatar retires it and its Hardware', () => {
|
||||
test('recruit rule: recruiting over an Anomaly retires it and its Hardware', () => {
|
||||
const t = recruitTable({ south: { main: ['Additional Core'] } });
|
||||
t.own(0, 'A2');
|
||||
const ref = t.place(0, 1, 'A2');
|
||||
const old = t.avatar(0, 1).card;
|
||||
const old = t.anomaly(0, 1).card;
|
||||
const hw = t.hardware(ref.player, ref.slot, 'Additional Core');
|
||||
const card = t.s.players[0].hand.find((id) => t.s.defs[t.s.cards[id].name].kind === 'avatar')!;
|
||||
t.ram(0, 6).to('play').go({ type: 'recruit', card, slot: 1 });
|
||||
assert.equal(t.avatar(0, 1).card, card);
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, []);
|
||||
const card = t.s.players[0].hand.find((id) => t.s.defs[t.s.cards[id].name].kind === 'anomaly')!;
|
||||
t.bandwidth(0, 6).to('play').go({ type: 'recruit', card, slot: 1 });
|
||||
assert.equal(t.anomaly(0, 1).card, card);
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, []);
|
||||
assert.ok(t.s.players[0].discard.includes(old) && t.s.players[0].discard.includes(hw));
|
||||
assert.equal(t.s.locations.A2.owner, 0, 'the location stays yours');
|
||||
});
|
||||
|
||||
test('recruit rule: decks keep one Avatar outside and shuffle the rest into the main deck', () => {
|
||||
test('recruit rule: decks keep one Anomaly outside and shuffle the rest into the main deck', () => {
|
||||
const pool = loadCards();
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), 'recruit.avatarsInDeck=5');
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), 'recruit.anomaliesInDeck=5');
|
||||
const deck = randomDeck(pool, makeRng(3), rules);
|
||||
assert.equal(deck.avatars.length, 1);
|
||||
assert.equal(deck.anomalies.length, 1);
|
||||
assert.equal(deck.main.length, 45);
|
||||
assert.equal(deck.main.filter((n) => pool.byName.get(n)!.kind === 'avatar').length, 5);
|
||||
assert.equal(deck.main.filter((n) => pool.byName.get(n)!.kind === 'anomaly').length, 5);
|
||||
const s = createGame({ pool, decks: [deck, randomDeck(pool, makeRng(4), rules)], seed: 1, rules });
|
||||
assert.deepEqual(s.players[0].avatars.slice(0, 4).map((a) => a.card >= 0), [true, false, false, false]);
|
||||
assert.deepEqual(s.players[0].anomalies.slice(0, 4).map((a) => a.card >= 0), [true, false, false, false]);
|
||||
assert.equal(checkInvariants(s).length, 0);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Buy-Avatars rule (prototype): pay RAM to flip the next Avatar instead of unlocking by level
|
||||
// Buy-Anomalies rule (prototype): pay Bandwidth to flip the next Anomaly instead of unlocking by level
|
||||
|
||||
test('buy rule: pay to flip the next face-down Avatar; it enters play on a later turn', () => {
|
||||
test('buy rule: pay to flip the next face-down Anomaly; it enters play on a later turn', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'buyAvatars.on=true'), 'buyAvatars.prices=8,12,16');
|
||||
t.ram(0, 7).to('play');
|
||||
assert.ok(!t.can({ type: 'buyAvatar', slot: 2 }), "can't afford 8 RAM");
|
||||
t.ram(0, 20).go({ type: 'buyAvatar', slot: 2 });
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].ram, 12);
|
||||
assert.ok(t.can({ type: 'buyAvatar', slot: 3 }), 'Avatar 3 is next, at 12');
|
||||
t.go({ type: 'buyAvatar', slot: 3 });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'buyAnomalies.on=true'), 'buyAnomalies.prices=8,12,16');
|
||||
t.bandwidth(0, 7).to('play');
|
||||
assert.ok(!t.can({ type: 'buyAnomaly', slot: 2 }), "can't afford 8 Gb");
|
||||
t.bandwidth(0, 20).go({ type: 'buyAnomaly', slot: 2 });
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].bandwidth, 12);
|
||||
assert.ok(t.can({ type: 'buyAnomaly', slot: 3 }), 'Anomaly 3 is next, at 12');
|
||||
t.go({ type: 'buyAnomaly', slot: 3 });
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.ok(t.can({ type: 'place', slot: 2, to: 'S1' }));
|
||||
});
|
||||
|
||||
test('buy rule: captures unlock nothing', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(t.s.rules, 'buyAvatars.on=true');
|
||||
t.s.rules = withRule(t.s.rules, 'buyAnomalies.on=true');
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, 0);
|
||||
assert.deepEqual([t.avatar(0, 2).faceUp, t.avatar(0, 3).faceUp], [false, false]);
|
||||
assert.deepEqual([t.anomaly(0, 2).faceUp, t.anomaly(0, 3).faceUp], [false, false]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
@ -423,7 +423,7 @@ test('command rule: the order of commands can follow a pattern of round leads, o
|
|||
assert.deepEqual(DEFAULT_RULES.commands, { on: true, perPlayer: 2, leads: 'F', snake: true }, 'the default since v0.9: the first player leads every round, snake order');
|
||||
});
|
||||
|
||||
test('command rule: one advance or attack per command, each Avatar once a round', () => {
|
||||
test('command rule: one advance or attack per command, each Anomaly once a round', () => {
|
||||
const t = commandTable();
|
||||
t.own(0, 'A2');
|
||||
t.own(0, 'A1');
|
||||
|
|
@ -436,15 +436,15 @@ test('command rule: one advance or attack per command, each Avatar once a round'
|
|||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.equal(t.s.turn, 3);
|
||||
const movers = new Set(t.legal().filter((a) => a.type === 'advance').map((a) => a.type === 'advance' && a.slot));
|
||||
assert.deepEqual([...movers], [2], 'Avatar 1 already acted this round');
|
||||
assert.deepEqual([...movers], [2], 'Anomaly 1 already acted this round');
|
||||
});
|
||||
|
||||
test('command rule: an Avatar unlocked this round enters play next round', () => {
|
||||
test('command rule: an Anomaly unlocked this round enters play next round', () => {
|
||||
const t = commandTable();
|
||||
t.own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
t.go({ type: 'advance', slot: 1, to: 'B1' }).to('attack').end();
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.equal(t.s.turn, 3);
|
||||
assert.ok(!t.legal().some((a) => a.type === 'place' && a.slot === 2));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores, execBlocked, executionActions, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, execBlocked, executionActions, openWindow } from '../src/engine.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
|
|
@ -22,12 +22,12 @@ card('Execute: Disconnect', () => {
|
|||
t.own(1, 'D1');
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.hand(1, 'Execute: Disconnect');
|
||||
t.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.play(1, 'Execute: Disconnect', 'C1', { ref: { player: 1, slot: 1 }, to: 'D1' }).settle();
|
||||
assert.equal(t.avatar(1, 1).at, 'D1');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, [hw]);
|
||||
assert.equal(t.anomaly(1, 1).at, 'D1');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, [hw]);
|
||||
assert.equal(t.s.locations.C1.owner, 0, 'the attacker takes the empty location');
|
||||
});
|
||||
|
||||
|
|
@ -35,14 +35,14 @@ card('Execute: Disconnect', () => {
|
|||
// An attacker retreats after a bad roll and isn't defeated.
|
||||
const t = scene({ south: { main: ['Execute: Disconnect'] } });
|
||||
t.hand(0, 'Execute: Disconnect');
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6);
|
||||
fight(t);
|
||||
assert.equal(openWindow(t.s)?.kind, 'preRoll');
|
||||
t.act({ type: 'pass' });
|
||||
assert.equal(openWindow(t.s)?.kind, 'postRoll');
|
||||
t.play(0, 'Execute: Disconnect', 'C1', { ref: { player: 0, slot: 1 }, to: 'B1' }).settle();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.s.locations.C1.owner, 1);
|
||||
assert.match(t.logText(), /combat at C1 ends/);
|
||||
});
|
||||
|
|
@ -51,7 +51,7 @@ card('Execute: Sabotage', () => {
|
|||
const t = scene({ south: { main: ['Execute: Sabotage'] }, north: { main: ['Additional Core'] } });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.hand(0, 'Execute: Sabotage');
|
||||
t.ram(0, 7);
|
||||
t.bandwidth(0, 7);
|
||||
fight(t);
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.play(0, 'Execute: Sabotage', 'C1', { card: hw, mode: 'destroy' }).settle();
|
||||
|
|
@ -62,27 +62,27 @@ card('Execute: Sabotage', () => {
|
|||
card('Execute: Kill Process', () => {
|
||||
const t = scene({ south: { main: ['Execute: Kill Process'] }, north: { main: ['Stack Overflow'] } });
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5);
|
||||
t.hand(0, 'Execute: Kill Process');
|
||||
t.ram(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, "back on at its controller's next turn");
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, "back on at its controller's next turn");
|
||||
});
|
||||
|
||||
card('Execute: Force Reboot', () => {
|
||||
const t = scene({ south: { main: ['Execute: Force Reboot', 'Additional Core', 'Dedicated GPU', 'Execute: Ping Sweep'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
const t = scene({ south: { main: ['Execute: Force Reboot', 'Additional Core', 'Dedicated GPU', 'Execute: Ping Sweep'] }, north: { main: ['Bloatware'] } });
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hardware(0, 1, 'Dedicated GPU');
|
||||
t.hand(0, 'Execute: Force Reboot', 'Execute: Ping Sweep');
|
||||
const fromB1 = () => executionActions(t.s, 0, 'any').some((a) => a.type === 'play' && a.from === 'B1');
|
||||
assert.ok(fromB1(), 'B1 can perform Executions');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
fight(t);
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.play(0, 'Execute: Force Reboot', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
assert.equal(attackerDice(t), 5, "Memory Leak's penalty is gone");
|
||||
assert.equal(attackerDice(t), 5, "Bloatware's penalty is gone");
|
||||
assert.ok(execBlocked(t.s, 'B1'), 'the Server it stands on is blocked for the turn');
|
||||
assert.ok(!fromB1());
|
||||
});
|
||||
|
|
@ -91,16 +91,16 @@ card('Execute: Fork', () => {
|
|||
const t = scene({ south: { main: ['Execute: Fork', 'Stack Overflow'] } });
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Fork');
|
||||
t.ram(0, 7).play(0, 'Execute: Fork', 'B1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 6, 'two Stack Overflow effects, +1 each');
|
||||
t.bandwidth(0, 7).play(0, 'Execute: Fork', 'B1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 6, 'two Stack Overflow effects, +1 each');
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5, 'until end of turn');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5, 'until end of turn');
|
||||
});
|
||||
|
||||
card('Execute: Ping Sweep', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Ping Sweep'] } });
|
||||
t.hand(0, 'Execute: Ping Sweep');
|
||||
t.ram(0, 4).play(0, 'Execute: Ping Sweep', null).settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Ping Sweep', null).settle();
|
||||
assert.equal(t.s.players[0].hand.length, 2);
|
||||
});
|
||||
|
||||
|
|
@ -108,26 +108,26 @@ card('Execute: Trace Route', () => {
|
|||
const t = scene({ south: { main: ['Execute: Trace Route'] } });
|
||||
t.hand(0, 'Execute: Trace Route');
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.ram(0, 5).to('play').play(0, 'Execute: Trace Route', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
t.bandwidth(0, 5).to('play').play(0, 'Execute: Trace Route', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
assert.equal(attackerDice(t), 5, 'attacks right away with +1 Core');
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'C1');
|
||||
});
|
||||
|
||||
card('Execute: Override', () => {
|
||||
const t = scene({ south: { main: ['Execute: Override'] }, north: { main: ['Stack Overflow'] } });
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Override');
|
||||
t.ram(0, 5).play(0, 'Execute: Override', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Override', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'until end of turn');
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, 'until end of turn');
|
||||
});
|
||||
|
||||
card('Execute: Memory Dump', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Memory Dump', 'Execute: Memory Dump'] } });
|
||||
t.hand(0, 'Execute: Memory Dump', 'Execute: Memory Dump');
|
||||
t.ram(0, 8).play(0, 'Execute: Memory Dump', 'C1');
|
||||
t.bandwidth(0, 8).play(0, 'Execute: Memory Dump', 'C1');
|
||||
assert.equal(t.s.choice?.kind, 'Execute: Memory Dump:discard', "not South's: draw 2, discard 1");
|
||||
t.choose('Network Interface Upgrade').settle();
|
||||
assert.equal(t.s.players[0].hand.length, 1 + 2 - 1);
|
||||
|
|
@ -141,8 +141,8 @@ card('Execute: Rollback', () => {
|
|||
t.own(1, 'C1');
|
||||
const [so] = t.hand(1, 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Rollback');
|
||||
t.ram(0, 4);
|
||||
t.ram(1, 7).to('play').act({ type: 'installProgram', card: so, at: 'C1' });
|
||||
t.bandwidth(0, 4);
|
||||
t.bandwidth(1, 7).to('play').act({ type: 'installProgram', card: so, at: 'C1' });
|
||||
assert.equal(t.decider, 0, 'South may respond to the install');
|
||||
t.play(0, 'Execute: Rollback', 'C1', { card: so }).settle();
|
||||
assert.deepEqual(t.s.players[1].hand, [so]);
|
||||
|
|
@ -152,7 +152,7 @@ card('Execute: Rollback', () => {
|
|||
card('Execute: Root Access', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Root Access'] } });
|
||||
t.hand(0, 'Execute: Root Access');
|
||||
t.ram(0, 4).play(0, 'Execute: Root Access', 'C1').settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Root Access', 'C1').settle();
|
||||
assert.ok(t.s.locations.C1.rootAccess[0] > t.s.clock);
|
||||
t.to('playAgain').end();
|
||||
assert.ok(t.s.locations.C1.rootAccess[0] <= t.s.clock, 'until end of turn');
|
||||
|
|
@ -163,19 +163,19 @@ card('Execute: Packet Flood', () => {
|
|||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.hand(1, 'Execute: Packet Flood');
|
||||
t.ram(1, 5);
|
||||
t.bandwidth(1, 5);
|
||||
t.act({ type: 'advance', slot: 1, to: 'C2' });
|
||||
assert.equal(t.decider, 1);
|
||||
t.play(1, 'Execute: Packet Flood', 'B1', { to: 'B1' }).settle();
|
||||
t.to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, null, "the advance fails: it can't move");
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
});
|
||||
|
||||
card('Execute: Emergency Shutdown', () => {
|
||||
const t = scene({ north: { main: ['Execute: Emergency Shutdown'] } });
|
||||
t.hand(1, 'Execute: Emergency Shutdown');
|
||||
t.ram(1, 6);
|
||||
t.bandwidth(1, 6);
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1);
|
||||
fight(t);
|
||||
assert.equal(openWindow(t.s)?.kind, 'preRoll');
|
||||
|
|
@ -183,17 +183,17 @@ card('Execute: Emergency Shutdown', () => {
|
|||
assert.equal(openWindow(t.s)?.kind, 'postRoll', 'North waits to see the dice');
|
||||
t.play(1, 'Execute: Emergency Shutdown', 'C1').settle();
|
||||
assert.equal(t.s.locations.C1.owner, 1);
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.ok(t.avatar(0, 1).disabledUntil > t.s.clock);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.ok(t.anomaly(0, 1).disabledUntil > t.s.clock);
|
||||
});
|
||||
|
||||
card('Execute: Process Clone', () => {
|
||||
const t = scene({ south: { main: ['Execute: Process Clone', 'Stack Overflow'] } });
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Process Clone');
|
||||
t.ram(0, 7).play(0, 'Execute: Process Clone', 'B1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4 + 2 + 2, 'two copies, each counting 2 Programs');
|
||||
t.bandwidth(0, 7).play(0, 'Execute: Process Clone', 'B1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4 + 2 + 2, 'two copies, each counting 2 Programs');
|
||||
});
|
||||
|
||||
card('Execute: Defragment', () => {
|
||||
|
|
@ -201,9 +201,9 @@ card('Execute: Defragment', () => {
|
|||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.s.cards[so].disabledUntil = 1e9;
|
||||
t.hand(0, 'Execute: Defragment');
|
||||
t.ram(0, 4).play(0, 'Execute: Defragment', 'B1', { card: so }).settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Defragment', 'B1', { card: so }).settle();
|
||||
assert.equal(t.s.cards[so].disabledUntil, 0);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5);
|
||||
});
|
||||
|
||||
card('Execute: Remote Access', () => {
|
||||
|
|
@ -211,18 +211,18 @@ card('Execute: Remote Access', () => {
|
|||
t.own(1, 'D1');
|
||||
const so = t.program(1, 'D1', 'Stack Overflow');
|
||||
t.hand(1, 'Execute: Remote Access');
|
||||
t.ram(1, 6).play(1, 'Execute: Remote Access', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'Stack Overflow runs on C1 too');
|
||||
t.bandwidth(1, 6).play(1, 'Execute: Remote Access', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, 'Stack Overflow runs on C1 too');
|
||||
});
|
||||
|
||||
card('Execute: Purge', () => {
|
||||
const t = scene({ south: { main: ['Execute: Purge', 'Additional Core'] } });
|
||||
const hw = t.hardware(0, 1, 'Additional Core');
|
||||
t.s.cards[hw].disabledUntil = 1e9;
|
||||
Object.assign(t.avatar(0, 1), { infection: 2, permanentInfection: 1 });
|
||||
Object.assign(t.anomaly(0, 1), { infection: 2, permanentInfection: 1 });
|
||||
t.hand(0, 'Execute: Purge');
|
||||
t.ram(0, 4).play(0, 'Execute: Purge', 'B1', { to: 'B1' }).settle();
|
||||
assert.equal(t.avatar(0, 1).infection + t.avatar(0, 1).permanentInfection, 0);
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Purge', 'B1', { to: 'B1' }).settle();
|
||||
assert.equal(t.anomaly(0, 1).infection + t.anomaly(0, 1).permanentInfection, 0);
|
||||
assert.equal(t.s.cards[hw].disabledUntil, 0);
|
||||
});
|
||||
|
||||
|
|
@ -232,8 +232,8 @@ card('Execute: Hard Reset', () => {
|
|||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
const hf = t.program(0, 'B1', 'Hotfix');
|
||||
t.hand(0, 'Execute: Hard Reset');
|
||||
t.ram(0, 6).play(0, 'Execute: Hard Reset', 'B1', { cards: [so, hf] }).settle();
|
||||
t.bandwidth(0, 6).play(0, 'Execute: Hard Reset', 'B1', { cards: [so, hf] }).settle();
|
||||
assert.deepEqual(t.s.locations.B1.programs, []);
|
||||
assert.deepEqual(t.s.players[0].hand.sort(), [so, hf].sort());
|
||||
assert.equal(t.s.players[0].ram, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 2);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import assert from 'node:assert/strict';
|
|||
import { test } from 'node:test';
|
||||
import { DEFAULT_GREEDY, greedyBot } from '../src/bots/greedy.ts';
|
||||
import { randomBot } from '../src/bots/random.ts';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { playGame } from '../src/play.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
||||
// playGame with `check` throws on the first broken invariant (card conservation, RAM, placement).
|
||||
// playGame with `check` throws on the first broken invariant (card conservation, Bandwidth, placement).
|
||||
test('random bots play 200 games with every card without breaking a rule', () => {
|
||||
for (let seed = 1; seed <= 200; seed++) {
|
||||
const s = playGame({ pool, bots: [randomBot, randomBot], seed, check: true });
|
||||
|
|
@ -29,7 +29,7 @@ test('greedy bots play 200 games without breaking a rule', () => {
|
|||
|
||||
test('bots play the recruit rule without breaking a rule', () => {
|
||||
for (const k of [3, 7]) {
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), `recruit.avatarsInDeck=${k}`);
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), `recruit.anomaliesInDeck=${k}`);
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
|
|
@ -37,8 +37,8 @@ test('bots play the recruit rule without breaking a rule', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('bots play the buy-Avatars rule without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'buyAvatars.on=true');
|
||||
test('bots play the buy-Anomalies rule without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'buyAnomalies.on=true');
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
|
|
@ -46,7 +46,7 @@ test('bots play the buy-Avatars rule without breaking a rule', () => {
|
|||
});
|
||||
|
||||
test('bots play the copy-rule variants without breaking a rule', () => {
|
||||
for (const spec of ['copies.waitATurn=true', 'copies.needAvatar2=true', 'copies.allowed=false']) {
|
||||
for (const spec of ['copies.waitATurn=true', 'copies.needAnomaly2=true', 'copies.allowed=false']) {
|
||||
const rules = withRule(DEFAULT_RULES, spec);
|
||||
for (let seed = 1; seed <= 15; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
|
|
@ -81,6 +81,16 @@ test('bots play the command rule without breaking a rule', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('bots play the 4×4 and lanes boards without breaking a rule', () => {
|
||||
for (const board of ['grid4', 'grid4-wide', 'grid4-one', 'lanes', 'lanes-open']) {
|
||||
const rules = withRule(DEFAULT_RULES, `board=${board}`);
|
||||
for (let seed = 1; seed <= 15; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('greedy beats random', () => {
|
||||
let wins = 0;
|
||||
for (let seed = 1; seed <= 100; seed++) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { addBugs } from '../src/cards/util.ts';
|
||||
import { avatarCores, canWear, executionActions, executionCost, programCost } from '../src/engine.ts';
|
||||
import { healthOf, portsFree } from '../src/query.ts';
|
||||
import { anomalyCores, canWear, executionActions, executionCost, programCost } from '../src/engine.ts';
|
||||
import { healthOf, slotsFree } from '../src/query.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
|
|
@ -20,21 +20,21 @@ const attackerDice = (t: Table) => t.logText().match(/Roll: Broken Bits \[([\d,]
|
|||
card('RAM Expansion', () => {
|
||||
const t = scene({ south: { main: ['RAM Expansion'] } });
|
||||
t.hardware(0, 1, 'RAM Expansion');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4, 'no Cores');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4, 'no Cores');
|
||||
assert.equal(healthOf(t.s, { player: 0, slot: 1 }), 9 + 2, 'Broken Bits: 9 Health, +2');
|
||||
});
|
||||
|
||||
card('Additional Core', () => {
|
||||
const t = scene({ south: { main: ['Additional Core'] } });
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5);
|
||||
});
|
||||
|
||||
card('Overclocked CPU', () => {
|
||||
const t = scene({ south: { main: ['Overclocked CPU', 'Stack Overflow'] } });
|
||||
t.hardware(0, 1, 'Overclocked CPU');
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 6, '+2 in combat');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 6, '+2 in combat');
|
||||
attackC1(t);
|
||||
t.rig(6, 6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.equal(attackerDice(t), 6);
|
||||
|
|
@ -53,7 +53,7 @@ card('Solid-State Cache', () => {
|
|||
const [so, hf] = t.hand(0, 'Stack Overflow', 'Hotfix');
|
||||
assert.equal(programCost(t.s, 0, so, 'B1'), 4);
|
||||
assert.equal(programCost(t.s, 0, so, 'S1'), 7, 'only on the occupied Server');
|
||||
t.ram(0, 4).to('play').go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
t.bandwidth(0, 4).to('play').go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
assert.equal(programCost(t.s, 0, hf, 'B1'), 7, 'first each turn');
|
||||
});
|
||||
|
||||
|
|
@ -63,28 +63,28 @@ card('Redundant Power Supply', () => {
|
|||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [rps, ac], 'kept, in its slot');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [rps, ac], 'kept, in its slot');
|
||||
// The second defeat loses it.
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
t.go({ type: 'place', slot: 1, to: 'B1' });
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, []);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, []);
|
||||
});
|
||||
|
||||
card('Network Interface Upgrade', () => {
|
||||
const t = new Table({ south: { avatars: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'], main: ['Additional Core', 'RAM Expansion', 'Network Interface Upgrade', 'Packet Accelerator'] } });
|
||||
const t = new Table({ south: { anomalies: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'], main: ['Additional Core', 'RAM Expansion', 'Network Interface Upgrade', 'Packet Accelerator'] } });
|
||||
const beta = { player: 0 as const, slot: 1 };
|
||||
t.place(0, 1, 'S1');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hardware(0, 1, 'RAM Expansion');
|
||||
const [niu, pa] = t.hand(0, 'Network Interface Upgrade', 'Packet Accelerator');
|
||||
assert.equal(portsFree(t.s, beta), 0);
|
||||
assert.equal(slotsFree(t.s, beta), 0);
|
||||
assert.ok(!canWear(t.s, pa, beta));
|
||||
assert.ok(canWear(t.s, niu, beta), 'fits with both ports full');
|
||||
t.ram(0, 4).to('play').go({ type: 'installHardware', card: niu, slot: 1 });
|
||||
assert.equal(portsFree(t.s, beta), 1, 'and adds a port');
|
||||
assert.ok(canWear(t.s, niu, beta), 'fits with both Expansion Slots full');
|
||||
t.bandwidth(0, 4).to('play').go({ type: 'installHardware', card: niu, slot: 1 });
|
||||
assert.equal(slotsFree(t.s, beta), 1, 'and adds an Expansion Slot');
|
||||
assert.ok(canWear(t.s, pa, beta));
|
||||
});
|
||||
|
||||
|
|
@ -93,22 +93,22 @@ card('Dedicated GPU', () => {
|
|||
t.place(0, 1, 'S1');
|
||||
t.hardware(0, 1, 'Dedicated GPU');
|
||||
t.hand(0, 'Execute: Ping Sweep');
|
||||
t.ram(0, 4).play(0, 'Execute: Ping Sweep', null, {}, 'S1').settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Ping Sweep', null, {}, 'S1').settle();
|
||||
assert.equal(t.s.players[0].hand.length, 3, 'performed by the Server it stands on: draws 2 + 1');
|
||||
});
|
||||
|
||||
card('ECC Memory', () => {
|
||||
const t = scene({ south: { main: ['ECC Memory', 'Additional Core'] }, north: { main: ['Memory Leak', 'Stock Rice'] } });
|
||||
const t = scene({ south: { main: ['ECC Memory', 'Additional Core'] }, north: { main: ['Bloatware', 'Stock Rice'] } });
|
||||
t.hardware(0, 1, 'ECC Memory');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.program(1, 'C1', 'Stock Rice');
|
||||
attackC1(t);
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.equal(attackerDice(t), 5, "neither Bug Program touches it");
|
||||
assert.equal(addBugs(t.s, { player: 0, slot: 1 }, 1, 'a Bug card', 1), false, "and opponents can't give it Bug counters");
|
||||
assert.equal(t.avatar(0, 1).bugs, 0);
|
||||
assert.equal(addBugs(t.s, { player: 1, slot: 1 }, 1, 'a Bug card', 0), true, 'Avatars without it can get them');
|
||||
assert.equal(t.anomaly(0, 1).bugs, 0);
|
||||
assert.equal(addBugs(t.s, { player: 1, slot: 1 }, 1, 'a Bug card', 0), true, 'Anomalies without it can get them');
|
||||
});
|
||||
|
||||
card('Cooling System', () => {
|
||||
|
|
@ -118,43 +118,43 @@ card('Cooling System', () => {
|
|||
t.hardware(0, 1, 'Cooling System');
|
||||
t.hardware(0, 1, 'Solid-State Cache');
|
||||
const [so, hf] = t.hand(0, 'Stack Overflow', 'Hotfix');
|
||||
t.ram(0, 20).to('play');
|
||||
t.bandwidth(0, 20).to('play');
|
||||
t.go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
assert.equal(programCost(t.s, 0, hf, 'B1'), 4, 'Solid-State Cache works twice');
|
||||
t.go({ type: 'installProgram', card: hf, at: 'B1' });
|
||||
assert.equal(t.s.players[0].ram, 20 - 4 - 4);
|
||||
assert.equal(t.s.players[0].bandwidth, 20 - 4 - 4);
|
||||
});
|
||||
|
||||
card('RAID Array', () => {
|
||||
const t = scene({ south: { main: ['RAID Array', 'Additional Core'] } });
|
||||
t.hardware(0, 1, 'RAID Array');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.s.choice?.kind, 'RAID Array:keep');
|
||||
t.choose('Keep').settle();
|
||||
assert.equal(t.avatar(0, 1).hardware.length, 2);
|
||||
assert.equal(t.s.players[0].ram, 0, 'half of 5 + 5');
|
||||
assert.equal(t.anomaly(0, 1).hardware.length, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'half of 5 + 5');
|
||||
});
|
||||
|
||||
card('Packet Accelerator', () => {
|
||||
const t = scene({ south: { main: ['Packet Accelerator'] } });
|
||||
t.hardware(0, 1, 'Packet Accelerator');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 5);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4);
|
||||
});
|
||||
|
||||
card('Firewall Appliance', () => {
|
||||
const t = scene({ south: { main: ['Execute: Sabotage'] }, north: { main: ['Firewall Appliance'] } });
|
||||
const fa = t.hardware(1, 1, 'Firewall Appliance');
|
||||
const [sab] = t.hand(0, 'Execute: Sabotage');
|
||||
t.ram(0, 10);
|
||||
t.bandwidth(0, 10);
|
||||
attackC1(t);
|
||||
t.act({ type: 'end' });
|
||||
assert.equal(executionCost(t.s, 0, sab, 'C1', { card: fa, mode: 'destroy' }), 10, '+3 for the first hostile Execution');
|
||||
t.play(0, 'Execute: Sabotage', 'C1', { card: fa, mode: 'destroy' });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
});
|
||||
|
||||
card('Hardware Sandbox', () => {
|
||||
|
|
@ -164,11 +164,11 @@ card('Hardware Sandbox', () => {
|
|||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
const hf = t.program(1, 'C1', 'Hotfix');
|
||||
const [sandbox] = t.hand(1, 'Hardware Sandbox');
|
||||
t.ram(1, 7).to('play').act({ type: 'installHardware', card: sandbox, slot: 1 });
|
||||
t.bandwidth(1, 7).to('play').act({ type: 'installHardware', card: sandbox, slot: 1 });
|
||||
t.choose('Stack Overflow').settle();
|
||||
t.to('playAgain').end();
|
||||
t.hand(0, 'Execute: Kill Process', 'Execute: Root Access');
|
||||
t.ram(0, 9);
|
||||
t.bandwidth(0, 9);
|
||||
const kills = () => executionActions(t.s, 0, 'now').filter((a) => a.type === 'play' && t.s.cards[a.card].name === 'Execute: Kill Process').map((a) => a.type === 'play' && a.args.card);
|
||||
assert.deepEqual(kills(), [hf], 'Stack Overflow is protected');
|
||||
t.play(0, 'Execute: Root Access', 'C1').settle();
|
||||
|
|
@ -193,16 +193,16 @@ card('Hot-Swap Bay', () => {
|
|||
const hsb = t.hardware(0, 1, 'Hot-Swap Bay');
|
||||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
const [oc] = t.hand(0, 'Overclocked CPU');
|
||||
t.ram(0, 1).use(hsb, { card: ac, cards: [oc] }).settle();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [hsb, oc]);
|
||||
t.bandwidth(0, 1).use(hsb, { card: ac, cards: [oc] }).settle();
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [hsb, oc]);
|
||||
assert.deepEqual(t.s.players[0].hand, [ac]);
|
||||
assert.equal(t.s.players[0].ram, 0, 'pays the 1 RAM difference');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'pays the 1 Gb difference');
|
||||
});
|
||||
|
||||
test('Hardware must still fit its ports when Network Interface Upgrade leaves', () => {
|
||||
test('Hardware must still fit its Expansion Slots when Network Interface Upgrade leaves', () => {
|
||||
const t = new Table({
|
||||
south: {
|
||||
avatars: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'],
|
||||
anomalies: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'],
|
||||
main: ['Network Interface Upgrade', 'Hot-Swap Bay', 'Additional Core', 'Packet Accelerator', 'RAM Expansion', 'Execute: Rollback'],
|
||||
},
|
||||
});
|
||||
|
|
@ -212,15 +212,15 @@ test('Hardware must still fit its ports when Network Interface Upgrade leaves',
|
|||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
const pa = t.hardware(0, 1, 'Packet Accelerator');
|
||||
t.hand(0, 'RAM Expansion', 'Execute: Rollback');
|
||||
t.ram(0, 20);
|
||||
// Beta Version 1.0 has 2 ports, +1 from the NIU, and all 3 are in use.
|
||||
t.bandwidth(0, 20);
|
||||
// Beta Version 1.0 has 2 Expansion Slots, +1 from the NIU, and all 3 are in use.
|
||||
const swaps = t.legal().filter((a) => a.type === 'activate' && a.card === hsb);
|
||||
assert.ok(!swaps.some((a) => a.type === 'activate' && a.args.card === niu), "Hot-Swap Bay can't swap the NIU for a card that needs a port");
|
||||
assert.ok(!swaps.some((a) => a.type === 'activate' && a.args.card === niu), "Hot-Swap Bay can't swap the NIU for a card that needs an Expansion Slot");
|
||||
assert.ok(swaps.some((a) => a.type === 'activate' && a.args.card === ac));
|
||||
// Rollback returns the NIU: the newest Hardware no longer fits and is discarded.
|
||||
t.s.cards[niu].installedTurn = t.s.turn;
|
||||
t.play(0, 'Execute: Rollback', 'S1', { card: niu }).settle();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [hsb, ac]);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [hsb, ac]);
|
||||
assert.ok(t.s.players[0].discard.includes(pa));
|
||||
});
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ card('Quantum Coprocessor', () => {
|
|||
t.place(0, 1, 'S1');
|
||||
const qc = t.hardware(0, 1, 'Quantum Coprocessor');
|
||||
t.hand(0, 'Execute: Kill Process');
|
||||
t.ram(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }, 'S1').settle();
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }, 'S1').settle();
|
||||
assert.equal(t.s.choice?.kind, 'Quantum Coprocessor:copy');
|
||||
t.choose('Hotfix').settle();
|
||||
assert.ok(t.s.cards[so].disabledUntil > t.s.clock);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function turnOf(t: Table, p: 0 | 1): Table {
|
|||
return t;
|
||||
}
|
||||
|
||||
/** South's Avatar 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Avatar 1 on C1. */
|
||||
/** South's Anomaly 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Anomaly 1 on C1. */
|
||||
function standoff(o: { northMain?: string[]; southMain?: string[] } = {}): Table {
|
||||
const t = new Table({ health: true, north: { main: o.northMain }, south: { main: o.southMain } });
|
||||
t.own(0, 'B1');
|
||||
|
|
@ -38,9 +38,9 @@ test('health: the loser takes the margin as damage, and nobody moves', () => {
|
|||
t.rig(6, 6, 6, 6, 5, 5, 5, 4); // 24 to 19
|
||||
t.end();
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1', 'the attacker stays where it attacked from');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.equal(t.avatar(1, 1).damage, 5);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1', 'the attacker stays where it attacked from');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(1, 1).damage, 5);
|
||||
assert.equal(healthLeft(t.s, { player: 1, slot: 1 }), 4);
|
||||
assert.equal(t.s.stats.attacksWon[0], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 5);
|
||||
|
|
@ -48,21 +48,21 @@ test('health: the loser takes the margin as damage, and nobody moves', () => {
|
|||
assert.equal(t.s.combat, null);
|
||||
});
|
||||
|
||||
test('health: damage adds up; the Avatar is destroyed at 0 Health, loses its Hardware, and the location falls', () => {
|
||||
test('health: damage adds up; the Anomaly is destroyed at 0 Health, loses its Hardware, and the location falls', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 6;
|
||||
t.anomaly(1, 1).damage = 6;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 3, 3, 3, 3, 3); // 24 to 15: 9 damage, 3 was enough
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null, 'destroyed: back in its slot');
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'a destroyed Avatar comes back at full Health');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, []);
|
||||
assert.equal(t.anomaly(1, 1).at, null, 'destroyed: back in its slot');
|
||||
assert.equal(t.anomaly(1, 1).damage, 0, 'a destroyed Anomaly comes back at full Health');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, []);
|
||||
assert.ok(t.s.players[1].discard.includes(hw));
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'C1');
|
||||
assert.equal(t.s.stats.capturesInCombat[0], 1);
|
||||
assert.equal(t.s.stats.avatarsDestroyed[1], 1);
|
||||
assert.equal(t.s.stats.anomaliesDestroyed[1], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 9, 'the whole margin counts as dealt');
|
||||
});
|
||||
|
||||
|
|
@ -71,18 +71,18 @@ test('health: a losing attacker takes damage and stays put, or is destroyed by a
|
|||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 4, 4); // 12 to 16
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(0, 1).damage, 4);
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'the winner takes no damage');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 4);
|
||||
assert.equal(t.anomaly(1, 1).damage, 0, 'the winner takes no damage');
|
||||
assert.equal(t.s.stats.damageDealt[1], 4);
|
||||
|
||||
const u = standoff();
|
||||
u.avatar(0, 1).damage = 5;
|
||||
u.anomaly(0, 1).damage = 5;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(1, 1, 1, 1, 2, 2, 2, 2); // 4 to 8: 4 damage, 4 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(0, 1).at, null, 'destroyed');
|
||||
assert.equal(u.avatar(0, 1).damage, 0);
|
||||
assert.equal(u.anomaly(0, 1).at, null, 'destroyed');
|
||||
assert.equal(u.anomaly(0, 1).damage, 0);
|
||||
assert.equal(u.s.locations.B1.owner, 0, 'losing an attack never loses the origin');
|
||||
});
|
||||
|
||||
|
|
@ -91,10 +91,10 @@ test('health: a tie is a stalemate, with no reroll and no damage', () => {
|
|||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 2, 2);
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).damage, 0);
|
||||
assert.equal(t.avatar(1, 1).damage, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 0);
|
||||
assert.equal(t.anomaly(1, 1).damage, 0);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.s.rigged, [], 'no dice were rerolled');
|
||||
assert.match(t.logText(), /stalemate/);
|
||||
assert.equal(t.s.stats.combatsTied[0], 1);
|
||||
|
|
@ -104,13 +104,13 @@ test('health: a tie is a stalemate, with no reroll and no damage', () => {
|
|||
test('health: recall heals fully, keeps Hardware, counts as the placement, and leaves the location undefended', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 7;
|
||||
t.avatar(1, 1).infection = 2;
|
||||
t.anomaly(1, 1).damage = 7;
|
||||
t.anomaly(1, 1).infection = 2;
|
||||
turnOf(t, 1); // South's turn passes without acting
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
assert.ok(!t.can({ type: 'recall', slot: 2 }), 'only Avatars in play can be recalled');
|
||||
assert.ok(!t.can({ type: 'recall', slot: 2 }), 'only Anomalies in play can be recalled');
|
||||
t.go({ type: 'recall', slot: 1 });
|
||||
const av = t.avatar(1, 1);
|
||||
const av = t.anomaly(1, 1);
|
||||
assert.equal(av.at, null);
|
||||
assert.equal(av.damage, 0);
|
||||
assert.equal(av.infection, 0, 'leaving play removes counters');
|
||||
|
|
@ -124,26 +124,26 @@ test('health: recall heals fully, keeps Hardware, counts as the placement, and l
|
|||
assert.ok(t.can({ type: 'advance', slot: 1, to: 'C1' }));
|
||||
});
|
||||
|
||||
test('health: a rooted Avatar can\'t be recalled, and the rule can be switched off', () => {
|
||||
test('health: a rooted Anomaly can\'t be recalled, and the rule can be switched off', () => {
|
||||
const t = standoff();
|
||||
t.avatar(0, 1).rootedUntil = FOREVER;
|
||||
t.anomaly(0, 1).rootedUntil = FOREVER;
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }), 'Packet Flood: no retreat');
|
||||
t.avatar(0, 1).rootedUntil = 0;
|
||||
t.anomaly(0, 1).rootedUntil = 0;
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
t.s.rules = withRule(t.s.rules, 'health.recall=false');
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }));
|
||||
});
|
||||
|
||||
test('health: Redundant Power Supply still saves the Hardware of a destroyed Avatar', () => {
|
||||
test('health: Redundant Power Supply still saves the Hardware of a destroyed Anomaly', () => {
|
||||
const t = standoff({ northMain: ['Redundant Power Supply', 'Additional Core'] });
|
||||
const rps = t.hardware(1, 1, 'Redundant Power Supply');
|
||||
const core = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 8;
|
||||
t.anomaly(1, 1).damage = 8;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 1); // 24 to 5
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null);
|
||||
assert.deepEqual([...t.avatar(1, 1).hardware].sort(), [rps, core].sort());
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.deepEqual([...t.anomaly(1, 1).hardware].sort(), [rps, core].sort());
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
});
|
||||
|
||||
|
|
@ -154,14 +154,14 @@ test('health: with two defenders the damage destroys the weakest first, and the
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1'); // Broken Bits, 4 Cores, 9 Health
|
||||
t.place(1, 2, 'C1'); // Pixelated Picture, 3 Cores, 10 Health
|
||||
t.avatar(1, 2).damage = 7; // 3 left
|
||||
t.anomaly(1, 2).damage = 7; // 3 left
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 5, 5, 5); // 24 to 4 + 15 = 19: 5 damage
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 2).at, null, 'the weak one is destroyed with 3 of the damage');
|
||||
assert.equal(t.avatar(1, 1).damage, 2, 'the other 2 land on the survivor');
|
||||
assert.equal(t.anomaly(1, 2).at, null, 'the weak one is destroyed with 3 of the damage');
|
||||
assert.equal(t.anomaly(1, 1).damage, 2, 'the other 2 land on the survivor');
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds with a defender left');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
|
||||
// Enough damage for both takes the location.
|
||||
const u = new Table({ health: true, north: { servers: ['Cluster Server'] } });
|
||||
|
|
@ -170,29 +170,29 @@ test('health: with two defenders the damage destroys the weakest first, and the
|
|||
u.place(0, 1, 'B1');
|
||||
u.place(1, 1, 'C1');
|
||||
u.place(1, 2, 'C1');
|
||||
u.avatar(1, 1).damage = 8;
|
||||
u.avatar(1, 2).damage = 8;
|
||||
u.anomaly(1, 1).damage = 8;
|
||||
u.anomaly(1, 2).damage = 8;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1); // 24 to 7: 17 damage for 1 + 2 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(1, 1).at, null);
|
||||
assert.equal(u.avatar(1, 2).at, null);
|
||||
assert.equal(u.anomaly(1, 1).at, null);
|
||||
assert.equal(u.anomaly(1, 2).at, null);
|
||||
assert.equal(u.s.locations.C1.owner, 0);
|
||||
assert.equal(u.avatar(0, 1).at, 'C1');
|
||||
assert.equal(u.anomaly(0, 1).at, 'C1');
|
||||
});
|
||||
|
||||
test('health: Resource Leech and Persistent Infection fire on a lost roll, not only a destruction', () => {
|
||||
const t = standoff({ northMain: ['Resource Leech', 'Persistent Infection'] });
|
||||
t.program(1, 'C1', 'Resource Leech');
|
||||
t.program(1, 'C1', 'Persistent Infection');
|
||||
const ram = t.s.players[1].ram;
|
||||
const bandwidth = t.s.players[1].bandwidth;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 4, 4); // 12 to 16: the attacker takes 4 and lives
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(0, 1).damage, 4);
|
||||
assert.equal(t.s.players[1].ram, ram + 3, 'Resource Leech pays 3');
|
||||
assert.equal(t.avatar(0, 1).permanentInfection, 1, 'a permanent Infection counter');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 4);
|
||||
assert.equal(t.s.players[1].bandwidth, bandwidth + 3, 'Resource Leech pays 3');
|
||||
assert.equal(t.anomaly(0, 1).permanentInfection, 1, 'a permanent Infection counter');
|
||||
});
|
||||
|
||||
test('health: Overflow Error only disables, until the next command, while the attacker lives', () => {
|
||||
|
|
@ -219,19 +219,19 @@ test('health: Overflow Error may destroy a Program when the attacker is destroye
|
|||
assert.equal(t.s.choice?.kind, 'Overflow Error:hit');
|
||||
t.choose('Destroy Stack Overflow').settle();
|
||||
assert.ok(t.s.players[0].discard.includes(so));
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
});
|
||||
|
||||
test("health: Backup Machine's Restore Point heals 3 damage", () => {
|
||||
const t = new Table({ health: true, south: { avatars: ['Backup Machine', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
const t = new Table({ health: true, south: { anomalies: ['Backup Machine', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
const bm = t.avatar(0, 1).card;
|
||||
const bm = t.anomaly(0, 1).card;
|
||||
assert.ok(!t.legal().some((a) => a.type === 'activate' && a.card === bm && a.args.heal), 'nothing to heal yet');
|
||||
t.avatar(0, 1).damage = 5;
|
||||
t.ram(0, 5).use(bm, { heal: true }).settle();
|
||||
assert.equal(t.avatar(0, 1).damage, 2);
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
t.anomaly(0, 1).damage = 5;
|
||||
t.bandwidth(0, 5).use(bm, { heal: true }).settle();
|
||||
assert.equal(t.anomaly(0, 1).damage, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
assert.equal(healthLeft(t.s, { player: 0, slot: 1 }), 8);
|
||||
});
|
||||
|
||||
|
|
@ -242,6 +242,6 @@ test('health: RAM Expansion adds 2 Health, so a hit that would destroy the weare
|
|||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 4, 4, 4, 3); // 24 to 15: 9 damage against 11 Health
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, 'C1', 'C1 holds');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1', 'C1 holds');
|
||||
assert.equal(healthLeft(t.s, { player: 1, slot: 1 }), 2);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd } from '../src/map.ts';
|
||||
import * as map from '../src/map.ts';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd, useBoard } from '../src/map.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
|
||||
const RULES_MD = readFileSync(new URL('../../rules.md', import.meta.url), 'utf8');
|
||||
|
||||
|
|
@ -31,3 +33,58 @@ test('levels are mirrored between the players', () => {
|
|||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(0, 'E3'), 5);
|
||||
});
|
||||
|
||||
test('the 4×4 board: squares joined side to side, levels 1–4, starts join the middle of their row', () => {
|
||||
useBoard('grid4');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 16);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 24);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['D2', 'D3']);
|
||||
assert.deepEqual(near('B2'), ['A2', 'B1', 'B3', 'C2']);
|
||||
assert.deepEqual(near('A1'), ['A2', 'B1']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'DCBA'['ABCD'.indexOf(loc[0])] + (5 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'A4'), 1);
|
||||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(1, 'A1'), 4);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('the lanes board: three lanes of five, linked only across the middle row', () => {
|
||||
useBoard('lanes');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 15);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 14);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A1', 'A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['E1', 'E2', 'E3']);
|
||||
assert.deepEqual(near('B1'), ['A1', 'C1']);
|
||||
assert.deepEqual(near('C2'), ['B2', 'C1', 'C3', 'D2']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'EDCBA'['ABCDE'.indexOf(loc[0])] + (4 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'C1'), 3);
|
||||
useBoard('lanes-open');
|
||||
assert.deepEqual(map.LINES.filter((l) => l.gateway).map((l) => l.id), ['C1-C2', 'C2-C3']);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('board=grid4 wins with 12, unless a later winLocations changes it', () => {
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=grid4').winLocations, 12);
|
||||
assert.equal(withRule(withRule(DEFAULT_RULES, 'board=grid4'), 'winLocations=11').winLocations, 11);
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=lanes').winLocations, 11);
|
||||
assert.throws(() => withRule(DEFAULT_RULES, 'board=hex'), /Unknown board/);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { winChance } from '../src/odds.ts';
|
||||
import { rollOdds, winChance } from '../src/odds.ts';
|
||||
|
||||
test('equal Cores are a coin flip and odds are complementary', () => {
|
||||
for (let a = 1; a <= 8; a++) {
|
||||
|
|
@ -16,3 +16,17 @@ test('matches the table in rules.md', () => {
|
|||
assert.equal(Math.round(100 * winChance(6, 4)), 91);
|
||||
assert.equal(Math.round(100 * winChance(8, 7)), 71);
|
||||
});
|
||||
|
||||
test('one-roll odds add up, agree with winChance, and 1 Core vs 1 Core deals 35/36 damage on average', () => {
|
||||
for (let a = 1; a <= 6; a++) {
|
||||
for (let d = 1; d <= 6; d++) {
|
||||
const o = rollOdds(a, d);
|
||||
assert.ok(Math.abs(o.win + o.tie + o.lose - 1) < 1e-12);
|
||||
assert.ok(Math.abs(o.win / (o.win + o.lose) - winChance(a, d)) < 1e-12);
|
||||
}
|
||||
}
|
||||
const one = rollOdds(1, 1);
|
||||
assert.ok(Math.abs(one.tie - 1 / 6) < 1e-12);
|
||||
assert.ok(Math.abs(one.damageDealt - 35 / 36) < 1e-12);
|
||||
assert.ok(Math.abs(one.damageDealt - one.damageTaken) < 1e-12);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores, execBlocked, executionActions, executionCost, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, execBlocked, executionActions, executionCost, openWindow } from '../src/engine.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
/** South's Avatar 1 on B1, North's Avatar 1 on C1 (both Broken Bits, 4 Cores). */
|
||||
/** South's Anomaly 1 on B1, North's Anomaly 1 on C1 (both Broken Bits, 4 Cores). */
|
||||
function scene(o: { south?: Side; north?: Side; first?: 0 | 1 } = {}) {
|
||||
const t = new Table(o);
|
||||
t.own(0, 'B1');
|
||||
|
|
@ -20,11 +20,11 @@ const defenderDice = (t: Table) => t.logText().match(/Roll: .* vs Broken Bits \[
|
|||
card('Recursive Infection', () => {
|
||||
const t = scene({ north: { main: ['Recursive Infection'] } });
|
||||
t.program(1, 'C1', 'Recursive Infection');
|
||||
t.avatar(0, 1).infection = 2;
|
||||
t.anomaly(0, 1).infection = 2;
|
||||
attackC1(t);
|
||||
assert.equal(t.avatar(0, 1).infection, 3, 'a counter for attacking');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 2, '3+ counters: -2 Cores');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack', 'S1'), 2, 'anywhere, while the Program is in play');
|
||||
assert.equal(t.anomaly(0, 1).infection, 3, 'a counter for attacking');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 2, '3+ counters: -2 Cores');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack', 'S1'), 2, 'anywhere, while the Program is in play');
|
||||
});
|
||||
|
||||
card('Recursive Infection', () => {
|
||||
|
|
@ -34,7 +34,7 @@ card('Recursive Infection', () => {
|
|||
t.program(1, 'C1', 'Recursive Infection');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C1' }).to('attack').end();
|
||||
assert.equal(t.avatar(0, 1).infection, 1, 'a counter for breaching');
|
||||
assert.equal(t.anomaly(0, 1).infection, 1, 'a counter for breaching');
|
||||
});
|
||||
|
||||
card('Memory Parasite', () => {
|
||||
|
|
@ -45,7 +45,7 @@ card('Memory Parasite', () => {
|
|||
attackC1(t);
|
||||
t.rig(6, 6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.equal(t.s.choice?.kind, 'Memory Parasite:disable');
|
||||
assert.equal(t.s.choice?.player, 0, "the attacking Avatar's owner chooses");
|
||||
assert.equal(t.s.choice?.player, 0, "the attacking Anomaly's owner chooses");
|
||||
t.choose('Additional Core').settle();
|
||||
assert.equal(attackerDice(t), 6, '4 + Overclocked CPU only');
|
||||
});
|
||||
|
|
@ -54,11 +54,11 @@ card('Replication Routine', () => {
|
|||
const t = new Table({ south: { main: ['Replication Routine', 'Resource Leech'] } });
|
||||
t.own(0, 'B1');
|
||||
const [rr, leech] = t.hand(0, 'Replication Routine', 'Resource Leech');
|
||||
t.ram(0, 6).to('play').act({ type: 'installProgram', card: rr, at: 'B1' });
|
||||
t.bandwidth(0, 6).to('play').act({ type: 'installProgram', card: rr, at: 'B1' });
|
||||
assert.equal(t.s.choice?.kind, 'Replication Routine:install');
|
||||
t.choose('Resource Leech').settle();
|
||||
assert.deepEqual(t.s.locations.B1.programs, [rr, leech]);
|
||||
assert.equal(t.s.players[0].ram, 0, 'the second Virus is free');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'the second Virus is free');
|
||||
});
|
||||
|
||||
card('Resource Leech', () => {
|
||||
|
|
@ -66,27 +66,27 @@ card('Resource Leech', () => {
|
|||
t.program(1, 'C1', 'Resource Leech');
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.s.players[1].ram, 3);
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.s.players[1].bandwidth, 3);
|
||||
});
|
||||
|
||||
card('Worm Protocol', () => {
|
||||
const t = new Table({ first: 1, north: { main: ['Worm Protocol', 'Memory Leak'] }, south: { main: ['Additional Core'] } });
|
||||
const t = new Table({ first: 1, north: { main: ['Worm Protocol', 'Bloatware'] }, south: { main: ['Additional Core'] } });
|
||||
t.own(1, 'C1');
|
||||
t.own(1, 'D1');
|
||||
t.own(0, 'C2');
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.place(1, 1, 'D1');
|
||||
const [worm] = t.hand(1, 'Worm Protocol');
|
||||
t.ram(1, 4).to('play').act({ type: 'installProgram', card: worm, at: 'C1' });
|
||||
t.bandwidth(1, 4).to('play').act({ type: 'installProgram', card: worm, at: 'C1' });
|
||||
assert.equal(t.s.choice?.kind, 'Worm Protocol:spread');
|
||||
t.choose('D1').to('playAgain').end();
|
||||
// South attacks D1, where Memory Leak now also applies.
|
||||
// South attacks D1, where Bloatware now also applies.
|
||||
t.place(0, 1, 'C2');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'D1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.match(t.logText(), /Memory Leak: Avatar 1 \(Broken Bits\) loses 1 Core/);
|
||||
assert.match(t.logText(), /Bloatware: Anomaly 1 \(Broken Bits\) loses 1 Core/);
|
||||
assert.equal(attackerDice(t), 4, '4 + 1 - 1');
|
||||
});
|
||||
|
||||
|
|
@ -97,8 +97,8 @@ card('Payload Injector', () => {
|
|||
const [ra] = t.hand(0, 'Execute: Root Access', 'Execute: Root Access');
|
||||
assert.equal(executionCost(t.s, 0, ra, 'B1', {}), 2);
|
||||
assert.equal(executionCost(t.s, 0, ra, 'A2', {}), 4, 'only when targeting its Server');
|
||||
t.ram(0, 2).play(0, 'Execute: Root Access', 'B1').settle();
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
t.bandwidth(0, 2).play(0, 'Execute: Root Access', 'B1').settle();
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
assert.equal(executionCost(t.s, 0, t.s.players[0].hand[0], 'B1', {}), 4, 'first each turn only');
|
||||
});
|
||||
|
||||
|
|
@ -107,8 +107,8 @@ card('Persistent Infection', () => {
|
|||
t.program(1, 'C1', 'Persistent Infection');
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.avatar(0, 1).permanentInfection, 1, 'stays after defeat');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(0, 1).permanentInfection, 1, 'stays after defeat');
|
||||
});
|
||||
|
||||
card('Infinite Loop', () => {
|
||||
|
|
@ -132,8 +132,8 @@ card('Stack Overflow', () => {
|
|||
const t = scene({ north: { main: ['Stack Overflow', 'Resource Leech'] } });
|
||||
t.program(1, 'C1', 'Stack Overflow');
|
||||
t.program(1, 'C1', 'Resource Leech');
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 6, '+1 per Program here');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4);
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 6, '+1 per Program here');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4);
|
||||
});
|
||||
|
||||
card('Race Condition', () => {
|
||||
|
|
@ -150,9 +150,9 @@ card('Race Condition', () => {
|
|||
}
|
||||
});
|
||||
|
||||
card('Memory Leak', () => {
|
||||
const t = scene({ south: { main: ['Additional Core', 'Overclocked CPU'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
card('Bloatware', () => {
|
||||
const t = scene({ south: { main: ['Additional Core', 'Overclocked CPU'] }, north: { main: ['Bloatware'] } });
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hardware(0, 1, 'Overclocked CPU');
|
||||
attackC1(t);
|
||||
|
|
@ -165,7 +165,7 @@ card('Null Pointer', () => {
|
|||
t.program(1, 'C1', 'Null Pointer');
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Kill Process', 'Execute: Kill Process');
|
||||
t.ram(0, 10).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
t.bandwidth(0, 10).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.equal(t.s.cards[so].disabledUntil, 0, 'the first enemy Execution has no effect');
|
||||
t.play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.ok(t.s.cards[so].disabledUntil > t.s.clock, 'once per turn');
|
||||
|
|
@ -202,11 +202,11 @@ card('Undefined Behavior', () => {
|
|||
const ub = t.program(1, 'C1', 'Undefined Behavior');
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.use(ub, { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'copied Stack Overflow: +1 for the one Program here');
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, 'copied Stack Overflow: +1 for the one Program here');
|
||||
assert.ok(t.s.cards[ub].disabledUntil > t.s.clock, 'Undefined Behavior shuts itself off');
|
||||
t.to('playAgain').end();
|
||||
assert.equal(t.s.active, 0);
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, "the copy lasts through the opponent's turn");
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, "the copy lasts through the opponent's turn");
|
||||
});
|
||||
|
||||
card('Packet Loss', () => {
|
||||
|
|
@ -228,7 +228,7 @@ card('Desynchronization', () => {
|
|||
t.hardware(0, 1, 'Hot-Swap Bay');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hand(0, 'RAM Expansion');
|
||||
t.ram(0, 10);
|
||||
t.bandwidth(0, 10);
|
||||
attackC1(t);
|
||||
t.act({ type: 'end' });
|
||||
// Broken Bits' own Ability still works after the roll; only the Hardware ability is blocked.
|
||||
|
|
@ -251,7 +251,7 @@ card('Ghost Process', () => {
|
|||
const t = scene({ south: { main: ['Ghost Process', 'Execute: Kill Process'] }, north: { main: ['Stack Overflow'] } });
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Kill Process');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
const reach = () => executionActions(t.s, 0, 'now').some((a) => a.type === 'play' && a.target === 'B1' && a.args.card === so);
|
||||
assert.ok(!reach(), 'without Ghost Process, B1 only reaches B1');
|
||||
t.program(0, 'B1', 'Ghost Process');
|
||||
|
|
@ -268,14 +268,14 @@ card('False Positive', () => {
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(0, 2, 'A2');
|
||||
t.hand(0, 'Execute: Force Reboot');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'B1' }).act({ type: 'end' });
|
||||
assert.equal(t.decider, 0, 'South may respond before the roll');
|
||||
t.play(0, 'Execute: Force Reboot', 'B1', { ref: { player: 1, slot: 1 } });
|
||||
assert.equal(t.s.choice?.kind, 'False Positive:redirect');
|
||||
t.choose('Pixelated Picture').settle();
|
||||
assert.ok(!execBlocked(t.s, 'C1'), "North's attacker is untouched");
|
||||
assert.ok(execBlocked(t.s, 'A2'), "South's own Avatar took it");
|
||||
assert.ok(execBlocked(t.s, 'A2'), "South's own Anomaly took it");
|
||||
});
|
||||
|
||||
card('Fragmentation', () => {
|
||||
|
|
@ -291,7 +291,7 @@ card('Latency Spike', () => {
|
|||
const t = scene({ south: { main: ['Execute: Ping Sweep'] }, north: { main: ['Latency Spike'] } });
|
||||
if (spike) t.program(1, 'C1', 'Latency Spike');
|
||||
t.hand(0, 'Execute: Ping Sweep');
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
attackC1(t);
|
||||
t.act({ type: 'end' });
|
||||
assert.equal(openWindow(t.s)?.kind, spike ? 'postRoll' : 'preRoll');
|
||||
|
|
@ -315,10 +315,10 @@ card('Error Correction', () => {
|
|||
t.own(0, 'B1');
|
||||
t.program(0, 'B1', 'Error Correction');
|
||||
t.place(0, 1, 'B1');
|
||||
t.avatar(0, 1).infection = 2;
|
||||
t.anomaly(0, 1).infection = 2;
|
||||
t.to('playAgain').end();
|
||||
assert.equal(t.s.active, 0);
|
||||
assert.equal(t.avatar(0, 1).infection, 1, 'one removed at the start of the turn');
|
||||
assert.equal(t.anomaly(0, 1).infection, 1, 'one removed at the start of the turn');
|
||||
});
|
||||
|
||||
card('Garbage Collection', () => {
|
||||
|
|
@ -327,7 +327,7 @@ card('Garbage Collection', () => {
|
|||
const gc = t.program(0, 'B1', 'Garbage Collection');
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.use(gc, { card: so }).settle();
|
||||
assert.equal(t.s.players[0].ram, 7);
|
||||
assert.equal(t.s.players[0].bandwidth, 7);
|
||||
assert.deepEqual(t.s.locations.B1.programs, [gc]);
|
||||
});
|
||||
|
||||
|
|
@ -346,8 +346,8 @@ card('Version Control', () => {
|
|||
});
|
||||
|
||||
card('Rollback Routine', () => {
|
||||
const t = scene({ south: { main: ['Rollback Routine', 'Additional Core'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
const t = scene({ south: { main: ['Rollback Routine', 'Additional Core'] }, north: { main: ['Bloatware'] } });
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
const rr = t.program(0, 'B1', 'Rollback Routine');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
attackC1(t);
|
||||
|
|
@ -356,17 +356,17 @@ card('Rollback Routine', () => {
|
|||
assert.equal(t.decider, 0);
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.use(rr, { ref: { player: 0, slot: 1 } }).settle();
|
||||
assert.equal(attackerDice(t), 5, "Memory Leak's -1 is undone");
|
||||
assert.equal(attackerDice(t), 5, "Bloatware's -1 is undone");
|
||||
});
|
||||
|
||||
card('Compatibility Layer', () => {
|
||||
const t = new Table({ south: { main: ['Compatibility Layer', 'Stack Overflow', 'Hotfix'] } });
|
||||
t.own(0, 'B1');
|
||||
const [cl, so, hf] = t.hand(0, 'Compatibility Layer', 'Stack Overflow', 'Hotfix');
|
||||
t.ram(0, 6 + 7 + 5).to('play');
|
||||
t.bandwidth(0, 6 + 7 + 5).to('play');
|
||||
t.go({ type: 'installProgram', card: cl, at: 'B1' });
|
||||
t.go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
t.go({ type: 'installProgram', card: hf, at: 'B1' });
|
||||
assert.equal(t.s.locations.B1.programs.length, 3);
|
||||
assert.equal(t.s.players[0].ram, 0, 'Hotfix, a Patch, cost 2 less');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'Hotfix, a Patch, cost 2 less');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores } from '../src/engine.ts';
|
||||
import { anomalyCores } from '../src/engine.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table } from './table.ts';
|
||||
|
||||
/** South advances its Avatar 1 from S1 into A2, drawing `server` for it. */
|
||||
/** South advances its Anomaly 1 from S1 into A2, drawing `server` for it. */
|
||||
function captureA2(server: string) {
|
||||
const t = new Table({ south: { servers: [server] } });
|
||||
t.nextServer(0, server);
|
||||
|
|
@ -13,36 +13,36 @@ function captureA2(server: string) {
|
|||
return t;
|
||||
}
|
||||
|
||||
card('High Efficiency RAM Server', () => {
|
||||
const t = captureA2('High Efficiency RAM Server');
|
||||
assert.equal(t.s.players[0].ram, 4 + 4, 'the capture pays 4, the Server adds 4');
|
||||
card('High Bandwidth Server', () => {
|
||||
const t = captureA2('High Bandwidth Server');
|
||||
assert.equal(t.s.players[0].bandwidth, 4 + 4, 'the capture pays 4, the Server adds 4');
|
||||
});
|
||||
|
||||
card('Power Server', () => {
|
||||
const t = captureA2('Power Server');
|
||||
assert.equal(t.s.players[0].ram, 8);
|
||||
assert.equal(t.s.players[0].bandwidth, 8);
|
||||
});
|
||||
|
||||
card('Server Farm', () => {
|
||||
const t = captureA2('Server Farm');
|
||||
assert.equal(t.s.players[0].ram, 8);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4 + 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 8);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4 + 2);
|
||||
});
|
||||
|
||||
card('MultiCore Server', () => {
|
||||
const t = new Table({ south: { servers: ['MultiCore Server'] } });
|
||||
t.own(0, 'B1', 'MultiCore Server');
|
||||
t.place(0, 1, 'B1');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 6);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 6, 'attacking from it counts too');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack', 'S1'), 4, 'only on that location');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 6);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 6, 'attacking from it counts too');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack', 'S1'), 4, 'only on that location');
|
||||
});
|
||||
|
||||
card('Cloud Compute', () => {
|
||||
const t = new Table({ south: { servers: ['Cloud Compute'] } });
|
||||
t.own(0, 'B1', 'Cloud Compute');
|
||||
t.place(0, 1, 'B1');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 8);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 8);
|
||||
});
|
||||
|
||||
const twoDefenders = (name: string) => () => {
|
||||
|
|
@ -57,8 +57,8 @@ const twoDefenders = (name: string) => () => {
|
|||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1).end();
|
||||
assert.match(t.logText(), /vs Broken Bits \[1,1,1,1\] \+ Pixelated Picture \[1,1,1\]=7/, 'both defenders roll together');
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(1, 1).at, null);
|
||||
assert.equal(t.avatar(1, 2).at, null, 'both defenders are defeated');
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.equal(t.anomaly(1, 2).at, null, 'both defenders are defeated');
|
||||
};
|
||||
card('Cluster Server', twoDefenders('Cluster Server'));
|
||||
card('Pingable Server', twoDefenders('Pingable Server'));
|
||||
|
|
@ -71,13 +71,13 @@ card('Backup Server', () => {
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1');
|
||||
t.use(backup, { ref: { player: 0, slot: 1 }, to: 'A2' }).settle();
|
||||
assert.equal(t.avatar(0, 5).at, 'A2', 'the copy of Avatar 1 is in play');
|
||||
assert.equal(avatarCores(t.s, 0, 5, 'defend'), 4);
|
||||
assert.equal(t.anomaly(0, 5).at, 'A2', 'the copy of Anomaly 1 is in play');
|
||||
assert.equal(anomalyCores(t.s, 0, 5, 'defend'), 4);
|
||||
assert.ok(!t.legal().some((a) => a.type === 'activate'), 'once per turn');
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.avatar(0, 5).at, null, 'the copy goes when the original is defeated');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(0, 5).at, null, 'the copy goes when the original is defeated');
|
||||
});
|
||||
|
||||
card('Upgraded Hardware', () => {
|
||||
|
|
@ -86,32 +86,32 @@ card('Upgraded Hardware', () => {
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(0, 2, 'S1');
|
||||
const [hw] = t.hand(0, 'Additional Core');
|
||||
t.ram(0, 3).to('play');
|
||||
t.bandwidth(0, 3).to('play');
|
||||
assert.ok(!t.can({ type: 'installHardware', card: hw, slot: 2 }), 'full price elsewhere');
|
||||
t.go({ type: 'installHardware', card: hw, slot: 1 });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
});
|
||||
|
||||
card('Network Throttle', () => {
|
||||
const t = new Table();
|
||||
t.own(0, 'A2');
|
||||
t.ram(0, 1).to('play');
|
||||
t.bandwidth(0, 1).to('play');
|
||||
t.go({ type: 'firewall', line: 'A1-A2', level: 1 });
|
||||
assert.equal(t.s.players[0].ram, 0, 'Lv 1 costs 1 next to Network Throttle');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'Lv 1 costs 1 next to Network Throttle');
|
||||
});
|
||||
|
||||
card('Duplicate Server', () => {
|
||||
for (const [copy, check] of [['Cloud Compute', 'cores'], ['High Efficiency RAM Server', 'ram']] as const) {
|
||||
const t = new Table({ south: { servers: ['Duplicate Server', 'Cloud Compute', 'High Efficiency RAM Server'] } });
|
||||
for (const [copy, check] of [['Cloud Compute', 'cores'], ['High Bandwidth Server', 'bandwidth']] as const) {
|
||||
const t = new Table({ south: { servers: ['Duplicate Server', 'Cloud Compute', 'High Bandwidth Server'] } });
|
||||
t.own(0, 'B1', 'Cloud Compute');
|
||||
t.own(0, 'B2', 'High Efficiency RAM Server');
|
||||
t.own(0, 'B2', 'High Bandwidth Server');
|
||||
t.nextServer(0, 'Duplicate Server');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.choice?.kind, 'Duplicate Server:copy');
|
||||
t.choose(copy);
|
||||
if (check === 'cores') assert.equal(avatarCores(t.s, 0, 1, 'defend'), 8);
|
||||
else assert.equal(t.s.players[0].ram, 4 + 4, 'the capture pays 4, the copied bonus 4');
|
||||
if (check === 'cores') assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 8);
|
||||
else assert.equal(t.s.players[0].bandwidth, 4 + 4, 'the capture pays 4, the copied bonus 4');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ card('Protected Server', () => {
|
|||
t.place(1, 1, 'C1');
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.s.players[1].ram, 2);
|
||||
assert.equal(t.s.players[1].bandwidth, 2);
|
||||
});
|
||||
|
||||
card('Callable Server', () => {
|
||||
|
|
|
|||
|
|
@ -3,25 +3,25 @@
|
|||
* directly and drive decisions one at a time.
|
||||
*/
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { actionKey, applyAction, createGame, decider, legalActions, openWindow } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import type { LocId } from '../src/map.ts';
|
||||
import { coresOf, fighterOf, sideCores } from '../src/query.ts';
|
||||
import { DEFAULT_RULES, type RulesConfig } from '../src/rules.ts';
|
||||
import { avatar, removeFrom } from '../src/state.ts';
|
||||
import type { Action, Args, AvatarRef, GameState, PlayerId } from '../src/types.ts';
|
||||
import { anomaly, logFor, removeFrom } from '../src/state.ts';
|
||||
import type { Action, Args, AnomalyRef, GameState, PlayerId } from '../src/types.ts';
|
||||
|
||||
export const pool = loadCards();
|
||||
|
||||
/** Cards that do nothing in hand and can't be played in response, used to pad decks. */
|
||||
const FILLER = 'Network Interface Upgrade';
|
||||
const PLAIN_SERVER = 'Network Throttle';
|
||||
/** Avatars whose Abilities only work in combat, so they don't open response windows. */
|
||||
const DEFAULT_AVATARS = ['Broken Bits', 'Pixelated Picture', 'Corrupt Driver', 'Code Zero'];
|
||||
/** Anomalies whose Abilities only work in combat, so they don't open response windows. */
|
||||
const DEFAULT_ANOMALIES = ['Broken Bits', 'Pixelated Picture', 'Corrupt Driver', 'Code Zero'];
|
||||
|
||||
export interface Side {
|
||||
avatars?: string[];
|
||||
anomalies?: string[];
|
||||
servers?: string[];
|
||||
main?: string[];
|
||||
}
|
||||
|
|
@ -31,12 +31,12 @@ export class Table {
|
|||
|
||||
constructor(o: { south?: Side; north?: Side; first?: PlayerId; seed?: number; health?: boolean } = {}) {
|
||||
const side = (x: Side = {}) => ({
|
||||
avatars: x.avatars ?? DEFAULT_AVATARS,
|
||||
anomalies: x.anomalies ?? DEFAULT_ANOMALIES,
|
||||
servers: [...(x.servers ?? []), ...Array(12).fill(PLAIN_SERVER)],
|
||||
main: [...(x.main ?? []), ...Array(12).fill(FILLER)],
|
||||
});
|
||||
const decks = [side(o.south), side(o.north)] as const;
|
||||
// Classic turns (one turn each, every Avatar acts), no turn-1 draw for the first player, and
|
||||
// Classic turns (one turn each, every Anomaly acts), no turn-1 draw for the first player, and
|
||||
// one-roll combats, which the card tests are written for. The command rule has its own tests in
|
||||
// engine.test.ts, the health rule in health.test.ts (`health: true`).
|
||||
const rules: RulesConfig = {
|
||||
|
|
@ -45,7 +45,7 @@ export class Table {
|
|||
firstTurn: { ...DEFAULT_RULES.firstTurn, draw: false },
|
||||
health: { ...DEFAULT_RULES.health, on: o.health ?? false },
|
||||
openingHand: 0,
|
||||
deck: { avatars: 4, servers: decks[0].servers.length, main: decks[0].main.length, maxCopies: 99 },
|
||||
deck: { anomalies: 4, servers: decks[0].servers.length, main: decks[0].main.length, maxCopies: 99 },
|
||||
};
|
||||
// Both decks must be the same size under one rules object; pad the shorter one.
|
||||
const n = Math.max(decks[0].main.length, decks[1].main.length);
|
||||
|
|
@ -65,10 +65,10 @@ export class Table {
|
|||
const L = this.s.locations[start];
|
||||
this.s.players[p].serverPile.push(L.server!);
|
||||
L.server = this.take(p, PLAIN_SERVER);
|
||||
this.s.players[p].ram = 0;
|
||||
// Avatars in the order given, slot 1 face up.
|
||||
const want = (p === 0 ? o.south : o.north)?.avatars ?? DEFAULT_AVATARS;
|
||||
const avs = this.s.players[p].avatars;
|
||||
this.s.players[p].bandwidth = 0;
|
||||
// Anomalies in the order given, slot 1 face up.
|
||||
const want = (p === 0 ? o.south : o.north)?.anomalies ?? DEFAULT_ANOMALIES;
|
||||
const avs = this.s.players[p].anomalies;
|
||||
want.forEach((name, i) => {
|
||||
const j = avs.findIndex((a, k) => k < 4 && k >= i && this.s.cards[a.card].name === name);
|
||||
[avs[i].card, avs[j].card] = [avs[j].card, avs[i].card];
|
||||
|
|
@ -116,8 +116,8 @@ export class Table {
|
|||
return id;
|
||||
}
|
||||
|
||||
ram(p: PlayerId, n: number): this {
|
||||
this.s.players[p].ram = n;
|
||||
bandwidth(p: PlayerId, n: number): this {
|
||||
this.s.players[p].bandwidth = n;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -130,9 +130,9 @@ export class Table {
|
|||
return L.server;
|
||||
}
|
||||
|
||||
/** Puts Avatar `slot` of `p` in play on `at` (face up). */
|
||||
place(p: PlayerId, slot: number, at: LocId): AvatarRef {
|
||||
const av = this.s.players[p].avatars[slot - 1];
|
||||
/** Puts Anomaly `slot` of `p` in play on `at` (face up). */
|
||||
place(p: PlayerId, slot: number, at: LocId): AnomalyRef {
|
||||
const av = this.s.players[p].anomalies[slot - 1];
|
||||
av.faceUp = true;
|
||||
av.at = at;
|
||||
return { player: p, slot };
|
||||
|
|
@ -146,7 +146,7 @@ export class Table {
|
|||
|
||||
hardware(p: PlayerId, slot: number, name: string): number {
|
||||
const id = this.take(p, name);
|
||||
this.s.players[p].avatars[slot - 1].hardware.push(id);
|
||||
this.s.players[p].anomalies[slot - 1].hardware.push(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ export class Table {
|
|||
return this.act({ type: 'play', card, target, args, from });
|
||||
}
|
||||
|
||||
/** Activates the ability of the card `id` (an Avatar's card id, a Program or Hardware). */
|
||||
/** Activates the ability of the card `id` (an Anomaly's card id, a Program or Hardware). */
|
||||
use(id: number, args: Args = {}): this {
|
||||
return this.act({ type: 'activate', card: id, name: this.s.cards[id].name, args });
|
||||
}
|
||||
|
|
@ -220,8 +220,8 @@ export class Table {
|
|||
// -------------------------------------------------------------------------------------------
|
||||
// Reading
|
||||
|
||||
avatar(p: PlayerId, slot: number) {
|
||||
return avatar(this.s, { player: p, slot });
|
||||
anomaly(p: PlayerId, slot: number) {
|
||||
return anomaly(this.s, { player: p, slot });
|
||||
}
|
||||
|
||||
cores(p: PlayerId, slot: number): number {
|
||||
|
|
@ -239,6 +239,6 @@ export class Table {
|
|||
}
|
||||
|
||||
logText(): string {
|
||||
return (this.s.log ?? []).join('\n');
|
||||
return logFor(this.s, null).join('\n');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue