Support Advanced Semuta at Sapho auction ordering
Verify and publish checkpoint container / container (push) Canceled after 0s

This commit is contained in:
Quintine committed 2026-11-16 18:54:59 +11:00
1 parent 868713eeb9
commit dd4222ee92
9 files changed
+270 -19

No files matched your search

@@ -0,0 +1,88 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame, type Game } from '../game/engine';
import { createSaphoTruthRicheseFixture, assertRicheseParent } from './fixture-sapho-truth-richese';
import { createSaphoTruthAuctionFixture, assertAuctionParent, act, inventory, player } from './fixture-sapho-truth-auction';
import { passTruthOrder, playSaphoTruthOrder, finishOriginalTruthQuestions, passFreshDiscard } from './fixture-sapho-truth-order';
/** All games start through native Advanced setup and bidding. Cache cases use
* the fixture's disclosed physical cache/hand swaps. The ordinary case swaps
* the original cached Semuta with a held card after the actual Sapho purchase. */
for (const method of ['onceAround','silent'] as const) for (const claim of [false,true]) void test(
`Advanced ${method} cache Sapho Semuta ${claim ? 'claim' : 'pass'} restores the original auction and queued questions`, () => {
const f = createSaphoTruthRicheseFixture({advanced:true,method,standingBid:true,semuta:true});
assert.equal(f.game.semutaAdvancedOrdinaryPreview,true); assert.ok(f.semuta);
let game = passTruthOrder(f.game,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,f.mode);
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'saphoTruthOrderDiscard');
assert.equal(pending.batch.entries[0].card.id,f.card);
assert.equal(viewGame(game,f.semutaHolder).semutaReaction?.canCommit,true);
assertRicheseParent(game,f.parent);
if (method === 'silent') {
assert.equal(viewGame(game,f.semutaHolder).richeseAuction?.ownBid,1);
assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null);
}
game = claim ? act(game,f.semutaHolder,{type:'semutaCommit',event:pending.batch.event}) : passFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance?.stage,'ask');
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,f.owner);
assert.equal(player(game,f.semutaHolder).hand.some(card => card.id === f.card),claim);
assert.equal(game.discard.some(card => card.id === f.semuta),claim);
assertRicheseParent(game,f.parent);
game = finishOriginalTruthQuestions(game); assert.equal(game.truthtrance,null);
assertRicheseParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
const lot = game.richeseAuction!;
const actor = method === 'onceAround' ? lot.active : lot.eligible.find(id => !Object.hasOwn(lot.sealed,id));
assert.ok(actor);
game = act(game,actor,{type:'richeseBid',event:f.lot,amount:method === 'silent' ? 0 : null,allyPayment:0});
assert.deepEqual(inventory(game),f.originalCards);
},
);
for (const claim of [false,true]) void test(
`Advanced ordinary standing bid survives Sapho Truth-order Semuta ${claim ? 'claim' : 'pass'}`, () => {
const f = createSaphoTruthAuctionFixture({advanced:true,standingBid:true,mode:'first'});
let game: Game = structuredClone(f.game);
assert.equal(game.semutaAdvancedOrdinaryPreview,true);
const claimant = player(game,'atreides'), cache = game.richeseCache;
assert.ok(cache && claimant.hand.length);
const index = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(index >= 0);
const [semuta] = cache.splice(index,1), [exchange] = claimant.hand.splice(0,1);
claimant.hand.push(semuta); cache.push(exchange);
assertAuctionParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
game = passTruthOrder(game,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,'first');
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'saphoTruthOrderDiscard');
assert.equal(viewGame(game,'atreides').semutaReaction?.canCommit,true);
assertAuctionParent(game,f.parent);
game = claim ? act(game,'atreides',{type:'semutaCommit',event:pending.batch.event}) : passFreshDiscard(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance?.stage,'ask');
assert.equal(game.truthtrance?.queue[0].player,f.owner);
assert.equal(player(game,'atreides').hand.some(card => card.id === f.card),claim);
assert.equal(game.discard.some(card => card.id === semuta.id),claim);
assertAuctionParent(game,f.parent);
game = finishOriginalTruthQuestions(game); assert.equal(game.truthtrance,null);
assertAuctionParent(game,f.parent); assert.deepEqual(inventory(game),f.originalCards);
game = act(game,game.auction!.active,{type:'passBid'});
assert.equal(game.auction?.bid,1); assert.equal(game.auction?.bidder,f.parent.auction!.bidder);
assert.deepEqual(inventory(game),f.originalCards);
},
);
void test('an older Advanced cache game without the Semuta preview marker keeps its original synchronous Sapho continuation', () => {
const f = createSaphoTruthRicheseFixture({advanced:true,method:'silent',standingBid:true,semuta:true});
const older = structuredClone(f.game);
delete older.semutaAdvancedOrdinaryPreview; // Simulate a saved start predating the marker.
assert.ok(f.semuta && player(older,f.semutaHolder).hand.some(card => card.id === f.semuta));
let game = passTruthOrder(older,f.other);
game = playSaphoTruthOrder(game,f.owner,f.card,f.mode);
assert.equal(game.pendingTreacheryDiscard ?? null,null);
assert.equal(game.truthtrance?.stage,'ask');
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,f.owner);
assert.ok(player(game,f.semutaHolder).hand.some(card => card.id === f.semuta));
assertRicheseParent(game,f.parent);
game = finishOriginalTruthQuestions(game);
assert.equal(game.truthtrance,null); assertRicheseParent(game,f.parent);
assert.deepEqual(inventory(game),f.originalCards);
});
+2 -2
View File
@@ -48,7 +48,7 @@ function openTimedTruth(advanced: boolean, semuta: boolean) {
for (const scenario of [
{label:'Basic Semuta pass',advanced:false,semuta:true,claim:false},
{label:'Basic Semuta claim',advanced:false,semuta:true,claim:true},
{label:'Advanced without Semuta preview',advanced:true,semuta:false,claim:false},
{label:'Advanced neutral Semuta offer',advanced:true,semuta:false,claim:false},
]) void test(`${scenario.label}: the native bidder clock pauses through Truth order and Sapho disposal`, () => {
const {f,game:opened,initial} = openTimedTruth(scenario.advanced,scenario.semuta);
let game = opened;
@@ -61,7 +61,7 @@ for (const scenario of [
assert.equal(game.auctionClock?.event,event); assert.equal(game.auctionClock?.player,playerId);
assert.equal(game.auctionClock?.remainingMs,8_000); assert.equal(game.auctionClock?.startedAt,null);
assert.deepEqual(game.auction,beforeLot);
if (scenario.semuta) {
if (scenario.semuta || scenario.advanced) {
assert.ok(game.pendingTreacheryDiscard?.reaction);
const pendingEvent = game.pendingTreacheryDiscard.batch.event;
const held = advanceAuctionClock(game,100_000,epoch);
@@ -0,0 +1,117 @@
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, playSaphoTruthOrder, finishTruthOrder, finishOriginalTruthQuestions } 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 public start and original Black Market actions.
* Conserved staged custody moves original Sapho and Semuta from the cache and
* one unopened Truth to hands. The unopened deal/Spice order is selected by
* the underlying fixture; the sale, bid and Truth declarations are actual. */
function fixture(method: Method) {
const source = createTruthtranceRichesePromisesFixture({advanced:true});
let game = structuredClone(source.game);
assert.equal(game.semutaAdvancedOrdinaryPreview,true);
const cache = game.richeseCache!, emperor = player(game,'emperor'), richese = player(game,'richese');
const saphoAt = cache.findIndex(card => card.effect === 'juiceOfSapho'); assert.ok(saphoAt >= 0);
const [sapho] = cache.splice(saphoAt,1), [swap] = emperor.hand.splice(0,1);
emperor.hand.push(sapho); cache.push(swap);
const semutaAt = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt >= 0);
const [semuta] = cache.splice(semutaAt,1); richese.hand.push(semuta);
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 = 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');
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});
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 order = truthOrderFrame(game);
const mode: 'first' | 'last' = game.truthtrance!.queue[0].player === 'emperor' ? 'last' : 'first';
return {game,parent,offered:offered.id,lot:lot.event,bidder,order,mode,sapho:sapho.id,semuta:semuta.id,cards:source.originalCards};
}
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},f.parent);
assert.ok(player(game,'richese').hand.some(card => card.id === f.offered));
}
function assertSilent(game: Game, bidder: string) {
const owner = viewGame(game,bidder).richeseAuction!, observer = viewGame(game,'emperor').richeseAuction!;
assert.equal(owner.ownBid,1); assert.equal(observer.ownBid,null);
assert.equal(observer.revealedBids,null); assert.equal('sealed' in observer,false);
}
function passOffer(state: Game): Game {
let game = state;
for (let n=0; game.pendingTreacheryDiscard?.reaction?.stage === 'offer' && n<game.players.length; n++) {
const pending = game.pendingTreacheryDiscard, reaction = pending.reaction!;
assert.equal(reaction.stage,'offer');
if (reaction.stage !== 'offer') throw Error('Expected Semuta offer');
const actor = game.players.find(row => !reaction.passed.includes(row.id)); assert.ok(actor);
game = act(game,actor.id,{type:'semutaPass',event:pending.batch.event});
}
return game;
}
for (const method of ['normal','onceAround','silent'] as const) for (const claim of [false,true]) void test(
`Advanced ${method} Black Market Sapho Truth order offers Semuta and ${claim?'claim':'pass'} resumes`, () => {
const f = fixture(method);
const before = structuredClone(f.game), queue = structuredClone(before.truthtrance!.queue);
assert.ok(viewGame(before,'emperor').saphoTruthOrderChoices.some(row => row.card === f.sapho && row.mode === f.mode));
let game = playSaphoTruthOrder(before,'emperor',f.sapho,f.mode);
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'saphoTruthOrderDiscard');
assert.equal(pending.batch.entries[0].card.id,f.sapho);
assert.equal(game.truthtrance,null);
assert.equal(viewGame(game,'richese').semutaReaction?.canCommit,true);
assertParent(game,f);
if (method === 'silent') assertSilent(game,f.bidder);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,'richese'); view.players.find(row => row.id === 'richese')!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action,difficulty);
assert.ok(action.type === 'semutaCommit' || action.type === 'semutaPass');
assert.doesNotThrow(() => act(game,'richese',action));
}
const event = pending.batch.event;
game = claim ? act(game,'richese',{type:'semutaCommit',event}) : passOffer(game);
assert.equal(game.pendingTreacheryDiscard,null);
assert.equal(player(game,'richese').hand.some(card => card.id === f.sapho),claim);
assert.equal(game.discard.some(card => card.id === f.semuta),claim);
assertParent(game,f);
assert.deepEqual(game.truthtrance!.queue.map(row => row.card).sort(),queue.map(row => row.card).sort());
if (game.truthtrance?.stage === 'order') game = finishTruthOrder(game);
assert.equal(f.mode === 'first' ? game.truthtrance!.queue[0].player : game.truthtrance!.queue.at(-1)!.player,'emperor');
game = finishOriginalTruthQuestions(game);
assert.equal(game.truthtrance,null); assertParent(game,f);
assert.deepEqual(inventory(game),f.cards);
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.cards);
});
@@ -6,7 +6,8 @@ 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';
finishTruthOrder as finish, finishOriginalTruthQuestions as answer, rejectSaphoTruthOrder as reject,
passFreshDiscard } 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';
@@ -80,6 +81,7 @@ for (const method of ['normal','onceAround','silent'] as const) void test(
let game = play(f.game,'emperor',f.card,f.mode);
assertParent(game,f);
if (method === 'silent') assertSilent(game,f.bidder);
game = passFreshDiscard(game);
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);