Support Basic Kull and Leader Skills with Ecaz
Verify and publish checkpoint container / container (push) Successful in 10m49s

This commit is contained in:
Quintine committed 2026-11-16 16:31:43 +11:00
1 parent 4270b36be7
commit 4fba4860e1
11 files changed
+415 -13

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
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 { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { RECRUITS_CARD_ID } from '../game/recruits';
import { takeKullCard } from './fixture-choam-kull';
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
import { advanceSemutaNexusTrade, type SemutaNexusTradeStep } from './fixture-semuta-nexus-trade';
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
function seat(game: Game, id: string) {
const player = game.players.find(candidate => candidate.id === id);
assert.ok(player); return player;
}
function inventory(game: Game) {
const ids = [ ...game.deck, ...game.discard, ...(game.auction?.cards.slice(game.auction.index) ?? []),
...(game.ixAuction?.cards ?? []), ...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []),
...game.players.flatMap(player => player.hand) ].map(card => card.id).sort();
assert.equal(new Set(ids).size, ids.length); return ids;
}
function skills(game: Game) {
assert.ok(game.leaderSkills);
validateLeaderSkills(game.leaderSkills, game.players);
assert.deepEqual([...game.leaderSkills.deck,
...Object.values(game.leaderSkills.offers).flatMap(offer => offer.cards),
...game.leaderSkills.assignments.map(row => row.skill)].sort(),
LEADER_SKILL_CARDS.map(card => card.id).sort());
}
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision && !game.truthtrance;
/** Public Basic lobby and actual skill training. Only unopened Spice ordering
* and conserved held Treachery positions are staged before the Karama attempt. */
function fixture(independent: boolean, richese = false) {
let game = createGame('KULLSKILLS', 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'] : []), 'leaderSkills', 'kullPreview'])
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
const selected = viewGame(game, 'c').lobbyModules!;
assert.equal(selected.nexusCards, false); 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.ok(!game.nexusKullPreview && !game.nexusCards);
assert.equal(game.ecazTreachery === true, independent);
if (richese) { assert.equal(game.semutaPreview, true); assert.ok(game.richeseCache?.length); }
const setup: SemutaNexusTradeStep[] = [];
game = advanceSemutaNexusTrade(game, state => state.status === 'playing', setup);
assert.equal(setup.filter(row => row.action.type === 'leaderSkill').length, game.players.length);
assert.equal(game.leaderSkills!.assignments.length, game.players.length);
skills(game);
const originalSkills = structuredClone(game.leaderSkills), originalCards = inventory(game);
game = advanceSemutaNexusTrade(game, beforeIxSpiceDraw);
orderIxSpiceCards(game, ['land', 'land']);
game = advanceSemutaNexusTrade(game, state => state.phase === 5 && state.active === 'g' && clean(state));
for (const player of game.players) game.deck.push(...player.hand.splice(0));
const printed = takeKullCard(game, 'ix-kull-wahad'); seat(game, 'c').hand.push(printed);
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(inventory(game), originalCards);
assert.deepEqual(game.leaderSkills, originalSkills);
game = act(game, 'g', { type: 'card', mode: 'shipment', card: original.id, target: 'g' });
assert.ok(game.pendingKull);
return { game, printed: printed.id, original: original.id, event: game.pendingKull.event, originalCards, originalSkills };
}
function usePrinted(f: ReturnType<typeof fixture>) {
assert.ok(viewGame(f.game, 'c').kullReaction?.plays.some(play => play.source === 'printed' && play.card.id === f.printed));
let game = act(f.game, 'c', { type: 'kullDecision', event: f.event, source: 'printed', card: f.printed });
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);
assert.equal(seat(game, 'g').hand.some(card => card.id === f.original), true);
return game;
}
for (const independent of [false, true]) void test(
`Basic public printed Kull retains trained Skills${independent ? ' and 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));
}
const game = usePrinted(f);
assert.equal(game.discard.filter(card => card.id === f.printed).length, 1);
assert.deepEqual(inventory(game), f.originalCards);
assert.deepEqual(game.leaderSkills, f.originalSkills); skills(game);
},
);
void test('Richese can claim printed Kull with Semuta and retain original Skills and cache', () => {
const f = fixture(true, true);
let game = usePrinted(f);
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), [f.printed]);
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.printed });
assert.equal(game.pendingTreacheryDiscard, null);
assert.ok(seat(game, 'r').hand.some(card => card.id === f.printed));
assert.ok(game.discard.some(card => card.id === SEMUTA_DRUG_ID));
assert.deepEqual(inventory(game), f.originalCards);
assert.deepEqual(game.leaderSkills, f.originalSkills); skills(game);
});
for (const claim of [false, true]) void test(
`Basic printed Kull and Skills retain Recruits while Richese ${claim ? 'claims' : 'passes'} with Semuta`, () => {
let game = createGame('KULLSKILLSRECRUITS', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam']);
for (const [id, faction] of [['r', 'richese'], ['a', 'atreides'], ['g', 'guild']] as const)
joinGame(game, newPlayer(id, faction, faction));
for (const moduleName of ['ecazTreachery', 'leaderSkills', 'kullPreview'])
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
for (const player of game.players) game = act(game, player.id, { type: 'ready' });
game = act(game, 'c', { type: 'start' });
assert.equal(game.ecazTreachery, true);
assert.equal(game.kullPreview, true);
assert.equal(game.semutaPreview, true);
assert.ok(game.leaderSkills && !game.nexusCards && !game.nexusKullPreview);
const setup: SemutaNexusTradeStep[] = [];
game = advanceSemutaNexusTrade(game, state => state.status === 'playing', setup);
assert.equal(setup.filter(row => row.action.type === 'leaderSkill').length, game.players.length);
game = advanceSemutaNexusTrade(game, beforeIxSpiceDraw);
orderIxSpiceCards(game, ['land', 'land']);
game = advanceSemutaNexusTrade(game, state => state.phase === 4 && clean(state) && !state.pendingTreacheryDiscard);
const originalCards = inventory(game), originalSkills = structuredClone(game.leaderSkills);
for (const id of ['a', 'r']) game.deck.push(...seat(game, id).hand.splice(0));
seat(game, 'a').hand.push(takeKullCard(game, RECRUITS_CARD_ID));
seat(game, 'r').hand.push(takeKullCard(game, SEMUTA_DRUG_ID));
assert.deepEqual(inventory(game), originalCards);
const preview = viewGame(game, 'a').recruitsPreview?.play;
assert.ok(preview && !preview.blocked);
game = act(game, 'a', { type: 'card', card: RECRUITS_CARD_ID });
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind, 'ordinaryCardDiscard');
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), [RECRUITS_CARD_ID]);
assert.equal(game.recruits?.turn, game.turn);
if (claim) {
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: RECRUITS_CARD_ID });
} else {
for (const player of game.players) game = act(game, player.id, { type: 'semutaPass', event: pending.batch.event });
}
assert.equal(game.pendingTreacheryDiscard, null);
assert.equal(viewGame(game, 'a').revival.freeRemaining, 4);
assert.equal(viewGame(game, 'a').revival.limit, 7);
assert.equal(seat(game, 'r').hand.some(card => card.id === RECRUITS_CARD_ID), claim);
assert.equal(game.discard.some(card => card.id === RECRUITS_CARD_ID), !claim);
assert.equal(game.discard.some(card => card.id === SEMUTA_DRUG_ID), claim);
assert.deepEqual(inventory(game), originalCards);
assert.deepEqual(game.leaderSkills, originalSkills); skills(game);
},
);