Support Advanced early cache bid promises
Verify and publish checkpoint container / container (push) Successful in 11m48s

This commit is contained in:
Quintine committed 2026-11-16 20:34:43 +11:00
1 parent 1a65e69932
commit 225b2174ad
14 files changed
+1071 -22

No files matched your search

+118 -12
View File
@@ -35,7 +35,7 @@ import { RicheseBidPromiseError, richeseBidCompletionRange, richeseBidRequired,
liveRicheseBidPromises, reconcileRicheseBidPromises, finishRicheseBidLot, validateRicheseBidPromises,
type RicheseBidClaim, type RicheseBidPromise, type RicheseBidOpportunity } from './richese-bid-promises';
import { jointRicheseBidCompletionRange } from './joint-richese-bids';
import { EarlyRicheseBidError, earlyRicheseBidAnswerOptions, bindEarlyRicheseBid,
import { EarlyRicheseBidError, earlyRicheseBidModeSupported, earlyRicheseBidAnswerOptions, bindEarlyRicheseBid,
attachEarlyRicheseBids, liveEarlyRicheseBidPromises, reconcileEarlyRicheseBids,
validateEarlyRicheseBidPromises, type EarlyRicheseBidClaim, type EarlyRicheseBidPromise } from './early-richese-bid';
import { quoteJointEarlyRicheseBids } from './joint-early-richese-bids';
@@ -2012,6 +2012,8 @@ export type Game = {
jointOrdinaryPhaseBid?: true;
/** Fresh waiting cache/all-auction answer; absent on older receipts. */
jointEarlyPhaseBid?: true;
/** Fresh Advanced pre-Bidding cache/phase answer and its ledgers. */
advancedEarlyCacheTruth?: true;
resume: NonNullable<Game['pendingNullentropy']>['resume'];
promise:
| { kind: 'shipment'; index: number; value: ShipmentPromise }
@@ -8070,6 +8072,8 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) {
bidPromises:g.bidPromises,mixedBidQuestions:g.mixedBidQuestions} : {}),
...(next.jointEarlyPhaseBid ? {jointEarlyPhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
earlyRicheseBidPromises:g.earlyRicheseBidPromises} : {}),
...(next.advancedEarlyCacheTruth ? {advancedEarlyCacheTruth:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
earlyRicheseBidPromises:g.earlyRicheseBidPromises} : {}),
...(next.record.question.kind === 'mixedRevival' ? {
mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises,
} : {}),
@@ -8153,6 +8157,7 @@ function finishTruthtranceAnswer(g: Game) {
record,
remaining,
...(advancedTruthAuctionSupported(g,record.question.kind) ? {advancedAuctionTruth:true as const} : {}),
...(advancedEarlyCacheTruthSupported(g,record.question.kind) ? {advancedEarlyCacheTruth:true as const} : {}),
...(supportedRicheseTruthLot(g) || advancedTruthAuctionSupported(g,record.question.kind) &&
supportedSaphoRicheseTruthLot(g) ? {richeseLotEvent:g.richeseAuction!.event} : {}),
...(g.richeseAuction && ['phaseAnyBid','richeseBid','mixedRicheseBid'].includes(record.question.kind) &&
@@ -9194,6 +9199,9 @@ function treacheryDiscardIntegrity(g: Game) {
'The consumed Truthtrance does not match its completed answer history.',
);
const remaining = c.remaining;
requireRule(!c.advancedEarlyCacheTruth || c.advancedEarlyCacheTruth === true &&
advancedEarlyCacheTruthSupported(g,record.question.kind),
'The completed Truthtrance no longer matches its original Advanced cache question.');
if (c.jointEarlyPhaseBid) {
const target = record.question.target;
requireRule(c.jointEarlyPhaseBid === true &&
@@ -10013,6 +10021,13 @@ function advancedTruthAuctionSupported(g: Game, kind: TruthQuestion['kind']): bo
return advancedSaphoAuctionSemuta(g) &&
['fact','freeform','bid','mixedBid','phaseBid','phaseAnyBid','richeseBid','mixedRicheseBid'].includes(kind);
}
/** Fresh pre-Bidding Advanced cache questions have their own signed ledgers;
* older saved Truth discards keep their original continuation and signature. */
function advancedEarlyCacheTruthSupported(g: Game, kind: TruthQuestion['kind']): boolean {
return g.semutaAdvancedOrdinaryPreview === true && bareAdvancedClassicSemutaProfile(g) &&
g.status === 'playing' && g.phase >= 0 && g.phase <= 2 && (g.richeseCache?.length ?? 0) > 0 &&
['earlyRicheseBid','phaseAnyBid'].includes(kind);
}
/** Bind a parked native ride to its original remaining Spice Blow sequence. */
function wormDiscardCursor(g: Game): string {
return JSON.stringify([g.turn, g.phase, g.wormRides, g.spiceSequence,
@@ -10091,6 +10106,9 @@ function semutaOfferSupported(
advancedTruthAuctionSupported(g,continuation.record.question.kind) &&
(!g.richeseAuction || supportedSaphoRicheseTruthLot(g) &&
continuation.richeseLotEvent === g.richeseAuction.event);
const advancedEarlyCacheDiscard = continuation.kind === 'truthtranceDiscard' &&
continuation.advancedEarlyCacheTruth === true && continuation.promise === null &&
advancedEarlyCacheTruthSupported(g,continuation.record.question.kind);
const richeseBoxDiscard = supportedRicheseTruthLot(g) && continuation.kind === 'nullentropyDiscard' &&
continuation.auctionBinding?.kind === 'richese';
const richeseDistransDiscard = continuation.kind === 'distransDiscard' &&
@@ -10361,7 +10379,7 @@ function semutaOfferSupported(
continuation.kind === 'nullentropyDiscard' || continuation.kind === 'distransDiscard' ||
continuation.kind === 'residualPoisonDiscard' || continuation.kind === 'choamSaleDiscard' ||
continuation.kind === 'saphoTruthOrderDiscard' && advancedSaphoAuctionSemuta(g) ||
advancedTruthAuctionDiscard ||
advancedTruthAuctionDiscard || advancedEarlyCacheDiscard ||
continuation.kind === 'karamaEmperorShareDiscard' &&
emperorAuctionGiftResumeMatches(g, continuation.use.response, continuation.resume.decision) ||
((continuation.kind === 'choamKulonDiscard' || continuation.kind === 'choamLaLaLaDiscard' ||
@@ -18579,19 +18597,27 @@ function earlyRicheseBidRule<T>(run: () => T): T {
try { return run(); } catch (error) { if (error instanceof EarlyRicheseBidError) throw new RuleError(error.message); throw error; }
}
function earlyRicheseBidWindow(g: Game): boolean {
return bidPromiseModeSupported({ ...g, semutaPreview: undefined }) && !g.kullPreview && !g.advanced &&
return earlyRicheseBidModeSupported(g) &&
g.status === 'playing' && g.phase >= 0 && g.phase <= 2 && !!byFaction(g, 'richese') &&
(g.richeseCache?.length ?? 0) > 0 && !g.response && !g.decision && !g.phaseOpening &&
!g.pendingKarama && !g.pendingTreacheryDiscard;
}
/** A conservative witness uses the respondent's current uncommitted spice;
* it does not assume an ally's future aid or an opponent's future bid. */
function pendingBlackMarketCards(g: Game,p: Player): number {
const lot = g.richeseAuction;
const marketWin = lot?.source === 'blackMarket' && lot.owner !== p.id &&
!p.hand.some(card => card.id === lot.cardId) &&
(lot.outcome?.kind === 'sold' ? lot.outcome.winner === p.id : !lot.outcome &&
(lot.method === 'silent' ? (lot.sealed[p.id] ?? 0) > 0 : lot.bidder === p.id));
return marketWin ? 1 + Number(p.faction === 'harkonnen') : 0;
}
function earlyRicheseBidMaximum(g: Game, p: Player): number {
// A leading ordinary bid may become a real purchase when the other players
// pass. Reserve its physical hand slot, including Harkonnen's bonus draw.
// A leading bid may become a real purchase when the other players pass.
const pendingPurchase = g.auction?.bidder === p.id && !g.currentAuctionSale
? 1 + Number(p.faction === 'harkonnen') : 0;
if (p.hand.length + pendingPurchase >= handLimit(p)) return 0;
const pendingMarket = pendingBlackMarketCards(g,p);
if (p.hand.length + pendingPurchase + pendingMarket >= handLimit(p)) return 0;
const amount = uncommittedSpice(g,p);
return Number.isSafeInteger(amount) ? Math.max(0,amount) : 0;
}
@@ -18696,6 +18722,11 @@ function richeseBidTruthAnswers(g: Game, p: Player, claim: RicheseBidClaim): Tru
if (!richeseBidWindow(g) || !lot || claim.turn !== g.turn || claim.event !== lot.event ||
!lot.eligible.includes(p.id) || lot.acted.includes(p.id) ||
!richeseBidFitsHand(lot.source,lot.owner,p.id,p.hand.length,handLimit(p))) return [];
// A separately asked Black Market bid needs a three-ledger planner before
// it can coexist with an unbound first-cache promise. Do not admit a Yes
// that could reserve the same spice or hand space twice.
if (lot.source === 'blackMarket' &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length) return [];
const base = g.richeseBidPromises ?? [], opportunity = richeseBidOpportunity(g,p);
const context = {turn:g.turn,event:lot.event,player:p.id};
const asker = g.truthtrance?.queue[0]?.player ?? g.players.find(row => row.id !== p.id)?.id ?? g.host;
@@ -19110,6 +19141,34 @@ 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;
}
/** Before the Advanced market closes, quote a possible later ordinary lot
* from the actual cache, deck, public bid and this seat's own commitment.
* Never inspect another player's sealed bid or assume a future refund. */
function phaseAnyMarketOrdinary(g: Game,p: Player): PhaseBidOpportunity | null {
const lot = g.richeseAuction, round = g.richeseBidding;
if (g.phase !== 3 || lot?.source !== 'blackMarket' || !round || round.turn !== g.turn ||
round.stage !== 'lot' || !(g.deck.length || g.discard.length)) return null;
const cards = pendingBlackMarketCards(g,p);
if (p.hand.length + cards >= handLimit(p)) return null;
const ownBid = lot.outcome ? lot.outcome.kind === 'sold' && lot.outcome.winner === p.id :
lot.method === 'silent' ? (lot.sealed[p.id] ?? 0) > 0 : lot.bidder === p.id;
// While offers are still sealed, use only public hand capacities. A sale
// could fill at most one other buyer's hand and reduce the ordinary pool.
const possibleSale = !lot.outcome || lot.outcome.kind === 'sold';
const mayFill = (buyer: Player) => buyer.id !== p.id && buyer.id !== lot.owner &&
!buyer.hand.some(card => card.id === lot.cardId) && buyer.hand.length < handLimit(buyer) &&
buyer.hand.length + 1 + Number(buyer.faction === 'harkonnen') >= handLimit(buyer);
const possibleFullBuyer = lot.outcome?.kind === 'sold'
? mayFill(getPlayer(g,lot.outcome.winner)) : !lot.outcome && g.players.some(mayFill);
const eligible = auctionEligible(g).length;
if (eligible - Number(possibleFullBuyer) - Number(possibleSale) -
Number((g.richeseCache?.length ?? 0) > 0) < 1) return null;
const lockedAid = ownBid ? (g.richeseFunding?.[p.id]?.allyPayment ?? 0) : 0;
const maximum = Math.min(Number.MAX_SAFE_INTEGER,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;
}
/** 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 {
@@ -19197,18 +19256,34 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro
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)) {
if (special && lot?.source === 'blackMarket') {
// The current market bid is distinct from the still-waiting cache.
// Paid seller retention does not add a second card to its owner's hand.
const joint = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase:neutralPhase,cacheMaximum,
ordinary:{opportunity:special,cashAvailable:Math.max(0,uncommittedSpice(g,p)),
aidAvailable:Math.max(0,aidFor(g,p)?.amount ?? 0),freeSlots:Math.max(0,handLimit(p)-p.hand.length),
cacheWinSlots:1+Number(p.faction === 'harkonnen'),winSlots:lot.owner === p.id ? 0 : 1}});
if (joint.separate) result.push({...special,...joint.separate.ordinary});
}
const marketOrdinary = phaseAnyMarketOrdinary(g,p);
for (const opportunity of [...viablePhaseBidWitnesses(g,p,neutralPhase,true),
...(marketOrdinary ? [marketOrdinary] : [])]) {
// 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 freeSlots = Math.max(0,handLimit(owner)-owner.hand.length-pendingCards-pendingBlackMarketCards(source,owner));
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 market = source.richeseAuction;
const ownMarket = market?.source === 'blackMarket' && (market.outcome
? market.outcome.kind === 'sold' && market.outcome.winner === p.id
: market.method === 'silent' ? (market.sealed[p.id] ?? 0) > 0 : market.bidder === p.id);
const marketAid = ownMarket ? (source.richeseFunding?.[p.id]?.allyPayment ?? 0) : 0;
const aid = Math.max(0,(aidFor(source,owner)?.amount ?? 0)-lockedAid-marketAid);
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')}});
@@ -19279,12 +19354,31 @@ function reconcilePhaseAnyBids(g: Game,voluntary?: {actor:string;action:Action})
if (!g.phaseAnyBidPromises?.length || g.truthtrance || g.response || g.decision || g.phaseOpening ||
g.pendingTreacheryDiscard || g.pendingKarama || g.pendingKull || g.pendingRicheseBetrayal) return;
for (const p of g.players) {
const live = livePhaseBidPromises(g.phaseAnyBidPromises,p.id,g.turn);
const live = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn);
if (!live.length) continue;
const change = voluntary?.actor === p.id ? 'voluntary' : 'external';
if (g.phase > 3) g.phaseAnyBidPromises = phaseBidRule(() => finishPhaseBidPhase(g.phaseAnyBidPromises!,p.id,g.turn,change));
else g.phaseAnyBidPromises = phaseBidRule(() => reconcilePhaseBidPromises(g.phaseAnyBidPromises!,p.id,g.turn,
phaseAnyBidWitnesses(g,p,g.phaseAnyBidPromises!),change));
else {
const witnesses = phaseAnyBidWitnesses(g,p,g.phaseAnyBidPromises!);
// A pending market has not yet established its real ordinary-lot
// count. Do not release a still-fundable Yes solely because the
// conservative public-information lower bound cannot prove that count.
const lot = g.richeseAuction;
const deferred = new Set<string>();
if (change === 'external' && lot?.source === 'blackMarket' && !lot.outcome &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length) {
const maximum = Math.min(Number.MAX_SAFE_INTEGER,Math.max(0,p.spice) + Math.max(0,aidFor(g,p)?.amount ?? 0));
const no = live.filter(row => !row.answer);
if (maximum > 0) for (const row of live) if (row.answer &&
!witnesses.some(witness => !!phaseBidCompletionRange([...no,row],witness)) &&
!!phaseBidCompletionRange([...no,row],{turn:g.turn,player:p.id,kind:'future',minimum:1,maximum}))
deferred.add(row.event);
}
const before: PhaseBidPromise[] = g.phaseAnyBidPromises ?? [];
const reconciled: PhaseBidPromise[] = phaseBidRule((): PhaseBidPromise[] =>
reconcilePhaseBidPromises(before,p.id,g.turn,witnesses,change));
g.phaseAnyBidPromises = reconciled.map((row,index) => deferred.has(row.event) ? before[index] : row);
}
}
}
/** One exact native action is shared by both panels, bots and the clock. */
@@ -19347,6 +19441,18 @@ function projectedPhaseAnyBidGuide(g: Game, id: string): {action:Action} | null
if (!lot || (lot.method === 'silent' ? Object.hasOwn(lot.sealed,id) : lot.active !== id)) return null;
if (['onceAround','silent'].includes(lot.method) && liveRicheseBidPromises(g.richeseBidPromises ?? [],
{turn:g.turn,event:lot.event,player:id}).length) return projectedJointRicheseBidGuide(g,id);
if (lot.source === 'blackMarket' && liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],id,g.turn).length) {
const witnesses = phaseAnyBidWitnesses(g,p,live), required = live.some(row => row.answer);
const current = witnesses.find(witness => witness.kind === 'current' && !!phaseBidCompletionRange(live,witness));
const range = current && phaseBidCompletionRange(live,current);
if (required && !range && !witnesses.some(witness => witness.kind === 'future' &&
!!phaseBidCompletionRange(live,witness))) return null;
const amount = required && range ? range.minimum : lot.method === 'silent' ? 0 : null;
const own = uncommittedSpice(g,p) + richeseOwnCommitment(lot,g.richeseFunding ?? {},id);
return {action:{type:'richeseBid',event:lot.event,amount,
allyPayment:amount === null ? 0 : Math.max(0,amount-own),phaseAnyBidPromiseEvent:live[0].event,
phaseAnyBidLotEvent:lot.event}};
}
const required = live.some(row => row.answer), opportunity = phaseAnySpecialOpportunity(g,p);
const range = opportunity && phaseBidCompletionRange(live,opportunity);
if (required && !range) return null;