forked from WikiDeck/wikideck
148 lines
6.3 KiB
TypeScript
148 lines
6.3 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { KEYWORDS, Rng, hiddenFrom, laneFaction, parseRuleset } from '../shared/game/index.ts';
|
|
import { card, cardPower, emptyBoard, endOfTurn, lanePower, place, reveal, testRules } from './game/build.ts';
|
|
|
|
test('every keyword has an id matching its key, a name and rules text', () => {
|
|
for (const [id, def] of Object.entries(KEYWORDS)) {
|
|
assert.equal(def.id, id);
|
|
assert.ok(def.name && def.text, `${id} needs name and text`);
|
|
}
|
|
});
|
|
|
|
test('the all-keywords test ruleset validates', () => {
|
|
assert.doesNotThrow(() => parseRuleset(testRules()));
|
|
});
|
|
|
|
test('Edition: +2 for each other copy of the same article on your side, any lane', () => {
|
|
const s = emptyBoard();
|
|
const a = place(s, 0, 0, card({ pageId: 42, power: 5, keyword: 'edition' }));
|
|
assert.equal(cardPower(s, a), 5);
|
|
const b = place(s, 0, 2, card({ pageId: 42, power: 5, keyword: 'edition' }));
|
|
assert.equal(cardPower(s, a), 7);
|
|
assert.equal(cardPower(s, b), 7);
|
|
place(s, 1, 0, card({ pageId: 42, power: 5 })); // the opponent's copy doesn't count
|
|
assert.equal(cardPower(s, a), 7);
|
|
});
|
|
|
|
test('Translated: +1 to your first card in each other lane that has one', () => {
|
|
const s = emptyBoard();
|
|
const left = place(s, 0, 0, card({ power: 2 }));
|
|
const leftSecond = place(s, 0, 0, card({ power: 2 }));
|
|
const enemy = place(s, 1, 2, card({ power: 2 }));
|
|
const t = reveal(s, 0, 1, card({ power: 4, keyword: 'translated' }));
|
|
assert.equal(left.bonus, 1);
|
|
assert.equal(leftSecond.bonus, 0);
|
|
assert.equal(enemy.bonus, 0);
|
|
assert.equal(t.bonus, 0);
|
|
});
|
|
|
|
test('Viral: adds a 1-power Mention token to a random other lane with space', () => {
|
|
const s = emptyBoard();
|
|
reveal(s, 0, 1, card({ keyword: 'viral' }), new Rng([9, 9, 9, 9]));
|
|
const tokens = s.lanes.flatMap((lane, index) => lane.cards[0].filter(c => c.card.meta?.token).map(c => ({ c, index })));
|
|
assert.equal(tokens.length, 1);
|
|
assert.notEqual(tokens[0].index, 1);
|
|
assert.equal(tokens[0].c.lane, tokens[0].index);
|
|
assert.equal(cardPower(s, tokens[0].c), 1);
|
|
});
|
|
|
|
test('Viral: deterministic for the same rng, and a no-op when no other lane has space', () => {
|
|
const run = () => { const s = emptyBoard(); reveal(s, 0, 1, card({ id: 'v', name: 'V', pageId: 1, keyword: 'viral' }), new Rng([5, 6, 7, 8])); return s.lanes; };
|
|
assert.deepEqual(run(), run());
|
|
const s = emptyBoard();
|
|
for (const lane of [0, 2]) for (let i = 0; i < s.ruleset.laneCapacity; i++) place(s, 0, lane, card());
|
|
const before = JSON.stringify(s.lanes);
|
|
reveal(s, 0, 1, card({ id: 'viral-full', keyword: 'viral' }));
|
|
s.lanes[1].cards[0].pop();
|
|
assert.equal(JSON.stringify(s.lanes), before);
|
|
});
|
|
|
|
test('Rising: +1 at each end of turn, capped at +3', () => {
|
|
const s = emptyBoard();
|
|
const r = place(s, 0, 1, card({ power: 3, keyword: 'rising' }));
|
|
const seen = [];
|
|
for (let i = 0; i < 5; i++) { endOfTurn(s, r); seen.push(cardPower(s, r)); }
|
|
assert.deepEqual(seen, [4, 5, 6, 6, 6]);
|
|
});
|
|
|
|
test('Rising: the cap counts only Rising gains, not other bonuses', () => {
|
|
const s = emptyBoard();
|
|
const r = place(s, 0, 1, card({ power: 3, keyword: 'rising' }));
|
|
r.bonus += 5; // e.g. Translated/Rally
|
|
for (let i = 0; i < 4; i++) endOfTurn(s, r);
|
|
assert.equal(cardPower(s, r), 11);
|
|
});
|
|
|
|
test('Nostalgic: +3 only when losing the lane, judged without itself (DESIGN example: 2 vs 8)', () => {
|
|
const s = emptyBoard();
|
|
place(s, 0, 1, card({ power: 2 }));
|
|
place(s, 1, 1, card({ power: 8 }));
|
|
const n = reveal(s, 0, 1, card({ power: 3, keyword: 'nostalgic' }));
|
|
assert.equal(cardPower(s, n), 6);
|
|
assert.deepEqual(lanePower(s, 1), [8, 8]);
|
|
});
|
|
|
|
test('Nostalgic: no bonus when tied or winning', () => {
|
|
const s = emptyBoard();
|
|
place(s, 0, 1, card({ power: 4 }));
|
|
place(s, 1, 1, card({ power: 4 }));
|
|
assert.equal(reveal(s, 0, 1, card({ power: 3, keyword: 'nostalgic' })).bonus, 0);
|
|
const t = emptyBoard();
|
|
assert.equal(reveal(t, 0, 1, card({ power: 3, keyword: 'nostalgic' })).bonus, 0); // 0 vs 0 is not losing
|
|
});
|
|
|
|
test('Encyclopedic: +2 when alone here; floors its own negative bonus', () => {
|
|
const s = emptyBoard();
|
|
const e = reveal(s, 0, 1, card({ power: 7, keyword: 'encyclopedic' }));
|
|
assert.equal(cardPower(s, e), 9);
|
|
place(s, 0, 2, card());
|
|
const f = (() => { place(s, 0, 2, card()); return reveal(s, 0, 2, card({ power: 7, keyword: 'encyclopedic' })); })();
|
|
assert.equal(cardPower(s, f), 7);
|
|
f.bonus = -4;
|
|
assert.equal(cardPower(s, f), 7);
|
|
});
|
|
|
|
test('Local: +2 only in a lane whose faction matches', () => {
|
|
const s = emptyBoard();
|
|
assert.equal(laneFaction(s, 0), 'Science');
|
|
assert.equal(laneFaction(s, 1), null);
|
|
const home = place(s, 0, 0, card({ power: 2, category: 'Science', keyword: 'local' }));
|
|
const away = place(s, 0, 1, card({ power: 2, category: 'Science', keyword: 'local' }));
|
|
const wrong = place(s, 0, 0, card({ power: 2, category: 'History', keyword: 'local' }));
|
|
assert.deepEqual([cardPower(s, home), cardPower(s, away), cardPower(s, wrong)], [4, 2, 2]);
|
|
});
|
|
|
|
test('laneFaction is null until the portal lane is revealed', () => {
|
|
const s = emptyBoard(testRules({ laneModifiers: { pool: [], revealTurns: [3, 1, 1], params: { portal: { categoryIndex: 3, amount: 0 } } } }));
|
|
assert.equal(laneFaction(s, 0), null);
|
|
s.turn = 3;
|
|
assert.equal(laneFaction(s, 0), 'Science');
|
|
});
|
|
|
|
test('Wildcard: takes the lane faction on reveal, and then counts for Local', () => {
|
|
const s = emptyBoard();
|
|
const w = reveal(s, 0, 0, card({ category: 'Culture', keyword: 'wildcard' }));
|
|
assert.equal(w.card.category, 'Science');
|
|
const plain = reveal(s, 0, 1, card({ category: 'Culture', keyword: 'wildcard' }));
|
|
assert.equal(plain.card.category, 'Culture');
|
|
});
|
|
|
|
test('Obscure: hidden from the opponent only, and only while the match runs', () => {
|
|
const s = emptyBoard();
|
|
const o = place(s, 0, 1, card({ keyword: 'obscure' }));
|
|
assert.equal(hiddenFrom(s, o, 1), true);
|
|
assert.equal(hiddenFrom(s, o, 0), false);
|
|
s.phase = 'over';
|
|
assert.equal(hiddenFrom(s, o, 1), false);
|
|
});
|
|
|
|
test('a keyword the ruleset does not enable has no effect', () => {
|
|
const s = emptyBoard(testRules({ keywords: {} }));
|
|
place(s, 0, 0, card({ pageId: 7, power: 5, keyword: 'edition' }));
|
|
const b = place(s, 0, 1, card({ pageId: 7, power: 5, keyword: 'edition' }));
|
|
assert.equal(cardPower(s, b), 5);
|
|
const o = place(s, 0, 2, card({ keyword: 'obscure' }));
|
|
assert.equal(hiddenFrom(s, o, 1), false);
|
|
});
|