Support Advanced early cache bid promises
Verify and publish checkpoint container / container (push) Successful in 11m48s

This commit is contained in:
Quintine committed 2026-11-16 20:34:43 +11:00
1 parent 1a65e69932
commit 225b2174ad
14 files changed
+1071 -22

No files matched your search

@@ -0,0 +1,160 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Action, 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,
type TruthtranceRichesePromisesFixture,
} from './fixture-truthtrance-richese-promises';
type Method = 'silent' | 'onceAround';
/** Public Advanced R/A/E setup; the second original Truthtrance and, in the
* seller-retention cases, two original unopened cards move from deck to hands.
* A mutual alliance is explicitly staged; the actual pledge, Truth answers,
* auction, payments and cache are all produced by native actions. */
function source(seller: boolean) {
const f = fixture({advanced:true});
const game = structuredClone(f.earlySource);
const target = seller ? f.richese : f.emperor;
const donor = seller ? f.emperor : f.asker;
player(game,target).ally = donor; player(game,donor).ally = target;
const at = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(at >= 0);
const [second] = game.deck.splice(at,1); player(game,f.asker).hand.push(second);
if (seller) for (let i = 0; i < 2; i++) {
const index = game.deck.findIndex(card => card.effect !== 'truthtrance'); assert.ok(index >= 0);
const [card] = game.deck.splice(index,1); player(game,target).hand.push(card);
}
assert.ok(player(game,donor).spice >= 4);
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,target,donor,second:second.id};
}
function ask(game:Game, f:TruthtranceRichesePromisesFixture, target:string, card:string,
kind:'earlyRicheseBid'|'phaseAnyBid', minimum:number) {
game = act(game,f.asker,{type:'card',card});
game = advance(game,state => state.truthtrance?.stage === 'ask');
game = act(game,f.asker,{type:'truthAsk',question:{kind,target,turn:game.turn,minimum}});
const view = viewGame(game,target);
assert.ok((kind === 'earlyRicheseBid' ? view.truthEarlyRicheseBidAnswers : view.truthPhaseAnyBidAnswers)?.includes('yes'));
return passTruthRicheseFreshDiscard(act(game,target,{type:'truthAnswer',answer:'yes'}));
}
function begin(seller:boolean) {
const s = source(seller);
let game = ask(s.game,s.f,s.target,s.f.truth,'earlyRicheseBid',4);
game = ask(game,s.f,s.target,s.second,'phaseAnyBid',seller ? 3 : 6);
const early = game.earlyRicheseBidPromises?.find(row => row.player === s.target); assert.ok(early);
const phase = game.phaseAnyBidPromises?.find(row => row.player === s.target); assert.ok(phase);
return {...s,game,early,phase};
}
function market(game:Game, f:TruthtranceRichesePromisesFixture, method:Method) {
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,card:f.targetCard,
method,...(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'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
assert.equal(game.richeseAuction?.method,method);
return game;
}
function reject(game:Game, actor:string, action:Action) {
const before = structuredClone(game);
assert.throws(() => act(game,actor,action));
assert.deepEqual(game,before,'Rejected bids and funding updates preserve the original source');
}
function finishMarket(game:Game, event:string, method:Method):Game {
while (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
const lot = game.richeseAuction;
const actor = method === 'silent' ? lot.eligible.find(id => !Object.hasOwn(lot.sealed,id)) : lot.active;
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event,amount:method === 'silent' ? 0 : null,allyPayment:0});
}
return game;
}
function completeCache(game:Game, f:TruthtranceRichesePromisesFixture, target:string, earlyId:string) {
game = advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' &&
state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'});
const lot = game.richeseAuction!, card = lot.cardId;
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === earlyId)?.boundEvent,lot.event);
const guide = viewGame(game,target).richeseBidPromiseGuide?.action; assert.ok(guide);
assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,lot.event); assert.equal(guide.amount,4);
game = act(game,target,guide);
assert.ok(game.richeseBidPromises?.some(row => row.id === earlyId && row.fulfilled));
game = advance(game,state => player(state,target).hand.some(item => item.id === card),[],
{position:'first',method:'silent'});
assert.deepEqual(inventory(game),f.originalCards);
}
for (const method of ['silent','onceAround'] as const) void test(
`Advanced ${method} Black Market protects the funded cache when the phase bid uses locked allied spice`, () => {
const s = begin(false), startCash = player(s.game,s.target).spice;
assert.equal(startCash,10);
let game = market(s.game,s.f,method);
game = act(game,s.donor,{type:'pledgeAid',amount:4});
if (method === 'onceAround')
game = advance(game,state => clean(state) && state.richeseAuction?.active === s.target);
const lot = game.richeseAuction!, event = lot.event;
reject(game,s.target,{type:'richeseBid',event,amount:11,allyPayment:4});
game = act(game,s.target,{type:'richeseBid',event,amount:10,allyPayment:4});
assert.equal(player(game,s.target).spice,startCash,'A submitted bid has not been paid');
assert.equal(game.richeseFunding?.[s.target]?.allyPayment,4);
assert.ok(game.phaseAnyBidPromises?.find(row => row.event === s.phase.event)?.fulfilled);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.released);
if (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
reject(game,s.donor,{type:'pledgeAid',amount:3});
reject(game,s.target,{type:'bribe',target:s.f.richese,amount:5});
}
game = finishMarket(game,event,method);
game = advance(game,state => player(state,s.target).hand.some(card => card.id === s.f.targetCard));
assert.equal(player(game,s.target).spice,startCash-6);
assert.equal(game.aid[s.donor]?.amount,0,'The pledged four was spent exactly once');
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.released);
assert.deepEqual(inventory(game),s.f.originalCards);
completeCache(game,s.f,s.target,s.early.id);
});
for (const method of ['silent','onceAround'] as const) void test(
`Advanced ${method} Black Market paid self-retention reserves no extra seller hand slot`, () => {
const s = begin(true), originalHand = player(s.game,s.target).hand.map(card => card.id).sort();
const ownSpice = player(s.game,s.target).spice;
assert.equal(originalHand.length,3,'Only one physical cache hand slot remains');
let game = market(s.game,s.f,method);
game = act(game,s.donor,{type:'pledgeAid',amount:4});
const event = game.richeseAuction!.event;
if (method === 'onceAround') {
let opened = false;
while (game.richeseAuction?.event === event && game.richeseAuction.active !== s.target) {
const actor = game.richeseAuction.active; assert.ok(actor && actor !== s.target);
game = act(game,actor,{type:'richeseBid',event,amount:opened ? null : 1,allyPayment:0});
opened = true;
}
assert.ok(opened,'The seller gets its native Once Around turn after an opposing bid');
}
game = act(game,s.target,{type:'richeseBid',event,amount:4,allyPayment:4});
assert.ok(game.phaseAnyBidPromises?.find(row => row.event === s.phase.event)?.fulfilled);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.released);
if (game.richeseAuction?.event === event && !game.richeseAuction.outcome)
reject(game,s.donor,{type:'pledgeAid',amount:3});
game = finishMarket(game,event,method);
game = advance(game,state => state.decision?.kind === 'richeseDeclaration');
assert.deepEqual(player(game,s.target).hand.map(card => card.id).sort(),originalHand,
'The seller retains its own offered physical card instead of acquiring an extra card');
assert.equal(player(game,s.target).spice,ownSpice);
assert.equal(game.aid[s.donor]?.amount,0);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.released);
assert.deepEqual(inventory(game),s.f.originalCards);
completeCache(game,s.f,s.target,s.early.id);
});
@@ -0,0 +1,175 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Action, 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,
type TruthtranceRichesePromisesFixture,
} from './fixture-truthtrance-richese-promises';
type Method = 'silent' | 'onceAround';
type Position = 'first' | 'last';
/** The genuine Advanced R/A/E fixture selects only unopened deal/Spice order.
* Joint questions stage the second original Truthtrance from the unopened deck;
* the near-full-hand case stages two original cards from there. No wallet,
* promise, bid, phase or auction is installed. */
function source(joint = false, nearFull = false) {
const f = fixture({advanced:true});
const game = structuredClone(f.earlySource);
let second: string | undefined;
if (joint) {
const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(index >= 0);
const [card] = game.deck.splice(index,1); second = card.id;
player(game,f.asker).hand.push(card);
}
if (nearFull) {
for (let i = 0; i < 2; i++) {
const index = game.deck.findIndex(card => card.effect !== 'truthtrance'); assert.ok(index >= 0);
const [card] = game.deck.splice(index,1); player(game,f.emperor).hand.push(card);
}
}
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,second};
}
function answer(game:Game, f:TruthtranceRichesePromisesFixture, card:string,
kind:'earlyRicheseBid'|'phaseAnyBid', minimum:number) {
game = act(game,f.asker,{type:'card',card});
game = advance(game,state => state.truthtrance?.stage === 'ask');
game = act(game,f.asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum}});
const view = viewGame(game,f.emperor);
const choices = kind === 'earlyRicheseBid' ? view.truthEarlyRicheseBidAnswers : view.truthPhaseAnyBidAnswers;
assert.ok(choices?.includes('yes'), `${kind} must admit the funded Yes`);
return passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
}
function begin(joint = false, nearFull = false) {
const f = source(joint,nearFull);
let game = answer(f.game,f.f,f.f.truth,'earlyRicheseBid',4);
if (f.second) game = answer(game,f.f,f.second,'phaseAnyBid',6);
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.f.emperor); assert.ok(early);
const phase = joint ? game.phaseAnyBidPromises?.find(row => row.player === f.f.emperor) : undefined;
if (joint) assert.ok(phase);
assert.deepEqual(inventory(game),f.f.originalCards);
return {f:f.f,game,early,phase};
}
function openMarket(game:Game, f:TruthtranceRichesePromisesFixture, method:Method) {
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,...(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'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
assert.equal(game.richeseAuction?.method,method);
return game;
}
function reachBid(game:Game, f:TruthtranceRichesePromisesFixture, method:Method) {
if (method === 'onceAround')
game = advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor);
return game;
}
function reject(game:Game, actor:string, action:Action) {
const original = structuredClone(game);
assert.throws(() => act(game,actor,action));
assert.deepEqual(game,original,'A rejected auction action keeps its original receipt and funds');
}
function closeMarket(game:Game, f:TruthtranceRichesePromisesFixture, method:Method) {
const event = game.richeseAuction!.event;
while (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
const lot = game.richeseAuction;
const actor = method === 'silent' ? lot.eligible.find(id => !Object.hasOwn(lot.sealed,id)) : lot.active;
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event,amount:method === 'silent' ? 0 : null,allyPayment:0});
}
return advance(game,state => player(state,f.emperor).hand.some(card => card.id === f.targetCard));
}
function completeCache(game:Game, f:TruthtranceRichesePromisesFixture, id:string, method:Method, position:Position) {
game = advance(game,state => clean(state) && gameIsCache(state,method),[],{position,method});
const event = game.richeseAuction!.event, card = game.richeseAuction!.cardId;
if (method === 'onceAround') game = advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor);
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === id)?.boundEvent,event);
const guide = viewGame(game,f.emperor).richeseBidPromiseGuide; assert.ok(guide);
assert.equal(guide.action.event,event); assert.equal(guide.action.amount,4);
const spice = player(game,f.emperor).spice;
game = act(game,f.emperor,guide.action);
assert.equal(player(game,f.emperor).spice,spice,'The accepted bid is not prepaid');
assert.ok(game.richeseBidPromises?.some(row => row.id === id && row.fulfilled));
game = advance(game,state => player(state,f.emperor).hand.some(item => item.id === card),[],{position,method});
assert.equal(player(game,f.emperor).spice,spice-4);
assert.deepEqual(inventory(game),f.originalCards);
return game;
}
function gameIsCache(game:Game, method:Method) {
return !!game.richeseAuction && game.richeseAuction.source === 'cache' &&
game.richeseAuction.method === method && !game.richeseAuction.outcome;
}
for (const method of ['onceAround','silent'] as const)
for (const position of ['first','last'] as const) void test(
`Advanced ${position} ${method}: Black Market purchase reserves the funded later cache`, () => {
const f = begin(true), before = player(f.game,f.f.emperor).spice;
assert.equal(before,10);
let game = reachBid(openMarket(f.game,f.f,method),f.f,method);
const event = game.richeseAuction!.event;
reject(game,f.f.emperor,{type:'richeseBid',event,amount:7,allyPayment:0});
game = act(game,f.f.emperor,{type:'richeseBid',event,amount:6,allyPayment:0});
assert.equal(player(game,f.f.emperor).spice,before);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === f.early.id)?.released);
assert.ok(game.phaseAnyBidPromises?.find(row => row.event === f.phase!.event)?.fulfilled);
if (method === 'silent') {
assert.equal(viewGame(game,f.f.asker).richeseAuction?.revealedBids,null);
assert.equal(viewGame(game,f.f.asker).richeseAuction?.ownBid,null);
}
game = closeMarket(game,f.f,method);
assert.equal(player(game,f.f.emperor).spice,before-6);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === f.early.id)?.released);
assert.deepEqual(inventory(game),f.f.originalCards);
completeCache(game,f.f,f.early.id,method,position);
});
for (const method of ['onceAround','silent'] as const) void test(
`Advanced ${method}: a Black Market win cannot consume the final cache hand slot`, () => {
const f = begin(false,true);
let game = reachBid(openMarket(f.game,f.f,method),f.f,method);
const event = game.richeseAuction!.event;
assert.equal(player(game,f.f.emperor).hand.length,3);
reject(game,f.f.emperor,{type:'richeseBid',event,amount:1,allyPayment:0});
game = act(game,f.f.emperor,{type:'richeseBid',event,amount:method === 'silent' ? 0 : null,allyPayment:0});
while (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
const lot = game.richeseAuction;
const actor = method === 'silent' ? lot.eligible.find(id => !Object.hasOwn(lot.sealed,id)) : lot.active;
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event,amount:method === 'silent' ? 0 : null,allyPayment:0});
}
assert.ok(player(game,f.f.richese).hand.some(card => card.id === f.f.targetCard));
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === f.early.id)?.released);
completeCache(game,f.f,f.early.id,method,'first');
});
void test('an opponent winning the Advanced Black Market preserves the respondent’s later cache Yes', () => {
const f = begin(), method:Method = 'silent';
let game = openMarket(f.game,f.f,method);
const event = game.richeseAuction!.event, spice = player(game,f.f.emperor).spice;
game = act(game,f.f.emperor,{type:'richeseBid',event,amount:0,allyPayment:0});
game = act(game,f.f.asker,{type:'richeseBid',event,amount:1,allyPayment:0});
game = act(game,f.f.richese,{type:'richeseBid',event,amount:0,allyPayment:0});
game = advance(game,state => player(state,f.f.asker).hand.some(card => card.id === f.f.targetCard));
assert.equal(player(game,f.f.emperor).spice,spice);
assert.ok(!game.earlyRicheseBidPromises?.find(row => row.id === f.early.id)?.released);
completeCache(game,f.f,f.early.id,method,'first');
});
@@ -0,0 +1,144 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Action, type Game } from '../game/engine';
import {
actTruthtranceRichesePromises as act,
advanceTruthtranceRichesePromises as advance,
createTruthtranceRichesePromisesFixture as fixture,
nextTruthtranceRichesePromisesStep as nextStep,
passTruthRicheseFreshDiscard,
truthtranceRichesePromisesClean as clean,
truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player,
type TruthtranceRichesePromisesFixture,
} from './fixture-truthtrance-richese-promises';
/** Real Advanced public R/A/E starts. The second original Truthtrance and,
* in the two-turn case, one additional seller card move from the unopened
* deck; two later unopened land Spice cards are ordered. No wallet, phase,
* auction, promise, receipt or sale is assigned. */
function source(seller = false) {
const f = fixture({advanced:true}), game = structuredClone(f.earlySource);
const at = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(at >= 0); const [second] = game.deck.splice(at,1);
player(game,f.asker).hand.push(second);
let sellerCard: string | undefined;
if (seller) {
const index = game.deck.findIndex(card => card.effect !== 'truthtrance'); assert.ok(index >= 0);
const [card] = game.deck.splice(index,1); sellerCard = card.id; player(game,f.richese).hand.push(card);
for (let position = 0; position < 2; position++) {
const from = game.spiceDeck.findIndex((card,index) => index >= position && 'territory' in card && !card.discovery);
assert.ok(from >= position);
const [card] = game.spiceDeck.splice(from,1); game.spiceDeck.splice(position,0,card);
}
}
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,second:second.id,sellerCard};
}
function ask(game:Game, f:TruthtranceRichesePromisesFixture, card:string, target:string,
kind:'phaseAnyBid'|'earlyRicheseBid', minimum:number, answer:'yes'|'no') {
game = act(game,f.asker,{type:'card',card});
game = advance(game,state => state.truthtrance?.stage === 'ask');
game = act(game,f.asker,{type:'truthAsk',question:{kind,target,turn:game.turn,minimum}});
const view = viewGame(game,target);
const options = kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers;
assert.ok(options?.includes(answer),`${kind} ${answer} must have its native witness`);
return passTruthRicheseFreshDiscard(act(game,target,{type:'truthAnswer',answer}));
}
function market(game:Game, f:TruthtranceRichesePromisesFixture, card:string, method:'silent'|'onceAround') {
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
assert.ok(player(game,f.richese).hand.some(item => item.id === card));
game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,card,method,
...(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'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
assert.equal(game.richeseAuction?.method,method);
return game;
}
void test('Advanced current Black Market bid question cannot strand a waiting early cache Yes', () => {
const f = source();
let game = ask(f.game,f.f,f.f.truth,f.f.emperor,'earlyRicheseBid',6,'yes');
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.f.emperor); assert.ok(early);
assert.equal(player(game,f.f.emperor).spice,10);
game = market(game,f.f,f.f.targetCard,'silent');
const lot = game.richeseAuction!, event = lot.event;
game = act(game,f.f.asker,{type:'card',card:f.second});
game = advance(game,state => state.truthtrance?.stage === 'ask');
const before = structuredClone(game);
const question = {kind:'richeseBid',target:f.f.emperor,turn:game.turn,event,minimum:6};
assert.throws(() => act(game,f.f.asker,{type:'truthAsk',question}),
'The separately asked current-lot promise awaits a three-ledger planner');
assert.deepEqual(game,before,'Rejected question cannot mutate the auction, question or cache receipt');
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === early.id && !row.boundEvent && !row.released));
assert.equal(player(game,f.f.emperor).spice,10);
assert.deepEqual(inventory(game),f.f.originalCards);
});
/** Drive the original live turn to the next Charity without inventing income.
* The borrowed stepper stops intentionally at Richese movement; end that own
* turn through its normal action. All auction/card and phase steps are real. */
function nextCharity(initial:Game): Game {
let game = initial;
for (let count = 0; count < 2600; count++) {
if (game.status === 'playing' && game.turn === 2 && game.phase === 2 && clean(game)) return game;
const next = nextStep(game);
let actor: string, action: Action;
if (next) { actor = next.actor; action = next.action; }
else {
assert.ok(clean(game) && game.phase === 5 && game.active,
`Native continuation needs a real action at ${game.turn}/${game.phase}/${game.decision?.kind}`);
actor = game.active; action = {type:'endMovement'};
}
game = act(game,actor,action);
}
throw Error('The genuine Advanced turn did not reach its next Charity');
}
void test('Advanced Once Around seller retains phase Yes after all pass and bids in the later ordinary lot', () => {
const f = source(true); assert.ok(f.sellerCard);
// Earn the sixth spice through a real prior Black Market sale: the Emperor
// buys the original Shield for one and both other seats decline.
let game = market(f.game,f.f,f.f.targetCard,'silent');
const firstEvent = game.richeseAuction!.event;
assert.equal(player(game,f.f.richese).spice,5);
game = act(game,f.f.emperor,{type:'richeseBid',event:firstEvent,amount:1,allyPayment:0});
game = act(game,f.f.asker,{type:'richeseBid',event:firstEvent,amount:0,allyPayment:0});
game = act(game,f.f.richese,{type:'richeseBid',event:firstEvent,amount:0,allyPayment:0});
game = advance(game,state => player(state,f.f.richese).spice === 6);
assert.ok(player(game,f.f.emperor).hand.some(card => card.id === f.f.targetCard));
game = nextCharity(game);
assert.equal(player(game,f.f.richese).spice,6,'The sixth spice was earned by the actual sale');
assert.ok(player(game,f.f.richese).hand.some(card => card.id === f.sellerCard));
game = ask(game,f.f,f.f.truth,f.f.richese,'phaseAnyBid',6,'yes');
game = ask(game,f.f,f.second,f.f.richese,'earlyRicheseBid',4,'no');
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.f.richese && row.turn === game.turn);
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.f.richese && row.turn === game.turn);
assert.ok(phase && early);
game = market(game,f.f,f.sellerCard,'onceAround');
const event = game.richeseAuction!.event;
while (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
const actor = game.richeseAuction.active; assert.ok(actor);
assert.notEqual(actor,f.f.richese,'The Once Around seller gets no turn when all buyers decline');
game = act(game,actor,{type:'richeseBid',event,amount:null,allyPayment:0});
}
const pending = game.phaseAnyBidPromises?.find(row => row.event === phase.event); assert.ok(pending);
assert.equal(!!pending.fulfilled,false); assert.equal(!!pending.released,false);
assert.equal(player(game,f.f.richese).spice,6);
assert.ok(player(game,f.f.richese).hand.some(card => card.id === f.sellerCard));
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === early.id && !row.boundEvent && !row.released));
const nextCache = game.richeseCache?.[0]?.id; assert.ok(nextCache,'The second turn uses an original remaining cache card');
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.f.richese,
[],{position:'first',method:'silent',card:nextCache});
assert.ok(game.richeseBidPromises?.some(row => row.id === early.id && row.fulfilled));
const guide = viewGame(game,f.f.richese).phaseAnyBidGuide?.action; assert.ok(guide);
assert.equal(guide.type,'bid'); assert.equal(guide.amount,6);
game = act(game,f.f.richese,guide);
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase.event && row.fulfilled));
assert.deepEqual(inventory(game),f.f.originalCards);
});
@@ -0,0 +1,160 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Action, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import {
actTruthtranceRichesePromises as act,
advanceTruthtranceRichesePromises as advance,
createTruthtranceRichesePromisesFixture as fixture,
passTruthRicheseFreshDiscard,
truthtranceRichesePromisesClean as clean,
truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player,
type TruthtranceRichesePromisesFixture,
} from './fixture-truthtrance-richese-promises';
type Method = 'normal' | 'onceAround' | 'silent';
type Early = 'yes' | 'no';
/** Genuine public Advanced R/A/E and native opening; one additional original
* Truthtrance moves from the unopened deck. The seller case moves two other
* original unopened cards into Richese's hand. No purse, phase, bid, answer,
* auction or commitment is manufactured. */
function source(seller = false) {
const f = fixture({advanced:true}), game = structuredClone(f.earlySource);
const at = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
assert.ok(at >= 0); const [second] = game.deck.splice(at,1);
player(game,f.asker).hand.push(second);
if (seller) for (let i = 0; i < 2; i++) {
const index = game.deck.findIndex(card => card.effect !== 'truthtrance'); assert.ok(index >= 0);
const [card] = game.deck.splice(index,1); player(game,f.richese).hand.push(card);
}
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,second:second.id};
}
function ask(game:Game, f:TruthtranceRichesePromisesFixture, card:string, target:string,
kind:'phaseAnyBid'|'earlyRicheseBid', minimum:number, answer:'yes'|'no') {
game = act(game,f.asker,{type:'card',card});
game = advance(game,state => state.truthtrance?.stage === 'ask');
game = act(game,f.asker,{type:'truthAsk',question:{kind,target,turn:game.turn,minimum}});
const view = viewGame(game,target);
const choices = kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers;
assert.ok(choices?.includes(answer),`${kind} ${answer} needs a real funded completion`);
return passTruthRicheseFreshDiscard(act(game,target,{type:'truthAnswer',answer}));
}
function begin(early:Early, seller = false) {
const f = source(seller), target = seller ? f.f.richese : f.f.emperor;
const phaseMinimum = seller ? 2 : 6, earlyMinimum = seller ? 3 : 4;
let game = ask(f.game,f.f,f.f.truth,target,'phaseAnyBid',phaseMinimum,'yes');
game = ask(game,f.f,f.second,target,'earlyRicheseBid',earlyMinimum,early);
const phase = game.phaseAnyBidPromises?.find(row => row.player === target); assert.ok(phase);
const cache = game.earlyRicheseBidPromises?.find(row => row.player === target); assert.ok(cache);
assert.deepEqual(inventory(game),f.f.originalCards);
return {f:f.f,game,target,phase,cache,phaseMinimum,earlyMinimum};
}
function open(game:Game,f:TruthtranceRichesePromisesFixture,method:Method) {
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,...(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'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
assert.equal(game.richeseAuction?.method,method);
return game;
}
function reject(game:Game,actor:string,action:Action) {
const before = structuredClone(game);
assert.throws(() => act(game,actor,action));
assert.deepEqual(game,before,'An invalid guide keeps the standing lot and both commitments');
}
function passRemainder(game:Game,method:Method,event:string) {
while (game.richeseAuction?.event === event && !game.richeseAuction.outcome) {
const lot = game.richeseAuction;
const actor = method === 'silent' ? lot.eligible.find(id => !Object.hasOwn(lot.sealed,id)) : lot.active;
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event,amount:method === 'silent' ? 0 : null,allyPayment:0});
}
return game;
}
for (const method of ['normal','onceAround','silent'] as const)
for (const early of ['yes','no'] as const) void test(
`Advanced ${method}: phase Yes and early ${early} share a funded Black Market guide`, () => {
const f = begin(early), before = player(f.game,f.target).spice;
assert.equal(before,10);
let game = open(f.game,f.f,method);
if (method !== 'silent')
game = advance(game,state => clean(state) && state.richeseAuction?.active === f.target);
const lot = game.richeseAuction!, guide = viewGame(game,f.target).phaseAnyBidGuide?.action;
assert.ok(guide,'A current native bid can satisfy the phase Yes');
assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,lot.event);
assert.equal(guide.amount,6);
assert.equal(guide.phaseAnyBidPromiseEvent,f.phase.event);
assert.doesNotThrow(() => act(game,f.target,guide));
reject(game,f.target,{...guide,phaseAnyBidPromiseEvent:'stale-phase-event'});
reject(game,f.target,{...guide,event:'stale-market-event'});
if (early === 'yes')
reject(game,f.target,{type:'richeseBid',event:lot.event,amount:7,allyPayment:0});
for (const difficulty of DIFFICULTIES) {
const bot = viewGame(game,f.target); bot.players.find(seat => seat.id === f.target)!.bot = difficulty;
const action = botActions(bot)[0]; assert.deepEqual(action,guide,difficulty);
assert.doesNotThrow(() => act(game,f.target,action),difficulty);
}
const old = structuredClone(game);
game = act(game,f.target,guide);
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === f.phase.event && row.fulfilled));
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === f.cache.id && !row.boundEvent && !row.released));
assert.equal(player(game,f.target).spice,before,'The market bid has not been paid early');
reject(game,f.target,guide);
if (method === 'silent') {
assert.equal(viewGame(game,f.f.asker).richeseAuction?.revealedBids,null);
assert.equal(viewGame(game,f.f.asker).richeseAuction?.ownBid,null);
}
assert.notDeepEqual(game,old);
game = passRemainder(game,method,lot.event);
game = advance(game,state => player(state,f.target).hand.some(card => card.id === f.f.targetCard));
assert.equal(player(game,f.target).spice,before-6);
assert.deepEqual(inventory(game),f.f.originalCards);
game = advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' &&
state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'});
const cacheEvent = game.richeseAuction!.event;
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === f.cache.id)?.boundEvent,cacheEvent);
const cacheAction = early === 'yes' ? viewGame(game,f.target).richeseBidPromiseGuide?.action :
{type:'richeseBid',event:cacheEvent,amount:2,allyPayment:0};
assert.ok(cacheAction);
if (early === 'yes') assert.equal(cacheAction.amount,4);
game = act(game,f.target,cacheAction);
assert.ok(game.richeseBidPromises?.some(row => row.id === f.cache.id && row.fulfilled));
assert.deepEqual(inventory(game),f.f.originalCards);
});
void test('Advanced Black Market seller self-retention does not consume the promised cache hand slot', () => {
const f = begin('yes',true);
let game = open(f.game,f.f,'silent');
const before = player(game,f.target).spice, hand = player(game,f.target).hand.map(card => card.id).sort();
assert.equal(before,5); assert.equal(hand.length,3);
const lot = game.richeseAuction!, guide = viewGame(game,f.target).phaseAnyBidGuide?.action;
assert.ok(guide); assert.equal(guide.event,lot.event); assert.equal(guide.amount,2);
game = act(game,f.target,guide);
game = passRemainder(game,'silent',lot.event);
assert.deepEqual(player(game,f.target).hand.map(card => card.id).sort(),hand);
assert.equal(player(game,f.target).spice,before-2);
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === f.phase.event && row.fulfilled));
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === f.cache.id && !row.released));
game = advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' &&
state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'});
const cache = viewGame(game,f.target).richeseBidPromiseGuide?.action; assert.ok(cache);
assert.equal(cache.amount,3);
game = act(game,f.target,cache);
assert.ok(game.richeseBidPromises?.some(row => row.id === f.cache.id && row.fulfilled));
assert.deepEqual(inventory(game),f.f.originalCards);
});
@@ -0,0 +1,94 @@
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);
});
@@ -0,0 +1,150 @@
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,
truthtranceRichesePromisesClean as clean,
truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player,
} from './fixture-truthtrance-richese-promises';
/** Public Advanced Richese/Atreides/Emperor setup. The original Semuta moves
* from cache to its owner, and the original second Truthtrance moves from the
* unopened deck to Atreides. No answer, purse, auction or reaction is made up. */
function source(two: boolean) {
const f = fixture({advanced:true});
const game = structuredClone(f.earlySource);
assert.equal(game.semutaAdvancedOrdinaryPreview,true);
const cache = game.richeseCache!;
const semutaAt = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt >= 0);
const [semuta] = cache.splice(semutaAt,1); player(game,f.richese).hand.push(semuta);
let second: string | undefined;
if (two) {
const at = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(at >= 0);
const [card] = game.deck.splice(at,1); player(game,f.asker).hand.push(card); second = card.id;
}
assert.deepEqual(inventory(game),f.originalCards);
return {f,game,second,semuta:semuta.id};
}
function parent(game: Game) {
return structuredClone({turn:game.turn,phase:game.phase,active:game.active,ready:game.ready,order:game.order,
charityOrder:game.charityOrder,auction:game.auction,richeseAuction:game.richeseAuction,
richeseBidding:game.richeseBidding,richeseFunding:game.richeseFunding,aid:game.aid});
}
function reachQuestions(game: Game, asker: string, card: string, second?: string): Game {
game = act(game,asker,{type:'card',card,...(second ? {cards:[second]} : {})});
while (game.truthtrance?.stage === 'priority') {
const actor = game.players.find(seat => !game.truthtrance!.passed.includes(seat.id)); assert.ok(actor);
game = act(game,actor.id,{type:'truthPass'});
}
assert.equal(game.truthtrance?.stage,'ask');
return game;
}
function settle(game: Game, owner: string, claim: boolean): Game {
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(viewGame(game,owner).semutaReaction?.canCommit,true);
return claim ? act(game,owner,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game);
}
function bidRealCache(game: Game, f: ReturnType<typeof fixture>, earlyId: string, withPhase: boolean) {
game = advance(game,state => clean(state) && !!state.richeseAuction &&
state.richeseAuction.source === 'cache' && state.richeseAuction.method === 'silent' &&
!state.richeseAuction.outcome,[],{position:'first',method:'silent'});
const lot = game.richeseAuction!, card = lot.cardId;
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === earlyId)?.boundEvent,lot.event);
assert.equal(game.richeseBidPromises?.find(row => row.id === earlyId)?.event,lot.event);
const view = viewGame(game,f.emperor);
const guide = withPhase ? view.phaseAnyBidGuide?.action : view.richeseBidPromiseGuide?.action;
assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,lot.event);
assert.equal(guide.amount,4);
const before = player(game,f.emperor).spice;
game = act(game,f.emperor,guide);
assert.equal(player(game,f.emperor).spice,before,'A sealed declaration does not prepay');
assert.ok(game.richeseBidPromises?.some(row => row.id === earlyId && row.fulfilled));
if (withPhase) assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
game = advance(game,state => player(state,f.emperor).hand.some(item => item.id === card),[],
{position:'first',method:'silent'});
assert.deepEqual(inventory(game),f.originalCards);
}
for (const claim of [false,true]) void test(
`Advanced early cache Yes Semuta ${claim ? 'claim' : 'pass'} preserves the physical future bid`, () => {
const s = source(false), original = parent(s.game);
let game = reachQuestions(s.game,s.f.asker,s.f.truth);
game = act(game,s.f.asker,{type:'truthAsk',question:{kind:'earlyRicheseBid',
target:s.f.emperor,turn:game.turn,minimum:4}});
assert.ok(viewGame(game,s.f.emperor).truthEarlyRicheseBidAnswers?.includes('yes'));
game = act(game,s.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,s.f.truth);
const receipt = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(receipt);
assert.equal(receipt.boundEvent,undefined);
assert.deepEqual(parent(game),original);
const tampered = structuredClone(game); tampered.earlyRicheseBidPromises![0].minimum++;
assert.throws(() => act(tampered,s.f.richese,{type:'semutaCommit',event:pending.batch.event}),
'A standalone early answer is bound to its Semuta continuation');
game = settle(game,s.f.richese,claim);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
assert.equal(player(game,s.f.richese).hand.some(card => card.id === s.f.truth),claim);
assert.equal(game.discard.some(card => card.id === s.semuta),claim);
assert.deepEqual(parent(game),original);
assert.deepEqual(inventory(game),s.f.originalCards);
bidRealCache(game,s.f,receipt.id,false);
});
for (const first of ['phase','early'] as const) for (const claim of [false,true]) void test(
`Advanced ${first} first: joint early and phase Yes survive Semuta ${claim ? 'claim' : 'pass'}`, () => {
const s = source(true), original = parent(s.game); assert.ok(s.second);
const phase = {kind:'phaseAnyBid',target:s.f.emperor,turn:s.game.turn,minimum:3};
const early = {kind:'earlyRicheseBid',target:s.f.emperor,turn:s.game.turn,minimum:4};
let game = reachQuestions(s.game,s.f.asker,s.f.truth,s.second);
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[s.f.truth,s.second]);
game = act(game,s.f.asker,{type:'truthAsk',question:first === 'phase' ? phase : early});
game = act(game,s.f.emperor,{type:'truthAnswer',answer:'yes'});
assert.ok(game.pendingTreacheryDiscard?.reaction,'First actual Truth discard has its own Semuta offer');
game = passTruthRicheseFreshDiscard(game);
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[s.second]);
game = act(game,s.f.asker,{type:'truthAsk',question:first === 'phase' ? early : phase});
game = act(game,s.f.emperor,{type:'truthAnswer',answer:'yes'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard');
assert.equal(pending.continuation.jointEarlyPhaseBid,true);
assert.equal(pending.batch.entries[0].card.id,s.second);
const earlyReceipt = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(earlyReceipt);
const earlyPromises = structuredClone(game.earlyRicheseBidPromises), phasePromises = structuredClone(game.phaseAnyBidPromises);
assert.deepEqual(parent(game),original);
for (const family of ['phaseAnyBidPromises','earlyRicheseBidPromises'] as const) {
const tampered = structuredClone(game); tampered[family]![0].minimum++;
assert.throws(() => act(tampered,s.f.richese,{type:'semutaCommit',event:pending.batch.event}),
`The joint completed answer binds ${family}`);
}
game = settle(game,s.f.richese,claim);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
assert.equal(player(game,s.f.richese).hand.some(card => card.id === s.second),claim);
assert.equal(game.discard.some(card => card.id === s.semuta),claim);
assert.deepEqual(game.earlyRicheseBidPromises,earlyPromises);
assert.deepEqual(game.phaseAnyBidPromises,phasePromises);
assert.deepEqual(parent(game),original);
assert.deepEqual(inventory(game),s.f.originalCards);
bidRealCache(game,s.f,earlyReceipt.id,true);
});
void test('Advanced early cache Unknown keeps the Truthtrance and opens no Semuta discard', () => {
const s = source(false);
let game = reachQuestions(s.game,s.f.asker,s.f.truth);
game = act(game,s.f.asker,{type:'truthAsk',question:{kind:'earlyRicheseBid',
target:s.f.emperor,turn:game.turn,minimum:99}});
assert.ok(viewGame(game,s.f.emperor).truthEarlyRicheseBidAnswers?.includes('unknown'));
game = act(game,s.f.emperor,{type:'truthAnswer',answer:'unknown'});
assert.ok(game.pendingTreacheryDiscard == null);
assert.ok(player(game,s.f.asker).hand.some(card => card.id === s.f.truth));
assert.equal(game.earlyRicheseBidPromises?.length ?? 0,0);
assert.deepEqual(inventory(game),s.f.originalCards);
});