sim
This commit is contained in:
parent
746d218eda
commit
e590baf28d
44 changed files with 8308 additions and 0 deletions
194
sim/test/engine.test.ts
Normal file
194
sim/test/engine.test.ts
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { randomDeck } from '../src/deck.ts';
|
||||
import { advanceTargets, avatarCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES } from '../src/rules.ts';
|
||||
import { Table } from './table.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
||||
test('setup follows rules.md', () => {
|
||||
const rng = makeRng(5);
|
||||
const decks = [randomDeck(pool, rng, DEFAULT_RULES), randomDeck(pool, rng, DEFAULT_RULES)] as const;
|
||||
const s = createGame({ pool, decks: [decks[0], decks[1]], seed: 3 });
|
||||
for (const p of [0, 1] as const) {
|
||||
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.equal(s.locations[p === 0 ? 'S1' : 'S2'].owner, p);
|
||||
}
|
||||
assert.equal(s.turn, 1);
|
||||
assert.equal(s.active, s.firstPlayer);
|
||||
assert.deepEqual(checkInvariants(s), []);
|
||||
});
|
||||
|
||||
test('the first player skips the draw; the second player draws', () => {
|
||||
const t = new Table({ south: { main: ['Additional Core'] }, north: { main: ['Additional Core'] } });
|
||||
assert.equal(t.s.players[0].hand.length, 0);
|
||||
t.to('playAgain').end();
|
||||
assert.equal(t.s.active, 1);
|
||||
assert.equal(t.s.players[1].hand.length, 1);
|
||||
});
|
||||
|
||||
test('advancing captures an unowned location in step 5, pays its level and unlocks an Avatar', () => {
|
||||
const t = new Table();
|
||||
t.ram(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 a Lv 2 capture');
|
||||
assert.equal(t.avatar(0, 2).faceUp, true, 'Lv 2 unlocks Avatar 2');
|
||||
assert.equal(t.s.step, 'playAgain');
|
||||
});
|
||||
|
||||
test('placement closes once an advance is declared', () => {
|
||||
const t = new Table();
|
||||
t.go({ type: 'place', slot: 1, to: 'S1' }).go({ type: 'advance', slot: 1, to: 'A2' });
|
||||
assert.ok(!t.legal().some((a) => a.type === 'place'));
|
||||
});
|
||||
|
||||
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' });
|
||||
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.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');
|
||||
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.firewalls['A1-A2'], 2);
|
||||
});
|
||||
|
||||
test('combat: the loser goes back to its slot and loses its Hardware; the winner captures', () => {
|
||||
for (const attackerWins of [true, false]) {
|
||||
const t = new Table({ north: { main: ['Additional Core'] } });
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.place(0, 1, 'B1');
|
||||
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');
|
||||
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.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.s.stats.attacks[0], 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('ties reroll every die', () => {
|
||||
const t = new Table();
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1');
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.end();
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.match(t.logText(), /after 1 tie reroll/);
|
||||
});
|
||||
|
||||
test('an attacker can only hit a defended location next to where it stands', () => {
|
||||
const t = new Table();
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.own(1, 'C3');
|
||||
t.place(1, 1, 'C1');
|
||||
t.place(1, 2, 'C3');
|
||||
t.place(0, 1, 'B1');
|
||||
t.to('attack');
|
||||
assert.deepEqual(
|
||||
t.legal().filter((a) => a.type === 'attack'),
|
||||
[{ type: 'attack', slot: 1, to: 'C1' }],
|
||||
);
|
||||
});
|
||||
|
||||
test('reaching the location target wins immediately', () => {
|
||||
const t = new Table();
|
||||
for (const loc of ['A1', 'A3', 'B1', 'B2', 'C1', 'C2', 'C3', 'D1', 'D2']) t.own(0, loc);
|
||||
t.place(0, 1, 'S1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'A2' }).to('attack').end();
|
||||
assert.equal(t.s.over, true);
|
||||
assert.equal(t.s.winner, 0);
|
||||
assert.equal(t.s.endReason, 'win');
|
||||
assert.deepEqual(legalActions(t.s), []);
|
||||
});
|
||||
|
||||
test('Salvage pays full printed RAM, 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.ok(t.s.players[0].discard.includes(card));
|
||||
});
|
||||
|
||||
test('views hide the opponent hand, both decks, face-down Avatars 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');
|
||||
const v = viewFor(t.s, 0);
|
||||
assert.deepEqual(v.players[1].hand, [-1]);
|
||||
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.rng.s, 0);
|
||||
assert.notEqual(t.s.rng.s, 0);
|
||||
});
|
||||
|
||||
test('the same seed replays the same game', () => {
|
||||
const rng = makeRng(9);
|
||||
const decks = [randomDeck(pool, rng, DEFAULT_RULES), randomDeck(pool, rng, DEFAULT_RULES)] as const;
|
||||
const a = createGame({ pool, decks: [decks[0], decks[1]], seed: 42 });
|
||||
const b = createGame({ pool, decks: [decks[0], decks[1]], seed: 42 });
|
||||
assert.deepEqual(a, b);
|
||||
});
|
||||
|
||||
test('an opponent with a response gets a window after a declaration; without one it passes itself', () => {
|
||||
const t = new Table({ north: { main: ['Execute: Ping Sweep'] } });
|
||||
t.own(0, 'A2');
|
||||
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');
|
||||
t.hand(1, 'Execute: Ping Sweep');
|
||||
t.ram(1, 4);
|
||||
t.act({ type: 'advance', slot: 2, to: 'A3' });
|
||||
assert.equal(t.decider, 1, 'North may respond');
|
||||
t.act({ type: 'pass' });
|
||||
assert.equal(t.decider, 0);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue