Compose market, early cache and phase bid promises
Verify and publish checkpoint container / container (push) Successful in 12m4s

This commit is contained in:
Quintine committed 2026-11-16 20:51:03 +11:00
1 parent 225b2174ad
commit 6a30fdf376
16 files changed
+1183 -21

No files matched your search

+137 -7
View File
@@ -39,6 +39,7 @@ import { EarlyRicheseBidError, earlyRicheseBidModeSupported, earlyRicheseBidAnsw
attachEarlyRicheseBids, liveEarlyRicheseBidPromises, reconcileEarlyRicheseBids,
validateEarlyRicheseBidPromises, type EarlyRicheseBidClaim, type EarlyRicheseBidPromise } from './early-richese-bid';
import { quoteJointEarlyRicheseBids } from './joint-early-richese-bids';
import { quoteJointMarketEarlyBids } from './joint-market-early-bids';
import { AuctionClockError, AUCTION_BID_MS, quoteAuctionClock, viewAuctionClock,
type AuctionClock, type AuctionClockView } from './auction-clock';
import { PrintedCardPlayError, printedCardPlayCount, recordPrintedCardPlay,
@@ -2014,6 +2015,8 @@ export type Game = {
jointEarlyPhaseBid?: true;
/** Fresh Advanced pre-Bidding cache/phase answer and its ledgers. */
advancedEarlyCacheTruth?: true;
/** Fresh current market answer and waiting early-cache receipt. */
jointMarketEarlyBid?: true;
resume: NonNullable<Game['pendingNullentropy']>['resume'];
promise:
| { kind: 'shipment'; index: number; value: ShipmentPromise }
@@ -8074,6 +8077,9 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) {
earlyRicheseBidPromises:g.earlyRicheseBidPromises} : {}),
...(next.advancedEarlyCacheTruth ? {advancedEarlyCacheTruth:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
earlyRicheseBidPromises:g.earlyRicheseBidPromises} : {}),
...(next.jointMarketEarlyBid ? {jointMarketEarlyBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
earlyRicheseBidPromises:g.earlyRicheseBidPromises,richeseBidPromises:g.richeseBidPromises,
mixedRicheseBidQuestions:g.mixedRicheseBidQuestions} : {}),
...(next.record.question.kind === 'mixedRevival' ? {
mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises,
} : {}),
@@ -8172,6 +8178,12 @@ function finishTruthtranceAnswer(g: Game) {
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],record.question.target,g.turn).length
? {jointEarlyPhaseBid:true as const} : {}),
...(g.richeseAuction?.source === 'blackMarket' &&
['phaseAnyBid','richeseBid','mixedRicheseBid'].includes(record.question.kind) &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],record.question.target,g.turn).length &&
(record.question.kind === 'mixedRicheseBid' ||
liveRicheseBidPromises(g.richeseBidPromises ?? [],{turn:g.turn,event:g.richeseAuction.event,
player:record.question.target}).length) ? {jointMarketEarlyBid:true as const} : {}),
resume,
promise,
parentSignature: '',
@@ -9199,6 +9211,17 @@ function treacheryDiscardIntegrity(g: Game) {
'The consumed Truthtrance does not match its completed answer history.',
);
const remaining = c.remaining;
if (c.jointMarketEarlyBid) {
const lot = g.richeseAuction, target = record.question.target;
requireRule(c.jointMarketEarlyBid === true && lot?.source === 'blackMarket' &&
['phaseAnyBid','richeseBid','mixedRicheseBid'].includes(record.question.kind) &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],target,g.turn).length > 0 &&
(liveRicheseBidPromises(g.richeseBidPromises ?? [],{turn:g.turn,event:lot.event,player:target}).length > 0 ||
record.question.kind === 'mixedRicheseBid' && (g.mixedRicheseBidQuestions ?? []).some(row =>
row.turn === g.turn && row.event === lot.event && row.player === target && row.asker === record.asker &&
row.answer === (record.answer === 'yes') && !row.binding)),
'The completed Truthtrance lost its original market and early cache commitments.');
}
requireRule(!c.advancedEarlyCacheTruth || c.advancedEarlyCacheTruth === true &&
advancedEarlyCacheTruthSupported(g,record.question.kind),
'The completed Truthtrance no longer matches its original Advanced cache question.');
@@ -18722,11 +18745,6 @@ 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;
@@ -18735,6 +18753,9 @@ function richeseBidTruthAnswers(g: Game, p: Player, claim: RicheseBidClaim): Tru
const all = [...base,candidate];
if (answer === 'yes' && richeseBidOtherPromises(g,p,{allowPhaseAny:true})) return false;
const phase = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn);
if (lot.source === 'blackMarket' &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length)
return marketEarlyPossible(g,p,all,phase);
if (phase.length) return richesePhaseJointPossible({...g,richeseBidPromises:all},p,phase);
return !richeseBidRequired(all,context) || !!opportunity && !!richeseBidCompletionRange(all,opportunity);
});
@@ -18808,9 +18829,18 @@ function reconcileRicheseBids(g: Game,voluntary?: {actor:string;action:Action})
if (g.turn !== row.turn || !lot || lot.event !== row.event || lot.outcome)
g.richeseBidPromises = richeseBidRule(() => finishRicheseBidLot(g.richeseBidPromises!,context,change));
else {
const opportunity = richeseBidOpportunity(g,getPlayer(g,row.player));
const owner = getPlayer(g,row.player);
const opportunity = richeseBidOpportunity(g,owner);
const caps = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],row.player,g.turn).filter(item => !item.answer);
const maximum = opportunity ? caps.reduce((value,item) => Math.min(value,item.minimum-1),opportunity.maximum) : 0;
let maximum = opportunity ? caps.reduce((value,item) => Math.min(value,item.minimum-1),opportunity.maximum) : 0;
if (lot.source === 'blackMarket' &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],row.player,g.turn).length) {
// Quote the common funded ceiling independently of Yes minima, so
// an external change can release only the impossible higher answers.
const local = liveRicheseBidPromises(g.richeseBidPromises ?? [],context)
.filter(item => !item.answer);
maximum = Math.min(maximum,marketEarlyQuote(g,owner,local,caps)?.market?.maximum ?? 0);
}
const adjusted = opportunity && maximum >= opportunity.minimum ? {...opportunity,maximum} : null;
g.richeseBidPromises = richeseBidRule(() => reconcileRicheseBidPromises(g.richeseBidPromises!,context,adjusted,change));
}
@@ -18822,6 +18852,8 @@ function projectedRicheseBidGuide(g: Game, player: string): {action:Action} | nu
g.truthtrance || !richeseBidWindow(g)) return null;
const context = {turn:g.turn,event:lot.event,player}, live = liveRicheseBidPromises(g.richeseBidPromises ?? [],context);
if (!live.length) return null;
if (lot.source === 'blackMarket' && liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],player,g.turn).length)
return projectedMarketEarlyGuide(g,player);
if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],player,g.turn).length)
return projectedJointRicheseBidGuide(g,player);
if (!richeseBidRequired(live,context)) return {action:{type:'richeseBid',event:lot.event,amount:lot.method === 'silent' ? 0 : null,allyPayment:0,richeseBidPromiseId:live[0].id}};
@@ -19181,6 +19213,10 @@ function pendingEarlyCacheMaximum(g: Game,p: Player): number {
function earlyPhaseAnyPossible(g: Game,p: Player,early: readonly EarlyRicheseBidPromise[],
phase: readonly PhaseBidPromise[]): boolean {
const trial = {...g,earlyRicheseBidPromises:[...early]};
const market = g.richeseAuction;
const native = market?.source === 'blackMarket'
? liveRicheseBidPromises(g.richeseBidPromises ?? [],{turn:g.turn,event:market.event,player:p.id}) : [];
if (native.length) return marketEarlyPossible(trial,p,native,phase);
const cache = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase,
cacheMaximum:pendingEarlyCacheMaximum(g,p)});
if (cache.earlyRequired && !cache.cache) return false;
@@ -19190,6 +19226,63 @@ function earlyPhaseAnyPossible(g: Game,p: Player,early: readonly EarlyRicheseBid
return !cache.phaseRequired || phaseAnyBidWitnesses(trial,p,phase)
.some(witness => !!phaseBidCompletionRange(phase,witness));
}
/** Quote a real current market declaration while retaining the first cache. */
function marketEarlyQuote(g: Game,p: Player,native: readonly RicheseBidPromise[],phase: readonly PhaseBidPromise[]) {
const lot = g.richeseAuction;
if (!lot || lot.source !== 'blackMarket') return null;
return quoteJointMarketEarlyBids({context:{turn:g.turn,event:lot.event,player:p.id},native,
early:g.earlyRicheseBidPromises ?? [],phase,opportunity:richeseBidOpportunity(g,p),
cashAvailable:Math.max(0,uncommittedSpice(g,p)+richeseOwnCommitment(lot,g.richeseFunding ?? {},p.id)),
aidAvailable:Math.max(0,aidFor(g,p)?.amount ?? 0),cacheMaximum:pendingEarlyCacheMaximum(g,p),
freeSlots:Math.max(0,handLimit(p)-p.hand.length),marketEntrySlots:lot.owner === p.id ? 0 : 1,
marketWinSlots:lot.owner === p.id ? 0 : 1+Number(p.faction === 'harkonnen')});
}
/** The minimum native market declaration is materialized on a detached
* state before a later cache or ordinary lot is counted. */
function marketEarlyWitnesses(g: Game,p: Player,native: readonly RicheseBidPromise[],
phase: readonly PhaseBidPromise[]): PhaseBidOpportunity[] {
const lot = g.richeseAuction, quote = marketEarlyQuote(g,p,native,phase);
if (!lot || !quote || quote.nativeRequired && !quote.market || !quote.nativeRequired && !quote.canPass) return [];
const result: PhaseBidOpportunity[] = quote.market ? [{turn:g.turn,player:p.id,kind:'current',
minimum:quote.market.minimum,maximum:quote.market.maximum}] : [];
const declarations = quote.nativeRequired ? [quote.market!,...(quote.marketForCache ? [quote.marketForCache] : [])] : [null];
for (const declaration of declarations) {
const trial = structuredClone(g), pending = trial.richeseAuction!;
trial.truthtrance = null;
const amount = declaration ? declaration.minimum : lot.method === 'silent' ? 0 : null;
if (!pending.acted.includes(p.id)) pending.acted.push(p.id);
if (pending.method === 'silent') pending.sealed[p.id] = amount ?? 0;
else if (amount === null) { if (!pending.passed.includes(p.id)) pending.passed.push(p.id); }
else { pending.bid = amount; pending.bidder = p.id; }
if (amount !== null && amount > 0) (trial.richeseFunding ??= {})[p.id] = {
amount,allyPayment:declaration!.allyPayment,donor:declaration!.allyPayment ? p.ally : null};
const owner = getPlayer(trial,p.id), early = trial.earlyRicheseBidPromises ?? [];
const cacheMaximum = pendingEarlyCacheMaximum(trial,owner);
const cache = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase,cacheMaximum});
if (cache.cache) result.push({turn:g.turn,player:p.id,kind:'future',...cache.cache});
const positive = livePhaseBidPromises(phase,p.id,g.turn).find(row => row.answer);
const later = positive && phaseAnyMarketOrdinary(trial,owner);
if (later && positive) {
const neutral = [...livePhaseBidPromises(phase,p.id,g.turn).filter(row => !row.answer),{...positive,minimum:1}];
const locked = declaration?.allyPayment ?? 0;
const joint = quoteJointEarlyRicheseBids({player:p.id,turn:g.turn,early,phase:neutral,cacheMaximum,
ordinary:{opportunity:later,cashAvailable:Math.max(0,uncommittedSpice(trial,owner)),
aidAvailable:Math.max(0,(aidFor(trial,owner)?.amount ?? 0)-locked),
freeSlots:Math.max(0,handLimit(owner)-owner.hand.length-pendingBlackMarketCards(trial,owner)),
cacheWinSlots:1+Number(owner.faction === 'harkonnen')}});
if (joint.separate) result.push({...later,...joint.separate.ordinary});
}
}
return result;
}
function marketEarlyPossible(g: Game,p: Player,native: readonly RicheseBidPromise[],
phase: readonly PhaseBidPromise[]): boolean {
const quote = marketEarlyQuote(g,p,native,phase);
if (!quote) return false;
if (quote.nativeRequired ? !quote.market : !quote.canPass) return false;
return !quote.phaseRequired || marketEarlyWitnesses(g,p,native,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[],
@@ -19223,6 +19316,9 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro
const context = {turn:g.turn,event:lot.event,player:p.id};
const native = liveRicheseBidPromises(g.richeseBidPromises ?? [],context);
if (native.length) {
if (lot.source === 'blackMarket' &&
liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length)
return marketEarlyWitnesses(g,p,native,promises);
const opportunity = richeseBidOpportunity(g,p);
const range = opportunity && jointRicheseBidCompletionRange(native,promises,opportunity,{includePhaseYes:false});
const current: PhaseBidOpportunity[] = special && range ? [{...special,...range}] : [];
@@ -19382,6 +19478,31 @@ function reconcilePhaseAnyBids(g: Game,voluntary?: {actor:string;action:Action})
}
}
/** One exact native action is shared by both panels, bots and the clock. */
function projectedMarketEarlyGuide(g: Game,id: string): {action:Action} | null {
const lot = g.richeseAuction, p = getPlayer(g,id);
if (!lot || lot.source !== 'blackMarket' || g.truthtrance || !richeseBidWindow(g) ||
(lot.method === 'silent' ? Object.hasOwn(lot.sealed,id) : lot.active !== id)) return null;
const context = {turn:g.turn,event:lot.event,player:id};
const native = liveRicheseBidPromises(g.richeseBidPromises ?? [],context);
const early = liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],id,g.turn);
const phase = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],id,g.turn);
if (!native.length || !early.length) return null;
const quote = marketEarlyQuote(g,p,native,phase);
if (!quote) return null;
let bid = quote.phaseRequired ? quote.marketForPhase : null;
if (!bid && quote.nativeRequired) {
if (!quote.market) return null;
bid = quote.phaseRequired ? quote.marketForCache ?? quote.market : quote.market;
}
if (quote.phaseRequired && !quote.marketForPhase && !marketEarlyWitnesses(g,p,native,phase)
.some(witness => witness.kind === 'future' && !!phaseBidCompletionRange(phase,witness))) return null;
if (!bid && !quote.canPass) return null;
return {action:{type:'richeseBid',event:lot.event,
amount:bid ? bid.minimum : lot.method === 'silent' ? 0 : null,
allyPayment:bid?.allyPayment ?? 0,richeseBidPromiseId:native[0].id,
earlyRicheseBidPromiseId:early[0].id,
...(phase.length ? {phaseAnyBidPromiseEvent:phase[0].event,phaseAnyBidLotEvent:lot.event} : {})}};
}
function projectedJointRicheseBidGuide(g: Game,id: string): {action:Action} | null {
const lot = g.richeseAuction, p = getPlayer(g,id);
if (!lot || g.truthtrance || !richeseBidWindow(g) ||
@@ -19390,6 +19511,8 @@ function projectedJointRicheseBidGuide(g: Game,id: string): {action:Action} | nu
const native = liveRicheseBidPromises(g.richeseBidPromises ?? [],context);
const phase = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],id,g.turn);
if (!native.length || !phase.length) return null;
if (lot.source === 'blackMarket' && liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],id,g.turn).length)
return projectedMarketEarlyGuide(g,id);
const opportunity = richeseBidOpportunity(g,p);
const current = opportunity && jointRicheseBidCompletionRange(native,phase,opportunity);
const nativeRequired = richeseBidRequired(native,context), phaseRequired = phase.some(row => row.answer);
@@ -45053,6 +45176,13 @@ function applyActionWithInitiator(state: Game, id: string, action: Action, initi
Object.keys(guide.action).every(key => action[key] === guide.action[key]),
'This Richese bid guide is stale or belongs to another lot.');
}
if (action.earlyRicheseBidPromiseId !== undefined) {
requireRule(action.type === 'richeseBid' && state.richeseAuction?.source === 'blackMarket' &&
typeof action.earlyRicheseBidPromiseId === 'string' && action.richeseBidPromiseId !== undefined &&
liveEarlyRicheseBidPromises(state.earlyRicheseBidPromises ?? [],id,state.turn)
.some(row => row.id === action.earlyRicheseBidPromiseId),
'This early cache bid guide is stale or belongs to another player.');
}
let g = applyActionInner(state, id, action, 'live', initiator);
if (state.pendingPublicDealSettlement && !g.bureaucratPayments?.pending) {
const frame = state.pendingPublicDealSettlement;