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