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