updates
This commit is contained in:
parent
e590baf28d
commit
6382de19c9
15 changed files with 239 additions and 28 deletions
|
|
@ -12,6 +12,7 @@ cd sim
|
|||
npm run sim -- -n 5000 # 5,000 greedy-vs-greedy games
|
||||
npm run sim -- -n 5000 --card-report # plus how each card did
|
||||
npm run sim -- --south greedy --north nocards # does playing cards help?
|
||||
npm run sim -- --rule secondPlayer.cards=2 # try a rule variant (see src/rules.ts)
|
||||
npm run sim -- --log --seed 7 # watch one game, play by play
|
||||
npm run sim -- --json out/run.json # also save every game's result
|
||||
npm run sim -- --help # all options and bots
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import {
|
|||
wearerOf,
|
||||
} from '../state.ts';
|
||||
import { FOREVER, type AvatarRef, type GameState, type PlayerId, type Task } from '../types.ts';
|
||||
import { shedHardware } from './hardware.ts';
|
||||
import { cardOptions, ghostsOf, mine, programsOn, scopeOf, subsets } from './util.ts';
|
||||
|
||||
const liveCombat = (s: GameState) => (s.combat && !s.combat.ended ? s.combat : null);
|
||||
|
|
@ -130,6 +131,7 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
toDiscard(s, hw);
|
||||
stat(s, 'hardwareLost', owner.player);
|
||||
say(s, `Sabotage destroys ${nameOf(s, hw)}.`);
|
||||
shedHardware(s, owner);
|
||||
} else {
|
||||
s.cards[hw].disabledUntil = FOREVER;
|
||||
say(s, `Sabotage disables ${nameOf(s, hw)}.`);
|
||||
|
|
@ -311,10 +313,12 @@ export const EXECUTIONS: Record<string, Script> = {
|
|||
targetsAvatars: (s, item) => wearerList(s, item.args.card),
|
||||
resolve(s, item) {
|
||||
const card = item.args.card!;
|
||||
const wearer = wearerOf(s, card);
|
||||
if (!uninstallProgram(s, card) && !uninstallHardware(s, card)) return;
|
||||
toHand(s, card);
|
||||
fired(s, item.name, item.player);
|
||||
say(s, `Rollback returns ${nameOf(s, card)} to ${playerName(ownerOf(s, card))}'s hand.`);
|
||||
if (wearer) shedHardware(s, wearer);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* wearer stands on.
|
||||
*/
|
||||
import { knockOut } from '../flow.ts';
|
||||
import { desynced, hardwareActive } from '../query.ts';
|
||||
import { desynced, hardwareActive, portsFit, takesPort } from '../query.ts';
|
||||
import { scriptOf, type Script } from '../scripts.ts';
|
||||
import {
|
||||
ask,
|
||||
|
|
@ -24,6 +24,7 @@ import {
|
|||
startOf,
|
||||
endOf,
|
||||
stat,
|
||||
toDiscard,
|
||||
toHand,
|
||||
uninstallHardware,
|
||||
usedThisTurn,
|
||||
|
|
@ -53,6 +54,20 @@ function coolerFor(s: GameState, hw: number): number | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reading: an Avatar that loses a port (Network Interface Upgrade removed) discards Hardware until it
|
||||
* fits, the most recently installed first.
|
||||
*/
|
||||
export function shedHardware(s: GameState, r: AvatarRef): void {
|
||||
while (!portsFit(s, r)) {
|
||||
const hw = avatar(s, r).hardware.findLast((id) => takesPort(s, id))!;
|
||||
uninstallHardware(s, hw);
|
||||
toDiscard(s, hw);
|
||||
stat(s, 'hardwareLost', r.player);
|
||||
say(s, `${avatarName(s, r)} is out of ports and discards ${nameOf(s, hw)}.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function useHardware(s: GameState, hw: number): void {
|
||||
const cooler = coolerFor(s, hw);
|
||||
markUsed(s, `hw:${hw}`);
|
||||
|
|
@ -271,7 +286,9 @@ export const HARDWARE: Record<string, Script> = {
|
|||
uses(s, src) {
|
||||
const av = avatar(s, src.ref!);
|
||||
const hand = s.players[src.controller].hand.filter((id) => defOf(s, id).kind === 'hardware');
|
||||
return av.hardware.flatMap((out) => cardOptions(s, hand).map((o) => ({ card: out, cards: [o.value as number] })));
|
||||
return av.hardware.flatMap((out) => cardOptions(s, hand)
|
||||
.filter((o) => portsFit(s, src.ref!, out, o.value as number))
|
||||
.map((o) => ({ card: out, cards: [o.value as number] })));
|
||||
},
|
||||
extraCost: (s, _src, args) => Math.max(0, defOf(s, args.cards![0]).ram - defOf(s, args.card!).ram),
|
||||
resolve(s, item, src) {
|
||||
|
|
@ -279,6 +296,7 @@ export const HARDWARE: Record<string, Script> = {
|
|||
const into = item.args.cards![0];
|
||||
const ref = src.ref!;
|
||||
if (!avatar(s, ref).hardware.includes(out) || !s.players[src.controller].hand.includes(into)) return;
|
||||
if (!portsFit(s, ref, out, into)) return;
|
||||
uninstallHardware(s, out);
|
||||
toHand(s, out);
|
||||
attachHardware(s, into, ref);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { DEFAULT_GREEDY, greedyBot } from './bots/greedy.ts';
|
|||
import { randomBot } from './bots/random.ts';
|
||||
import { DEFAULT_CARDS_CSV, loadCards, type CardKind } from './cards.ts';
|
||||
import { playGame } from './play.ts';
|
||||
import { DEFAULT_RULES } from './rules.ts';
|
||||
import { DEFAULT_RULES, withRule } from './rules.ts';
|
||||
import { isImplemented, staleScripts } from './scripts.ts';
|
||||
import { cardReport, formatCardReport, formatSummary, recordOf, summarize, type GameRecord } from './stats.ts';
|
||||
import { PLAYER_NAMES } from './types.ts';
|
||||
|
|
@ -30,6 +30,11 @@ const USAGE = `Files TCG simulator
|
|||
--south BOT South's bot (default greedy)
|
||||
--north BOT North's bot (default greedy)
|
||||
--max-turns N player turns before a draw (default ${DEFAULT_RULES.maxTurns})
|
||||
--rule K=V change a rule in src/rules.ts; repeatable. Examples: winLocations=9,
|
||||
levelRam=4,4,6,8,10, startingAvatars=4, firstTurn.advance=false,
|
||||
firstTurn.captureRam=false, firstTurn.unlock=false, firstTurn.cards=false,
|
||||
secondPlayer.ram=4, secondPlayer.avatars=1, secondPlayer.cards=2,
|
||||
secondPlayer.locations=1
|
||||
--log play one game and print the play-by-play
|
||||
--check check rule invariants after every action (slow)
|
||||
--json FILE also write the summary and every game's result as JSON
|
||||
|
|
@ -47,6 +52,7 @@ const { values: opt } = parseArgs({
|
|||
south: { type: 'string', default: 'greedy' },
|
||||
north: { type: 'string', default: 'greedy' },
|
||||
'max-turns': { type: 'string' },
|
||||
rule: { type: 'string', multiple: true, default: [] },
|
||||
log: { type: 'boolean', default: false },
|
||||
check: { type: 'boolean', default: false },
|
||||
json: { type: 'string' },
|
||||
|
|
@ -81,7 +87,14 @@ const seed = count('seed', opt.seed)!;
|
|||
const maxTurns = count('max-turns', opt['max-turns']);
|
||||
|
||||
const pool = loadCards(opt.cards);
|
||||
const rules = maxTurns === undefined ? DEFAULT_RULES : { ...DEFAULT_RULES, maxTurns };
|
||||
let rules = maxTurns === undefined ? DEFAULT_RULES : { ...DEFAULT_RULES, maxTurns };
|
||||
try {
|
||||
for (const spec of opt.rule) rules = withRule(rules, spec);
|
||||
} catch (e) {
|
||||
console.error((e as Error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
if (opt.rule.length) console.log(`Rules changed: ${opt.rule.join(', ')}`);
|
||||
const bots: [BotFactory, BotFactory] = [BOTS[opt.south].make, BOTS[opt.north].make];
|
||||
|
||||
for (const warning of staleScripts(pool)) console.warn(`warning: ${warning}`);
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
discard: [],
|
||||
serverPile: shuffle(rng, deck.servers.map((n) => add(n, p))),
|
||||
avatars: [
|
||||
...avatars.map((card, i) => newAvatar(card, i === 0, null)),
|
||||
...avatars.map((card, i) => newAvatar(card, i < rules.startingAvatars, null)),
|
||||
...avatars.map((card, i) => newAvatar(card, false, i + 1)),
|
||||
],
|
||||
unlockedLevel: 1,
|
||||
|
|
@ -202,9 +202,22 @@ export function createGame({ pool, decks, seed, rules = DEFAULT_RULES, log = fal
|
|||
for (let i = 0; i < rules.openingHand; i++) drawNow(s, p);
|
||||
say(s, `${playerName(p)} starts on ${nameOf(s, server)} with ${me.ram} RAM. Avatar 1: ${nameOf(s, me.avatars[0].card)}.`);
|
||||
}
|
||||
s.stats.cardsDrawn = [0, 0];
|
||||
s.firstPlayer = randInt(rng, 2) as PlayerId;
|
||||
s.active = s.firstPlayer;
|
||||
const p2 = other(s.firstPlayer);
|
||||
const second = s.players[p2];
|
||||
second.ram += rules.secondPlayer.ram;
|
||||
second.avatars.slice(0, rules.startingAvatars + rules.secondPlayer.avatars).forEach((av) => (av.faceUp = true));
|
||||
for (let i = 0; i < rules.secondPlayer.cards; i++) drawNow(s, p2);
|
||||
if (rules.secondPlayer.locations > 0) {
|
||||
// The location next to the starting Server, with a Server from the pile: no RAM, no unlock.
|
||||
const line = LINES_AT.get(START_LOC[p2])![0];
|
||||
const L = s.locations[otherEnd(line, START_LOC[p2])];
|
||||
L.owner = p2;
|
||||
L.server = second.serverPile.shift()!;
|
||||
played(s, s.cards[L.server].name, p2);
|
||||
}
|
||||
s.stats.cardsDrawn = [0, 0];
|
||||
say(s, `${playerName(s.firstPlayer)} goes first.`);
|
||||
beginTurn(s, true);
|
||||
run(s);
|
||||
|
|
@ -326,6 +339,11 @@ function pushClears(s: GameState, p: PlayerId, out: Action[]): void {
|
|||
}
|
||||
|
||||
/** Latency Spike: the attacking player can't play Executions before the roll. */
|
||||
/** Whether a first-turn rule variant stops p playing cards from hand right now. */
|
||||
function cardsBlocked(s: GameState, p: PlayerId): boolean {
|
||||
return s.turn === 1 && p === s.firstPlayer && !s.rules.firstTurn.cards;
|
||||
}
|
||||
|
||||
function latencyBlocked(s: GameState, p: PlayerId): boolean {
|
||||
const c = s.combat;
|
||||
const w = openWindow(s);
|
||||
|
|
@ -375,7 +393,7 @@ export function executionCost(s: GameState, p: PlayerId, card: number, target: L
|
|||
*/
|
||||
export function executionActions(s: GameState, p: PlayerId, budget: 'now' | 'reachable' | 'any', limit = Infinity): Action[] {
|
||||
const out: Action[] = [];
|
||||
if (latencyBlocked(s, p)) return out;
|
||||
if (latencyBlocked(s, p) || cardsBlocked(s, p)) return out;
|
||||
const seen = new Set<string>();
|
||||
let who: (LocId | null)[] | null = null;
|
||||
let all: Source[] | null = null;
|
||||
|
|
@ -484,7 +502,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
|
||||
if (s.step === 'deploy') {
|
||||
const placementOpen = s.declarations.length === 0;
|
||||
const targets = advanceTargets(s, p);
|
||||
const targets = s.turn === 1 && !s.rules.firstTurn.advance ? [] : advanceTargets(s, p);
|
||||
me.avatars.forEach((av, i) => {
|
||||
const ref = { player: p, slot: i + 1 };
|
||||
if (!av.faceUp || av.advanced || av.attacks > 0) return;
|
||||
|
|
@ -503,7 +521,7 @@ export function legalActions(s: GameState): Action[] {
|
|||
} else {
|
||||
const seen = new Set<string>();
|
||||
const all = sources(s);
|
||||
for (const card of me.hand) {
|
||||
for (const card of cardsBlocked(s, p) ? [] : me.hand) {
|
||||
const def = defOf(s, card);
|
||||
if (seen.has(def.name)) continue;
|
||||
seen.add(def.name);
|
||||
|
|
|
|||
|
|
@ -374,13 +374,15 @@ export function captureMain(s: GameState, ref: AvatarRef, loc: LocId, how: Captu
|
|||
avatar(s, ref).at = loc;
|
||||
|
||||
const level = levelFor(p, loc);
|
||||
const turn1 = s.turn === 1 ? s.rules.firstTurn : null;
|
||||
const bonus = L.server === null ? 0 : (scriptOf(s.cards[L.server].name)?.ramOnPlace ?? 0);
|
||||
gainRam(s, p, s.rules.levelRam[level] + bonus, 'ramFromCaptures');
|
||||
const ram = (turn1?.captureRam === false ? 0 : s.rules.levelRam[level]) + bonus;
|
||||
gainRam(s, p, ram, 'ramFromCaptures');
|
||||
stat(s, how, p);
|
||||
const from = previous === null ? '' : ` from ${playerName(previous)}`;
|
||||
say(s, `${playerName(p)} captures ${loc}${from} (Lv ${level}) with ${L.server === null ? 'no Server' : nameOf(s, L.server)}: +${s.rules.levelRam[level] + bonus} RAM (now ${me.ram}).`);
|
||||
say(s, `${playerName(p)} captures ${loc}${from} (Lv ${level}) with ${L.server === null ? 'no Server' : nameOf(s, L.server)}: +${ram} RAM (now ${me.ram}).`);
|
||||
|
||||
if (level > me.unlockedLevel) {
|
||||
if (level > me.unlockedLevel && turn1?.unlock !== false) {
|
||||
me.unlockedLevel = level;
|
||||
me.avatars.slice(0, 4).forEach((av, i) => {
|
||||
if (i < level && !av.faceUp) {
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@ const LINE_DEFS: [LocId, LocId, boolean][] = [
|
|||
['S1', 'A2', false],
|
||||
['A1', 'A2', true], ['A2', 'A3', true],
|
||||
['A1', 'B1', true], ['A2', 'B1', true], ['A2', 'B2', true], ['A3', 'B2', true],
|
||||
['A2', 'C2', false],
|
||||
['B1', 'C1', true], ['B1', 'C2', true], ['B2', 'C2', true], ['B2', 'C3', true],
|
||||
['C1', 'D1', true], ['C2', 'D1', true], ['C2', 'D2', true], ['C3', 'D2', true],
|
||||
['C2', 'E2', false],
|
||||
['D1', 'E1', true], ['D1', 'E2', true], ['D2', 'E2', true], ['D2', 'E3', true],
|
||||
['E1', 'E2', true], ['E2', 'E3', true],
|
||||
['S2', 'E2', false],
|
||||
|
|
@ -47,10 +45,10 @@ export const otherEnd = (line: Line, loc: LocId): LocId => (line.a === loc ? lin
|
|||
|
||||
export const isStart = (loc: LocId): boolean => loc === START_LOC[0] || loc === START_LOC[1];
|
||||
|
||||
/** Level by row letter, from each player's side of the mat. */
|
||||
/** Level by row letter, from each player's side of the mat: your first row is Lv 1, the far row Lv 5. */
|
||||
const LEVEL_BY_ROW: readonly [Record<string, number>, Record<string, number>] = [
|
||||
{ A: 2, B: 2, C: 3, D: 4, E: 5 },
|
||||
{ A: 5, B: 4, C: 3, D: 2, E: 2 },
|
||||
{ A: 1, B: 2, C: 3, D: 4, E: 5 },
|
||||
{ A: 5, B: 4, C: 3, D: 2, E: 1 },
|
||||
];
|
||||
|
||||
/** A location's level for the player capturing it. Your own start is Lv 1. */
|
||||
|
|
|
|||
|
|
@ -95,6 +95,8 @@ export function capacity(s: GameState, loc: LocId): number {
|
|||
/** Whether `p` can put another Avatar on `loc`. */
|
||||
export function hasRoom(s: GameState, p: PlayerId, loc: LocId): boolean {
|
||||
if (!controls(s, p, loc)) return false;
|
||||
// Nothing enters a location mid-combat (a copy, or an Avatar moved by Disconnect).
|
||||
if (s.combat && !s.combat.ended && s.combat.loc === loc) return false;
|
||||
return refsInPlay(s, p).filter((r) => avatar(s, r).at === loc).length < capacity(s, loc);
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +124,18 @@ export const portsTotal = (s: GameState, r: AvatarRef): number =>
|
|||
|
||||
export const portsFree = (s: GameState, r: AvatarRef): number => portsTotal(s, r) - portsUsed(s, r);
|
||||
|
||||
/** Whether a Hardware takes a port: Network Interface Upgrade and Hardware pushed on over the limit don't. */
|
||||
export const takesPort = (s: GameState, id: number): boolean =>
|
||||
!scriptOf(s.cards[id].name)?.noPort && s.cards[id].pushedUntil === undefined;
|
||||
|
||||
/** Whether an Avatar's Hardware fits its ports, with `out` taken off and `into` put on. */
|
||||
export function portsFit(s: GameState, r: AvatarRef, out: number | null = null, into: number | null = null): boolean {
|
||||
const hw = avatar(s, r).hardware.filter((id) => id !== out);
|
||||
if (into !== null) hw.push(into);
|
||||
const total = defOf(s, avatar(s, r).card).slots + hw.reduce((t, id) => t + (scriptOf(s.cards[id].name)?.extraSlots ?? 0), 0);
|
||||
return hw.filter((id) => takesPort(s, id)).length <= total;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Cores
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,23 @@ export interface RulesConfig {
|
|||
firewallCost: readonly number[];
|
||||
maxProgramsPerLocation: number;
|
||||
deck: { avatars: number; servers: number; main: number; maxCopies: number };
|
||||
/** Avatars face up at the start (rules: Avatar 1 only). */
|
||||
startingAvatars: number;
|
||||
/** What the first player may do on turn 1 (the rules allow everything). */
|
||||
firstTurn: {
|
||||
advance: boolean;
|
||||
/** Captures pay capture RAM. A Server card's own RAM bonus is still paid. */
|
||||
captureRam: boolean;
|
||||
/** Captures unlock Avatars. They unlock on a later capture instead. */
|
||||
unlock: boolean;
|
||||
/** Playing cards from hand: Hardware, Programs, Executions. */
|
||||
cards: boolean;
|
||||
};
|
||||
/**
|
||||
* Catch-up for whoever goes second: extra starting RAM, extra Avatars face up, extra cards in the
|
||||
* opening hand, and (0 or 1) owning the location next to their starting Server at the start.
|
||||
*/
|
||||
secondPlayer: { ram: number; avatars: number; cards: number; locations: number };
|
||||
}
|
||||
|
||||
export const DEFAULT_RULES: RulesConfig = {
|
||||
|
|
@ -22,8 +39,44 @@ export const DEFAULT_RULES: RulesConfig = {
|
|||
openingHand: 7,
|
||||
winLocations: 10,
|
||||
maxTurns: 200,
|
||||
levelRam: { 1: 4, 2: 4, 3: 6, 4: 8, 5: 10 },
|
||||
levelRam: { 1: 4, 2: 4, 3: 4, 4: 4, 5: 4 },
|
||||
firewallCost: [2, 4, 8],
|
||||
maxProgramsPerLocation: 2,
|
||||
deck: { avatars: 4, servers: 20, main: 30, maxCopies: 2 },
|
||||
startingAvatars: 1,
|
||||
firstTurn: { advance: true, captureRam: true, unlock: true, cards: true },
|
||||
secondPlayer: { ram: 0, avatars: 0, cards: 0, locations: 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* A copy of `rules` with one setting changed, from text like "winLocations=9",
|
||||
* "secondPlayer.ram=4", "firstTurn.advance=false" or "levelRam=4,4,4,4,4" (Lv 1 to 5).
|
||||
*/
|
||||
export function withRule(rules: RulesConfig, spec: string): RulesConfig {
|
||||
const m = spec.match(/^([\w.]+)=(.+)$/);
|
||||
if (!m) throw new Error(`Rule "${spec}" should look like name=value`);
|
||||
const [, key, raw] = m;
|
||||
const next = structuredClone(rules) as unknown as Record<string, unknown>;
|
||||
const path = key.split('.');
|
||||
let obj = next;
|
||||
for (const part of path.slice(0, -1)) {
|
||||
if (typeof obj[part] !== 'object' || obj[part] === null) throw new Error(`Unknown rule "${key}"`);
|
||||
obj = obj[part] as Record<string, unknown>;
|
||||
}
|
||||
const last = path[path.length - 1];
|
||||
const old = obj[last];
|
||||
const num = (x: string) => {
|
||||
const n = Number(x);
|
||||
if (!Number.isFinite(n)) throw new Error(`Rule "${key}" needs numbers, got "${x}"`);
|
||||
return n;
|
||||
};
|
||||
if (typeof old === 'number') obj[last] = num(raw);
|
||||
else if (typeof old === 'boolean') {
|
||||
if (raw !== 'true' && raw !== 'false') throw new Error(`Rule "${key}" needs true or false`);
|
||||
obj[last] = raw === 'true';
|
||||
} else if (key === 'levelRam') {
|
||||
obj[last] = Object.fromEntries(raw.split(',').map((x, i) => [i + 1, num(x)]));
|
||||
} else if (Array.isArray(old)) obj[last] = raw.split(',').map(num);
|
||||
else throw new Error(`Unknown rule "${key}"`);
|
||||
return next as unknown as RulesConfig;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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