import assert from 'node:assert/strict'; import test from 'node:test'; import { viewGame, type Game } from '../game/engine'; import { botActions } from '../game/bots'; import { DIFFICULTIES } from '../game/bot-profiles'; import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, askTruthtranceRichesePromises as ask, createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard, truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, } from './fixture-truthtrance-richese-promises'; /** Original Basic setup and Charity; the original Box is exchanged with the * respondent's held card and two original unopened cards are moved to the * discard to make the paid search a genuine multi-choice decision. */ function source(minimum: number) { const f = fixture({advanced:false}); let game = structuredClone(f.earlySource); const owner = player(game,f.emperor), cache = game.richeseCache!; const index = cache.findIndex(card => card.effect === 'nullentropyBox'); assert.ok(index >= 0); const [box] = cache.splice(index,1), [exchange] = owner.hand.splice(0,1); owner.hand.push(box); cache.push(exchange); for (let n = 0; n < 2; n++) { const card = game.deck.shift(); assert.ok(card); game.discard.push(card); } const original = inventory(game); assert.equal(owner.spice,10); game = ask(game,f,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum}); assert.ok(viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes')); game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'})); return {f,game,box:box.id,original}; } function promise(g: Game, playerId: string) { const row = g.phaseAnyBidPromises?.find(item => item.player === playerId); assert.ok(row); return row; } void test('a paid Box search cannot voluntarily spend the last funds for an all-auction Yes', () => { const f = source(10), before = structuredClone(f.game); assert.throws(() => act(f.game,f.f.emperor,{type:'card',card:f.box})); assert.deepEqual(f.game,before); assert.equal(player(f.game,f.f.emperor).spice,10); assert.equal(!!promise(f.game,f.f.emperor).released,false); assert.deepEqual(inventory(f.game),f.original); }); void test('an affordable Box search can finish while preserving the all-auction Yes', () => { const f = source(8); let game = act(f.game,f.f.emperor,{type:'card',card:f.box}); assert.equal(player(game,f.f.emperor).spice,8); assert.equal(game.decision?.kind,'nullentropy'); const pending = game.pendingNullentropy; assert.ok(pending); const card = game.discard.find(item => item.effect !== 'nullentropyBox'); assert.ok(card); game = act(game,f.f.emperor,{type:'decision',event:pending.event,card:card.id}); game = passTruthRicheseFreshDiscard(game); assert.equal(game.pendingNullentropy,null); assert.equal(player(game,f.f.emperor).spice,8); assert.equal(!!promise(game,f.f.emperor).released,false); assert.equal(!!promise(game,f.f.emperor).fulfilled,false); assert.deepEqual(inventory(game),f.original); }); void test('a No-only Silent guide waits while bots answer a real Emperor gift response', () => { const f = fixture({advanced:false}); let game = structuredClone(f.earlySource); // Stage mutual alliance; move an existing unopened Karama into Richese's // hand so the real gift response remains open for that player. player(game,f.emperor).ally = f.richese; player(game,f.richese).ally = f.emperor; game = ask(game,f,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:4}); assert.ok(viewGame(game,f.richese).truthPhaseAnyBidAnswers?.includes('no')); game = passTruthRicheseFreshDiscard(act(game,f.richese,{type:'truthAnswer',answer:'no'})); game = advance(game,state => clean(state) && !!state.richeseAuction && state.richeseAuction.source === 'cache' && !state.richeseAuction.outcome, [],{position:'first',method:'silent'}); const index = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0); const [karama] = game.deck.splice(index,1); player(game,f.richese).hand.push(karama); const physical = inventory(game); assert.equal(viewGame(game,f.richese).phaseAnyBidGuide?.action.type,'richeseBid'); game = act(game,f.emperor,{type:'emperorGift',amount:1}); assert.equal(game.response?.kind,'emperorGift'); assert.equal(viewGame(game,f.richese).phaseAnyBidGuide,null); for (const difficulty of DIFFICULTIES) { const view = viewGame(game,f.richese); view.players.find(row => row.id === f.richese)!.bot = difficulty; const action = botActions(view)[0]; assert.ok(action,difficulty); assert.notEqual(action.type,'richeseBid'); assert.doesNotThrow(() => act(game,f.richese,action)); } assert.deepEqual(inventory(game),physical); });