import assert from 'node:assert/strict'; import test from 'node:test'; import { advanceAuctionClock, synchronizeAuctionClock, viewGame, type Game } from '../game/engine'; import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard, truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, } from './fixture-truthtrance-richese-promises'; /** Original Advanced R/A/E public start. The second original Truthtrance and * original Semuta move from unopened zones. A real Semuta claim returns the * first discarded Truthtrance for the third question; no player purse, phase, * auction, clock or commitment is installed by the fixture. */ function source() { const f=fixture({advanced:true}); let game:Game=structuredClone(f.earlySource); const truthAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(truthAt >= 0); const [second]=game.deck.splice(truthAt,1); player(game,f.asker).hand.push(second); const semutaAt=game.richeseCache!.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt >= 0); const [semuta]=game.richeseCache!.splice(semutaAt,1); player(game,f.richese).hand.push(semuta); assert.deepEqual(inventory(game),f.originalCards); function ask(asker:string,card:string,question:Record,claim=false) { game=act(game,asker,{type:'card',card}); game=advance(game,state => state.truthtrance?.stage === 'ask'); game=act(game,asker,{type:'truthAsk',question}); game=act(game,f.emperor,{type:'truthAnswer',answer:'yes'}); if (!claim) { game=passTruthRicheseFreshDiscard(game); return; } const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction); assert.ok(viewGame(game,f.richese).semutaReaction?.canCommit); game=act(game,f.richese,{type:'semutaCommit',event:pending.batch.event}); if (game.pendingTreacheryDiscard?.reaction?.stage === 'select') game=act(game,f.richese,{type:'semutaSelect',event:pending.batch.event,card}); assert.ok(player(game,f.richese).hand.some(item => item.id === card)); } ask(f.asker,f.truth,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:4},true); ask(f.asker,second.id,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:6}); const phase=game.phaseAnyBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(phase); const early=game.earlyRicheseBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(early); game=advance(game,state => state.decision?.kind === 'richeseBlackMarket'); game=act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,card:f.targetCard, method:'onceAround',direction:'clockwise'}); while (game.response) { const actor=game.players.find(seat => !game.response!.passed.includes(seat.id)); assert.ok(actor); game=act(game,actor.id,{type:'passResponse'}); } game=advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor); const lot=game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket' && lot.clockVersion === 1); ask(f.richese,f.truth,{kind:'richeseBid',target:f.emperor,turn:game.turn,event:lot.event,minimum:4}); const native=game.richeseBidPromises?.find(row => row.player === f.emperor && row.event === lot.event && row.answer); assert.ok(native); assert.deepEqual(inventory(game),f.originalCards); return {game,f,event:lot.event,phase,early,native}; } void test('Advanced Once Around market clock executes the shared three-way guide once',() => { const s=source(), view=viewGame(s.game,s.f.emperor); const guide=view.richeseBidPromiseGuide?.action; assert.ok(guide && view.phaseAnyBidGuide); assert.deepEqual(guide,view.phaseAnyBidGuide.action); assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,s.event); assert.equal(guide.amount,4); assert.equal(guide.richeseBidPromiseId,s.native.id); assert.equal(guide.earlyRicheseBidPromiseId,s.early.id); assert.equal(guide.phaseAnyBidPromiseEvent,s.phase.event); assert.equal(player(s.game,s.f.emperor).spice,10); const armed=synchronizeAuctionClock(s.game,1_000,'advanced-three-ledger'); const expired=advanceAuctionClock(armed,11_000,'advanced-three-ledger'); assert.equal(expired.richeseAuction?.event,s.event); assert.equal(expired.richeseAuction?.bidder,s.f.emperor); assert.equal(expired.richeseAuction?.bid,4); assert.equal(expired.richeseFunding?.[s.f.emperor]?.amount,4); assert.equal(player(expired,s.f.emperor).spice,10,'A bid is reserved before payment'); assert.ok(expired.richeseBidPromises?.some(row => row.id === s.native.id && row.fulfilled)); assert.ok(expired.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled)); assert.ok(expired.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released)); const again=advanceAuctionClock(expired,11_000,'advanced-three-ledger'); assert.equal(again.richeseAuction?.bid,4); assert.equal(again.richeseAuction?.acted.filter(id => id === s.f.emperor).length,1); assert.equal(again.richeseFunding?.[s.f.emperor]?.amount,4); let game=advance(again,state => player(state,s.f.emperor).hand.some(card => card.id === s.f.targetCard)); assert.equal(player(game,s.f.emperor).spice,6); game=advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' && state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'}); assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.boundEvent,game.richeseAuction!.event); const cache=viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(cache); assert.equal(cache.amount,6); game=act(game,s.f.emperor,cache); assert.ok(game.richeseBidPromises?.some(row => row.id === s.early.id && row.fulfilled)); const cacheCard=game.richeseAuction!.cardId; game=advance(game,state => player(state,s.f.emperor).hand.some(card => card.id === cacheCard), [],{position:'first',method:'silent'}); assert.equal(player(game,s.f.emperor).spice,0); assert.deepEqual(inventory(game),s.f.originalCards); });