import assert from 'node:assert/strict'; import test from 'node:test'; import { botActions } from '../game/bots'; import { DIFFICULTIES } from '../game/bot-profiles'; import { viewGame, type Action, type Game } from '../game/engine'; import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, createTruthtranceRichesePromisesFixture, passTruthRicheseFreshDiscard, truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, } from './fixture-truthtrance-richese-promises'; type Method = 'onceAround' | 'silent'; type QuestionKind = 'richeseBid' | 'mixedRicheseBid'; /** Original Advanced R/A/E setup, starting deal and Charity. Only the * fixture's disclosed unopened deal/Spice order and scalar rolls are staged; * Richese offers the physical Shield actually dealt into its own hand. */ function fixture(method: Method) { const source = createTruthtranceRichesePromisesFixture({advanced:true}); let game = advance(structuredClone(source.earlySource), state => state.decision?.kind === 'richeseBlackMarket'); const card = source.targetCard, event = game.richeseBidding!.event; assert.ok(player(game,source.richese).hand.some(held => held.id === card)); game = act(game,source.richese,{type:'decision',event,card,method, ...(method === 'onceAround' ? {direction:'clockwise'} : {})}); while (game.response) { const seat = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(seat); game = act(game,seat.id,{type:'passResponse'}); } assert.equal(game.richeseAuction?.source,'blackMarket'); assert.equal(game.richeseAuction?.method,method); assert.equal(viewGame(game,source.richese).richeseAuction?.card?.id,card); assert.equal(viewGame(game,source.asker).richeseAuction?.card?.id,game.richesePeekKnown ? card : undefined); assert.equal(viewGame(game,source.emperor).richeseAuction?.card,null); assert.ok(player(game,source.asker).hand.some(held => held.id === source.truth)); assert.deepEqual(inventory(game),source.originalCards); return {game,asker:source.asker,target:source.emperor,owner:source.richese, truth:source.truth,card,lot:game.richeseAuction!.event,originalCards:source.originalCards}; } function reject(game:Game,actor:string,action:Action) { const before=structuredClone(game); assert.throws(() => act(game,actor,action)); assert.deepEqual(game,before); } function ask(f:ReturnType,kind:QuestionKind) { let game=act(f.game,f.asker,{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'}); } assert.equal(game.truthtrance?.stage,'ask'); const question = kind === 'richeseBid' ? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:4} : {kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[ {kind:'fact',fact:{kind:'spice',compare:'gte',value:10}}, {kind:'action',action:{minimum:4}}, ]}}; return act(game,f.asker,{type:'truthAsk',question}); } for (const method of ['onceAround','silent'] as const) for (const kind of ['richeseBid','mixedRicheseBid'] as const) for (const answer of ['yes','no'] as const) void test( `Advanced ${method} Black Market ${kind} ${answer} retains the original sale`,() => { const f=fixture(method), asked=ask(f,kind); assert.equal(viewGame(asked,f.asker).richeseAuction?.card?.id,asked.richesePeekKnown ? f.card : undefined); assert.equal(viewGame(asked,f.target).richeseAuction?.card,null); assert.equal(viewGame(asked,f.owner).richeseAuction?.card?.id,f.card); const answerView=viewGame(asked,f.target); const answers=kind === 'richeseBid' ? answerView.truthRicheseBidAnswers : answerView.truthMixedRicheseBidAnswers; assert.ok(answers?.includes(answer)); assert.equal(player(asked,f.target).spice,10); for (const difficulty of DIFFICULTIES) { const botView=viewGame(asked,f.target); botView.players.find(row => row.id === f.target)!.bot=difficulty; const choice=botActions(botView)[0]; assert.equal(choice?.type,'truthAnswer',difficulty); assert.ok(answers?.includes(choice.answer as 'yes'|'no'|'unknown')); } let game=passTruthRicheseFreshDiscard(act(asked,f.target,{type:'truthAnswer',answer})); assert.equal(game.richeseAuction?.event,f.lot); assert.ok(player(game,f.owner).hand.some(held => held.id === f.card)); if (method === 'onceAround') { while (game.richeseAuction?.event === f.lot && game.richeseAuction.active !== f.target) { const actor=game.richeseAuction.active; assert.ok(actor); assert.notEqual(actor,f.owner); game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null}); } } const guide=viewGame(game,f.target).richeseBidPromiseGuide; assert.ok(guide); reject(game,f.target,{...guide.action,richeseBidPromiseId:'stale-promise'}); reject(game,f.target,{type:'richeseBid',event:f.lot,amount:answer === 'yes' ? 3 : 4,allyPayment:0}); const amount=answer === 'yes' ? 4 : 2; const beforeBuyer=player(game,f.target).spice, beforeSeller=player(game,f.owner).spice; game=act(game,f.target,{type:'richeseBid',event:f.lot,amount,allyPayment:0}); assert.equal(player(game,f.target).spice,beforeBuyer,'Declaring does not pay the winning invoice'); if (method === 'silent') { assert.equal(viewGame(game,f.target).richeseAuction?.ownBid,amount); assert.equal(viewGame(game,f.owner).richeseAuction?.ownBid,null); assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null); assert.ok(player(game,f.owner).hand.some(held => held.id === f.card)); for (const id of [f.asker,f.owner]) game=act(game,id,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0}); } else { while (game.richeseAuction?.event === f.lot && !game.richeseAuction.outcome) { const actor=game.richeseAuction.active; assert.ok(actor); game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null}); } } assert.ok(player(game,f.target).hand.some(held => held.id === f.card)); assert.ok(!player(game,f.owner).hand.some(held => held.id === f.card)); assert.equal(player(game,f.target).spice,beforeBuyer-amount); assert.equal(player(game,f.owner).spice,beforeSeller+amount); assert.equal(game.discard.filter(held => held.id === f.truth).length,1); assert.deepEqual(inventory(game),f.originalCards); }); for (const method of ['onceAround','silent'] as const) void test( `Advanced ${method} seller honors a Truthtrance Yes and retains its physical Black Market card`,() => { const original=fixture(method); let game=original.game; if (method === 'onceAround') { const first=game.richeseAuction!.active; assert.ok(first); assert.notEqual(first,original.owner); game=act(game,first,{type:'richeseBid',event:original.lot,amount:1,allyPayment:0}); } const f={...original,game,target:original.owner}; const asked=ask(f,'richeseBid'); assert.ok(viewGame(asked,f.target).truthRicheseBidAnswers?.includes('yes')); game=passTruthRicheseFreshDiscard(act(asked,f.target,{type:'truthAnswer',answer:'yes'})); const beforeHand=player(game,f.owner).hand.map(card => card.id); const beforeSeller=player(game,f.owner).spice, beforeEmperor=player(game,original.target).spice; if (method === 'onceAround') { while (game.richeseAuction?.event === f.lot && game.richeseAuction.active !== f.owner) { const actor=game.richeseAuction.active; assert.ok(actor); game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null}); } } const guide=viewGame(game,f.owner).richeseBidPromiseGuide; assert.ok(guide); assert.equal(guide.action.amount,4); game=act(game,f.owner,guide.action); if (method === 'silent') { assert.equal(viewGame(game,f.asker).richeseAuction?.ownBid,null); assert.equal(viewGame(game,f.asker).richeseAuction?.revealedBids,null); assert.deepEqual(player(game,f.owner).hand.map(card => card.id),beforeHand); for (const actor of [f.asker,original.target]) game=act(game,actor,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0}); } assert.deepEqual(player(game,f.owner).hand.map(card => card.id),beforeHand); assert.equal(player(game,f.owner).spice,beforeSeller-4); assert.equal(player(game,original.target).spice,beforeEmperor+4); assert.equal(game.richeseBidding?.blackMarketSold,true); assert.deepEqual(inventory(game),f.originalCards); });