Support Advanced early cache bid promises
Verify and publish checkpoint container / container (push) Successful in 11m48s
Verify and publish checkpoint container / container (push) Successful in 11m48s
This commit is contained in:
1 parent
1a65e69932
commit
225b2174ad
14 files changed
+1071
-22
No files matched your search
@@ -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);
|
||||
});
|
||||
Reference in new issue
Block a user