400 lines
25 KiB
TypeScript
400 lines
25 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { advanceAuctionClock, hasAuctionClockOpportunity, synchronizeAuctionClock,
|
|
viewGame, type Action, type Game } from '../game/engine';
|
|
import { botActions } from '../game/bots';
|
|
import { DIFFICULTIES } from '../game/bot-profiles';
|
|
import { createTruthAllianceFixture, declareTruthAlliance, finishTruthAlliance,
|
|
actTruthAlliance, truthAllianceInventory, truthAlliancePlayer } from './fixture-truth-alliance';
|
|
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';
|
|
|
|
type Method = 'normal' | 'onceAround' | 'silent';
|
|
type Source = ReturnType<typeof fixture>;
|
|
function reject(game: Game, actor: string, action: Action) {
|
|
const before = structuredClone(game);
|
|
assert.throws(() => act(game, actor, action));
|
|
assert.deepEqual(game, before);
|
|
}
|
|
function askAny(source: Game, f: Source) {
|
|
return ask(source, f, {kind:'phaseAnyBid', target:f.emperor, turn:source.turn, minimum:4});
|
|
}
|
|
function bindAny(asked: Game, f: Source, answer: 'yes'|'no') {
|
|
assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes(answer));
|
|
return passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer}));
|
|
}
|
|
function currentCache(game: Game, f: Source, method: Exclude<Method,'normal'>, position: 'first'|'last' = 'first') {
|
|
const options = {position,method};
|
|
let state = advance(game, g => clean(g) && !!g.richeseAuction &&
|
|
g.richeseAuction.source === 'cache' && !g.richeseAuction.outcome, [], options);
|
|
if (method === 'onceAround')
|
|
state = advance(state,g => clean(g) && g.richeseAuction?.active === f.emperor, [], options);
|
|
return state;
|
|
}
|
|
function blackMarket(game: Game, f: Source, method: Method) {
|
|
let state = advance(game,g => g.decision?.kind === 'richeseBlackMarket');
|
|
const card = f.targetCard, event = state.richeseBidding!.event;
|
|
assert.ok(player(state,f.richese).hand.some(item => item.id === card));
|
|
state = act(state,f.richese,{type:'decision',event,card,method,
|
|
...(method === 'onceAround' ? {direction:'clockwise'} : {})});
|
|
while (state.response) {
|
|
const actor = state.players.find(row => !state.response!.passed.includes(row.id)); assert.ok(actor);
|
|
state = act(state,actor.id,{type:'passResponse'});
|
|
}
|
|
assert.equal(state.richeseAuction?.source,'blackMarket');
|
|
return state;
|
|
}
|
|
function targetTurn(game: Game, f: Source, method: Method) {
|
|
if (method === 'silent') return game;
|
|
let state = game;
|
|
for (let n = 0; state.richeseAuction?.active !== f.emperor && n < 10; n++) {
|
|
const lot = state.richeseAuction; assert.ok(lot && !lot.outcome && lot.active);
|
|
// Keep the auction alive until the actual target's own opportunity.
|
|
state = act(state,lot.active,{type:'richeseBid',event:lot.event,amount:null});
|
|
}
|
|
assert.equal(state.richeseAuction?.active,f.emperor);
|
|
return state;
|
|
}
|
|
|
|
/** Genuine R/A/E setup and real turn-one Charity. The fixture stages only
|
|
* unopened original deal and Spice order plus native scalar rolls. */
|
|
for (const method of ['onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
|
|
void test(`Basic pre-Bidding all-auction ${answer} governs the first real ${method} cache declaration`, () => {
|
|
const f = fixture({advanced:false}), asked = askAny(structuredClone(f.earlySource),f);
|
|
let game = bindAny(asked,f,answer);
|
|
const live = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(live);
|
|
game = currentCache(game,f,method);
|
|
const lot = game.richeseAuction!;
|
|
const held = inventory(game), amount = answer === 'yes' ? 4 : 2;
|
|
if (answer === 'yes') {
|
|
for (const lower of [3,method === 'silent' ? 0 : null]) {
|
|
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:lower,allyPayment:0});
|
|
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
|
|
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
|
|
}
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
|
|
for (const difficulty of DIFFICULTIES) {
|
|
const bot = viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot = difficulty;
|
|
assert.deepEqual(botActions(bot)[0],guide.action);
|
|
}
|
|
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
|
const before = player(game,f.emperor).spice;
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
|
|
const result = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(result);
|
|
assert.equal(!!result.fulfilled,answer === 'yes');
|
|
assert.equal(player(game,f.emperor).spice,before,'Declaring a bid is not the purchase invoice');
|
|
if (method === 'silent' && game.richeseAuction?.event === lot.event) {
|
|
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
|
|
}
|
|
assert.deepEqual(inventory(game),held);
|
|
const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId),
|
|
[], {position:'first',method});
|
|
assert.equal(player(purchased,f.emperor).spice,before-amount);
|
|
assert.ok(!purchased.richeseCache?.some(card => card.id === lot.cardId));
|
|
assert.deepEqual(inventory(purchased),held);
|
|
});
|
|
|
|
for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
|
|
void test(`Advanced current ${method} Black Market all-auction ${answer} preserves the seller card and native bid`, () => {
|
|
const f = fixture({advanced:true});
|
|
const source = blackMarket(structuredClone(f.earlySource),f,method);
|
|
const lot = source.richeseAuction!;
|
|
const asked = askAny(source,f);
|
|
let game = bindAny(asked,f,answer);
|
|
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
|
|
game = targetTurn(game,f,method);
|
|
const amount = answer === 'yes' ? 4 : 2;
|
|
if (answer === 'yes') {
|
|
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
|
|
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
|
|
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
|
|
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
|
const purse = player(game,f.emperor).spice, seller = player(game,f.richese).spice;
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
|
|
assert.equal(player(game,f.emperor).spice,purse);
|
|
const row = game.phaseAnyBidPromises?.find(item => item.player === f.emperor); assert.ok(row);
|
|
assert.equal(!!row.fulfilled,answer === 'yes');
|
|
if (method === 'silent') {
|
|
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
|
|
}
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === f.targetCard));
|
|
assert.equal(player(purchased,f.emperor).spice,purse-amount);
|
|
assert.equal(player(purchased,f.richese).spice,seller+amount);
|
|
assert.ok(!player(purchased,f.richese).hand.some(card => card.id === f.targetCard));
|
|
assert.deepEqual(inventory(purchased),f.originalCards);
|
|
});
|
|
|
|
for (const method of ['onceAround','silent'] as const) void test(
|
|
`A saved ordinary-only phaseBid remains ordinary-only during a real ${method} cache lot`, () => {
|
|
const f = fixture({advanced:false});
|
|
const asked = ask(structuredClone(f.earlySource),f,{kind:'phaseBid',target:f.emperor,turn:f.earlySource.turn,minimum:4});
|
|
assert.ok(viewGame(asked,f.emperor).truthPhaseBidAnswers?.includes('no'));
|
|
let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'}));
|
|
game = currentCache(game,f,method);
|
|
const lot = game.richeseAuction!;
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
|
const legacy = game.phaseBidPromises?.find(row => row.player === f.emperor); assert.ok(legacy);
|
|
assert.equal(legacy.answer,false); assert.equal(!!legacy.fulfilled,false);
|
|
assert.equal(!!legacy.released,false);
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
for (const advanced of [false,true]) for (const method of ['onceAround','silent'] as const)
|
|
for (const answer of ['yes','no'] as const) void test(
|
|
`${advanced?'Advanced':'Basic'} current ${method} cache accepts an all-auction ${answer}`, () => {
|
|
const f = fixture({advanced});
|
|
const source = currentCache(structuredClone(f.earlySource),f,method);
|
|
const lot = source.richeseAuction!;
|
|
const asked = askAny(source,f);
|
|
let game = bindAny(asked,f,answer);
|
|
assert.ok(game.richeseCache?.some(card => card.id === lot.cardId));
|
|
const amount = answer === 'yes' ? 4 : 2;
|
|
if (answer === 'yes') {
|
|
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
|
|
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
|
|
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'});
|
|
reject(game,f.emperor,{...guide.action,phaseAnyBidLotEvent:'stale-lot'});
|
|
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
|
|
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes');
|
|
if (method === 'silent') {
|
|
assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null);
|
|
assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null);
|
|
}
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const)
|
|
void test(`Advanced pre-Bidding all-auction ${answer} binds an actual ${method} Black Market bid`, () => {
|
|
const f = fixture({advanced:true});
|
|
const asked = askAny(structuredClone(f.earlySource),f);
|
|
let game = bindAny(asked,f,answer);
|
|
game = blackMarket(game,f,method);
|
|
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
|
|
game = targetTurn(game,f,method);
|
|
const lot = game.richeseAuction!;
|
|
if (answer === 'yes') {
|
|
const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
|
|
const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise);
|
|
assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false);
|
|
} else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0});
|
|
const amount = answer === 'yes' ? 4 : 2;
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0});
|
|
assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes');
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
void test('Advanced all-auction Yes permits the Richese seller to retain its own Silent Black Market card', () => {
|
|
const f = fixture({advanced:true}), source = structuredClone(f.earlySource);
|
|
const asked = ask(source,f,{kind:'phaseAnyBid',target:f.richese,turn:source.turn,minimum:4});
|
|
assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes'));
|
|
let game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'}));
|
|
game = blackMarket(game,f,'silent');
|
|
const lot = game.richeseAuction!, originalHand = player(game,f.richese).hand.map(card => card.id);
|
|
const seller = player(game,f.richese).spice, emperor = player(game,f.emperor).spice;
|
|
const guide = viewGame(game,f.richese).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
|
|
game = act(game,f.richese,guide.action);
|
|
assert.equal(viewGame(game,f.asker).richeseAuction?.ownBid,null);
|
|
assert.equal(viewGame(game,f.asker).richeseAuction?.revealedBids,null);
|
|
for (const actor of [f.asker,f.emperor])
|
|
game = act(game,actor,{type:'richeseBid',event:lot.event,amount:0,allyPayment:0});
|
|
assert.deepEqual(player(game,f.richese).hand.map(card => card.id),originalHand);
|
|
assert.equal(player(game,f.richese).spice,seller-4);
|
|
assert.equal(player(game,f.emperor).spice,emperor+4);
|
|
assert.equal(game.richeseBidding?.blackMarketSold,true);
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.fulfilled));
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
void test('Basic all-auction Yes follows the ordinary native bid guide and is fulfilled by its actual declaration', () => {
|
|
const f = fixture({advanced:false});
|
|
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
|
|
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,
|
|
[], {position:'first',method:'onceAround'});
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4);
|
|
reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'});
|
|
reject(game,f.emperor,{...guide.action,phaseAnyBidLot:999});
|
|
const before = player(game,f.emperor).spice;
|
|
game = act(game,f.emperor,guide.action);
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
|
assert.equal(player(game,f.emperor).spice,before);
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
void test('Basic all-auction No is fulfilled only at real Bidding close', () => {
|
|
const f = fixture({advanced:false});
|
|
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'no');
|
|
game = advance(game,state => state.phase > 3 && clean(state), [], {position:'first',method:'silent'});
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.answer && row.fulfilled && !row.released));
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
/** Reach the last cache through a real earlier ordinary purchase. Richese has
|
|
* four spendable spice and its own eventual Once Around bid becomes possible
|
|
* only after the real Emperor's opening bid. No board, balance or lot is staged. */
|
|
function finalCache() {
|
|
const f = fixture({advanced:false}), options = {position:'last' as const,method:'onceAround' as const};
|
|
let game = advance(structuredClone(f.earlySource),state => clean(state) && !!state.auction,[],options);
|
|
assert.equal(game.auction?.active,f.richese);
|
|
game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0});
|
|
game = advance(game,state => clean(state) && state.phase === 3 && !!state.richeseAuction && !state.richeseAuction.outcome,[],options);
|
|
const lot = game.richeseAuction!;
|
|
assert.equal(lot.source,'cache'); assert.equal(lot.active,f.emperor);
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
|
|
assert.equal(game.richeseAuction?.active,f.asker);
|
|
const asked = ask(game,f,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:4});
|
|
assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes'));
|
|
game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'}));
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.answer && !row.fulfilled));
|
|
return {f,game,lot:lot.event};
|
|
}
|
|
|
|
void test('an actual opposing raise can externally release an impossible all-auction Yes at the final cache', () => {
|
|
const f = finalCache();
|
|
let game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0});
|
|
const promise = game.phaseAnyBidPromises?.find(row => row.player === f.f.richese); assert.ok(promise);
|
|
assert.equal(!!promise.released,true); assert.equal(!!promise.fulfilled,false);
|
|
assert.equal(game.richeseAuction?.active,f.f.richese);
|
|
game = act(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
|
|
assert.deepEqual(inventory(game),f.f.originalCards);
|
|
});
|
|
|
|
void test('an expiring final-cache clock makes the required all-auction Yes bid', () => {
|
|
const f = finalCache();
|
|
const game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
|
|
assert.equal(game.richeseAuction?.active,f.f.richese);
|
|
assert.ok(hasAuctionClockOpportunity(game));
|
|
reject(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0});
|
|
const guide = viewGame(game,f.f.richese).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4);
|
|
const armed = synchronizeAuctionClock(game,1_000,'phase-any-bid-test:0');
|
|
const expired = advanceAuctionClock(armed,11_000,'phase-any-bid-test:0');
|
|
assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.f.richese && row.answer && row.fulfilled));
|
|
assert.match(expired.log.at(-1)!.text,/legal bid required by their binding Truthtrance answer was submitted/);
|
|
assert.deepEqual(inventory(expired),f.f.originalCards);
|
|
});
|
|
|
|
for (const first of ['phaseBid','phaseAnyBid'] as const) void test(
|
|
`a live ${first} answer prevents an incompatible second bid-family question`, () => {
|
|
const f = fixture({advanced:false});
|
|
const source = structuredClone(f.earlySource);
|
|
const asked = ask(source,f,{kind:first,target:f.emperor,turn:source.turn,minimum:4});
|
|
let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'}));
|
|
// The original second physical Truth is moved from the unopened deck into
|
|
// its owner's hand solely to exercise two real questions in this same turn.
|
|
const index = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(index >= 0);
|
|
const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second);
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
game = act(game,f.asker,{type:'card',card:second.id});
|
|
game = advance(game,state => state.truthtrance?.stage === 'ask');
|
|
const kind = first === 'phaseBid' ? 'phaseAnyBid' : 'phaseBid';
|
|
reject(game,f.asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum:5}});
|
|
});
|
|
|
|
for (const method of ['onceAround','silent'] as const) void test(
|
|
`a smaller ${method} cache bid preserves a later funded ordinary all-auction Yes`, () => {
|
|
const f = fixture({advanced:false}), options = {position:'first' as const,method};
|
|
let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
|
|
game = currentCache(game,f,method);
|
|
const lot = game.richeseAuction!, spice = player(game,f.emperor).spice;
|
|
game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0});
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released));
|
|
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,[],options);
|
|
assert.ok(player(game,f.emperor).hand.some(card => card.id === lot.cardId));
|
|
assert.equal(player(game,f.emperor).spice,spice-3);
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4);
|
|
game = act(game,f.emperor,guide.action);
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
for (const claim of [false,true]) void test(
|
|
`Advanced all-auction Truth answer offers Semuta and ${claim ? 'claim' : 'pass'} retains the bid and Black Market lot`, () => {
|
|
const f = fixture({advanced:true});
|
|
let source = structuredClone(f.earlySource);
|
|
// Conserved supplement: move the original Semuta from Richese's cache to
|
|
// its hand. The original dealt Shield remains the actual sale card.
|
|
const cache = source.richeseCache!, index = cache.findIndex(card => card.effect === 'semutaDrug');
|
|
assert.ok(index >= 0);
|
|
const [semuta] = cache.splice(index,1); player(source,f.richese).hand.push(semuta);
|
|
assert.deepEqual(inventory(source),f.originalCards);
|
|
source = targetTurn(blackMarket(source,f,'onceAround'),f,'onceAround');
|
|
const lot = structuredClone(source.richeseAuction), funding = structuredClone(source.richeseFunding);
|
|
const asked = askAny(source,f);
|
|
assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes('yes'));
|
|
let game = act(asked,f.emperor,{type:'truthAnswer',answer:'yes'});
|
|
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
|
assert.equal(pending.continuation.kind,'truthtranceDiscard');
|
|
assert.equal(pending.batch.entries[0].card.id,f.truth);
|
|
assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true);
|
|
const promise = structuredClone(game.phaseAnyBidPromises);
|
|
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
|
|
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
|
|
game = claim ? act(game,f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game);
|
|
assert.equal(game.pendingTreacheryDiscard,null);
|
|
assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding);
|
|
assert.deepEqual(game.phaseAnyBidPromises,promise);
|
|
assert.equal(player(game,f.richese).hand.some(card => card.id === f.truth),claim);
|
|
assert.equal(game.discard.some(card => card.id === semuta.id),claim);
|
|
assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard));
|
|
const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide);
|
|
game = act(game,f.emperor,guide.action);
|
|
assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled));
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|
|
|
|
void test('a voluntary real bribe cannot spend the last money required by an all-auction Yes', () => {
|
|
const f = fixture({advanced:false});
|
|
const game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes');
|
|
assert.equal(player(game,f.emperor).spice,10);
|
|
reject(game,f.emperor,{type:'bribe',target:f.richese,amount:7});
|
|
const paid = act(game,f.emperor,{type:'bribe',target:f.richese,amount:6});
|
|
assert.equal(player(paid,f.emperor).spice,4);
|
|
assert.ok(paid.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released));
|
|
assert.deepEqual(inventory(paid),f.originalCards);
|
|
});
|
|
|
|
void test('an Emperor cannot give away spice required by an all-auction Yes', () => {
|
|
const f = createTruthAllianceFixture({advanced:true,consent:'allied'});
|
|
const charity = finishTruthAlliance(f.game);
|
|
const declared = declareTruthAlliance(f,charity).game;
|
|
const asked = actTruthAlliance(declared,f.asker,{type:'truthAsk',question:{kind:'phaseAnyBid',
|
|
target:f.target,turn:declared.turn,minimum:4}});
|
|
assert.ok(viewGame(asked,f.target).truthPhaseAnyBidAnswers?.includes('yes'));
|
|
const game = actTruthAlliance(asked,f.target,{type:'truthAnswer',answer:'yes'});
|
|
assert.equal(truthAlliancePlayer(game,f.target).spice,10);
|
|
const before = structuredClone(game);
|
|
assert.throws(() => actTruthAlliance(game,f.target,{type:'emperorGift',amount:7}));
|
|
assert.deepEqual(game,before);
|
|
let shared = actTruthAlliance(game,f.target,{type:'emperorGift',amount:6});
|
|
for (let n = 0; shared.response?.kind === 'emperorGift' && n < 10; n++) {
|
|
const actor = shared.players.find(row => !shared.response!.passed.includes(row.id)); assert.ok(actor);
|
|
shared = actTruthAlliance(shared,actor.id,{type:'passResponse'});
|
|
}
|
|
assert.equal(truthAlliancePlayer(shared,f.target).spice,4);
|
|
assert.ok(shared.phaseAnyBidPromises?.some(row => row.player === f.target && row.answer && !row.fulfilled && !row.released));
|
|
assert.deepEqual(truthAllianceInventory(shared),f.originalCards);
|
|
});
|