Combine Basic bidding and movement commitments
Verify and publish checkpoint container / container (push) Successful in 10m49s

This commit is contained in:
Quintine committed 2026-11-16 15:03:09 +11:00
1 parent b03efd2371
commit 235696263a
9 files changed
+404 -17

No files matched your search

+10
View File
@@ -17,6 +17,16 @@ open mode gates.
## Current checkpoint and work
**Basic phase-bid, Movement and travel commitments — 16 November. Prototyped /
Partial.** Supported classic Basic answers share the owned purse across bidding,
Revival, Shipment and Movement, with connected bot guidance. Silent cache sales
retain movement commitments through the Emperor's gift opportunity, and
unrelated already-unfunded debts no longer veto immediate public deals. The
changed-rule cases, types and lint pass; Advanced and expansion combinations,
complete games and deployed acceptance remain open. [Scope](TRUTHTRANCE_BID_PROMISES.md#basic-bid-with-movement-and-travel--16-november-2026),
[Silent sales](TRUTHTRANCE_MOVEMENT_PROMISES.md#silent-cache-settlement-and-emperor-gift--16-november-2026),
[deals](PUBLIC_DEALS.md#immediate-deals-and-unrelated-debt--16-november-2026).
**Multiple immediate deal payments — 16 November. Prototyped / Partial.**
Final consent preflights the complete ordered sequence; native Bureaucrat
decisions can pause it and a validated saved frame resumes the original remaining
+9
View File
@@ -1,5 +1,14 @@
# Public deal records
## Immediate deals and unrelated debt — 16 November 2026
**Prototyped / Partial.** An already-unfunded due debt belonging to an
unrelated player no longer vetoes another pair's immediate payments. The
preflight still preserves each previously witnessed due-payment route and the
actual payers' own commitments. [Public-game cases](../tests/public-deals-immediate-unrelated-debts.test.ts)
cover a conserved external loss, unrelated payments and a payer's own
overcommitment. Wider deal interactions and deployed verification remain open.
## Multiple immediate payments — 16 November 2026
**Prototyped / Partial.** A public offer may include up to twelve additional
+19
View File
@@ -1,5 +1,24 @@
# Truthtrance ordinary bid commitments
## Basic bid with Movement and travel — 16 November 2026
**Prototyped / Partial.** In supported classic Basic games before Bidding,
the owned-cash phase-bid witness can include ordinary Movement, grouped
movement expressions and structured travel. After reserving the specific bid
and materializing any required native Revival, the detached planner checks the
same physical Shipment and Movement route with the remaining resources. It
does not assume an ally, future income, Charity or an unowned card. Other
commitment families and later auction lots keep their existing bounds.
Automatic players retain the server's required bid and Revival instructions
before following Movement or travel; nested guide metadata is not mistaken
for another action's authorization. [Public-game cases](../tests/truth-phase-bid-movement-joint.test.ts)
cover both question orders, actual bidding and movement, paid shipment,
grouped expressions and all bot difficulties. The travel-deal/Revival cases
move conserved reserve counters to Tanks as an explicit fixture supplement;
the deal, questions and actions are real. Advanced, expansion factions, other
promises, complete games and deployed verification remain open.
## Basic bid with Revival and Shipment — 16 November 2026
**Prototyped / Partial.** The classic Basic pre-Bidding owned-cash witness
+14
View File
@@ -5,6 +5,20 @@ adds full grouped future destinations/minima to the same owned-action search.
Each leaf still requires one actual qualifying group, never a sum; the new
ledger retains whole No and dynamic alternatives without changing scalar claims.
## Silent cache settlement and Emperor gift — 16 November 2026
**Prototyped / Partial.** A revealed Silent cache bid can open the Emperor's
allied-gift opportunity before the winning buyer's pledged funds are settled.
External movement and travel reconciliation now waits through that pending
opportunity instead of treating the still-locked pledge as a final loss. The
actual sale and resulting donor cost still determine whether a route remains.
The [native Silent case](../tests/truth-movement-native-early-engine.test.ts)
covers a winning or losing ally and two real pledge splits. A [positive final
bid](../tests/truth-movement-silent-final-donor.test.ts) also retains voluntary
legality checks against the revealed payment while leaving the actual gift
opportunity intact. Other nested auction interactions and complete-game
acceptance remain open.
## Native early Advanced and CHOAM opening — 26 October 2026
**Prototyped / Partial.** Both Basic and Advanced now admit clean current-round
+66 -16
View File
@@ -6122,6 +6122,12 @@ function publicDealIntegrity(g: Game, internalSettlement?: string): void {
function preflightPublicDealSettlement(g: Game, deal: PublicDeal, initiator: string): void {
requireRule(!bribeTimingBlock(g), 'Finish the current decision or response before paying a deal.');
const legs = publicDealImmediateLegs(deal);
// Existing unrelated obligations may already lack a funded route after an
// external loss. Preserve witnessed routes without making those unrelated
// shortfalls a veto over this agreement.
const protectedPayers = g.players.filter(player =>
pendingPublicDealPayments(g.deals ?? [],player.id,g.turn).length > 0 && publicDealCompletion(g,player))
.map(player => player.id);
const visit = (trial: Game, index: number): void => {
if (index === legs.length) return;
const leg = legs[index];
@@ -6132,8 +6138,8 @@ function preflightPublicDealSettlement(g: Game, deal: PublicDeal, initiator: str
const candidates = pending ? [false,true].map(redirect => applyActionWithInitiator(next,pending.owner,
{type:'decision',event:pending.source.event,redirect},pending.owner,{publicDealSettlement:deal.id})) : [next];
for (const candidate of candidates) {
for (const player of candidate.players) if (pendingPublicDealPayments(candidate.deals ?? [],player.id,candidate.turn).length)
requireRule(publicDealCompletion(candidate,player), 'Retain a funded completion for each due deal payment.');
for (const id of protectedPayers)
requireRule(publicDealCompletion(candidate,getPlayer(candidate,id)), 'Retain a funded completion for each due deal payment.');
visit(candidate,index + 1);
}
};
@@ -18553,14 +18559,15 @@ function phaseBidHonorsTurnActions(g: Game, p: Player, lot: BidOpportunity, acti
function phaseBidFuturePlannerUnsupported(g: Game, p: Player): boolean {
return liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).some(row => row.answer) ||
liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn).some(row => matchesShipment(row,null) !== row.answer) ||
hasMovementPromises(g,p.id,true) || liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
hasMovementPromises(g,p.id,!!g.advanced || g.expansions.length > 0) ||
liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],p.id,g.turn).length > 0 ||
liveTurnActionPromises(g.turnActionPromises ?? [],p.id,g.turn).length > 0 ||
(!!bidOpportunity(g) && hasBribePromises(g,p.id,true));
}
/** A conservative owned-cash witness for a future Basic bid followed by
* native Revival and Shipment commitments. Other obligations keep their own
* native Revival, Shipment and Movement commitments. Other obligations keep their own
* guards. No pledged refund, Charity, income, ally or Karama is assumed;
* failure to find this witness is not proof of impossibility. */
function phaseBidRevivalShipmentWitness(g: Game, p: Player, promises: readonly PhaseBidPromise[],
@@ -18571,8 +18578,8 @@ function phaseBidRevivalShipmentWitness(g: Game, p: Player, promises: readonly P
const shipments = liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn);
if (g.advanced || g.expansions.length || g.phase >= 3 || g.auction ||
(![...revivals,...leaders].some(row => row.answer) && !expressions.length &&
!shipments.some(row => matchesShipment(row,null) !== row.answer)) ||
hasMovementPromises(g,p.id) ||
!shipments.some(row => matchesShipment(row,null) !== row.answer) && !hasMovementPromises(g,p.id)) ||
liveTurnActionPromises(g.turnActionPromises ?? [],p.id,g.turn).length > 0 ||
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length || hasBribePromises(g,p.id) ||
g.charityPromises?.some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released)) return null;
const range = phaseBidCompletionRange(promises,witness);
@@ -18591,15 +18598,17 @@ function phaseBidRevivalShipmentWitness(g: Game, p: Player, promises: readonly P
const completed = completeTurnActionRevivalSeed(seed,p.id);
if (!completed || currentRevivalPromiseCompletion(completed.game,getPlayer(completed.game,p.id),
completed.game.revivalPromises ?? [])?.type !== 'ready') continue;
if (shipments.some(row => matchesShipment(row,null) !== row.answer)) {
if (hasMovementPromises(g,p.id) || shipments.some(row => matchesShipment(row,null) !== row.answer)) {
const future = completed.game;
future.phase = 5;
future.ready = [];
delete future.revivalOrder;
resetGroundMovementForecast(future,p.id);
future.active = p.id;
const shipment = findShipmentCompletion(future,getPlayer(future,p.id),shipments);
if (!shipment || shipment.early?.length || shipment.actions.some(action => action.type !== 'ship')) continue;
const completion = hasMovementPromises(g,p.id)
? groundMovementCompletion(future,p.id) : findShipmentCompletion(future,getPlayer(future,p.id),shipments);
if (!completion || completion.early?.length ||
completion.actions.some(action => !['ship','guildShip','move','endMovement'].includes(action.type))) continue;
}
return {...witness,minimum:range.minimum,maximum:range.minimum};
}
@@ -24485,7 +24494,7 @@ function reconcileTravelPromises(g: Game, actor?: string, action?: Action, sourc
g.response?.kind === 'advisorFlip' && g.response.owner === p.id ||
g.pendingAutomaticAdvisorFlips?.some(source => source.owner === p.id ||
source.producer === 'groundMovement' && source.mover === p.id)) continue;
if (!voluntary && (g.response || g.decision || g.pendingAmbassador || g.pendingTerrorEntry ||
if (!voluntary && (g.response || g.decision || g.pendingEmperorAuctionGift || g.pendingAmbassador || g.pendingTerrorEntry ||
g.pendingArrivalOverlap || g.pendingArrivalReaction?.length || g.pendingTreacheryDiscard ||
g.phase === 3 && !g.currentAuctionSale &&
(g.auction?.bidder === p.ally && (g.auction?.allyPayment ?? 0) > 0 ||
@@ -24568,8 +24577,9 @@ function projectedDealTravelStatus(g: Game): Record<string, 'scheduled' | 'pendi
function projectedTravelGuide(g: Game, player: Player): { event: string; action: Action } | null {
const promise = liveTravelPromises(g.travelPromises ?? [], player.id, g.turn)[0];
const lot = promise && g.phase === 3 && !g.decision ? bidOpportunity(g) : null;
const needsBid = !!lot && bidRequired(g.bidPromises ?? [], player.id, lot);
const requiredBid = needsBid ? projectedBidPromiseGuide(g, player.id) : null;
const needsBid = !!lot && (bidRequired(g.bidPromises ?? [], player.id, lot) ||
livePhaseBidPromises(g.phaseBidPromises ?? [],player.id,g.turn).length > 0);
const requiredBid = needsBid ? projectedPhaseBidGuide(g,player.id) ?? projectedBidPromiseGuide(g, player.id) : null;
const needsRevival = !!promise && g.phase <= 4 && [
...liveRevivalPromises(g.revivalPromises ?? [], player.id, g.turn),
...liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [], player.id, g.turn),
@@ -24584,6 +24594,8 @@ function projectedTravelGuide(g: Game, player: Player): { event: string; action:
if (!prior) return null;
const action = { ...structuredClone(prior.action) };
delete action.bidPromiseEvent;
delete action.phaseBidPromiseEvent;
delete action.phaseBidPromiseLot;
delete action.revivalExpressionPromiseEvent;
delete action.leaderRevivalPromiseEvent;
delete action.revivalPromiseEvent;
@@ -24591,7 +24603,15 @@ function projectedTravelGuide(g: Game, player: Player): { event: string; action:
}
const policy = promise && (g.phase < 5 || g.active === player.id) ? projectedGroundMovementPolicy(g, player) : null;
const action = policy?.[0];
return promise && action ? { event: promise.event, action: { ...structuredClone(action), travelPromiseEvent: promise.event, travelPromisePhase: g.phase } } : null;
if (!promise || !action) return null;
const native = {...structuredClone(action)};
delete native.bidPromiseEvent;
delete native.phaseBidPromiseEvent;
delete native.phaseBidPromiseLot;
delete native.revivalExpressionPromiseEvent;
delete native.leaderRevivalPromiseEvent;
delete native.revivalPromiseEvent;
return { event: promise.event, action: { ...native, travelPromiseEvent: promise.event, travelPromisePhase: g.phase } };
}
function groundMovementCompletion(source: Game, actor: string,
promises = liveMovementPromises(source.movementPromises ?? [], actor, source.turn),
@@ -24839,7 +24859,21 @@ function earlyGroundMovementPolicy(g: Game, player: Player): Action[] | null {
if (lot) return !lot.outcome && lot.eligible.includes(player.id) &&
(lot.method === 'silent' ? !Object.hasOwn(lot.sealed, player.id) : lot.active === player.id)
? [{ type: 'richeseBid', event: lot.event, amount: lot.method === 'silent' ? 0 : null, allyPayment: 0 }] : [];
return g.auction?.active === player.id ? [{ type: 'passBid' }] : [];
if (g.auction?.active !== player.id) return [];
const guide = projectedPhaseBidGuide(g,player.id)?.action ?? projectedBidPromiseGuide(g,player.id)?.action;
const ordinaryLot = bidOpportunity(g);
if (guide) return [guide];
if (livePhaseBidPromises(g.phaseBidPromises ?? [],player.id,g.turn).some(row => row.answer) ||
ordinaryLot && bidRequired(g.bidPromises ?? [],player.id,ordinaryLot)) return [];
return [{ type: 'passBid' }];
}
if (g.phase === 4 && !g.decision) {
const guide = projectedRevivalExpressionPromiseGuide(g,player.id) ?? projectedLeaderRevivalPromiseGuide(g,player.id) ??
projectedRevivalPromiseGuide(g,player.id);
if (guide) return [guide.action];
if ([...liveRevivalPromises(g.revivalPromises ?? [],player.id,g.turn),
...liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [],player.id,g.turn),
...liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [],player.id,g.turn)].some(row => row.answer)) return [];
}
const completion = groundMovementCompletion(g, player.id);
if (!completion) return null;
@@ -24973,7 +25007,15 @@ function projectedMovementExpressionGuide(g: Game, player: Player): { phase: num
const promise = live.find(promise => promise.answer) ?? live[0];
if (!promise) return null;
const action = projectedGroundMovementPolicy(g, player)?.[0];
return action ? { phase: g.phase, action: { ...structuredClone(action), movementExpressionPromiseEvent: promise.event } } : null;
if (!action) return null;
const native = {...structuredClone(action)};
delete native.bidPromiseEvent;
delete native.phaseBidPromiseEvent;
delete native.phaseBidPromiseLot;
delete native.revivalExpressionPromiseEvent;
delete native.leaderRevivalPromiseEvent;
delete native.revivalPromiseEvent;
return { phase: g.phase, action: { ...native, movementExpressionPromiseEvent: promise.event } };
}
function checkGroundMovementPromises(g: Game, p: Player, move: MovementOrder) {
if (move.source === 'ambassador' || !hasMovementPromises(g, p.id)) return;
@@ -25033,7 +25075,7 @@ function reconcileGroundMovementPromises(g: Game, actor?: string, action?: Actio
(['card', 'bribe', 'charity', 'alliance', 'pledgeAid', 'emperorGift', 'bid', 'richeseGift', 'revealNoField', 'revive', 'reviveLeader', 'reviveKwisatz', 'emperorRevival', 'decision'].includes(action.type) ||
action.type === 'richeseBid' && typeof action.amount === 'number' && action.amount > 0 ||
action.type === 'ready' && [2, 4].includes(sourcePhase)));
const busy = !!(g.response || g.decision || g.phaseOpening || g.pendingTreacheryDiscard ||
const busy = !!(g.response || g.decision || g.phaseOpening || g.pendingTreacheryDiscard || g.pendingEmperorAuctionGift ||
g.pendingAmbassador || g.pendingTerrorEntry || g.pendingArrivalOverlap || g.pendingArrivalReaction?.length ||
g.phase === 3 && !g.currentAuctionSale &&
(g.auction?.bidder === p.ally && (g.auction?.allyPayment ?? 0) > 0 ||
@@ -34069,6 +34111,14 @@ function earlyRevivalCompletionSeeds(initial: Game, source: Game, owner: string)
}
// Native Bidding refunds its unused pledges. An ally's incoming
// Bidding escrow is never a promised future Shipment contribution.
// This detached seed already accounts for the revealed cache sale.
// Its optional gift window belongs to the real table, not the later
// Revival/Movement simulation; leave the live window untouched.
const gift = source.pendingEmperorAuctionGift, outcome = source.richeseAuction?.outcome;
if (gift?.source === 'richese' && !source.response && !source.decision && gift.quote &&
outcome?.kind === 'sold' && outcome.winner === gift.quote.winner &&
outcome.amount === gift.quote.amount && source.richeseAuction?.cardId === gift.quote.card.id)
g.pendingEmperorAuctionGift = null;
g.aid = {}; g.auction = null; g.currentAuctionSale = null;
g.richeseAuction = null; g.richeseFunding = {}; g.richeseBidding = null;
fundingSeeds.push({ game: g, actions, early });
@@ -0,0 +1,62 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { type Game } from '../game/engine';
import {
actMentatBribe as act, createMentatBribeFixture as fixture,
mentatBribeInventory as inventory, mentatBribePlayer as player,
} from './fixture-mentat-bribes';
/** Real Basic setup and Mentat; both separate four-spice debts are accepted
* through public offers and votes before the controlled external loss. */
function withTwoDebts() {
const f = fixture();
let game: Game = f.game;
const debts: string[] = [];
for (let n = 0; n < 2; n++) {
game = act(game, f.asker, {type:'dealOffer', target:f.target, terms:'Pay four spice.',
payment:{kind:'deferredBribe', payer:f.target, recipient:f.asker, amount:4, dueTurn:game.turn}});
const id = game.deals?.at(-1)?.id; assert.ok(id); debts.push(id);
game = act(game, f.target, {type:'dealRespond', deal:id, accept:true});
}
return {f, game, debts};
}
void test('an unrelated insolvency does not block a funded multi-payment deal', () => {
const {f, game:accepted, debts} = withTwoDebts();
const staged = structuredClone(accepted);
const beforeTotal = staged.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0);
// Transfer five existing spice to represent a settled external loss. Each
// debt remains individually payable, while their sum no longer fits.
player(staged,f.target).spice -= 5;
player(staged,f.asker).spice += 5;
let game = act(staged, f.opponent, {type:'ready'});
assert.deepEqual(debts.map(id => game.deals!.find(deal => deal.id === id)!.paymentStatus), ['pending','pending']);
const payerBefore = player(game,f.asker).spice, recipientBefore = player(game,f.opponent).bribes;
game = act(game,f.asker,{type:'dealOffer',target:f.opponent,terms:'Two immediate payments.',
payment:{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1},
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.asker,recipient:f.opponent,amount:1}]});
const id = game.deals?.at(-1)?.id; assert.ok(id);
game = act(game,f.opponent,{type:'dealRespond',deal:id,accept:true});
assert.equal(game.deals!.find(deal => deal.id === id)!.status,'active');
assert.equal(player(game,f.asker).spice,payerBefore-2);
assert.equal(player(game,f.opponent).bribes,recipientBefore+2);
assert.equal(player(game,f.target).spice,5);
assert.deepEqual(debts.map(debt => game.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
assert.equal(game.players.reduce((sum, seat) => sum + seat.spice + seat.bribes, 0),beforeTotal);
assert.deepEqual(inventory(game),f.originalCards);
});
void test('a payer cannot use the same spice for due debts and immediate payments', () => {
const {f, game:accepted, debts} = withTwoDebts();
const offered = act(accepted,f.asker,{type:'dealOffer',target:f.target,terms:'Two immediate payments.',
payment:{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:1},
additionalImmediatePayments:[{kind:'immediateBribe',payer:f.target,recipient:f.asker,amount:2}]});
const id = offered.deals?.at(-1)?.id; assert.ok(id);
const before = structuredClone(offered);
assert.throws(() => act(offered,f.target,{type:'dealRespond',deal:id,accept:true}));
assert.deepEqual(offered,before);
assert.equal(offered.deals!.find(deal => deal.id === id)!.status,'offered');
assert.deepEqual(debts.map(debt => offered.deals!.find(deal => deal.id === debt)!.paymentStatus), ['pending','pending']);
assert.equal(player(offered,f.target).spice,10);
assert.deepEqual(inventory(offered),f.originalCards);
});
@@ -69,7 +69,8 @@ void test('controlled Silent ally funding keeps the full pledge locked and resol
game = act(game, 'richese', { type: 'richeseBid', event, amount: loses ? 4 : 0, allyPayment: 0 });
game = advance(game, g => g.phase === 4 && clean(g), [], auction);
assert.equal(owner(game).spice, loses ? 14 : 10 - allyPayment);
assert.equal(game.movementPromises![0].released, !loses && allyPayment === 3 ? true : undefined);
assert.equal(game.movementPromises![0].released, !loses && allyPayment === 3 ? true : undefined,
`loses=${loses}, allyPayment=${allyPayment}`);
}
});
@@ -0,0 +1,45 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { viewGame } from '../game/engine';
import { createTruthMovementNativeEarlyFixture as fixture, actTruthMovementNativeEarly as act,
advanceTruthMovementNativeEarly as advance, truthMovementNativeEarlyClean as clean,
truthMovementNativeEarlyPlayer as player } from './fixture-truth-movement-native-early';
void test('a positive final Silent bid keeps an affordable movement promise through the allied gift window', () => {
const f = fixture(), source = structuredClone(f.game), auction = { method: 'silent' as const };
player(source, f.target).ally = 'choam';
player(source, 'choam').ally = f.target;
let game = act(source, f.asker, f.declarationStep.action);
while (game.truthtrance?.stage === 'priority') {
const seat = game.players.find(p => !game.truthtrance!.passed.includes(p.id));
assert.ok(seat);
game = act(game, seat.id, { type: 'truthPass' });
}
game = act(game, f.asker, { type: 'truthAsk', question: f.claim });
assert.ok(viewGame(game, f.target).truthMovementAnswers!.includes('yes'));
game = advance(act(game, f.target, { type: 'truthAnswer', answer: 'yes' }), clean);
game = advance(game, g => g.phase === 3 && clean(g) && !!g.richeseAuction &&
!g.richeseAuction.outcome, [], auction);
game = act(game, f.target, { type: 'pledgeAid', amount: 8 });
const lot = game.richeseAuction!;
assert.ok(['choam', 'richese', f.target].every(id => lot.eligible.includes(id)));
game = act(game, 'choam', { type: 'richeseBid', event: lot.event, amount: 3, allyPayment: 1 });
for (const id of lot.eligible.filter(id => id !== 'choam' && id !== f.target))
game = act(game, id, { type: 'richeseBid', event: lot.event, amount: 0, allyPayment: 0 });
assert.equal(game.movementPromises![0].released, undefined);
game = act(game, f.target, { type: 'richeseBid', event: lot.event, amount: 1, allyPayment: 0 });
assert.deepEqual(game.richeseAuction?.outcome, { kind: 'sold', winner: 'choam', amount: 3 });
assert.equal(game.pendingEmperorAuctionGift?.owner, f.target);
assert.equal(game.movementPromises![0].released, undefined);
const event = game.pendingEmperorAuctionGift!.event;
game = act(game, f.target, { type: 'emperorAuctionGiftContinue', event });
assert.equal(player(game, f.target).spice, 2);
assert.equal(game.aid[f.target]?.amount, 7);
assert.equal(game.movementPromises![0].released, undefined);
game = advance(game, g => g.phase === 5 && clean(g) && g.active === f.target, [], auction);
assert.equal(player(game, f.target).spice, 9);
game = act(game, f.target, f.shipment);
game = advance(game, clean, [], auction);
game = act(game, f.target, f.move);
assert.equal(game.movementPromises![0].fulfilled, true);
});
@@ -0,0 +1,177 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { applyAction, viewGame, type Game } from '../game/engine';
import { botActions } from '../game/bots';
import { DIFFICULTIES } from '../game/bot-profiles';
import { actTruthBid as act, advanceTruthBid as advance, truthBidClean as clean,
truthBidInventory as inventory, truthBidPlayer as player } from './fixture-truth-bid';
import { createTruthTurnBidFixture } from './fixture-truth-turn-bid';
/** Public Basic Harkonnen/Atreides/Emperor setup and actual opening. Only the
* existing unopened Spice cards are reordered; both Truthtrances are dealt. */
function fixture() {
const f = createTruthTurnBidFixture();
let game = structuredClone(f.afterSetup);
for (const {position, from, card} of f.spiceOrder) {
const [selected] = game.spiceDeck.splice(from,1);
assert.deepEqual(selected,card); game.spiceDeck.splice(position,0,selected);
}
game = advance(game,state => state.turn === 1 && state.phase === 2 && clean(state));
assert.equal(player(game,f.target).spice,10);
assert.ok(player(game,f.target).reserves >= 4);
assert.deepEqual(inventory(game),f.originalCards);
return {f,game};
}
function ask(game: Game, asker: string, card: string, question: object): Game {
game = act(game,asker,{type:'card',card});
for (let count = 0; game.truthtrance?.stage === 'priority' && count < game.players.length; count++) {
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');
return act(game,asker,{type:'truthAsk',question});
}
for (const kind of ['movement','travel'] as const)
for (const first of ['bid','movement'] as const)
for (const affordable of [true,false]) {
void test(`Basic phase bid and ${kind} in ${first}-first order ${affordable ? 'share enough spice' : 'cannot overcommit spice'}`, () => {
const {f,game:initial} = fixture();
const bid = {kind:'phaseBid',target:f.target,turn:initial.turn,minimum:affordable ? 6 : 7};
const move = kind === 'movement'
? {kind:'movement',target:f.target,territory:'carthag',minimum:4}
: {kind:'travel',target:f.target,turn:initial.turn,mixed:{kind:'and',terms:[
{kind:'action',action:{kind:'ship',territory:'arrakeen',minimum:4}},
{kind:'action',action:{kind:'move',territory:'carthag',minimum:4}},
]}};
const questions = first === 'bid' ? [bid,move] : [move,bid];
const movementAnswers = (state:Game) => kind === 'movement'
? viewGame(state,f.target).truthMovementAnswers : viewGame(state,f.target).truthTravelAnswers;
let game = ask(initial,f.asker,f.truths[0],questions[0]);
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : movementAnswers(game);
assert.ok(firstAnswers?.includes('yes'),'Either single commitment is feasible');
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = ask(game,f.asker,f.truths[1],questions[1]);
const answers = first === 'bid' ? movementAnswers(game) : viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('no'));
assert.equal(answers?.includes('yes'),affordable,'Bid and physical shipment share the same purse');
if (!affordable) {
const before = structuredClone(game);
assert.throws(() => act(game,f.target,{type:'truthAnswer',answer:'yes'}));
assert.deepEqual(game,before);
return;
}
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action);
const done = applyAction(game,f.target,action);
assert.equal(done.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled),true,
`${difficulty} makes the required legal bid`);
}
game = act(game,f.target,{type:'bid',amount:6,allyPayment:0});
assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled));
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
assert.equal(player(game,f.target).spice,4,'The real winning invoice is paid once');
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action);
assert.doesNotThrow(() => applyAction(game,f.target,action),`${difficulty} can begin legal travel`);
}
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:4,elite:0,allyPayment:0}),clean);
assert.equal(player(game,f.target).spice,0);
game = advance(act(game,f.target,{type:'move',from:'arrakeen:10',territory:'carthag',sector:11,amount:4}),clean);
assert.equal(player(game,f.target).forces['carthag:11'],4);
assert.equal(kind === 'movement' ? game.movementPromises?.[0]?.fulfilled : game.travelPromises?.[0]?.fulfilled,true);
assert.deepEqual(inventory(game),f.originalCards);
});
}
for (const first of ['bid','expression'] as const) {
void test(`Basic phase bid and grouped movement in ${first}-first order keep a legal bot guide`, () => {
const {f,game:initial} = fixture();
const bid = {kind:'phaseBid',target:f.target,turn:initial.turn,minimum:6};
const expression = {kind:'movementExpression',target:f.target,turn:initial.turn,claim:{kind:'or',terms:[
{kind:'move',territory:'carthag',minimum:4},
{kind:'move',territory:'imperial_basin',minimum:4},
]}};
const questions = first === 'bid' ? [bid,expression] : [expression,bid];
let game = ask(initial,f.asker,f.truths[0],questions[0]);
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers
: viewGame(game,f.target).truthMovementExpressionAnswers;
assert.ok(firstAnswers?.includes('yes'));
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = ask(game,f.asker,f.truths[1],questions[1]);
const answers = first === 'bid' ? viewGame(game,f.target).truthMovementExpressionAnswers
: viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('yes'));
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action);
const done = applyAction(game,f.target,action);
assert.equal(done.phaseBidPromises?.some(row => row.player === f.target && row.fulfilled),true,
`${difficulty} follows a legal required bid`);
}
game = act(game,f.target,{type:'bid',amount:6,allyPayment:0});
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:4,elite:0,allyPayment:0}),clean);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action);
assert.doesNotThrow(() => applyAction(game,f.target,action),`${difficulty} can make a legal movement choice`);
}
game = advance(act(game,f.target,{type:'move',from:'arrakeen:10',territory:'carthag',sector:11,amount:4}),clean);
assert.equal(game.movementExpressionPromises?.[0]?.fulfilled,true);
assert.equal(player(game,f.target).spice,0);
assert.deepEqual(inventory(game),f.originalCards);
});
}
/** The public deal and both Truthtrance answers are real. Only three of the
* Emperor's existing reserve forces are staged into Tanks to create a paid
* Revival need; no cards, spice, accepted promises or force counters are added. */
for (const first of ['bid','revival'] as const) {
void test(`Basic public travel deal, bid and Revival in ${first}-first order retain legal native bot actions`, () => {
const {f,game:initial} = fixture();
player(initial,f.target).reserves -= 3; player(initial,f.target).tanks += 3;
let game = act(initial,f.asker,{type:'dealOffer',target:f.target,terms:'Ship two forces to Arrakeen.',
travel:{kind:'ship',territory:'arrakeen',minimum:2,answer:true}});
const deal = game.deals?.at(-1); assert.ok(deal);
game = act(game,f.target,{type:'dealRespond',deal:deal.id,accept:true});
assert.equal(viewGame(game,f.target).dealTravelStatus[deal.id],'pending');
const bid = {kind:'phaseBid',target:f.target,turn:game.turn,minimum:4};
const revival = {kind:'revival',target:f.target,turn:game.turn,counter:'total',minimum:3};
const questions = first === 'bid' ? [bid,revival] : [revival,bid];
game = ask(game,f.asker,f.truths[0],questions[0]);
const firstAnswers = first === 'bid' ? viewGame(game,f.target).truthPhaseBidAnswers : viewGame(game,f.target).truthRevivalAnswers;
assert.ok(firstAnswers?.includes('yes'));
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = ask(game,f.asker,f.truths[1],questions[1]);
const answers = first === 'bid' ? viewGame(game,f.target).truthRevivalAnswers : viewGame(game,f.target).truthPhaseBidAnswers;
assert.ok(answers?.includes('yes'),'Four bid, four paid Revival and two shipment share ten spice');
game = act(game,f.target,{type:'truthAnswer',answer:'yes'});
game = advance(game,state => clean(state) && state.phase === 3 && state.auction?.active === f.target);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action);
assert.equal(applyAction(game,f.target,action).phaseBidPromises?.some(row => row.fulfilled),true);
}
game = act(game,f.target,{type:'bid',amount:4,allyPayment:0});
game = advance(game,state => clean(state) && state.phase === 4);
for (const difficulty of DIFFICULTIES) {
const view = viewGame(game,f.target); view.players.find(row => row.id === f.target)!.bot = difficulty;
const action = botActions(view)[0]; assert.ok(action); assert.equal(action.type,'revive');
assert.equal(applyAction(game,f.target,action).revivalPromises?.some(row => row.fulfilled),true);
}
game = act(game,f.target,{type:'revive',amount:3,elite:0});
game = advance(game,state => clean(state) && state.phase === 5 && state.active === f.target);
game = advance(act(game,f.target,{type:'ship',territory:'arrakeen',sector:10,amount:2,elite:0,allyPayment:0}),clean);
assert.equal(viewGame(game,f.target).dealTravelStatus[deal.id],'fulfilled');
assert.equal(player(game,f.target).spice,0);
assert.deepEqual(inventory(game),f.originalCards);
});
}