Compose early cache and phase-wide bid commitments
Verify and publish checkpoint container / container (push) Successful in 11m28s

This commit is contained in:
Quintine committed 2026-11-16 20:01:53 +11:00
1 parent 05f7fc8f20
commit 3ede19c90a
12 files changed
+990 -22

No files matched your search

+108 -14
View File
@@ -38,6 +38,7 @@ import { jointRicheseBidCompletionRange } from './joint-richese-bids';
import { EarlyRicheseBidError, earlyRicheseBidAnswerOptions, bindEarlyRicheseBid,
attachEarlyRicheseBids, liveEarlyRicheseBidPromises, reconcileEarlyRicheseBids,
validateEarlyRicheseBidPromises, type EarlyRicheseBidClaim, type EarlyRicheseBidPromise } from './early-richese-bid';
import { quoteJointEarlyRicheseBids } from './joint-early-richese-bids';
import { AuctionClockError, AUCTION_BID_MS, quoteAuctionClock, viewAuctionClock,
type AuctionClock, type AuctionClockView } from './auction-clock';
import { PrintedCardPlayError, printedCardPlayCount, recordPrintedCardPlay,
@@ -2009,6 +2010,8 @@ export type Game = {
jointRichesePhaseBid?: true;
/** Fresh joint ordinary/all-auction answer; absent on older receipts. */
jointOrdinaryPhaseBid?: true;
/** Fresh waiting cache/all-auction answer; absent on older receipts. */
jointEarlyPhaseBid?: true;
resume: NonNullable<Game['pendingNullentropy']>['resume'];
promise:
| { kind: 'shipment'; index: number; value: ShipmentPromise }
@@ -8065,6 +8068,8 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) {
richeseBidPromises:g.richeseBidPromises,mixedRicheseBidQuestions:g.mixedRicheseBidQuestions} : {}),
...(next.jointOrdinaryPhaseBid ? {jointOrdinaryPhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
bidPromises:g.bidPromises,mixedBidQuestions:g.mixedBidQuestions} : {}),
...(next.jointEarlyPhaseBid ? {jointEarlyPhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
earlyRicheseBidPromises:g.earlyRicheseBidPromises} : {}),
...(next.record.question.kind === 'mixedRevival' ? {
mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises,
} : {}),
@@ -8158,6 +8163,10 @@ function finishTruthtranceAnswer(g: Game) {
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length &&
liveBidPromises(g.bidPromises ?? [],record.question.target,bidOpportunity(g)!).length
? {jointOrdinaryPhaseBid:true as const} : {}),
...(['phaseAnyBid','earlyRicheseBid'].includes(record.question.kind) &&
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],record.question.target,g.turn).length
? {jointEarlyPhaseBid:true as const} : {}),
resume,
promise,
parentSignature: '',
@@ -9185,6 +9194,14 @@ function treacheryDiscardIntegrity(g: Game) {
'The consumed Truthtrance does not match its completed answer history.',
);
const remaining = c.remaining;
if (c.jointEarlyPhaseBid) {
const target = record.question.target;
requireRule(c.jointEarlyPhaseBid === true &&
['phaseAnyBid','earlyRicheseBid'].includes(record.question.kind) &&
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],target,g.turn).length > 0 &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],target,g.turn).length > 0,
'The completed Truthtrance lost its waiting cache and phase bid commitments.');
}
if (c.jointOrdinaryPhaseBid) {
const lot = bidOpportunity(g), target = record.question.target;
requireRule(c.jointOrdinaryPhaseBid === true && !!lot &&
@@ -18580,11 +18597,13 @@ function earlyRicheseBidMaximum(g: Game, p: Player): number {
}
function earlyRicheseBidTruthAnswers(g: Game,p: Player,claim: EarlyRicheseBidClaim): TruthAnswer[] {
if (!earlyRicheseBidWindow(g) || claim.turn !== g.turn) return [];
if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) return ['unknown'];
if (richeseBidOtherPromises(g,p)) return ['unknown'];
if (richeseBidOtherPromises(g,p,{allowPhaseAny:true})) return ['unknown'];
const asker = g.truthtrance?.queue[0]?.player ?? g.players.find(row => row.id !== p.id)?.id ?? g.host;
const answers = earlyRicheseBidRule(() => earlyRicheseBidAnswerOptions(g.earlyRicheseBidPromises ?? [],claim,p.id,asker,
earlyRicheseBidMaximum(g,p))).map(answer => answer ? 'yes' as const : 'no' as const);
earlyRicheseBidMaximum(g,p))).filter(answer => {
const early = [...(g.earlyRicheseBidPromises ?? []),{...claim,id:'candidate',player:p.id,asker,answer}];
return earlyPhaseAnyPossible(g,p,early,g.phaseAnyBidPromises ?? []);
}).map(answer => answer ? 'yes' as const : 'no' as const);
return answers.includes('yes') ? answers : [...answers,'unknown'];
}
function bindEarlyRicheseBidTruth(g: Game,p: Player,claim: EarlyRicheseBidClaim,answer: boolean,asker: string): void {
@@ -18611,8 +18630,10 @@ function reconcileEarlyRicheseTruth(g: Game,voluntary?: {actor:string;action:Act
(g.richeseCache?.length ?? 0) > 0 &&
(g.phase < 3 || !round || round.turn !== turn || !round.cacheCanceled && round.stage !== 'complete');
const before: EarlyRicheseBidPromise[] = g.earlyRicheseBidPromises ?? [];
const phaseCaps = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,turn).filter(row => !row.answer);
const maximum = Math.min(earlyRicheseBidMaximum(g,p),...phaseCaps.map(row => row.minimum - 1));
g.earlyRicheseBidPromises = earlyRicheseBidRule((): EarlyRicheseBidPromise[] => reconcileEarlyRicheseBids(before,p.id,turn,{
cachePending,canBid:p.hand.length < handLimit(p),maximum:earlyRicheseBidMaximum(g,p),
cachePending,canBid:p.hand.length < handLimit(p),maximum,
change:voluntary?.actor === p.id ? 'voluntary' : 'external',
}));
if (g.earlyRicheseBidPromises.some((row,index) => row.player === p.id && row.released && !before[index]?.released))
@@ -18654,7 +18675,7 @@ function richeseBidOtherPromises(g: Game, p: Player, options?: {allowPhaseAny?:
function richeseBidCompatibleLaterPromises(g: Game,p: Player): boolean {
const lot = g.richeseAuction;
if (!lot) return !liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).some(row => row.answer) ||
!richeseBidOtherPromises(g,p);
!richeseBidOtherPromises(g,p,{allowPhaseAny:true});
const context = {turn:g.turn,event:lot.event,player:p.id};
return !richeseBidRequired(g.richeseBidPromises ?? [],context) || !richeseBidOtherPromises(g,p);
}
@@ -18791,8 +18812,8 @@ function phaseBidHonorsTurnActions(g: Game, p: Player, lot: BidOpportunity, acti
/** Current witnesses must also satisfy the existing native funding and
* current-lot commitments. Future bidding with other financial/transport
* promises awaits their combined planner; do not invent those resources. */
function phaseBidFuturePlannerUnsupported(g: Game, p: Player): boolean {
return liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).some(row => row.answer) ||
function phaseBidFuturePlannerUnsupported(g: Game, p: Player, allowEarlyCache = false): boolean {
return !allowEarlyCache && 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,!!g.advanced || g.expansions.length > 0) ||
liveRevivalPromises(g.revivalPromises ?? [],p.id,g.turn).some(row => row.answer) ||
@@ -18849,10 +18870,10 @@ function phaseBidRevivalShipmentWitness(g: Game, p: Player, promises: readonly P
}
return null;
}
function viablePhaseBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPromise[]) {
function viablePhaseBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPromise[], allowEarlyCache = false) {
const lot = bidOpportunity(g);
const live = livePhaseBidPromises(promises,p.id,g.turn);
const otherCommitments = phaseBidFuturePlannerUnsupported(g,p);
const otherCommitments = phaseBidFuturePlannerUnsupported(g,p,allowEarlyCache);
return phaseBidWitnesses(g,p).flatMap(witness => {
if (witness.kind === 'future') {
if (otherCommitments) {
@@ -18964,6 +18985,8 @@ function reconcilePhaseBids(g: Game, voluntary?: {actor:string;action:Action}) {
phaseBidIntegrity(g);
// An external raise can release an impossible local Yes while leaving a
// phase-wide Yes achievable in a later lot; resolve the narrower scope first.
if (g.phaseAnyBidPromises?.length && g.earlyRicheseBidPromises?.length)
reconcileEarlyRicheseTruth(g,voluntary);
if (g.phaseAnyBidPromises?.length && g.richeseBidPromises?.length) reconcileRicheseBids(g,voluntary);
reconcilePhaseAnyBids(g,voluntary);
if (!g.phaseBidPromises?.length || g.truthtrance || g.response || g.decision || g.phaseOpening ||
@@ -19040,13 +19063,10 @@ function phaseAnyBidConflict(g: Game, p: Player): boolean {
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 &&
(!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) ||
(g.charityPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) ||
hasBribePromises(g,p.id,true) ||
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length > 0 ||
phaseBidFuturePlannerUnsupported(g,p);
phaseBidFuturePlannerUnsupported(g,p,true);
}
/** A completed Black Market offer is followed by Richese's real cache lot.
* Reserve this player's possibly winning card and its own committed funds;
@@ -19078,6 +19098,27 @@ function phaseAnyLastCache(g: Game,p: Player): PhaseBidOpportunity | null {
return Number.isSafeInteger(maximum) && maximum > 0
? {turn:g.turn,player:p.id,kind:'future',minimum:1,maximum} : null;
}
/** The waiting first cache is physical but its method and order are not yet
* known. Reserve only owned spice and never assume another player's bid. */
function pendingEarlyCacheMaximum(g: Game,p: Player): number {
const round = g.richeseBidding;
const pending = g.status === 'playing' && g.phase <= 3 && !!byFaction(g,'richese') &&
(g.richeseCache?.length ?? 0) > 0 && g.richeseAuction?.source !== 'cache' &&
(g.phase < 3 || !round || round.turn !== g.turn || !round.cacheCanceled && round.stage !== 'complete');
return pending ? earlyRicheseBidMaximum(g,p) : 0;
}
function earlyPhaseAnyPossible(g: Game,p: Player,early: readonly EarlyRicheseBidPromise[],
phase: readonly PhaseBidPromise[]): boolean {
const trial = {...g,earlyRicheseBidPromises:[...early]};
const cache = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase,
cacheMaximum:pendingEarlyCacheMaximum(g,p)});
if (cache.earlyRequired && !cache.cache) return false;
const lot = bidOpportunity(g);
if (!cache.phaseRequired && cache.earlyRequired && lot && bidRequired(g.bidPromises ?? [],p.id,lot))
return phaseAnyBidWitnesses(trial,p,phase).some(witness => witness.kind === 'future');
return !cache.phaseRequired || phaseAnyBidWitnesses(trial,p,phase)
.some(witness => !!phaseBidCompletionRange(phase,witness));
}
/** 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[],
@@ -19117,6 +19158,52 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro
return [...current,...jointRicheseFutureWitnesses(g,p,promises,native,opportunity)];
}
}
const early = liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn);
if (early.length) {
const cacheMaximum = pendingEarlyCacheMaximum(g,p);
const phase = livePhaseBidPromises(promises,p.id,g.turn);
const ordinaryLot = bidOpportunity(g);
let afterLocal = g;
if (ordinaryLot && bidRequired(g.bidPromises ?? [],p.id,ordinaryLot)) {
const caps: BidPromise[] = phase.filter(row => !row.answer).map((row,index) => ({
turn:g.turn,lot:ordinaryLot.lot,minimum:row.minimum,event:`early-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') return [];
afterLocal = structuredClone(g);
afterLocal.auction!.bid = Number(action.amount); afterLocal.auction!.bidder = p.id;
afterLocal.auction!.allyPayment = Number(action.allyPayment ?? 0);
afterLocal.bidPromises = recordPromisedBid(afterLocal.bidPromises ?? [],p.id,ordinaryLot,Number(action.amount));
}
const quote = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase,
cacheMaximum:pendingEarlyCacheMaximum(afterLocal,getPlayer(afterLocal,p.id))});
if (quote.earlyRequired && !quote.cache) return [];
const result: PhaseBidOpportunity[] = quote.cache ?
[{turn:g.turn,player:p.id,kind:'future',...quote.cache}] : [];
// Quote each ordinary route with a minimal phase Yes so reconciliation can
// release individual impossible answers rather than discarding them all.
const positive = phase.find(row => row.answer);
if (!positive) return result;
const neutralPhase = [...phase.filter(row => !row.answer),{...positive,minimum:1}];
for (const opportunity of viablePhaseBidWitnesses(g,p,neutralPhase,true)) {
// Later ordinary witnesses follow any required local purchase; current
// witnesses are that purchase and must not reserve it twice.
const source = opportunity.kind === 'future' ? afterLocal : g;
const owner = getPlayer(source,p.id);
const pendingCards = source.auction?.bidder === p.id && !source.currentAuctionSale
? 1 + Number(p.faction === 'harkonnen') : 0;
const freeSlots = Math.max(0,handLimit(owner)-owner.hand.length-pendingCards);
const cash = Math.max(0,uncommittedSpice(source,owner));
const lockedAid = source.auction?.bidder === p.id && !source.currentAuctionSale
? (source.auction.allyPayment ?? 0) : 0;
const aid = Math.max(0,(aidFor(source,owner)?.amount ?? 0)-lockedAid);
const joint = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase:neutralPhase,cacheMaximum,
ordinary:{opportunity,cashAvailable:cash,aidAvailable:aid,freeSlots,
cacheWinSlots:1+Number(p.faction === 'harkonnen')}});
if (joint.separate) result.push({...opportunity,...joint.separate.ordinary});
}
return result;
}
const futureCache = phaseAnyFutureCache(g,p);
let lastCache = phaseAnyLastCache(g,p);
const ordinaryLot = bidOpportunity(g);
@@ -19134,8 +19221,13 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro
}
}
const ordinary = viablePhaseBidWitnesses(g,p,promises);
// Before Bidding the physically held Richese cache is itself an auction,
// even when its replacement leaves no ordinary cards to be sold.
const beforeBiddingCache = g.phase < 3 ? pendingEarlyCacheMaximum(g,p) : 0;
return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),
...(lastCache ? [lastCache] : []),...ordinary];
...(lastCache ? [lastCache] : []),
...(beforeBiddingCache > 0 ? [{turn:g.turn,player:p.id,kind:'future' as const,
minimum:1,maximum:beforeBiddingCache}] : []),...ordinary];
}
function richesePhaseJointPossible(g: Game,p: Player,phase: readonly PhaseBidPromise[]): boolean {
const lot = g.richeseAuction;
@@ -19152,6 +19244,8 @@ function phaseAnyBidTruthAnswers(g: Game, p: Player, claim: PhaseBidClaim): Trut
return (['yes','no'] as const).filter(answer => {
const all: PhaseBidPromise[] = [...(g.phaseAnyBidPromises ?? []),
{...claim,event:'candidate',player:p.id,asker,answer:answer === 'yes'}];
if (liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length)
return earlyPhaseAnyPossible(g,p,g.earlyRicheseBidPromises ?? [],all);
if (g.richeseAuction && liveRicheseBidPromises(g.richeseBidPromises ?? [],
{turn:g.turn,event:g.richeseAuction.event,player:p.id}).length)
return richesePhaseJointPossible(g,p,all);