import assert from 'node:assert/strict'; import test from 'node:test'; import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine'; import { SEMUTA_DRUG_ID } from '../game/semuta-drug'; import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta'; /** Only the original unopened deal and a safe unopened Spice position are * selected. Richese actually purchases Semuta in the native cache auction, * then Guild asks its original physically held Truthtrance during Bidding. */ function fixture() { let game=createGame('KULLRICHTRUTH',newPlayer('choam','CHOAM','choam'),false,['choam','ix']); for (const id of ['richese','emperor','harkonnen','guild'] as const) joinGame(game,newPlayer(id,id,id)); game=act(game,'choam',{type:'moduleOption',module:'kullPreview',enabled:true}); for (const seat of game.players) game=act(game,seat.id,{type:'ready'}); game=act(game,'choam',{type:'start'}); assert.equal(game.status,'setup'); assert.ok(game.kullPreview && game.semutaPreview); const originalCards=inventory(game), selected:Game['deck']=[]; for (const kind of ['kull','filler','karama','karama','filler','truth'] as const) { const index=game.deck.findIndex(card=>kind==='kull' ? card.id==='ix-kull-wahad' : kind==='truth' ? card.effect==='truthtrance' : kind==='karama' ? card.effect==='karama' : card.kind==='worthless' && card.id!=='ix-kull-wahad'); assert.ok(index>=0); selected.push(game.deck.splice(index,1)[0]); } game.deck.unshift(...selected); game=advance(game,state=>state.status==='playing'); const truth=selected[5].id; assert.ok(player(game,'guild').hand.some(card=>card.id===truth)); const spice=game.spiceDeck.findIndex(card=>'territory' in card && !card.discovery); assert.ok(spice>=0); game.spiceDeck.unshift(game.spiceDeck.splice(spice,1)[0]); game=advance(game,state=>player(state,'richese').hand.some(card=>card.id===SEMUTA_DRUG_ID) && !!state.auction && state.auction.active==='emperor' && clean(state)); assert.deepEqual(inventory(game),originalCards); return {game,truth,originalCards}; } function resolveSemuta(game:Game,card:string,claim:boolean):Game { const pending=game.pendingTreacheryDiscard; assert.ok(pending); assert.equal(pending.reaction?.stage,'offer'); assert.ok(pending.batch.entries.some(entry=>entry.card.id===card)); const event=pending.batch.event; if (claim) { assert.equal(viewGame(game,'richese').semutaReaction?.canCommit,true); game=act(game,'richese',{type:'semutaCommit',event}); if (game.pendingTreacheryDiscard?.reaction?.stage==='select') game=act(game,'richese',{type:'semutaSelect',event,card}); } else { for (let count=0;game.pendingTreacheryDiscard?.batch.event===event && count!reaction.passed.includes(row.id)); assert.ok(next); game=act(game,next.id,{type:'semutaPass',event}); } } assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event); return game; } for (const kind of ['bribe','bribeExpression','mixedBribe'] as const) for (const claim of [false,true]) void test(`Basic ${kind} answer retains its payment after Semuta ${claim?'claims':'passes'} Truthtrance`,()=>{ const f=fixture(); let game=act(f.game,'guild',{type:'card',card:f.truth}); while (game.truthtrance?.stage==='priority') { const next=game.players.find(row=>!game.truthtrance!.passed.includes(row.id)); assert.ok(next); game=act(game,next.id,{type:'truthPass'}); } const payment={kind:'payment' as const,recipient:'guild',minimum:2}; const question=kind==='bribe' ? {kind,target:'emperor',turn:game.turn,recipient:'guild',minimum:2} : kind==='bribeExpression' ? {kind,target:'emperor',turn:game.turn,claim:payment} : {kind,target:'emperor',turn:game.turn,mixed:{kind:'and',terms:[ {kind:'fact',fact:{kind:'spice',compare:'eq',value:player(game,'emperor').spice}}, {kind:'action',action:{recipient:'guild',minimum:2}}, ]}}; game=act(game,'guild',{type:'truthAsk',question}); const view=viewGame(game,'emperor'); const answers=kind==='bribe' ? view.truthBribeAnswers : kind==='bribeExpression' ? view.truthBribeExpressionAnswers : view.truthMixedBribeAnswers; assert.ok(answers?.includes('yes')); game=act(game,'emperor',{type:'truthAnswer',answer:'yes'}); game=resolveSemuta(game,f.truth,claim); game=advance(game,clean); const guide=viewGame(game,'emperor').bribePromiseGuide; assert.ok(guide); assert.equal(guide.action.type,'bribe'); assert.equal(guide.action.target,'guild'); game=act(game,'emperor',guide.action); assert.equal(player(game,'guild').bribes,2); if (kind==='bribe') assert.ok(game.bribePromises?.some(row=>row.player==='emperor' && row.fulfilled)); else assert.ok(game.bribeExpressionPromises?.some(row=>row.player==='emperor' && row.fulfilled)); assert.equal(player(game,'richese').hand.some(card=>card.id===f.truth),claim); assert.deepEqual(inventory(game),f.originalCards); });