import assert from 'node:assert/strict'; import { avatarCores, openWindow } from '../src/engine.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. */ 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) } }); t.own(0, 'B1'); t.own(1, 'C1'); t.place(0, 1, 'B1'); t.place(1, 1, 'C1'); return t; } const fight = (t: Table) => t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' }).act({ type: 'end' }); 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; 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(); 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. t.place(0, 1, 'S1'); t.s.players[0].avatars[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); }); 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); fight(t); t.rig(1, 1, 1, 6, 6, 6, 6); t.use(avatarCard(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); fight(t); assert.equal(t.decider, 1); t.rig(6, 6, 6, 1, 1, 1); t.use(avatarCard(t, 1, 1)).settle(); assert.equal(dice(t, 'atk'), 3, 'the attacker has -1 Core'); }); 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'); t.hardware(0, 1, 'Packet Accelerator'); const [ac] = t.hand(0, 'Additional Core'); t.ram(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.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.avatar(0, 1).infection = 1; t.ram(1, 4); fight(t); assert.equal(t.decider, 1); t.rig(6, 6, 6, 1, 1); t.use(avatarCard(t, 1, 1)).settle(); assert.equal(t.avatar(0, 1).infection >= 2 || t.avatar(0, 1).at === null, true); assert.equal(dice(t, 'atk'), 3, '2 Infection counters: -1 Core while Code Zero is in play'); }); 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); // 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)); 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[0].hand.length, 1, 'it breached this turn, so it draws'); }); 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 }); 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'); }); card('Broken Bits', () => { const t = scene('Broken Bits', 'Broken Bits'); t.ram(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(); assert.match(t.logText(), /Bit Flip rerolls 4 dice/); assert.equal(t.s.locations.C1.owner, 0); });