import assert from 'node:assert/strict'; import test from 'node:test'; import { createGame, initializeSemutaGameForAudit, joinGame, newPlayer, viewGame, type Game } from '../game/engine'; import { SEMUTA_DRUG_ID } from '../game/semuta-drug'; import { nextStrongholdFactionsNativeStep } from './fixture-stronghold-factions'; import { actTruthMovementNativeEarly as act, nextTruthMovementNativeEarlyStep } from './fixture-truth-movement-native-early'; import { truthMovementInventory } from './fixture-truth-movement'; import { moveSemutaEmperorCard, semutaEmperorCardId } from './fixture-semuta-emperor-share'; import { reactSemutaSpecial } from './fixture-semuta-special-karama'; const player = (game:Game, id:string) => { const result = game.players.find(seat => seat.id === id); assert.ok(result); return result; }; function advance(game:Game, until:(state:Game) => boolean):Game { for (let count = 0; count < 500; count++) { if (until(game)) return game; const step = nextTruthMovementNativeEarlyStep(game); assert.ok(step); game = act(game,step.actor,step.action); } throw Error('The original game did not return to its Ix opening.'); } /** Genuine Advanced native Semuta setup and Ix opening. Staging moves the * original Semuta and, if needed, an existing printed Karama between physical * zones to exercise its special discard and reaction. No opening, spice or * force state is installed by the fixture. */ function source() { let game = createGame('RICHSEMUTAOPEN',newPlayer('r','Richese','richese'),true,['choam','ix']); joinGame(game,newPlayer('i','Ixians','ixians')); joinGame(game,newPlayer('a','Atreides','atreides')); joinGame(game,newPlayer('e','Emperor','emperor')); for (const seat of game.players) game = act(game,seat.id,{type:'ready'}); game = initializeSemutaGameForAudit(game); for (let count = 0; game.status === 'setup' && count < 200; count++) { const step = nextStrongholdFactionsNativeStep(game); assert.ok(step); game = act(game,step.actor,step.action); } assert.equal(game.status,'playing'); assert.equal(game.phase,0); assert.ok(game.phaseOpening && game.amalWindowOpen); moveSemutaEmperorCard(game,SEMUTA_DRUG_ID,'a'); let karama = player(game,'r').hand.find(card => card.effect === 'karama'); if (!karama) { const id = semutaEmperorCardId(game,card => card.effect === 'karama'); moveSemutaEmperorCard(game,id,'r'); karama = player(game,'r').hand.find(card => card.id === id); } assert.ok(karama); const acquired = game.richeseCache?.find(card => card.id !== SEMUTA_DRUG_ID); assert.ok(acquired); return {game,karama:karama.id,acquired:acquired.id}; } let cached:ReturnType | undefined; const fixture = () => {cached ??= source(); return {...cached,game:structuredClone(cached.game)};}; for (const claim of [false,true]) void test(`Semuta ${claim ? 'claims' : 'passes'} the Richese cost and restores the same Ix opening after Emperor income`, () => { const {game,karama,acquired} = fixture(); const before = act(game,'i',{type:'ready'}); const opening = structuredClone(before.phaseOpening), inventory = truthMovementInventory(before); const richeseSpice = player(before,'r').spice, emperorSpice = player(before,'e').spice; assert.ok(opening?.passed.includes('i')); assert.equal(viewGame(before,'r').richeseSpecialKarama?.blocked,null); let next = act(before,'r',{type:'card',mode:'special',card:karama,acquire:acquired}); assert.equal(next.pendingTreacheryDiscard?.batch.cause,'specialKarama:richese'); assert.deepEqual(next.pendingTreacheryDiscard?.continuation?.kind,'specialKaramaDiscard'); assert.equal(next.phaseOpening,null); assert.equal(player(next,'r').spice,richeseSpice); assert.equal(player(next,'r').specialKaramaUsed,undefined); assert.ok(next.richeseCache?.some(card => card.id === acquired)); next = reactSemutaSpecial(next,'a',claim); assert.equal(player(next,'r').spice,richeseSpice - 3); assert.equal(player(next,'r').specialKaramaUsed,true); assert.ok(player(next,'r').hand.some(card => card.id === acquired)); assert.equal(player(next,'a').hand.some(card => card.id === karama),claim); if (next.response) next = advance(next,state => !!state.phaseOpening && !state.response && !state.decision); assert.deepEqual(next.phaseOpening,opening); assert.equal(next.amalWindowOpen,true); assert.equal(player(next,'e').spice,emperorSpice + 3); assert.deepEqual(truthMovementInventory(next),inventory); });