files-tcg/sim/test/servers.test.ts
2026-09-28 01:56:25 -04:00

139 lines
5.2 KiB
TypeScript

import assert from 'node:assert/strict';
import { avatarCores } 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. */
function captureA2(server: string) {
const t = new Table({ south: { servers: [server] } });
t.nextServer(0, server);
t.place(0, 1, 'S1');
t.go({ type: 'advance', slot: 1, to: 'A2' }).to('attack').end();
assert.equal(t.s.locations.A2.owner, 0);
return t;
}
card('High Efficiency RAM Server', () => {
const t = captureA2('High Efficiency RAM Server');
assert.equal(t.s.players[0].ram, 4 + 4, 'Lv 2 pays 4, the Server adds 4');
});
card('Power Server', () => {
const t = captureA2('Power Server');
assert.equal(t.s.players[0].ram, 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);
});
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');
});
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);
});
const twoDefenders = (name: string) => () => {
const t = new Table({ north: { servers: [name] } });
t.own(0, 'B1');
t.own(1, 'C1', name);
t.place(0, 1, 'B1');
t.place(1, 1, 'C1');
t.place(1, 2, 'C1');
assert.equal(t.s.locations.C1.owner, 1);
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
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');
};
card('Cluster Server', twoDefenders('Cluster Server'));
card('Pingable Server', twoDefenders('Pingable Server'));
card('Backup Server', () => {
const t = new Table({ south: { servers: ['Backup Server'] } });
const backup = t.own(0, 'B1', 'Backup Server');
t.own(0, 'A2');
t.own(1, 'C1');
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.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');
});
card('Upgraded Hardware', () => {
const t = new Table({ south: { servers: ['Upgraded Hardware'], main: ['Additional Core'] } });
t.own(0, 'B1', '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');
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);
});
card('Network Throttle', () => {
const t = new Table();
t.own(0, 'A2');
t.ram(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');
});
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'] } });
t.own(0, 'B1', 'Cloud Compute');
t.own(0, 'B2', 'High Efficiency RAM 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, 6 + 4, 'Lv 3 pays 6, the copied bonus 4');
}
});
card('Protected Server', () => {
const t = new Table({ north: { servers: ['Protected Server'] } });
t.own(0, 'B1');
t.own(1, 'C1', 'Protected Server');
t.place(0, 1, 'B1');
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);
});
card('Callable Server', () => {
const t = new Table({ first: 1, south: { servers: ['Callable Server'], main: ['Additional Core', 'Cooling System'] } });
t.own(0, 'B1', 'Callable Server');
const [a, b] = t.top(0, 'Additional Core', 'Cooling System');
t.to('playAgain').end();
assert.equal(t.s.choice?.kind, 'Callable Server:redraw');
t.choose('Bottom').settle();
const pl = t.s.players[0];
assert.deepEqual(pl.hand, [b]);
assert.equal(pl.deck[pl.deck.length - 1], a);
});