Files
Dune/tests/nexus-kull-leader-skills.test.ts
T
Quintine 4270b36be7
Verify and publish checkpoint container / container (push) Successful in 10m45s
Connect Nexus Skills and Advanced Ambassador markers
2026-11-16 16:23:53 +11:00

149 lines
8.8 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
applyAction, createGame, joinGame, newPlayer, normalizeAutomaticGame, viewGame,
type Action, type Game,
} from '../game/engine';
import { LEADER_SKILL_CARDS } from '../game/leader-skill-cards';
import { validateLeaderSkills } from '../game/leader-skills';
import { validateNexusCards } from '../game/nexus-cards';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { takeKullCard } from './fixture-choam-kull';
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
import {
advanceSemutaNexusTrade, swapSemutaNexusTradeIdentity,
type SemutaNexusTradeStep,
} from './fixture-semuta-nexus-trade';
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
const seat = (game: Game, id: string) => {
const player = game.players.find(candidate => candidate.id === id);
assert.ok(player); return player;
};
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision && !game.truthtrance;
const physical = (game: Game) => [
...game.deck, ...game.discard, ...(game.auction?.cards.slice(game.auction.index) ?? []),
...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []),
...(game.ixAuction?.cards ?? []), ...game.players.flatMap(player => player.hand),
].map(card => card.id).sort();
function skills(game: Game) {
assert.ok(game.leaderSkills);
validateLeaderSkills(game.leaderSkills, game.players);
const state = game.leaderSkills;
assert.deepEqual([...state.deck, ...Object.values(state.offers).flatMap(offer => offer.cards),
...state.assignments.map(assignment => assignment.skill)].sort(),
LEADER_SKILL_CARDS.map(card => card.id).sort());
}
/** Public selected-module start, real skill training and a real earned Nexus.
* Only unopened Spice order, the identity of an earned card, and conserved
* board/hand pieces are staged, matching the existing public Kull fixture. */
function fixture(independent: boolean, richese = false) {
let game = createGame('NEXUSKULLSKILLS', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam', 'ecaz']);
for (const [id, faction] of [['a', 'atreides'], ['g', 'guild'], ['h', 'harkonnen']] as const)
joinGame(game, newPlayer(id, faction, faction));
if (richese) joinGame(game, newPlayer('r', 'Richese', 'richese'));
for (const moduleName of [...(independent ? ['ecazTreachery'] : []), 'nexusCards', 'leaderSkills', 'kullPreview'])
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
const selected = viewGame(game, 'c').lobbyModules!;
assert.equal(selected.nexusCards, true); assert.equal(selected.leaderSkills, true);
assert.equal(selected.kullPreview, true);
if (independent) assert.equal(selected.ecazTreachery, true);
for (const player of game.players) game = act(game, player.id, { type: 'ready' });
game = act(game, 'c', { type: 'start' });
assert.equal(game.kullPreview, true); assert.equal(game.nexusKullPreview, true);
if (richese) { assert.equal(game.semutaPreview, true); assert.ok(game.richeseCache?.length); }
assert.ok(game.leaderSkills); assert.ok(game.nexusCards);
assert.equal(game.ecazTreachery === true, independent);
const setupActions: SemutaNexusTradeStep[] = [];
game = advanceSemutaNexusTrade(game, state => state.status === 'playing', setupActions);
assert.equal(setupActions.filter(row => row.action.type === 'leaderSkill').length, game.players.length);
assert.equal(game.leaderSkills!.assignments.length, game.players.length);
skills(game); validateNexusCards(game.nexusCards!.cards!, game.players);
const inventory = physical(game);
const originalSkills = structuredClone(game.leaderSkills);
for (const player of game.players) {
player.reserves += Object.values(player.forces).reduce((sum, amount) => sum + amount, 0);
player.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', 'choam');
game = advanceSemutaNexusTrade(game, state => state.phase === 5 && state.active === 'g' && clean(state));
assert.equal(game.nexusCards!.cards!.hands.c, 'choam');
for (const player of game.players) game.deck.push(...player.hand.splice(0));
const fuel = takeKullCard(game, 'ix-hunter-seeker'); seat(game, 'c').hand.push(fuel);
const original = takeKullCard(game, 'karama'); seat(game, 'g').hand.push(original);
if (richese) seat(game, 'r').hand.push(takeKullCard(game, SEMUTA_DRUG_ID));
assert.deepEqual(physical(game), inventory);
assert.deepEqual(game.leaderSkills, originalSkills);
game = act(game, 'g', { type: 'card', mode: 'shipment', card: original.id, target: 'g' });
assert.ok(game.pendingKull);
assert.deepEqual(game.leaderSkills, originalSkills);
return { game, fuel: fuel.id, original: original.id, event: game.pendingKull.event, inventory, originalSkills };
}
for (const independent of [false, true]) void test(
`Basic public Nexus Kull keeps trained Leader Skills${independent ? ' with independent Ecaz cards' : ''}`, () => {
const f = fixture(independent);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(f.game, 'c'); view.players.find(player => player.id === 'c')!.bot = difficulty;
const choice = botActions(view).find(action => action.type === 'kullDecision');
assert.ok(choice); assert.doesNotThrow(() => act(f.game, 'c', choice));
}
assert.ok(viewGame(f.game, 'c').kullReaction?.plays.some(play => play.source === 'nexus' && play.card.id === f.fuel));
let game = act(f.game, 'c', { type: 'kullDecision', event: f.event, source: 'nexus', card: f.fuel });
while (game.pendingKull) {
const responder = game.players.find(player => {
const controls = viewGame(game, player.id).responseControls;
return controls && !controls.hasPassed && controls.cancelCards.length > 0;
});
game = responder ? act(game, responder.id, { type: 'passResponse' }) : normalizeAutomaticGame(game);
}
assert.equal(game.nexusCards!.cards!.hands.c, null);
assert.equal(game.discard.filter(card => card.id === f.fuel).length, 1);
assert.equal(seat(game, 'g').hand.some(card => card.id === f.original), true);
assert.deepEqual(physical(game), f.inventory);
assert.deepEqual(game.leaderSkills, f.originalSkills);
skills(game); validateNexusCards(game.nexusCards!.cards!, game.players);
},
);
void test('Richese can claim Nexus Kull fuel with Semuta while original Skills and cache remain physical', () => {
const f = fixture(true, true);
assert.ok(viewGame(f.game, 'c').kullReaction?.plays.some(play => play.source === 'nexus' && play.card.id === f.fuel));
let game = act(f.game, 'c', { type: 'kullDecision', event: f.event, source: 'nexus', card: f.fuel });
for (let n = 0; game.pendingKull && n < 20; n++) {
const responder = game.players.find(player => {
const controls = viewGame(game, player.id).responseControls;
return controls && !controls.hasPassed && controls.cancelCards.length > 0;
});
game = responder ? act(game, responder.id, { type: 'passResponse' }) : normalizeAutomaticGame(game);
}
assert.equal(game.pendingKull, null);
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), [f.fuel]);
assert.equal(viewGame(game, 'r').semutaReaction?.canCommit, true);
game = act(game, 'r', { type: 'semutaCommit', event: pending.batch.event });
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
game = act(game, 'r', { type: 'semutaSelect', event: pending.batch.event, card: f.fuel });
assert.equal(game.pendingTreacheryDiscard, null);
assert.equal(seat(game, 'r').hand.some(card => card.id === f.fuel), true);
assert.equal(game.discard.some(card => card.id === SEMUTA_DRUG_ID), true);
assert.equal(game.nexusCards!.cards!.hands.c, null);
assert.equal(seat(game, 'g').hand.some(card => card.id === f.original), true);
assert.deepEqual(physical(game), f.inventory);
assert.deepEqual(game.leaderSkills, f.originalSkills);
skills(game); validateNexusCards(game.nexusCards!.cards!, game.players);
});