87 lines
4.4 KiB
TypeScript
87 lines
4.4 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createGame, newPlayer, type Game } from '../game/engine';
|
|
import { acquireDuke, captureDuke, createDukeVidal, executeCapturedDuke, returnedDukeCapture } from '../game/duke-vidal';
|
|
import { ecazDukeRevivalBlock, EcazDukeRevivalError, quoteEcazDukeRevival } from '../game/ecaz-duke-revival';
|
|
|
|
/** A model quote with the real shared disc; no transaction or revival is run. */
|
|
function table(): Game {
|
|
const game = createGame('PLAINHARKONNENDUKEREVIVAL', newPlayer('e', 'Ecaz', 'ecaz'), true, ['ecaz']);
|
|
game.players.push(newPlayer('h', 'Harkonnen', 'harkonnen'), newPlayer('g', 'Guild', 'guild'));
|
|
game.status = 'playing'; game.turn = 3; game.phase = 4;
|
|
game.order = game.players.map(player => player.id);
|
|
game.dukeVidal = createDukeVidal();
|
|
game.dukeVidal.leader.dead = true; game.dukeVidal.leader.deaths = 1;
|
|
game.dukeCaptureUncertain = false;
|
|
return game;
|
|
}
|
|
|
|
void test('plain Advanced Ecaz/Harkonnen quotes the publicly dead shared Duke at five or discounted three without mutation', () => {
|
|
const game = table(), before = structuredClone(game);
|
|
const normal = quoteEcazDukeRevival(game, 'e', false);
|
|
const discounted = quoteEcazDukeRevival(game, 'e', true);
|
|
assert.equal(normal.leader, 'duke-vidal');
|
|
assert.equal(normal.normalCost, 5); assert.equal(normal.cost, 5);
|
|
assert.equal(discounted.normalCost, 5); assert.equal(discounted.cost, 3);
|
|
assert.equal(ecazDukeRevivalBlock(game, 'e'), null);
|
|
normal.duke.leader.deaths = 99;
|
|
assert.deepEqual(game, before, 'Reading or modifying the detached quote must not change the shared disc.');
|
|
});
|
|
|
|
void test('plain selected native faction decks preserve the original public-dead quote', () => {
|
|
const profiles: readonly (readonly ('ecaz'|'ix'|'choam')[])[] =
|
|
[['ecaz'], ['ecaz','ix'], ['ecaz','choam'], ['ecaz','ix','choam']];
|
|
for (const expansions of profiles) {
|
|
const game = table(); game.expansions = [...expansions];
|
|
if (expansions.includes('ix')) game.players.push(newPlayer('i', 'Ixians', 'ixians'));
|
|
if (expansions.includes('choam')) game.players.push(newPlayer('c', 'CHOAM', 'choam'));
|
|
game.order = game.players.map(player => player.id);
|
|
const before = structuredClone(game);
|
|
assert.equal(quoteEcazDukeRevival(game, 'e', false).cost, 5, expansions.join(','));
|
|
assert.deepEqual(game, before);
|
|
}
|
|
});
|
|
|
|
void test('a captive and an undisclosed execution controlled by a third faction remain equally unavailable to Ecaz', () => {
|
|
const game = table();
|
|
const held = acquireDuke(createDukeVidal(), 'g', game.turn, 'ecaz');
|
|
const captured = captureDuke(held, 'h', 'g', game.turn, 'arrakeen');
|
|
const executed = executeCapturedDuke(captured, 'h', game.turn);
|
|
assert.equal(returnedDukeCapture(executed), true);
|
|
const reasons: string[] = [];
|
|
for (const duke of [captured, executed]) {
|
|
const source = structuredClone(game); source.dukeVidal = duke;
|
|
source.dukeCaptureUncertain = true;
|
|
const before = structuredClone(source), reason = ecazDukeRevivalBlock(source, 'e');
|
|
assert.ok(reason); reasons.push(reason);
|
|
assert.throws(() => quoteEcazDukeRevival(source, 'e', false), EcazDukeRevivalError);
|
|
assert.deepEqual(source, before);
|
|
}
|
|
assert.equal(reasons[0], reasons[1], 'The denied quote must not disclose a concealed execution.');
|
|
});
|
|
|
|
void test('Ecaz as the original concealed controller may use the known returned-Duke quote', () => {
|
|
const game = table(), held = acquireDuke(createDukeVidal(), 'e', game.turn, 'ecaz');
|
|
game.dukeVidal = executeCapturedDuke(captureDuke(held, 'h', 'e', game.turn, 'arrakeen'), 'h', game.turn);
|
|
game.dukeCaptureUncertain = true;
|
|
const before = structuredClone(game);
|
|
assert.equal(returnedDukeCapture(game.dukeVidal), true);
|
|
assert.equal(quoteEcazDukeRevival(game, 'e', false).cost, 5);
|
|
assert.deepEqual(game, before);
|
|
});
|
|
|
|
void test('plain admission does not silently admit unrelated optional overlays', () => {
|
|
for (const mutate of [
|
|
(game: Game) => { game.leaderSkills = {} as NonNullable<Game['leaderSkills']>; },
|
|
(game: Game) => { game.homeworlds = {custody:null}; },
|
|
(game: Game) => { game.semutaPreview = true; },
|
|
(game: Game) => { game.kullPreview = true; },
|
|
(game: Game) => { game.advancedPreview = true; },
|
|
]) {
|
|
const game = table(); mutate(game);
|
|
const before = structuredClone(game);
|
|
assert.throws(() => quoteEcazDukeRevival(game, 'e', false), EcazDukeRevivalError);
|
|
assert.deepEqual(game, before);
|
|
}
|
|
});
|