Files
Dune/tests/semuta-advanced-truth-black-market.test.ts
T
Quintine 12060f3112
Verify and publish checkpoint container / container (push) Successful in 11m23s
Support Advanced Semuta at Truthtrance auction answers
2026-11-16 19:00:42 +11:00

201 lines
12 KiB
TypeScript

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,
truthtranceRichesePromisesPlayer as player } from './fixture-truthtrance-richese-promises';
type Method = 'normal' | 'onceAround' | 'silent';
type Kind = 'fact' | 'richeseBid' | 'mixedRicheseBid';
/** Real Advanced setup, dealt Truth and seller Shield, and real Black Market
* actions. The original physical Semuta moves from cache into Richese's hand;
* the underlying fixture selects the unopened deal, Spice order and rolls. */
function fixture(method: Method) {
const source = createTruthtranceRichesePromisesFixture({advanced:true});
let game = structuredClone(source.earlySource);
assert.equal(game.semutaAdvancedOrdinaryPreview,true);
const cache = game.richeseCache!;
const at = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(at >= 0);
const [semuta] = cache.splice(at,1); player(game,source.richese).hand.push(semuta);
assert.deepEqual(inventory(game),source.originalCards);
game = advance(game,state => state.decision?.kind === 'richeseBlackMarket');
const card = source.targetCard;
assert.ok(player(game,source.richese).hand.some(held => held.id === card));
game = act(game,source.richese,{type:'decision',event:game.richeseBidding!.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'});
}
const lot = game.richeseAuction; assert.ok(lot && lot.source === 'blackMarket');
if (method === 'silent') game = act(game,source.richese,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0});
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});
return {game,asker:source.asker,target:source.emperor,owner:source.richese,truth:source.truth,
semuta:semuta.id,card,lot:lot.event,cards:source.originalCards,parent};
}
type Fixture = ReturnType<typeof fixture>;
function assertParent(game: Game, f: 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,f.owner).hand.some(card => card.id === f.card));
if (game.richeseAuction?.method === 'silent') {
assert.equal(viewGame(game,f.owner).richeseAuction?.ownBid,1);
assert.equal(viewGame(game,f.target).richeseAuction?.ownBid,null);
assert.equal(viewGame(game,f.target).richeseAuction?.revealedBids,null);
}
}
function ask(f: Fixture, kind: Kind) {
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 === 'fact' ? {kind,target:f.target,fact:{kind:'spice',compare:'gte',value:0}} :
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});
}
function passOffer(state: Game) {
let game = state;
while (game.pendingTreacheryDiscard?.reaction?.stage === 'offer') {
const pending = game.pendingTreacheryDiscard, reaction = pending.reaction!;
if (reaction.stage !== 'offer') throw Error('Expected a Semuta offer');
const seat = game.players.find(row => !reaction.passed.includes(row.id)); assert.ok(seat);
game = act(game,seat.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 definite fact offers Semuta and ${claim ? 'claim' : 'pass'} preserves the lot`,() => {
const f = fixture(method), asked = ask(f,'fact');
let game = act(asked,f.target,{type:'truthAnswer',answer:'yes'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard');
assert.equal(pending.batch.entries[0].card.id,f.truth);
assert.equal(viewGame(game,f.owner).semutaReaction?.canCommit,true);
assertParent(game,f);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.owner); view.players.find(row => row.id === f.owner)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action,difficulty);
assert.ok(action.type === 'semutaPass' || action.type === 'semutaCommit');
assert.doesNotThrow(() => act(game,f.owner,action));
}
game = claim ? act(game,f.owner,{type:'semutaCommit',event:pending.batch.event}) : passOffer(game);
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null);
assert.equal(player(game,f.owner).hand.some(card => card.id === f.truth),claim);
assert.equal(game.discard.some(card => card.id === f.semuta),claim);
assertParent(game,f); assert.deepEqual(inventory(game),f.cards);
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:f.lot,amount:method === 'silent' ? 0 : null,allyPayment:0});
assert.deepEqual(inventory(game),f.cards);
});
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 its native bid commitment through Semuta`,() => {
const f = fixture(method), asked = ask(f,kind);
let game = act(asked,f.target,{type:'truthAnswer',answer});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
assert.equal(pending.continuation.kind,'truthtranceDiscard'); assertParent(game,f);
const native = game.richeseBidPromises?.find(row => row.player === f.target && !row.fulfilled && !row.released);
assert.ok(native); assert.equal(native.answer,answer === 'yes');
game = act(game,f.owner,{type:'semutaCommit',event:pending.batch.event});
assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null); assertParent(game,f);
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);
const bad: Action = {...guide.action,richeseBidPromiseId:'stale'};
const before = structuredClone(game); assert.throws(() => act(game,f.target,bad)); assert.deepEqual(game,before);
const amount = answer === 'yes' ? 4 : 2;
game = act(game,f.target,{type:'richeseBid',event:f.lot,amount,allyPayment:0});
assert.ok(game.richeseBidPromises?.find(row => row.id === native.id)?.fulfilled);
if (method === 'silent') {
assert.equal(viewGame(game,f.target).richeseAuction?.ownBid,amount);
assert.equal(viewGame(game,f.owner).richeseAuction?.revealedBids,null);
game = act(game,f.asker,{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(card => card.id === f.card));
assert.equal(game.discard.some(card => card.id === f.semuta),true);
assert.deepEqual(inventory(game),f.cards);
});
void test('Advanced Silent Black Market resumes the second actual Truth question after Semuta claims the first',() => {
const f = fixture('silent'); let game = structuredClone(f.game);
// Move the other original unopened Truth card into Emperor's hand. This is
// the only extra fixture staging; each holder actually declares its card.
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.target).hand.push(second);
assert.deepEqual(inventory(game),f.cards);
game = act(game,f.asker,{type:'card',card:f.truth});
game = act(game,f.target,{type:'card',card:second.id});
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'});
}
while (game.truthtrance?.stage === 'order') {
const order = game.truthtrance.order!;
const actor = order.holders.find(id => !order.passed.includes(id)); assert.ok(actor);
game = act(game,actor,{type:'truthOrderPass',event:order.event,revision:order.revision});
}
assert.equal(game.truthtrance?.stage,'ask'); assert.equal(game.truthtrance.queue.length,2);
const originalQueue = structuredClone(game.truthtrance.queue), first = originalQueue[0];
game = act(game,first.player,{type:'truthAsk',question:{kind:'fact',target:f.owner,
fact:{kind:'spice',compare:'gte',value:0}}});
game = act(game,f.owner,{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,first.card); assertParent(game,f);
game = act(game,f.owner,{type:'semutaCommit',event:pending.batch.event});
assert.equal(game.pendingTreacheryDiscard,null);
assert.deepEqual(game.truthtrance?.queue,originalQueue.slice(1));
assert.equal(game.truthtrance?.stage,'ask'); assertParent(game,f);
const remaining = game.truthtrance!.queue[0];
game = act(game,remaining.player,{type:'truthAsk',question:{kind:'fact',target:f.owner,
fact:{kind:'spice',compare:'gte',value:0}}});
game = act(game,f.owner,{type:'truthAnswer',answer:'yes'});
assert.ok(game.pendingTreacheryDiscard?.reaction);
game = passOffer(game);
assert.equal(game.truthtrance,null); assertParent(game,f);
assert.deepEqual(inventory(game),f.cards);
});
void test('an unknown Advanced Black Market answer keeps the physical Truth and opens no Semuta discard',() => {
const f = fixture('silent'); 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'});
}
game = act(game,f.asker,{type:'truthAsk',question:{kind:'fact',target:f.target,
fact:{kind:'stormForecast',compare:'gte',value:1}}});
assert.equal(viewGame(game,f.target).truthAnswer,'unknown');
game = act(game,f.target,{type:'truthAnswer',answer:'unknown'});
assert.equal(game.truthtrance?.stage,'unknown');
assert.equal(game.pendingTreacheryDiscard ?? null,null);
assert.ok(player(game,f.asker).hand.some(card => card.id === f.truth));
assert.ok(player(game,f.owner).hand.some(card => card.id === f.semuta));
assertParent(game,f); assert.deepEqual(inventory(game),f.cards);
});