79 lines
4.3 KiB
TypeScript
79 lines
4.3 KiB
TypeScript
// DESIGN §2.1 starter decks (PR #18). Owner: engine-b.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
DEFAULT_DERIVATION, DEFAULT_RULESET, RULESET_V1_0, RULESET_V1_1, keywordFor, STARTER_DECKS, createMatch, starterDeckById, validateDeck,
|
|
} from '../shared/game/index.ts';
|
|
|
|
const countBy = (keys: string[]) => keys.reduce<Record<string, number>>((m, k) => ({ ...m, [k]: (m[k] ?? 0) + 1 }), {});
|
|
|
|
test('four starter decks, each with the frozen curve, 6+6 factions and 4 cards per home stat', () => {
|
|
assert.deepEqual(STARTER_DECKS.map(d => d.id), ['stargazers', 'field-guide', 'headliners', 'pioneers']);
|
|
for (const def of STARTER_DECKS) {
|
|
const deck = starterDeckById(def.id);
|
|
assert.deepEqual(deck.map(c => c.cost), [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6], def.id);
|
|
const factions = Object.values(countBy(deck.map(c => c.faction)));
|
|
assert.deepEqual(factions, [6, 6], `${def.id} factions`);
|
|
const homes = Object.values(countBy(deck.map(c => c.home)));
|
|
assert.deepEqual(homes, [4, 4, 4], `${def.id} homes`);
|
|
}
|
|
});
|
|
|
|
for (const [label, rules] of [['v1.0', RULESET_V1_0], ['v1.1', RULESET_V1_1]] as const)
|
|
test(`starter cards follow §10.1 and the power curve like owned cards (${label})`, () => {
|
|
for (const def of STARTER_DECKS) for (const card of starterDeckById(def.id, rules)) {
|
|
assert.equal(card.source, 'loaner');
|
|
assert.equal(card.rarity, 'Common');
|
|
assert.equal(card.trend, 0);
|
|
assert.match(card.cardId, /^loaner:[a-z0-9-]+$/);
|
|
if (card.cost === 1) { assert.deepEqual([card.keyword, card.power], [null, 2]); continue; }
|
|
const { keyword } = keywordFor(card.faction, card.cost, false, rules, card.home);
|
|
assert.equal(card.keyword, keyword);
|
|
assert.equal(card.power, rules.powerByCost[card.cost] + (rules.keywordParams[keyword!]?.powerDelta ?? 0));
|
|
}
|
|
});
|
|
|
|
test('all 6 factions covered; every starter card has a real pageId, catalog ones as in shared/catalog.ts', () => {
|
|
const all = STARTER_DECKS.flatMap(d => starterDeckById(d.id));
|
|
assert.equal(new Set(all.map(c => c.faction)).size, 6);
|
|
const ids = Object.fromEntries(all.map(c => [c.title, c.pageId]));
|
|
assert.deepEqual([ids.Moon, ids['Periodic table'], ids.Octopus, ids['Albert Einstein']], [19331, 23053, 22780, 736]);
|
|
for (const c of all) assert.ok(Number.isInteger(c.pageId) && c.pageId! > 0, `${c.title} has a real pageId`);
|
|
assert.equal(new Set(all.map(c => c.pageId)).size, all.length, 'no two starter cards share a pageId');
|
|
});
|
|
|
|
test('every starter deck passes engine deck validation and starts a match against every other', () => {
|
|
for (const a of STARTER_DECKS) {
|
|
assert.deepEqual(validateDeck(DEFAULT_RULESET, starterDeckById(a.id)), [], a.id);
|
|
for (const b of STARTER_DECKS) assert.doesNotThrow(() => createMatch(DEFAULT_RULESET, [starterDeckById(a.id), starterDeckById(b.id)], 1));
|
|
}
|
|
});
|
|
|
|
test('modes changing the curve change loaners too; unknown ids are rejected', () => {
|
|
const flat = starterDeckById('pioneers', { ...DEFAULT_DERIVATION, powerByCost: [0, 3, 3, 3, 3, 3, 3], vanillaBonus: 0 });
|
|
assert.ok(flat.every(c => c.power === 3));
|
|
assert.throws(() => starterDeckById('nope'), RangeError);
|
|
});
|
|
|
|
test('previewPool derives the frozen starter-cards.json loaners through §1', async () => {
|
|
const { previewPool, LOANER_SNAPSHOTS, CARD_SAMPLE_PERCENTILES, DEFAULT_RULESET, validateDeck } = await import('../shared/game/index.ts');
|
|
const pool = previewPool();
|
|
assert.equal(pool.length, LOANER_SNAPSHOTS.length);
|
|
assert.deepEqual(previewPool(), pool, 'deterministic');
|
|
for (const stat of ['attention', 'depth', 'reach'] as const) {
|
|
const cuts = CARD_SAMPLE_PERCENTILES[stat];
|
|
assert.equal(cuts.length, 99);
|
|
assert.ok(cuts.every((v, i) => i === 0 || v >= cuts[i - 1]), `${stat} cuts ascend`);
|
|
}
|
|
assert.equal(new Set(pool.map(c => c.cardId)).size, pool.length);
|
|
for (const c of pool) {
|
|
assert.equal(c.source, 'loaner');
|
|
assert.match(c.cardId, /^loaner:\d+$/);
|
|
assert.ok(c.cost >= 1 && c.cost <= 6);
|
|
const delta = c.keyword ? (DEFAULT_DERIVATION.keywordParams[c.keyword]?.powerDelta ?? 0) : 0;
|
|
assert.equal(c.power, DEFAULT_DERIVATION.powerByCost[c.cost] + (c.keyword === null && c.cost === 1 ? DEFAULT_DERIVATION.vanillaBonus : 0) + delta);
|
|
}
|
|
// 12 of them make a legal loaner deck.
|
|
assert.deepEqual(validateDeck(DEFAULT_RULESET, pool.slice(0, 12)), []);
|
|
});
|