Compose phase-wide and ordinary bid commitments
Verify and publish checkpoint container / container (push) Successful in 10m37s

This commit is contained in:
Quintine committed 2026-11-16 19:42:53 +11:00
1 parent 9e020ccd64
commit 1ff520a9fc
11 files changed
+591 -15

No files matched your search

+88 -11
View File
@@ -2005,6 +2005,8 @@ export type Game = {
advancedAuctionTruth?: true;
/** Fresh joint Richese/all-auction answer; absent on older receipts. */
jointRichesePhaseBid?: true;
/** Fresh joint ordinary/all-auction answer; absent on older receipts. */
jointOrdinaryPhaseBid?: true;
resume: NonNullable<Game['pendingNullentropy']>['resume'];
promise:
| { kind: 'shipment'; index: number; value: ShipmentPromise }
@@ -8058,6 +8060,8 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) {
...(next.record.question.kind === 'phaseAnyBid' ? {phaseAnyBidPromises:g.phaseAnyBidPromises} : {}),
...(next.jointRichesePhaseBid ? {jointRichesePhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
richeseBidPromises:g.richeseBidPromises,mixedRicheseBidQuestions:g.mixedRicheseBidQuestions} : {}),
...(next.jointOrdinaryPhaseBid ? {jointOrdinaryPhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
bidPromises:g.bidPromises,mixedBidQuestions:g.mixedBidQuestions} : {}),
...(next.record.question.kind === 'mixedRevival' ? {
mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises,
} : {}),
@@ -8147,6 +8151,10 @@ function finishTruthtranceAnswer(g: Game) {
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length &&
liveRicheseBidPromises(g.richeseBidPromises ?? [],{turn:g.turn,event:g.richeseAuction.event,
player:record.question.target}).length ? {jointRichesePhaseBid:true as const} : {}),
...(bidOpportunity(g) && ['phaseAnyBid','bid','mixedBid'].includes(record.question.kind) &&
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length &&
liveBidPromises(g.bidPromises ?? [],record.question.target,bidOpportunity(g)!).length
? {jointOrdinaryPhaseBid:true as const} : {}),
resume,
promise,
parentSignature: '',
@@ -9174,6 +9182,14 @@ function treacheryDiscardIntegrity(g: Game) {
'The consumed Truthtrance does not match its completed answer history.',
);
const remaining = c.remaining;
if (c.jointOrdinaryPhaseBid) {
const lot = bidOpportunity(g), target = record.question.target;
requireRule(c.jointOrdinaryPhaseBid === true && !!lot &&
['phaseAnyBid','bid','mixedBid'].includes(record.question.kind) &&
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],target,g.turn).length > 0 &&
liveBidPromises(g.bidPromises ?? [],target,lot).length > 0,
'The completed Truthtrance lost its joint ordinary auction commitments.');
}
if (c.jointRichesePhaseBid) {
const lot = g.richeseAuction, target = record.question.target;
requireRule(c.jointRichesePhaseBid === true && !!lot &&
@@ -19013,8 +19029,10 @@ function phaseAnyBidWindow(g: Game): boolean {
(g.phase < 3 || !!bidOpportunity(g) || !!g.richeseAuction && !g.richeseAuction.outcome);
}
function phaseAnyBidConflict(g: Game, p: Player): boolean {
const current = bidOpportunity(g);
return livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn).length > 0 ||
(g.bidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) ||
(g.bidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released &&
(!current || row.source !== current.source)) ||
(g.earlyRicheseBidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn &&
!row.fulfilled && !row.released) ||
(g.pledgePromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) ||
@@ -19039,6 +19057,20 @@ function phaseAnyFutureCache(g: Game, p: Player): PhaseBidOpportunity | null {
return Number.isSafeInteger(maximum) && maximum > 0
? {turn:g.turn,player:p.id,kind:'future',minimum:1,maximum} : null;
}
/** A declared last cache follows the ordinary pool even if its last lot is
* unbid. Keep a current winning invoice and card slot reserved. */
function phaseAnyLastCache(g: Game,p: Player): PhaseBidOpportunity | null {
const round = g.richeseBidding, auction = g.auction;
if (g.phase !== 3 || !round || round.turn !== g.turn || round.stage !== 'normal' ||
round.position !== 'last' || !auction || g.richeseAuction || !richeseCacheRuns(g)) return null;
const own = auction.bidder === p.id && !g.currentAuctionSale;
const added = own ? 1 + Number(p.faction === 'harkonnen') : 0;
if (p.hand.length + added >= handLimit(p)) return null;
const lockedAid = own ? (auction.allyPayment ?? 0) : 0;
const maximum = Math.max(0,uncommittedSpice(g,p) + Math.max(0,(aidFor(g,p)?.amount ?? 0)-lockedAid));
return Number.isSafeInteger(maximum) && maximum > 0
? {turn:g.turn,player:p.id,kind:'future',minimum:1,maximum} : null;
}
/** Quote the real local declaration before relying on a later phase-wide bid.
* This detached forecast records only the respondent's own Silent submission. */
function jointRicheseFutureWitnesses(g: Game,p: Player,phase: readonly PhaseBidPromise[],
@@ -19079,8 +19111,24 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro
}
}
const futureCache = phaseAnyFutureCache(g,p);
let lastCache = phaseAnyLastCache(g,p);
const ordinaryLot = bidOpportunity(g);
if (lastCache && ordinaryLot && bidRequired(g.bidPromises ?? [],p.id,ordinaryLot)) {
const caps: BidPromise[] = livePhaseBidPromises(promises,p.id,g.turn).filter(row => !row.answer)
.map((row,index) => ({turn:g.turn,lot:ordinaryLot.lot,minimum:row.minimum,event:`any-cache-cap-${index}`,
source:ordinaryLot.source,player:p.id,asker:row.asker,answer:false}));
const action = bidPromiseCompletion(g,p,[...(g.bidPromises ?? []),...caps]);
if (!action || action.type !== 'bid') lastCache = null;
else {
const trial = structuredClone(g);
trial.auction!.bid = Number(action.amount); trial.auction!.bidder = p.id;
trial.auction!.allyPayment = Number(action.allyPayment ?? 0);
lastCache = phaseAnyLastCache(trial,getPlayer(trial,p.id));
}
}
const ordinary = viablePhaseBidWitnesses(g,p,promises);
return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),...ordinary];
return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),
...(lastCache ? [lastCache] : []),...ordinary];
}
function richesePhaseJointPossible(g: Game,p: Player,phase: readonly PhaseBidPromise[]): boolean {
const lot = g.richeseAuction;
@@ -19100,7 +19148,8 @@ function phaseAnyBidTruthAnswers(g: Game, p: Player, claim: PhaseBidClaim): Trut
if (g.richeseAuction && liveRicheseBidPromises(g.richeseBidPromises ?? [],
{turn:g.turn,event:g.richeseAuction.event,player:p.id}).length)
return richesePhaseJointPossible(g,p,all);
return !livePhaseBidPromises(all,p.id,g.turn).some(row => row.answer) ||
const ordinary = bidOpportunity(g), localRequired = ordinary && bidRequired(g.bidPromises ?? [],p.id,ordinary);
return !localRequired && !livePhaseBidPromises(all,p.id,g.turn).some(row => row.answer) ||
phaseAnyBidWitnesses(g,p,all).some(witness => !!phaseBidCompletionRange(all,witness));
});
}
@@ -19157,10 +19206,29 @@ function projectedPhaseAnyBidGuide(g: Game, id: string): {action:Action} | null
const live = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],id,g.turn), p = getPlayer(g,id);
if (!live.length || g.truthtrance || !phaseAnyBidWindow(g)) return null;
if (g.auction) {
const ordinary = projectedPhaseBidGuide({...g,phaseBidPromises:live},id)?.action;
let ordinary = projectedPhaseBidGuide({...g,phaseBidPromises:live},id)?.action;
const lot = bidOpportunity(g);
if (!ordinary && lot && g.auction.active === id && phaseAnyLastCache(g,p)) {
const caps: BidPromise[] = live.filter(row => !row.answer).map((row,index) => ({
turn:g.turn,lot:lot.lot,minimum:row.minimum,event:`any-cache-guide-${index}`,
source:lot.source,player:id,asker:row.asker,answer:false}));
const action = bidPromiseCompletion(g,p,[...(g.bidPromises ?? []),...caps]);
if (action) {
const trial = structuredClone(g);
if (action.type === 'bid') {
trial.auction!.bid = Number(action.amount); trial.auction!.bidder = id;
trial.auction!.allyPayment = Number(action.allyPayment ?? 0);
trial.bidPromises = recordPromisedBid(trial.bidPromises ?? [],id,lot,Number(action.amount));
} else if (!trial.auction!.passed.includes(id)) trial.auction!.passed.push(id);
if (phaseAnyBidWitnesses(trial,getPlayer(trial,id),live).some(witness =>
witness.kind === 'future' && !!phaseBidCompletionRange(live,witness))) ordinary = action;
}
}
if (!ordinary) return null;
const action = {...ordinary}; delete action.phaseBidPromiseEvent; delete action.phaseBidPromiseLot;
return {action:{...action,phaseAnyBidPromiseEvent:live[0].event,phaseAnyBidLot:g.auction.index + 1}};
const native = lot && liveBidPromises(g.bidPromises ?? [],id,lot)[0];
return {action:{...action,...(native ? {bidPromiseEvent:native.event} : {}),
phaseAnyBidPromiseEvent:live[0].event,phaseAnyBidLot:g.auction.index + 1}};
}
const lot = g.richeseAuction;
if (!lot || (lot.method === 'silent' ? Object.hasOwn(lot.sealed,id) : lot.active !== id)) return null;
@@ -19212,10 +19280,10 @@ function bidPromiseCompletion(g: Game, p: Player, promises = g.bidPromises ?? []
function bidTruthAnswers(g: Game, p: Player, claim: BidClaim): ('yes' | 'no' | 'unknown')[] {
const opportunity = bidOpportunity(g);
if (!opportunity || !bidQuestionWindow(g) || claim.turn !== opportunity.turn || claim.lot !== opportunity.lot ||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length ||
!opportunity.eligible.includes(p.id) || opportunity.passed.includes(p.id) || opportunity.bidder === p.id) return [];
return (['yes', 'no'] as const).filter(answer => {
const phases = livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn);
const phases = [...livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn),
...livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn)];
const caps: BidPromise[] = phases.filter(row => !row.answer).map((row,index) => ({
turn:g.turn,lot:opportunity.lot,minimum:row.minimum,event:`phase-cap-${index}`,
source:opportunity.source,player:p.id,asker:row.asker,answer:false,
@@ -19228,8 +19296,11 @@ function bidTruthAnswers(g: Game, p: Player, claim: BidClaim): ('yes' | 'no' | '
const phaseYes = phases.filter(row => row.answer);
const trial = structuredClone(g);
trial.bidPromises = claims;
if (!phaseYes.length || viablePhaseBidWitnesses(trial,getPlayer(trial,p.id),trial.phaseBidPromises ?? []).some(w => w.kind === 'future' &&
!!phaseBidCompletionRange(g.phaseBidPromises ?? [],w))) return true;
const future = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length
? phaseAnyBidWitnesses(trial,getPlayer(trial,p.id),phases)
: viablePhaseBidWitnesses(trial,getPlayer(trial,p.id),phases);
if (!phaseYes.length || future.some(w => w.kind === 'future' &&
!!phaseBidCompletionRange(phases,w))) return true;
const required: BidPromise[] = phaseYes.map((row,index) => ({
turn:g.turn,lot:opportunity.lot,minimum:row.minimum,event:`phase-yes-${index}`,
source:opportunity.source,player:p.id,asker:row.asker,answer:true,
@@ -19254,7 +19325,6 @@ function compileMixedBid(g: Game, p: Player, claim: MixedBidClaim, answer: boole
function mixedBidTruthAnswers(g: Game, p: Player, claim: MixedBidClaim): TruthAnswer[] {
const opportunity = bidOpportunity(g);
if (!opportunity || !mixedBidQuestionWindow(g) || claim.turn !== opportunity.turn || claim.lot !== opportunity.lot ||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length ||
!opportunity.eligible.includes(p.id) || opportunity.passed.includes(p.id) || opportunity.bidder === p.id) return [];
const answers: TruthAnswer[] = [];
for (const answer of [true, false]) {
@@ -19307,7 +19377,10 @@ function reconcileBidPromises(g: Game, voluntary?: { actor: string; action: Acti
if (!promise.answer && same) continue;
const own = voluntary?.actor === promise.player &&
['bid', 'passBid', 'card', 'bribe', 'pledgeAid', 'emperorGift', 'richeseGift', 'richeseBid', 'decision', 'karama', 'specialKarama'].includes(voluntary.action.type);
const possible = same && bidPromiseCompletion(g, getPlayer(g, promise.player), [...no, ...kept, promise]);
const caps: BidPromise[] = same ? livePhaseBidPromises(g.phaseAnyBidPromises ?? [],promise.player,g.turn)
.filter(row => !row.answer).map((row,index) => ({turn:g.turn,lot:opportunity.lot,minimum:row.minimum,
event:`phase-any-reconcile-${index}`,source:opportunity.source,player:promise.player,asker:row.asker,answer:false})) : [];
const possible = same && bidPromiseCompletion(g, getPlayer(g, promise.player), [...no, ...kept, promise,...caps]);
if (promise.answer && !possible) {
requireRule(!own, 'You cannot voluntarily evade your Truthtrance bid answer.');
promise.released = true;
@@ -19327,6 +19400,8 @@ function projectedBidPromises(g: Game, player: string) {
function projectedBidPromiseGuide(g: Game, player: string): { action: Action } | null {
// The phase-wide guide combines both sets of live bounds into one packet.
if (livePhaseBidPromises(g.phaseBidPromises ?? [],player,g.turn).length) return null;
if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],player,g.turn).length)
return projectedPhaseAnyBidGuide(g,player);
const opportunity = bidOpportunity(g);
if (!opportunity || !bidQuestionWindow(g) || g.truthtrance || g.auction?.active !== player) return null;
const promise = liveBidPromises(g.bidPromises ?? [], player, opportunity)[0];
@@ -19347,6 +19422,8 @@ function guardPromisedBid(g: Game, p: Player, action: Action, amount?: number) {
if (amount !== undefined) {
trial.auction!.bid = amount; trial.auction!.bidder = p.id;
trial.auction!.allyPayment = normalBidQuote(g,p,amount,action.allyPayment).allyPayment;
try { trial.bidPromises = recordPromisedBid(trial.bidPromises ?? [],p.id,opportunity,amount); }
catch (error) { if (error instanceof BidPromiseError) throw new RuleError(error.message); throw error; }
} else if (!trial.auction!.passed.includes(p.id)) trial.auction!.passed.push(p.id);
const future = phaseAnyBidWitnesses(trial,getPlayer(trial,p.id),trial.phaseAnyBidPromises ?? [])
.find(witness => witness.kind === 'future' && !!phaseBidCompletionRange(trial.phaseAnyBidPromises ?? [],witness));