import assert from 'node:assert/strict'; import test from 'node:test'; import { viewGame, type Game } from '../game/engine'; import { TERRITORIES } from '../game/board'; import { act, advance, clean, createKullNativeIxFixture, inventory, player } from './fixture-kull-native-ix'; import { nextKullPurposeStep } from './fixture-kull-purpose'; /** Start from the native public five-seat setup before Spice Blow. The fixture * selects original unopened cards but all questions, auctions, shipments and * battle responses below are real actions. */ function answered(target:'ixians'|'emperor') { const f=createKullNativeIxFixture('ixians'); let game=f.early; game=act(game,'guild',{type:'card',card:f.truth}); while (game.truthtrance?.stage==='priority') { const seat=game.players.find(row=>!game.truthtrance!.passed.includes(row.id)); assert.ok(seat); game=act(game,seat.id,{type:'truthPass'}); } const recipient=target==='ixians'?'emperor':'ixians'; game=act(game,'guild',{type:'truthAsk',question:{kind:'turnActions',target,turn:game.turn, mixed:{kind:'action',action:{kind:'payment',recipient,minimum:1}}}}); assert.ok(viewGame(game,target).truthTurnActionAnswers?.includes('yes')); game=act(game,target,{type:'truthAnswer',answer:'yes'}); const row=game.turnActionPromises?.at(-1); assert.ok(row); return {...f,game,event:row.event}; } function offer(game:Game,actor:string,card:string) { assert.ok(viewGame(game,actor).responseControls?.cancelCards.includes(card)); game=act(game,actor,{type:'card',mode:'cancel',card}); const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction); return {game,event:reaction.event}; } for (const outcome of ['decline','success','counter'] as const) void test(`whole payment answer survives real Guild income cancellation and Kull ${outcome}`,()=>{ const f=answered('ixians'); let game=advance(f.game,state=>state.phase===5 && state.active==='ixians' && clean(state)); game=act(game,'ixians',{type:'ship',territory:'polar_sink',sector:0,amount:1,elite:0,allyPayment:0}); assert.equal(game.response?.kind,'guildIncome'); const choice=offer(game,'ixians',f.karama); game=choice.game; game=outcome==='decline'?act(game,'choam',{type:'kullDecision',event:choice.event,decline:true}): act(game,'choam',{type:'kullDecision',event:choice.event,source:'printed',card:f.kull}); if (outcome==='counter') game=act(game,'emperor',{type:'card',mode:'cancel',card:f.counter}); if (outcome==='success') game=advance(game,state=>!state.pendingKull && state.response?.kind!=='choamWorthless'); assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released)); assert.equal(player(game,'ixians').hand.some(card=>card.id===f.karama),outcome==='success'); assert.deepEqual(inventory(game),f.originalCards); }); void test('whole payment answer survives real Basic Ixian cyborg-strength cancellation and Kull decline',()=>{ const f=answered('emperor'); let game=f.game; let target:{territory:string;sector:number}|null=null; for (let count=0;count<1200 && game.phase!==6;count++) { if (game.phase===5 && clean(game) && game.active) { const actor=game.active, seat=player(game,actor); if ((actor==='emperor'||actor==='ixians') && !seat.shipped) { if (!target) { const territory=TERRITORIES.find(row=>row.type==='stronghold' && row.sectors.some(s=>s!==game.storm) && game.players.every(p=>!Object.keys(p.forces).some(key=>key.startsWith(`${row.id}:`)))); assert.ok(territory); target={territory:territory.id,sector:territory.sectors.find(s=>s!==game.storm)!}; } game=act(game,actor,{type:'ship',territory:target.territory,sector:target.sector,amount:1, elite:actor==='ixians'?1:0,allyPayment:0}); } else game=act(game,actor,{type:'endMovement'}); continue; } const next=nextKullPurposeStep(game); assert.ok(next); game=act(game,next.actor,next.action); } assert.equal(game.phase,6); assert.ok(target); assert.equal(player(game,'emperor').forces[`${target.territory}:${target.sector}`],1); assert.equal(player(game,'ixians').elites?.forces[`${target.territory}:${target.sector}`],1); for (let count=0;count<30 && !game.battle;count++) { const view=game.active?viewGame(game,game.active):null; const choice=view?.battleChoices?.find(row=>row.territory===target!.territory && (row.chooser??row.attacker)===game.active && [row.attacker,row.defender].includes(game.active!)); if (choice) { game=act(game,game.active!,{type:'chooseBattle',territory:target.territory, target:game.active==='emperor'?'ixians':'emperor'}); break; } const next=nextKullPurposeStep(game); assert.ok(next); game=act(game,next.actor,next.action); } assert.equal(game.response?.kind,'eliteStrength'); const choice=offer(game,'emperor',f.counter); game=choice.game; game=act(game,'choam',{type:'kullDecision',event:choice.event,decline:true}); assert.ok(game.turnActionPromises?.some(row=>row.event===f.event && !row.released)); assert.ok(!player(game,'emperor').hand.some(card=>card.id===f.counter)); assert.deepEqual(inventory(game),f.originalCards); });