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,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);
|
||||
});
|
||||
Reference in new issue
Block a user