Compose early cache and phase-wide bid commitments
Verify and publish checkpoint container / container (push) Successful in 11m28s
Verify and publish checkpoint container / container (push) Successful in 11m28s
This commit is contained in:
1 parent
05f7fc8f20
commit
3ede19c90a
12 files changed
+990
-22
No files matched your search
@@ -0,0 +1,96 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { quoteJointEarlyRicheseBids, type JointEarlyRicheseBidInput } from '../game/joint-early-richese-bids';
|
||||
import type { EarlyRicheseBidPromise } from '../game/early-richese-bid';
|
||||
import type { PhaseBidPromise } from '../game/turn-bid-promises';
|
||||
|
||||
const early = (minimum:number,answer:boolean,extra:Partial<EarlyRicheseBidPromise> = {}):EarlyRicheseBidPromise =>
|
||||
({id:`early-${minimum}-${answer}`,turn:3,player:'emperor',asker:'atreides',minimum,answer,...extra});
|
||||
const phase = (minimum:number,answer:boolean,extra:Partial<PhaseBidPromise> = {}):PhaseBidPromise =>
|
||||
({event:`phase-${minimum}-${answer}`,turn:3,player:'emperor',asker:'atreides',minimum,answer,...extra});
|
||||
const input = (extra:Partial<JointEarlyRicheseBidInput> = {}):JointEarlyRicheseBidInput => ({
|
||||
player:'emperor',turn:3,early:[],phase:[],cacheMaximum:10,...extra,
|
||||
});
|
||||
const ordinary = (extra:Partial<NonNullable<JointEarlyRicheseBidInput['ordinary']>> = {}) => ({
|
||||
opportunity:{player:'emperor',turn:3,kind:'future' as const,minimum:1,maximum:10},
|
||||
cashAvailable:9,aidAvailable:0,freeSlots:2,cacheWinSlots:1,...extra,
|
||||
});
|
||||
|
||||
void test('one physical cache declaration intersects every live Yes and No',() => {
|
||||
const result=quoteJointEarlyRicheseBids(input({
|
||||
early:[early(3,true),early(8,false)],phase:[phase(5,true),phase(7,false)],
|
||||
}));
|
||||
assert.equal(result.earlyRequired,true); assert.equal(result.phaseRequired,true);
|
||||
assert.deepEqual(result.cache,{minimum:3,maximum:6});
|
||||
assert.deepEqual(result.shared,{minimum:5,maximum:6});
|
||||
assert.equal(result.separate,null); assert.equal(result.possible,true);
|
||||
const conflict=quoteJointEarlyRicheseBids(input({early:[early(3,true)],phase:[phase(3,false)]}));
|
||||
assert.equal(conflict.cache,null); assert.equal(conflict.shared,null); assert.equal(conflict.possible,false);
|
||||
const onlyNo=quoteJointEarlyRicheseBids(input({early:[early(1,false)],phase:[phase(1,false)]}));
|
||||
assert.equal(onlyNo.cache,null); assert.equal(onlyNo.possible,true,'Both obligations can pass');
|
||||
});
|
||||
|
||||
void test('a distinct ordinary bid reserves cash and a hand slot for a required cache purchase',() => {
|
||||
const baseline=input({early:[early(3,true),early(4,false)],phase:[phase(6,true)],ordinary:ordinary()});
|
||||
const quote=quoteJointEarlyRicheseBids(baseline);
|
||||
assert.deepEqual(quote.cache,{minimum:3,maximum:3}); assert.equal(quote.shared,null);
|
||||
assert.deepEqual(quote.separate,{cacheBid:3,ordinary:{minimum:6,maximum:6}});
|
||||
assert.equal(quote.possible,true);
|
||||
const insufficient=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({cashAvailable:8})});
|
||||
assert.equal(insufficient.separate,null); assert.equal(insufficient.possible,false);
|
||||
const aided=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({cashAvailable:8,aidAvailable:1})});
|
||||
assert.deepEqual(aided.separate,{cacheBid:3,ordinary:{minimum:6,maximum:6}});
|
||||
assert.equal(aided.possible,true);
|
||||
const noSecondSlot=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({freeSlots:1})});
|
||||
assert.equal(noSecondSlot.separate,null); assert.equal(noSecondSlot.possible,false);
|
||||
// The first Harkonnen purchase can add its bonus card before the second
|
||||
// declaration. Once that declaration is placed both obligations are met.
|
||||
const harkonnenTwo=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({freeSlots:2,cacheWinSlots:2})});
|
||||
assert.equal(harkonnenTwo.separate,null); assert.equal(harkonnenTwo.possible,false);
|
||||
const harkonnenThree=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({freeSlots:3,cacheWinSlots:2})});
|
||||
assert.deepEqual(harkonnenThree.separate,{cacheBid:3,ordinary:{minimum:6,maximum:6}});
|
||||
assert.equal(harkonnenThree.possible,true);
|
||||
const noCashForCache=quoteJointEarlyRicheseBids({...baseline,ordinary:ordinary({cashAvailable:2,aidAvailable:100})});
|
||||
assert.equal(noCashForCache.separate,null,'Uncommitted ally aid cannot replace the cache cash witness');
|
||||
});
|
||||
|
||||
void test('a phase Yes can use a separate ordinary bid while the early No permits a cache pass',() => {
|
||||
const quote=quoteJointEarlyRicheseBids(input({early:[early(4,false)],phase:[phase(6,true)],
|
||||
ordinary:ordinary({cashAvailable:6,freeSlots:1})}));
|
||||
assert.equal(quote.earlyRequired,false); assert.equal(quote.shared,null);
|
||||
assert.deepEqual(quote.separate,{cacheBid:null,ordinary:{minimum:6,maximum:6}});
|
||||
assert.equal(quote.possible,true);
|
||||
const blocked=quoteJointEarlyRicheseBids(input({early:[early(4,false)],phase:[phase(6,true),phase(6,false)],
|
||||
ordinary:ordinary({cashAvailable:10})}));
|
||||
assert.equal(blocked.shared,null); assert.equal(blocked.separate,null); assert.equal(blocked.possible,false);
|
||||
});
|
||||
|
||||
void test('only the respondent’s live receipts for this turn bind the joint quote',() => {
|
||||
const quote=quoteJointEarlyRicheseBids(input({
|
||||
early:[early(3,true),early(1,false,{id:'other',player:'richese'}),
|
||||
early(1,false,{id:'old',turn:2}),early(1,false,{id:'bound',boundEvent:'real-cache'}),
|
||||
early(1,false,{id:'finished',fulfilled:true}),early(1,false,{id:'released',released:true})],
|
||||
phase:[phase(4,true),phase(1,false,{event:'other',player:'richese'}),
|
||||
phase(1,false,{event:'old',turn:2}),phase(1,false,{event:'finished',fulfilled:true}),
|
||||
phase(1,false,{event:'released',released:true})],
|
||||
}));
|
||||
assert.deepEqual(quote.cache,{minimum:3,maximum:10});
|
||||
assert.deepEqual(quote.shared,{minimum:4,maximum:10});
|
||||
assert.equal(quote.possible,true);
|
||||
});
|
||||
|
||||
void test('zero and maximum safe integer budgets do not invent funding',() => {
|
||||
assert.equal(quoteJointEarlyRicheseBids(input({cacheMaximum:0,early:[early(1,true)]})).possible,false);
|
||||
assert.equal(quoteJointEarlyRicheseBids(input({cacheMaximum:0,early:[early(1,false)]})).possible,true);
|
||||
const max=Number.MAX_SAFE_INTEGER;
|
||||
const single=quoteJointEarlyRicheseBids(input({cacheMaximum:max,early:[early(max,true)],phase:[phase(max,true)]}));
|
||||
assert.deepEqual(single.shared,{minimum:max,maximum:max}); assert.equal(single.possible,true);
|
||||
for (const cacheMaximum of [-1,0.5,Infinity,Number.NaN,Number.MAX_SAFE_INTEGER+1])
|
||||
assert.throws(() => quoteJointEarlyRicheseBids(input({cacheMaximum})));
|
||||
assert.throws(() => quoteJointEarlyRicheseBids(input({turn:0})));
|
||||
assert.throws(() => quoteJointEarlyRicheseBids(input({player:' emperor '})));
|
||||
assert.throws(() => quoteJointEarlyRicheseBids(input({phase:[phase(1,true)],
|
||||
ordinary:ordinary({cashAvailable:1,aidAvailable:-1})})));
|
||||
assert.throws(() => quoteJointEarlyRicheseBids(input({phase:[phase(1,true)],
|
||||
ordinary:ordinary({opportunity:{player:'richese',turn:3,kind:'future',minimum:1,maximum:1}})})));
|
||||
});
|
||||
@@ -0,0 +1,138 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { handLimit, viewGame, type Game } 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';
|
||||
|
||||
/** Public Basic setup; explicitly supplement only physical card custody.
|
||||
* Atreides and Richese receive original unopened cards up to their hand limits;
|
||||
* Emperor receives the original Distrans from the cache. No purse, auction,
|
||||
* phase, promise or outcome is installed. Atreides discards its original
|
||||
* Truthtrance, then Emperor uses the actual Distrans to fill that freed slot.
|
||||
* The natural Bidding declaration therefore has only one eligible seat and
|
||||
* the compulsory cache consumes that sole lot. */
|
||||
function source() {
|
||||
const f = fixture({advanced:false});
|
||||
let game = structuredClone(f.earlySource);
|
||||
const karamaIndex = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(karamaIndex >= 0);
|
||||
const [karama] = game.deck.splice(karamaIndex,1);
|
||||
player(game,f.asker).hand.push(karama);
|
||||
for (const id of [f.asker,f.richese]) {
|
||||
const owner = player(game,id);
|
||||
while (owner.hand.length < handLimit(owner)) {
|
||||
const [card] = game.deck.splice(0,1); assert.ok(card);
|
||||
owner.hand.push(card);
|
||||
}
|
||||
}
|
||||
const index = game.richeseCache!.findIndex(card => card.effect === 'distrans'); assert.ok(index >= 0);
|
||||
const [distrans] = game.richeseCache!.splice(index,1);
|
||||
player(game,f.emperor).hand.push(distrans);
|
||||
const given = player(game,f.emperor).hand.find(card => card.id !== distrans.id); assert.ok(given);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
game = ask(game,f,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:6});
|
||||
assert.ok(viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'));
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
const receipt = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(receipt);
|
||||
game = act(game,f.emperor,{type:'card',card:distrans.id,target:f.asker,give:given.id});
|
||||
game = passTruthRicheseFreshDiscard(game);
|
||||
assert.equal(player(game,f.asker).hand.length,handLimit(player(game,f.asker)));
|
||||
assert.equal(player(game,f.richese).hand.length,handLimit(player(game,f.richese)));
|
||||
assert.ok(player(game,f.emperor).hand.length < handLimit(player(game,f.emperor)));
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === receipt.event && !row.released && !row.fulfilled));
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
game = advance(game,state => state.decision?.kind === 'richeseDeclaration');
|
||||
assert.equal(game.richeseBidding?.normalCountBeforeCache,1);
|
||||
assert.equal(game.richeseBidding?.normalCount,0);
|
||||
return {f,game,receipt,karama:karama.id};
|
||||
}
|
||||
|
||||
void test('a phase Yes remains funded by the sole actual cache when no ordinary lots remain', () => {
|
||||
const {f,receipt,...bound} = source();
|
||||
let game = advance(bound.game,state => clean(state) && !!state.richeseAuction &&
|
||||
state.richeseAuction.source === 'cache' && state.richeseAuction.method === 'silent' &&
|
||||
!state.richeseAuction.outcome, [], {position:'first',method:'silent'});
|
||||
assert.equal(game.richeseBidding?.normalCount,0);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === receipt.event && !row.released));
|
||||
const lot = game.richeseAuction!, purse = player(game,f.emperor).spice;
|
||||
const guide = viewGame(game,f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.amount,6);
|
||||
game = act(game,f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === receipt.event && row.fulfilled));
|
||||
game = advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId));
|
||||
assert.equal(player(game,f.emperor).spice,purse-6);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
void test('external cache cancellation restores an ordinary lot and preserves the phase Yes', () => {
|
||||
const {f,receipt,karama,...bound} = source();
|
||||
let game:Game = act(bound.game,f.richese,
|
||||
{type:'decision',event:bound.game.richeseBidding!.event,position:'first'});
|
||||
assert.equal(game.response?.kind,'richeseAuction');
|
||||
game = act(game,f.asker,{type:'card',card:karama,mode:'cancel'});
|
||||
game = passTruthRicheseFreshDiscard(game);
|
||||
assert.equal(game.richeseBidding?.cacheCanceled,true);
|
||||
assert.equal(game.richeseBidding?.normalCount,1);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === receipt.event && !row.fulfilled && !row.released));
|
||||
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor);
|
||||
const card = game.auction!.cards[game.auction!.index].id, purse = player(game,f.emperor).spice;
|
||||
const guide = viewGame(game,f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'bid'); assert.equal(guide.amount,6);
|
||||
game = act(game,f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === receipt.event && row.fulfilled));
|
||||
game = advance(game,state => player(state,f.emperor).hand.some(item => item.id === card));
|
||||
assert.equal(player(game,f.emperor).spice,purse-6);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
void test('external cache cancellation releases the early Yes but retains the phase Yes for the restored ordinary lot', () => {
|
||||
const f = fixture({advanced:false});
|
||||
let game = structuredClone(f.earlySource);
|
||||
// Two original unopened cards change custody: Atreides receives a second
|
||||
// Truthtrance and the printed Karama. No auction, funding or receipt is
|
||||
// fabricated; both questions and the cancellation use native controls.
|
||||
const secondIndex = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(secondIndex >= 0);
|
||||
const [secondTruth] = game.deck.splice(secondIndex,1);
|
||||
const karamaIndex = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(karamaIndex >= 0);
|
||||
const [karama] = game.deck.splice(karamaIndex,1);
|
||||
player(game,f.asker).hand.push(secondTruth,karama);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
game = ask(game,f,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:4});
|
||||
assert.ok(viewGame(game,f.emperor).truthEarlyRicheseBidAnswers?.includes('yes'));
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.emperor); assert.ok(early);
|
||||
game = act(game,f.asker,{type:'card',card:secondTruth.id});
|
||||
game = advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game = act(game,f.asker,{type:'truthAsk',question:{
|
||||
kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:6,
|
||||
}});
|
||||
assert.ok(viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'));
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(phase);
|
||||
game = advance(game,state => state.decision?.kind === 'richeseDeclaration');
|
||||
const ordinaryBefore = game.richeseBidding!.normalCount!;
|
||||
game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,position:'first'});
|
||||
assert.equal(game.response?.kind,'richeseAuction');
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.asker,{type:'card',card:karama.id,mode:'cancel'}));
|
||||
assert.equal(game.richeseBidding?.cacheCanceled,true);
|
||||
assert.equal(game.richeseBidding?.normalCount,ordinaryBefore+1);
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === early.id && row.released && !row.boundEvent));
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase.event && !row.fulfilled && !row.released));
|
||||
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor);
|
||||
const card = game.auction!.cards[game.auction!.index].id, purse = player(game,f.emperor).spice;
|
||||
const guide = viewGame(game,f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'bid'); assert.equal(guide.amount,6);
|
||||
game = act(game,f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase.event && row.fulfilled));
|
||||
game = advance(game,state => player(state,f.emperor).hand.some(item => item.id === card));
|
||||
assert.equal(player(game,f.emperor).spice,purse-6);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import type { TruthQuestion } from '../game/truthtrance';
|
||||
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';
|
||||
|
||||
type Fixture = ReturnType<typeof fixture>;
|
||||
|
||||
/** Public Basic source with explicitly staged legacy Semuta marker and card
|
||||
* custody. A second original Truth moves from the unopened deck to Atreides;
|
||||
* for a third question its first discarded original card is later recovered
|
||||
* by a conserved zone move. No phase, auction, bid or receipt is fabricated.
|
||||
* This covers a legacy saved profile, not a fresh Basic Richese start. */
|
||||
function source() {
|
||||
const f = fixture({advanced:false}), game = structuredClone(f.earlySource);
|
||||
delete game.semutaPreview;
|
||||
const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(index >= 0);
|
||||
const [second] = game.deck.splice(index,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
assert.equal(player(game,f.emperor).spice,10);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game,second:second.id};
|
||||
}
|
||||
|
||||
function recoverOriginal(game:Game,f:Fixture,card:string) {
|
||||
const at = game.discard.findIndex(row => row.id === card);
|
||||
assert.ok(at >= 0,'The original discarded Truthtrance remains available for conserved staging');
|
||||
player(game,f.asker).hand.push(game.discard.splice(at,1)[0]);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
}
|
||||
|
||||
function ask(game:Game,f:Fixture,card:string,question:TruthQuestion,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});
|
||||
const view=viewGame(game,f.emperor);
|
||||
const choices=question.kind === 'earlyRicheseBid' ? view.truthEarlyRicheseBidAnswers :
|
||||
question.kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthBidAnswers;
|
||||
assert.ok(choices?.includes(answer),`${question.kind} must offer ${answer}: ${JSON.stringify(choices)}`);
|
||||
return passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer}));
|
||||
}
|
||||
|
||||
void test('a phase Yes cannot reuse the funds already needed for a mandatory ordinary bid and later cache',() => {
|
||||
const {f,second,...start}=source(); let game=start.game;
|
||||
game=ask(game,f,f.truth,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:1},'yes');
|
||||
game=advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,
|
||||
[],{position:'last',method:'silent'});
|
||||
const lot=game.auction!.index+1;
|
||||
game=ask(game,f,second,{kind:'bid',target:f.emperor,turn:game.turn,lot,minimum:9},'yes');
|
||||
recoverOriginal(game,f,f.truth);
|
||||
game=act(game,f.asker,{type:'card',card:f.truth});
|
||||
game=advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game=act(game,f.asker,{type:'truthAsk',question:{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:10}});
|
||||
assert.ok(!viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'),
|
||||
'Ten spice cannot fund both the current nine-spice bid and a later ten-spice cache bid, or a ten-spice ordinary bid plus cache one');
|
||||
const before=structuredClone(game);
|
||||
assert.throws(() => act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
assert.deepEqual(game,before);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
|
||||
void test('an external shortfall releases only the higher phase Yes while the lower Yes can still use the cache',() => {
|
||||
const {f,second,...start}=source(); let game=start.game;
|
||||
game=ask(game,f,f.truth,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:6},'no');
|
||||
recoverOriginal(game,f,f.truth);
|
||||
game=ask(game,f,second,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:4},'yes');
|
||||
game=ask(game,f,f.truth,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:8},'yes');
|
||||
const low=game.phaseAnyBidPromises?.find(row => row.player === f.emperor && row.minimum === 4);
|
||||
const high=game.phaseAnyBidPromises?.find(row => row.player === f.emperor && row.minimum === 8);
|
||||
assert.ok(low && high);
|
||||
// Simulate an external loss rather than inventing a specific unimplemented
|
||||
// interrupt: the other player's real ready action triggers reconciliation.
|
||||
player(game,f.emperor).spice=6;
|
||||
const other=game.players.find(row => row.id !== f.emperor && !game.ready.includes(row.id));
|
||||
assert.ok(other,'A different original player can complete Charity');
|
||||
game=act(game,other.id,{type:'ready'});
|
||||
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === low.event)?.released,false);
|
||||
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === high.event)?.released,true);
|
||||
assert.equal(!!game.earlyRicheseBidPromises?.find(row => row.player === f.emperor)?.released,false);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,214 @@
|
||||
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 Answer = 'yes' | 'no';
|
||||
type Kind = 'phaseAnyBid' | 'earlyRicheseBid';
|
||||
|
||||
/** The real public-start Richese/Atreides/Emperor fixture orders unopened
|
||||
* setup and Spice cards. For two actual questions, move one additional original
|
||||
* Truthtrance from the unopened deck into Atreides' hand; no wallets, auctions,
|
||||
* or receipts are fabricated. */
|
||||
function source() {
|
||||
const f = fixture({ advanced: false });
|
||||
const game = structuredClone(f.earlySource);
|
||||
const at = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(at >= 0, 'A second original Truthtrance must remain in the unopened deck');
|
||||
const [second] = game.deck.splice(at, 1);
|
||||
player(game, f.asker).hand.push(second);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
return { f, game, second: second.id };
|
||||
}
|
||||
|
||||
function openQuestion(game: Game, f: TruthtranceRichesePromisesFixture, card: string, kind: Kind, minimum: number) {
|
||||
game = act(game, f.asker, { type: 'card', card });
|
||||
game = advance(game, state => state.truthtrance?.stage === 'ask');
|
||||
return act(game, f.asker, { type: 'truthAsk', question: { kind, target: f.emperor, turn: game.turn, minimum } });
|
||||
}
|
||||
|
||||
function options(game: Game, f: TruthtranceRichesePromisesFixture, kind: Kind) {
|
||||
const view = viewGame(game, f.emperor);
|
||||
return kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers;
|
||||
}
|
||||
|
||||
function answer(game: Game, f: TruthtranceRichesePromisesFixture, kind: Kind, value: Answer) {
|
||||
assert.ok(options(game, f, kind)?.includes(value), `${kind} ${value} must be offered when jointly feasible`);
|
||||
return passTruthRicheseFreshDiscard(act(game, f.emperor, { type: 'truthAnswer', answer: value }));
|
||||
}
|
||||
|
||||
function reject(game: Game, actor: string, action: Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game, actor, action));
|
||||
assert.deepEqual(game, before, 'A rejected declaration or stale guide preserves its source');
|
||||
}
|
||||
|
||||
for (const method of ['onceAround', 'silent'] as const)
|
||||
for (const position of ['first', 'last'] as const)
|
||||
for (const first of ['phaseAnyBid', 'earlyRicheseBid'] as const)
|
||||
for (const phaseAnswer of ['yes', 'no'] as const)
|
||||
for (const earlyAnswer of ['yes', 'no'] as const) void test(
|
||||
`Basic ${position} ${method}: ${first} first, phase ${phaseAnswer}, early ${earlyAnswer}`, () => {
|
||||
const { f, second, ...initial } = source();
|
||||
// Both Yes requirements can share a bid of 6. A No caps at 6,
|
||||
// leaving the other Yes's bid of 4 possible in the same cache.
|
||||
const phaseMinimum = phaseAnswer === 'yes' ? 4 : 6;
|
||||
const earlyMinimum = earlyAnswer === 'yes' && phaseAnswer === 'yes' ? 6 :
|
||||
earlyAnswer === 'yes' ? 4 : 6;
|
||||
const secondKind: Kind = first === 'phaseAnyBid' ? 'earlyRicheseBid' : 'phaseAnyBid';
|
||||
const minimum = (kind: Kind) => kind === 'phaseAnyBid' ? phaseMinimum : earlyMinimum;
|
||||
const response = (kind: Kind) => kind === 'phaseAnyBid' ? phaseAnswer : earlyAnswer;
|
||||
let game = openQuestion(initial.game, f, f.truth, first, minimum(first));
|
||||
game = answer(game, f, first, response(first));
|
||||
game = openQuestion(game, f, second, secondKind, minimum(secondKind));
|
||||
game = answer(game, f, secondKind, response(secondKind));
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.emperor);
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.emperor);
|
||||
assert.ok(early && phase);
|
||||
assert.equal(early.answer, earlyAnswer === 'yes');
|
||||
assert.equal(phase.answer, phaseAnswer === 'yes');
|
||||
assert.equal(early.boundEvent, undefined, 'The future cache has no invented event');
|
||||
|
||||
game = advance(game, state => clean(state) && !!state.richeseAuction &&
|
||||
state.richeseAuction.source === 'cache' && state.richeseAuction.method === method &&
|
||||
!state.richeseAuction.outcome, [], { position, method });
|
||||
const lot = game.richeseAuction!;
|
||||
const event = lot.event, card = lot.cardId;
|
||||
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === early.id)?.boundEvent, event);
|
||||
if (method === 'onceAround')
|
||||
game = advance(game, state => clean(state) && state.richeseAuction?.active === f.emperor);
|
||||
const native = game.richeseBidPromises?.find(row => row.id === early.id); assert.ok(native);
|
||||
assert.equal(native.event, event);
|
||||
const view = viewGame(game, f.emperor);
|
||||
const guide = view.phaseAnyBidGuide?.action ?? view.richeseBidPromiseGuide?.action;
|
||||
assert.ok(guide, 'A jointly legal native guide is available');
|
||||
assert.equal(guide.type, 'richeseBid');
|
||||
assert.doesNotThrow(() => act(game, f.emperor, guide));
|
||||
if (guide.phaseAnyBidPromiseEvent !== undefined)
|
||||
reject(game, f.emperor, { ...guide, phaseAnyBidPromiseEvent: 'stale-phase' });
|
||||
if (guide.richeseBidPromiseId !== undefined)
|
||||
reject(game, f.emperor, { ...guide, richeseBidPromiseId: 'stale-cache' });
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const bot = viewGame(game, f.emperor);
|
||||
bot.players.find(row => row.id === f.emperor)!.bot = difficulty;
|
||||
const chosen = botActions(bot)[0]; assert.ok(chosen, difficulty);
|
||||
assert.doesNotThrow(() => act(game, f.emperor, chosen), difficulty);
|
||||
}
|
||||
if (phaseAnswer === 'no')
|
||||
reject(game, f.emperor, { type: 'richeseBid', event, amount: phaseMinimum, allyPayment: 0 });
|
||||
if (earlyAnswer === 'no')
|
||||
reject(game, f.emperor, { type: 'richeseBid', event, amount: earlyMinimum, allyPayment: 0 });
|
||||
if (earlyAnswer === 'yes')
|
||||
reject(game, f.emperor, { type: 'richeseBid', event, amount: method === 'silent' ? 0 : null });
|
||||
const amount = earlyAnswer === 'yes' ? earlyMinimum : phaseAnswer === 'yes' ? phaseMinimum : 2;
|
||||
const before = player(game, f.emperor).spice;
|
||||
game = act(game, f.emperor, { type: 'richeseBid', event, amount, allyPayment: 0 });
|
||||
assert.equal(player(game, f.emperor).spice, before, 'A declaration does not prepay the invoice');
|
||||
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === phase.event)?.fulfilled, phaseAnswer === 'yes');
|
||||
assert.ok(game.richeseBidPromises?.find(row => row.id === early.id)?.fulfilled);
|
||||
game = advance(game, state => player(state, f.emperor).hand.some(item => item.id === card),
|
||||
[], { position, method });
|
||||
assert.equal(player(game, f.emperor).spice, before - amount);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
});
|
||||
|
||||
for (const first of ['phaseAnyBid', 'earlyRicheseBid'] as const) void test(
|
||||
`A phase No 6 conflicts with an early cache Yes 6 when ${first} is asked first`, () => {
|
||||
const { f, second, ...initial } = source();
|
||||
const secondKind: Kind = first === 'phaseAnyBid' ? 'earlyRicheseBid' : 'phaseAnyBid';
|
||||
const firstAnswer = first === 'phaseAnyBid' ? 'no' : 'yes';
|
||||
let game = openQuestion(initial.game, f, f.truth, first, 6);
|
||||
game = answer(game, f, first, firstAnswer);
|
||||
game = openQuestion(game, f, second, secondKind, 6);
|
||||
const impossible = secondKind === 'phaseAnyBid' ? 'no' : 'yes';
|
||||
assert.ok(!options(game, f, secondKind)?.includes(impossible),
|
||||
'A definite answer cannot demand a cache bid that its phase-wide No forbids');
|
||||
reject(game, f.emperor, { type: 'truthAnswer', answer: impossible });
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
});
|
||||
|
||||
void test('a voluntary bribe preserves the common funded Yes witness', () => {
|
||||
const { f, second, ...initial } = source();
|
||||
let game = openQuestion(initial.game, f, f.truth, 'phaseAnyBid', 6);
|
||||
game = answer(game, f, 'phaseAnyBid', 'yes');
|
||||
game = openQuestion(game, f, second, 'earlyRicheseBid', 4);
|
||||
game = answer(game, f, 'earlyRicheseBid', 'yes');
|
||||
reject(game, f.emperor, {type:'bribe',target:f.asker,amount:5});
|
||||
game = act(game, f.emperor, {type:'bribe',target:f.asker,amount:4});
|
||||
assert.equal(player(game, f.emperor).spice, 6);
|
||||
game = advance(game, state => clean(state) && !!state.richeseAuction &&
|
||||
state.richeseAuction.source === 'cache' && state.richeseAuction.method === 'silent', [],
|
||||
{position:'first',method:'silent'});
|
||||
const guide = viewGame(game, f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type, 'richeseBid'); assert.equal(guide.amount, 6);
|
||||
game = act(game, f.emperor, guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
});
|
||||
|
||||
for (const position of ['first', 'last'] as const)
|
||||
for (const method of ['onceAround', 'silent'] as const)
|
||||
for (const first of ['phaseAnyBid', 'earlyRicheseBid'] as const)
|
||||
for (const earlyAnswer of ['yes', 'no'] as const) void test(
|
||||
`Basic ${position} ${method}: ${first} first, phase Yes 6 and cache ${earlyAnswer} 4 may use separately funded bids`, () => {
|
||||
const { f, second, ...initial } = source();
|
||||
const secondKind: Kind = first === 'phaseAnyBid' ? 'earlyRicheseBid' : 'phaseAnyBid';
|
||||
const min = (kind: Kind) => kind === 'phaseAnyBid' ? 6 : 4;
|
||||
const response = (kind: Kind) => kind === 'phaseAnyBid' ? 'yes' : earlyAnswer;
|
||||
let game = openQuestion(initial.game, f, f.truth, first, min(first));
|
||||
game = answer(game, f, first, response(first));
|
||||
game = openQuestion(game, f, second, secondKind, min(secondKind));
|
||||
game = answer(game, f, secondKind, response(secondKind));
|
||||
const originalSpice = player(game, f.emperor).spice;
|
||||
assert.equal(originalSpice, 10, 'Use the real Emperor starting funds');
|
||||
const round = {position,method};
|
||||
const cacheBid = earlyAnswer === 'yes' ? 4 : 2;
|
||||
|
||||
const ordinary = (sourceGame: Game) => advance(sourceGame,
|
||||
state => clean(state) && !!state.auction && state.auction.active === f.emperor, [], round);
|
||||
const cache = (sourceGame: Game) => {
|
||||
let current = advance(sourceGame, state => clean(state) && !!state.richeseAuction &&
|
||||
state.richeseAuction.source === 'cache' && !state.richeseAuction.outcome, [], round);
|
||||
if (method === 'onceAround')
|
||||
current = advance(current, state => clean(state) && state.richeseAuction?.active === f.emperor, [], round);
|
||||
return current;
|
||||
};
|
||||
const payOrdinary = (current: Game) => {
|
||||
const guide = viewGame(current, f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type, 'bid'); assert.equal(guide.amount, 6);
|
||||
if (earlyAnswer === 'yes' && position === 'last')
|
||||
reject(current, f.emperor, {type:'bid',amount:7,allyPayment:0});
|
||||
const card = current.auction!.cards[current.auction!.index].id;
|
||||
const placed = act(current, f.emperor, guide);
|
||||
assert.ok(placed.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
||||
return advance(placed, state => player(state, f.emperor).hand.some(item => item.id === card), [], round);
|
||||
};
|
||||
const payCache = (current: Game) => {
|
||||
const lot = current.richeseAuction!, card = lot.cardId;
|
||||
if (earlyAnswer === 'no')
|
||||
reject(current, f.emperor, {type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
||||
else
|
||||
reject(current, f.emperor, {type:'richeseBid',event:lot.event,amount:method === 'silent' ? 0 : null});
|
||||
const placed = act(current, f.emperor, {type:'richeseBid',event:lot.event,amount:cacheBid,allyPayment:0});
|
||||
if (position === 'first')
|
||||
assert.ok(placed.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.fulfilled && !row.released));
|
||||
assert.ok(placed.richeseBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
||||
return advance(placed, state => player(state, f.emperor).hand.some(item => item.id === card), [], round);
|
||||
};
|
||||
game = position === 'first' ? payCache(cache(game)) : payOrdinary(ordinary(game));
|
||||
game = position === 'first' ? payOrdinary(ordinary(game)) : payCache(cache(game));
|
||||
assert.equal(player(game, f.emperor).spice, originalSpice - cacheBid - 6);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,122 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { advanceAuctionClock, synchronizeAuctionClock, viewGame, type Game } from '../game/engine';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import type { TruthQuestion } from '../game/truthtrance';
|
||||
import {
|
||||
actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance,
|
||||
createTruthtranceRichesePromisesFixture as fixture, nextTruthtranceRichesePromisesStep as next,
|
||||
passTruthRicheseFreshDiscard, truthtranceRichesePromisesClean as clean,
|
||||
truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player,
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
type Fixture = ReturnType<typeof fixture>;
|
||||
type Method = 'onceAround' | 'silent';
|
||||
type Kind = 'earlyRicheseBid' | 'phaseAnyBid';
|
||||
|
||||
/** Native public Basic setup; only a second physical Truthtrance moves from
|
||||
* the unopened deck to Atreides. The original cache, hands, funds and both
|
||||
* later auction sales retain their real physical identities and controls. */
|
||||
function source() {
|
||||
const f = fixture({advanced:false});
|
||||
const game = structuredClone(f.earlySource);
|
||||
const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(index >= 0);
|
||||
const [second] = game.deck.splice(index,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
assert.equal(player(game,f.emperor).spice,10);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game,second:second.id};
|
||||
}
|
||||
function question(game:Game,f:Fixture,card:string,kind:Kind,minimum:number,answer:'yes'|'no') {
|
||||
game = act(game,f.asker,{type:'card',card});
|
||||
game = advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
const claim:TruthQuestion = {kind,target:f.emperor,turn:game.turn,minimum};
|
||||
game = act(game,f.asker,{type:'truthAsk',question:claim});
|
||||
const view = viewGame(game,f.emperor);
|
||||
const choices = kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers;
|
||||
assert.ok(choices?.includes(answer),`${kind} must offer ${answer}: ${JSON.stringify(choices)}`);
|
||||
return passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer}));
|
||||
}
|
||||
function both(first:Kind) {
|
||||
const {f,second,...initial} = source(); let game = initial.game;
|
||||
const secondKind:Kind = first === 'phaseAnyBid' ? 'earlyRicheseBid' : 'phaseAnyBid';
|
||||
const minimum = (kind:Kind) => kind === 'phaseAnyBid' ? 4 : 6;
|
||||
game = question(game,f,f.truth,first,minimum(first),'yes');
|
||||
game = question(game,f,second,secondKind,minimum(secondKind),'yes');
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === f.emperor); assert.ok(early);
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(phase);
|
||||
return {game,f,early,phase};
|
||||
}
|
||||
function ordinaryTurn(game:Game,f:Fixture,method:Method) {
|
||||
const opts = {position:'last' as const,method};
|
||||
game = advance(game,state => clean(state) && !!state.auction,[],opts);
|
||||
for (let count=0;game.auction?.active !== f.emperor && count<game.players.length;count++) {
|
||||
const actor=game.auction?.active; assert.ok(actor);
|
||||
game=act(game,actor,{type:'passBid'});
|
||||
}
|
||||
assert.equal(game.auction?.active,f.emperor);
|
||||
assert.equal(game.richeseBidding?.position,'last');
|
||||
return game;
|
||||
}
|
||||
function lastCache(game:Game,method:Method) {
|
||||
const opts = {position:'last' as const,method};
|
||||
for (let count=0;count<1000;count++) {
|
||||
if (clean(game) && game.richeseAuction?.source === 'cache' && !game.richeseAuction.outcome) return game;
|
||||
const step=next(game,opts); assert.ok(step,'Native controls must reach the actual last cache');
|
||||
game=act(game,step.actor,step.action);
|
||||
}
|
||||
throw Error('The real last cache did not open');
|
||||
}
|
||||
|
||||
for (const first of ['phaseAnyBid','earlyRicheseBid'] as const)
|
||||
for (const method of ['onceAround','silent'] as const) void test(
|
||||
`Basic last ${method}, ${first} first: ordinary phase Yes purchase retains independently funded cache Yes`,() => {
|
||||
const bound=both(first), f=bound.f;
|
||||
let game=ordinaryTurn(bound.game,f,method);
|
||||
const ordinaryCard=game.auction!.cards[game.auction!.index].id;
|
||||
const before=structuredClone(game);
|
||||
assert.throws(() => act(game,f.emperor,{type:'bid',amount:5,allyPayment:0}),
|
||||
'A five-spice purchase would leave less than the six-spice cache promise');
|
||||
assert.deepEqual(game,before,'Rejected overcommitment cannot change either receipt or auction');
|
||||
const guide=viewGame(game,f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'bid'); assert.equal(guide.amount,4);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const bot=viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot=difficulty;
|
||||
const action=botActions(bot)[0]; assert.ok(action,`${difficulty} supplies a legal ordinary action`);
|
||||
assert.doesNotThrow(() => act(game,f.emperor,action));
|
||||
}
|
||||
game=act(game,f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.find(row => row.event === bound.phase.event)?.fulfilled);
|
||||
const waiting=game.earlyRicheseBidPromises?.find(row => row.id === bound.early.id); assert.ok(waiting);
|
||||
assert.equal(waiting.boundEvent,undefined); assert.equal(!!waiting.released,false);
|
||||
assert.equal(player(game,f.emperor).spice,10,'The native winning declaration is not prepaid');
|
||||
game=lastCache(game,method);
|
||||
assert.ok(player(game,f.emperor).hand.some(card => card.id === ordinaryCard));
|
||||
assert.equal(player(game,f.emperor).spice,6,'The actual ordinary invoice reserves the cache budget');
|
||||
const lot=game.richeseAuction!;
|
||||
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === bound.early.id)?.boundEvent,lot.event);
|
||||
if (method === 'onceAround') game=advance(game,state => clean(state) &&
|
||||
state.richeseAuction?.event === lot.event && state.richeseAuction.active === f.emperor,[],{position:'last',method});
|
||||
const native=viewGame(game,f.emperor).richeseBidPromiseGuide?.action;
|
||||
assert.ok(native); assert.equal(native.type,'richeseBid'); assert.equal(native.amount,6);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const bot=viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot=difficulty;
|
||||
const action=botActions(bot)[0]; assert.ok(action,`${difficulty} supplies a legal cache action`);
|
||||
assert.doesNotThrow(() => act(game,f.emperor,action));
|
||||
}
|
||||
if (method === 'onceAround') {
|
||||
const armed=synchronizeAuctionClock(game,1_000,'last-cache');
|
||||
const expired=advanceAuctionClock(armed,11_000,'last-cache');
|
||||
assert.ok(expired.richeseBidPromises?.find(row => row.id === bound.early.id)?.fulfilled,
|
||||
'The native deadline honors the attached early Yes');
|
||||
}
|
||||
game=act(game,f.emperor,native);
|
||||
assert.ok(game.richeseBidPromises?.find(row => row.id === bound.early.id)?.fulfilled);
|
||||
assert.equal(player(game,f.emperor).spice,6);
|
||||
game=advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId),
|
||||
[],{position:'last',method});
|
||||
assert.equal(player(game,f.emperor).spice,0);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import {
|
||||
actTruthtranceRichesePromises as act,
|
||||
createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard,
|
||||
truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player,
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
/** Genuine public Basic Richese setup; a second physical Truthtrance moves
|
||||
* from unopened deck to Atreides and Semuta moves from Richese cache to its
|
||||
* owner. No answer, bid, purse or reaction is manufactured. */
|
||||
function source() {
|
||||
const f=fixture({advanced:false});
|
||||
const game=structuredClone(f.earlySource);
|
||||
assert.equal(game.semutaPreview,true);
|
||||
const secondAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(secondAt>=0);
|
||||
const [second]=game.deck.splice(secondAt,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 parent(game:Game) {
|
||||
return structuredClone({turn:game.turn,phase:game.phase,active:game.active,ready:game.ready,order:game.order,
|
||||
auction:game.auction,richeseAuction:game.richeseAuction,richeseBidding:game.richeseBidding,aid:game.aid});
|
||||
}
|
||||
|
||||
for (const first of ['phase','early'] as const) for (const claim of [false,true]) void test(
|
||||
`Basic early ${first} first: second Truth Semuta ${claim ? 'claim' : 'pass'} binds both waiting ledgers`,() => {
|
||||
const f=source(), original=parent(f.game);
|
||||
const phase={kind:'phaseAnyBid',target:f.f.emperor,turn:f.game.turn,minimum:4};
|
||||
const early={kind:'earlyRicheseBid',target:f.f.emperor,turn:f.game.turn,minimum:6};
|
||||
let game=act(f.game,f.f.asker,{type:'card',card:f.f.truth,cards:[f.second]});
|
||||
while (game.truthtrance?.stage === 'priority') {
|
||||
const actor=game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor);
|
||||
game=act(game,actor.id,{type:'truthPass'});
|
||||
}
|
||||
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.f.truth,f.second]);
|
||||
game=act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? phase : early});
|
||||
game=act(game,f.f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
const single=game.pendingTreacheryDiscard; assert.ok(single?.reaction);
|
||||
assert.equal(single.continuation.kind,'truthtranceDiscard');
|
||||
assert.equal(single.continuation.jointEarlyPhaseBid,undefined,'The older single-answer receipt keeps its shape');
|
||||
game=passTruthRicheseFreshDiscard(game);
|
||||
assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.second]);
|
||||
game=act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? early : phase});
|
||||
game=act(game,f.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,f.second);
|
||||
assert.equal(viewGame(game,f.f.richese).semutaReaction?.canCommit,true);
|
||||
const phasePromises=structuredClone(game.phaseAnyBidPromises), earlyPromises=structuredClone(game.earlyRicheseBidPromises);
|
||||
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,f.f.richese,{type:'semutaCommit',event:pending.batch.event}),
|
||||
`The completed answer binds ${family}`);
|
||||
}
|
||||
game=claim ? act(game,f.f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game);
|
||||
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
|
||||
assert.equal(player(game,f.f.richese).hand.some(card => card.id === f.second),claim);
|
||||
assert.equal(game.discard.some(card => card.id === f.semuta),claim);
|
||||
assert.deepEqual(game.phaseAnyBidPromises,phasePromises); assert.deepEqual(game.earlyRicheseBidPromises,earlyPromises);
|
||||
assert.deepEqual(parent(game),original);
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.player === f.f.emperor && !row.boundEvent && !row.released));
|
||||
assert.deepEqual(inventory(game),f.f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user