This commit is contained in:
Forrest 2026-10-01 17:20:33 -04:00
parent 5368464042
commit 937f44defe
100 changed files with 10185 additions and 2042 deletions

View file

@ -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++) {