import assert from 'node:assert/strict'; import test from 'node:test'; import {createGame, joinGame, newPlayer, viewGame, type Game} from '../game/engine'; import {actKullPurpose as act, advanceKullPurpose as advance, kullPurposeClean as clean, kullPurposePlayer as seat} from './fixture-kull-purpose'; import {publicKullInventory as inventory} from './fixture-public-choam-kull'; import {takeKullCard} from './fixture-choam-kull'; import {beforeIxSpiceDraw, orderIxSpiceCards} from './fixture-ix-spice-cards'; /** Real public Advanced CHOAM+Ix setup with selected printed Kull, natural * worm/alliance and native ordinary bidding. Unopened Spice order, conserved * initial board forces, physical cards and auction wallets are staged. */ function fixture() { let g=createGame('ADVAUCTIONKULL',newPlayer('choam','CHOAM','choam'),true,['choam','ix']); for(const id of ['emperor','guild','atreides'] as const)joinGame(g,newPlayer(id,id,id)); g=act(g,'choam',{type:'moduleOption',module:'kullPreview',enabled:true}); for(const p of g.players)g=act(g,p.id,{type:'ready'}); g=act(g,'choam',{type:'start',advancedPreview:true});assert.equal(g.kullPreview,true); g=advance(g,s=>s.status==='playing'); for(const p of g.players){p.reserves+=Object.values(p.forces).reduce((sum,n)=>sum+n,0);p.forces={};} g=advance(g,beforeIxSpiceDraw);orderIxSpiceCards(g,['land','land']); g=advance(g,s=>s.turn===2&&beforeIxSpiceDraw(s));orderIxSpiceCards(g,['worm','land','land']); g=advance(g,s=>!!s.nexus&&!s.spiceWindow&&clean(s)); g=act(g,'emperor',{type:'alliance',target:'guild'});g=act(g,'guild',{type:'alliance',target:'emperor'}); g=advance(g,s=>s.phase===3&&s.phaseOpening?.initialize===true); const cards=inventory(g); for(const p of g.players)g.deck.push(...p.hand.splice(0)); const kull=takeKullCard(g,'ix-kull-wahad');seat(g,'choam').hand.push(kull); const cost=takeKullCard(g,'karama');seat(g,'atreides').hand.push(cost); const counter=takeKullCard(g,'karama');seat(g,'guild').hand.push(counter); seat(g,'emperor').spice=8;seat(g,'guild').spice=7; assert.deepEqual(inventory(g),cards); g=advance(g,s=>s.phase===3&&!!s.auction&&clean(s)); while(g.auction!.active!=='guild')g=act(g,g.auction!.active,{type:'passBid'}); const card=g.auction!.cards[g.auction!.index].id; g=act(g,'emperor',{type:'pledgeAid',amount:1}); g=act(g,'guild',{type:'bid',amount:3,allyPayment:1}); for(let n=0;g.auction&&!g.response&&!g.decision&&n<15;n++)g=act(g,g.auction.active,{type:'passBid'}); assert.equal(g.decision?.kind,'auctionPayment'); const offer=viewGame(g,'emperor').emperorAuctionGift;assert.ok(offer); return {g,card,kull:kull.id,cost:cost.id,counter:counter.id,cards,event:offer.event}; } function finishGift(g:Game) { for(let n=0;g.response?.kind==='emperorGift'&&n<20;n++) { const p=g.players.find(row=>!g.response!.passed.includes(row.id));assert.ok(p); g=act(g,p.id,{type:'passResponse'}); } return g; } function finishSale(g:Game,event:string) { g=act(g,'emperor',{type:'emperorAuctionGiftContinue',event}); if(g.decision?.kind==='auctionPayment')g=act(g,'guild',{type:'decision',karama:false}); for(let n=0;g.response&&n<20;n++) { const p=g.players.find(row=>!g.response!.passed.includes(row.id));assert.ok(p); g=act(g,p.id,{type:'passResponse'}); } return g; } for(const mode of ['decline','successful','countered'] as const) void test( `Advanced printed Kull ${mode} preserves the allied ordinary auction gift and physical cards`,()=>{ const f=fixture(),before=structuredClone(f.g), lot=structuredClone(f.g.auction),aid=structuredClone(f.g.aid); let g=act(f.g,'emperor',{type:'emperorGift',amount:2}); g=act(g,'atreides',{type:'card',mode:'cancel',card:f.cost}); assert.equal(g.pendingKull?.stage,'offer'); const event=g.pendingKull!.event; if(mode==='decline')g=act(g,'choam',{type:'kullDecision',event,decline:true}); else { g=act(g,'choam',{type:'kullDecision',event,source:'printed',card:f.kull}); assert.equal(g.pendingKull?.stage,'counter'); if(mode==='countered')g=act(g,'guild',{type:'card',mode:'cancel',card:f.counter}); else for(let n=0;g.pendingKull?.stage==='counter'&&g.response&&n<20;n++) { const p=g.players.find(row=>!g.response!.passed.includes(row.id));assert.ok(p); g=act(g,p.id,{type:'passResponse'}); } } g=finishGift(g); assert.equal(viewGame(g,'emperor').emperorAuctionGift?.event,f.event); assert.deepEqual(g.auction,lot);assert.deepEqual(g.aid,aid); const transferred=mode==='successful'; assert.equal(seat(g,'guild').spice,seat(before,'guild').spice+(transferred?2:0)); assert.equal(seat(g,'emperor').spice,seat(before,'emperor').spice-(transferred?2:0)); assert.equal(seat(g,'atreides').hand.some(card=>card.id===f.cost),transferred); g=finishSale(g,f.event); assert.ok(seat(g,'guild').hand.some(card=>card.id===f.card)); assert.deepEqual(inventory(g),f.cards); });