Compose market, early cache and phase bid promises
Verify and publish checkpoint container / container (push) Successful in 12m4s
Verify and publish checkpoint container / container (push) Successful in 12m4s
This commit is contained in:
1 parent
225b2174ad
commit
6a30fdf376
16 files changed
+1183
-21
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { quoteJointMarketEarlyBids, type JointMarketEarlyBidInput } from '../game/joint-market-early-bids';
|
||||
import type { RicheseBidPromise } from '../game/richese-bid-promises';
|
||||
import type { EarlyRicheseBidPromise } from '../game/early-richese-bid';
|
||||
import type { PhaseBidPromise } from '../game/turn-bid-promises';
|
||||
|
||||
const context = {turn:3,event:'market-event',player:'emperor'};
|
||||
const native = (minimum:number,answer:boolean,extra:Partial<RicheseBidPromise> = {}):RicheseBidPromise =>
|
||||
({...context,id:`market-${minimum}-${answer}`,asker:'atreides',minimum,answer,...extra});
|
||||
const early = (minimum:number,answer:boolean,extra:Partial<EarlyRicheseBidPromise> = {}):EarlyRicheseBidPromise =>
|
||||
({turn:3,player:'emperor',id:`cache-${minimum}-${answer}`,asker:'atreides',minimum,answer,...extra});
|
||||
const phase = (minimum:number,answer:boolean,extra:Partial<PhaseBidPromise> = {}):PhaseBidPromise =>
|
||||
({turn:3,player:'emperor',event:`phase-${minimum}-${answer}`,asker:'atreides',minimum,answer,...extra});
|
||||
const input = (extra:Partial<JointMarketEarlyBidInput> = {}):JointMarketEarlyBidInput => ({
|
||||
context,native:[],early:[],phase:[],opportunity:{...context,minimum:1,maximum:10},
|
||||
cashAvailable:10,aidAvailable:0,cacheMaximum:10,freeSlots:2,marketEntrySlots:1,marketWinSlots:1,...extra,
|
||||
});
|
||||
|
||||
void test('a native Yes and waiting cache Yes reserve independent purchases without any phase receipt',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({native:[native(6,true)],early:[early(4,true)]}));
|
||||
assert.equal(result.nativeRequired,true); assert.equal(result.earlyRequired,true); assert.equal(result.phaseRequired,false);
|
||||
assert.equal(result.canPass,false);
|
||||
assert.deepEqual(result.market,{minimum:6,maximum:6,allyPayment:0});
|
||||
assert.equal(result.marketForPhase,null); assert.equal(result.marketForCache,null);
|
||||
});
|
||||
|
||||
void test('all three ledgers intersect their own Yes and No bounds',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({
|
||||
native:[native(4,true),native(6,false)],early:[early(4,true),early(6,false)],
|
||||
phase:[phase(5,true),phase(7,false)],
|
||||
}));
|
||||
assert.deepEqual(result.market,{minimum:4,maximum:5,allyPayment:0});
|
||||
assert.deepEqual(result.marketForPhase,{minimum:5,maximum:5,allyPayment:0});
|
||||
assert.deepEqual(result.marketForCache,{minimum:4,maximum:5,allyPayment:0});
|
||||
assert.equal(result.canPass,false);
|
||||
const blocked = quoteJointMarketEarlyBids(input({native:[native(4,true)],early:[early(4,true)],phase:[phase(4,false)]}));
|
||||
assert.equal(blocked.market,null); assert.equal(blocked.canPass,false);
|
||||
});
|
||||
|
||||
void test('an unaffordable native and cache pair cannot borrow an assumed refund',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({native:[native(7,true)],early:[early(4,true)]}));
|
||||
assert.equal(result.market,null); assert.equal(result.canPass,false);
|
||||
const aided = quoteJointMarketEarlyBids(input({native:[native(7,true)],early:[early(4,true)],aidAvailable:1}));
|
||||
assert.deepEqual(aided.market,{minimum:7,maximum:7,allyPayment:1});
|
||||
});
|
||||
|
||||
void test('allied market funding preserves the personal cash required by a higher later phase bid',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({native:[native(4,true)],early:[early(2,true)],
|
||||
phase:[phase(6,true)],cashAvailable:8,aidAvailable:2,cacheMaximum:8}));
|
||||
assert.deepEqual(result.market,{minimum:4,maximum:8,allyPayment:0});
|
||||
assert.deepEqual(result.marketForPhase,{minimum:6,maximum:8,allyPayment:0});
|
||||
assert.deepEqual(result.marketForCache,{minimum:4,maximum:4,allyPayment:2});
|
||||
const noAid = quoteJointMarketEarlyBids(input({native:[native(4,true)],early:[early(2,true)],
|
||||
phase:[phase(6,true)],cashAvailable:8,aidAvailable:0,cacheMaximum:8}));
|
||||
assert.equal(noAid.marketForCache,null);
|
||||
});
|
||||
|
||||
void test('paid self-retention needs no incoming hand slot but another buyer does',() => {
|
||||
const common = {native:[native(6,true)],early:[early(4,true)],freeSlots:1};
|
||||
const seller = quoteJointMarketEarlyBids(input({...common,marketEntrySlots:0,marketWinSlots:0}));
|
||||
assert.deepEqual(seller.market,{minimum:6,maximum:6,allyPayment:0});
|
||||
const other = quoteJointMarketEarlyBids(input(common));
|
||||
assert.equal(other.market,null);
|
||||
});
|
||||
|
||||
void test('a Harkonnen market win reserves its potential bonus before the later cache',() => {
|
||||
const common = {native:[native(4,true)],early:[early(4,true)],marketEntrySlots:1,marketWinSlots:2};
|
||||
const two = quoteJointMarketEarlyBids(input({...common,freeSlots:2}));
|
||||
assert.equal(two.market,null);
|
||||
const three = quoteJointMarketEarlyBids(input({...common,freeSlots:3}));
|
||||
assert.deepEqual(three.market,{minimum:4,maximum:6,allyPayment:0});
|
||||
const noCache = quoteJointMarketEarlyBids(input({native:[native(4,true)],freeSlots:1,
|
||||
marketEntrySlots:1,marketWinSlots:2}));
|
||||
assert.deepEqual(noCache.market,{minimum:4,maximum:10,allyPayment:0},
|
||||
'After the only required bid, an unavailable bonus slot does not prevent that bid');
|
||||
});
|
||||
|
||||
void test('individual native Yes receipts can be re-quoted against all live No caps',() => {
|
||||
const low = native(4,true), high = native(8,true), cap = native(9,false);
|
||||
const common = {early:[early(2,true)],cashAvailable:9,cacheMaximum:9};
|
||||
const both = quoteJointMarketEarlyBids(input({...common,native:[low,high,cap]}));
|
||||
assert.equal(both.market,null);
|
||||
const onlyLow = quoteJointMarketEarlyBids(input({...common,native:[low,cap]}));
|
||||
assert.deepEqual(onlyLow.market,{minimum:4,maximum:7,allyPayment:0});
|
||||
const onlyHigh = quoteJointMarketEarlyBids(input({...common,native:[high,cap]}));
|
||||
assert.equal(onlyHigh.market,null);
|
||||
});
|
||||
|
||||
void test('a cache No can leave a phase Yes for another actually proven auction',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({native:[native(4,false)],early:[early(4,false)],phase:[phase(6,true)]}));
|
||||
assert.equal(result.nativeRequired,false); assert.equal(result.canPass,true);
|
||||
assert.deepEqual(result.market,{minimum:1,maximum:3,allyPayment:0});
|
||||
assert.equal(result.marketForPhase,null); assert.equal(result.marketForCache,null);
|
||||
assert.equal(result.phaseCacheAfterPass,null);
|
||||
});
|
||||
|
||||
void test('receipts from other seats, turns and finished events do not constrain the quote',() => {
|
||||
const result = quoteJointMarketEarlyBids(input({
|
||||
native:[native(4,true),native(1,false,{id:'old-lot',event:'old'}),native(1,false,{id:'done',fulfilled:true})],
|
||||
early:[early(2,true),early(1,false,{id:'other',player:'richese'}),early(1,false,{id:'bound',boundEvent:'cache'})],
|
||||
phase:[phase(5,true),phase(1,false,{event:'old-turn',turn:2}),phase(1,false,{event:'released',released:true})],
|
||||
}));
|
||||
assert.deepEqual(result.market,{minimum:4,maximum:8,allyPayment:0});
|
||||
assert.deepEqual(result.marketForPhase,{minimum:5,maximum:8,allyPayment:0});
|
||||
});
|
||||
|
||||
void test('invalid or stale opportunity and resource inputs fail closed',() => {
|
||||
for (const cashAvailable of [-1,0.5,Number.NaN,Infinity,Number.MAX_SAFE_INTEGER+1])
|
||||
assert.throws(() => quoteJointMarketEarlyBids(input({cashAvailable})));
|
||||
assert.throws(() => quoteJointMarketEarlyBids(input({marketEntrySlots:2,marketWinSlots:1})));
|
||||
assert.throws(() => quoteJointMarketEarlyBids(input({opportunity:{...context,event:'other',minimum:1,maximum:10}})));
|
||||
const noOpportunity = quoteJointMarketEarlyBids(input({native:[native(1,false)],opportunity:null}));
|
||||
assert.equal(noOpportunity.market,null); assert.equal(noOpportunity.canPass,true);
|
||||
});
|
||||
@@ -61,7 +61,7 @@ function market(game:Game, f:TruthtranceRichesePromisesFixture, card:string, met
|
||||
return game;
|
||||
}
|
||||
|
||||
void test('Advanced current Black Market bid question cannot strand a waiting early cache Yes', () => {
|
||||
void test('Advanced current Black Market answer 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);
|
||||
@@ -70,11 +70,16 @@ void test('Advanced current Black Market bid question cannot strand a waiting ea
|
||||
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');
|
||||
game = act(game,f.f.asker,{type:'truthAsk',question});
|
||||
const choices = viewGame(game,f.f.emperor).truthRicheseBidAnswers;
|
||||
assert.ok(!choices?.includes('yes'),'The two six-spice purchases cannot both be funded from ten');
|
||||
assert.ok(choices?.includes('no'),'A lower or declined current bid can preserve the cache promise');
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,f.f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
assert.deepEqual(game,before,'Rejected answer cannot mutate the auction, question or cache receipt');
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.f.emperor,{type:'truthAnswer',answer:'no'}));
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.player === f.f.emperor && row.event === event && !row.answer));
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { advanceAuctionClock, synchronizeAuctionClock, viewGame, type Game } from '../game/engine';
|
||||
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';
|
||||
|
||||
/** Original Advanced R/A/E public start. The second original Truthtrance and
|
||||
* original Semuta move from unopened zones. A real Semuta claim returns the
|
||||
* first discarded Truthtrance for the third question; no player purse, phase,
|
||||
* auction, clock or commitment is installed by the fixture. */
|
||||
function source() {
|
||||
const f=fixture({advanced:true}); let game:Game=structuredClone(f.earlySource);
|
||||
const truthAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(truthAt >= 0); const [second]=game.deck.splice(truthAt,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
const semutaAt=game.richeseCache!.findIndex(card => card.effect === 'semutaDrug');
|
||||
assert.ok(semutaAt >= 0); const [semuta]=game.richeseCache!.splice(semutaAt,1);
|
||||
player(game,f.richese).hand.push(semuta);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
|
||||
function ask(asker:string,card:string,question:Record<string,unknown>,claim=false) {
|
||||
game=act(game,asker,{type:'card',card});
|
||||
game=advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game=act(game,asker,{type:'truthAsk',question});
|
||||
game=act(game,f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
if (!claim) { game=passTruthRicheseFreshDiscard(game); return; }
|
||||
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
||||
assert.ok(viewGame(game,f.richese).semutaReaction?.canCommit);
|
||||
game=act(game,f.richese,{type:'semutaCommit',event:pending.batch.event});
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game=act(game,f.richese,{type:'semutaSelect',event:pending.batch.event,card});
|
||||
assert.ok(player(game,f.richese).hand.some(item => item.id === card));
|
||||
}
|
||||
ask(f.asker,f.truth,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:4},true);
|
||||
ask(f.asker,second.id,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:6});
|
||||
const phase=game.phaseAnyBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(phase);
|
||||
const early=game.earlyRicheseBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(early);
|
||||
game=advance(game,state => state.decision?.kind === 'richeseBlackMarket');
|
||||
game=act(game,f.richese,{type:'decision',event:game.richeseBidding!.event,card:f.targetCard,
|
||||
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'});
|
||||
}
|
||||
game=advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor);
|
||||
const lot=game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket' && lot.clockVersion === 1);
|
||||
ask(f.richese,f.truth,{kind:'richeseBid',target:f.emperor,turn:game.turn,event:lot.event,minimum:4});
|
||||
const native=game.richeseBidPromises?.find(row => row.player === f.emperor && row.event === lot.event && row.answer);
|
||||
assert.ok(native); assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {game,f,event:lot.event,phase,early,native};
|
||||
}
|
||||
|
||||
void test('Advanced Once Around market clock executes the shared three-way guide once',() => {
|
||||
const s=source(), view=viewGame(s.game,s.f.emperor);
|
||||
const guide=view.richeseBidPromiseGuide?.action; assert.ok(guide && view.phaseAnyBidGuide);
|
||||
assert.deepEqual(guide,view.phaseAnyBidGuide.action);
|
||||
assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,s.event); assert.equal(guide.amount,4);
|
||||
assert.equal(guide.richeseBidPromiseId,s.native.id);
|
||||
assert.equal(guide.earlyRicheseBidPromiseId,s.early.id);
|
||||
assert.equal(guide.phaseAnyBidPromiseEvent,s.phase.event);
|
||||
assert.equal(player(s.game,s.f.emperor).spice,10);
|
||||
|
||||
const armed=synchronizeAuctionClock(s.game,1_000,'advanced-three-ledger');
|
||||
const expired=advanceAuctionClock(armed,11_000,'advanced-three-ledger');
|
||||
assert.equal(expired.richeseAuction?.event,s.event);
|
||||
assert.equal(expired.richeseAuction?.bidder,s.f.emperor);
|
||||
assert.equal(expired.richeseAuction?.bid,4);
|
||||
assert.equal(expired.richeseFunding?.[s.f.emperor]?.amount,4);
|
||||
assert.equal(player(expired,s.f.emperor).spice,10,'A bid is reserved before payment');
|
||||
assert.ok(expired.richeseBidPromises?.some(row => row.id === s.native.id && row.fulfilled));
|
||||
assert.ok(expired.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled));
|
||||
assert.ok(expired.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
|
||||
const again=advanceAuctionClock(expired,11_000,'advanced-three-ledger');
|
||||
assert.equal(again.richeseAuction?.bid,4);
|
||||
assert.equal(again.richeseAuction?.acted.filter(id => id === s.f.emperor).length,1);
|
||||
assert.equal(again.richeseFunding?.[s.f.emperor]?.amount,4);
|
||||
|
||||
let game=advance(again,state => player(state,s.f.emperor).hand.some(card => card.id === s.f.targetCard));
|
||||
assert.equal(player(game,s.f.emperor).spice,6);
|
||||
game=advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' &&
|
||||
state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'});
|
||||
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === s.early.id)?.boundEvent,game.richeseAuction!.event);
|
||||
const cache=viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(cache);
|
||||
assert.equal(cache.amount,6);
|
||||
game=act(game,s.f.emperor,cache);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.early.id && row.fulfilled));
|
||||
const cacheCard=game.richeseAuction!.cardId;
|
||||
game=advance(game,state => player(state,s.f.emperor).hand.some(card => card.id === cacheCard),
|
||||
[],{position:'first',method:'silent'});
|
||||
assert.equal(player(game,s.f.emperor).spice,0);
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createElement, isValidElement, type ReactElement, type ReactNode } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises';
|
||||
import { RicheseBidPromiseGuide, RicheseBidPromisePanel } from '../components/richese-bid-promise-panel';
|
||||
import { MixedRicheseBidPromises } from '../components/mixed-richese-bid-promises';
|
||||
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 Props = {children?: ReactNode; [key:string]:unknown};
|
||||
type Kind = 'richeseBid' | 'mixedRicheseBid';
|
||||
const elements = (node:ReactNode):ReactElement<Props>[] => Array.isArray(node) ? node.flatMap(elements) :
|
||||
!isValidElement<Props>(node) ? [] : [node,...elements(node.props.children)];
|
||||
|
||||
/** A genuine Advanced public start. Move the second original Truthtrance and
|
||||
* Semuta from unopened zones, then actually reclaim the first discarded Truth
|
||||
* with Semuta to ask the third question. No wallet, bid or receipt is staged. */
|
||||
function source(method:'silent'|'onceAround',kind:Kind) {
|
||||
const f=fixture({advanced:true}); let game:Game=structuredClone(f.earlySource);
|
||||
const truthAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(truthAt >= 0); const [second]=game.deck.splice(truthAt,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
const semutaAt=game.richeseCache!.findIndex(card => card.effect === 'semutaDrug');
|
||||
assert.ok(semutaAt >= 0); const [semuta]=game.richeseCache!.splice(semutaAt,1);
|
||||
player(game,f.richese).hand.push(semuta);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
|
||||
function ask(asker:string,card:string,question:Record<string,unknown>,claim=false) {
|
||||
game=act(game,asker,{type:'card',card});
|
||||
game=advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game=act(game,asker,{type:'truthAsk',question});
|
||||
game=act(game,f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
if (!claim) { game=passTruthRicheseFreshDiscard(game); return; }
|
||||
const pending=game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
||||
assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true);
|
||||
game=act(game,f.richese,{type:'semutaCommit',event:pending.batch.event});
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game=act(game,f.richese,{type:'semutaSelect',event:pending.batch.event,card});
|
||||
assert.ok(player(game,f.richese).hand.some(item => item.id === card));
|
||||
}
|
||||
ask(f.asker,f.truth,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:4},true);
|
||||
ask(f.asker,second.id,{kind:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:6});
|
||||
game=advance(game,state => state.decision?.kind === 'richeseBlackMarket');
|
||||
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'});
|
||||
}
|
||||
if (method === 'onceAround') game=advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor);
|
||||
const lot=game.richeseAuction!;
|
||||
assert.equal(lot.source,'blackMarket');
|
||||
const question=kind === 'richeseBid' ? {kind,target:f.emperor,turn:game.turn,event:lot.event,minimum:4} :
|
||||
{kind,target:f.emperor,turn:game.turn,event:lot.event,mixed:{kind:'and',terms:[
|
||||
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},{kind:'action',action:{minimum:4}},
|
||||
]}};
|
||||
ask(f.richese,f.truth,question);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {game,f};
|
||||
}
|
||||
|
||||
for (const method of ['onceAround','silent'] as const) for (const kind of ['richeseBid','mixedRicheseBid'] as const) void test(
|
||||
`Advanced ${method} ${kind} three-way guides share a live owner-bound action`,() => {
|
||||
const {game,f}=source(method,kind), view=viewGame(game,f.emperor), sent:Action[]=[];
|
||||
assert.ok(view.phaseAnyBidGuide && view.richeseBidPromiseGuide);
|
||||
assert.deepEqual(view.phaseAnyBidGuide.action,view.richeseBidPromiseGuide.action);
|
||||
const action=view.phaseAnyBidGuide.action, early=view.ownEarlyRicheseBidPromises.find(row => !row.boundEvent && !row.released);
|
||||
const phase=view.phaseAnyBidPromises.find(row => !row.fulfilled && !row.released);
|
||||
assert.ok(early && phase); assert.equal(action.type,'richeseBid'); assert.equal(action.amount,4);
|
||||
assert.equal(action.earlyRicheseBidPromiseId,early.id);
|
||||
assert.equal(action.phaseAnyBidPromiseEvent,phase.event);
|
||||
assert.equal(action.phaseAnyBidLotEvent,view.richeseAuction!.event);
|
||||
const phaseProps={game:view,busy:false,send(value:Action){sent.push(value);}};
|
||||
const localProps={game:view,promises:view.richeseBidPromises,guide:view.richeseBidPromiseGuide,busy:false,
|
||||
act(value:Action){sent.push(value);}};
|
||||
const mixedProps={game:view,busy:false,send(value:Action){sent.push(value);}};
|
||||
assert.match(renderToStaticMarkup(createElement(PhaseAnyBidPromises,phaseProps)),/data-testid="phase-any-bid-guide"/);
|
||||
const phaseButton=PhaseAnyBidGuideButton(phaseProps); assert.ok(phaseButton);
|
||||
const html=kind === 'richeseBid' ? renderToStaticMarkup(createElement(RicheseBidPromisePanel,localProps)) :
|
||||
renderToStaticMarkup(createElement(MixedRicheseBidPromises,mixedProps));
|
||||
assert.match(html,kind === 'richeseBid' ? /Your (?:Once Around|Silent) bid promises/ : /Your mixed Richese bid promises/);
|
||||
const localButton=kind === 'richeseBid' ? RicheseBidPromiseGuide(localProps) :
|
||||
elements(MixedRicheseBidPromises(mixedProps)).find(node => node.props['data-testid'] === 'mixed-richese-bid-promise-guide');
|
||||
assert.ok(localButton);
|
||||
const clickPhase=() => phaseButton.props.onClick();
|
||||
const clickLocal=() => (localButton.props.onClick as () => void)();
|
||||
clickPhase(); clickLocal(); assert.deepEqual(sent,[action,action]);
|
||||
phaseProps.busy=true; localProps.busy=true; mixedProps.busy=true;
|
||||
clickPhase(); clickLocal(); assert.equal(sent.length,2);
|
||||
phaseProps.busy=false; localProps.busy=false; mixedProps.busy=false;
|
||||
const event=view.richeseAuction!.event; view.richeseAuction!.event='stale-market';
|
||||
clickPhase(); clickLocal(); assert.equal(sent.length,2); view.richeseAuction!.event=event;
|
||||
const acted=[...view.richeseAuction!.acted];
|
||||
view.richeseAuction!.acted.push('changed-public-seat');
|
||||
clickPhase(); clickLocal(); assert.equal(sent.length,2,'Same-event public auction progress invalidates both callbacks');
|
||||
view.richeseAuction!.acted.splice(0,view.richeseAuction!.acted.length,...acted);
|
||||
if (method === 'silent') {
|
||||
const ownBid=view.richeseAuction!.ownBid; view.richeseAuction!.ownBid=1;
|
||||
clickPhase(); clickLocal(); assert.equal(sent.length,2,'A changed own Silent submission invalidates both callbacks');
|
||||
view.richeseAuction!.ownBid=ownBid;
|
||||
}
|
||||
phase.fulfilled=true; clickPhase(); clickLocal(); assert.equal(sent.length,2); phase.fulfilled=false;
|
||||
const local=kind === 'richeseBid' ? view.richeseBidPromises.find(row => row.id === action.richeseBidPromiseId) :
|
||||
view.mixedRicheseBidPromises.find(row => row.id === action.richeseBidPromiseId);
|
||||
assert.ok(local); local.released=true; clickPhase(); clickLocal(); assert.equal(sent.length,2); local.released=false;
|
||||
early.released=true; clickPhase(); clickLocal(); assert.equal(sent.length,2,'Closing the waiting cache answer invalidates both callbacks');
|
||||
early.released=false; early.boundEvent='different-cache';
|
||||
clickPhase(); clickLocal(); assert.equal(sent.length,2,'Binding the cache to a different event invalidates both callbacks');
|
||||
delete early.boundEvent;
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const bot=viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot=difficulty;
|
||||
const selected=botActions(bot)[0]; assert.deepEqual(selected,action,difficulty);
|
||||
assert.doesNotThrow(() => act(game,f.emperor,selected),difficulty);
|
||||
}
|
||||
const applied=act(game,f.emperor,action);
|
||||
assert.ok(applied.phaseAnyBidPromises?.some(row => row.event === phase.event && row.fulfilled));
|
||||
assert.ok(applied.richeseBidPromises?.some(row => row.id === action.richeseBidPromiseId && row.fulfilled));
|
||||
assert.ok(applied.earlyRicheseBidPromises?.some(row => row.id === early.id && !row.boundEvent && !row.released));
|
||||
assert.deepEqual(inventory(applied),f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,242 @@
|
||||
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 = 'silent' | 'onceAround';
|
||||
type EarlyAnswer = 'yes' | 'no';
|
||||
type Kind = 'earlyRicheseBid' | 'phaseAnyBid';
|
||||
|
||||
/** Original public Advanced R/A/E setup. The original second Truthtrance moves
|
||||
* from the unopened deck to Atreides and the original Semuta from Richese's
|
||||
* cache to its hand. The actual first Truthtrance is reclaimed by Richese via
|
||||
* Semuta, then played as the third question; no receipt, wallet, bid, auction,
|
||||
* phase or card is invented. */
|
||||
function source() {
|
||||
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);
|
||||
const semutaAt = game.richeseCache!.findIndex(card => card.effect === 'semutaDrug');
|
||||
assert.ok(semutaAt >= 0); const [semuta] = game.richeseCache!.splice(semutaAt,1);
|
||||
player(game,f.richese).hand.push(semuta);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game,second:second.id,semuta:semuta.id};
|
||||
}
|
||||
|
||||
function openQuestion(game:Game, asker:string, card:string) {
|
||||
game = act(game,asker,{type:'card',card});
|
||||
return advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
}
|
||||
|
||||
function answerEarly(game:Game, f:TruthtranceRichesePromisesFixture, card:string,
|
||||
kind:Kind, minimum:number, answer:EarlyAnswer, claim:boolean) {
|
||||
game = openQuestion(game,f.asker,card);
|
||||
game = act(game,f.asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum}});
|
||||
const view = viewGame(game,f.emperor);
|
||||
const options = kind === 'earlyRicheseBid' ? view.truthEarlyRicheseBidAnswers : view.truthPhaseAnyBidAnswers;
|
||||
assert.ok(options?.includes(answer),`${kind} ${answer} must have a funded native witness`);
|
||||
game = act(game,f.emperor,{type:'truthAnswer',answer});
|
||||
if (!claim) return passTruthRicheseFreshDiscard(game);
|
||||
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
||||
assert.ok(viewGame(game,f.richese).semutaReaction?.canCommit);
|
||||
game = act(game,f.richese,{type:'semutaCommit',event:pending.batch.event});
|
||||
assert.ok(player(game,f.richese).hand.some(item => item.id === card));
|
||||
return game;
|
||||
}
|
||||
|
||||
function openMarket(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 prebound(method:Method, first:Kind, early:EarlyAnswer, earlyMinimum:number, phaseMinimum:number) {
|
||||
const s = source(), secondKind:Kind = first === 'earlyRicheseBid' ? 'phaseAnyBid' : 'earlyRicheseBid';
|
||||
const value = (kind:Kind) => kind === 'earlyRicheseBid' ? early : 'yes';
|
||||
const minimum = (kind:Kind) => kind === 'earlyRicheseBid' ? earlyMinimum : phaseMinimum;
|
||||
let game = answerEarly(s.game,s.f,s.f.truth,first,minimum(first),value(first),true);
|
||||
assert.ok(game.discard.some(card => card.id === s.semuta));
|
||||
game = answerEarly(game,s.f,s.second,secondKind,minimum(secondKind),value(secondKind),false);
|
||||
const earlyRow = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(earlyRow);
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === s.f.emperor); assert.ok(phase);
|
||||
game = openMarket(game,s.f,method);
|
||||
assert.equal(player(game,s.f.emperor).spice,10);
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
return {...s,game,earlyRow,phase};
|
||||
}
|
||||
|
||||
function askCurrent(game:Game,f:TruthtranceRichesePromisesFixture,minimum:number) {
|
||||
const lot = game.richeseAuction; assert.ok(lot);
|
||||
assert.ok(!lot.acted.includes(f.emperor),'Respondent must retain its original market opportunity');
|
||||
game = openQuestion(game,f.richese,f.truth);
|
||||
game = act(game,f.richese,{type:'truthAsk',question:{kind:'richeseBid',target:f.emperor,
|
||||
turn:game.turn,event:lot.event,minimum}});
|
||||
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 action must retain both physical and promise state');
|
||||
}
|
||||
|
||||
function bindCurrent(game:Game,f:TruthtranceRichesePromisesFixture,answer:EarlyAnswer) {
|
||||
assert.ok(viewGame(game,f.emperor).truthRicheseBidAnswers?.includes(answer),
|
||||
`A funded current market ${answer} must be available`);
|
||||
game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer}));
|
||||
const native = game.richeseBidPromises?.find(row => row.player === f.emperor && row.event === game.richeseAuction?.event);
|
||||
assert.ok(native); assert.equal(native.answer,answer === 'yes');
|
||||
return {game,native};
|
||||
}
|
||||
|
||||
function reachMarketBid(game:Game,f:TruthtranceRichesePromisesFixture,method:Method) {
|
||||
return method === 'silent' ? game : advance(game,state => clean(state) && state.richeseAuction?.active === f.emperor);
|
||||
}
|
||||
|
||||
function finishMarket(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 ['silent','onceAround'] as const)
|
||||
for (const first of ['earlyRicheseBid','phaseAnyBid'] as const) void test(
|
||||
`Advanced ${method} ${first} first: real market Yes and phase Yes reserve the early cache Yes`, () => {
|
||||
const s = prebound(method,first,'yes',6,4);
|
||||
let game = askCurrent(s.game,s.f,4);
|
||||
const current = bindCurrent(game,s.f,'yes'); game = reachMarketBid(current.game,s.f,method);
|
||||
const lot = game.richeseAuction!, view = viewGame(game,s.f.emperor);
|
||||
const nativeGuide = view.richeseBidPromiseGuide?.action, phaseGuide = view.phaseAnyBidGuide?.action;
|
||||
assert.ok(nativeGuide && phaseGuide); assert.deepEqual(nativeGuide,phaseGuide);
|
||||
assert.equal(nativeGuide.type,'richeseBid'); assert.equal(nativeGuide.event,lot.event);
|
||||
assert.equal(nativeGuide.amount,4); assert.equal(nativeGuide.richeseBidPromiseId,current.native.id);
|
||||
assert.equal(nativeGuide.earlyRicheseBidPromiseId,s.earlyRow.id);
|
||||
assert.equal(nativeGuide.phaseAnyBidPromiseEvent,s.phase.event);
|
||||
assert.equal(nativeGuide.phaseAnyBidLotEvent,lot.event);
|
||||
for (const bad of [
|
||||
{...nativeGuide,richeseBidPromiseId:'stale-native'},
|
||||
{...nativeGuide,earlyRicheseBidPromiseId:'stale-early'},
|
||||
{...nativeGuide,phaseAnyBidPromiseEvent:'stale-phase'},
|
||||
{...nativeGuide,event:'stale-lot'},
|
||||
]) reject(game,s.f.emperor,bad);
|
||||
reject(game,s.f.emperor,{type:'richeseBid',event:lot.event,amount:5,allyPayment:0});
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const bot = viewGame(game,s.f.emperor); bot.players.find(row => row.id === s.f.emperor)!.bot = difficulty;
|
||||
const action = botActions(bot)[0]; assert.ok(action,difficulty);
|
||||
assert.doesNotThrow(() => act(game,s.f.emperor,action),difficulty);
|
||||
}
|
||||
game = act(game,s.f.emperor,nativeGuide);
|
||||
assert.equal(player(game,s.f.emperor).spice,10,'The bid is reserved, not prepaid');
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === current.native.id && row.fulfilled));
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled));
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.earlyRow.id && !row.boundEvent && !row.released));
|
||||
if (method === 'silent') assert.equal(viewGame(game,s.f.asker).richeseAuction?.revealedBids,null);
|
||||
game = finishMarket(game,method,lot.event);
|
||||
game = advance(game,state => player(state,s.f.emperor).hand.some(card => card.id === s.f.targetCard));
|
||||
assert.equal(player(game,s.f.emperor).spice,6);
|
||||
game = advance(game,state => clean(state) && state.richeseAuction?.source === 'cache' &&
|
||||
state.richeseAuction.method === 'silent' && !state.richeseAuction.outcome,[],{position:'first',method:'silent'});
|
||||
assert.equal(game.earlyRicheseBidPromises?.find(row => row.id === s.earlyRow.id)?.boundEvent,game.richeseAuction!.event);
|
||||
const cache = viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(cache);
|
||||
assert.equal(cache.amount,6);
|
||||
game = act(game,s.f.emperor,cache);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.earlyRow.id && row.fulfilled));
|
||||
const cacheCard = game.richeseAuction!.cardId;
|
||||
game = advance(game,state => player(state,s.f.emperor).hand.some(card => card.id === cacheCard),
|
||||
[],{position:'first',method:'silent'});
|
||||
assert.equal(player(game,s.f.emperor).spice,0);
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
|
||||
for (const method of ['silent','onceAround'] as const) void test(
|
||||
`Advanced ${method}: unfunded market Yes is unavailable, while No preserves a real phase bid`, () => {
|
||||
const s = prebound(method,'earlyRicheseBid','yes',6,4);
|
||||
let game = askCurrent(s.game,s.f,6);
|
||||
const answers = viewGame(game,s.f.emperor).truthRicheseBidAnswers;
|
||||
assert.ok(!answers?.includes('yes'),'Market 6 and cache 6 cannot both be funded from 10');
|
||||
assert.ok(answers?.includes('no'));
|
||||
reject(game,s.f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
const current = bindCurrent(game,s.f,'no'); game = reachMarketBid(current.game,s.f,method);
|
||||
const lot = game.richeseAuction!, guide = viewGame(game,s.f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.amount,4);
|
||||
assert.equal(guide.richeseBidPromiseId,current.native.id);
|
||||
assert.equal(guide.earlyRicheseBidPromiseId,s.earlyRow.id);
|
||||
game = act(game,s.f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled));
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === current.native.id && row.fulfilled));
|
||||
game = finishMarket(game,method,lot.event);
|
||||
game = advance(game,state => player(state,s.f.emperor).hand.some(card => card.id === s.f.targetCard));
|
||||
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,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(cache);
|
||||
assert.equal(cache.amount,6);
|
||||
game = act(game,s.f.emperor,cache);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.earlyRow.id && row.fulfilled));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
|
||||
for (const method of ['silent','onceAround'] as const) void test(
|
||||
`Advanced ${method}: current and early No retain a separately funded later phase Yes`, () => {
|
||||
const s = prebound(method,'phaseAnyBid','no',4,6);
|
||||
let game = askCurrent(s.game,s.f,6);
|
||||
const current = bindCurrent(game,s.f,'no'); game = reachMarketBid(current.game,s.f,method);
|
||||
const lot = game.richeseAuction!, guide = viewGame(game,s.f.emperor).phaseAnyBidGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.type,'richeseBid');
|
||||
assert.ok(guide.amount === null || typeof guide.amount === 'number' && guide.amount < 6);
|
||||
assert.equal(guide.richeseBidPromiseId,current.native.id);
|
||||
assert.equal(guide.earlyRicheseBidPromiseId,s.earlyRow.id);
|
||||
game = act(game,s.f.emperor,guide);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === current.native.id && row.fulfilled));
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && !row.fulfilled && !row.released));
|
||||
game = finishMarket(game,method,lot.event);
|
||||
game = advance(game,state => clean(state) && !!state.auction && state.auction.active === s.f.emperor,
|
||||
[],{position:'first',method:'silent'});
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.earlyRow.id && row.fulfilled));
|
||||
const ordinary = viewGame(game,s.f.emperor).phaseAnyBidGuide?.action; assert.ok(ordinary);
|
||||
assert.equal(ordinary.type,'bid'); assert.equal(ordinary.amount,6);
|
||||
game = act(game,s.f.emperor,ordinary);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
|
||||
void test('Advanced current Yes with an early Yes needs both market and cache funding even without a phase promise', () => {
|
||||
const s = source();
|
||||
let game = answerEarly(s.game,s.f,s.f.truth,'earlyRicheseBid',6,'yes',true);
|
||||
game = openMarket(game,s.f,'silent');
|
||||
game = askCurrent(game,s.f,4);
|
||||
const current = bindCurrent(game,s.f,'yes'); game = current.game;
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(early);
|
||||
const lot = game.richeseAuction!, guide = viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action;
|
||||
assert.ok(guide); assert.equal(guide.amount,4); assert.equal(guide.richeseBidPromiseId,current.native.id);
|
||||
assert.equal(guide.earlyRicheseBidPromiseId,early.id);
|
||||
reject(game,s.f.emperor,{...guide,earlyRicheseBidPromiseId:'stale-early'});
|
||||
reject(game,s.f.emperor,{type:'richeseBid',event:lot.event,amount:5,allyPayment:0});
|
||||
game = act(game,s.f.emperor,guide);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === current.native.id && row.fulfilled));
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === early.id && !row.released));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,165 @@
|
||||
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,
|
||||
passTruthRicheseFreshDiscard,
|
||||
truthtranceRichesePromisesClean as clean,
|
||||
truthtranceRichesePromisesInventory as inventory,
|
||||
truthtranceRichesePromisesPlayer as player,
|
||||
type TruthtranceRichesePromisesFixture,
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
type Method = 'silent' | 'onceAround';
|
||||
type Kind = 'richeseBid' | 'mixedRicheseBid' | 'constantMixed';
|
||||
|
||||
/** Public Advanced R/A/E start with original unopened setup/Spice order. Move
|
||||
* the second original Truth to Atreides, the original Semuta from the cache
|
||||
* to Richese, and the original Nullentropy Box from the
|
||||
* cache to Atreides. The actual Semuta reclaims the first used Truth; the
|
||||
* actual two-spice Box search recovers Semuta for Atreides, who can claim
|
||||
* Richese's later discard. No promise,
|
||||
* bid, purse, reaction or physical card is fabricated. */
|
||||
function source() {
|
||||
const f = fixture({advanced:true}), game = structuredClone(f.earlySource);
|
||||
const secondAt = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(secondAt >= 0); const [second] = game.deck.splice(secondAt,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
const take = (effect:string, owner:string) => {
|
||||
const at = game.richeseCache!.findIndex(card => card.effect === effect); assert.ok(at >= 0);
|
||||
const [card] = game.richeseCache!.splice(at,1); player(game,owner).hand.push(card); return card.id;
|
||||
};
|
||||
const semuta = take('semutaDrug',f.richese), box = take('nullentropyBox',f.asker);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {f,game,second:second.id,semuta,box};
|
||||
}
|
||||
|
||||
function askPre(game:Game,f:TruthtranceRichesePromisesFixture,card:string,
|
||||
kind:'phaseAnyBid'|'earlyRicheseBid',minimum:number) {
|
||||
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:f.emperor,turn:game.turn,minimum}});
|
||||
const view = viewGame(game,f.emperor);
|
||||
const options = kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthEarlyRicheseBidAnswers;
|
||||
assert.ok(options?.includes('yes'));
|
||||
return act(game,f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
}
|
||||
|
||||
function parkedMarket(method:Method, kind:Kind) {
|
||||
const s = source();
|
||||
let game = askPre(s.game,s.f,s.f.truth,'phaseAnyBid',4);
|
||||
const first = game.pendingTreacheryDiscard; assert.ok(first?.reaction);
|
||||
assert.ok(viewGame(game,s.f.richese).semutaReaction?.canCommit,
|
||||
JSON.stringify(viewGame(game,s.f.richese).semutaReaction));
|
||||
game = act(game,s.f.richese,{type:'semutaCommit',event:first.batch.event});
|
||||
assert.ok(player(game,s.f.richese).hand.some(card => card.id === s.f.truth));
|
||||
assert.ok(game.discard.some(card => card.id === s.semuta));
|
||||
|
||||
// Recover the actual used Semuta with the actual Box and exact native cost.
|
||||
const purse = player(game,s.f.asker).spice;
|
||||
game = act(game,s.f.asker,{type:'card',card:s.box});
|
||||
if (game.decision?.kind === 'nullentropy') {
|
||||
assert.ok(game.pendingNullentropy);
|
||||
game = act(game,s.f.asker,{type:'decision',event:game.pendingNullentropy.event,card:s.semuta});
|
||||
}
|
||||
game = passTruthRicheseFreshDiscard(game);
|
||||
assert.equal(player(game,s.f.asker).spice,purse-2);
|
||||
assert.ok(player(game,s.f.asker).hand.some(card => card.id === s.semuta));
|
||||
assert.ok(game.discard.some(card => card.id === s.box));
|
||||
|
||||
game = passTruthRicheseFreshDiscard(askPre(game,s.f,s.second,'earlyRicheseBid',6));
|
||||
const early = game.earlyRicheseBidPromises?.find(row => row.player === s.f.emperor); assert.ok(early);
|
||||
const phase = game.phaseAnyBidPromises?.find(row => row.player === s.f.emperor); assert.ok(phase);
|
||||
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
|
||||
assert.ok(player(game,s.f.richese).hand.some(card => card.id === s.f.targetCard));
|
||||
game = act(game,s.f.richese,{type:'decision',event:game.richeseBidding!.event,
|
||||
card:s.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'});
|
||||
}
|
||||
const lot = game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket');
|
||||
game = act(game,s.f.richese,{type:'card',card:s.f.truth});
|
||||
game = advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
const base = {target:s.f.emperor,turn:game.turn,event:lot.event};
|
||||
const question = kind === 'richeseBid' ? {kind:'richeseBid',...base,minimum:4} :
|
||||
{kind:'mixedRicheseBid',...base,mixed:{kind:kind === 'constantMixed' ? 'or' : 'and',terms:[
|
||||
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
|
||||
{kind:'action',action:{minimum:4}},
|
||||
]}};
|
||||
game = act(game,s.f.richese,{type:'truthAsk',question});
|
||||
const view = viewGame(game,s.f.emperor);
|
||||
const answers = kind === 'richeseBid' ? view.truthRicheseBidAnswers : view.truthMixedRicheseBidAnswers;
|
||||
assert.ok(answers?.includes('yes'));
|
||||
const parent = structuredClone({lot:game.richeseAuction,round:game.richeseBidding,
|
||||
funding:game.richeseFunding,aid:game.aid,turn:game.turn,phase:game.phase,active:game.active,order:game.order});
|
||||
game = act(game,s.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,s.f.truth);
|
||||
assert.ok(viewGame(game,s.f.asker).semutaReaction?.canCommit,
|
||||
JSON.stringify(viewGame(game,s.f.asker).semutaReaction));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
return {...s,game,early,phase,lot:lot.event,pending:pending.batch.event,parent};
|
||||
}
|
||||
|
||||
function reject(game:Game,actor:string,action:Action) {
|
||||
const before = structuredClone(game);
|
||||
assert.throws(() => act(game,actor,action));
|
||||
assert.deepEqual(game,before);
|
||||
}
|
||||
|
||||
for (const method of ['silent','onceAround'] as const)
|
||||
for (const kind of ['richeseBid','mixedRicheseBid','constantMixed'] as const)
|
||||
for (const claim of [false,true]) void test(
|
||||
`Advanced ${method} ${kind} third answer: Semuta ${claim ? 'claim' : 'pass'} binds and resumes original ledgers`, () => {
|
||||
const s = parkedMarket(method,kind);
|
||||
const local = s.game.richeseBidPromises?.find(row => row.player === s.f.emperor && row.event === s.lot);
|
||||
const mixed = s.game.mixedRicheseBidQuestions?.find(row => row.player === s.f.emperor && row.event === s.lot);
|
||||
if (kind === 'constantMixed') {
|
||||
assert.ok(mixed && !mixed.binding,'A true fact settles the expression without inventing a bid');
|
||||
assert.equal(local,undefined);
|
||||
} else {
|
||||
assert.ok(local && local.answer);
|
||||
if (kind === 'mixedRicheseBid') assert.ok(mixed?.binding);
|
||||
}
|
||||
const families: Array<'earlyRicheseBidPromises'|'phaseAnyBidPromises'|'richeseBidPromises'|'mixedRicheseBidQuestions'> =
|
||||
['earlyRicheseBidPromises','phaseAnyBidPromises'];
|
||||
if (local) families.push('richeseBidPromises');
|
||||
if (mixed) families.push('mixedRicheseBidQuestions');
|
||||
for (const family of families) {
|
||||
const tampered = structuredClone(s.game);
|
||||
if (family === 'mixedRicheseBidQuestions') tampered.mixedRicheseBidQuestions![0].answer = false;
|
||||
else tampered[family]![0].minimum++;
|
||||
assert.throws(() => act(tampered,s.f.asker,{type:'semutaCommit',event:s.pending}),
|
||||
`The third answer binds its original ${family}`);
|
||||
}
|
||||
reject(s.game,s.f.asker,{type:'semutaCommit',event:'stale-discard'});
|
||||
let game = claim ? act(s.game,s.f.asker,{type:'semutaCommit',event:s.pending}) :
|
||||
passTruthRicheseFreshDiscard(s.game);
|
||||
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
|
||||
assert.equal(player(game,s.f.asker).hand.some(card => card.id === s.f.truth),claim);
|
||||
assert.equal(game.discard.some(card => card.id === s.semuta),claim);
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && !row.fulfilled && !row.released));
|
||||
assert.deepEqual({lot:game.richeseAuction,round:game.richeseBidding,funding:game.richeseFunding,aid:game.aid,
|
||||
turn:game.turn,phase:game.phase,active:game.active,order:game.order},s.parent);
|
||||
if (method === 'onceAround')
|
||||
game = advance(game,state => clean(state) && state.richeseAuction?.active === s.f.emperor);
|
||||
const view = viewGame(game,s.f.emperor), guide = view.phaseAnyBidGuide?.action; assert.ok(guide);
|
||||
if (local) {
|
||||
assert.deepEqual(guide,view.richeseBidPromiseGuide?.action);
|
||||
assert.equal(guide.richeseBidPromiseId,local.id);
|
||||
assert.equal(guide.earlyRicheseBidPromiseId,s.early.id);
|
||||
reject(game,s.f.emperor,{...guide,richeseBidPromiseId:'stale-native'});
|
||||
reject(game,s.f.emperor,{...guide,earlyRicheseBidPromiseId:'stale-early'});
|
||||
}
|
||||
reject(game,s.f.emperor,{...guide,phaseAnyBidPromiseEvent:'stale-phase'});
|
||||
reject(game,s.f.emperor,{...guide,event:'stale-market'});
|
||||
game = act(game,s.f.emperor,guide);
|
||||
assert.ok(game.phaseAnyBidPromises?.some(row => row.event === s.phase.event && row.fulfilled));
|
||||
if (local) assert.ok(game.richeseBidPromises?.some(row => row.id === local.id && row.fulfilled));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { viewGame, type Game } from '../game/engine';
|
||||
import {
|
||||
actTruthtranceRichesePromises as act,
|
||||
advanceTruthtranceRichesePromises as advance,
|
||||
createTruthtranceRichesePromisesFixture as fixture,
|
||||
passTruthRicheseFreshDiscard,
|
||||
truthtranceRichesePromisesInventory as inventory,
|
||||
truthtranceRichesePromisesPlayer as player,
|
||||
} from './fixture-truthtrance-richese-promises';
|
||||
|
||||
/** Real Advanced R/A/E opening and actual market actions. Stage only the
|
||||
* original second Truthtrance and Semuta into hands, then use Semuta to
|
||||
* recover the first discarded Truthtrance for the third real question. */
|
||||
function source(method:'silent'|'onceAround') {
|
||||
const f=fixture({advanced:true}); let game:Game=structuredClone(f.earlySource);
|
||||
const truthAt=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth);
|
||||
assert.ok(truthAt >= 0); const [second]=game.deck.splice(truthAt,1);
|
||||
player(game,f.asker).hand.push(second);
|
||||
const semutaAt=game.richeseCache!.findIndex(card => card.effect === 'semutaDrug');
|
||||
assert.ok(semutaAt >= 0); const [semuta]=game.richeseCache!.splice(semutaAt,1);
|
||||
player(game,f.richese).hand.push(semuta);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
|
||||
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:'earlyRicheseBid',target:f.emperor,turn:game.turn,minimum:2}});
|
||||
game=act(game,f.emperor,{type:'truthAnswer',answer:'yes'});
|
||||
const firstDiscard=game.pendingTreacheryDiscard; assert.ok(firstDiscard?.reaction);
|
||||
assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true);
|
||||
game=act(game,f.richese,{type:'semutaCommit',event:firstDiscard.batch.event});
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game=act(game,f.richese,{type:'semutaSelect',event:firstDiscard.batch.event,card:f.truth});
|
||||
assert.ok(player(game,f.richese).hand.some(card => card.id === f.truth));
|
||||
const early=game.earlyRicheseBidPromises?.find(row => row.player === f.emperor && row.answer); assert.ok(early);
|
||||
|
||||
game=advance(game,state => state.decision?.kind === 'richeseBlackMarket');
|
||||
const open=(direction:'clockwise'|'counterclockwise') => act(game,f.richese,
|
||||
{type:'decision',event:game.richeseBidding!.event,card:f.targetCard,method,
|
||||
...(method === 'onceAround' ? {direction} : {})});
|
||||
let market=open('clockwise');
|
||||
// Both directions are genuine physical choices; select one whose first
|
||||
// actor is not the respondent so the test can perform an external action.
|
||||
if (method === 'onceAround' && market.richeseAuction?.active === f.emperor)
|
||||
market=open('counterclockwise');
|
||||
game=market;
|
||||
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'});
|
||||
}
|
||||
const lot=game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket');
|
||||
if (method === 'onceAround') assert.notEqual(lot.active,f.emperor);
|
||||
const event=lot.event;
|
||||
function ask(asker:string,card:string,minimum:number) {
|
||||
game=act(game,asker,{type:'card',card});
|
||||
game=advance(game,state => state.truthtrance?.stage === 'ask');
|
||||
game=act(game,asker,{type:'truthAsk',question:{kind:'richeseBid',target:f.emperor,turn:game.turn,event,minimum}});
|
||||
assert.ok(viewGame(game,f.emperor).truthRicheseBidAnswers?.includes('yes'));
|
||||
game=passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'}));
|
||||
}
|
||||
ask(f.asker,second.id,4);
|
||||
ask(f.richese,f.truth,8);
|
||||
const low=game.richeseBidPromises?.find(row => row.event === event && row.player === f.emperor && row.minimum === 4);
|
||||
const high=game.richeseBidPromises?.find(row => row.event === event && row.player === f.emperor && row.minimum === 8);
|
||||
assert.ok(low && high);
|
||||
assert.equal(player(game,f.emperor).spice,10);
|
||||
assert.deepEqual(inventory(game),f.originalCards);
|
||||
return {game,f,event,early,low,high};
|
||||
}
|
||||
|
||||
for (const method of ['silent','onceAround'] as const) void test(
|
||||
`Advanced ${method} market releases only the native Yes made impossible by an external loss`,() => {
|
||||
const s=source(method); let game=structuredClone(s.game);
|
||||
// Explicit external-loss supplement: cash falls from 10 to 7 while the
|
||||
// original market remains open. Two must stay reserved for the cache,
|
||||
// leaving a market ceiling of five. No cards or receipts are staged here.
|
||||
player(game,s.f.emperor).spice=7;
|
||||
const lot=game.richeseAuction!;
|
||||
const actor=method === 'silent' ? s.f.asker : lot.active;
|
||||
assert.ok(actor && actor !== s.f.emperor);
|
||||
game=act(game,actor,{type:'richeseBid',event:s.event,amount:method === 'silent' ? 0 : null,allyPayment:0});
|
||||
const low=game.richeseBidPromises?.find(row => row.id === s.low.id);
|
||||
const high=game.richeseBidPromises?.find(row => row.id === s.high.id);
|
||||
assert.ok(low && high);
|
||||
assert.equal(!!low.fulfilled,false); assert.equal(!!low.released,false,'The affordable native Yes remains binding');
|
||||
assert.equal(!!high.fulfilled,false); assert.equal(!!high.released,true,'Only the unaffordable native Yes releases');
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
|
||||
if (method === 'silent') {
|
||||
assert.equal(viewGame(game,s.f.richese).richeseAuction?.revealedBids,null);
|
||||
} else assert.equal(game.richeseAuction?.active,s.f.emperor);
|
||||
const guide=viewGame(game,s.f.emperor).richeseBidPromiseGuide?.action; assert.ok(guide);
|
||||
assert.equal(guide.type,'richeseBid'); assert.equal(guide.event,s.event); assert.equal(guide.amount,4);
|
||||
assert.equal(guide.richeseBidPromiseId,s.low.id); assert.equal(guide.earlyRicheseBidPromiseId,s.early.id);
|
||||
game=act(game,s.f.emperor,guide);
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.low.id && row.fulfilled));
|
||||
assert.ok(game.richeseBidPromises?.some(row => row.id === s.high.id && row.released));
|
||||
assert.ok(game.earlyRicheseBidPromises?.some(row => row.id === s.early.id && !row.boundEvent && !row.released));
|
||||
assert.deepEqual(inventory(game),s.f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user