Files
Dune/tests/nexus-emperor-sandtrout-public.test.ts
T
Quintine d4cd03afff
Verify and publish checkpoint container / container (push) Canceled after 0s
Extend Basic Nexus Kull to Ixian factions
2026-10-30 18:31:58 +11:00

88 lines
5.8 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { advanceSemutaNexusTrade, swapSemutaNexusTradeIdentity } from './fixture-semuta-nexus-trade';
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
const player = (game: Game, id: string) => { const p = game.players.find(row => row.id === id); assert.ok(p); return p; };
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision && !game.truthtrance && !game.pendingTreacheryDiscard;
const physical = (game: Game) => [...game.deck, ...game.discard, ...game.players.flatMap(p => p.hand),
...(game.auction?.cards.slice(game.auction.index + Number(game.currentAuctionSale?.origin === 'normal')) ?? [])]
.map(card => card.id).sort();
/** Genuine public setup, earned Nexus and actual subsequent Sandtrout. The
* unopened Spice/Nexus identities and physical force positions are staged;
* every card and counter remains in its original physical inventory. */
function fixture(kull: boolean) {
let game = createGame('EMPEROR-SANDTROUT', newPlayer('c', 'Buyer', kull ? 'choam' : 'atreides'), false,
kull ? ['choam', 'ix'] : ['ix']);
for (const [id, faction] of [['a', 'guild'], ['h', 'harkonnen']] as const)
joinGame(game, newPlayer(id, faction, faction));
game = act(game, 'c', {type:'moduleOption',module:'nexusCards',enabled:true});
for (const p of game.players) game = act(game, p.id, {type:'ready'});
game = act(game, 'c', {type:'start'});
assert.equal(!!game.nexusKullPreview, kull);
game = advanceSemutaNexusTrade(game, state => state.status === 'playing');
const cards = physical(game);
for (const p of game.players) {p.reserves += Object.values(p.forces).reduce((a,b) => a+b,0); p.forces = {};}
game = advanceSemutaNexusTrade(game, beforeIxSpiceDraw);
orderIxSpiceCards(game, ['land','land']);
game = advanceSemutaNexusTrade(game, state => state.turn === 2 && beforeIxSpiceDraw(state));
orderIxSpiceCards(game, ['worm','land','land']);
game = advanceSemutaNexusTrade(game, state => state.nexus && !state.spiceWindow && clean(state));
game = act(game,'a',{type:'alliance',target:'h'}); game = act(game,'h',{type:'alliance',target:'a'});
game = advanceSemutaNexusTrade(game, state => state.nexusCards?.phase?.stage === 'drawing' && clean(state));
assert.ok(game.nexusCards!.phase!.eligible.includes('c'));
game = act(game,'c',{type:'nexusCardChoice',turn:game.turn,card:null,choice:'draw',ownRedraws:0});
swapSemutaNexusTradeIdentity(game,'c','emperor');
game = advanceSemutaNexusTrade(game, state => state.turn === 3 && beforeIxSpiceDraw(state));
orderIxSpiceCards(game,['sandtrout','land','land']);
game = advanceSemutaNexusTrade(game, state => state.phase === 3 && !!state.auction && clean(state));
assert.equal(game.sandtrout,true);
assert.equal(game.nexusCards!.cards!.hands.c,'emperor');
assert.ok(game.players.every(p => p.ally === null));
assert.deepEqual(physical(game), cards);
return {game, cards};
}
for (const kull of [false,true]) for (const use of [false,true]) void test(
`Basic ${kull ? 'Kull/Nexus' : 'Ix/Nexus'} Emperor bank ${use ? 'Use' : 'Pay'} after actual Sandtrout`, () => {
const f = fixture(kull); let game = f.game;
while (game.auction!.active !== 'c') game = act(game, game.auction!.active, {type:'passBid'});
const card = game.auction!.cards[game.auction!.index], before = player(game,'c').spice;
assert.ok(before >= 1);
game = act(game,'c',{type:'bid',amount:1,allyPayment:0});
game = advanceSemutaNexusTrade(game, state => state.decision?.kind === 'auctionPayment');
const offer = viewGame(game,'c').nexusEmperorSecretAlly;
assert.ok(offer?.purchase && !offer.purchase.blocked);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,'c'); view.players.find(p => p.id === 'c')!.bot = difficulty;
const choice = botActions(view)[0]; assert.ok(choice); assert.doesNotThrow(() => act(game,'c',choice));
}
game = act(game,'c',use ? {type:'nexusEmperorPurchase',event:offer.event} : {type:'decision',karama:false});
assert.equal(player(game,'c').spice,before - (use ? 0 : 1));
assert.equal(game.nexusCards!.cards!.hands.c,use ? null : 'emperor');
if (game.pendingNexusIxianReplacement)
game = act(game,'c',{type:'nexusIxianReplacementPass',event:game.pendingNexusIxianReplacement.event});
assert.equal(player(game,'c').hand.filter(row => row.id === card.id).length,1);
assert.equal(game.sandtrout,true); assert.deepEqual(physical(game),f.cards);
});
for (const kull of [false,true]) void test(
`Basic ${kull ? 'Kull/Nexus' : 'Ix/Nexus'} Emperor extra revival after actual Sandtrout`, () => {
const f = fixture(kull); let game = f.game;
game = advanceSemutaNexusTrade(game,state => state.phase === 4 && clean(state));
const owner = player(game,'c'); assert.ok(owner.reserves >= 3); owner.reserves -= 3; owner.tanks += 3;
const before = {reserves:owner.reserves,tanks:owner.tanks,revived:owner.revived,free:owner.freeForcesRevived};
const offer = viewGame(game,'c').nexusEmperorSecretAlly; assert.ok(offer && !offer.revival.blocked);
game = act(game,'c',{type:'nexusEmperorRevive',event:offer.event,elite:0});
assert.equal(player(game,'c').reserves,before.reserves+3); assert.equal(player(game,'c').tanks,before.tanks-3);
assert.equal(player(game,'c').revived,before.revived);
assert.equal(player(game,'c').freeForcesRevived,before.free);
assert.equal(game.nexusCards!.cards!.hands.c,null); assert.equal(game.sandtrout,true);
assert.deepEqual(physical(game),f.cards);
});