updates
This commit is contained in:
parent
5368464042
commit
937f44defe
100 changed files with 10185 additions and 2042 deletions
|
|
@ -1,16 +1,16 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { avatarCores, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, openWindow } from '../src/engine.ts';
|
||||
import { hasRoom } from '../src/query.ts';
|
||||
import { withRule } from '../src/rules.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. */
|
||||
/** South's Anomaly 1 (`south`) on B1 attacks North's Anomaly 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) } });
|
||||
const t = new Table({ south: { ...o.south, anomalies: four(south) }, north: { ...o.north, anomalies: four(north) } });
|
||||
t.own(0, 'B1');
|
||||
t.own(1, 'C1');
|
||||
t.place(0, 1, 'B1');
|
||||
|
|
@ -22,30 +22,30 @@ 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;
|
||||
const anomalyCard = (t: Table, p: 0 | 1, slot: number) => t.anomaly(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, 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");
|
||||
t.bandwidth(0, 6).use(anomalyCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.anomaly(0, 5).at, 'A2', 'the copy is in play');
|
||||
assert.equal(anomalyCores(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.s.players[0].anomalies[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);
|
||||
assert.equal(t.anomaly(0, 5).at, null);
|
||||
assert.equal(t.anomaly(0, 1).hardware.length, 1);
|
||||
});
|
||||
|
||||
test('copy rule variants: a new copy defends but only advances or attacks from its next turn', () => {
|
||||
const t = scene('Carbon NanoBots', 'Broken Bits');
|
||||
t.s.rules = withRule(t.s.rules, 'copies.waitATurn=true');
|
||||
t.own(0, 'A2');
|
||||
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');
|
||||
t.bandwidth(0, 6).use(anomalyCard(t, 0, 1), { to: 'A2' }).settle();
|
||||
assert.equal(t.anomaly(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(), []);
|
||||
assert.ok(t.legal().some((a) => a.type === 'advance' && a.slot === 1), 'the original still can');
|
||||
|
|
@ -55,15 +55,15 @@ test('copy rule variants: a new copy defends but only advances or attacks from i
|
|||
assert.ok(acts().length > 0, 'next turn it can advance');
|
||||
});
|
||||
|
||||
test('copy rule variants: copies can need Avatar 2 unlocked, or be off', () => {
|
||||
test('copy rule variants: copies can need Anomaly 2 unlocked, or be off', () => {
|
||||
const t = scene('Carbon NanoBots', 'Broken Bits');
|
||||
t.own(0, 'A2');
|
||||
t.ram(0, 6);
|
||||
t.bandwidth(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');
|
||||
assert.ok(!replicate(), 'Avatar 2 is still face down');
|
||||
t.avatar(0, 2).faceUp = true;
|
||||
t.s.rules = withRule(t.s.rules, 'copies.needAnomaly2=true');
|
||||
assert.ok(!replicate(), 'Anomaly 2 is still face down');
|
||||
t.anomaly(0, 2).faceUp = true;
|
||||
assert.ok(replicate());
|
||||
t.s.rules = withRule(t.s.rules, 'copies.allowed=false');
|
||||
assert.ok(!replicate());
|
||||
|
|
@ -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, 6);
|
||||
t.bandwidth(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'));
|
||||
|
|
@ -82,21 +82,21 @@ test('no copy can enter a location while a combat is going on there', () => {
|
|||
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);
|
||||
t.bandwidth(0, 4);
|
||||
fight(t);
|
||||
t.rig(1, 1, 1, 6, 6, 6, 6);
|
||||
t.use(avatarCard(t, 0, 1), { card: hw }).settle();
|
||||
t.use(anomalyCard(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);
|
||||
t.bandwidth(1, 3);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.rig(6, 6, 6, 1, 1, 1);
|
||||
t.use(avatarCard(t, 1, 1)).settle();
|
||||
t.use(anomalyCard(t, 1, 1)).settle();
|
||||
assert.equal(dice(t, 'atk'), 3, 'the attacker has -1 Core');
|
||||
});
|
||||
|
||||
|
|
@ -105,23 +105,23 @@ card('Beta Version 1.0', () => {
|
|||
t.hardware(0, 1, 'Overclocked CPU');
|
||||
t.hardware(0, 1, 'Packet Accelerator');
|
||||
const [ac] = t.hand(0, 'Additional Core');
|
||||
t.ram(0, 4 + 5);
|
||||
t.bandwidth(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.use(anomalyCard(t, 0, 1), { card: ac }).settle();
|
||||
assert.equal(dice(t, 'atk'), 4 + 2 + 1 + 1, 'a third Hardware on a 2-slot Anomaly');
|
||||
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.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.rig(6, 6, 6, 1, 1, 1);
|
||||
t.use(avatarCard(t, 1, 1)).settle();
|
||||
assert.equal(t.avatar(0, 1).infection >= 1 || t.avatar(0, 1).at === null, true);
|
||||
t.use(anomalyCard(t, 1, 1)).settle();
|
||||
assert.equal(t.anomaly(0, 1).infection >= 1 || t.anomaly(0, 1).at === null, true);
|
||||
assert.equal(dice(t, 'atk'), 3, '1 Infection counter: -1 Core while Code Zero is in play');
|
||||
assert.equal(dice(t, 'def'), 3, 'Code Zero has 3 Cores');
|
||||
});
|
||||
|
|
@ -130,16 +130,16 @@ 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);
|
||||
t.bandwidth(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));
|
||||
t.use(anomalyCard(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[1].bandwidth, 0, 'no Bandwidth for the discard');
|
||||
assert.equal(t.s.players[0].hand.length, 1, 'it breached this turn, so it draws');
|
||||
});
|
||||
|
||||
|
|
@ -147,21 +147,21 @@ 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 });
|
||||
t.bandwidth(0, 5 + 3).use(anomalyCard(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');
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [ac]);
|
||||
assert.equal(t.s.players[0].bandwidth, 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.bandwidth(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();
|
||||
t.use(anomalyCard(t, 0, 1), { k: 2 }).settle();
|
||||
assert.match(t.logText(), /Bit Flip rerolls 4 dice/);
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
});
|
||||
103
sim/test/app.test.ts
Normal file
103
sim/test/app.test.ts
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/** What the app needs from the sim: action labels, private log lines, Cores breakdowns. */
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import type { Bot } from '../src/bots/bot.ts';
|
||||
import { greedyBot } from '../src/bots/greedy.ts';
|
||||
import { randomBot } from '../src/bots/random.ts';
|
||||
import { randomDeck } from '../src/deck.ts';
|
||||
import { describeAction } from '../src/describe.ts';
|
||||
import { actionKey, applyAction, createGame, decider, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { coresOf, fighterOf, type CorePart } from '../src/query.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES, withRule, type RulesConfig } from '../src/rules.ts';
|
||||
import { fightersOf, logFor, nameOf, programLocation, wearerOf } from '../src/state.ts';
|
||||
import type { Action, GameState } from '../src/types.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
||||
/** Plays a game, calling `each` at every decision with the legal actions. */
|
||||
function play(seed: number, bots: [Bot, Bot], each: (s: GameState, legal: Action[]) => void, rules: RulesConfig = DEFAULT_RULES): GameState {
|
||||
const rng = makeRng(seed ^ 0x9e3779b9);
|
||||
const s = createGame({ pool, decks: [randomDeck(pool, rng, rules), randomDeck(pool, rng, rules)], seed, rules, log: true });
|
||||
for (let n = 0; !s.over && n < 50_000; n++) {
|
||||
const p = decider(s)!;
|
||||
const legal = legalActions(s);
|
||||
each(s, legal);
|
||||
applyAction(s, bots[p].choose(viewFor(s, p), legal, p), legal);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two actions are the same move when they differ only in which of two same-named cards in the same
|
||||
* place they use: salvaging either copy in hand, swapping out either of two identical Hardware.
|
||||
*/
|
||||
function sameMove(s: GameState, a: Action, b: Action): boolean {
|
||||
const where = (id: number) => {
|
||||
const wearer = wearerOf(s, id);
|
||||
return `${nameOf(s, id)}@${programLocation(s, id) ?? (wearer ? `${wearer.player}:${wearer.slot}` : zoneOf(s, id))}`;
|
||||
};
|
||||
const canon = (x: Action) =>
|
||||
JSON.stringify(x, (k, v) => (['card', 'cards'].includes(k) ? (Array.isArray(v) ? v.map(where) : typeof v === 'number' ? where(v) : v) : v));
|
||||
return canon(a) === canon(b);
|
||||
}
|
||||
|
||||
const zoneOf = (s: GameState, id: number): string => {
|
||||
const pl = s.players[s.cards[id].owner];
|
||||
return pl.hand.includes(id) ? 'hand' : pl.discard.includes(id) ? 'discard' : 'elsewhere';
|
||||
};
|
||||
|
||||
function checkLabels(s: GameState, legal: Action[]): void {
|
||||
const seen = new Map<string, Action>();
|
||||
for (const a of legal) {
|
||||
const label = describeAction(s, a);
|
||||
assert.ok(label.length > 0, `empty label for ${actionKey(a)}`);
|
||||
assert.ok(!label.includes('undefined') && !label.includes('NaN'), `bad label "${label}" for ${actionKey(a)}`);
|
||||
const prev = seen.get(label);
|
||||
if (prev && !sameMove(s, prev, a)) assert.fail(`"${label}" labels both ${actionKey(prev)} and ${actionKey(a)} (turn ${s.turn})`);
|
||||
seen.set(label, a);
|
||||
}
|
||||
}
|
||||
|
||||
test('every legal action gets a label, and no two moves in a decision share one', () => {
|
||||
for (let seed = 1; seed <= 60; seed++) play(seed, [randomBot(seed * 2), randomBot(seed * 2 + 1)], checkLabels);
|
||||
for (let seed = 1; seed <= 30; seed++) play(seed, [greedyBot(), greedyBot()], checkLabels);
|
||||
for (const spec of ['recruit.on=true', 'buyAnomalies.on=true', 'commands.on=false']) {
|
||||
const rules = withRule(DEFAULT_RULES, spec);
|
||||
for (let seed = 1; seed <= 10; seed++) play(seed, [randomBot(seed * 2), randomBot(seed * 2 + 1)], checkLabels, rules);
|
||||
}
|
||||
});
|
||||
|
||||
test("a player's log never names the other player's secret choices", () => {
|
||||
let secrets = 0;
|
||||
for (let seed = 1; seed <= 80; seed++) {
|
||||
const s = play(seed, [greedyBot(), greedyBot()], () => {});
|
||||
for (const l of s.log!) if (l.to !== undefined) secrets++;
|
||||
for (const p of [0, 1] as const) {
|
||||
const mine = logFor(s, p);
|
||||
s.log!.forEach((l, i) => {
|
||||
if (l.to === undefined) assert.equal(mine[i], l.text);
|
||||
else assert.equal(mine[i], l.to === p ? l.text : l.public);
|
||||
});
|
||||
}
|
||||
}
|
||||
assert.ok(secrets > 0, 'no secret lines came up; the check tested nothing');
|
||||
});
|
||||
|
||||
test('a Cores breakdown adds up to the total', () => {
|
||||
let combats = 0;
|
||||
for (let seed = 1; seed <= 20; seed++) {
|
||||
play(seed, [greedyBot(), greedyBot()], (s) => {
|
||||
if (!s.combat || s.combat.ended) return;
|
||||
combats++;
|
||||
for (const r of fightersOf(s.combat)) {
|
||||
const parts: CorePart[] = [];
|
||||
const total = coresOf(s, fighterOf(s, r), undefined, parts);
|
||||
assert.equal(parts[0].kind, 'anomaly');
|
||||
assert.equal(Math.max(1, parts.reduce((t, x) => t + x.cores, 0)), total);
|
||||
}
|
||||
});
|
||||
}
|
||||
assert.ok(combats > 50);
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { randomDeck, validateDeck } from '../src/deck.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES } from '../src/rules.ts';
|
||||
|
|
@ -11,14 +11,14 @@ const pool = loadCards();
|
|||
|
||||
test('cards.csv loads every playable card', () => {
|
||||
const count = (kind: string) => pool.all.filter((c) => c.kind === kind).length;
|
||||
assert.equal(count('avatar'), 8);
|
||||
assert.equal(count('anomaly'), 8);
|
||||
assert.equal(count('server'), 13);
|
||||
assert.equal(count('program'), 28);
|
||||
assert.equal(count('hardware'), 16);
|
||||
assert.equal(count('execution'), 18);
|
||||
assert.equal(pool.byName.get('Broken Bits')?.cores, 4);
|
||||
assert.equal(pool.byName.get('Carbon NanoBots')?.slots, 4);
|
||||
assert.equal(pool.byName.get('Quantum Coprocessor')?.ram, 9);
|
||||
assert.equal(pool.byName.get('Quantum Coprocessor')?.bandwidth, 9);
|
||||
});
|
||||
|
||||
test('every card has a script written for its current text', () => {
|
||||
|
|
@ -37,7 +37,7 @@ test('every card has its own test', () => {
|
|||
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('anomaly'), 12);
|
||||
assert.equal(count('server'), 7);
|
||||
assert.equal(count('program'), 17);
|
||||
assert.equal(count('hardware'), 8);
|
||||
|
|
@ -46,16 +46,16 @@ test('set 2 loads on request, is well formed, and is unscripted', () => {
|
|||
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') {
|
||||
if (c.kind === 'anomaly') {
|
||||
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`);
|
||||
assert.ok(c.type && c.ability && c.ability.cost >= 3 && c.ability.cost <= 5, `${c.name}: typed, Ability 3-5 Gb`);
|
||||
} else if (c.kind === 'program') {
|
||||
assert.ok(c.type && c.ram >= 4 && c.ram <= 6, `${c.name}: typed, 4-6 RAM`);
|
||||
assert.ok(c.type && c.bandwidth >= 4 && c.bandwidth <= 6, `${c.name}: typed, 4-6 Gb`);
|
||||
} else if (c.kind === 'execution') {
|
||||
assert.ok(c.ram >= 3 && c.ram <= 5, `${c.name}: 3-5 RAM`);
|
||||
assert.ok(c.bandwidth >= 3 && c.bandwidth <= 5, `${c.name}: 3-5 Gb`);
|
||||
} else if (c.kind === 'hardware') {
|
||||
assert.ok(c.ram >= 4 && c.ram <= 7, `${c.name}: 4-7 RAM`);
|
||||
assert.ok(c.bandwidth >= 4 && c.bandwidth <= 7, `${c.name}: 4-7 Gb`);
|
||||
}
|
||||
}
|
||||
const all = loadCards(undefined, 'all');
|
||||
|
|
@ -76,7 +76,7 @@ test('deck validation catches size, kind and copy problems', () => {
|
|||
const deck = randomDeck(pool, makeRng(1), DEFAULT_RULES);
|
||||
deck.main[0] = deck.main[1] = deck.main[2] = 'Execute: Fork';
|
||||
deck.servers.pop();
|
||||
deck.avatars[0] = 'Cloud Compute';
|
||||
deck.anomalies[0] = 'Cloud Compute';
|
||||
const errors = validateDeck(pool, deck, DEFAULT_RULES).join('\n');
|
||||
assert.match(errors, /Servers: 19 cards/);
|
||||
assert.match(errors, /"Cloud Compute" is a server/);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { randomDeck } from '../src/deck.ts';
|
||||
import { advanceTargets, avatarCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { advanceTargets, anomalyCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES, withRule, type RulesConfig } from '../src/rules.ts';
|
||||
|
|
@ -19,9 +19,9 @@ test('setup follows rules.md', () => {
|
|||
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.ok(pl.bandwidth >= 4);
|
||||
assert.deepEqual(pl.anomalies.slice(0, 4).map((a) => a.faceUp), [true, false, false, false]);
|
||||
assert.ok(pl.anomalies.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);
|
||||
|
|
@ -62,53 +62,53 @@ test('rule variants: more cards per draw step', () => {
|
|||
assert.equal(t.s.players[1].hand.length, 2);
|
||||
});
|
||||
|
||||
test('advancing captures an unowned location in step 5 and pays 4 RAM; Lv 1 unlocks nothing', () => {
|
||||
test('advancing captures an unowned location in step 5 and pays 4 Gb; Lv 1 unlocks nothing', () => {
|
||||
const t = new Table();
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(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 the capture');
|
||||
assert.equal(t.avatar(0, 2).faceUp, false, 'A2 is Lv 1 for South');
|
||||
assert.equal(t.anomaly(0, 1).at, 'A2');
|
||||
assert.equal(t.s.players[0].bandwidth, 8, '4 Gb + 4 for the capture');
|
||||
assert.equal(t.anomaly(0, 2).faceUp, false, 'A2 is Lv 1 for South');
|
||||
assert.equal(t.s.step, 'playAgain');
|
||||
});
|
||||
|
||||
test('the second row (Lv 2) unlocks Avatar 2; the middle row (Lv 3) unlocks Avatars 2 and 3', () => {
|
||||
test('the second row (Lv 2) unlocks Anomaly 2; the middle row (Lv 3) unlocks Anomalies 2 and 3', () => {
|
||||
for (const [from, to, unlocked] of [['A2', 'B1', [true, false]], ['B1', 'C2', [true, true]]] as const) {
|
||||
const t = new Table();
|
||||
t.own(0, from);
|
||||
t.place(0, 1, from);
|
||||
t.go({ type: 'advance', slot: 1, to }).to('attack').end();
|
||||
assert.equal(t.s.locations[to].owner, 0);
|
||||
assert.deepEqual([t.avatar(0, 2).faceUp, t.avatar(0, 3).faceUp], unlocked, to);
|
||||
assert.deepEqual([t.anomaly(0, 2).faceUp, t.anomaly(0, 3).faceUp], unlocked, to);
|
||||
}
|
||||
});
|
||||
|
||||
test('rule variants: a turn-1 capture can pay no RAM and unlock nothing', () => {
|
||||
test('rule variants: a turn-1 capture can pay no Bandwidth and unlock nothing', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'firstTurn.captureRam=false'), 'firstTurn.unlock=false');
|
||||
t.ram(0, 4).own(0, 'A2');
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'firstTurn.captureBandwidth=false'), 'firstTurn.unlock=false');
|
||||
t.bandwidth(0, 4).own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
t.go({ type: 'advance', slot: 1, to: 'B1' }).to('attack').end();
|
||||
assert.equal(t.s.locations.B1.owner, 0);
|
||||
assert.equal(t.s.players[0].ram, 4);
|
||||
assert.equal(t.avatar(0, 2).faceUp, false);
|
||||
assert.equal(t.s.players[0].bandwidth, 4);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, false);
|
||||
});
|
||||
|
||||
test('rule variants: the first player can be barred from playing cards on turn 1', () => {
|
||||
const t = new Table({ south: { main: ['Additional Core'] }, north: { main: ['Additional Core'] } });
|
||||
t.s.rules = withRule(t.s.rules, 'firstTurn.cards=false');
|
||||
t.hand(0, 'Additional Core');
|
||||
t.ram(0, 9).place(0, 1, 'S1');
|
||||
t.bandwidth(0, 9).place(0, 1, 'S1');
|
||||
t.to('playAgain');
|
||||
assert.ok(!t.legal().some((a) => a.type === 'installHardware'));
|
||||
t.end();
|
||||
t.hand(1, 'Additional Core');
|
||||
t.ram(1, 9).place(1, 1, 'S2');
|
||||
t.bandwidth(1, 9).place(1, 1, 'S2');
|
||||
t.to('playAgain');
|
||||
assert.ok(t.legal().some((a) => a.type === 'installHardware'), 'the second player can on turn 2');
|
||||
});
|
||||
|
|
@ -136,21 +136,21 @@ 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' });
|
||||
t.bandwidth(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.equal(t.s.players[0].bandwidth, 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');
|
||||
t.bandwidth(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.players[0].bandwidth, 20 - 2 - 4);
|
||||
assert.equal(t.s.firewalls['A1-A2'], 2);
|
||||
});
|
||||
|
||||
|
|
@ -163,21 +163,21 @@ test('combat: the loser goes back to its slot and loses its Hardware; the winner
|
|||
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');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 4);
|
||||
assert.equal(anomalyCores(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.equal(t.anomaly(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(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.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, [hw]);
|
||||
}
|
||||
assert.equal(t.s.stats.attacks[0], 1);
|
||||
}
|
||||
|
|
@ -222,15 +222,15 @@ test('reaching the location target wins immediately', () => {
|
|||
assert.deepEqual(legalActions(t.s), []);
|
||||
});
|
||||
|
||||
test('Salvage pays full printed RAM, from hand only', () => {
|
||||
test('Salvage pays full printed Bandwidth, 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.equal(t.s.players[0].bandwidth, 6);
|
||||
assert.ok(t.s.players[0].discard.includes(card));
|
||||
});
|
||||
|
||||
test('views hide the opponent hand, both decks, face-down Avatars and the RNG', () => {
|
||||
test('views hide the opponent hand, both decks, face-down Anomalies 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');
|
||||
|
|
@ -239,8 +239,8 @@ test('views hide the opponent hand, both decks, face-down Avatars and the RNG',
|
|||
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.players[0].anomalies[1].card, -1);
|
||||
assert.equal(v.players[1].anomalies[1].card, -1);
|
||||
assert.equal(v.rng.s, 0);
|
||||
assert.notEqual(t.s.rng.s, 0);
|
||||
});
|
||||
|
|
@ -259,9 +259,9 @@ test('an opponent with a response gets a window after a declaration; without one
|
|||
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');
|
||||
assert.equal(t.decider, 0, 'North has no Bandwidth, so no window');
|
||||
t.hand(1, 'Execute: Ping Sweep');
|
||||
t.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
t.act({ type: 'advance', slot: 2, to: 'A3' });
|
||||
assert.equal(t.decider, 1, 'North may respond');
|
||||
t.act({ type: 'pass' });
|
||||
|
|
@ -269,17 +269,17 @@ test('an opponent with a response gets a window after a declaration; without one
|
|||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Recruit rule (prototype): Avatars in the deck, bought with RAM
|
||||
// Recruit rule (prototype): Anomalies in the deck, bought with Bandwidth
|
||||
|
||||
/** A table under the recruit rule: Avatar 1 stays, Avatars 2–4 move to their owner's hand, priced at 6 RAM. */
|
||||
/** A table under the recruit rule: Anomaly 1 stays, Anomalies 2–4 move to their owner's hand, priced at 6 Gb. */
|
||||
function recruitTable(o: ConstructorParameters<typeof Table>[0] = {}): Table {
|
||||
const t = new Table(o);
|
||||
t.s.rules = withRule(t.s.rules, 'recruit.on=true');
|
||||
for (const p of [0, 1] as const) {
|
||||
const avs = t.s.players[p].avatars;
|
||||
const avs = t.s.players[p].anomalies;
|
||||
for (let i = 1; i < 4; i++) {
|
||||
const name = t.s.cards[avs[i].card].name;
|
||||
t.s.defs[name] = { ...t.s.defs[name], ram: 6 };
|
||||
t.s.defs[name] = { ...t.s.defs[name], bandwidth: 6 };
|
||||
t.s.players[p].hand.push(avs[i].card);
|
||||
avs[i].card = avs[i + 4].card = -1;
|
||||
avs[i].faceUp = false;
|
||||
|
|
@ -290,101 +290,101 @@ function recruitTable(o: ConstructorParameters<typeof Table>[0] = {}): Table {
|
|||
|
||||
const recruits = (t: Table) => t.legal().filter((a) => a.type === 'recruit');
|
||||
|
||||
test('recruit rule: buy an Avatar from hand into an empty slot; it enters play on a later turn', () => {
|
||||
test('recruit rule: buy an Anomaly from hand into an empty slot; it enters play on a later turn', () => {
|
||||
const t = recruitTable();
|
||||
const card = t.s.players[0].hand[0];
|
||||
t.ram(0, 5).to('play');
|
||||
assert.equal(recruits(t).length, 0, "can't afford 6 RAM");
|
||||
t.ram(0, 6);
|
||||
assert.deepEqual(recruits(t).map((a) => a.type === 'recruit' && a.slot), [2, 1, 2, 1, 2, 1], 'first empty slot, or over Avatar 1');
|
||||
t.bandwidth(0, 5).to('play');
|
||||
assert.equal(recruits(t).length, 0, "can't afford 6 Gb");
|
||||
t.bandwidth(0, 6);
|
||||
assert.deepEqual(recruits(t).map((a) => a.type === 'recruit' && a.slot), [2, 1, 2, 1, 2, 1], 'first empty slot, or over Anomaly 1');
|
||||
t.go({ type: 'recruit', card, slot: 2 });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
assert.equal(t.avatar(0, 2).card, card);
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
assert.equal(t.anomaly(0, 2).card, card);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
assert.ok(!t.s.players[0].hand.includes(card));
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.ok(t.can({ type: 'place', slot: 2, to: 'S1' }));
|
||||
});
|
||||
|
||||
test('recruit rule: captures unlock nothing, and a salvaged Avatar pays its price', () => {
|
||||
test('recruit rule: captures unlock nothing, and a salvaged Anomaly pays its price', () => {
|
||||
const t = recruitTable();
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, 0);
|
||||
assert.equal(t.avatar(0, 2).card, -1);
|
||||
const ram = t.s.players[0].ram;
|
||||
assert.equal(t.anomaly(0, 2).card, -1);
|
||||
const bandwidth = t.s.players[0].bandwidth;
|
||||
t.go({ type: 'salvage', card: t.s.players[0].hand[0] });
|
||||
assert.equal(t.s.players[0].ram, ram + 6);
|
||||
assert.equal(t.s.players[0].bandwidth, bandwidth + 6);
|
||||
});
|
||||
|
||||
test('recruit rule: copies count toward the 4 Avatars', () => {
|
||||
const t = recruitTable({ south: { avatars: ['Carbon NanoBots', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
test('recruit rule: copies count toward the 4 Anomalies', () => {
|
||||
const t = recruitTable({ south: { anomalies: ['Carbon NanoBots', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
t.own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
const [a, b] = t.s.players[0].hand;
|
||||
t.ram(0, 30).to('play');
|
||||
t.bandwidth(0, 30).to('play');
|
||||
t.go({ type: 'recruit', card: a, slot: 2 }).go({ type: 'recruit', card: b, slot: 3 });
|
||||
const replicate = t.legal().find((x) => x.type === 'activate' && x.name === 'Carbon NanoBots' && x.args.to === 'S1');
|
||||
assert.ok(replicate, '3 Avatars, so a copy fits');
|
||||
assert.ok(replicate, '3 Anomalies, so a copy fits');
|
||||
t.go(replicate).settle();
|
||||
assert.equal(t.avatar(0, 5).at, 'S1');
|
||||
assert.equal(t.anomaly(0, 5).at, 'S1');
|
||||
assert.ok(!recruits(t).some((r) => r.type === 'recruit' && r.slot === 4), 'no room for a fourth with the copy out');
|
||||
});
|
||||
|
||||
test('recruit rule: recruiting over an Avatar retires it and its Hardware', () => {
|
||||
test('recruit rule: recruiting over an Anomaly retires it and its Hardware', () => {
|
||||
const t = recruitTable({ south: { main: ['Additional Core'] } });
|
||||
t.own(0, 'A2');
|
||||
const ref = t.place(0, 1, 'A2');
|
||||
const old = t.avatar(0, 1).card;
|
||||
const old = t.anomaly(0, 1).card;
|
||||
const hw = t.hardware(ref.player, ref.slot, 'Additional Core');
|
||||
const card = t.s.players[0].hand.find((id) => t.s.defs[t.s.cards[id].name].kind === 'avatar')!;
|
||||
t.ram(0, 6).to('play').go({ type: 'recruit', card, slot: 1 });
|
||||
assert.equal(t.avatar(0, 1).card, card);
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, []);
|
||||
const card = t.s.players[0].hand.find((id) => t.s.defs[t.s.cards[id].name].kind === 'anomaly')!;
|
||||
t.bandwidth(0, 6).to('play').go({ type: 'recruit', card, slot: 1 });
|
||||
assert.equal(t.anomaly(0, 1).card, card);
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, []);
|
||||
assert.ok(t.s.players[0].discard.includes(old) && t.s.players[0].discard.includes(hw));
|
||||
assert.equal(t.s.locations.A2.owner, 0, 'the location stays yours');
|
||||
});
|
||||
|
||||
test('recruit rule: decks keep one Avatar outside and shuffle the rest into the main deck', () => {
|
||||
test('recruit rule: decks keep one Anomaly outside and shuffle the rest into the main deck', () => {
|
||||
const pool = loadCards();
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), 'recruit.avatarsInDeck=5');
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), 'recruit.anomaliesInDeck=5');
|
||||
const deck = randomDeck(pool, makeRng(3), rules);
|
||||
assert.equal(deck.avatars.length, 1);
|
||||
assert.equal(deck.anomalies.length, 1);
|
||||
assert.equal(deck.main.length, 45);
|
||||
assert.equal(deck.main.filter((n) => pool.byName.get(n)!.kind === 'avatar').length, 5);
|
||||
assert.equal(deck.main.filter((n) => pool.byName.get(n)!.kind === 'anomaly').length, 5);
|
||||
const s = createGame({ pool, decks: [deck, randomDeck(pool, makeRng(4), rules)], seed: 1, rules });
|
||||
assert.deepEqual(s.players[0].avatars.slice(0, 4).map((a) => a.card >= 0), [true, false, false, false]);
|
||||
assert.deepEqual(s.players[0].anomalies.slice(0, 4).map((a) => a.card >= 0), [true, false, false, false]);
|
||||
assert.equal(checkInvariants(s).length, 0);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Buy-Avatars rule (prototype): pay RAM to flip the next Avatar instead of unlocking by level
|
||||
// Buy-Anomalies rule (prototype): pay Bandwidth to flip the next Anomaly instead of unlocking by level
|
||||
|
||||
test('buy rule: pay to flip the next face-down Avatar; it enters play on a later turn', () => {
|
||||
test('buy rule: pay to flip the next face-down Anomaly; it enters play on a later turn', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'buyAvatars.on=true'), 'buyAvatars.prices=8,12,16');
|
||||
t.ram(0, 7).to('play');
|
||||
assert.ok(!t.can({ type: 'buyAvatar', slot: 2 }), "can't afford 8 RAM");
|
||||
t.ram(0, 20).go({ type: 'buyAvatar', slot: 2 });
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].ram, 12);
|
||||
assert.ok(t.can({ type: 'buyAvatar', slot: 3 }), 'Avatar 3 is next, at 12');
|
||||
t.go({ type: 'buyAvatar', slot: 3 });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
t.s.rules = withRule(withRule(t.s.rules, 'buyAnomalies.on=true'), 'buyAnomalies.prices=8,12,16');
|
||||
t.bandwidth(0, 7).to('play');
|
||||
assert.ok(!t.can({ type: 'buyAnomaly', slot: 2 }), "can't afford 8 Gb");
|
||||
t.bandwidth(0, 20).go({ type: 'buyAnomaly', slot: 2 });
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
assert.equal(t.s.players[0].bandwidth, 12);
|
||||
assert.ok(t.can({ type: 'buyAnomaly', slot: 3 }), 'Anomaly 3 is next, at 12');
|
||||
t.go({ type: 'buyAnomaly', slot: 3 });
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.ok(t.can({ type: 'place', slot: 2, to: 'S1' }));
|
||||
});
|
||||
|
||||
test('buy rule: captures unlock nothing', () => {
|
||||
const t = new Table();
|
||||
t.s.rules = withRule(t.s.rules, 'buyAvatars.on=true');
|
||||
t.s.rules = withRule(t.s.rules, 'buyAnomalies.on=true');
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.go({ type: 'advance', slot: 1, to: 'C2' }).to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, 0);
|
||||
assert.deepEqual([t.avatar(0, 2).faceUp, t.avatar(0, 3).faceUp], [false, false]);
|
||||
assert.deepEqual([t.anomaly(0, 2).faceUp, t.anomaly(0, 3).faceUp], [false, false]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
|
@ -423,7 +423,7 @@ test('command rule: the order of commands can follow a pattern of round leads, o
|
|||
assert.deepEqual(DEFAULT_RULES.commands, { on: true, perPlayer: 2, leads: 'F', snake: true }, 'the default since v0.9: the first player leads every round, snake order');
|
||||
});
|
||||
|
||||
test('command rule: one advance or attack per command, each Avatar once a round', () => {
|
||||
test('command rule: one advance or attack per command, each Anomaly once a round', () => {
|
||||
const t = commandTable();
|
||||
t.own(0, 'A2');
|
||||
t.own(0, 'A1');
|
||||
|
|
@ -436,15 +436,15 @@ test('command rule: one advance or attack per command, each Avatar once a round'
|
|||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.equal(t.s.turn, 3);
|
||||
const movers = new Set(t.legal().filter((a) => a.type === 'advance').map((a) => a.type === 'advance' && a.slot));
|
||||
assert.deepEqual([...movers], [2], 'Avatar 1 already acted this round');
|
||||
assert.deepEqual([...movers], [2], 'Anomaly 1 already acted this round');
|
||||
});
|
||||
|
||||
test('command rule: an Avatar unlocked this round enters play next round', () => {
|
||||
test('command rule: an Anomaly unlocked this round enters play next round', () => {
|
||||
const t = commandTable();
|
||||
t.own(0, 'A2');
|
||||
t.place(0, 1, 'A2');
|
||||
t.go({ type: 'advance', slot: 1, to: 'B1' }).to('attack').end();
|
||||
assert.equal(t.avatar(0, 2).faceUp, true);
|
||||
assert.equal(t.anomaly(0, 2).faceUp, true);
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
assert.equal(t.s.turn, 3);
|
||||
assert.ok(!t.legal().some((a) => a.type === 'place' && a.slot === 2));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores, execBlocked, executionActions, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, execBlocked, executionActions, openWindow } from '../src/engine.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
|
|
@ -22,12 +22,12 @@ card('Execute: Disconnect', () => {
|
|||
t.own(1, 'D1');
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.hand(1, 'Execute: Disconnect');
|
||||
t.ram(1, 4);
|
||||
t.bandwidth(1, 4);
|
||||
fight(t);
|
||||
assert.equal(t.decider, 1);
|
||||
t.play(1, 'Execute: Disconnect', 'C1', { ref: { player: 1, slot: 1 }, to: 'D1' }).settle();
|
||||
assert.equal(t.avatar(1, 1).at, 'D1');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, [hw]);
|
||||
assert.equal(t.anomaly(1, 1).at, 'D1');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, [hw]);
|
||||
assert.equal(t.s.locations.C1.owner, 0, 'the attacker takes the empty location');
|
||||
});
|
||||
|
||||
|
|
@ -35,14 +35,14 @@ card('Execute: Disconnect', () => {
|
|||
// An attacker retreats after a bad roll and isn't defeated.
|
||||
const t = scene({ south: { main: ['Execute: Disconnect'] } });
|
||||
t.hand(0, 'Execute: Disconnect');
|
||||
t.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6);
|
||||
fight(t);
|
||||
assert.equal(openWindow(t.s)?.kind, 'preRoll');
|
||||
t.act({ type: 'pass' });
|
||||
assert.equal(openWindow(t.s)?.kind, 'postRoll');
|
||||
t.play(0, 'Execute: Disconnect', 'C1', { ref: { player: 0, slot: 1 }, to: 'B1' }).settle();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.s.locations.C1.owner, 1);
|
||||
assert.match(t.logText(), /combat at C1 ends/);
|
||||
});
|
||||
|
|
@ -51,7 +51,7 @@ card('Execute: Sabotage', () => {
|
|||
const t = scene({ south: { main: ['Execute: Sabotage'] }, north: { main: ['Additional Core'] } });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.hand(0, 'Execute: Sabotage');
|
||||
t.ram(0, 7);
|
||||
t.bandwidth(0, 7);
|
||||
fight(t);
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.play(0, 'Execute: Sabotage', 'C1', { card: hw, mode: 'destroy' }).settle();
|
||||
|
|
@ -62,27 +62,27 @@ card('Execute: Sabotage', () => {
|
|||
card('Execute: Kill Process', () => {
|
||||
const t = scene({ south: { main: ['Execute: Kill Process'] }, north: { main: ['Stack Overflow'] } });
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5);
|
||||
t.hand(0, 'Execute: Kill Process');
|
||||
t.ram(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, "back on at its controller's next turn");
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, "back on at its controller's next turn");
|
||||
});
|
||||
|
||||
card('Execute: Force Reboot', () => {
|
||||
const t = scene({ south: { main: ['Execute: Force Reboot', 'Additional Core', 'Dedicated GPU', 'Execute: Ping Sweep'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
const t = scene({ south: { main: ['Execute: Force Reboot', 'Additional Core', 'Dedicated GPU', 'Execute: Ping Sweep'] }, north: { main: ['Bloatware'] } });
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hardware(0, 1, 'Dedicated GPU');
|
||||
t.hand(0, 'Execute: Force Reboot', 'Execute: Ping Sweep');
|
||||
const fromB1 = () => executionActions(t.s, 0, 'any').some((a) => a.type === 'play' && a.from === 'B1');
|
||||
assert.ok(fromB1(), 'B1 can perform Executions');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
fight(t);
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.play(0, 'Execute: Force Reboot', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
assert.equal(attackerDice(t), 5, "Memory Leak's penalty is gone");
|
||||
assert.equal(attackerDice(t), 5, "Bloatware's penalty is gone");
|
||||
assert.ok(execBlocked(t.s, 'B1'), 'the Server it stands on is blocked for the turn');
|
||||
assert.ok(!fromB1());
|
||||
});
|
||||
|
|
@ -91,16 +91,16 @@ card('Execute: Fork', () => {
|
|||
const t = scene({ south: { main: ['Execute: Fork', 'Stack Overflow'] } });
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Fork');
|
||||
t.ram(0, 7).play(0, 'Execute: Fork', 'B1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 6, 'two Stack Overflow effects, +1 each');
|
||||
t.bandwidth(0, 7).play(0, 'Execute: Fork', 'B1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 6, 'two Stack Overflow effects, +1 each');
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5, 'until end of turn');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5, 'until end of turn');
|
||||
});
|
||||
|
||||
card('Execute: Ping Sweep', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Ping Sweep'] } });
|
||||
t.hand(0, 'Execute: Ping Sweep');
|
||||
t.ram(0, 4).play(0, 'Execute: Ping Sweep', null).settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Ping Sweep', null).settle();
|
||||
assert.equal(t.s.players[0].hand.length, 2);
|
||||
});
|
||||
|
||||
|
|
@ -108,26 +108,26 @@ card('Execute: Trace Route', () => {
|
|||
const t = scene({ south: { main: ['Execute: Trace Route'] } });
|
||||
t.hand(0, 'Execute: Trace Route');
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1);
|
||||
t.ram(0, 5).to('play').play(0, 'Execute: Trace Route', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
t.bandwidth(0, 5).to('play').play(0, 'Execute: Trace Route', 'C1', { ref: { player: 0, slot: 1 } }).settle();
|
||||
assert.equal(attackerDice(t), 5, 'attacks right away with +1 Core');
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'C1');
|
||||
});
|
||||
|
||||
card('Execute: Override', () => {
|
||||
const t = scene({ south: { main: ['Execute: Override'] }, north: { main: ['Stack Overflow'] } });
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Override');
|
||||
t.ram(0, 5).play(0, 'Execute: Override', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Override', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 4);
|
||||
t.to('playAgain').end();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'until end of turn');
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, 'until end of turn');
|
||||
});
|
||||
|
||||
card('Execute: Memory Dump', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Memory Dump', 'Execute: Memory Dump'] } });
|
||||
t.hand(0, 'Execute: Memory Dump', 'Execute: Memory Dump');
|
||||
t.ram(0, 8).play(0, 'Execute: Memory Dump', 'C1');
|
||||
t.bandwidth(0, 8).play(0, 'Execute: Memory Dump', 'C1');
|
||||
assert.equal(t.s.choice?.kind, 'Execute: Memory Dump:discard', "not South's: draw 2, discard 1");
|
||||
t.choose('Network Interface Upgrade').settle();
|
||||
assert.equal(t.s.players[0].hand.length, 1 + 2 - 1);
|
||||
|
|
@ -141,8 +141,8 @@ card('Execute: Rollback', () => {
|
|||
t.own(1, 'C1');
|
||||
const [so] = t.hand(1, 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Rollback');
|
||||
t.ram(0, 4);
|
||||
t.ram(1, 7).to('play').act({ type: 'installProgram', card: so, at: 'C1' });
|
||||
t.bandwidth(0, 4);
|
||||
t.bandwidth(1, 7).to('play').act({ type: 'installProgram', card: so, at: 'C1' });
|
||||
assert.equal(t.decider, 0, 'South may respond to the install');
|
||||
t.play(0, 'Execute: Rollback', 'C1', { card: so }).settle();
|
||||
assert.deepEqual(t.s.players[1].hand, [so]);
|
||||
|
|
@ -152,7 +152,7 @@ card('Execute: Rollback', () => {
|
|||
card('Execute: Root Access', () => {
|
||||
const t = new Table({ south: { main: ['Execute: Root Access'] } });
|
||||
t.hand(0, 'Execute: Root Access');
|
||||
t.ram(0, 4).play(0, 'Execute: Root Access', 'C1').settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Root Access', 'C1').settle();
|
||||
assert.ok(t.s.locations.C1.rootAccess[0] > t.s.clock);
|
||||
t.to('playAgain').end();
|
||||
assert.ok(t.s.locations.C1.rootAccess[0] <= t.s.clock, 'until end of turn');
|
||||
|
|
@ -163,19 +163,19 @@ card('Execute: Packet Flood', () => {
|
|||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
t.hand(1, 'Execute: Packet Flood');
|
||||
t.ram(1, 5);
|
||||
t.bandwidth(1, 5);
|
||||
t.act({ type: 'advance', slot: 1, to: 'C2' });
|
||||
assert.equal(t.decider, 1);
|
||||
t.play(1, 'Execute: Packet Flood', 'B1', { to: 'B1' }).settle();
|
||||
t.to('attack').end();
|
||||
assert.equal(t.s.locations.C2.owner, null, "the advance fails: it can't move");
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
});
|
||||
|
||||
card('Execute: Emergency Shutdown', () => {
|
||||
const t = scene({ north: { main: ['Execute: Emergency Shutdown'] } });
|
||||
t.hand(1, 'Execute: Emergency Shutdown');
|
||||
t.ram(1, 6);
|
||||
t.bandwidth(1, 6);
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1);
|
||||
fight(t);
|
||||
assert.equal(openWindow(t.s)?.kind, 'preRoll');
|
||||
|
|
@ -183,17 +183,17 @@ card('Execute: Emergency Shutdown', () => {
|
|||
assert.equal(openWindow(t.s)?.kind, 'postRoll', 'North waits to see the dice');
|
||||
t.play(1, 'Execute: Emergency Shutdown', 'C1').settle();
|
||||
assert.equal(t.s.locations.C1.owner, 1);
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.ok(t.avatar(0, 1).disabledUntil > t.s.clock);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.ok(t.anomaly(0, 1).disabledUntil > t.s.clock);
|
||||
});
|
||||
|
||||
card('Execute: Process Clone', () => {
|
||||
const t = scene({ south: { main: ['Execute: Process Clone', 'Stack Overflow'] } });
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Process Clone');
|
||||
t.ram(0, 7).play(0, 'Execute: Process Clone', 'B1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4 + 2 + 2, 'two copies, each counting 2 Programs');
|
||||
t.bandwidth(0, 7).play(0, 'Execute: Process Clone', 'B1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4 + 2 + 2, 'two copies, each counting 2 Programs');
|
||||
});
|
||||
|
||||
card('Execute: Defragment', () => {
|
||||
|
|
@ -201,9 +201,9 @@ card('Execute: Defragment', () => {
|
|||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.s.cards[so].disabledUntil = 1e9;
|
||||
t.hand(0, 'Execute: Defragment');
|
||||
t.ram(0, 4).play(0, 'Execute: Defragment', 'B1', { card: so }).settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Defragment', 'B1', { card: so }).settle();
|
||||
assert.equal(t.s.cards[so].disabledUntil, 0);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5);
|
||||
});
|
||||
|
||||
card('Execute: Remote Access', () => {
|
||||
|
|
@ -211,18 +211,18 @@ card('Execute: Remote Access', () => {
|
|||
t.own(1, 'D1');
|
||||
const so = t.program(1, 'D1', 'Stack Overflow');
|
||||
t.hand(1, 'Execute: Remote Access');
|
||||
t.ram(1, 6).play(1, 'Execute: Remote Access', 'C1', { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'Stack Overflow runs on C1 too');
|
||||
t.bandwidth(1, 6).play(1, 'Execute: Remote Access', 'C1', { card: so }).settle();
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, 'Stack Overflow runs on C1 too');
|
||||
});
|
||||
|
||||
card('Execute: Purge', () => {
|
||||
const t = scene({ south: { main: ['Execute: Purge', 'Additional Core'] } });
|
||||
const hw = t.hardware(0, 1, 'Additional Core');
|
||||
t.s.cards[hw].disabledUntil = 1e9;
|
||||
Object.assign(t.avatar(0, 1), { infection: 2, permanentInfection: 1 });
|
||||
Object.assign(t.anomaly(0, 1), { infection: 2, permanentInfection: 1 });
|
||||
t.hand(0, 'Execute: Purge');
|
||||
t.ram(0, 4).play(0, 'Execute: Purge', 'B1', { to: 'B1' }).settle();
|
||||
assert.equal(t.avatar(0, 1).infection + t.avatar(0, 1).permanentInfection, 0);
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Purge', 'B1', { to: 'B1' }).settle();
|
||||
assert.equal(t.anomaly(0, 1).infection + t.anomaly(0, 1).permanentInfection, 0);
|
||||
assert.equal(t.s.cards[hw].disabledUntil, 0);
|
||||
});
|
||||
|
||||
|
|
@ -232,8 +232,8 @@ card('Execute: Hard Reset', () => {
|
|||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
const hf = t.program(0, 'B1', 'Hotfix');
|
||||
t.hand(0, 'Execute: Hard Reset');
|
||||
t.ram(0, 6).play(0, 'Execute: Hard Reset', 'B1', { cards: [so, hf] }).settle();
|
||||
t.bandwidth(0, 6).play(0, 'Execute: Hard Reset', 'B1', { cards: [so, hf] }).settle();
|
||||
assert.deepEqual(t.s.locations.B1.programs, []);
|
||||
assert.deepEqual(t.s.players[0].hand.sort(), [so, hf].sort());
|
||||
assert.equal(t.s.players[0].ram, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 2);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import assert from 'node:assert/strict';
|
|||
import { test } from 'node:test';
|
||||
import { DEFAULT_GREEDY, greedyBot } from '../src/bots/greedy.ts';
|
||||
import { randomBot } from '../src/bots/random.ts';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { playGame } from '../src/play.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
||||
// playGame with `check` throws on the first broken invariant (card conservation, RAM, placement).
|
||||
// playGame with `check` throws on the first broken invariant (card conservation, Bandwidth, placement).
|
||||
test('random bots play 200 games with every card without breaking a rule', () => {
|
||||
for (let seed = 1; seed <= 200; seed++) {
|
||||
const s = playGame({ pool, bots: [randomBot, randomBot], seed, check: true });
|
||||
|
|
@ -29,7 +29,7 @@ test('greedy bots play 200 games without breaking a rule', () => {
|
|||
|
||||
test('bots play the recruit rule without breaking a rule', () => {
|
||||
for (const k of [3, 7]) {
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), `recruit.avatarsInDeck=${k}`);
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'recruit.on=true'), `recruit.anomaliesInDeck=${k}`);
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
|
|
@ -37,8 +37,8 @@ test('bots play the recruit rule without breaking a rule', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('bots play the buy-Avatars rule without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'buyAvatars.on=true');
|
||||
test('bots play the buy-Anomalies rule without breaking a rule', () => {
|
||||
const rules = withRule(DEFAULT_RULES, 'buyAnomalies.on=true');
|
||||
for (let seed = 1; seed <= 25; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
|
|
@ -46,7 +46,7 @@ test('bots play the buy-Avatars rule without breaking a rule', () => {
|
|||
});
|
||||
|
||||
test('bots play the copy-rule variants without breaking a rule', () => {
|
||||
for (const spec of ['copies.waitATurn=true', 'copies.needAvatar2=true', 'copies.allowed=false']) {
|
||||
for (const spec of ['copies.waitATurn=true', 'copies.needAnomaly2=true', 'copies.allowed=false']) {
|
||||
const rules = withRule(DEFAULT_RULES, spec);
|
||||
for (let seed = 1; seed <= 15; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
|
|
@ -81,6 +81,16 @@ test('bots play the command rule without breaking a rule', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('bots play the 4×4 and lanes boards without breaking a rule', () => {
|
||||
for (const board of ['grid4', 'grid4-wide', 'grid4-one', 'lanes', 'lanes-open']) {
|
||||
const rules = withRule(DEFAULT_RULES, `board=${board}`);
|
||||
for (let seed = 1; seed <= 15; seed++) {
|
||||
assert.ok(playGame({ pool, bots: [randomBot, randomBot], seed, rules, check: true }).over);
|
||||
assert.ok(playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, rules, check: true }).over);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('greedy beats random', () => {
|
||||
let wins = 0;
|
||||
for (let seed = 1; seed <= 100; seed++) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
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 { healthOf, portsFree } from '../src/query.ts';
|
||||
import { anomalyCores, canWear, executionActions, executionCost, programCost } from '../src/engine.ts';
|
||||
import { healthOf, slotsFree } from '../src/query.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
|
|
@ -20,21 +20,21 @@ 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'), 4, 'no Cores');
|
||||
assert.equal(anomalyCores(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', () => {
|
||||
const t = scene({ south: { main: ['Additional Core'] } });
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 5);
|
||||
});
|
||||
|
||||
card('Overclocked CPU', () => {
|
||||
const t = scene({ south: { main: ['Overclocked CPU', 'Stack Overflow'] } });
|
||||
t.hardware(0, 1, 'Overclocked CPU');
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 6, '+2 in combat');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 6, '+2 in combat');
|
||||
attackC1(t);
|
||||
t.rig(6, 6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.equal(attackerDice(t), 6);
|
||||
|
|
@ -53,7 +53,7 @@ card('Solid-State Cache', () => {
|
|||
const [so, hf] = t.hand(0, 'Stack Overflow', 'Hotfix');
|
||||
assert.equal(programCost(t.s, 0, so, 'B1'), 4);
|
||||
assert.equal(programCost(t.s, 0, so, 'S1'), 7, 'only on the occupied Server');
|
||||
t.ram(0, 4).to('play').go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
t.bandwidth(0, 4).to('play').go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
assert.equal(programCost(t.s, 0, hf, 'B1'), 7, 'first each turn');
|
||||
});
|
||||
|
||||
|
|
@ -63,28 +63,28 @@ card('Redundant Power Supply', () => {
|
|||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [rps, ac], 'kept, in its slot');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [rps, ac], 'kept, in its slot');
|
||||
// The second defeat loses it.
|
||||
t.to('playAgain').end().to('playAgain').end();
|
||||
t.go({ type: 'place', slot: 1, to: 'B1' });
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, []);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, []);
|
||||
});
|
||||
|
||||
card('Network Interface Upgrade', () => {
|
||||
const t = new Table({ south: { avatars: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'], main: ['Additional Core', 'RAM Expansion', 'Network Interface Upgrade', 'Packet Accelerator'] } });
|
||||
const t = new Table({ south: { anomalies: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'], main: ['Additional Core', 'RAM Expansion', 'Network Interface Upgrade', 'Packet Accelerator'] } });
|
||||
const beta = { player: 0 as const, slot: 1 };
|
||||
t.place(0, 1, 'S1');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hardware(0, 1, 'RAM Expansion');
|
||||
const [niu, pa] = t.hand(0, 'Network Interface Upgrade', 'Packet Accelerator');
|
||||
assert.equal(portsFree(t.s, beta), 0);
|
||||
assert.equal(slotsFree(t.s, beta), 0);
|
||||
assert.ok(!canWear(t.s, pa, beta));
|
||||
assert.ok(canWear(t.s, niu, beta), 'fits with both ports full');
|
||||
t.ram(0, 4).to('play').go({ type: 'installHardware', card: niu, slot: 1 });
|
||||
assert.equal(portsFree(t.s, beta), 1, 'and adds a port');
|
||||
assert.ok(canWear(t.s, niu, beta), 'fits with both Expansion Slots full');
|
||||
t.bandwidth(0, 4).to('play').go({ type: 'installHardware', card: niu, slot: 1 });
|
||||
assert.equal(slotsFree(t.s, beta), 1, 'and adds an Expansion Slot');
|
||||
assert.ok(canWear(t.s, pa, beta));
|
||||
});
|
||||
|
||||
|
|
@ -93,22 +93,22 @@ card('Dedicated GPU', () => {
|
|||
t.place(0, 1, 'S1');
|
||||
t.hardware(0, 1, 'Dedicated GPU');
|
||||
t.hand(0, 'Execute: Ping Sweep');
|
||||
t.ram(0, 4).play(0, 'Execute: Ping Sweep', null, {}, 'S1').settle();
|
||||
t.bandwidth(0, 4).play(0, 'Execute: Ping Sweep', null, {}, 'S1').settle();
|
||||
assert.equal(t.s.players[0].hand.length, 3, 'performed by the Server it stands on: draws 2 + 1');
|
||||
});
|
||||
|
||||
card('ECC Memory', () => {
|
||||
const t = scene({ south: { main: ['ECC Memory', 'Additional Core'] }, north: { main: ['Memory Leak', 'Stock Rice'] } });
|
||||
const t = scene({ south: { main: ['ECC Memory', 'Additional Core'] }, north: { main: ['Bloatware', 'Stock Rice'] } });
|
||||
t.hardware(0, 1, 'ECC Memory');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.program(1, 'C1', 'Stock Rice');
|
||||
attackC1(t);
|
||||
t.rig(6, 6, 6, 6, 6, 1, 1, 1, 1).end();
|
||||
assert.equal(attackerDice(t), 5, "neither Bug Program touches it");
|
||||
assert.equal(addBugs(t.s, { player: 0, slot: 1 }, 1, 'a Bug card', 1), false, "and opponents can't give it Bug counters");
|
||||
assert.equal(t.avatar(0, 1).bugs, 0);
|
||||
assert.equal(addBugs(t.s, { player: 1, slot: 1 }, 1, 'a Bug card', 0), true, 'Avatars without it can get them');
|
||||
assert.equal(t.anomaly(0, 1).bugs, 0);
|
||||
assert.equal(addBugs(t.s, { player: 1, slot: 1 }, 1, 'a Bug card', 0), true, 'Anomalies without it can get them');
|
||||
});
|
||||
|
||||
card('Cooling System', () => {
|
||||
|
|
@ -118,43 +118,43 @@ card('Cooling System', () => {
|
|||
t.hardware(0, 1, 'Cooling System');
|
||||
t.hardware(0, 1, 'Solid-State Cache');
|
||||
const [so, hf] = t.hand(0, 'Stack Overflow', 'Hotfix');
|
||||
t.ram(0, 20).to('play');
|
||||
t.bandwidth(0, 20).to('play');
|
||||
t.go({ type: 'installProgram', card: so, at: 'B1' });
|
||||
assert.equal(programCost(t.s, 0, hf, 'B1'), 4, 'Solid-State Cache works twice');
|
||||
t.go({ type: 'installProgram', card: hf, at: 'B1' });
|
||||
assert.equal(t.s.players[0].ram, 20 - 4 - 4);
|
||||
assert.equal(t.s.players[0].bandwidth, 20 - 4 - 4);
|
||||
});
|
||||
|
||||
card('RAID Array', () => {
|
||||
const t = scene({ south: { main: ['RAID Array', 'Additional Core'] } });
|
||||
t.hardware(0, 1, 'RAID Array');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.ram(0, 5);
|
||||
t.bandwidth(0, 5);
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.s.choice?.kind, 'RAID Array:keep');
|
||||
t.choose('Keep').settle();
|
||||
assert.equal(t.avatar(0, 1).hardware.length, 2);
|
||||
assert.equal(t.s.players[0].ram, 0, 'half of 5 + 5');
|
||||
assert.equal(t.anomaly(0, 1).hardware.length, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'half of 5 + 5');
|
||||
});
|
||||
|
||||
card('Packet Accelerator', () => {
|
||||
const t = scene({ south: { main: ['Packet Accelerator'] } });
|
||||
t.hardware(0, 1, 'Packet Accelerator');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 5);
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 5);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 4);
|
||||
});
|
||||
|
||||
card('Firewall Appliance', () => {
|
||||
const t = scene({ south: { main: ['Execute: Sabotage'] }, north: { main: ['Firewall Appliance'] } });
|
||||
const fa = t.hardware(1, 1, 'Firewall Appliance');
|
||||
const [sab] = t.hand(0, 'Execute: Sabotage');
|
||||
t.ram(0, 10);
|
||||
t.bandwidth(0, 10);
|
||||
attackC1(t);
|
||||
t.act({ type: 'end' });
|
||||
assert.equal(executionCost(t.s, 0, sab, 'C1', { card: fa, mode: 'destroy' }), 10, '+3 for the first hostile Execution');
|
||||
t.play(0, 'Execute: Sabotage', 'C1', { card: fa, mode: 'destroy' });
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
});
|
||||
|
||||
card('Hardware Sandbox', () => {
|
||||
|
|
@ -164,11 +164,11 @@ card('Hardware Sandbox', () => {
|
|||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
const hf = t.program(1, 'C1', 'Hotfix');
|
||||
const [sandbox] = t.hand(1, 'Hardware Sandbox');
|
||||
t.ram(1, 7).to('play').act({ type: 'installHardware', card: sandbox, slot: 1 });
|
||||
t.bandwidth(1, 7).to('play').act({ type: 'installHardware', card: sandbox, slot: 1 });
|
||||
t.choose('Stack Overflow').settle();
|
||||
t.to('playAgain').end();
|
||||
t.hand(0, 'Execute: Kill Process', 'Execute: Root Access');
|
||||
t.ram(0, 9);
|
||||
t.bandwidth(0, 9);
|
||||
const kills = () => executionActions(t.s, 0, 'now').filter((a) => a.type === 'play' && t.s.cards[a.card].name === 'Execute: Kill Process').map((a) => a.type === 'play' && a.args.card);
|
||||
assert.deepEqual(kills(), [hf], 'Stack Overflow is protected');
|
||||
t.play(0, 'Execute: Root Access', 'C1').settle();
|
||||
|
|
@ -193,16 +193,16 @@ card('Hot-Swap Bay', () => {
|
|||
const hsb = t.hardware(0, 1, 'Hot-Swap Bay');
|
||||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
const [oc] = t.hand(0, 'Overclocked CPU');
|
||||
t.ram(0, 1).use(hsb, { card: ac, cards: [oc] }).settle();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [hsb, oc]);
|
||||
t.bandwidth(0, 1).use(hsb, { card: ac, cards: [oc] }).settle();
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [hsb, oc]);
|
||||
assert.deepEqual(t.s.players[0].hand, [ac]);
|
||||
assert.equal(t.s.players[0].ram, 0, 'pays the 1 RAM difference');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'pays the 1 Gb difference');
|
||||
});
|
||||
|
||||
test('Hardware must still fit its ports when Network Interface Upgrade leaves', () => {
|
||||
test('Hardware must still fit its Expansion Slots when Network Interface Upgrade leaves', () => {
|
||||
const t = new Table({
|
||||
south: {
|
||||
avatars: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'],
|
||||
anomalies: ['Beta Version 1.0', 'Broken Bits', 'Code Zero', 'Pixelated Picture'],
|
||||
main: ['Network Interface Upgrade', 'Hot-Swap Bay', 'Additional Core', 'Packet Accelerator', 'RAM Expansion', 'Execute: Rollback'],
|
||||
},
|
||||
});
|
||||
|
|
@ -212,15 +212,15 @@ test('Hardware must still fit its ports when Network Interface Upgrade leaves',
|
|||
const ac = t.hardware(0, 1, 'Additional Core');
|
||||
const pa = t.hardware(0, 1, 'Packet Accelerator');
|
||||
t.hand(0, 'RAM Expansion', 'Execute: Rollback');
|
||||
t.ram(0, 20);
|
||||
// Beta Version 1.0 has 2 ports, +1 from the NIU, and all 3 are in use.
|
||||
t.bandwidth(0, 20);
|
||||
// Beta Version 1.0 has 2 Expansion Slots, +1 from the NIU, and all 3 are in use.
|
||||
const swaps = t.legal().filter((a) => a.type === 'activate' && a.card === hsb);
|
||||
assert.ok(!swaps.some((a) => a.type === 'activate' && a.args.card === niu), "Hot-Swap Bay can't swap the NIU for a card that needs a port");
|
||||
assert.ok(!swaps.some((a) => a.type === 'activate' && a.args.card === niu), "Hot-Swap Bay can't swap the NIU for a card that needs an Expansion Slot");
|
||||
assert.ok(swaps.some((a) => a.type === 'activate' && a.args.card === ac));
|
||||
// Rollback returns the NIU: the newest Hardware no longer fits and is discarded.
|
||||
t.s.cards[niu].installedTurn = t.s.turn;
|
||||
t.play(0, 'Execute: Rollback', 'S1', { card: niu }).settle();
|
||||
assert.deepEqual(t.avatar(0, 1).hardware, [hsb, ac]);
|
||||
assert.deepEqual(t.anomaly(0, 1).hardware, [hsb, ac]);
|
||||
assert.ok(t.s.players[0].discard.includes(pa));
|
||||
});
|
||||
|
||||
|
|
@ -232,7 +232,7 @@ card('Quantum Coprocessor', () => {
|
|||
t.place(0, 1, 'S1');
|
||||
const qc = t.hardware(0, 1, 'Quantum Coprocessor');
|
||||
t.hand(0, 'Execute: Kill Process');
|
||||
t.ram(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }, 'S1').settle();
|
||||
t.bandwidth(0, 5).play(0, 'Execute: Kill Process', 'C1', { card: so }, 'S1').settle();
|
||||
assert.equal(t.s.choice?.kind, 'Quantum Coprocessor:copy');
|
||||
t.choose('Hotfix').settle();
|
||||
assert.ok(t.s.cards[so].disabledUntil > t.s.clock);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function turnOf(t: Table, p: 0 | 1): Table {
|
|||
return t;
|
||||
}
|
||||
|
||||
/** South's Avatar 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Avatar 1 on C1. */
|
||||
/** South's Anomaly 1 (Broken Bits, 4 Cores, 9 Health) on B1 facing North's Anomaly 1 on C1. */
|
||||
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');
|
||||
|
|
@ -38,9 +38,9 @@ test('health: the loser takes the margin as damage, and nobody moves', () => {
|
|||
t.rig(6, 6, 6, 6, 5, 5, 5, 4); // 24 to 19
|
||||
t.end();
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1', 'the attacker stays where it attacked from');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.equal(t.avatar(1, 1).damage, 5);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1', 'the attacker stays where it attacked from');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(1, 1).damage, 5);
|
||||
assert.equal(healthLeft(t.s, { player: 1, slot: 1 }), 4);
|
||||
assert.equal(t.s.stats.attacksWon[0], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 5);
|
||||
|
|
@ -48,21 +48,21 @@ test('health: the loser takes the margin as damage, and nobody moves', () => {
|
|||
assert.equal(t.s.combat, null);
|
||||
});
|
||||
|
||||
test('health: damage adds up; the Avatar is destroyed at 0 Health, loses its Hardware, and the location falls', () => {
|
||||
test('health: damage adds up; the Anomaly is destroyed at 0 Health, loses its Hardware, and the location falls', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 6;
|
||||
t.anomaly(1, 1).damage = 6;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 3, 3, 3, 3, 3); // 24 to 15: 9 damage, 3 was enough
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null, 'destroyed: back in its slot');
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'a destroyed Avatar comes back at full Health');
|
||||
assert.deepEqual(t.avatar(1, 1).hardware, []);
|
||||
assert.equal(t.anomaly(1, 1).at, null, 'destroyed: back in its slot');
|
||||
assert.equal(t.anomaly(1, 1).damage, 0, 'a destroyed Anomaly comes back at full Health');
|
||||
assert.deepEqual(t.anomaly(1, 1).hardware, []);
|
||||
assert.ok(t.s.players[1].discard.includes(hw));
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'C1');
|
||||
assert.equal(t.s.stats.capturesInCombat[0], 1);
|
||||
assert.equal(t.s.stats.avatarsDestroyed[1], 1);
|
||||
assert.equal(t.s.stats.anomaliesDestroyed[1], 1);
|
||||
assert.equal(t.s.stats.damageDealt[0], 9, 'the whole margin counts as dealt');
|
||||
});
|
||||
|
||||
|
|
@ -71,18 +71,18 @@ test('health: a losing attacker takes damage and stays put, or is destroyed by a
|
|||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 4, 4); // 12 to 16
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(0, 1).damage, 4);
|
||||
assert.equal(t.avatar(1, 1).damage, 0, 'the winner takes no damage');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 4);
|
||||
assert.equal(t.anomaly(1, 1).damage, 0, 'the winner takes no damage');
|
||||
assert.equal(t.s.stats.damageDealt[1], 4);
|
||||
|
||||
const u = standoff();
|
||||
u.avatar(0, 1).damage = 5;
|
||||
u.anomaly(0, 1).damage = 5;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(1, 1, 1, 1, 2, 2, 2, 2); // 4 to 8: 4 damage, 4 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(0, 1).at, null, 'destroyed');
|
||||
assert.equal(u.avatar(0, 1).damage, 0);
|
||||
assert.equal(u.anomaly(0, 1).at, null, 'destroyed');
|
||||
assert.equal(u.anomaly(0, 1).damage, 0);
|
||||
assert.equal(u.s.locations.B1.owner, 0, 'losing an attack never loses the origin');
|
||||
});
|
||||
|
||||
|
|
@ -91,10 +91,10 @@ test('health: a tie is a stalemate, with no reroll and no damage', () => {
|
|||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(3, 3, 3, 3, 4, 4, 2, 2);
|
||||
t.end();
|
||||
assert.equal(t.avatar(0, 1).damage, 0);
|
||||
assert.equal(t.avatar(1, 1).damage, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.avatar(1, 1).at, 'C1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 0);
|
||||
assert.equal(t.anomaly(1, 1).damage, 0);
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(1, 1).at, 'C1');
|
||||
assert.deepEqual(t.s.rigged, [], 'no dice were rerolled');
|
||||
assert.match(t.logText(), /stalemate/);
|
||||
assert.equal(t.s.stats.combatsTied[0], 1);
|
||||
|
|
@ -104,13 +104,13 @@ test('health: a tie is a stalemate, with no reroll and no damage', () => {
|
|||
test('health: recall heals fully, keeps Hardware, counts as the placement, and leaves the location undefended', () => {
|
||||
const t = standoff({ northMain: ['Additional Core'] });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 7;
|
||||
t.avatar(1, 1).infection = 2;
|
||||
t.anomaly(1, 1).damage = 7;
|
||||
t.anomaly(1, 1).infection = 2;
|
||||
turnOf(t, 1); // South's turn passes without acting
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
assert.ok(!t.can({ type: 'recall', slot: 2 }), 'only Avatars in play can be recalled');
|
||||
assert.ok(!t.can({ type: 'recall', slot: 2 }), 'only Anomalies in play can be recalled');
|
||||
t.go({ type: 'recall', slot: 1 });
|
||||
const av = t.avatar(1, 1);
|
||||
const av = t.anomaly(1, 1);
|
||||
assert.equal(av.at, null);
|
||||
assert.equal(av.damage, 0);
|
||||
assert.equal(av.infection, 0, 'leaving play removes counters');
|
||||
|
|
@ -124,26 +124,26 @@ test('health: recall heals fully, keeps Hardware, counts as the placement, and l
|
|||
assert.ok(t.can({ type: 'advance', slot: 1, to: 'C1' }));
|
||||
});
|
||||
|
||||
test('health: a rooted Avatar can\'t be recalled, and the rule can be switched off', () => {
|
||||
test('health: a rooted Anomaly can\'t be recalled, and the rule can be switched off', () => {
|
||||
const t = standoff();
|
||||
t.avatar(0, 1).rootedUntil = FOREVER;
|
||||
t.anomaly(0, 1).rootedUntil = FOREVER;
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }), 'Packet Flood: no retreat');
|
||||
t.avatar(0, 1).rootedUntil = 0;
|
||||
t.anomaly(0, 1).rootedUntil = 0;
|
||||
assert.ok(t.can({ type: 'recall', slot: 1 }));
|
||||
t.s.rules = withRule(t.s.rules, 'health.recall=false');
|
||||
assert.ok(!t.can({ type: 'recall', slot: 1 }));
|
||||
});
|
||||
|
||||
test('health: Redundant Power Supply still saves the Hardware of a destroyed Avatar', () => {
|
||||
test('health: Redundant Power Supply still saves the Hardware of a destroyed Anomaly', () => {
|
||||
const t = standoff({ northMain: ['Redundant Power Supply', 'Additional Core'] });
|
||||
const rps = t.hardware(1, 1, 'Redundant Power Supply');
|
||||
const core = t.hardware(1, 1, 'Additional Core');
|
||||
t.avatar(1, 1).damage = 8;
|
||||
t.anomaly(1, 1).damage = 8;
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 1); // 24 to 5
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 1).at, null);
|
||||
assert.deepEqual([...t.avatar(1, 1).hardware].sort(), [rps, core].sort());
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.deepEqual([...t.anomaly(1, 1).hardware].sort(), [rps, core].sort());
|
||||
assert.equal(t.s.locations.C1.owner, 0);
|
||||
});
|
||||
|
||||
|
|
@ -154,14 +154,14 @@ test('health: with two defenders the damage destroys the weakest first, and the
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(1, 1, 'C1'); // Broken Bits, 4 Cores, 9 Health
|
||||
t.place(1, 2, 'C1'); // Pixelated Picture, 3 Cores, 10 Health
|
||||
t.avatar(1, 2).damage = 7; // 3 left
|
||||
t.anomaly(1, 2).damage = 7; // 3 left
|
||||
t.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
t.rig(6, 6, 6, 6, 1, 1, 1, 1, 5, 5, 5); // 24 to 4 + 15 = 19: 5 damage
|
||||
t.end();
|
||||
assert.equal(t.avatar(1, 2).at, null, 'the weak one is destroyed with 3 of the damage');
|
||||
assert.equal(t.avatar(1, 1).damage, 2, 'the other 2 land on the survivor');
|
||||
assert.equal(t.anomaly(1, 2).at, null, 'the weak one is destroyed with 3 of the damage');
|
||||
assert.equal(t.anomaly(1, 1).damage, 2, 'the other 2 land on the survivor');
|
||||
assert.equal(t.s.locations.C1.owner, 1, 'C1 holds with a defender left');
|
||||
assert.equal(t.avatar(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
|
||||
// Enough damage for both takes the location.
|
||||
const u = new Table({ health: true, north: { servers: ['Cluster Server'] } });
|
||||
|
|
@ -170,29 +170,29 @@ test('health: with two defenders the damage destroys the weakest first, and the
|
|||
u.place(0, 1, 'B1');
|
||||
u.place(1, 1, 'C1');
|
||||
u.place(1, 2, 'C1');
|
||||
u.avatar(1, 1).damage = 8;
|
||||
u.avatar(1, 2).damage = 8;
|
||||
u.anomaly(1, 1).damage = 8;
|
||||
u.anomaly(1, 2).damage = 8;
|
||||
u.to('attack').go({ type: 'attack', slot: 1, to: 'C1' });
|
||||
u.rig(6, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1); // 24 to 7: 17 damage for 1 + 2 left
|
||||
u.end();
|
||||
assert.equal(u.avatar(1, 1).at, null);
|
||||
assert.equal(u.avatar(1, 2).at, null);
|
||||
assert.equal(u.anomaly(1, 1).at, null);
|
||||
assert.equal(u.anomaly(1, 2).at, null);
|
||||
assert.equal(u.s.locations.C1.owner, 0);
|
||||
assert.equal(u.avatar(0, 1).at, 'C1');
|
||||
assert.equal(u.anomaly(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;
|
||||
const bandwidth = t.s.players[1].bandwidth;
|
||||
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');
|
||||
assert.equal(t.anomaly(0, 1).at, 'B1');
|
||||
assert.equal(t.anomaly(0, 1).damage, 4);
|
||||
assert.equal(t.s.players[1].bandwidth, bandwidth + 3, 'Resource Leech pays 3');
|
||||
assert.equal(t.anomaly(0, 1).permanentInfection, 1, 'a permanent Infection counter');
|
||||
});
|
||||
|
||||
test('health: Overflow Error only disables, until the next command, while the attacker lives', () => {
|
||||
|
|
@ -219,19 +219,19 @@ test('health: Overflow Error may destroy a Program when the attacker is destroye
|
|||
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);
|
||||
assert.equal(t.anomaly(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'] } });
|
||||
const t = new Table({ health: true, south: { anomalies: ['Backup Machine', 'Broken Bits', 'Pixelated Picture', 'Corrupt Driver'] } });
|
||||
t.own(0, 'B1');
|
||||
t.place(0, 1, 'B1');
|
||||
const bm = t.avatar(0, 1).card;
|
||||
const bm = t.anomaly(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);
|
||||
t.anomaly(0, 1).damage = 5;
|
||||
t.bandwidth(0, 5).use(bm, { heal: true }).settle();
|
||||
assert.equal(t.anomaly(0, 1).damage, 2);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
assert.equal(healthLeft(t.s, { player: 0, slot: 1 }), 8);
|
||||
});
|
||||
|
||||
|
|
@ -242,6 +242,6 @@ test('health: RAM Expansion adds 2 Health, so a hit that would destroy the weare
|
|||
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(t.anomaly(1, 1).at, 'C1', 'C1 holds');
|
||||
assert.equal(healthLeft(t.s, { player: 1, slot: 1 }), 2);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd } from '../src/map.ts';
|
||||
import * as map from '../src/map.ts';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd, useBoard } from '../src/map.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
|
||||
const RULES_MD = readFileSync(new URL('../../rules.md', import.meta.url), 'utf8');
|
||||
|
||||
|
|
@ -31,3 +33,58 @@ test('levels are mirrored between the players', () => {
|
|||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(0, 'E3'), 5);
|
||||
});
|
||||
|
||||
test('the 4×4 board: squares joined side to side, levels 1–4, starts join the middle of their row', () => {
|
||||
useBoard('grid4');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 16);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 24);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['D2', 'D3']);
|
||||
assert.deepEqual(near('B2'), ['A2', 'B1', 'B3', 'C2']);
|
||||
assert.deepEqual(near('A1'), ['A2', 'B1']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'DCBA'['ABCD'.indexOf(loc[0])] + (5 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'A4'), 1);
|
||||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(1, 'A1'), 4);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('the lanes board: three lanes of five, linked only across the middle row', () => {
|
||||
useBoard('lanes');
|
||||
try {
|
||||
assert.equal(map.GRID.length, 15);
|
||||
assert.equal(map.LINES.filter((l) => l.gateway).length, 14);
|
||||
const near = (loc: string) => map.LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(near('S1'), ['A1', 'A2', 'A3']);
|
||||
assert.deepEqual(near('S2'), ['E1', 'E2', 'E3']);
|
||||
assert.deepEqual(near('B1'), ['A1', 'C1']);
|
||||
assert.deepEqual(near('C2'), ['B2', 'C1', 'C3', 'D2']);
|
||||
const rotate = (loc: string) =>
|
||||
({ S1: 'S2', S2: 'S1' })[loc] ?? 'EDCBA'['ABCDE'.indexOf(loc[0])] + (4 - Number(loc[1]));
|
||||
for (const loc of map.GRID) {
|
||||
assert.equal(levelFor(0, loc), levelFor(1, rotate(loc)), loc);
|
||||
assert.deepEqual(near(loc).map(rotate).sort(), near(rotate(loc)), loc);
|
||||
}
|
||||
assert.equal(levelFor(0, 'C1'), 3);
|
||||
useBoard('lanes-open');
|
||||
assert.deepEqual(map.LINES.filter((l) => l.gateway).map((l) => l.id), ['C1-C2', 'C2-C3']);
|
||||
} finally {
|
||||
useBoard('classic');
|
||||
}
|
||||
});
|
||||
|
||||
test('board=grid4 wins with 12, unless a later winLocations changes it', () => {
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=grid4').winLocations, 12);
|
||||
assert.equal(withRule(withRule(DEFAULT_RULES, 'board=grid4'), 'winLocations=11').winLocations, 11);
|
||||
assert.equal(withRule(DEFAULT_RULES, 'board=lanes').winLocations, 11);
|
||||
assert.throws(() => withRule(DEFAULT_RULES, 'board=hex'), /Unknown board/);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { winChance } from '../src/odds.ts';
|
||||
import { rollOdds, winChance } from '../src/odds.ts';
|
||||
|
||||
test('equal Cores are a coin flip and odds are complementary', () => {
|
||||
for (let a = 1; a <= 8; a++) {
|
||||
|
|
@ -16,3 +16,17 @@ test('matches the table in rules.md', () => {
|
|||
assert.equal(Math.round(100 * winChance(6, 4)), 91);
|
||||
assert.equal(Math.round(100 * winChance(8, 7)), 71);
|
||||
});
|
||||
|
||||
test('one-roll odds add up, agree with winChance, and 1 Core vs 1 Core deals 35/36 damage on average', () => {
|
||||
for (let a = 1; a <= 6; a++) {
|
||||
for (let d = 1; d <= 6; d++) {
|
||||
const o = rollOdds(a, d);
|
||||
assert.ok(Math.abs(o.win + o.tie + o.lose - 1) < 1e-12);
|
||||
assert.ok(Math.abs(o.win / (o.win + o.lose) - winChance(a, d)) < 1e-12);
|
||||
}
|
||||
}
|
||||
const one = rollOdds(1, 1);
|
||||
assert.ok(Math.abs(one.tie - 1 / 6) < 1e-12);
|
||||
assert.ok(Math.abs(one.damageDealt - 35 / 36) < 1e-12);
|
||||
assert.ok(Math.abs(one.damageDealt - one.damageTaken) < 1e-12);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores, execBlocked, executionActions, executionCost, openWindow } from '../src/engine.ts';
|
||||
import { anomalyCores, execBlocked, executionActions, executionCost, openWindow } from '../src/engine.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
/** South's Avatar 1 on B1, North's Avatar 1 on C1 (both Broken Bits, 4 Cores). */
|
||||
/** 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');
|
||||
|
|
@ -20,11 +20,11 @@ const defenderDice = (t: Table) => t.logText().match(/Roll: .* vs Broken Bits \[
|
|||
card('Recursive Infection', () => {
|
||||
const t = scene({ north: { main: ['Recursive Infection'] } });
|
||||
t.program(1, 'C1', 'Recursive Infection');
|
||||
t.avatar(0, 1).infection = 2;
|
||||
t.anomaly(0, 1).infection = 2;
|
||||
attackC1(t);
|
||||
assert.equal(t.avatar(0, 1).infection, 3, 'a counter for attacking');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack'), 2, '3+ counters: -2 Cores');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'attack', 'S1'), 2, 'anywhere, while the Program is in play');
|
||||
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', () => {
|
||||
|
|
@ -34,7 +34,7 @@ card('Recursive Infection', () => {
|
|||
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.avatar(0, 1).infection, 1, 'a counter for breaching');
|
||||
assert.equal(t.anomaly(0, 1).infection, 1, 'a counter for breaching');
|
||||
});
|
||||
|
||||
card('Memory Parasite', () => {
|
||||
|
|
@ -45,7 +45,7 @@ card('Memory Parasite', () => {
|
|||
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");
|
||||
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');
|
||||
});
|
||||
|
|
@ -54,11 +54,11 @@ 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.ram(0, 6).to('play').act({ type: 'installProgram', card: rr, at: 'B1' });
|
||||
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].ram, 0, 'the second Virus is free');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'the second Virus is free');
|
||||
});
|
||||
|
||||
card('Resource Leech', () => {
|
||||
|
|
@ -66,27 +66,27 @@ card('Resource Leech', () => {
|
|||
t.program(1, 'C1', '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, 3);
|
||||
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', 'Memory Leak'] }, south: { main: ['Additional Core'] } });
|
||||
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', 'Memory Leak');
|
||||
t.program(1, 'C1', 'Bloatware');
|
||||
t.place(1, 1, 'D1');
|
||||
const [worm] = t.hand(1, 'Worm Protocol');
|
||||
t.ram(1, 4).to('play').act({ type: 'installProgram', card: worm, at: 'C1' });
|
||||
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 Memory Leak now also applies.
|
||||
// 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(), /Memory Leak: Avatar 1 \(Broken Bits\) loses 1 Core/);
|
||||
assert.match(t.logText(), /Bloatware: Anomaly 1 \(Broken Bits\) loses 1 Core/);
|
||||
assert.equal(attackerDice(t), 4, '4 + 1 - 1');
|
||||
});
|
||||
|
||||
|
|
@ -97,8 +97,8 @@ card('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.ram(0, 2).play(0, 'Execute: Root Access', 'B1').settle();
|
||||
assert.equal(t.s.players[0].ram, 0);
|
||||
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');
|
||||
});
|
||||
|
||||
|
|
@ -107,8 +107,8 @@ card('Persistent Infection', () => {
|
|||
t.program(1, 'C1', 'Persistent Infection');
|
||||
attackC1(t);
|
||||
t.rig(1, 1, 1, 1, 6, 6, 6, 6).end();
|
||||
assert.equal(t.avatar(0, 1).at, null);
|
||||
assert.equal(t.avatar(0, 1).permanentInfection, 1, 'stays after defeat');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(0, 1).permanentInfection, 1, 'stays after defeat');
|
||||
});
|
||||
|
||||
card('Infinite Loop', () => {
|
||||
|
|
@ -132,8 +132,8 @@ 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(avatarCores(t.s, 1, 1, 'defend'), 6, '+1 per Program here');
|
||||
assert.equal(avatarCores(t.s, 0, 1, 'defend'), 4);
|
||||
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', () => {
|
||||
|
|
@ -150,9 +150,9 @@ card('Race Condition', () => {
|
|||
}
|
||||
});
|
||||
|
||||
card('Memory Leak', () => {
|
||||
const t = scene({ south: { main: ['Additional Core', 'Overclocked CPU'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
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);
|
||||
|
|
@ -165,7 +165,7 @@ card('Null Pointer', () => {
|
|||
t.program(1, 'C1', 'Null Pointer');
|
||||
const so = t.program(1, 'C1', 'Stack Overflow');
|
||||
t.hand(0, 'Execute: Kill Process', 'Execute: Kill Process');
|
||||
t.ram(0, 10).play(0, 'Execute: Kill Process', 'C1', { card: so }).settle();
|
||||
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');
|
||||
|
|
@ -202,11 +202,11 @@ card('Undefined Behavior', () => {
|
|||
const ub = t.program(1, 'C1', 'Undefined Behavior');
|
||||
const so = t.program(0, 'B1', 'Stack Overflow');
|
||||
t.use(ub, { card: so }).settle();
|
||||
assert.equal(avatarCores(t.s, 1, 1, 'defend'), 5, 'copied Stack Overflow: +1 for the one Program here');
|
||||
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(avatarCores(t.s, 1, 1, 'defend'), 5, "the copy lasts through the opponent's turn");
|
||||
assert.equal(anomalyCores(t.s, 1, 1, 'defend'), 5, "the copy lasts through the opponent's turn");
|
||||
});
|
||||
|
||||
card('Packet Loss', () => {
|
||||
|
|
@ -228,7 +228,7 @@ card('Desynchronization', () => {
|
|||
t.hardware(0, 1, 'Hot-Swap Bay');
|
||||
t.hardware(0, 1, 'Additional Core');
|
||||
t.hand(0, 'RAM Expansion');
|
||||
t.ram(0, 10);
|
||||
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.
|
||||
|
|
@ -251,7 +251,7 @@ 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.ram(0, 5);
|
||||
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');
|
||||
|
|
@ -268,14 +268,14 @@ card('False Positive', () => {
|
|||
t.place(0, 1, 'B1');
|
||||
t.place(0, 2, 'A2');
|
||||
t.hand(0, 'Execute: Force Reboot');
|
||||
t.ram(0, 5);
|
||||
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 Avatar took it");
|
||||
assert.ok(execBlocked(t.s, 'A2'), "South's own Anomaly took it");
|
||||
});
|
||||
|
||||
card('Fragmentation', () => {
|
||||
|
|
@ -291,7 +291,7 @@ card('Latency Spike', () => {
|
|||
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.ram(0, 4);
|
||||
t.bandwidth(0, 4);
|
||||
attackC1(t);
|
||||
t.act({ type: 'end' });
|
||||
assert.equal(openWindow(t.s)?.kind, spike ? 'postRoll' : 'preRoll');
|
||||
|
|
@ -315,10 +315,10 @@ card('Error Correction', () => {
|
|||
t.own(0, 'B1');
|
||||
t.program(0, 'B1', 'Error Correction');
|
||||
t.place(0, 1, 'B1');
|
||||
t.avatar(0, 1).infection = 2;
|
||||
t.anomaly(0, 1).infection = 2;
|
||||
t.to('playAgain').end();
|
||||
assert.equal(t.s.active, 0);
|
||||
assert.equal(t.avatar(0, 1).infection, 1, 'one removed at the start of the turn');
|
||||
assert.equal(t.anomaly(0, 1).infection, 1, 'one removed at the start of the turn');
|
||||
});
|
||||
|
||||
card('Garbage Collection', () => {
|
||||
|
|
@ -327,7 +327,7 @@ card('Garbage Collection', () => {
|
|||
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].ram, 7);
|
||||
assert.equal(t.s.players[0].bandwidth, 7);
|
||||
assert.deepEqual(t.s.locations.B1.programs, [gc]);
|
||||
});
|
||||
|
||||
|
|
@ -346,8 +346,8 @@ card('Version Control', () => {
|
|||
});
|
||||
|
||||
card('Rollback Routine', () => {
|
||||
const t = scene({ south: { main: ['Rollback Routine', 'Additional Core'] }, north: { main: ['Memory Leak'] } });
|
||||
t.program(1, 'C1', 'Memory Leak');
|
||||
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);
|
||||
|
|
@ -356,17 +356,17 @@ card('Rollback Routine', () => {
|
|||
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, "Memory Leak's -1 is undone");
|
||||
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.ram(0, 6 + 7 + 5).to('play');
|
||||
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].ram, 0, 'Hotfix, a Patch, cost 2 less');
|
||||
assert.equal(t.s.players[0].bandwidth, 0, 'Hotfix, a Patch, cost 2 less');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { avatarCores } from '../src/engine.ts';
|
||||
import { anomalyCores } 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. */
|
||||
/** South advances its Anomaly 1 from S1 into A2, drawing `server` for it. */
|
||||
function captureA2(server: string) {
|
||||
const t = new Table({ south: { servers: [server] } });
|
||||
t.nextServer(0, server);
|
||||
|
|
@ -13,36 +13,36 @@ function captureA2(server: string) {
|
|||
return t;
|
||||
}
|
||||
|
||||
card('High Efficiency RAM Server', () => {
|
||||
const t = captureA2('High Efficiency RAM Server');
|
||||
assert.equal(t.s.players[0].ram, 4 + 4, 'the capture pays 4, the Server adds 4');
|
||||
card('High Bandwidth Server', () => {
|
||||
const t = captureA2('High Bandwidth Server');
|
||||
assert.equal(t.s.players[0].bandwidth, 4 + 4, 'the capture pays 4, the Server adds 4');
|
||||
});
|
||||
|
||||
card('Power Server', () => {
|
||||
const t = captureA2('Power Server');
|
||||
assert.equal(t.s.players[0].ram, 8);
|
||||
assert.equal(t.s.players[0].bandwidth, 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);
|
||||
assert.equal(t.s.players[0].bandwidth, 8);
|
||||
assert.equal(anomalyCores(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');
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 6);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'attack'), 6, 'attacking from it counts too');
|
||||
assert.equal(anomalyCores(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);
|
||||
assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 8);
|
||||
});
|
||||
|
||||
const twoDefenders = (name: string) => () => {
|
||||
|
|
@ -57,8 +57,8 @@ const twoDefenders = (name: string) => () => {
|
|||
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');
|
||||
assert.equal(t.anomaly(1, 1).at, null);
|
||||
assert.equal(t.anomaly(1, 2).at, null, 'both defenders are defeated');
|
||||
};
|
||||
card('Cluster Server', twoDefenders('Cluster Server'));
|
||||
card('Pingable Server', twoDefenders('Pingable Server'));
|
||||
|
|
@ -71,13 +71,13 @@ card('Backup Server', () => {
|
|||
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.equal(t.anomaly(0, 5).at, 'A2', 'the copy of Anomaly 1 is in play');
|
||||
assert.equal(anomalyCores(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');
|
||||
assert.equal(t.anomaly(0, 1).at, null);
|
||||
assert.equal(t.anomaly(0, 5).at, null, 'the copy goes when the original is defeated');
|
||||
});
|
||||
|
||||
card('Upgraded Hardware', () => {
|
||||
|
|
@ -86,32 +86,32 @@ card('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');
|
||||
t.bandwidth(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);
|
||||
assert.equal(t.s.players[0].bandwidth, 0);
|
||||
});
|
||||
|
||||
card('Network Throttle', () => {
|
||||
const t = new Table();
|
||||
t.own(0, 'A2');
|
||||
t.ram(0, 1).to('play');
|
||||
t.bandwidth(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');
|
||||
assert.equal(t.s.players[0].bandwidth, 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'] } });
|
||||
for (const [copy, check] of [['Cloud Compute', 'cores'], ['High Bandwidth Server', 'bandwidth']] as const) {
|
||||
const t = new Table({ south: { servers: ['Duplicate Server', 'Cloud Compute', 'High Bandwidth Server'] } });
|
||||
t.own(0, 'B1', 'Cloud Compute');
|
||||
t.own(0, 'B2', 'High Efficiency RAM Server');
|
||||
t.own(0, 'B2', 'High Bandwidth 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, 4 + 4, 'the capture pays 4, the copied bonus 4');
|
||||
if (check === 'cores') assert.equal(anomalyCores(t.s, 0, 1, 'defend'), 8);
|
||||
else assert.equal(t.s.players[0].bandwidth, 4 + 4, 'the capture pays 4, the copied bonus 4');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ card('Protected Server', () => {
|
|||
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);
|
||||
assert.equal(t.s.players[1].bandwidth, 2);
|
||||
});
|
||||
|
||||
card('Callable Server', () => {
|
||||
|
|
|
|||
|
|
@ -3,25 +3,25 @@
|
|||
* directly and drive decisions one at a time.
|
||||
*/
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadCards } from '../src/cards.ts';
|
||||
import { loadCards } from '../src/load.ts';
|
||||
import { actionKey, applyAction, createGame, decider, legalActions, openWindow } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import type { LocId } from '../src/map.ts';
|
||||
import { coresOf, fighterOf, sideCores } from '../src/query.ts';
|
||||
import { DEFAULT_RULES, type RulesConfig } from '../src/rules.ts';
|
||||
import { avatar, removeFrom } from '../src/state.ts';
|
||||
import type { Action, Args, AvatarRef, GameState, PlayerId } from '../src/types.ts';
|
||||
import { anomaly, logFor, removeFrom } from '../src/state.ts';
|
||||
import type { Action, Args, AnomalyRef, GameState, PlayerId } from '../src/types.ts';
|
||||
|
||||
export const pool = loadCards();
|
||||
|
||||
/** Cards that do nothing in hand and can't be played in response, used to pad decks. */
|
||||
const FILLER = 'Network Interface Upgrade';
|
||||
const PLAIN_SERVER = 'Network Throttle';
|
||||
/** Avatars whose Abilities only work in combat, so they don't open response windows. */
|
||||
const DEFAULT_AVATARS = ['Broken Bits', 'Pixelated Picture', 'Corrupt Driver', 'Code Zero'];
|
||||
/** Anomalies whose Abilities only work in combat, so they don't open response windows. */
|
||||
const DEFAULT_ANOMALIES = ['Broken Bits', 'Pixelated Picture', 'Corrupt Driver', 'Code Zero'];
|
||||
|
||||
export interface Side {
|
||||
avatars?: string[];
|
||||
anomalies?: string[];
|
||||
servers?: string[];
|
||||
main?: string[];
|
||||
}
|
||||
|
|
@ -31,12 +31,12 @@ export class Table {
|
|||
|
||||
constructor(o: { south?: Side; north?: Side; first?: PlayerId; seed?: number; health?: boolean } = {}) {
|
||||
const side = (x: Side = {}) => ({
|
||||
avatars: x.avatars ?? DEFAULT_AVATARS,
|
||||
anomalies: x.anomalies ?? DEFAULT_ANOMALIES,
|
||||
servers: [...(x.servers ?? []), ...Array(12).fill(PLAIN_SERVER)],
|
||||
main: [...(x.main ?? []), ...Array(12).fill(FILLER)],
|
||||
});
|
||||
const decks = [side(o.south), side(o.north)] as const;
|
||||
// Classic turns (one turn each, every Avatar acts), no turn-1 draw for the first player, and
|
||||
// Classic turns (one turn each, every Anomaly acts), no turn-1 draw for the first player, and
|
||||
// one-roll combats, which the card tests are written for. The command rule has its own tests in
|
||||
// engine.test.ts, the health rule in health.test.ts (`health: true`).
|
||||
const rules: RulesConfig = {
|
||||
|
|
@ -45,7 +45,7 @@ export class Table {
|
|||
firstTurn: { ...DEFAULT_RULES.firstTurn, draw: false },
|
||||
health: { ...DEFAULT_RULES.health, on: o.health ?? false },
|
||||
openingHand: 0,
|
||||
deck: { avatars: 4, servers: decks[0].servers.length, main: decks[0].main.length, maxCopies: 99 },
|
||||
deck: { anomalies: 4, servers: decks[0].servers.length, main: decks[0].main.length, maxCopies: 99 },
|
||||
};
|
||||
// Both decks must be the same size under one rules object; pad the shorter one.
|
||||
const n = Math.max(decks[0].main.length, decks[1].main.length);
|
||||
|
|
@ -65,10 +65,10 @@ export class Table {
|
|||
const L = this.s.locations[start];
|
||||
this.s.players[p].serverPile.push(L.server!);
|
||||
L.server = this.take(p, PLAIN_SERVER);
|
||||
this.s.players[p].ram = 0;
|
||||
// Avatars in the order given, slot 1 face up.
|
||||
const want = (p === 0 ? o.south : o.north)?.avatars ?? DEFAULT_AVATARS;
|
||||
const avs = this.s.players[p].avatars;
|
||||
this.s.players[p].bandwidth = 0;
|
||||
// Anomalies in the order given, slot 1 face up.
|
||||
const want = (p === 0 ? o.south : o.north)?.anomalies ?? DEFAULT_ANOMALIES;
|
||||
const avs = this.s.players[p].anomalies;
|
||||
want.forEach((name, i) => {
|
||||
const j = avs.findIndex((a, k) => k < 4 && k >= i && this.s.cards[a.card].name === name);
|
||||
[avs[i].card, avs[j].card] = [avs[j].card, avs[i].card];
|
||||
|
|
@ -116,8 +116,8 @@ export class Table {
|
|||
return id;
|
||||
}
|
||||
|
||||
ram(p: PlayerId, n: number): this {
|
||||
this.s.players[p].ram = n;
|
||||
bandwidth(p: PlayerId, n: number): this {
|
||||
this.s.players[p].bandwidth = n;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -130,9 +130,9 @@ export class Table {
|
|||
return L.server;
|
||||
}
|
||||
|
||||
/** Puts Avatar `slot` of `p` in play on `at` (face up). */
|
||||
place(p: PlayerId, slot: number, at: LocId): AvatarRef {
|
||||
const av = this.s.players[p].avatars[slot - 1];
|
||||
/** Puts Anomaly `slot` of `p` in play on `at` (face up). */
|
||||
place(p: PlayerId, slot: number, at: LocId): AnomalyRef {
|
||||
const av = this.s.players[p].anomalies[slot - 1];
|
||||
av.faceUp = true;
|
||||
av.at = at;
|
||||
return { player: p, slot };
|
||||
|
|
@ -146,7 +146,7 @@ export class Table {
|
|||
|
||||
hardware(p: PlayerId, slot: number, name: string): number {
|
||||
const id = this.take(p, name);
|
||||
this.s.players[p].avatars[slot - 1].hardware.push(id);
|
||||
this.s.players[p].anomalies[slot - 1].hardware.push(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ export class Table {
|
|||
return this.act({ type: 'play', card, target, args, from });
|
||||
}
|
||||
|
||||
/** Activates the ability of the card `id` (an Avatar's card id, a Program or Hardware). */
|
||||
/** Activates the ability of the card `id` (an Anomaly's card id, a Program or Hardware). */
|
||||
use(id: number, args: Args = {}): this {
|
||||
return this.act({ type: 'activate', card: id, name: this.s.cards[id].name, args });
|
||||
}
|
||||
|
|
@ -220,8 +220,8 @@ export class Table {
|
|||
// -------------------------------------------------------------------------------------------
|
||||
// Reading
|
||||
|
||||
avatar(p: PlayerId, slot: number) {
|
||||
return avatar(this.s, { player: p, slot });
|
||||
anomaly(p: PlayerId, slot: number) {
|
||||
return anomaly(this.s, { player: p, slot });
|
||||
}
|
||||
|
||||
cores(p: PlayerId, slot: number): number {
|
||||
|
|
@ -239,6 +239,6 @@ export class Table {
|
|||
}
|
||||
|
||||
logText(): string {
|
||||
return (this.s.log ?? []).join('\n');
|
||||
return logFor(this.s, null).join('\n');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue