Compose phase-wide and Richese bid commitments
Verify and publish checkpoint container / container (push) Successful in 11m13s
Verify and publish checkpoint container / container (push) Successful in 11m13s
This commit is contained in:
1 parent
38f1684e03
commit
9e020ccd64
12 files changed
+664
-13
No files matched your search
+115
-8
@@ -34,6 +34,7 @@ import { createSaphoArrivalOrder, validateSaphoArrivalOrder, quoteSaphoArrivalOr
|
||||
import { RicheseBidPromiseError, richeseBidCompletionRange, richeseBidRequired, recordRicheseBid,
|
||||
liveRicheseBidPromises, reconcileRicheseBidPromises, finishRicheseBidLot, validateRicheseBidPromises,
|
||||
type RicheseBidClaim, type RicheseBidPromise, type RicheseBidOpportunity } from './richese-bid-promises';
|
||||
import { jointRicheseBidCompletionRange } from './joint-richese-bids';
|
||||
import { EarlyRicheseBidError, earlyRicheseBidAnswerOptions, bindEarlyRicheseBid,
|
||||
attachEarlyRicheseBids, liveEarlyRicheseBidPromises, reconcileEarlyRicheseBids,
|
||||
validateEarlyRicheseBidPromises, type EarlyRicheseBidClaim, type EarlyRicheseBidPromise } from './early-richese-bid';
|
||||
@@ -2002,6 +2003,8 @@ export type Game = {
|
||||
richeseLotEvent?: string;
|
||||
/** Fresh Advanced auction answer with its exact native bid ledgers. */
|
||||
advancedAuctionTruth?: true;
|
||||
/** Fresh joint Richese/all-auction answer; absent on older receipts. */
|
||||
jointRichesePhaseBid?: true;
|
||||
resume: NonNullable<Game['pendingNullentropy']>['resume'];
|
||||
promise:
|
||||
| { kind: 'shipment'; index: number; value: ShipmentPromise }
|
||||
@@ -8053,6 +8056,8 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) {
|
||||
mixedRicheseBidQuestions: g.mixedRicheseBidQuestions, richeseBidPromises: g.richeseBidPromises,
|
||||
} : {}),
|
||||
...(next.record.question.kind === 'phaseAnyBid' ? {phaseAnyBidPromises:g.phaseAnyBidPromises} : {}),
|
||||
...(next.jointRichesePhaseBid ? {jointRichesePhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises,
|
||||
richeseBidPromises:g.richeseBidPromises,mixedRicheseBidQuestions:g.mixedRicheseBidQuestions} : {}),
|
||||
...(next.record.question.kind === 'mixedRevival' ? {
|
||||
mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises,
|
||||
} : {}),
|
||||
@@ -8138,6 +8143,10 @@ function finishTruthtranceAnswer(g: Game) {
|
||||
...(advancedTruthAuctionSupported(g,record.question.kind) ? {advancedAuctionTruth: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) &&
|
||||
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} : {}),
|
||||
resume,
|
||||
promise,
|
||||
parentSignature: '',
|
||||
@@ -9165,6 +9174,14 @@ function treacheryDiscardIntegrity(g: Game) {
|
||||
'The consumed Truthtrance does not match its completed answer history.',
|
||||
);
|
||||
const remaining = c.remaining;
|
||||
if (c.jointRichesePhaseBid) {
|
||||
const lot = g.richeseAuction, target = record.question.target;
|
||||
requireRule(c.jointRichesePhaseBid === true && !!lot &&
|
||||
['phaseAnyBid','richeseBid','mixedRicheseBid'].includes(record.question.kind) &&
|
||||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],target,g.turn).length > 0 &&
|
||||
liveRicheseBidPromises(g.richeseBidPromises ?? [],{turn:g.turn,event:lot.event,player:target}).length > 0,
|
||||
'The completed Truthtrance lost its joint auction commitments.');
|
||||
}
|
||||
requireRule(!c.advancedAuctionTruth || c.advancedAuctionTruth === true &&
|
||||
advancedTruthAuctionSupported(g,record.question.kind),
|
||||
'The completed Truthtrance no longer matches its original Advanced auction.');
|
||||
@@ -18599,14 +18616,14 @@ function richeseBidOpportunity(g: Game, p: Player): RicheseBidOpportunity | null
|
||||
if (!Number.isSafeInteger(max) || max < minimum) return null;
|
||||
return {turn:g.turn,event:lot.event,player:p.id,minimum,maximum:max};
|
||||
}
|
||||
function richeseBidOtherPromises(g: Game, p: Player): boolean {
|
||||
function richeseBidOtherPromises(g: Game, p: Player, options?: {allowPhaseAny?: boolean}): boolean {
|
||||
return liveShipmentPromises(g.shipmentPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
hasMovementPromises(g,p.id,true) || 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).some(row => row.answer) ||
|
||||
hasBribePromises(g,p.id,true) || liveTurnActionPromises(g.turnActionPromises ?? [],p.id,g.turn).length > 0 ||
|
||||
livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn).some(row => row.answer) ||
|
||||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).some(row => row.answer);
|
||||
!options?.allowPhaseAny && livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).some(row => row.answer);
|
||||
}
|
||||
/** Other financial/action answers need a joint planner before they can
|
||||
* coexist with a live Once Around Yes. Reject the unsupported combination at
|
||||
@@ -18621,7 +18638,6 @@ function richeseBidCompatibleLaterPromises(g: Game,p: Player): boolean {
|
||||
function richeseBidTruthAnswers(g: Game, p: Player, claim: RicheseBidClaim): TruthAnswer[] {
|
||||
const lot = g.richeseAuction;
|
||||
if (!richeseBidWindow(g) || !lot || claim.turn !== g.turn || claim.event !== lot.event ||
|
||||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length ||
|
||||
!lot.eligible.includes(p.id) || lot.acted.includes(p.id) ||
|
||||
!richeseBidFitsHand(lot.source,lot.owner,p.id,p.hand.length,handLimit(p))) return [];
|
||||
const base = g.richeseBidPromises ?? [], opportunity = richeseBidOpportunity(g,p);
|
||||
@@ -18630,7 +18646,9 @@ function richeseBidTruthAnswers(g: Game, p: Player, claim: RicheseBidClaim): Tru
|
||||
return (['yes','no'] as const).filter(answer => {
|
||||
const candidate: RicheseBidPromise = {...claim,id:'candidate',player:p.id,asker,answer:answer === 'yes'};
|
||||
const all = [...base,candidate];
|
||||
if (answer === 'yes' && richeseBidOtherPromises(g,p)) return false;
|
||||
if (answer === 'yes' && richeseBidOtherPromises(g,p,{allowPhaseAny:true})) return false;
|
||||
const phase = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn);
|
||||
if (phase.length) return richesePhaseJointPossible({...g,richeseBidPromises:all},p,phase);
|
||||
return !richeseBidRequired(all,context) || !!opportunity && !!richeseBidCompletionRange(all,opportunity);
|
||||
});
|
||||
}
|
||||
@@ -18648,7 +18666,6 @@ function compileMixedRicheseBid(g: Game, p: Player, claim: MixedRicheseBidClaim,
|
||||
function mixedRicheseBidTruthAnswers(g: Game, p: Player, claim: MixedRicheseBidClaim): TruthAnswer[] {
|
||||
const lot = g.richeseAuction;
|
||||
if (!richeseBidWindow(g) || !lot || claim.turn !== g.turn || claim.event !== lot.event ||
|
||||
livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length ||
|
||||
!lot.eligible.includes(p.id) || lot.acted.includes(p.id) ||
|
||||
!richeseBidFitsHand(lot.source,lot.owner,p.id,p.hand.length,handLimit(p))) return [];
|
||||
const answers: TruthAnswer[] = [];
|
||||
@@ -18703,8 +18720,13 @@ function reconcileRicheseBids(g: Game,voluntary?: {actor:string;action:Action})
|
||||
g.earlyRicheseBidPromises?.some(early => early.id === row.id && early.boundEvent === lot.event)) continue;
|
||||
if (g.turn !== row.turn || !lot || lot.event !== row.event || lot.outcome)
|
||||
g.richeseBidPromises = richeseBidRule(() => finishRicheseBidLot(g.richeseBidPromises!,context,change));
|
||||
else g.richeseBidPromises = richeseBidRule(() => reconcileRicheseBidPromises(g.richeseBidPromises!,context,
|
||||
richeseBidOpportunity(g,getPlayer(g,row.player)),change));
|
||||
else {
|
||||
const opportunity = richeseBidOpportunity(g,getPlayer(g,row.player));
|
||||
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;
|
||||
const adjusted = opportunity && maximum >= opportunity.minimum ? {...opportunity,maximum} : null;
|
||||
g.richeseBidPromises = richeseBidRule(() => reconcileRicheseBidPromises(g.richeseBidPromises!,context,adjusted,change));
|
||||
}
|
||||
}
|
||||
}
|
||||
function projectedRicheseBidGuide(g: Game, player: string): {action:Action} | null {
|
||||
@@ -18713,6 +18735,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 (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}};
|
||||
const opportunity = richeseBidOpportunity(g,p), range = opportunity && richeseBidCompletionRange(live,opportunity);
|
||||
if (!range) return null;
|
||||
@@ -18915,6 +18939,9 @@ function phaseBidIntegrity(g: Game) {
|
||||
}
|
||||
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.richeseBidPromises?.length) reconcileRicheseBids(g,voluntary);
|
||||
reconcilePhaseAnyBids(g,voluntary);
|
||||
if (!g.phaseBidPromises?.length || g.truthtrance || g.response || g.decision || g.phaseOpening ||
|
||||
g.pendingTreacheryDiscard || g.pendingKarama || g.pendingKull || g.pendingRicheseBetrayal) return;
|
||||
@@ -18988,7 +19015,8 @@ function phaseAnyBidWindow(g: Game): boolean {
|
||||
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) ||
|
||||
(g.richeseBidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) ||
|
||||
(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) ||
|
||||
@@ -19011,18 +19039,67 @@ 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;
|
||||
}
|
||||
/** 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[],
|
||||
native: readonly RicheseBidPromise[], opportunity: RicheseBidOpportunity | null): PhaseBidOpportunity[] {
|
||||
const lot = g.richeseAuction;
|
||||
if (!lot || !['onceAround','silent'].includes(lot.method)) return [];
|
||||
const context = {turn:g.turn,event:lot.event,player:p.id};
|
||||
const required = richeseBidRequired(native,context);
|
||||
const local = opportunity && jointRicheseBidCompletionRange(native,phase,opportunity,{includePhaseYes:false});
|
||||
if (required && !local) return [];
|
||||
const amount = required ? local!.minimum : lot.method === 'silent' ? 0 : null;
|
||||
const trial = structuredClone(g), pending = trial.richeseAuction!;
|
||||
trial.truthtrance = 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) {
|
||||
const own = uncommittedSpice(g,p) + richeseOwnCommitment(lot,g.richeseFunding ?? {},p.id);
|
||||
const allyPayment = Math.max(0,amount-own);
|
||||
(trial.richeseFunding ??= {})[p.id] = {amount,allyPayment,donor:allyPayment ? p.ally : null};
|
||||
}
|
||||
const owner = getPlayer(trial,p.id), cache = phaseAnyFutureCache(trial,owner);
|
||||
const ordinary = viablePhaseBidWitnesses(trial,owner,phase).filter(row => row.kind === 'future');
|
||||
return [...(cache ? [cache] : []),...ordinary];
|
||||
}
|
||||
function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPromise[]): PhaseBidOpportunity[] {
|
||||
const special = phaseAnySpecialOpportunity(g,p);
|
||||
const lot = g.richeseAuction;
|
||||
if (lot && ['onceAround','silent'].includes(lot.method)) {
|
||||
const context = {turn:g.turn,event:lot.event,player:p.id};
|
||||
const native = liveRicheseBidPromises(g.richeseBidPromises ?? [],context);
|
||||
if (native.length) {
|
||||
const opportunity = richeseBidOpportunity(g,p);
|
||||
const range = opportunity && jointRicheseBidCompletionRange(native,promises,opportunity,{includePhaseYes:false});
|
||||
const current: PhaseBidOpportunity[] = special && range ? [{...special,...range}] : [];
|
||||
return [...current,...jointRicheseFutureWitnesses(g,p,promises,native,opportunity)];
|
||||
}
|
||||
}
|
||||
const futureCache = phaseAnyFutureCache(g,p);
|
||||
const ordinary = viablePhaseBidWitnesses(g,p,promises);
|
||||
return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),...ordinary];
|
||||
}
|
||||
function richesePhaseJointPossible(g: Game,p: Player,phase: readonly PhaseBidPromise[]): boolean {
|
||||
const lot = g.richeseAuction;
|
||||
if (!lot) return false;
|
||||
const context = {turn:g.turn,event:lot.event,player:p.id};
|
||||
const nativeRequired = richeseBidRequired(g.richeseBidPromises ?? [],context);
|
||||
const phaseRequired = livePhaseBidPromises(phase,p.id,g.turn).some(row => row.answer);
|
||||
return !nativeRequired && !phaseRequired || phaseAnyBidWitnesses(g,p,phase)
|
||||
.some(witness => !!phaseBidCompletionRange(phase,witness));
|
||||
}
|
||||
function phaseAnyBidTruthAnswers(g: Game, p: Player, claim: PhaseBidClaim): TruthAnswer[] {
|
||||
if (!phaseAnyBidWindow(g) || claim.turn !== g.turn || phaseAnyBidConflict(g,p)) return [];
|
||||
const asker = g.truthtrance?.queue[0]?.player ?? g.players.find(row => row.id !== p.id)?.id ?? g.host;
|
||||
return (['yes','no'] as const).filter(answer => {
|
||||
const all: PhaseBidPromise[] = [...(g.phaseAnyBidPromises ?? []),
|
||||
{...claim,event:'candidate',player:p.id,asker,answer:answer === 'yes'}];
|
||||
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) ||
|
||||
phaseAnyBidWitnesses(g,p,all).some(witness => !!phaseBidCompletionRange(all,witness));
|
||||
});
|
||||
@@ -19048,6 +19125,34 @@ function reconcilePhaseAnyBids(g: Game,voluntary?: {actor:string;action:Action})
|
||||
phaseAnyBidWitnesses(g,p,g.phaseAnyBidPromises!),change));
|
||||
}
|
||||
}
|
||||
/** One exact native action is shared by both panels, bots and the clock. */
|
||||
function projectedJointRicheseBidGuide(g: Game,id: string): {action:Action} | null {
|
||||
const lot = g.richeseAuction, p = getPlayer(g,id);
|
||||
if (!lot || 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 phase = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],id,g.turn);
|
||||
if (!native.length || !phase.length) return null;
|
||||
const opportunity = richeseBidOpportunity(g,p);
|
||||
const current = opportunity && jointRicheseBidCompletionRange(native,phase,opportunity);
|
||||
const nativeRequired = richeseBidRequired(native,context), phaseRequired = phase.some(row => row.answer);
|
||||
let amount: number | null = lot.method === 'silent' ? 0 : null;
|
||||
if (nativeRequired || phaseRequired) {
|
||||
if (current) amount = current.minimum;
|
||||
else {
|
||||
const future = jointRicheseFutureWitnesses(g,p,phase,native,opportunity)
|
||||
.some(witness => !!phaseBidCompletionRange(phase,witness));
|
||||
if (!future || !phaseRequired) return null;
|
||||
const local = opportunity && jointRicheseBidCompletionRange(native,phase,opportunity,{includePhaseYes:false});
|
||||
if (nativeRequired) { if (!local) return null; amount = local.minimum; }
|
||||
}
|
||||
}
|
||||
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),
|
||||
richeseBidPromiseId:native[0].id,phaseAnyBidPromiseEvent:phase[0].event,phaseAnyBidLotEvent:lot.event}};
|
||||
}
|
||||
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;
|
||||
@@ -19059,6 +19164,8 @@ function projectedPhaseAnyBidGuide(g: Game, id: string): {action:Action} | null
|
||||
}
|
||||
const lot = g.richeseAuction;
|
||||
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);
|
||||
const required = live.some(row => row.answer), opportunity = phaseAnySpecialOpportunity(g,p);
|
||||
const range = opportunity && phaseBidCompletionRange(live,opportunity);
|
||||
if (required && !range) return null;
|
||||
|
||||
Reference in new issue
Block a user