Files
Dune/tests/semuta-ambassador-kull-skills.test.ts
T
Quintine 6acf2c200c
Verify and publish checkpoint container / container (push) Successful in 11m32s
Continue Semuta reactions in Kull Skills games
2026-11-16 16:41:00 +11:00

157 lines
9.6 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 { LEADER_SKILL_CARDS } from '../game/leader-skill-cards';
import { validateLeaderSkills } from '../game/leader-skills';
import { validateAmbassadors } from '../game/ecaz-ambassadors';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade';
const act = (g: Game, id: string, action: Action) => applyAction(g, id, action);
function seat(g: Game, id: string) { const p = g.players.find(row => row.id === id); assert.ok(p); return p; }
const clean = (g: Game) => !g.response && !g.phaseOpening && !g.decision && !g.truthtrance && !g.pendingTreacheryDiscard;
function reach(g: Game, until: (g: Game) => boolean): Game {
for (let i = 0; i < 1600; i++) {
if (until(g)) return g;
assert.notEqual(g.status, 'finished');
if (!g.response && !g.phaseOpening && g.decision?.kind === 'ecazPlacement')
g = act(g, g.decision.player, { type: 'decision', decline: true });
else {
const next = nextSemutaNexusTradeNativeStep(g);
g = act(g, next.actor, next.action);
}
}
throw Error('Native play did not reach the Ecaz Ambassador window');
}
function inventory(g: Game): string[] {
const ids = [...g.deck, ...g.discard, ...(g.richeseCache ?? []), ...(g.richeseRemoved ?? []),
...(g.auction?.cards.slice(g.auction.index) ?? []), ...(g.ixAuction?.cards ?? []),
...g.players.flatMap(p => p.hand)].map(c => c.id).sort();
assert.equal(new Set(ids).size, ids.length); return ids;
}
function skills(g: Game) {
assert.ok(g.leaderSkills); validateLeaderSkills(g.leaderSkills, g.players);
assert.deepEqual([...g.leaderSkills.deck, ...Object.values(g.leaderSkills.offers).flatMap(o => o.cards),
...g.leaderSkills.assignments.map(a => a.skill)].sort(), LEADER_SKILL_CARDS.map(c => c.id).sort());
}
/** Genuine public module setup and original entry; only unopened Spice order,
* the physical Ambassador packet, and conserved held cards are staged. */
function fixture(effect: 'choam' | 'ixians', nexus: boolean, independent: boolean) {
let g = createGame('SEMUTAKULLSKILLS', newPlayer('e', 'Ecaz', 'ecaz'), false, ['ix', 'choam', 'ecaz']);
for (const [id, faction] of [['c', 'choam'], ['r', 'richese'], ['g', 'guild']] as const)
joinGame(g, newPlayer(id, faction, faction));
for (const name of [...(nexus ? ['nexusCards'] : []), ...(independent ? ['ecazTreachery'] : []), 'leaderSkills', 'kullPreview'])
g = act(g, 'e', { type: 'moduleOption', module: name, enabled: true });
for (const p of g.players) g = act(g, p.id, { type: 'ready' });
g = act(g, 'e', { type: 'start' });
assert.equal(g.kullPreview, true); assert.equal(g.nexusKullPreview === true, nexus);
assert.equal(g.semutaPreview, true);
g = reach(g, state => state.status === 'playing');
assert.equal(g.leaderSkills!.assignments.length, g.players.length);
skills(g);
const originalCards = inventory(g), originalSkills = structuredClone(g.leaderSkills);
for (const position of [0, 1]) {
const from = g.spiceDeck.findIndex((card, i) => i >= position && 'territory' in card && !card.discovery);
assert.ok(from >= position); [g.spiceDeck[position], g.spiceDeck[from]] = [g.spiceDeck[from], g.spiceDeck[position]];
}
g = reach(g, state => state.phase === 4 && !state.response && !state.phaseOpening && state.decision?.kind === 'ecazPlacement');
const packet = g.ecazAmbassadors!;
const token = packet.tokens.find(row => row.effect === effect); assert.ok(token);
if (token.zone === 'pool') {
const replaced = packet.tokens.find(row => row.zone === 'supply' && row.effect !== 'ecaz'); assert.ok(replaced);
const index = packet.cohort.indexOf(replaced.id); assert.ok(index >= 0);
packet.cohort[index] = token.id; replaced.zone = 'pool'; token.zone = 'supply';
}
validateAmbassadors(packet);
const territory = 'habbanya_ridge_sietch', sector = 17;
g = act(g, 'e', { type: 'decision', token: token.id, territory });
g = reach(g, state => !state.response && state.decision?.kind === 'ecazPlacement');
g = act(g, 'e', { type: 'decision', decline: true });
g = reach(g, state => state.phase === 5 && state.active === 'g' && clean(state));
const owner = seat(g, 'e'), holder = seat(g, 'g');
while (owner.hand.length < 2) { const card = g.deck.shift(); assert.ok(card); owner.hand.push(card); }
const semuta = g.richeseCache!.findIndex(card => card.id === SEMUTA_DRUG_ID);
if (semuta >= 0) holder.hand.push(g.richeseCache!.splice(semuta, 1)[0]);
else {
const from = g.players.find(p => p.hand.some(card => card.id === SEMUTA_DRUG_ID));
if (from && from.id !== holder.id) holder.hand.push(from.hand.splice(from.hand.findIndex(c => c.id === SEMUTA_DRUG_ID), 1)[0]);
}
assert.ok(holder.hand.some(card => card.id === SEMUTA_DRUG_ID));
assert.deepEqual(inventory(g), originalCards);
g = act(g, 'g', { type: 'ship', amount: 1, territory, sector, elite: 0, allyPayment: 0 });
g = reach(g, state => !state.response && state.pendingAmbassador?.stage === 'offer');
const event = g.pendingAmbassador!.event;
g = act(g, 'e', { type: 'decision', event, trigger: true, beneficiary: 'e', choice: 'effect' });
assert.equal(g.pendingAmbassador?.stage, 'cards'); assert.equal(g.pendingAmbassador?.effect, effect);
const chosen = seat(g, 'e').hand.slice(0, effect === 'choam' ? 2 : 1).map(card => card.id);
assert.equal(chosen.length, effect === 'choam' ? 2 : 1);
return { g, event, chosen, originalCards, originalSkills };
}
for (const effect of ['choam', 'ixians'] as const) for (const nexus of [false, true])
for (const independent of [false, true]) for (const claim of [false, true]) void test(
`${effect} Ambassador Semuta ${claim ? 'claim' : 'pass'} with ${nexus ? 'Nexus' : 'printed'} Kull and Skills${independent ? ' and independent cards' : ''}`,
() => {
const f = fixture(effect, nexus, independent), source = structuredClone(f.g);
let g = act(f.g, 'e', { type: 'decision', event: f.event, cards: f.chosen });
assert.deepEqual(f.g, source);
const pending = g.pendingTreacheryDiscard; assert.equal(pending?.reaction?.stage, 'offer');
assert.equal(pending.continuation.kind, 'ambassador');
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), f.chosen);
assert.equal(viewGame(g, 'g').semutaReaction?.canCommit, true);
if (effect === 'choam' && !nexus && !independent && claim) {
for (const difficulty of DIFFICULTIES) {
const view = viewGame(g, 'g');
view.players.find(player => player.id === 'g')!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action, difficulty);
assert.doesNotThrow(() => act(g, 'g', action), difficulty);
}
}
if (claim) {
g = act(g, 'g', { type: 'semutaCommit', event: pending.batch.event });
if (g.pendingTreacheryDiscard?.reaction?.stage === 'select')
g = act(g, 'g', { type: 'semutaSelect', event: pending.batch.event, card: f.chosen[0] });
assert.ok(seat(g, 'g').hand.some(card => card.id === f.chosen[0]));
assert.ok(g.discard.some(card => card.id === SEMUTA_DRUG_ID));
} else {
for (const p of g.players) g = act(g, p.id, { type: 'semutaPass', event: pending.batch.event });
assert.ok(seat(g, 'g').hand.some(card => card.id === SEMUTA_DRUG_ID));
assert.ok(f.chosen.every(id => g.discard.some(card => card.id === id)));
}
assert.equal(g.pendingTreacheryDiscard, null); assert.equal(g.pendingAmbassador, null);
assert.equal(g.active, 'g'); assert.deepEqual(g.leaderSkills, f.originalSkills);
assert.deepEqual(inventory(g), f.originalCards); skills(g);
g = act(g, 'g', { type: 'endMovement' });
assert.ok(!g.movementRemaining?.includes('g'));
},
);
for (const effect of ['choam', 'ixians'] as const) for (const nexus of [false, true]) void test(
`Earlier ${effect} Ambassador discard with ${nexus ? 'Nexus' : 'printed'} Kull resumes without retroactive Semuta`,
() => {
const f = fixture(effect, nexus, false);
const produced = act(f.g, 'e', { type: 'decision', event: f.event, cards: f.chosen });
assert.equal(produced.pendingTreacheryDiscard?.reaction?.stage, 'offer');
// Model the same physical completed discard saved before this profile was
// admitted to Semuta: the original continuation was automatic, without a
// reaction. Every card, sequence, skill and native parent remains genuine.
const saved: Game = JSON.parse(JSON.stringify(produced));
assert.ok(saved.pendingTreacheryDiscard);
delete saved.pendingTreacheryDiscard.reaction;
const priorSpice = seat(saved, 'e').spice, priorHand = seat(saved, 'e').hand.length;
const resumed = act(saved, 'g', { type: 'advanceBots' });
assert.equal(resumed.pendingTreacheryDiscard, null);
assert.equal(viewGame(resumed, 'g').semutaReaction, null);
assert.ok(seat(resumed, 'g').hand.some(card => card.id === SEMUTA_DRUG_ID));
assert.ok(f.chosen.every(id => resumed.discard.some(card => card.id === id)));
assert.equal(seat(resumed, 'e').spice, priorSpice, 'Do not repeat the committed CHOAM payout.');
assert.equal(seat(resumed, 'e').hand.length, priorHand + (effect === 'ixians' ? 1 : 0));
assert.equal(resumed.pendingAmbassador, null); assert.equal(resumed.active, 'g');
assert.deepEqual(inventory(resumed), f.originalCards);
assert.deepEqual(resumed.leaderSkills, f.originalSkills); skills(resumed);
},
);