Support Truthtrance ordering in Black Market auctions
Verify and publish checkpoint container / container (push) Successful in 11m19s

This commit is contained in:
Quintine committed 2026-11-16 18:49:05 +11:00
1 parent 6ce9a4b4a7
commit 868713eeb9
15 files changed
+359 -28

No files matched your search

@@ -0,0 +1,132 @@
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 { createTruthtranceRichesePromisesFixture, advanceTruthtranceRichesePromises as advance,
actTruthtranceRichesePromises as act, truthtranceRichesePromisesInventory as inventory } from './fixture-truthtrance-richese-promises';
import { truthOrderFrame as frame, playSaphoTruthOrder as play,
finishTruthOrder as finish, finishOriginalTruthQuestions as answer, rejectSaphoTruthOrder as reject } from './fixture-sapho-truth-order';
const player = (game: Game, id: string) => { const p = game.players.find(row => row.id === id); assert.ok(p); return p; };
type Method = 'normal' | 'onceAround' | 'silent';
/** Genuine Advanced R/A/E setup and live Black Market. Controlled conserved
* supplements swap original cached Sapho for Emperor's held card and move an
* undealt physical Truth to Emperor; the actual starting Truth stays Atreides'. */
function fixture(method: Method) {
const source = createTruthtranceRichesePromisesFixture({advanced:true});
let game = structuredClone(source.game);
const emperor = player(game,'emperor'), atreides = player(game,'atreides');
const cache = game.richeseCache!;
const at = cache.findIndex(card => card.effect === 'juiceOfSapho'); assert.ok(at >= 0);
const [sapho] = cache.splice(at,1), [swap] = emperor.hand.splice(0,1);
emperor.hand.push(sapho); cache.push(swap);
const truthAt = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(truthAt >= 0);
const [truth] = game.deck.splice(truthAt,1); emperor.hand.push(truth);
const otherTruth = atreides.hand.find(card => card.effect === 'truthtrance'); assert.ok(otherTruth);
assert.deepEqual(inventory(game),source.originalCards);
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
const offered = player(game,'richese').hand.find(card => card.name === 'Shield'); assert.ok(offered);
game = act(game,'richese',{type:'decision',event:game.richeseBidding!.event,card:offered.id,method,
...(method === 'onceAround' ? {direction:'clockwise'} : {})});
for (let n=0; game.response && n<20; n++) {
const actor = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'passResponse'});
}
const lot = game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket' && lot.method === method);
const bidder = method === 'silent' ? 'richese' : lot.active; assert.ok(bidder);
game = act(game,bidder,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
assert.ok(game.richeseAuction && !game.richeseAuction.outcome);
const parent = structuredClone({turn:game.turn,phase:game.phase,active:game.active,order:game.order,
lot:game.richeseAuction,round:game.richeseBidding,funding:game.richeseFunding,aid:game.aid,
offered:game.richeseOfferedCard,sellerHand:player(game,'richese').hand});
for (const [actor,card] of [['emperor',truth.id],['atreides',otherTruth.id]] as const)
game = act(game,actor,{type:'card',card});
while (game.truthtrance?.stage === 'priority') {
const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'truthPass'});
}
const current = frame(game);
const mode: 'first' | 'last' = game.truthtrance!.queue[0].player === 'emperor' ? 'last' : 'first';
return {game,lot:lot.event,offered:offered.id,card:sapho.id,bidder,mode,parent,original:source.originalCards,current};
}
function assertParent(game: Game, f: ReturnType<typeof fixture>) {
assert.deepEqual({turn:game.turn,phase:game.phase,active:game.active,order:game.order,
lot:game.richeseAuction,round:game.richeseBidding,funding:game.richeseFunding,aid:game.aid,
offered:game.richeseOfferedCard,sellerHand:player(game,'richese').hand},f.parent);
assert.ok(player(game,'richese').hand.some(card => card.id === f.offered));
}
function assertSilent(game: Game, bidder: string) {
const ownerView = viewGame(game,bidder).richeseAuction!, otherView = viewGame(game,'emperor').richeseAuction!;
assert.equal(ownerView.ownBid,1); assert.equal(otherView.ownBid,null);
assert.equal(otherView.revealedBids,null); assert.equal('sealed' in otherView,false);
}
for (const method of ['normal','onceAround','silent'] as const) void test(
`Advanced ${method} Black Market retains its original lot when Sapho orders real Truth questions`, () => {
const f = fixture(method), before = structuredClone(f.game);
assertParent(f.game,f);
if (method === 'silent') assertSilent(f.game,f.bidder);
const offered = viewGame(f.game,'emperor').saphoTruthOrderChoices;
assert.ok(offered.some(row => row.card === f.card && row.mode === f.mode));
reject(f.game,'emperor',{type:'saphoTruthOrder',card:f.card,event:'stale',revision:f.current.revision,mode:f.mode});
reject(f.game,'emperor',{type:'saphoTruthOrder',card:f.card,event:f.current.event,revision:f.current.revision+1,mode:f.mode});
for (const difficulty of DIFFICULTIES) {
const view = viewGame(before,'emperor'); view.players.find(row => row.id === 'emperor')!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action,difficulty);
assert.ok(action.type === 'truthOrderPass' || action.type === 'saphoTruthOrder');
assert.doesNotThrow(() => act(before,'emperor',action));
}
let game = play(f.game,'emperor',f.card,f.mode);
assertParent(game,f);
if (method === 'silent') assertSilent(game,f.bidder);
game = finish(game);
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,'emperor');
game = answer(game); assert.equal(game.truthtrance,null); assertParent(game,f);
assert.deepEqual(inventory(game),f.original);
if (method === 'silent') assertSilent(game,f.bidder);
const lot = game.richeseAuction!;
const next = method === 'silent' ? lot.eligible.find(id => !Object.hasOwn(lot.sealed,id)) : lot.active;
assert.ok(next);
const action: Action = {type:'richeseBid',event:f.lot,amount:method === 'silent' ? 0 : null,allyPayment:0};
game = act(game,next,action);
assert.deepEqual(inventory(game),f.original);
});
void test('a Black Market seller cannot spend their offered Sapho to reorder their own queued Truth', () => {
const source = createTruthtranceRichesePromisesFixture({advanced:true});
let game = structuredClone(source.game);
const seller = player(game,'richese'), cache = game.richeseCache!;
const at = cache.findIndex(card => card.effect === 'juiceOfSapho'); assert.ok(at >= 0);
const [sapho] = cache.splice(at,1), [swap] = seller.hand.splice(0,1);
seller.hand.push(sapho); cache.push(swap);
const truthAt = game.deck.findIndex(card => card.effect === 'truthtrance'); assert.ok(truthAt >= 0);
const [sellerTruth] = game.deck.splice(truthAt,1); seller.hand.push(sellerTruth);
const otherTruth = player(game,'atreides').hand.find(card => card.effect === 'truthtrance'); assert.ok(otherTruth);
assert.deepEqual(inventory(game),source.originalCards);
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
game = act(game,'richese',{type:'decision',event:game.richeseBidding!.event,card:sapho.id,method:'silent'});
for (let n=0; game.response && n<20; n++) {
const actor = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'passResponse'});
}
const lot = game.richeseAuction; assert.ok(lot && lot.cardId === sapho.id);
game = act(game,'emperor',{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
for (const [actor,card] of [['richese',sellerTruth.id],['atreides',otherTruth.id]] as const)
game = act(game,actor,{type:'card',card});
while (game.truthtrance?.stage === 'priority') {
const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'truthPass'});
}
const order = frame(game);
assert.ok(order.holders.includes('richese'));
assert.deepEqual(viewGame(game,'richese').saphoTruthOrderChoices,[]);
for (const mode of ['first','last'] as const)
reject(game,'richese',{type:'saphoTruthOrder',card:sapho.id,event:order.event,revision:order.revision,mode});
assert.ok(player(game,'richese').hand.some(card => card.id === sapho.id));
assert.equal(game.richeseAuction?.cardId,sapho.id);
game = finish(game); game = answer(game);
assert.ok(player(game,'richese').hand.some(card => card.id === sapho.id));
assert.equal(game.richeseAuction?.cardId,sapho.id);
assert.deepEqual(inventory(game),source.originalCards);
});
@@ -0,0 +1,151 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { viewGame, type Action, type Game } from '../game/engine';
import {
actTruthtranceRichesePromises as act,
advanceTruthtranceRichesePromises as advance,
createTruthtranceRichesePromisesFixture,
passTruthRicheseFreshDiscard,
truthtranceRichesePromisesInventory as inventory,
truthtranceRichesePromisesPlayer as player,
} from './fixture-truthtrance-richese-promises';
type Method = 'onceAround' | 'silent';
type QuestionKind = 'richeseBid' | 'mixedRicheseBid';
/** Original Advanced R/A/E setup, starting deal and Charity. Only the
* fixture's disclosed unopened deal/Spice order and scalar rolls are staged;
* Richese offers the physical Shield actually dealt into its own hand. */
function fixture(method: Method) {
const source = createTruthtranceRichesePromisesFixture({advanced:true});
let game = advance(structuredClone(source.earlySource), state => state.decision?.kind === 'richeseBlackMarket');
const card = source.targetCard, event = game.richeseBidding!.event;
assert.ok(player(game,source.richese).hand.some(held => held.id === card));
game = act(game,source.richese,{type:'decision',event,card,method,
...(method === 'onceAround' ? {direction:'clockwise'} : {})});
while (game.response) {
const seat = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(seat);
game = act(game,seat.id,{type:'passResponse'});
}
assert.equal(game.richeseAuction?.source,'blackMarket');
assert.equal(game.richeseAuction?.method,method);
assert.equal(viewGame(game,source.richese).richeseAuction?.card?.id,card);
assert.equal(viewGame(game,source.asker).richeseAuction?.card?.id,game.richesePeekKnown ? card : undefined);
assert.equal(viewGame(game,source.emperor).richeseAuction?.card,null);
assert.ok(player(game,source.asker).hand.some(held => held.id === source.truth));
assert.deepEqual(inventory(game),source.originalCards);
return {game,asker:source.asker,target:source.emperor,owner:source.richese,
truth:source.truth,card,lot:game.richeseAuction!.event,originalCards:source.originalCards};
}
function reject(game:Game,actor:string,action:Action) {
const before=structuredClone(game); assert.throws(() => act(game,actor,action)); assert.deepEqual(game,before);
}
function ask(f:ReturnType<typeof fixture>,kind:QuestionKind) {
let game=act(f.game,f.asker,{type:'card',card:f.truth});
while (game.truthtrance?.stage === 'priority') {
const seat=game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
game=act(game,seat.id,{type:'truthPass'});
}
assert.equal(game.truthtrance?.stage,'ask');
const question = kind === 'richeseBid'
? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:4}
: {kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
{kind:'action',action:{minimum:4}},
]}};
return act(game,f.asker,{type:'truthAsk',question});
}
for (const method of ['onceAround','silent'] as const)
for (const kind of ['richeseBid','mixedRicheseBid'] as const)
for (const answer of ['yes','no'] as const) void test(
`Advanced ${method} Black Market ${kind} ${answer} retains the original sale`,() => {
const f=fixture(method), asked=ask(f,kind);
assert.equal(viewGame(asked,f.asker).richeseAuction?.card?.id,asked.richesePeekKnown ? f.card : undefined);
assert.equal(viewGame(asked,f.target).richeseAuction?.card,null);
assert.equal(viewGame(asked,f.owner).richeseAuction?.card?.id,f.card);
const answerView=viewGame(asked,f.target);
const answers=kind === 'richeseBid' ? answerView.truthRicheseBidAnswers : answerView.truthMixedRicheseBidAnswers;
assert.ok(answers?.includes(answer));
assert.equal(player(asked,f.target).spice,10);
for (const difficulty of DIFFICULTIES) {
const botView=viewGame(asked,f.target); botView.players.find(row => row.id === f.target)!.bot=difficulty;
const choice=botActions(botView)[0]; assert.equal(choice?.type,'truthAnswer',difficulty);
assert.ok(answers?.includes(choice.answer as 'yes'|'no'|'unknown'));
}
let game=passTruthRicheseFreshDiscard(act(asked,f.target,{type:'truthAnswer',answer}));
assert.equal(game.richeseAuction?.event,f.lot);
assert.ok(player(game,f.owner).hand.some(held => held.id === f.card));
if (method === 'onceAround') {
while (game.richeseAuction?.event === f.lot && game.richeseAuction.active !== f.target) {
const actor=game.richeseAuction.active; assert.ok(actor); assert.notEqual(actor,f.owner);
game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null});
}
}
const guide=viewGame(game,f.target).richeseBidPromiseGuide; assert.ok(guide);
reject(game,f.target,{...guide.action,richeseBidPromiseId:'stale-promise'});
reject(game,f.target,{type:'richeseBid',event:f.lot,amount:answer === 'yes' ? 3 : 4,allyPayment:0});
const amount=answer === 'yes' ? 4 : 2;
const beforeBuyer=player(game,f.target).spice, beforeSeller=player(game,f.owner).spice;
game=act(game,f.target,{type:'richeseBid',event:f.lot,amount,allyPayment:0});
assert.equal(player(game,f.target).spice,beforeBuyer,'Declaring does not pay the winning invoice');
if (method === 'silent') {
assert.equal(viewGame(game,f.target).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.owner).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null);
assert.ok(player(game,f.owner).hand.some(held => held.id === f.card));
for (const id of [f.asker,f.owner])
game=act(game,id,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0});
} else {
while (game.richeseAuction?.event === f.lot && !game.richeseAuction.outcome) {
const actor=game.richeseAuction.active; assert.ok(actor);
game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null});
}
}
assert.ok(player(game,f.target).hand.some(held => held.id === f.card));
assert.ok(!player(game,f.owner).hand.some(held => held.id === f.card));
assert.equal(player(game,f.target).spice,beforeBuyer-amount);
assert.equal(player(game,f.owner).spice,beforeSeller+amount);
assert.equal(game.discard.filter(held => held.id === f.truth).length,1);
assert.deepEqual(inventory(game),f.originalCards);
});
for (const method of ['onceAround','silent'] as const) void test(
`Advanced ${method} seller honors a Truthtrance Yes and retains its physical Black Market card`,() => {
const original=fixture(method);
let game=original.game;
if (method === 'onceAround') {
const first=game.richeseAuction!.active; assert.ok(first); assert.notEqual(first,original.owner);
game=act(game,first,{type:'richeseBid',event:original.lot,amount:1,allyPayment:0});
}
const f={...original,game,target:original.owner};
const asked=ask(f,'richeseBid');
assert.ok(viewGame(asked,f.target).truthRicheseBidAnswers?.includes('yes'));
game=passTruthRicheseFreshDiscard(act(asked,f.target,{type:'truthAnswer',answer:'yes'}));
const beforeHand=player(game,f.owner).hand.map(card => card.id);
const beforeSeller=player(game,f.owner).spice, beforeEmperor=player(game,original.target).spice;
if (method === 'onceAround') {
while (game.richeseAuction?.event === f.lot && game.richeseAuction.active !== f.owner) {
const actor=game.richeseAuction.active; assert.ok(actor);
game=act(game,actor,{type:'richeseBid',event:f.lot,amount:null});
}
}
const guide=viewGame(game,f.owner).richeseBidPromiseGuide; assert.ok(guide);
assert.equal(guide.action.amount,4);
game=act(game,f.owner,guide.action);
if (method === 'silent') {
assert.equal(viewGame(game,f.asker).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.asker).richeseAuction?.revealedBids,null);
assert.deepEqual(player(game,f.owner).hand.map(card => card.id),beforeHand);
for (const actor of [f.asker,original.target])
game=act(game,actor,{type:'richeseBid',event:f.lot,amount:0,allyPayment:0});
}
assert.deepEqual(player(game,f.owner).hand.map(card => card.id),beforeHand);
assert.equal(player(game,f.owner).spice,beforeSeller-4);
assert.equal(player(game,original.target).spice,beforeEmperor+4);
assert.equal(game.richeseBidding?.blackMarketSold,true);
assert.deepEqual(inventory(game),f.originalCards);
});
+4 -1
View File
@@ -39,6 +39,8 @@ void test('phase bid editor preserves the current turn and accepts only whole po
const props = { value, onChange(next: PhaseBidClaim) { changes.push(next); } };
const html = renderToStaticMarkup(createElement(PhaseBidClaimFields, props));
assert.match(html, /Turn 2/);
assert.match(html, /ordinary auction bid/);
assert.match(html, /Richese cache and Black Market bids do not count/);
assert.match(html, /before Bidding ends this turn/);
assert.match(html, /Earlier bids do not count/);
for (const minimum of [1, 7, Number.MAX_SAFE_INTEGER]) edit(props, minimum);
@@ -62,7 +64,8 @@ void test('phase promises remain visible and do not expose another player’s pr
const before = structuredClone(game);
const html = renderToStaticMarkup(createElement(PhaseBidPromises, { game, busy: false, send() {} }));
assert.match(html, /Your Bidding phase promises/);
assert.match(html, /No forbids qualifying bids through Bidding close/);
assert.match(html, /No forbids qualifying ordinary bids through Bidding close/);
assert.match(html, /Richese cache and Black Market bids do not count/);
assert.match(html, /Fulfilled: this commitment is complete/);
assert.match(html, /Released: this commitment is no longer possible/);
assert.match(html, /Your next bid opportunity is still ahead/);
@@ -40,8 +40,8 @@ for (const advanced of [false, true]) void test(
const asker = viewGame(b.declared.game, f.asker);
assert.ok(asker.truthPhaseBidTargets.includes(f.target));
const authored = truth(asker);
assert.match(authored, /<option value="phaseBid">Bind a bid this Bidding phase<\/option>/);
assert.match(table(asker), /Bind a bid this Bidding phase/);
assert.match(authored, /<option value="phaseBid">Bind an ordinary bid this Bidding phase<\/option>/);
assert.match(table(asker), /Bind an ordinary bid this Bidding phase/);
// Server rendering does not operate the stateful question selector; the
// fixture's actual native question is submitted by its engine action.
const respondent = viewGame(b.asked, f.target);
+1
View File
@@ -26,6 +26,7 @@ void test('phase bid claim is one positive safe turn and threshold, with no lot
const claim = parsePhaseBidClaim({ turn: 2, minimum: 6 });
assert.deepEqual(claim, { turn: 2, minimum: 6 });
assert.match(phaseBidClaimText(claim), /bid of at least 6 spice/);
assert.match(phaseBidClaimText(claim), /ordinary auction bid/);
assert.match(phaseBidClaimText(claim), /Bidding phase closes/);
for (const field of ['turn', 'minimum'] as const)
for (const value of [0, -1, 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1, '6', null, undefined])