Enable Ecaz Duke revival with Advanced Harkonnen
Verify and publish checkpoint container / container (push) Successful in 11m23s

This commit is contained in:
Quintine committed 2026-11-16 16:02:54 +11:00
1 parent ecd892b368
commit 88240e2cea
8 files changed
+287 -3

No files matched your search

@@ -0,0 +1,86 @@
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);
}
});
@@ -0,0 +1,156 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { registerHooks } from 'node:module';
import { readFileSync } from 'node:fs';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { acquireDuke, captureDuke, createDukeVidal, DUKE_VIDAL_ID, executeCapturedDuke } from '../game/duke-vidal';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { actDukeAmbassador as act, advanceDukeAmbassador as advance, dukeAmbassadorClean as clean } from './fixture-duke-ambassador';
const aliases = registerHooks({
resolve(specifier,context,next) {
return next(specifier === 'next/image' ? 'vinext/shims/image' : specifier === 'next/link' ? 'vinext/shims/link' : specifier,context);
},
load(url,context,next) {
if (!url.endsWith('.module.css')) return next(url,context);
const css = readFileSync(new URL(url),'utf8');
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1],match[1]]));
return {format:'module',source:`export default ${JSON.stringify(classes)}`,shortCircuit:true};
},
});
const { GameTable } = await import('../components/game-table');
aliases.deregister();
const seat = (game: Game, id: string) => {
const player = game.players.find(row => row.id === id); assert.ok(player); return player;
};
/** Genuine public Advanced E3 setup and ordered Revival. Only unopened Spice
* positions are selected; the public dead shared disc is explicitly staged. */
function nativeRevival() {
let game = createGame('PLAINADVANCEDDUKEREVIVAL',newPlayer('ecaz','Ecaz','ecaz'),true,['ecaz']);
for (const faction of ['harkonnen','guild'] as const) joinGame(game,newPlayer(faction,faction,faction));
for (const player of game.players) game = act(game,player.id,{type:'ready'});
game = act(game,'ecaz',{type:'start',advancedPreview:true});
game = advance(game,state => state.status === 'playing');
for (const position of [0,1]) {
const index = game.spiceDeck.findIndex((card,i) => i >= position && 'territory' in card && !card.discovery);
assert.ok(index >= position);
[game.spiceDeck[position],game.spiceDeck[index]] = [game.spiceDeck[index],game.spiceDeck[position]];
}
game = advance(game,state => state.phase === 4 && clean(state) && state.revivalOrder?.remaining[0] === 'ecaz');
assert.ok(game.dukeVidal);
assert.equal(game.dukeVidal.leader.dead,false);
assert.equal(game.dukeVidal.controller,null);
game.dukeVidal.leader.dead = true;
game.dukeVidal.leader.deaths = 1;
assert.ok(seat(game,'ecaz').spice >= 5);
return game;
}
let cached: Game | undefined;
const fixture = () => structuredClone(cached ??= nativeRevival());
function giveGhola(game: Game) {
const owner = seat(game,'ecaz');
if (owner.hand.some(card => card.effect === 'ghola')) return;
for (const zone of [game.deck,game.discard,...game.players.filter(player => player.id !== owner.id).map(player => player.hand)]) {
const index = zone.findIndex(card => card.effect === 'ghola');
if (index < 0) continue;
const [ghola] = zone.splice(index,1);
const displaced = owner.hand.pop();
if (displaced) zone.push(displaced);
owner.hand.push(ghola);
return;
}
throw Error('The native physical Ghola card was not found.');
}
void test('public dead Duke is offered and revived for five in a plain Advanced Harkonnen table', () => {
const game = fixture(), before = seat(game,'ecaz').spice;
const option = viewGame(game,'ecaz').revival.leaders.find(leader => leader.id === DUKE_VIDAL_ID);
assert.ok(option); assert.equal(option.cost,5); assert.equal(option.affordable,true);
const after = act(game,'ecaz',{type:'reviveLeader',leader:DUKE_VIDAL_ID});
assert.equal(seat(after,'ecaz').spice,before - 5);
assert.equal(after.dukeVidal!.leader.dead,false);
assert.equal(after.dukeVidal!.controller,null);
assert.ok(after.players.every(player => player.leaders.every(leader => leader.id !== DUKE_VIDAL_ID)));
});
void test('the real table renders the public Duke and five-spice revival choice', () => {
const game = fixture();
const html = renderToStaticMarkup(createElement(GameTable,{
game:viewGame(game,'ecaz'), busy:false, send:async () => {}, onExit() {},
}));
assert.match(html,/Duke Prad Vidal/);
assert.match(html,/5 spice/);
assert.match(html,/Revive leader/);
});
void test('Ecaz can use the real Ghola card on the same publicly dead Duke', () => {
const game = fixture(); giveGhola(game);
const card = seat(game,'ecaz').hand.find(row => row.effect === 'ghola'); assert.ok(card);
assert.ok(viewGame(game,'ecaz').ghola.leaders.some(leader => leader.id === DUKE_VIDAL_ID));
const before = seat(game,'ecaz').spice;
const after = act(game,'ecaz',{type:'card',card:card.id,leader:DUKE_VIDAL_ID});
assert.equal(after.dukeVidal!.leader.dead,false);
assert.equal(seat(after,'ecaz').spice,before);
assert.equal(after.discard.filter(row => row.id === card.id).length,1);
});
void test('all four bot profiles receive a legal native Duke return', () => {
for (const difficulty of DIFFICULTIES) {
const game = fixture(); seat(game,'ecaz').bot = difficulty;
const action = botActions(viewGame(game,'ecaz')).find(row => row.type === 'reviveLeader' && row.leader === DUKE_VIDAL_ID);
assert.ok(action,difficulty);
const after = act(game,'ecaz',action);
assert.equal(after.dukeVidal!.leader.dead,false);
}
});
function concealed(controller: 'guild' | 'ecaz') {
const alive = fixture();
const living = acquireDuke(createDukeVidal(),controller,alive.turn,'ecaz');
alive.dukeVidal = captureDuke(living,'harkonnen',controller,alive.turn,'arrakeen');
alive.dukeCaptureUncertain = true;
const executed = structuredClone(alive);
executed.dukeVidal = executeCapturedDuke(executed.dukeVidal!,'harkonnen',executed.turn);
giveGhola(alive); giveGhola(executed);
return {alive,executed};
}
void test('a foreign controller’s secret capture or execution gives Ecaz identical public revival options', () => {
const {alive,executed} = concealed('guild');
const before = viewGame(alive,'ecaz'), after = viewGame(executed,'ecaz');
assert.deepEqual(before.dukeVidal,after.dukeVidal);
assert.deepEqual(before.revival,after.revival);
assert.deepEqual(before.ghola,after.ghola);
assert.ok(!after.revival.leaders.some(leader => leader.id === DUKE_VIDAL_ID));
assert.ok(!after.ghola.leaders.some(leader => leader.id === DUKE_VIDAL_ID));
for (const game of [alive,executed]) {
const snapshot = structuredClone(game);
assert.throws(() => act(game,'ecaz',{type:'reviveLeader',leader:DUKE_VIDAL_ID}));
assert.deepEqual(game,snapshot);
const card = seat(game,'ecaz').hand.find(row => row.effect === 'ghola'); assert.ok(card);
assert.throws(() => act(game,'ecaz',{type:'card',card:card.id,leader:DUKE_VIDAL_ID}));
assert.deepEqual(game,snapshot);
}
});
void test('Ecaz may revive a secretly executed Duke when Ecaz was its informed original controller', () => {
const {executed} = concealed('ecaz');
const before = seat(executed,'ecaz').spice;
assert.ok(viewGame(executed,'ecaz').revival.leaders.some(leader => leader.id === DUKE_VIDAL_ID));
const gholaGame = structuredClone(executed);
const card = seat(gholaGame,'ecaz').hand.find(row => row.effect === 'ghola'); assert.ok(card);
assert.ok(viewGame(gholaGame,'ecaz').ghola.leaders.some(leader => leader.id === DUKE_VIDAL_ID));
const ghola = act(gholaGame,'ecaz',{type:'card',card:card.id,leader:DUKE_VIDAL_ID});
assert.equal(ghola.dukeVidal!.leader.dead,false);
assert.equal(seat(ghola,'ecaz').spice,before);
assert.equal(ghola.discard.filter(row => row.id === card.id).length,1);
const after = act(executed,'ecaz',{type:'reviveLeader',leader:DUKE_VIDAL_ID});
assert.equal(after.dukeVidal!.leader.dead,false);
assert.equal(seat(after,'ecaz').spice,before - 5);
});
+3 -1
View File
@@ -339,11 +339,13 @@ void test('captured, ghola and concealed records give identical reasons independ
['Duke Vidal is unavailable for this revival.'],
);
});
void test('Advanced Harkonnen retains its uniform public boundary while Basic and other Advanced tables resolve normally', () => {
void test('plain Advanced Harkonnen admits revival while unsupported Skills retain a uniform boundary', () => {
const g = fixture();
g.players.push(newPlayer('h', 'Harkonnen', 'harkonnen'));
assert.equal(ecazDukeRevivalBlock(g, 'ec'), null);
g.advanced = true;
assert.equal(ecazDukeRevivalBlock(g, 'ec'), null);
g.leaderSkills = {} as NonNullable<Game['leaderSkills']>;
const expected = ecazDukeRevivalBlock(g, 'ec');
assert.match(expected!, /Advanced Harkonnen/);
for (const dead of [false, true])