import assert from 'node:assert/strict'; import test from 'node:test'; import { createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine'; import { botActions } from '../game/bots'; import { DIFFICULTIES } from '../game/bot-profiles'; import { SEMUTA_DRUG_ID } from '../game/semuta-drug'; import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta'; /** Genuine public Basic start. Only the original unopened deal and a safe * unopened spice position are selected. The question, Richese cache purchase, * Kull response, Semuta reaction and payment all use actual actions. */ function fixture(answer:'yes'|'no' = 'yes') { let game = createGame('KULLRICHBRIBE',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'] = []; // Harkonnen receives two cards before Guild's one. 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 [kull,,karama,counter,,truth] = selected.map(card=>card.id); for (const [id,card] of [['choam',kull],['emperor',karama],['harkonnen',counter],['guild',truth]] as const) assert.ok(player(game,id).hand.some(row=>row.id===card),`${id} received ${card}`); 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 => state.phase===2 && clean(state) && state.choamCharity?.turn===state.turn); game = act(game,'guild',{type:'card',card: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'}); } game=act(game,'guild',{type:'truthAsk',question:{kind:'bribe',target:'emperor',turn:game.turn, recipient:'guild',minimum:2}}); const answers=viewGame(game,'emperor').truthBribeAnswers; assert.ok(answers?.includes(answer)); for (const difficulty of DIFFICULTIES) { const view=viewGame(game,'emperor'); view.players.find(row=>row.id==='emperor')!.bot=difficulty; const action=botActions(view)[0]; assert.ok(action,difficulty); assert.equal(action.type,'truthAnswer',difficulty); assert.ok(view.truthBribeAnswers?.includes(action.answer as 'yes'|'no'),difficulty); assert.doesNotThrow(()=>act(game,'emperor',action),difficulty); } game=act(game,'emperor',{type:'truthAnswer',answer}); const commitment=game.bribePromises!.find(row=>row.player==='emperor')!; game=advance(game,state=>player(state,'richese').hand.some(card=>card.id===SEMUTA_DRUG_ID) && !!state.auction && state.auction.active==='emperor' && clean(state)); assert.ok(game.bribePromises?.some(row=>row.event===commitment.event && !row.fulfilled && !row.released)); assert.deepEqual(inventory(game),originalCards); return {game,kull,karama,counter,event:commitment.event,originalCards}; } function declare(f:ReturnType) { let game=act(f.game,'harkonnen',{type:'card',mode:'purchase',card:f.counter}); assert.equal(game.pendingKull?.stage,'offer'); const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction); assert.ok(reaction.plays.some(row=>row.card.id===f.kull && !row.blocked)); game=act(game,'choam',{type:'kullDecision',event:reaction.event,source:'printed',card:f.kull}); assert.equal(game.pendingKull?.stage,'counter'); return game; } function resolveSemuta(game:Game,card:string,claim:boolean):Game { const pending=game.pendingTreacheryDiscard; assert.ok(pending); assert.equal(pending.reaction?.stage,'offer'); assert.equal(pending.batch.entries[0].card.id,card); const event=pending.batch.event; for (const difficulty of DIFFICULTIES) { const view=viewGame(game,'richese'); view.players.find(row=>row.id==='richese')!.bot=difficulty; const action=botActions(view)[0]; assert.ok(action,difficulty); assert.ok(['semutaPass','semutaCommit'].includes(action.type),difficulty); assert.doesNotThrow(()=>act(game,'richese',action),difficulty); } 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 claim of [false,true]) void test(`Basic bribe Yes survives Kull success and Semuta ${claim?'claim':'pass'}`,()=>{ const f=fixture(); let game=declare(f); assert.equal(viewGame(game,'emperor').bribePromiseGuide,null); game=advance(game,state=>!!state.pendingTreacheryDiscard); assert.ok(game.bribePromises?.some(row=>row.event===f.event && !row.fulfilled && !row.released)); game=resolveSemuta(game,f.kull,claim); game=advance(game,clean); assert.ok(game.bribePromises?.some(row=>row.event===f.event && !row.fulfilled && !row.released)); 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.ok(game.bribePromises?.some(row=>row.event===f.event && row.fulfilled)); assert.equal(player(game,'guild').bribes,2); assert.equal(player(game,'richese').hand.some(card=>card.id===f.kull),claim); assert.deepEqual(inventory(game),f.originalCards); }); for (const claim of [false,true]) void test(`Basic bribe Yes survives Kull counter and Semuta ${claim?'claim':'pass'}`,()=>{ const f=fixture(); let game=declare(f); assert.ok(viewGame(game,'emperor').responseControls?.cancelCards?.includes(f.karama)); game=act(game,'emperor',{type:'card',mode:'cancel',card:f.karama}); game=resolveSemuta(game,f.karama,claim); game=advance(game,clean); assert.ok(game.bribePromises?.some(row=>row.event===f.event && !row.fulfilled && !row.released)); 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.ok(game.bribePromises?.some(row=>row.event===f.event && row.fulfilled)); assert.equal(player(game,'guild').bribes,2); assert.equal(player(game,'richese').hand.some(card=>card.id===f.karama),claim); assert.deepEqual(inventory(game),f.originalCards); }); void test('Basic bribe No retains its cap through Kull and Semuta',()=>{ const f=fixture('no'); let game=declare(f); game=advance(game,state=>!!state.pendingTreacheryDiscard); game=resolveSemuta(game,f.kull,false); game=advance(game,clean); const before=structuredClone(game); assert.throws(()=>act(game,'emperor',{type:'bribe',target:'guild',amount:2} as Action)); assert.deepEqual(game,before); game=act(game,'emperor',{type:'bribe',target:'guild',amount:1}); assert.equal(player(game,'guild').bribes,1); assert.ok(!game.bribePromises?.find(row=>row.event===f.event)?.released); });