import assert from 'node:assert/strict'; import test from 'node:test'; import { viewGame, type Game } from '../game/engine'; import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard, truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, type TruthtranceRichesePromisesFixture, } from './fixture-truthtrance-richese-promises'; /** Real public Advanced R/A/E setup and real native Black Market. Two original * cards move from unopened zones: the second Truthtrance to Atreides, Semuta * to Richese. Richese actually reclaims the first discarded Truthtrance with * Semuta to ask the third question; no extra physical card is invented. */ function source() { const f = fixture({advanced:true}), 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); return {f,game,second:second.id,semuta:semuta.id}; } function ask(game:Game, f:TruthtranceRichesePromisesFixture, asker:string, card:string, kind:'phaseAnyBid'|'earlyRicheseBid', minimum:number, answer:'yes'|'no', claim = false) { game = act(game,asker,{type:'card',card}); game = advance(game,state => state.truthtrance?.stage === 'ask'); game = act(game,asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum}}); const view = viewGame(game,f.emperor); const options = kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers; assert.ok(options?.includes(answer),`${kind} ${answer} must retain its native witness`); game = act(game,f.emperor,{type:'truthAnswer',answer}); if (!claim) return passTruthRicheseFreshDiscard(game); const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction); assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true); game = act(game,f.richese,{type:'semutaCommit',event:pending.batch.event}); assert.equal(game.pendingTreacheryDiscard,null); assert.ok(player(game,f.richese).hand.some(item => item.id === card)); return game; } void test('Advanced unresolved Black Market releases only the phase Yes made impossible by an external shortfall', () => { const s = source(); let game = ask(s.game,s.f,s.f.asker,s.f.truth,'phaseAnyBid',4,'yes',true); assert.ok(game.discard.some(card => card.id === s.semuta)); game = ask(game,s.f,s.f.asker,s.second,'phaseAnyBid',8,'yes'); game = ask(game,s.f,s.f.richese,s.f.truth,'earlyRicheseBid',4,'no'); assert.equal(player(game,s.f.emperor).spice,10); const phase4 = game.phaseAnyBidPromises?.find(row => row.player === s.f.emperor && row.minimum === 4); const phase8 = game.phaseAnyBidPromises?.find(row => row.player === s.f.emperor && row.minimum === 8); const early = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(phase4 && phase8 && early && !early.answer); assert.deepEqual(inventory(game),s.f.originalCards); game = advance(game,state => state.decision?.kind === 'richeseBlackMarket'); game = act(game,s.f.richese,{type:'decision',event:game.richeseBidding!.event, card:s.f.targetCard,method:'silent'}); 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'}); } assert.equal(game.richeseAuction?.source,'blackMarket'); const event = game.richeseAuction!.event; // Controlled external-loss supplement: the three answers and the actual // market are native; this models another effect reducing the target's cash // before a different player's real sealed decline. No card/receipt changes. game = structuredClone(game); player(game,s.f.emperor).spice = 5; const before = structuredClone(game), actor = s.f.asker; assert.notEqual(actor,s.f.emperor); game = act(game,actor,{type:'richeseBid',event,amount:0,allyPayment:0}); assert.equal(player(before,s.f.emperor).spice,5); const lower = game.phaseAnyBidPromises?.find(row => row.event === phase4.event); const higher = game.phaseAnyBidPromises?.find(row => row.event === phase8.event); assert.ok(lower && higher); assert.equal(!!lower.fulfilled,false); assert.equal(!!lower.released,false, 'The affordable four-spice Black Market declaration remains available'); assert.equal(!!higher.fulfilled,false); assert.equal(!!higher.released,true, 'Only the independently impossible eight-spice answer releases'); assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === early.id && !row.released && !row.boundEvent)); assert.equal(game.richeseAuction?.event,event); assert.equal(viewGame(game,s.f.richese).richeseAuction?.revealedBids,null); const guide = viewGame(game,s.f.emperor).phaseAnyBidGuide?.action; assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,event); assert.equal(guide.amount,4); game = act(game,s.f.emperor,guide); assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase4.event && row.fulfilled)); assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase8.event && row.released)); assert.deepEqual(inventory(game),s.f.originalCards); });