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 { validateNexusCards } from '../game/nexus-cards'; import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards'; import { nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade'; const act = (g: Game, id: string, action: Action) => applyAction(g, id, action); const 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) { for (let i = 0; i < 2000; i++) { if (until(g)) return g; assert.notEqual(g.status, 'finished', `Game ended at ${g.turn}/${g.phase}: ${JSON.stringify(g.log.slice(-5))}`); 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 Ecaz/Nexus/Kull/Skills progression did not reach its boundary'); } function inventory(g: Game) { return [...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(card => card.id).sort(); } function physicalSkills(g: Game) { assert.ok(g.leaderSkills); validateLeaderSkills(g.leaderSkills, g.players); const state = g.leaderSkills; assert.deepEqual([...state.deck, ...Object.values(state.offers).flatMap(o => o.cards), ...state.assignments.map(a => a.skill)].sort(), LEADER_SKILL_CARDS.map(c => c.id).sort()); if (g.nexusCards) validateNexusCards(g.nexusCards.cards!, g.players); } for (const nexus of [false, true]) for (const independent of [false, true]) void test( `Public Basic Ecaz plays an Occupy battle with ${nexus ? 'Nexus ' : 'printed '}Kull and Skills${independent ? ' and independent Ecaz cards' : ''}`, () => { let g = createGame('NEXUSKULLECAZ', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam', 'ecaz']); for (const [id, faction] of [['e', 'ecaz'], ['a', 'atreides'], ['g', 'guild']] as const) joinGame(g, newPlayer(id, faction, faction)); for (const name of [...(independent ? ['ecazTreachery'] : []), ...(nexus ? ['nexusCards'] : []), 'leaderSkills', 'kullPreview']) g = act(g, 'c', { type: 'moduleOption', module: name, enabled: true }); for (const p of g.players) g = act(g, p.id, { type: 'ready' }); g = act(g, 'c', { type: 'start' }); assert.equal(g.ecazOccupyPreview, true); assert.equal(g.kullPreview, true); assert.equal(g.nexusKullPreview === true, nexus); assert.equal(!!g.nexusCards, nexus); assert.equal(g.ecazTreachery === true, independent); g = reach(g, state => state.status === 'playing'); assert.equal(g.leaderSkills!.assignments.length, g.players.length); physicalSkills(g); const cards = inventory(g); // Controlled board staging conserves each faction's pieces; unopened Spice // order produces the ordinary turn-two worm/alliance without assigning it. for (const p of g.players) { p.reserves += Object.values(p.forces).reduce((sum, n) => sum + n, 0); p.forces = {}; } g = reach(g, beforeIxSpiceDraw); orderIxSpiceCards(g, ['land', 'land']); g = reach(g, state => state.turn === 2 && beforeIxSpiceDraw(state)); orderIxSpiceCards(g, ['worm', 'land', 'land']); g = reach(g, state => !!state.nexus && !state.spiceWindow && clean(state)); g = act(g, 'e', { type: 'alliance', target: 'a' }); g = act(g, 'a', { type: 'alliance', target: 'e' }); g = reach(g, state => state.turn === 2 && state.phase === 5 && clean(state)); assert.equal(seat(g, 'e').ally, 'a'); assert.equal(seat(g, 'a').ally, 'e'); const territory = g.storm === 11 ? 'arrakeen' : 'carthag'; const sector = territory === 'carthag' ? 11 : 10; const location = `${territory}:${sector}`; for (const [id, amount] of [['e', 5], ['a', 4], ['g', 3]] as const) { const p = seat(g, id); assert.ok(p.reserves >= amount); p.reserves -= amount; p.forces[location] = amount; } g = reach(g, state => state.turn === 2 && state.phase === 6 && clean(state)); const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === territory); assert.ok(choice); g = act(g, choice.chooser, { type: 'chooseBattle', territory, target: choice.attacker === choice.chooser ? choice.defender : choice.attacker }); g = reach(g, state => !state.response && !state.phaseOpening && state.decision?.kind === 'ecazBattleLead'); assert.ok(g.decision?.kind === 'ecazBattleLead'); const event = g.decision.event; g = act(g, 'e', { type: 'decision', event, lead: 'e' }); g = reach(g, state => !!state.battle && !state.battle.preparation && state.battle.preLeader?.closed !== false && clean(state)); const view = viewGame(g, 'e'); assert.ok(view.battle?.ecazOccupy?.profile); assert.equal(view.battle.ecazOccupy.profile.fixedEcazDial, 3); physicalSkills(g); assert.deepEqual(inventory(g), cards); }, );