updates
This commit is contained in:
parent
e590baf28d
commit
6382de19c9
15 changed files with 239 additions and 28 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { avatarCores, openWindow } from '../src/engine.ts';
|
||||
import { hasRoom } from '../src/query.ts';
|
||||
import { card } from './card.ts';
|
||||
import { Table, type Side } from './table.ts';
|
||||
|
||||
|
|
@ -37,6 +39,16 @@ card('Carbon NanoBots', () => {
|
|||
assert.equal(t.avatar(0, 1).hardware.length, 1);
|
||||
});
|
||||
|
||||
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, 5);
|
||||
fight(t);
|
||||
assert.ok(t.s.combat, 'North can Replicate, so the combat stops for a response');
|
||||
assert.ok(!hasRoom(t.s, 1, 'C1'));
|
||||
});
|
||||
|
||||
card('Corrupt Driver', () => {
|
||||
const t = scene('Corrupt Driver', 'Broken Bits', { north: { main: ['Additional Core'] } });
|
||||
const hw = t.hardware(1, 1, 'Additional Core');
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { randomDeck } from '../src/deck.ts';
|
|||
import { advanceTargets, avatarCores, createGame, legalActions, viewFor } from '../src/engine.ts';
|
||||
import { checkInvariants } from '../src/invariants.ts';
|
||||
import { makeRng } from '../src/rng.ts';
|
||||
import { DEFAULT_RULES } from '../src/rules.ts';
|
||||
import { DEFAULT_RULES, withRule } from '../src/rules.ts';
|
||||
import { Table } from './table.ts';
|
||||
|
||||
const pool = loadCards();
|
||||
|
|
@ -36,7 +36,7 @@ test('the first player skips the draw; the second player draws', () => {
|
|||
assert.equal(t.s.players[1].hand.length, 1);
|
||||
});
|
||||
|
||||
test('advancing captures an unowned location in step 5, pays its level and unlocks an Avatar', () => {
|
||||
test('advancing captures an unowned location in step 5 and pays 4 RAM; Lv 1 unlocks nothing', () => {
|
||||
const t = new Table();
|
||||
t.ram(0, 4);
|
||||
assert.deepEqual(advanceTargets(t.s, 0), ['A2']);
|
||||
|
|
@ -46,11 +46,59 @@ test('advancing captures an unowned location in step 5, pays its level and unloc
|
|||
t.end();
|
||||
assert.equal(t.s.locations.A2.owner, 0);
|
||||
assert.equal(t.avatar(0, 1).at, 'A2');
|
||||
assert.equal(t.s.players[0].ram, 8, '4 RAM + 4 for a Lv 2 capture');
|
||||
assert.equal(t.avatar(0, 2).faceUp, true, 'Lv 2 unlocks Avatar 2');
|
||||
assert.equal(t.s.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.s.step, 'playAgain');
|
||||
});
|
||||
|
||||
test('the second row (Lv 2) unlocks Avatar 2; the middle row (Lv 3) unlocks Avatars 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);
|
||||
}
|
||||
});
|
||||
|
||||
test('rule variants: a turn-1 capture can pay no RAM 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.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);
|
||||
});
|
||||
|
||||
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.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.to('playAgain');
|
||||
assert.ok(t.legal().some((a) => a.type === 'installHardware'), 'the second player can on turn 2');
|
||||
});
|
||||
|
||||
test('rule variants: the second player can start with extra cards and a location', () => {
|
||||
const rng = makeRng(5);
|
||||
const decks = [randomDeck(pool, rng, DEFAULT_RULES), randomDeck(pool, rng, DEFAULT_RULES)] as const;
|
||||
const rules = withRule(withRule(DEFAULT_RULES, 'secondPlayer.cards=2'), 'secondPlayer.locations=1');
|
||||
const s = createGame({ pool, decks: [decks[0], decks[1]], seed: 3, rules });
|
||||
const p2 = s.firstPlayer === 0 ? 1 : 0;
|
||||
assert.equal(s.players[p2].hand.length, s.players[s.firstPlayer].hand.length + 2);
|
||||
assert.equal(s.locations[p2 === 0 ? 'A2' : 'E2'].owner, p2);
|
||||
assert.equal(s.players[p2].serverPile.length, 18);
|
||||
assert.deepEqual(checkInvariants(s), []);
|
||||
});
|
||||
|
||||
test('placement closes once an advance is declared', () => {
|
||||
const t = new Table();
|
||||
t.go({ type: 'place', slot: 1, to: 'S1' }).go({ type: 'advance', slot: 1, to: 'A2' });
|
||||
|
|
|
|||
|
|
@ -16,10 +16,14 @@ test('random bots play 200 games with every card without breaking a rule', () =>
|
|||
});
|
||||
|
||||
test('greedy bots play 200 games without breaking a rule', () => {
|
||||
let wins = 0;
|
||||
for (let seed = 1; seed <= 200; seed++) {
|
||||
const s = playGame({ pool, bots: [() => greedyBot(), () => greedyBot()], seed, check: true });
|
||||
assert.equal(s.endReason, 'win');
|
||||
assert.ok(s.over);
|
||||
if (s.endReason === 'win') wins++;
|
||||
}
|
||||
// A rare game stalls: every location defended and no attack at good odds.
|
||||
assert.ok(wins >= 196, `only ${wins}/200 games ended in a win`);
|
||||
});
|
||||
|
||||
test('greedy beats random', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
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 { portsFree } from '../src/query.ts';
|
||||
|
|
@ -197,6 +198,31 @@ card('Hot-Swap Bay', () => {
|
|||
assert.equal(t.s.players[0].ram, 0, 'pays the 1 RAM difference');
|
||||
});
|
||||
|
||||
test('Hardware must still fit its ports when Network Interface Upgrade leaves', () => {
|
||||
const t = new Table({
|
||||
south: {
|
||||
avatars: ['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'],
|
||||
},
|
||||
});
|
||||
t.place(0, 1, 'S1');
|
||||
const niu = t.hardware(0, 1, 'Network Interface Upgrade');
|
||||
const hsb = t.hardware(0, 1, 'Hot-Swap Bay');
|
||||
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.
|
||||
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 === 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.ok(t.s.players[0].discard.includes(pa));
|
||||
});
|
||||
|
||||
card('Quantum Coprocessor', () => {
|
||||
const t = new Table({ south: { main: ['Quantum Coprocessor', 'Execute: Kill Process'] }, north: { main: ['Stack Overflow', 'Hotfix'] } });
|
||||
t.own(1, 'C1');
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd } from '../src/map
|
|||
|
||||
const RULES_MD = readFileSync(new URL('../../rules.md', import.meta.url), 'utf8');
|
||||
|
||||
test('24 lines, 20 of them with gateways', () => {
|
||||
assert.equal(LINES.length, 24);
|
||||
test('22 lines, 20 of them with gateways', () => {
|
||||
assert.equal(LINES.length, 22);
|
||||
assert.equal(LINES.filter((l) => l.gateway).length, 20);
|
||||
});
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ test('levels are mirrored between the players', () => {
|
|||
const mirror = (loc: string) => ({ A: 'E', B: 'D', C: 'C', D: 'B', E: 'A' })[loc[0]]! + loc[1];
|
||||
for (const loc of GRID) assert.equal(levelFor(0, loc), levelFor(1, mirror(loc)), loc);
|
||||
assert.equal(levelFor(0, 'S1'), 1);
|
||||
assert.equal(levelFor(0, 'A2'), 2);
|
||||
assert.equal(levelFor(0, 'A2'), 1);
|
||||
assert.equal(levelFor(0, 'B1'), 2);
|
||||
assert.equal(levelFor(0, 'C2'), 3);
|
||||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ function captureA2(server: string) {
|
|||
|
||||
card('High Efficiency RAM Server', () => {
|
||||
const t = captureA2('High Efficiency RAM Server');
|
||||
assert.equal(t.s.players[0].ram, 4 + 4, 'Lv 2 pays 4, the Server adds 4');
|
||||
assert.equal(t.s.players[0].ram, 4 + 4, 'the capture pays 4, the Server adds 4');
|
||||
});
|
||||
|
||||
card('Power Server', () => {
|
||||
|
|
@ -111,7 +111,7 @@ card('Duplicate Server', () => {
|
|||
assert.equal(t.s.choice?.kind, 'Duplicate Server:copy');
|
||||
t.choose(copy);
|
||||
if (check === 'cores') assert.equal(avatarCores(t.s, 0, 1, 'defend'), 8);
|
||||
else assert.equal(t.s.players[0].ram, 6 + 4, 'Lv 3 pays 6, the copied bonus 4');
|
||||
else assert.equal(t.s.players[0].ram, 4 + 4, 'the capture pays 4, the copied bonus 4');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue