372 lines
15 KiB
TypeScript
372 lines
15 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { anomalyCores, execBlocked, executionActions, executionCost, openWindow } from '../src/engine.ts';
|
|
import { card } from './card.ts';
|
|
import { Table, type Side } from './table.ts';
|
|
|
|
/** 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');
|
|
t.own(1, 'C1');
|
|
t.place(0, 1, 'B1');
|
|
t.place(1, 1, 'C1');
|
|
return t;
|
|
}
|
|
const attackC1 = (t: Table) => t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
|
/** Dice South's attacker rolled, from the log. */
|
|
const attackerDice = (t: Table) => t.logText().match(/Roll: Broken Bits \[([\d,]*)\]/)![1].split(',').length;
|
|
const defenderDice = (t: Table) => t.logText().match(/Roll: .* vs Broken Bits \[([\d,]*)\]/)![1].split(',').length;
|
|
|
|
card('Recursive Infection', () => {
|
|
const t = scene({ north: { main: ['Recursive Infection'] } });
|
|
t.program(1, 'C1', 'Recursive Infection');
|
|
t.anomaly(0, 1).infection = 2;
|
|
attackC1(t);
|
|
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', () => {
|
|
const t = new Table({ north: { main: ['Recursive Infection'] } });
|
|
t.own(0, 'B1');
|
|
t.own(1, 'C1');
|
|
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.anomaly(0, 1).infection, 1, 'a counter for breaching');
|
|
});
|
|
|
|
card('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, '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 Anomaly's owner chooses");
|
|
t.choose('Additional Core').settle();
|
|
assert.equal(attackerDice(t), 6, '4 + Overclocked CPU only');
|
|
});
|
|
|
|
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.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].bandwidth, 0, 'the second Virus is free');
|
|
});
|
|
|
|
card('Resource Leech', () => {
|
|
const t = scene({ north: { main: ['Resource Leech'] } });
|
|
t.program(1, 'C1', 'Resource Leech');
|
|
attackC1(t);
|
|
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
|
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', 'Bloatware'] }, south: { main: ['Additional Core'] } });
|
|
t.own(1, 'C1');
|
|
t.own(1, 'D1');
|
|
t.own(0, 'C2');
|
|
t.program(1, 'C1', 'Bloatware');
|
|
t.place(1, 1, 'D1');
|
|
const [worm] = t.hand(1, 'Worm Protocol');
|
|
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 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(), /Bloatware: Anomaly 1 \(Broken Bits\) loses 1 Core/);
|
|
assert.equal(attackerDice(t), 4, '4 + 1 - 1');
|
|
});
|
|
|
|
card('Payload Injector', () => {
|
|
const t = new Table({ south: { main: ['Payload Injector', 'Execute: Root Access', 'Execute: Root Access'] } });
|
|
t.own(0, 'B1');
|
|
t.program(0, 'B1', '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.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');
|
|
});
|
|
|
|
card('Persistent Infection', () => {
|
|
const t = scene({ north: { main: ['Persistent Infection'] } });
|
|
t.program(1, 'C1', 'Persistent Infection');
|
|
attackC1(t);
|
|
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
|
assert.equal(t.anomaly(0, 1).at, null);
|
|
assert.equal(t.anomaly(0, 1).permanentInfection, 1, 'stays after defeat');
|
|
});
|
|
|
|
card('Infinite Loop', () => {
|
|
const t = new Table({ south: { main: ['Infinite Loop'] } });
|
|
t.own(0, 'B1');
|
|
t.own(1, 'C1');
|
|
t.own(1, 'C2');
|
|
t.place(0, 1, 'B1');
|
|
t.place(1, 1, 'C1');
|
|
t.place(1, 2, 'C2');
|
|
t.program(0, 'B1', 'Infinite Loop');
|
|
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
|
assert.ok(t.can({ type: 'attack', slot: 1, to: 'C2' }), 'a second attack');
|
|
t.go({ type: 'attack', slot: 1, to: 'C2' });
|
|
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 6, 6, 6, 6, 1, 1, 1).end();
|
|
assert.equal(t.s.locations.C1.owner, 0);
|
|
assert.equal(t.s.locations.C2.owner, 0, 'both attacks resolve');
|
|
});
|
|
|
|
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(anomalyCores(t.s, 1, 1, 'defend'), 6, '+1 per Program here');
|
|
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4);
|
|
});
|
|
|
|
card('Race Condition', () => {
|
|
for (const [atk, def, bonus] of [['Attack', 'Defend', true], ['Defend', 'Defend', false]] as const) {
|
|
const t = scene({ north: { main: ['Race Condition'] } });
|
|
t.program(1, 'C1', 'Race Condition');
|
|
attackC1(t);
|
|
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 1, 1).end();
|
|
assert.equal(t.s.choice?.player, 0, 'attacker picks first');
|
|
t.choose(atk);
|
|
assert.equal(t.s.choice?.player, 1);
|
|
t.choose(def).settle();
|
|
assert.equal(defenderDice(t), bonus ? 6 : 4);
|
|
}
|
|
});
|
|
|
|
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);
|
|
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
|
assert.equal(attackerDice(t), 5, '4 + 3 - 2 Hardware');
|
|
});
|
|
|
|
card('Null Pointer', () => {
|
|
const t = scene({ south: { main: ['Execute: Kill Process', 'Execute: Kill Process'] }, north: { main: ['Null Pointer', 'Stack Overflow'] } });
|
|
t.program(1, 'C1', 'Null Pointer');
|
|
const so = t.program(1, 'C1', 'Stack Overflow');
|
|
t.hand(0, 'Execute: Kill Process', 'Execute: Kill Process');
|
|
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');
|
|
});
|
|
|
|
card('Stock Rice', () => {
|
|
const t = scene({ south: { main: ['Additional Core'] }, north: { main: ['Stock Rice', 'Additional Core'] } });
|
|
t.program(1, 'C1', 'Stock Rice');
|
|
t.hardware(0, 1, 'Additional Core');
|
|
t.hardware(1, 1, 'Additional Core');
|
|
attackC1(t);
|
|
t.rig(6, 6, 6, 6, 1, 1, 1, 1).end();
|
|
assert.equal(attackerDice(t), 4);
|
|
assert.equal(defenderDice(t), 4, 'neither side gets Hardware bonuses');
|
|
});
|
|
|
|
card('Overflow Error', () => {
|
|
const t = scene({ south: { main: ['Stack Overflow'] }, north: { main: ['Overflow Error'] } });
|
|
t.program(1, 'C1', 'Overflow Error');
|
|
const so = t.program(0, 'B1', 'Stack Overflow');
|
|
attackC1(t);
|
|
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
|
assert.equal(t.s.choice?.kind, 'Overflow Error:hit');
|
|
t.choose('Destroy Stack Overflow').settle();
|
|
assert.deepEqual(t.s.locations.B1.programs, []);
|
|
assert.ok(t.s.players[0].discard.includes(so));
|
|
});
|
|
|
|
card('Undefined Behavior', () => {
|
|
const t = new Table({ first: 1, south: { main: ['Stack Overflow'] }, north: { main: ['Undefined Behavior'] } });
|
|
t.own(0, 'B1');
|
|
t.own(1, 'C1');
|
|
t.place(1, 1, 'C1');
|
|
const ub = t.program(1, 'C1', 'Undefined Behavior');
|
|
const so = t.program(0, 'B1', 'Stack Overflow');
|
|
t.use(ub, { card: so }).settle();
|
|
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(anomalyCores(t.s, 1, 1, 'defend'), 5, "the copy lasts through the opponent's turn");
|
|
});
|
|
|
|
card('Packet Loss', () => {
|
|
const t = new Table({ south: { main: ['Additional Core'] }, north: { main: ['Packet Loss'] } });
|
|
t.own(0, 'B1');
|
|
t.own(1, 'C1');
|
|
t.program(1, 'C1', 'Packet Loss');
|
|
t.place(0, 1, 'B1');
|
|
const [hw] = t.hand(0, 'Additional Core');
|
|
t.go({ type: 'advance', slot: 1, to: 'C1' }).to('attack').end();
|
|
assert.deepEqual(t.s.players[0].hand, []);
|
|
assert.ok(t.s.players[0].discard.includes(hw));
|
|
});
|
|
|
|
card('Desynchronization', () => {
|
|
for (const desync of [false, true]) {
|
|
const t = scene({ south: { main: ['Hot-Swap Bay', 'Additional Core', 'RAM Expansion'] }, north: { main: ['Desynchronization'] } });
|
|
if (desync) t.program(1, 'C1', 'Desynchronization');
|
|
t.hardware(0, 1, 'Hot-Swap Bay');
|
|
t.hardware(0, 1, 'Additional Core');
|
|
t.hand(0, 'RAM Expansion');
|
|
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.
|
|
const w = openWindow(t.s);
|
|
if (desync) assert.equal(w?.kind, 'postRoll', 'no Hot-Swap Bay before the roll');
|
|
else assert.equal(w?.kind, 'preRoll', 'South may use Hot-Swap Bay before the roll');
|
|
}
|
|
});
|
|
|
|
card('Visual Artifact', () => {
|
|
const t = scene({ north: { main: ['Visual Artifact'] } });
|
|
const va = t.program(1, 'C1', 'Visual Artifact');
|
|
attackC1(t);
|
|
t.rig(1, 1, 1, 6, 6, 6, 6).end();
|
|
assert.equal(attackerDice(t), 3);
|
|
assert.equal(t.s.cards[va].spent, true, 'only the first attack');
|
|
});
|
|
|
|
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.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');
|
|
assert.ok(reach(), 'with it, a Kill Process on B1 can hit C1');
|
|
});
|
|
|
|
card('False Positive', () => {
|
|
const t = new Table({ first: 1, north: { main: ['False Positive'] }, south: { main: ['Execute: Force Reboot'] } });
|
|
t.own(1, 'C1');
|
|
t.own(0, 'B1');
|
|
t.own(0, 'A2');
|
|
t.program(1, 'C1', 'False Positive');
|
|
t.place(1, 1, 'C1');
|
|
t.place(0, 1, 'B1');
|
|
t.place(0, 2, 'A2');
|
|
t.hand(0, 'Execute: Force Reboot');
|
|
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 Anomaly took it");
|
|
});
|
|
|
|
card('Fragmentation', () => {
|
|
const t = scene({ south: { main: ['Execute: Root Access'] }, north: { main: ['Fragmentation'] } });
|
|
t.program(1, 'C1', 'Fragmentation');
|
|
const [ra] = t.hand(0, 'Execute: Root Access');
|
|
assert.equal(executionCost(t.s, 0, ra, 'C1', {}), 6);
|
|
assert.equal(executionCost(t.s, 0, ra, 'B1', {}), 4);
|
|
});
|
|
|
|
card('Latency Spike', () => {
|
|
for (const spike of [false, true]) {
|
|
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.bandwidth(0, 4);
|
|
attackC1(t);
|
|
t.act({ type: 'end' });
|
|
assert.equal(openWindow(t.s)?.kind, spike ? 'postRoll' : 'preRoll');
|
|
}
|
|
});
|
|
|
|
card('Hotfix', () => {
|
|
const t = scene({ south: { main: ['Hotfix', 'Stack Overflow'] }, north: { main: ['Overflow Error'] } });
|
|
t.program(1, 'C1', 'Overflow Error');
|
|
t.program(0, 'B1', 'Hotfix');
|
|
const so = t.program(0, 'B1', 'Stack Overflow');
|
|
attackC1(t);
|
|
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
|
t.choose('Destroy Stack Overflow').settle();
|
|
assert.ok(t.s.locations.B1.programs.includes(so), 'still installed');
|
|
assert.ok(t.s.cards[so].disabledUntil > t.s.clock, 'but disabled');
|
|
});
|
|
|
|
card('Error Correction', () => {
|
|
const t = new Table({ first: 1, south: { main: ['Error Correction'] } });
|
|
t.own(0, 'B1');
|
|
t.program(0, 'B1', 'Error Correction');
|
|
t.place(0, 1, 'B1');
|
|
t.anomaly(0, 1).infection = 2;
|
|
t.to('playAgain').end();
|
|
assert.equal(t.s.active, 0);
|
|
assert.equal(t.anomaly(0, 1).infection, 1, 'one removed at the start of the turn');
|
|
});
|
|
|
|
card('Garbage Collection', () => {
|
|
const t = new Table({ south: { main: ['Garbage Collection', 'Stack Overflow'] } });
|
|
t.own(0, 'B1');
|
|
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].bandwidth, 7);
|
|
assert.deepEqual(t.s.locations.B1.programs, [gc]);
|
|
});
|
|
|
|
card('Version Control', () => {
|
|
const t = new Table({ north: { main: ['Version Control', 'Stack Overflow'] } });
|
|
t.own(0, 'B1');
|
|
t.own(1, 'C1');
|
|
const vc = t.program(1, 'C1', 'Version Control');
|
|
const so = t.program(1, 'C1', 'Stack Overflow');
|
|
t.place(0, 1, 'B1');
|
|
t.go({ type: 'advance', slot: 1, to: 'C1' }).to('attack').end();
|
|
assert.equal(t.s.choice?.kind, 'Version Control:save');
|
|
t.choose('Stack Overflow').settle();
|
|
assert.deepEqual(t.s.players[1].hand, [so]);
|
|
assert.ok(t.s.players[1].discard.includes(vc));
|
|
});
|
|
|
|
card('Rollback Routine', () => {
|
|
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);
|
|
t.act({ type: 'end' });
|
|
assert.equal(openWindow(t.s)?.kind, 'preRoll');
|
|
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, "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.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].bandwidth, 0, 'Hotfix, a Patch, cost 2 less');
|
|
});
|