This commit is contained in:
Forrest 2026-09-29 14:46:56 -04:00
parent 5d771eed1b
commit 5368464042
28 changed files with 887 additions and 187 deletions

View file

@ -31,8 +31,9 @@ of how much a card helps.
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,
Salvage, response windows and chains, and the win condition.
- **Every card:** all 83 cards in `../decks/files-deck-1/cards.csv` have a script, including Avatar
Abilities. Unclear card text follows the readings in `rules.md` → Card Rules; the ones marked ⚠
- **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
`--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
it was written for, so if you reword a card the sim warns you, and `npm test` fails until the

View file

@ -233,7 +233,12 @@ export function fallChance(v: GameState, ref: AvatarRef, origin: LocId, target:
/** Rough Cores a Hardware card adds in combat. */
export function hardwareCores(v: GameState, hw: number): number {
const name = v.cards[hw].name;
return { 'Additional Core': 1, 'RAM Expansion': 2, 'Overclocked CPU': 2, 'Packet Accelerator': 1 }[name] ?? 0;
return { 'Additional Core': 1, 'Overclocked CPU': 2, 'Packet Accelerator': 1 }[name] ?? 0;
}
/** Health a Hardware card adds to its wearer (RAM Expansion), when the health rule is on. */
export function hardwareHealth(v: GameState, hw: number): number {
return v.rules.health.on ? scriptOf(v.cards[hw].name)?.health ?? 0 : 0;
}
// ---------------------------------------------------------------------------------------------

View file

@ -41,6 +41,7 @@ import {
combatValue,
fallChance,
hardwareCores,
hardwareHealth,
locationValue,
printedRam,
unlocksAt,
@ -116,7 +117,7 @@ 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 === 'hardware') {
if (hardwareCores(v, id) > 0) return 6;
if (hardwareCores(v, id) > 0 || hardwareHealth(v, id) > 0) return 6;
return (UTILITY_HARDWARE[def.name] ?? 0) * 2;
}
if (def.kind === 'program') return PROGRAM_WEIGHT[def.name] ?? 1;
@ -254,6 +255,7 @@ function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
let budget = spendable(v, me);
const options: Option[] = [];
const longShots: Option[] = [];
for (const to of gridFrom(me)) {
if (controls(v, me, to)) continue;
const defended = defendersAt(v, to).length > 0;
@ -277,7 +279,14 @@ function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
const holder = occupant.get(from);
if (holder !== undefined && holder !== slot) continue;
const chance = attackOdds(v, ref, from, to);
if (chance < params.minWinChance) continue;
if (chance < params.minWinChance) {
// Health rule: a lost roll only costs damage, so a healthy Avatar 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;
options.push({ kind: 'attack', slot, to, origin: from, clear, score });
}
@ -310,6 +319,21 @@ function planTurn(v: GameState, me: PlayerId, params: GreedyParams): TurnPlan {
if (o.origin) origins.set(o.origin, o.slot);
chosen.push(o);
}
if (chosen.length === 0) {
// Nothing to advance into and no attack at good odds: take the best long shot rather than let
// the game stall with every location defended.
const shot = longShots.sort((x, y) => y.score - x.score)
.find((o) => (o.clear ? firewallCost(v, v.firewalls[o.clear]) : 0) <= budget);
if (shot) {
const cost = shot.clear ? firewallCost(v, v.firewalls[shot.clear]) : 0;
budget -= cost;
if (shot.clear) clears.add(shot.clear);
uses.set(shot.slot, 1);
usedTargets.add(shot.to);
origins.set(shot.origin!, shot.slot);
chosen.push(shot);
}
}
const deploy: Action[] = [...clears].map((line): Action => ({ type: 'clearFirewall', line }));
const pos = new Map<number, LocId | null>(ready.map((x) => [x.slot, x.at]));
@ -417,7 +441,8 @@ function copyAction(v: GameState, me: PlayerId): Action | null {
if (!spot) return null;
const backup = findUse(v, me, 'Backup Server', (a) => a.args.to === spot);
if (backup) return backup;
if (spendable(v, me) >= 5 + 4) return findUse(v, me, 'Carbon NanoBots', (a) => a.args.to === spot);
const replicate = findUse(v, me, 'Carbon NanoBots', (a) => a.args.to === spot);
if (replicate && spendable(v, me) >= actionCost(v, replicate) + 4) return replicate;
return null;
}
@ -437,9 +462,10 @@ function hardwarePlan(v: GameState, me: PlayerId, attackers: Set<number>, budget
for (const card of hand) {
const def = defOf(v, card);
if (def.kind !== 'hardware') continue;
const cores = hardwareCores(v, card);
const cores = hardwareCores(v, card) + hardwareHealth(v, card);
let target: AvatarRef | undefined;
if (cores > 0) {
// Core Hardware, and Health Hardware (RAM Expansion), go on Avatars that fight.
const attackOnly = def.name === 'Packet Accelerator';
target = wearers.find((r) => ports.get(r.slot)! > 0 && fights(r) && (!attackOnly || attackers.has(r.slot)));
} else if (def.name === 'Network Interface Upgrade') {
@ -629,7 +655,14 @@ function utilityPlays(v: GameState, me: PlayerId, budget: number): Action[] {
add(findPlay(v, me, 'Execute: Memory Dump', (a) => controls(v, me, a.target!)), 4);
add(findPlay(v, me, 'Execute: Ping Sweep', () => true), 4);
if (v.players[other(me)].hand.length > 0) add(findUse(v, me, 'Data Leaker'), 3);
// 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;
}), 5);
add(findUse(v, me, 'Backup Machine', (a) => {
if (a.args.heal) return false;
const id = a.args.card!;
return hardwareCores(v, id) > 0 || (PROGRAM_WEIGHT[cardName(v, id)] ?? 0) >= 2;
}), 5);
@ -789,8 +822,9 @@ function stopDeclaration(v: GameState, me: PlayerId): Action | null {
if (flood && stake > 5 * RAM_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);
const copy = findUse(v, me, 'Backup Server', (a) => a.args.to === d.to) ??
(reach(v, me) >= 5 ? findUse(v, me, 'Carbon NanoBots', (a) => a.args.to === d.to) : null);
(replicate && reach(v, me) >= actionCost(v, replicate) ? replicate : null);
if (copy) return copy;
// Or cash in the Programs there before they're lost.
const progs = v.locations[d.to].programs;

View file

@ -19,6 +19,8 @@ export interface CardDef {
/** Card text; flavor text for Avatars. */
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. */
set: number;
}
export interface CardPool {
@ -41,13 +43,18 @@ export const DEFAULT_CARDS_CSV = fileURLToPath(
const num = (s: string | undefined): number => (s ? Number(s) : 0);
/** Loads the Cider deck CSV. Reference cards (Turn Sequence) are skipped. */
export function loadCards(path = DEFAULT_CARDS_CSV): CardPool {
/**
* 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.
*/
export function loadCards(path = DEFAULT_CARDS_CSV, sets: number[] | 'all' = [1]): CardPool {
const all: CardDef[] = [];
const byName = new Map<string, CardDef>();
for (const row of parseCsvObjects(readFileSync(path, 'utf8'))) {
const kind = KIND_BY_TEMPLATE[row['Front Template']];
if (!kind) continue;
const set = row['Set'] ? Number(row['Set']) : 1;
if (sets !== 'all' && !sets.includes(set)) continue;
const card: CardDef = {
name: row['Name'],
kind,
@ -57,6 +64,7 @@ export function loadCards(path = DEFAULT_CARDS_CSV): CardPool {
slots: num(row['Expansion Slots']),
type: row['Type'],
text: row['Description'],
set,
};
if (row['Ability Name']) {
card.ability = {

View file

@ -154,15 +154,27 @@ export const AVATARS: Record<string, Script> = {
},
},
// Restore Point either heals 3 damage (health rule) or recovers a card from the discard pile.
'Backup Machine': {
text: '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 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.',
ability: {
uses: (s, src) =>
cardOptions(s, s.players[src.controller].discard.filter((id) => ['hardware', 'program'].includes(defOf(s, id).kind)))
uses: (s, src) => [
...(s.rules.health.on && avatar(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 card = item.args.card!;
const p = src.controller;
if (item.args.heal) {
const av = avatar(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!)}.`);
return;
}
const card = item.args.card!;
if (!removeFrom(s.players[p].discard, card)) return;
toHand(s, card);
fired(s, 'Backup Machine', p);

View file

@ -90,10 +90,10 @@ export function attachHardware(s: GameState, card: number, ref: AvatarRef): void
}
export const HARDWARE: Record<string, Script> = {
// Reading: "+2 Core capacity" means +2 Cores.
// 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 Core capacity.',
cores: () => 2,
text: 'Avatar gains +2 Health.',
health: 2,
},
'Additional Core': {
text: 'Avatar gains +1 Core.',

View file

@ -52,7 +52,7 @@ import {
usedThisTurn,
} from '../state.ts';
import { randInt } from '../rng.ts';
import { FOREVER, type AvatarRef, type GameState, type PlayerId, type Source, type Task } from '../types.ts';
import { type AvatarRef, 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;
@ -203,13 +203,14 @@ 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 is destroyed while attacking this Server, gain 5 RAM.',
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId; role: string }) {
text: 'Whenever an enemy Avatar takes damage while attacking this Server, gain 3 RAM.',
onDamage(s, src, ev) {
if (ev.loc !== src.at || ev.role !== 'attack' || !enemyOf(src, ev.ref)) return;
gainRam(s, src.controller, 5);
gainRam(s, src.controller, 3);
fired(s, 'Resource Leech', src.controller);
say(s, `Resource Leech: ${playerName(src.controller)} gains 5 RAM.`);
say(s, `Resource Leech: ${playerName(src.controller)} gains 3 RAM.`);
},
},
@ -246,10 +247,10 @@ export const PROGRAMS: Record<string, Script> = {
},
},
// Reading: enemy Avatars only (Virus Programs hit attackers). The counter survives defeat.
// Enemy Avatars are only ever at this location while attacking it. The counter survives defeat.
'Persistent Infection': {
text: 'If an Avatar is defeated at this Server, place an Infection Counter on it permanently.',
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId }) {
text: 'Whenever an enemy Avatar 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);
},
@ -330,10 +331,11 @@ export const PROGRAMS: Record<string, Script> = {
},
},
// Reading: an unspecified disable lasts until something re-enables it (Execute: Defragment).
// 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 is destroyed while attacking this Server, destroy or disable one Program that Avatar's controller has in play.",
onDefeat(s, src, ev: { ref: AvatarRef; loc: LocId; role: string }) {
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.',
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) : []))
.filter((id) => canTargetProgram(s, id, src.controller));
@ -342,9 +344,9 @@ export const PROGRAMS: Record<string, Script> = {
ask(s, {
player: src.controller,
kind: 'Overflow Error:hit',
prompt: 'Overflow Error: destroy or disable one of their Programs.',
prompt: ev.destroyed ? 'Overflow Error: destroy or disable one of their Programs.' : 'Overflow Error: disable one of their Programs.',
options: theirs.flatMap((id) => [
{ label: `Destroy ${nameOf(s, id)} on ${programLocation(s, id)}`, value: { card: id, mode: 'destroy' } },
...(ev.destroyed ? [{ label: `Destroy ${nameOf(s, id)} on ${programLocation(s, id)}`, value: { card: id, mode: 'destroy' } }] : []),
{ label: `Disable ${nameOf(s, id)} on ${programLocation(s, id)}`, value: { card: id, mode: 'disable' } },
]),
resume: { name: 'Overflow Error', fn: 'hit', data: null },
@ -354,7 +356,10 @@ export const PROGRAMS: Record<string, Script> = {
hit(s, _data, v: { card: number; mode: string }) {
if (!programLocation(s, v.card)) return;
if (v.mode === 'destroy') destroyProgram(s, v.card);
else s.cards[v.card].disabledUntil = FOREVER;
else {
const until = startOf(nextTurnOf(s, ownerOf(s, v.card)));
s.cards[v.card].disabledUntil = Math.max(s.cards[v.card].disabledUntil, until);
}
},
},
},

View file

@ -47,6 +47,7 @@ const USAGE = `Files TCG simulator
--json FILE also write the summary and every game's result as JSON
--card-report also print each card's win rate (decks holding it) and how often bots played it
--cards FILE card CSV (default decks/files-deck-1/cards.csv)
--set N card sets to load: 1 (default), 2, 1,2 or all. Set 2 has no scripts yet
Bots:
${Object.entries(BOTS).map(([name, b]) => ` ${name.padEnd(10)} ${b.about}`).join('\n')}
@ -65,6 +66,7 @@ const { values: opt } = parseArgs({
json: { type: 'string' },
'card-report': { type: 'boolean', default: false },
cards: { type: 'string', default: DEFAULT_CARDS_CSV },
set: { type: 'string', default: '1' },
help: { type: 'boolean', short: 'h', default: false },
},
});
@ -93,7 +95,7 @@ const games = count('games', opt.games)!;
const seed = count('seed', opt.seed)!;
const maxTurns = count('max-turns', opt['max-turns']);
const pool = loadCards(opt.cards);
const pool = loadCards(opt.cards, opt.set === 'all' ? 'all' : opt.set.split(',').map(Number));
let rules = maxTurns === undefined ? DEFAULT_RULES : { ...DEFAULT_RULES, maxTurns };
try {
for (const spec of opt.rule) rules = withRule(rules, spec);

View file

@ -253,22 +253,30 @@ 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): AvatarRef[] {
function allocateDamage(s: GameState, defenders: AvatarRef[], n: number): { ref: AvatarRef; amount: number; destroyed: boolean }[] {
const order = [...defenders].sort((a, b) => healthLeft(s, a) - healthLeft(s, b));
const destroyed: AvatarRef[] = [];
const hits: { ref: AvatarRef; amount: number; destroyed: boolean }[] = [];
for (const [i, d] of order.entries()) {
if (n <= 0) break;
const left = healthLeft(s, d);
const hit = n >= left ? left : i === order.length - 1 ? n : 0;
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);
if (first) first.amount += n;
else hits.push({ ref: order[0], amount: n, destroyed: false });
break;
}
n -= hit;
if (damageAvatar(s, d, hit)) destroyed.push(d);
hits.push({ ref: d, amount: hit, destroyed: damageAvatar(s, d, hit) });
}
return destroyed;
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 {
emit(s, 'onDamage', { ref, loc, role, amount, destroyed });
}
/** Health rule: the loser of the roll takes the difference as damage; destroyed Avatars are defeated. */
@ -287,14 +295,19 @@ function resolveDamage(s: GameState, c: Combat, t: { atk: number; def: number })
stat(s, 'damageDealt', winner, margin);
if (attackerWins) {
stat(s, 'attacksWon', c.attacker.player);
const destroyed = allocateDamage(s, c.defenders, margin);
const hits = allocateDamage(s, c.defenders, margin);
const destroyed = hits.filter((h) => h.destroyed).map((h) => h.ref);
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.`);
pushTasks(s, ...tasks);
} else if (damageAvatar(s, c.attacker, margin)) {
pushTasks(s, { t: 'defeat', ref: c.attacker, loc: c.loc, role: 'attack' });
// 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);
if (dead) pushTasks(s, { t: 'defeat', ref: c.attacker, loc: c.loc, role: 'attack' });
emitDamage(s, c.attacker, c.loc, 'attack', margin, dead);
}
}
@ -419,8 +432,11 @@ export function combatStage(s: GameState, stage: 'start' | 'roll' | 'result' | '
...c.defenders.map((ref): Task => ({ t: 'defeat', ref, loc: c.loc, role: 'defend' })),
{ t: 'capture', ref: c.attacker, loc: c.loc, stage: 'hooks', how: 'capturesInCombat' },
);
// Without the health rule a lost roll destroys, so the damage hooks fire with the full Health.
for (const ref of c.defenders) emitDamage(s, ref, c.loc, 'defend', healthLeft(s, ref), true);
} else {
pushTasks(s, { t: 'defeat', ref: c.attacker, loc: c.loc, role: 'attack' });
emitDamage(s, c.attacker, c.loc, 'attack', healthLeft(s, c.attacker), true);
}
}

View file

@ -77,7 +77,7 @@ export interface Script {
noPort?: boolean;
/** Hardware: Expansion Slots it adds to its wearer (Network Interface Upgrade). */
extraSlots?: number;
/** Hardware: Health it adds to its wearer (health rule). No card does yet. */
/** 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). */
extraAttacks?: number;
@ -118,6 +118,11 @@ export interface Script {
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 Avatar 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;
onCombatEnd?(s: GameState, src: Source): void;
/**
* Hardware: its wearer was just defeated. Return true to take over what happens to the Hardware

View file

@ -131,6 +131,8 @@ export interface Args {
cards?: number[];
to?: LocId;
mode?: 'destroy' | 'disable';
/** Restore Point: heal instead of recovering a card. */
heal?: boolean;
/** Bit Flip: reroll dice showing this or less. */
k?: number;
}
@ -216,6 +218,7 @@ export type HookName =
| 'onInstall'
| 'onCombatStart'
| 'onDefeat'
| 'onDamage'
| 'onCombatEnd';
/** Something that has an effect in play. */

View file

@ -28,7 +28,7 @@ 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, 5).use(avatarCard(t, 0, 1), { to: 'A2' }).settle();
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");
// The copy attacks and loses: the original keeps its Hardware.
@ -44,7 +44,7 @@ test('copy rule variants: a new copy defends but only advances or attacks from i
const t = scene('Carbon NanoBots', 'Broken Bits');
t.s.rules = withRule(t.s.rules, 'copies.waitATurn=true');
t.own(0, 'A2');
t.ram(0, 5).use(avatarCard(t, 0, 1), { to: 'A2' }).settle();
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');
const acts = () => t.legal().filter((a) => (a.type === 'advance' || a.type === 'attack') && a.slot === 5);
assert.deepEqual(acts(), []);
@ -58,7 +58,7 @@ test('copy rule variants: a new copy defends but only advances or attacks from i
test('copy rule variants: copies can need Avatar 2 unlocked, or be off', () => {
const t = scene('Carbon NanoBots', 'Broken Bits');
t.own(0, 'A2');
t.ram(0, 5);
t.ram(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');
@ -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, 5);
t.ram(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'));
@ -101,8 +101,8 @@ card('Pixelated Picture', () => {
});
card('Beta Version 1.0', () => {
const t = scene('Beta Version 1.0', 'Broken Bits', { south: { main: ['Additional Core', 'RAM Expansion', 'Packet Accelerator'] } });
t.hardware(0, 1, 'RAM Expansion');
const t = scene('Beta Version 1.0', 'Broken Bits', { south: { main: ['Additional Core', 'Overclocked CPU', 'Packet Accelerator'] } });
t.hardware(0, 1, 'Overclocked CPU');
t.hardware(0, 1, 'Packet Accelerator');
const [ac] = t.hand(0, 'Additional Core');
t.ram(0, 4 + 5);

View file

@ -34,6 +34,37 @@ test('every card has its own test', () => {
assert.deepEqual(pool.all.map((c) => c.name).filter((n) => !tested.has(n)), []);
});
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('server'), 7);
assert.equal(count('program'), 17);
assert.equal(count('hardware'), 8);
assert.equal(count('execution'), 8);
for (const c of two.all) {
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') {
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`);
} else if (c.kind === 'program') {
assert.ok(c.type && c.ram >= 4 && c.ram <= 6, `${c.name}: typed, 4-6 RAM`);
} else if (c.kind === 'execution') {
assert.ok(c.ram >= 3 && c.ram <= 5, `${c.name}: 3-5 RAM`);
} else if (c.kind === 'hardware') {
assert.ok(c.ram >= 4 && c.ram <= 7, `${c.name}: 4-7 RAM`);
}
}
const all = loadCards(undefined, 'all');
assert.equal(all.all.length, pool.all.length + two.all.length);
const warnings = staleScripts(all);
assert.equal(warnings.length, two.all.length, 'one warning per set 2 card');
assert.ok(warnings.every((w) => w.endsWith('no script yet')), 'the only warnings are missing scripts');
});
test('random decks are legal', () => {
const rng = makeRng(3);
for (let i = 0; i < 50; i++) {

View file

@ -2,7 +2,7 @@ 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 { portsFree } from '../src/query.ts';
import { healthOf, portsFree } from '../src/query.ts';
import { card } from './card.ts';
import { Table, type Side } from './table.ts';
@ -20,7 +20,8 @@ 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'), 6);
assert.equal(avatarCores(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', () => {

View file

@ -15,8 +15,8 @@ function turnOf(t: Table, p: 0 | 1): Table {
}
/** South's Avatar 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Avatar 1 on C1. */
function standoff(o: { northMain?: string[] } = {}): Table {
const t = new Table({ health: true, north: { main: o.northMain } });
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');
t.own(1, 'C1');
t.place(0, 1, 'B1');
@ -180,3 +180,68 @@ test('health: with two defenders the damage destroys the weakest first, and the
assert.equal(u.s.locations.C1.owner, 0);
assert.equal(u.avatar(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;
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');
});
test('health: Overflow Error only disables, until the next command, while the attacker lives', () => {
const t = standoff({ northMain: ['Overflow Error'], southMain: ['Stack Overflow'] });
t.program(1, 'C1', 'Overflow Error');
const so = t.program(0, 'B1', 'Stack Overflow');
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
t.rig(3, 3, 3, 3, 4, 4, 4, 4);
t.end();
assert.equal(t.s.choice?.kind, 'Overflow Error:hit');
assert.ok(t.s.choice!.options.every((o) => o.label.startsWith('Disable')), 'no destroy option while the attacker lives');
t.choose('Disable Stack Overflow').settle();
assert.ok(t.s.cards[so].disabledUntil > t.s.clock && t.s.cards[so].disabledUntil < FOREVER, 'disabled until the next command');
assert.ok(t.s.locations.B1.programs.includes(so), 'still installed');
});
test('health: Overflow Error may destroy a Program when the attacker is destroyed', () => {
const t = standoff({ northMain: ['Overflow Error'], southMain: ['Stack Overflow'] });
t.program(1, 'C1', 'Overflow Error');
const so = t.program(0, 'B1', 'Stack Overflow');
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
t.rig(1, 1, 1, 1, 6, 6, 6, 6); // 4 to 24: 20 damage on 9 Health
t.end();
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);
});
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'] } });
t.own(0, 'B1');
t.place(0, 1, 'B1');
const bm = t.avatar(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);
assert.equal(healthLeft(t.s, { player: 0, slot: 1 }), 8);
});
test('health: RAM Expansion adds 2 Health, so a hit that would destroy the wearer leaves it standing', () => {
const t = standoff({ northMain: ['RAM Expansion'] });
t.hardware(1, 1, 'RAM Expansion');
assert.equal(healthOf(t.s, { player: 1, slot: 1 }), 11);
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(healthLeft(t.s, { player: 1, slot: 1 }), 2);
});

View file

@ -38,16 +38,16 @@ card('Recursive Infection', () => {
});
card('Memory Parasite', () => {
const t = scene({ south: { main: ['Additional Core', 'RAM Expansion'] }, north: { main: ['Memory Parasite'] } });
const t = scene({ south: { main: ['Additional Core', 'Overclocked CPU'] }, north: { main: ['Memory Parasite'] } });
t.program(1, 'C1', 'Memory Parasite');
t.hardware(0, 1, 'Additional Core');
t.hardware(0, 1, 'RAM Expansion');
t.hardware(0, 1, 'Overclocked CPU');
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");
t.choose('Additional Core').settle();
assert.equal(attackerDice(t), 6, '4 + RAM Expansion only');
assert.equal(attackerDice(t), 6, '4 + Overclocked CPU only');
});
card('Replication Routine', () => {
@ -67,7 +67,7 @@ card('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, 5);
assert.equal(t.s.players[1].ram, 3);
});
card('Worm Protocol', () => {
@ -151,10 +151,10 @@ card('Race Condition', () => {
});
card('Memory Leak', () => {
const t = scene({ south: { main: ['Additional Core', 'RAM Expansion'] }, north: { main: ['Memory Leak'] } });
const t = scene({ south: { main: ['Additional Core', 'Overclocked CPU'] }, north: { main: ['Memory Leak'] } });
t.program(1, 'C1', 'Memory Leak');
t.hardware(0, 1, 'Additional Core');
t.hardware(0, 1, 'RAM Expansion');
t.hardware(0, 1, 'Overclocked CPU');
attackC1(t);
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1).end();
assert.equal(attackerDice(t), 5, '4 + 3 - 2 Hardware');