Support phase-wide bidding across all auctions
Verify and publish checkpoint container / container (push) Successful in 12m14s

This commit is contained in:
Quintine committed 2026-11-16 19:17:36 +11:00
1 parent 12060f3112
commit 38f1684e03
17 files changed
+1070 -18

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises';
import { createGame, joinGame, newPlayer, viewGame, type Action, type GameView } from '../game/engine';
import { createRicheseAuction, projectRicheseAuction } from '../game/richese-auction';
/** Controlled view tests verify only display and exact callback guards; native
* public-start question, auction and payment evidence belongs to runtime tests. */
function projected(): GameView {
const source = createGame('PHASEANYBIDCONTROLS',newPlayer('p','Respondent','emperor'),false);
joinGame(source,newPlayer('a','Asker','atreides'));
const game = viewGame(source,'p');
game.status = 'playing'; game.phase = 3; game.turn = 2;
game.auction = {bid:1,bidder:'a',active:'p',remaining:2,inspectionBlocked:null,card:null};
game.bidPromiseLot = {turn:2,lot:1};
game.phaseAnyBidPromises = [{turn:2,minimum:4,event:'promise',player:'p',asker:'a',answer:true}];
game.phaseAnyBidGuide = {action:{type:'bid',amount:4,allyPayment:0,
phaseAnyBidPromiseEvent:'promise',phaseAnyBidLot:1}};
return game;
}
void test('any-auction promise describes all auction sources and exact owned ordinary guide', () => {
const game = projected(), sent: Action[] = [];
const markup = renderToStaticMarkup(createElement(PhaseAnyBidPromises,{game,busy:false,send() {}}));
assert.match(markup,/ordinary, Richese cache, or Black Market auction/);
assert.match(markup,/Some combinations with other bidding commitments remain unavailable/);
const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button);
button.props.onClick(); assert.deepEqual(sent,[game.phaseAnyBidGuide!.action]);
game.auction!.bid = 2; button.props.onClick(); assert.equal(sent.length,1);
});
void test('busy, completed, wrong owner and stale ordinary guide callbacks do not send', () => {
const game = projected(), sent: Action[] = [];
const busy = PhaseAnyBidGuideButton({game,busy:true,send:action => sent.push(action)}); assert.ok(busy);
assert.equal(busy.props.disabled,true); busy.props.onClick();
const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button);
game.phaseAnyBidPromises[0].fulfilled = true; button.props.onClick();
game.phaseAnyBidPromises[0].fulfilled = false; game.auction!.active = 'a'; button.props.onClick();
game.auction!.active = 'p'; game.bidPromiseLot!.lot = 2; button.props.onClick();
assert.deepEqual(sent,[]);
});
for (const method of ['onceAround','silent'] as const) void test(`the ${method} guide checks its exact Richese lot and submission state`, () => {
const game = projected(), sent: Action[] = [];
game.auction = null;
const native = createRicheseAuction({event:'lot',cardId:'card',source:'cache',owner:'a',method,
eligible:['p','a'],order:['p','a'],tieOrder:['p','a']});
game.richeseAuction = {...projectRicheseAuction(native,'p'),card:null,claim:null,
ownAllyPayment:0,ownAvailable:5,allyAvailable:0,peekKnown:false,inspectionBlocked:null};
game.phaseAnyBidGuide = {action:{type:'richeseBid',event:'lot',amount:4,allyPayment:0,
phaseAnyBidPromiseEvent:'promise',phaseAnyBidLotEvent:'lot'}};
const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button);
button.props.onClick(); assert.equal(sent.length,1);
if (method === 'silent') game.richeseAuction.submitted.push('p');
else game.richeseAuction.active = 'a';
button.props.onClick(); assert.equal(sent.length,1);
});
+48
View File
@@ -0,0 +1,48 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
PhaseAnyBidPromiseError, finishPhaseAnyBidPhase, parsePhaseAnyBidClaim,
phaseAnyBidClaimText, phaseAnyBidCompletionRange, recordPhaseAnyBid,
reconcilePhaseAnyBidPromises, validatePhaseAnyBidPromises,
type PhaseAnyBidPromise,
} from '../game/phase-any-bid-promises';
import { truthQuestionText, validateTruthQuestionReceipt, type TruthQuestion } from '../game/truthtrance';
import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid';
const row = (event:string, minimum:number, answer:boolean): PhaseAnyBidPromise =>
({event,minimum,answer,turn:2,player:'p',asker:'a'});
void test('all-auction claim validates a safe threshold and explicitly includes special lots', () => {
const claim = parsePhaseAnyBidClaim({turn:2,minimum:5});
assert.deepEqual(claim,{turn:2,minimum:5});
assert.match(phaseAnyBidClaimText(claim),/ordinary, Richese cache, or Black Market auction/);
for (const value of [null, [], {}, {turn:2,minimum:0}, {turn:NaN,minimum:1},
{turn:2,minimum:Number.MAX_SAFE_INTEGER+1}, {turn:'2',minimum:1}])
assert.throws(() => parsePhaseAnyBidClaim(value),PhaseAnyBidPromiseError);
});
void test('all-auction ledger preserves distinct physical declarations and No restrictions', () => {
const source = [row('yes',5,true),row('no',8,false)];
assert.doesNotThrow(() => validatePhaseAnyBidPromises(source,['p','a']));
const opportunity = {turn:2,player:'p',kind:'current' as const,minimum:2,maximum:9};
assert.deepEqual(phaseAnyBidCompletionRange(source,opportunity),{minimum:5,maximum:7});
const small = recordPhaseAnyBid(source,'p',2,3);
assert.equal(small[0].fulfilled,undefined);
assert.throws(() => recordPhaseAnyBid(small,'p',2,8),PhaseAnyBidPromiseError);
const bound = recordPhaseAnyBid(small,'p',2,5);
assert.equal(bound[0].fulfilled,true);
assert.equal(finishPhaseAnyBidPhase(bound,'p',2,'external')[1].fulfilled,true);
assert.throws(() => reconcilePhaseAnyBidPromises(source,'p',2,[],'voluntary'),PhaseAnyBidPromiseError);
assert.equal(reconcilePhaseAnyBidPromises(source,'p',2,[],'external')[0].released,true);
assert.equal(source[0].fulfilled,undefined);
});
void test('all-auction question retains a distinct wire kind at a real cache lot', () => {
const f = createTruthRicheseBidFixture(false);
const question: TruthQuestion = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:4};
assert.doesNotThrow(() => validateTruthQuestionReceipt(f.game,f.asker,question));
assert.match(truthQuestionText(question,id => id,id => id,id => id),/Richese cache, or Black Market/);
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,turn:f.game.turn+1}));
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,event:f.lot} as TruthQuestion));
assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,minimum:0}));
});
@@ -0,0 +1,61 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame } from '../game/engine';
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';
/** Real Advanced setup and early question; the shared source selects only
* unopened deal/Spice cards and native scalar rolls. No purse, answer, lot,
* commitment, card location or force is injected for this scenario. */
void test('Richese all-auction Yes survives an unbid Black Market and is fulfilled in its actual later cache', () => {
const f = fixture({advanced:true});
const asked = ask(structuredClone(f.earlySource),f,
{kind:'phaseAnyBid',target:f.richese,turn:f.earlySource.turn,minimum:4});
assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes'));
let game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'}));
const receipt = game.phaseAnyBidPromises?.find(row => row.player === f.richese); assert.ok(receipt);
const event = receipt.event, originalSpice = player(game,f.richese).spice;
const before = inventory(game);
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,
card:f.targetCard,method:'onceAround',direction:'clockwise'});
while (game.response) {
const responder = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(responder);
game = act(game,responder.id,{type:'passResponse'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
const lot = game.richeseAuction!.event;
while (game.richeseAuction?.event === lot && !game.richeseAuction.outcome) {
const active = game.richeseAuction.active; assert.ok(active);
assert.notEqual(active,f.richese,'Once Around seller has no turn when everyone else passes');
game = act(game,active,{type:'richeseBid',event:lot,amount:null,allyPayment:0});
}
const waiting = game.phaseAnyBidPromises?.find(row => row.event === event); assert.ok(waiting);
assert.equal(!!waiting.fulfilled,false);
assert.equal(!!waiting.released,false,'The mandatory cache remains a real future bid opportunity');
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
assert.equal(player(game,f.richese).spice,originalSpice);
assert.deepEqual(inventory(game),before);
game = advance(game,state => clean(state) && !!state.richeseAuction &&
state.richeseAuction.source === 'cache' && !state.richeseAuction.outcome,
[], {position:'first',method:'silent'});
assert.equal(game.phaseAnyBidPromises?.find(row => row.event === event)?.released,undefined);
const cacheEvent = game.richeseAuction!.event;
const guide = viewGame(game,f.richese).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.event,cacheEvent);
assert.equal(guide.action.amount,4);
game = act(game,f.richese,guide.action);
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === event)?.fulfilled,true);
assert.equal(player(game,f.richese).spice,originalSpice,'A sealed declaration does not pay early');
assert.equal(viewGame(game,f.emperor).richeseAuction?.revealedBids,null);
assert.deepEqual(inventory(game),before);
});
+399
View File
@@ -0,0 +1,399 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { advanceAuctionClock, hasAuctionClockOpportunity, synchronizeAuctionClock,
viewGame, type Action, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { createTruthAllianceFixture, declareTruthAlliance, finishTruthAlliance,
actTruthAlliance, truthAllianceInventory, truthAlliancePlayer } from './fixture-truth-alliance';
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';
type Method = 'normal' | 'onceAround' | 'silent';
type Source = ReturnType<typeof fixture>;
function reject(game: Game, actor: string, action: Action) {
const before = structuredClone(game);
assert.throws(() => act(game, actor, action));
assert.deepEqual(game, before);
}
function askAny(source: Game, f: Source) {
return ask(source, f, {kind:'phaseAnyBid', target:f.emperor, turn:source.turn, minimum:4});
}
function bindAny(asked: Game, f: Source, answer: 'yes'|'no') {
assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes(answer));
return passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer}));
}
function currentCache(game: Game, f: Source, method: Exclude<Method,'normal'>, position: 'first'|'last' = 'first') {
const options = {position,method};
let state = advance(game, g => clean(g) && !!g.richeseAuction &&
g.richeseAuction.source === 'cache' && !g.richeseAuction.outcome, [], options);
if (method === 'onceAround')
state = advance(state,g => clean(g) && g.richeseAuction?.active === f.emperor, [], options);
return state;
}
function blackMarket(game: Game, f: Source, method: Method) {
let state = advance(game,g => g.decision?.kind === 'richeseBlackMarket');
const card = f.targetCard, event = state.richeseBidding!.event;
assert.ok(player(state,f.richese).hand.some(item => item.id === card));
state = act(state,f.richese,{type:'decision',event,card,method,
...(method === 'onceAround' ? {direction:'clockwise'} : {})});
while (state.response) {
const actor = state.players.find(row => !state.response!.passed.includes(row.id)); assert.ok(actor);
state = act(state,actor.id,{type:'passResponse'});
}
assert.equal(state.richeseAuction?.source,'blackMarket');
return state;
}
function targetTurn(game: Game, f: Source, method: Method) {
if (method === 'silent') return game;
let state = game;
for (let n = 0; state.richeseAuction?.active !== f.emperor && n < 10; n++) {
const lot = state.richeseAuction; assert.ok(lot && !lot.outcome && lot.active);
// Keep the auction alive until the actual target's own opportunity.
state = act(state,lot.active,{type:'richeseBid',event:lot.event,amount:null});
}
assert.equal(state.richeseAuction?.active,f.emperor);
return state;
}
/** Genuine R/A/E setup and real turn-one Charity. The fixture stages only
* unopened original deal and Spice order plus native scalar rolls. */
for (const method of ['onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
void test(`Basic pre-Bidding all-auction ${answer} governs the first real ${method} cache declaration`, () => {
const f = fixture({advanced:false}), asked = askAny(structuredClone(f.earlySource),f);
let game = bindAny(asked,f,answer);
const live = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(live);
game = currentCache(game,f,method);
const lot = game.richeseAuction!;
const held = inventory(game), amount = answer === 'yes' ? 4 : 2;
if (answer === 'yes') {
for (const lower of [3,method === 'silent' ? 0 : null]) {
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:lower,allyPayment:0});
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
}
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
for (const difficulty of DIFFICULTIES) {
const bot = viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot = difficulty;
assert.deepEqual(botActions(bot)[0],guide.action);
}
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
const before = player(game,f.emperor).spice;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
const result = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(result);
assert.equal(!!result.fulfilled,answer === 'yes');
assert.equal(player(game,f.emperor).spice,before,'Declaring a bid is not the purchase invoice');
if (method === 'silent' && game.richeseAuction?.event === lot.event) {
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
}
assert.deepEqual(inventory(game),held);
const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId),
[], {position:'first',method});
assert.equal(player(purchased,f.emperor).spice,before-amount);
assert.ok(!purchased.richeseCache?.some(card => card.id === lot.cardId));
assert.deepEqual(inventory(purchased),held);
});
for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
void test(`Advanced current ${method} Black Market all-auction ${answer} preserves the seller card and native bid`, () => {
const f = fixture({advanced:true});
const source = blackMarket(structuredClone(f.earlySource),f,method);
const lot = source.richeseAuction!;
const asked = askAny(source,f);
let game = bindAny(asked,f,answer);
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
game = targetTurn(game,f,method);
const amount = answer === 'yes' ? 4 : 2;
if (answer === 'yes') {
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
const purse = player(game,f.emperor).spice, seller = player(game,f.richese).spice;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
assert.equal(player(game,f.emperor).spice,purse);
const row = game.phaseAnyBidPromises?.find(item => item.player === f.emperor); assert.ok(row);
assert.equal(!!row.fulfilled,answer === 'yes');
if (method === 'silent') {
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
}
assert.deepEqual(inventory(game),f.originalCards);
const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === f.targetCard));
assert.equal(player(purchased,f.emperor).spice,purse-amount);
assert.equal(player(purchased,f.richese).spice,seller+amount);
assert.ok(!player(purchased,f.richese).hand.some(card => card.id === f.targetCard));
assert.deepEqual(inventory(purchased),f.originalCards);
});
for (const method of ['onceAround','silent'] as const) void test(
`A saved ordinary-only phaseBid remains ordinary-only during a real ${method} cache lot`, () => {
const f = fixture({advanced:false});
const asked = ask(structuredClone(f.earlySource),f,{kind:'phaseBid',target:f.emperor,turn:f.earlySource.turn,minimum:4});
assert.ok(viewGame(asked,f.emperor).truthPhaseBidAnswers?.includes('no'));
let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'}));
game = currentCache(game,f,method);
const lot = game.richeseAuction!;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
const legacy = game.phaseBidPromises?.find(row => row.player === f.emperor); assert.ok(legacy);
assert.equal(legacy.answer,false); assert.equal(!!legacy.fulfilled,false);
assert.equal(!!legacy.released,false);
assert.deepEqual(inventory(game),f.originalCards);
});
for (const advanced of [false,true]) for (const method of ['onceAround','silent'] as const)
for (const answer of ['yes','no'] as const) void test(
`${advanced?'Advanced':'Basic'} current ${method} cache accepts an all-auction ${answer}`, () => {
const f = fixture({advanced});
const source = currentCache(structuredClone(f.earlySource),f,method);
const lot = source.richeseAuction!;
const asked = askAny(source,f);
let game = bindAny(asked,f,answer);
assert.ok(game.richeseCache?.some(card => card.id === lot.cardId));
const amount = answer === 'yes' ? 4 : 2;
if (answer === 'yes') {
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'});
reject(game,f.emperor,{...guide.action,phaseAnyBidLotEvent:'stale-lot'});
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes');
if (method === 'silent') {
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
}
assert.deepEqual(inventory(game),f.originalCards);
});
for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
void test(`Advanced pre-Bidding all-auction ${answer} binds an actual ${method} Black Market bid`, () => {
const f = fixture({advanced:true});
const asked = askAny(structuredClone(f.earlySource),f);
let game = bindAny(asked,f,answer);
game = blackMarket(game,f,method);
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
game = targetTurn(game,f,method);
const lot = game.richeseAuction!;
if (answer === 'yes') {
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
const amount = answer === 'yes' ? 4 : 2;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes');
assert.deepEqual(inventory(game),f.originalCards);
});
void test('Advanced all-auction Yes permits the Richese seller to retain its own Silent Black Market card', () => {
const f = fixture({advanced:true}), source = structuredClone(f.earlySource);
const asked = ask(source,f,{kind:'phaseAnyBid',target:f.richese,turn:source.turn,minimum:4});
assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes'));
let game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'}));
game = blackMarket(game,f,'silent');
const lot = game.richeseAuction!, originalHand = player(game,f.richese).hand.map(card => card.id);
const seller = player(game,f.richese).spice, emperor = player(game,f.emperor).spice;
const guide = viewGame(game,f.richese).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
game = act(game,f.richese,guide.action);
assert.equal(viewGame(game,f.asker).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.asker).richeseAuction?.revealedBids,null);
for (const actor of [f.asker,f.emperor])
game = act(game,actor,{type:'richeseBid',event:lot.event,amount:0,allyPayment:0});
assert.deepEqual(player(game,f.richese).hand.map(card => card.id),originalHand);
assert.equal(player(game,f.richese).spice,seller-4);
assert.equal(player(game,f.emperor).spice,emperor+4);
assert.equal(game.richeseBidding?.blackMarketSold,true);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.fulfilled));
assert.deepEqual(inventory(game),f.originalCards);
});
void test('Basic all-auction Yes follows the ordinary native bid guide and is fulfilled by its actual declaration', () => {
const f = fixture({advanced:false});
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,
[], {position:'first',method:'onceAround'});
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4);
reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'});
reject(game,f.emperor,{...guide.action,phaseAnyBidLot:999});
const before = player(game,f.emperor).spice;
game = act(game,f.emperor,guide.action);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
assert.equal(player(game,f.emperor).spice,before);
assert.deepEqual(inventory(game),f.originalCards);
});
void test('Basic all-auction No is fulfilled only at real Bidding close', () => {
const f = fixture({advanced:false});
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'no');
game = advance(game,state => state.phase > 3 && clean(state), [], {position:'first',method:'silent'});
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.answer && row.fulfilled && !row.released));
assert.deepEqual(inventory(game),f.originalCards);
});
/** Reach the last cache through a real earlier ordinary purchase. Richese has
* four spendable spice and its own eventual Once Around bid becomes possible
* only after the real Emperor's opening bid. No board, balance or lot is staged. */
function finalCache() {
const f = fixture({advanced:false}), options = {position:'last' as const,method:'onceAround' as const};
let game = advance(structuredClone(f.earlySource),state => clean(state) && !!state.auction,[],options);
assert.equal(game.auction?.active,f.richese);
game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0});
game = advance(game,state => clean(state) && state.phase === 3 && !!state.richeseAuction && !state.richeseAuction.outcome,[],options);
const lot = game.richeseAuction!;
assert.equal(lot.source,'cache'); assert.equal(lot.active,f.emperor);
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
assert.equal(game.richeseAuction?.active,f.asker);
const asked = ask(game,f,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:4});
assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes'));
game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'}));
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.answer && !row.fulfilled));
return {f,game,lot:lot.event};
}
void test('an actual opposing raise can externally release an impossible all-auction Yes at the final cache', () => {
const f = finalCache();
let game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0});
const promise = game.phaseAnyBidPromises?.find(row => row.player === f.f.richese); assert.ok(promise);
assert.equal(!!promise.released,true); assert.equal(!!promise.fulfilled,false);
assert.equal(game.richeseAuction?.active,f.f.richese);
game = act(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
assert.deepEqual(inventory(game),f.f.originalCards);
});
void test('an expiring final-cache clock makes the required all-auction Yes bid', () => {
const f = finalCache();
const game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
assert.equal(game.richeseAuction?.active,f.f.richese);
assert.ok(hasAuctionClockOpportunity(game));
reject(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
const guide = viewGame(game,f.f.richese).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
const armed = synchronizeAuctionClock(game,1_000,'phase-any-bid-test:0');
const expired = advanceAuctionClock(armed,11_000,'phase-any-bid-test:0');
assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.f.richese && row.answer && row.fulfilled));
assert.match(expired.log.at(-1)!.text,/legal bid required by their binding Truthtrance answer was submitted/);
assert.deepEqual(inventory(expired),f.f.originalCards);
});
for (const first of ['phaseBid','phaseAnyBid'] as const) void test(
`a live ${first} answer prevents an incompatible second bid-family question`, () => {
const f = fixture({advanced:false});
const source = structuredClone(f.earlySource);
const asked = ask(source,f,{kind:first,target:f.emperor,turn:source.turn,minimum:4});
let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'}));
// The original second physical Truth is moved from the unopened deck into
// its owner's hand solely to exercise two real questions in this same turn.
const index = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(index >= 0);
const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second);
assert.deepEqual(inventory(game),f.originalCards);
game = act(game,f.asker,{type:'card',card:second.id});
game = advance(game,state => state.truthtrance?.stage === 'ask');
const kind = first === 'phaseBid' ? 'phaseAnyBid' : 'phaseBid';
reject(game,f.asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum:5}});
});
for (const method of ['onceAround','silent'] as const) void test(
`a smaller ${method} cache bid preserves a later funded ordinary all-auction Yes`, () => {
const f = fixture({advanced:false}), options = {position:'first' as const,method};
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
game = currentCache(game,f,method);
const lot = game.richeseAuction!, spice = player(game,f.emperor).spice;
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released));
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,[],options);
assert.ok(player(game,f.emperor).hand.some(card => card.id === lot.cardId));
assert.equal(player(game,f.emperor).spice,spice-3);
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4);
game = act(game,f.emperor,guide.action);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
assert.deepEqual(inventory(game),f.originalCards);
});
for (const claim of [false,true]) void test(
`Advanced all-auction Truth answer offers Semuta and ${claim ? 'claim' : 'pass'} retains the bid and Black Market lot`, () => {
const f = fixture({advanced:true});
let source = structuredClone(f.earlySource);
// Conserved supplement: move the original Semuta from Richese's cache to
// its hand. The original dealt Shield remains the actual sale card.
const cache = source.richeseCache!, index = cache.findIndex(card => card.effect === 'semutaDrug');
assert.ok(index >= 0);
const [semuta] = cache.splice(index,1); player(source,f.richese).hand.push(semuta);
assert.deepEqual(inventory(source),f.originalCards);
source = targetTurn(blackMarket(source,f,'onceAround'),f,'onceAround');
const lot = structuredClone(source.richeseAuction), funding = structuredClone(source.richeseFunding);
const asked = askAny(source,f);
assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'));
let game = act(asked,f.emperor,{type:'truthAnswer',answer:'yes'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard');
assert.equal(pending.batch.entries[0].card.id,f.truth);
assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true);
const promise = structuredClone(game.phaseAnyBidPromises);
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
game = claim ? act(game,f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null);
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
assert.deepEqual(game.phaseAnyBidPromises,promise);
assert.equal(player(game,f.richese).hand.some(card => card.id === f.truth),claim);
assert.equal(game.discard.some(card => card.id === semuta.id),claim);
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
game = act(game,f.emperor,guide.action);
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
assert.deepEqual(inventory(game),f.originalCards);
});
void test('a voluntary real bribe cannot spend the last money required by an all-auction Yes', () => {
const f = fixture({advanced:false});
const game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
assert.equal(player(game,f.emperor).spice,10);
reject(game,f.emperor,{type:'bribe',target:f.richese,amount:7});
const paid = act(game,f.emperor,{type:'bribe',target:f.richese,amount:6});
assert.equal(player(paid,f.emperor).spice,4);
assert.ok(paid.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released));
assert.deepEqual(inventory(paid),f.originalCards);
});
void test('an Emperor cannot give away spice required by an all-auction Yes', () => {
const f = createTruthAllianceFixture({advanced:true,consent:'allied'});
const charity = finishTruthAlliance(f.game);
const declared = declareTruthAlliance(f,charity).game;
const asked = actTruthAlliance(declared,f.asker,{type:'truthAsk',question:{kind:'phaseAnyBid',
target:f.target,turn:declared.turn,minimum:4}});
assert.ok(viewGame(asked,f.target).truthPhaseAnyBidAnswers?.includes('yes'));
const game = actTruthAlliance(asked,f.target,{type:'truthAnswer',answer:'yes'});
assert.equal(truthAlliancePlayer(game,f.target).spice,10);
const before = structuredClone(game);
assert.throws(() => actTruthAlliance(game,f.target,{type:'emperorGift',amount:7}));
assert.deepEqual(game,before);
let shared = actTruthAlliance(game,f.target,{type:'emperorGift',amount:6});
for (let n = 0; shared.response?.kind === 'emperorGift' && n < 10; n++) {
const actor = shared.players.find(row => !shared.response!.passed.includes(row.id)); assert.ok(actor);
shared = actTruthAlliance(shared,actor.id,{type:'passResponse'});
}
assert.equal(truthAlliancePlayer(shared,f.target).spice,4);
assert.ok(shared.phaseAnyBidPromises?.some(row => row.player === f.target && row.answer && !row.fulfilled && !row.released));
assert.deepEqual(truthAllianceInventory(shared),f.originalCards);
});
@@ -0,0 +1,91 @@
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);
});