Files
Dune/tests/kull-whole-auction-owner-guard.test.ts
T
Quintine 07f1f1f2ae
Verify and publish checkpoint container / container (push) Successful in 10m21s
Support whole-turn answers with Basic Kull
2026-10-29 01:37:33 +11:00

90 lines
5.6 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createGame, joinGame, newPlayer, viewGame, type Game } from '../game/engine';
import { windowCardOpportunity } from '../game/window-card-play';
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
import { act, advance, clean, inventory, player } from './fixture-kull-richese-semuta';
/** Genuine Basic setup and Richese cache purchase. Only unopened deal and
* Spice positions are selected; all answers, payments and auctions are real. */
function source() {
let game=createGame('KULLWHOLEAUCTION',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 p of game.players) game=act(game,p.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 [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));
const safe=game.spiceDeck.findIndex(card=>'territory' in card && !card.discovery); assert.ok(safe>=0);
game.spiceDeck.unshift(game.spiceDeck.splice(safe,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));
const window=windowCardOpportunity(game,'karamaAuction'); assert.ok(window);
const lot=game.auction!.cards[game.auction!.index].id;
assert.deepEqual(inventory(game),originalCards);
return {game,kull,karama,truth,window,lot,originalCards};
}
function passDiscard(game:Game):Game {
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
const event=pending.batch.event;
for (let count=0;game.pendingTreacheryDiscard?.batch.event===event && count<game.players.length;count++) {
const reaction=game.pendingTreacheryDiscard!.reaction; assert.ok(reaction?.stage==='offer');
const seat=game.players.find(row=>!reaction.passed.includes(row.id)); assert.ok(seat);
game=act(game,seat.id,{type:'semutaPass',event});
}
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
return game;
}
function answer(f:ReturnType<typeof source>,mixed:unknown,value:'yes'|'no') {
let game=act(f.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'});
}
game=act(game,'guild',{type:'truthAsk',question:{kind:'turnActions',target:'emperor',turn:game.turn,mixed}});
assert.ok(viewGame(game,'emperor').truthTurnActionAnswers?.includes(value));
game=act(game,'emperor',{type:'truthAnswer',answer:value});
const row=game.turnActionPromises!.at(-1); assert.ok(row);
if (game.pendingTreacheryDiscard) game=passDiscard(game);
return {game,event:row.event};
}
for (const decline of [true,false]) void test(`an unrelated whole payment remains legal through Karama purchase and Kull ${decline?'decline':'success'}`,()=>{
const f=source(); const {game:initialGame,event}=answer(f,{kind:'action',action:{kind:'payment',recipient:'guild',minimum:2}},'yes'); let game=initialGame;
game=act(game,'emperor',{type:'card',mode:'purchase',card:f.karama});
const reaction=viewGame(game,'choam').kullReaction; assert.ok(reaction);
game=decline ? act(game,'choam',{type:'kullDecision',event:reaction.event,decline:true}) :
act(game,'choam',{type:'kullDecision',event:reaction.event,source:'printed',card:f.kull});
if (!decline) game=advance(game,state=>!!state.pendingTreacheryDiscard);
if (game.pendingTreacheryDiscard) game=passDiscard(game);
game=advance(game,clean);
assert.ok(!game.turnActionPromises!.find(row=>row.event===event)?.released);
if (decline) assert.ok(player(game,'emperor').hand.some(card=>card.id===f.lot));
else assert.ok(player(game,'emperor').hand.some(card=>card.id===f.karama));
game=act(game,'emperor',{type:'bribe',target:'guild',amount:2});
assert.equal(game.turnActionPromises!.find(row=>row.event===event)?.fulfilled,true);
assert.equal(player(game,'guild').bribes,2);
assert.deepEqual(inventory(game),f.originalCards);
});
void test('a whole No to the original auction Karama rejects the printed purchase before Kull',()=>{
const f=source(); const {game:initialGame,event}=answer(f,{kind:'action',action:{kind:'windowCardPlay',
effect:'karamaAuction',source:f.window.source}},'no'); let game=initialGame;
const before=structuredClone(game);
assert.throws(()=>act(game,'emperor',{type:'card',mode:'purchase',card:f.karama}));
assert.deepEqual(game,before);
assert.equal(game.pendingKull ?? null,null);
game=act(game,'emperor',{type:'bid',amount:1,allyPayment:0});
assert.ok(!game.turnActionPromises!.find(row=>row.event===event)?.released);
assert.deepEqual(inventory(game),f.originalCards);
});