diff --git a/components/mixed-richese-bid-promises.tsx b/components/mixed-richese-bid-promises.tsx index 4077daac..4db1e8f0 100644 --- a/components/mixed-richese-bid-promises.tsx +++ b/components/mixed-richese-bid-promises.tsx @@ -21,7 +21,12 @@ export function MixedRicheseBidPromises(props: { game: GameView; busy: boolean; !guide || game.richeseBidPromiseGuide !== guide || !action || guide.action !== action || JSON.stringify(action) !== signature || action.type !== 'richeseBid' || action.event !== auction.event || typeof action.richeseBidPromiseId !== 'string') return false; - return own.some(promise => promise.id === action.richeseBidPromiseId && promise.turn === game.turn && + if (action.phaseAnyBidPromiseEvent !== undefined && + (typeof action.phaseAnyBidPromiseEvent !== 'string' || action.phaseAnyBidLotEvent !== auction.event || + !game.phaseAnyBidPromises.some(promise => promise.event === action.phaseAnyBidPromiseEvent && + promise.player === game.me && promise.turn === game.turn && !promise.fulfilled && !promise.released))) return false; + return game.mixedRicheseBidPromises.some(promise => promise.player === game.me && + promise.id === action.richeseBidPromiseId && promise.turn === game.turn && promise.event === auction.event && !promise.fulfilled && !promise.released); }; const canGuide = () => !props.busy && isCurrentGuide(); diff --git a/components/phase-any-bid-promises.tsx b/components/phase-any-bid-promises.tsx index b9a2e7a6..dff6498a 100644 --- a/components/phase-any-bid-promises.tsx +++ b/components/phase-any-bid-promises.tsx @@ -25,6 +25,12 @@ export function PhaseAnyBidGuideButton(props: Props) { typeof action.phaseAnyBidPromiseEvent !== 'string' || !current.phaseAnyBidPromises.some(promise => promise.event === action.phaseAnyBidPromiseEvent && promise.player === actor && promise.turn === turn && !promise.fulfilled && !promise.released)) return false; + if (action.richeseBidPromiseId !== undefined) { + if (action.type !== 'richeseBid' || typeof action.richeseBidPromiseId !== 'string' || !special || + ![...current.richeseBidPromises, ...current.mixedRicheseBidPromises].some(promise => + promise.id === action.richeseBidPromiseId && promise.player === actor && promise.turn === turn && + promise.event === special.event && !promise.fulfilled && !promise.released)) return false; + } if (action.type === 'bid' || action.type === 'passBid') return !!ordinary && current.auction === ordinary && ordinary.active === actor && JSON.stringify([ordinary.bid, ordinary.bidder, ordinary.active, ordinary.remaining]) === ordinarySignature && diff --git a/components/richese-bid-promise-panel.tsx b/components/richese-bid-promise-panel.tsx index 7dd24abb..9b8f6fc1 100644 --- a/components/richese-bid-promise-panel.tsx +++ b/components/richese-bid-promise-panel.tsx @@ -15,7 +15,9 @@ export type RicheseBidPromiseReceipt = { export type RicheseBidPromisePanelProps = { promises: RicheseBidPromiseReceipt[]; guide: { action: Action } | null; - game: { turn: number; richeseAuction: { event: string; method?: 'onceAround' | 'silent' | 'normal' } | null }; + game: { turn: number; me?: string; + phaseAnyBidPromises?: {event: string; player: string; turn: number; fulfilled?: boolean; released?: boolean}[]; + richeseAuction: { event: string; method?: 'onceAround' | 'silent' | 'normal' } | null }; act: (action: Action) => void; busy: boolean; }; @@ -32,6 +34,11 @@ export function RicheseBidPromiseGuide(props: RicheseBidPromisePanelProps) { game.turn === turn && !!auction && game.richeseAuction === auction && typeof auctionEvent === 'string' && auction.event === auctionEvent && typeof id === 'string' && action.type === 'richeseBid' && + (action.phaseAnyBidPromiseEvent === undefined || + typeof action.phaseAnyBidPromiseEvent === 'string' && action.phaseAnyBidLotEvent === auctionEvent && + typeof game.me === 'string' && !!game.phaseAnyBidPromises?.some(promise => + promise.event === action.phaseAnyBidPromiseEvent && promise.player === game.me && promise.turn === turn && + !promise.fulfilled && !promise.released)) && props.promises.some(promise => promise.id === id && promise.turn === turn && promise.event === auctionEvent && !promise.fulfilled && !promise.released); const canAct = () => !props.busy && isCurrent(); diff --git a/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 640f0997..09e83027 100644 --- a/docs/CURRENT_STATUS.md +++ b/docs/CURRENT_STATUS.md @@ -17,6 +17,16 @@ open mode gates. ## Current checkpoint and work +**Joint all-auction and Richese bid answers — 16 November. Prototyped / +Partial.** Supported current Richese Once Around/Silent and all-auction +Truthtrance answers can coexist in either order, including mixed factual +questions. Their shared guide uses the actual bid and funding; a later phase +Yes remains possible only with a separately funded forecast. The local No +ends with its lot, while the phase No lasts through Bidding. Twenty-two related +unit files pass 229 cases. Other commitment +families, optional modules, full games and deployed acceptance remain open. +[Scope](TRUTHTRANCE_BID_PROMISES.md#all-auction-and-current-richese-bids--16-november-2026). + **All-auction phase bid questions — 16 November. Prototyped / Partial.** A separate Truthtrance question can bind an accepted bid across ordinary, Richese cache and Black Market auctions. Human controls and minimal bots use diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index 0cc1ed9e..30a37d50 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,5 +1,12 @@ # Rule decision index +## Joint phase-wide and Richese bid answers — 16 November 2026 + +Current Richese Once Around/Silent and all-auction phase bid answers can share +the same native declaration, with a separately funded later lot when needed. +The forecast and online priority are provisional. +[Scope](TRUTHTRANCE_BID_PROMISES.md#all-auction-and-current-richese-bids--16-november-2026). + ## All-auction phase bid questions — 16 November 2026 A new phase-wide question includes ordinary, Richese cache and Black Market diff --git a/docs/TRUTHTRANCE_BID_PROMISES.md b/docs/TRUTHTRANCE_BID_PROMISES.md index ab9dcab2..8c5f7d77 100644 --- a/docs/TRUTHTRANCE_BID_PROMISES.md +++ b/docs/TRUTHTRANCE_BID_PROMISES.md @@ -1,5 +1,31 @@ # Truthtrance ordinary bid commitments +## All-auction and current Richese bids — 16 November 2026 + +**Prototyped / Partial.** A player may hold both an all-auction phase bid +answer and a current Richese Once Around or Silent bid answer, including a +mixed current-fact question. Both question orders use the same funded native +bid: each No caps the current declaration, and one qualifying bid can satisfy +both Yes answers. The local No ends with its lot; the phase-wide No continues +through Bidding. When a local answer can be fulfilled or declined now and a +separately funded later lot remains, the phase-wide Yes can stay open for that +later bid. The forecast reserves the actual possible purchase and hand slot; +it never relies on another player's sealed bid or an assumed refund. + +The two guides project the same event-bound native action for humans, bots and +the auction clock. A completed opposing raise releases an impossible local +Yes before checking whether the phase-wide answer remains possible. Supported +Semuta claim/pass preserves both bindings and the original question queue. +The existing online forecast and ordering remain provisional under the source +authority below. Early-cache and ordinary-only commitment combinations, other +financial/action commitments, optional modules, complete games and deployed +acceptance remain open. [Runtime cases](../tests/truth-phase-any-richese-joint.test.ts) +use actual questions and auction actions with explicitly staged original +card and unopened setup/Spice order. [Joint-quote rules](../tests/joint-richese-bids.test.ts) +check interval intersections independently. The [shared controls](../tests/truth-phase-any-richese-joint-controls.test.tsx) +exercise both panels and stale callbacks. Twenty-two related unit files pass +229 cases. + ## All-auction phase bid — 16 November 2026 **Prototyped / Partial.** A separate `phaseAnyBid` question asks about one @@ -18,9 +44,9 @@ known later ordinary lot or the mandatory cache following Black Market may preserve a Yes when a player passes or bids less now. Forecasts use currently owned resources and committed funding without assuming future rival bids, income or refunds. They are conservative, and a missing forecast does not -assert a publisher prohibition. Independent live bid-commitment families and -other unsupported financial/action promise combinations do not yet compose -with this question; older ordinary-only answers remain separate. Broader +assert a publisher prohibition. Current Richese bid answers now compose as +described above; early-cache, ordinary-only and other unsupported financial or +action promise combinations remain separate. Broader modules, full games and deployed acceptance remain open. The FAQ and supplied Advanced revision support current-turn questions and diff --git a/game/engine.ts b/game/engine.ts index 4ad599ce..20fd4f97 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -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['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; diff --git a/game/joint-richese-bids.ts b/game/joint-richese-bids.ts new file mode 100644 index 00000000..43214bd5 --- /dev/null +++ b/game/joint-richese-bids.ts @@ -0,0 +1,53 @@ +import { + richeseBidCompletionRange, + RicheseBidPromiseError, + type RicheseBidContext, + type RicheseBidOpportunity, + type RicheseBidPromise, + type RicheseBidRange, +} from './richese-bid-promises'; +import type { PhaseBidPromise } from './turn-bid-promises'; + +export type JointRicheseBidOptions = { + /** A separately proven later auction may satisfy phase-wide Yes answers. + * Phase-wide No answers always constrain the current Richese declaration. */ + includePhaseYes?: boolean; +}; + +/** Represent live phase-wide bounds in one specific Richese lot's native + * interval. These synthetic rows are quote-only: never save or project them. */ +export function richeseBidsWithPhaseBounds( + native: readonly RicheseBidPromise[], + phase: readonly PhaseBidPromise[], + context: RicheseBidContext, + options: JointRicheseBidOptions = {}, +): RicheseBidPromise[] { + if (!Array.isArray(native) || !Array.isArray(phase) || !context || + !Number.isSafeInteger(context.turn) || context.turn < 1 || + typeof context.event !== 'string' || !context.event || context.event.trim() !== context.event || + typeof context.player !== 'string' || !context.player || context.player.trim() !== context.player) + throw new RicheseBidPromiseError('Retain the original bidder, turn and Richese auction event.'); + const used = new Set(native.map(row => row.id)); + const bounds: RicheseBidPromise[] = []; + for (const row of phase) { + if (row.player !== context.player || row.turn !== context.turn || row.fulfilled || row.released || + (row.answer && options.includePhaseYes === false)) continue; + let id = `phase-any:${row.event}`; + while (used.has(id)) id += ':'; + used.add(id); + bounds.push({id,turn:context.turn,event:context.event,player:context.player, + asker:row.asker,minimum:row.minimum,answer:row.answer}); + } + return [...native,...bounds]; +} + +/** The native Richese quote owns funding, hand space and the single + * Once Around/Silent declaration; this helper only intersects obligations. */ +export function jointRicheseBidCompletionRange( + native: readonly RicheseBidPromise[], + phase: readonly PhaseBidPromise[], + opportunity: RicheseBidOpportunity, + options: JointRicheseBidOptions = {}, +): RicheseBidRange | null { + return richeseBidCompletionRange(richeseBidsWithPhaseBounds(native,phase,opportunity,options),opportunity); +} diff --git a/game/reference.ts b/game/reference.ts index ad1b796e..ae5f718d 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -3789,6 +3789,7 @@ export const RULE_TOPICS: RuleTopic[] = [ 'In a quiet Richese Once Around auction, choose Bind a bid in this Once Around lot to bind the respondent’s one remaining bid or pass. A waiting Richese owner cannot promise Yes until an actual bid ensures an owner turn. Current hand space, funds and pledged aid remain required; an opposing raise can release an impossible Yes. Normal special auctions remain outside this prototype.', 'Alternatively choose Bind an ordinary bid this Bidding phase. Yes requires one qualifying accepted ordinary bid after the answer and before Bidding closes; No forbids qualifying later ordinary bids across lots. Earlier bids do not count, and a bid does not promise a win.', 'Choose the separate all-auction phase bid question to include ordinary, Richese cache and Black Market declarations. One accepted qualifying bid fulfills Yes even if it loses; No caps qualifying bids until Bidding closes. Silent zero is a decline. Existing ordinary-only answers retain their original scope. Some combinations with other binding questions are not yet available.', + 'A current Richese Once Around or Silent bid answer can coexist with the all-auction answer. One native declaration may satisfy both; each No caps that declaration, and a phase-wide Yes may instead wait for a separately funded later lot.', 'In a Silent Richese lot the question binds the respondent’s single sealed submission. Zero declines; a positive bid remains hidden until the native simultaneous reveal. Available answers use that bidder’s own funding, without using opponents’ concealed amounts.', 'Before Basic Bidding, ask about a minimum bid in the first actual Richese cache auction of this turn. The answer waits for the real event and does not predict its card or method. Current uncommitted personal funds and hand space supply a conservative Yes witness; cancellation or an opposing action can release an impossible commitment. The Richese owner’s Once Around turn may vanish if everyone else passes.', 'Your waiting cache commitment remains visible until its auction opens or it ends. Once the real lot opens, the ordinary Richese bid guide takes over.', diff --git a/tests/joint-richese-bids.test.ts b/tests/joint-richese-bids.test.ts new file mode 100644 index 00000000..43cade0d --- /dev/null +++ b/tests/joint-richese-bids.test.ts @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {jointRicheseBidCompletionRange,richeseBidsWithPhaseBounds} from '../game/joint-richese-bids'; +import type {RicheseBidOpportunity,RicheseBidPromise} from '../game/richese-bid-promises'; +import type {PhaseBidPromise} from '../game/turn-bid-promises'; + +const opportunity: RicheseBidOpportunity = {turn:2,event:'lot',player:'p',minimum:2,maximum:10}; +const richese = (id:string,minimum:number,answer:boolean): RicheseBidPromise => + ({id,turn:2,event:'lot',player:'p',asker:'a',minimum,answer}); +const phase = (event:string,minimum:number,answer:boolean): PhaseBidPromise => + ({event,turn:2,player:'p',asker:'a',minimum,answer}); + +void test('native and phase-wide answers share one funded Richese declaration', () => { + const native = [richese('r-yes',4,true),richese('r-no',9,false)]; + const all = [phase('p-yes',7,true),phase('p-no',8,false)]; + const before = structuredClone({native,all}); + assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity),{minimum:7,maximum:7}); + assert.deepEqual({native,all},before,'A quote cannot mutate either actual ledger'); + assert.equal(jointRicheseBidCompletionRange(native,[...all,phase('contradiction',7,false)],opportunity),null); +}); + +void test('a separately witnessed future phase Yes does not relax current No caps', () => { + const native = [richese('current-yes',3,true)]; + const all = [phase('later-yes',7,true),phase('all-no',6,false)]; + assert.equal(jointRicheseBidCompletionRange(native,all,opportunity),null); + assert.deepEqual(jointRicheseBidCompletionRange(native,all,opportunity,{includePhaseYes:false}), + {minimum:3,maximum:5}); +}); + +void test('only this bidder’s live phase bounds enter the original event without ID collisions', () => { + const native = [richese('phase-any:live',2,false)]; + const all = [phase('live',5,false),{...phase('other',1,true),player:'q'}, + {...phase('earlier',1,true),turn:1},{...phase('fulfilled',1,true),fulfilled:true}, + {...phase('released',1,true),released:true}]; + const rows = richeseBidsWithPhaseBounds(native,all,opportunity); + assert.equal(rows.length,2); + assert.equal(rows[0],native[0]); + assert.notEqual(rows[1].id,native[0].id); + assert.deepEqual({...rows[1],id:'synthetic'}, + {id:'synthetic',turn:2,event:'lot',player:'p',asker:'a',minimum:5,answer:false}); + assert.deepEqual(jointRicheseBidCompletionRange([],all,opportunity),{minimum:2,maximum:4}); +}); + +void test('a synthetic bound requires the actual bidder, turn and lot event', () => { + assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,event:''})); + assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,player:' p'})); + assert.throws(() => richeseBidsWithPhaseBounds([],[],{...opportunity,turn:0})); +}); diff --git a/tests/truth-phase-any-richese-joint-controls.test.tsx b/tests/truth-phase-any-richese-joint-controls.test.tsx new file mode 100644 index 00000000..8e0ae503 --- /dev/null +++ b/tests/truth-phase-any-richese-joint-controls.test.tsx @@ -0,0 +1,93 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createElement, isValidElement, type ReactElement, type ReactNode } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises'; +import { RicheseBidPromiseGuide, RicheseBidPromisePanel } from '../components/richese-bid-promise-panel'; +import { MixedRicheseBidPromises } from '../components/mixed-richese-bid-promises'; +import { viewGame, type Action, type Game } from '../game/engine'; +import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid'; +import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent'; +import { actTruthtranceRichesePromises as act, passTruthRicheseFreshDiscard, + truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player } from './fixture-truthtrance-richese-promises'; + +type Props = { children?: ReactNode; [key:string]:unknown }; +type Fixture = ReturnType | ReturnType; +type Kind = 'richeseBid' | 'mixedRicheseBid'; +const elements = (node:ReactNode):ReactElement[] => Array.isArray(node) ? node.flatMap(elements) : + !isValidElement(node) ? [] : [node,...elements(node.props.children)]; +function answer(game:Game,f:Fixture,card:string,question:Record) { + let state = act(game,f.asker,{type:'card',card}); + for (let n=0;state.truthtrance?.stage === 'priority' && n !state.truthtrance!.passed.includes(row.id)); assert.ok(actor); + state=act(state,actor.id,{type:'truthPass'}); + } + assert.equal(state.truthtrance?.stage,'ask'); + state=act(state,f.asker,{type:'truthAsk',question}); + return passTruthRicheseFreshDiscard(act(state,f.target,{type:'truthAnswer',answer:'yes'})); +} +/** Real Advanced public start and original cache auction; stage only a second + * original unopened Truth into the asker's hand. The source fixture documents + * its selected unopened deal and Spice order and native scalar rolls. */ +function joint(method:'onceAround'|'silent',kind:Kind) { + const f:Fixture=method === 'onceAround' ? createTruthRicheseBidFixture(true) : createTruthRicheseSilentFixture(true); + let game=structuredClone(f.game); + const at=game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(at >= 0); + const [second]=game.deck.splice(at,1); player(game,f.asker).hand.push(second); + assert.deepEqual(inventory(game),f.originalCards); + if(method === 'onceAround') game=act(game,f.asker,{type:'richeseBid',event:f.lot,amount:null}); + game=answer(game,f,f.truth,{kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:4}); + const question=kind === 'richeseBid' ? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:6} : + {kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[ + {kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},{kind:'action',action:{minimum:6}}, + ]}}; + game=answer(game,f,second.id,question); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.target && row.answer)); + assert.ok(game.richeseBidPromises?.some(row => row.player === f.target && row.answer)); + return {game,f}; +} + +for (const method of ['onceAround','silent'] as const) for (const kind of ['richeseBid','mixedRicheseBid'] as const) void test( + `real Advanced ${method} ${kind} joint controls render and submit one shared native guide`,() => { + const {game,f}=joint(method,kind), view=viewGame(game,f.target), sent:Action[]=[]; + assert.ok(view.phaseAnyBidGuide && view.richeseBidPromiseGuide); + assert.deepEqual(view.phaseAnyBidGuide.action,view.richeseBidPromiseGuide.action); + assert.equal(view.phaseAnyBidGuide.action.amount,6); + const phaseHtml=renderToStaticMarkup(createElement(PhaseAnyBidPromises,{game:view,busy:false,send() {}})); + assert.match(phaseHtml,/Your any-auction bid promises/); + assert.match(phaseHtml,/data-testid="phase-any-bid-guide"/); + const phaseProps={game:view,busy:false,send(action:Action){sent.push(action);}}; + const phaseButton=PhaseAnyBidGuideButton(phaseProps); assert.ok(phaseButton); + const localProps={promises:view.richeseBidPromises,guide:view.richeseBidPromiseGuide,game:view,busy:false, + act(action:Action){sent.push(action);}}; + const mixedProps={game:view,busy:false,send(action:Action){sent.push(action);}}; + const localHtml=kind === 'richeseBid' + ? renderToStaticMarkup(createElement(RicheseBidPromisePanel,localProps)) + : renderToStaticMarkup(createElement(MixedRicheseBidPromises,mixedProps)); + assert.match(localHtml,kind === 'richeseBid' ? /Your (?:Once Around|Silent) bid promises/ : /Your mixed Richese bid promises/); + const localButton=kind === 'richeseBid' ? RicheseBidPromiseGuide(localProps) : + elements(MixedRicheseBidPromises(mixedProps)).find(node => node.props['data-testid'] === 'mixed-richese-bid-promise-guide'); + assert.ok(localButton); + const clickPhase=() => phaseButton.props.onClick(); + const clickLocal=() => (localButton.props.onClick as () => void)(); + clickPhase(); clickLocal(); + assert.deepEqual(sent,[view.phaseAnyBidGuide.action,view.phaseAnyBidGuide.action]); + phaseProps.busy=true; localProps.busy=true; mixedProps.busy=true; + clickPhase(); clickLocal(); assert.equal(sent.length,2); + phaseProps.busy=false; localProps.busy=false; mixedProps.busy=false; + const originalEvent=view.richeseAuction!.event; + view.richeseAuction!.event='stale-lot'; + clickPhase(); clickLocal(); assert.equal(sent.length,2); + view.richeseAuction!.event=originalEvent; + view.phaseAnyBidPromises[0].fulfilled=true; + clickPhase(); clickLocal(); assert.equal(sent.length,2,'A closed phase answer invalidates either shared callback'); + view.phaseAnyBidPromises[0].fulfilled=false; + const localReceipt=kind === 'richeseBid' ? view.richeseBidPromises[0] : view.mixedRicheseBidPromises[0]; + assert.ok(localReceipt); localReceipt.fulfilled=true; + clickPhase(); clickLocal(); assert.equal(sent.length,2,'A closed local answer invalidates either shared callback'); + localReceipt.fulfilled=false; + const applied=act(game,f.target,sent[0]); + assert.ok(applied.phaseAnyBidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.ok(applied.richeseBidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.deepEqual(inventory(applied),f.originalCards); + }); diff --git a/tests/truth-phase-any-richese-joint.test.ts b/tests/truth-phase-any-richese-joint.test.ts new file mode 100644 index 00000000..032b74c6 --- /dev/null +++ b/tests/truth-phase-any-richese-joint.test.ts @@ -0,0 +1,288 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { advanceAuctionClock, synchronizeAuctionClock, viewGame, type Action, type Game } from '../game/engine'; +import { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid'; +import { createTruthRicheseSilentFixture } from './fixture-truth-richese-silent'; +import { actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, + createTruthtranceRichesePromisesFixture as baseFixture, passTruthRicheseFreshDiscard, + truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory, + truthtranceRichesePromisesPlayer as player } from './fixture-truthtrance-richese-promises'; + +type Method = 'onceAround' | 'silent'; +type Kind = 'richeseBid' | 'mixedRicheseBid'; +type Answer = 'yes' | 'no'; +type Fixture = ReturnType | ReturnType; + +function reject(game:Game, actor:string, action:Action) { + const before = structuredClone(game); + assert.throws(() => act(game,actor,action)); + assert.deepEqual(game,before,'A rejected native action keeps its input unchanged'); +} +/** The starting games, sale and native funds are real. To obtain two questions + * in one turn, move the second original Truthtrance from the unopened deck to + * the same asker's hand; the underlying fixture stages its original deal, + * unopened Spice order and native scalar rolls. */ +function source(method:Method, advanced = false) { + const f:Fixture = method === 'silent' ? createTruthRicheseSilentFixture(advanced) : createTruthRicheseBidFixture(advanced); + let game = structuredClone(f.game); + const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); + assert.ok(index >= 0); + const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second); + assert.deepEqual(inventory(game),f.originalCards); + if (method === 'onceAround') game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:null}); + assert.ok(method === 'silent' || game.richeseAuction?.active === f.target); + return {f,game,second:second.id}; +} +function ask(game:Game, f:Fixture, card:string, question:Record, answer:Answer) { + let current = act(game,f.asker,{type:'card',card}); + for (let n = 0; current.truthtrance?.stage === 'priority' && n < current.players.length; n++) { + const actor = current.players.find(row => !current.truthtrance!.passed.includes(row.id)); assert.ok(actor); + current = act(current,actor.id,{type:'truthPass'}); + } + assert.equal(current.truthtrance?.stage,'ask'); + current = act(current,f.asker,{type:'truthAsk',question}); + const view = viewGame(current,f.target); + const options = question.kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : + question.kind === 'richeseBid' ? view.truthRicheseBidAnswers : view.truthMixedRicheseBidAnswers; + assert.ok(options?.includes(answer),`The compatible ${String(question.kind)} ${answer} must be offered`); + return passTruthRicheseFreshDiscard(act(current,f.target,{type:'truthAnswer',answer})); +} +function questions(f:Fixture, game:Game, kind:Kind, phaseAnswer:Answer, _lotAnswer:Answer) { + // Every pair has a joint funded witness: Yes/Yes requires six; Yes/No and + // No/Yes each permit four; No/No permits a two-spice bid or a pass. + const phaseMinimum = phaseAnswer === 'yes' ? 4 : 6; + const lotMinimum = phaseAnswer === 'yes' ? 6 : 4; + const phase = {kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:phaseMinimum}; + const lot = kind === 'richeseBid' + ? {kind,target:f.target,turn:game.turn,event:f.lot,minimum:lotMinimum} + : {kind,target:f.target,turn:game.turn,event:f.lot,mixed:{kind:'and',terms:[ + {kind:'fact',fact:{kind:'spice',compare:'gte',value:10}}, + {kind:'action',action:{minimum:lotMinimum}}, + ]}}; + return {phase,lot,phaseMinimum,lotMinimum}; +} + +for (const method of ['onceAround','silent'] as const) + for (const kind of ['richeseBid','mixedRicheseBid'] as const) + for (const first of ['phase','lot'] as const) + for (const phaseAnswer of ['yes','no'] as const) + for (const lotAnswer of ['yes','no'] as const) void test( + `Basic ${method} ${kind} ${first} first: phase ${phaseAnswer} and lot ${lotAnswer} share native bid`, () => { + const f = source(method), q = questions(f.f,f.game,kind,phaseAnswer,lotAnswer); + const firstQuestion = first === 'phase' ? q.phase : q.lot; + const secondQuestion = first === 'phase' ? q.lot : q.phase; + let game = ask(f.game,f.f,f.f.truth,firstQuestion,first === 'phase' ? phaseAnswer : lotAnswer); + game = ask(game,f.f,f.second,secondQuestion,first === 'phase' ? lotAnswer : phaseAnswer); + const phase = game.phaseAnyBidPromises?.find(row => row.player === f.f.target); assert.ok(phase); + const native = game.richeseBidPromises?.find(row => row.player === f.f.target); assert.ok(native); + assert.equal(phase.answer,phaseAnswer === 'yes'); assert.equal(native.answer,lotAnswer === 'yes'); + const view = viewGame(game,f.f.target), phaseGuide = view.phaseAnyBidGuide?.action; + const lotGuide = view.richeseBidPromiseGuide?.action; + assert.ok(phaseGuide || lotGuide,'The combined answer has a native guide'); + for (const guide of [phaseGuide,lotGuide]) if (guide) { + assert.equal(guide.type,'richeseBid'); + assert.doesNotThrow(() => act(game,f.f.target,guide),'Each offered guide must honor both answers'); + } + for (const difficulty of DIFFICULTIES) { + const bot = viewGame(game,f.f.target); bot.players.find(row => row.id === f.f.target)!.bot = difficulty; + const chosen = botActions(bot)[0]; assert.ok(chosen,difficulty); + assert.equal(chosen.type,'richeseBid'); + assert.doesNotThrow(() => act(game,f.f.target,chosen),difficulty); + } + const packet = phaseGuide ?? lotGuide!; + if (packet.phaseAnyBidPromiseEvent !== undefined) + reject(game,f.f.target,{...packet,phaseAnyBidPromiseEvent:'stale-phase-event'}); + if (packet.richeseBidPromiseId !== undefined) + reject(game,f.f.target,{...packet,richeseBidPromiseId:'stale-lot-promise'}); + if (lotAnswer === 'yes') + reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:method === 'silent' ? 0 : null}); + if (phaseAnswer === 'no') + reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:q.phaseMinimum,allyPayment:0}); + if (lotAnswer === 'no') + reject(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount:q.lotMinimum,allyPayment:0}); + const amount = lotAnswer === 'yes' ? q.lotMinimum : phaseAnswer === 'yes' ? q.phaseMinimum : 2; + const before = player(game,f.f.target).spice; + game = act(game,f.f.target,{type:'richeseBid',event:f.f.lot,amount,allyPayment:0}); + assert.equal(player(game,f.f.target).spice,before,'A bid is not its eventual invoice'); + assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === phase.event)?.fulfilled,phaseAnswer === 'yes'); + const accepted = game.richeseBidPromises?.find(row => row.id === native.id); assert.ok(accepted?.fulfilled); + if (method === 'silent') { + assert.equal(viewGame(game,f.f.target).richeseAuction?.ownBid,amount); + assert.equal(viewGame(game,f.f.owner).richeseAuction?.revealedBids,null); + assert.equal(viewGame(game,f.f.owner).richeseAuction?.ownBid,null); + game = act(game,f.f.asker,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0}); + game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0}); + } else if (game.richeseAuction?.event === f.f.lot && game.richeseAuction.active === f.f.owner) { + game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:null}); + } + assert.ok(player(game,f.f.target).hand.some(card => card.id === f.f.card)); + assert.equal(player(game,f.f.target).spice,before-amount); + assert.deepEqual(inventory(game),f.f.originalCards); + }); + +for (const method of ['onceAround','silent'] as const) for (const first of ['phase','lot'] as const) void test( + `Advanced ${method} ${first} first preserves two independently answered Yes requirements`, () => { + const f = source(method,true), q = questions(f.f,f.game,'richeseBid','yes','yes'); + let game = ask(f.game,f.f,f.f.truth,first === 'phase' ? q.phase : q.lot,'yes'); + game = ask(game,f.f,f.second,first === 'phase' ? q.lot : q.phase,'yes'); + const before = player(game,f.f.target).spice; + const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action; + assert.ok(guide); assert.equal(guide.type,'richeseBid'); assert.equal(guide.amount,6); + game = act(game,f.f.target,guide); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.f.target && row.fulfilled)); + assert.ok(game.richeseBidPromises?.some(row => row.player === f.f.target && row.fulfilled)); + assert.equal(player(game,f.f.target).spice,before); + if (method === 'silent') { + assert.equal(viewGame(game,f.f.owner).richeseAuction?.revealedBids,null); + game = act(game,f.f.asker,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0}); + game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:0,allyPayment:0}); + } else if (game.richeseAuction?.event === f.f.lot && game.richeseAuction.active === f.f.owner) + game = act(game,f.f.owner,{type:'richeseBid',event:f.f.lot,amount:null}); + assert.ok(player(game,f.f.target).hand.some(card => card.id === f.f.card)); + assert.equal(player(game,f.f.target).spice,before-6); + assert.deepEqual(inventory(game),f.f.originalCards); + }); + +for (const method of ['onceAround','silent'] as const) for (const first of ['phase','lot'] as const) void test( + `${method} live lot No permits an all-auction Yes in the actual later ordinary auction, ${first} first`, () => { + const f = source(method), phase = {kind:'phaseAnyBid',target:f.f.target,turn:f.game.turn,minimum:6}; + const lot = {kind:'richeseBid',target:f.f.target,turn:f.game.turn,event:f.f.lot,minimum:4}; + let game = ask(f.game,f.f,f.f.truth,first === 'phase' ? phase : lot,first === 'phase' ? 'yes' : 'no'); + game = ask(game,f.f,f.second,first === 'phase' ? lot : phase,first === 'phase' ? 'no' : 'yes'); + const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action; + assert.ok(guide); + assert.doesNotThrow(() => act(game,f.f.target,guide)); + if (typeof guide.amount === 'number') assert.ok(guide.amount < 4,'The current-lot No is never bypassed'); + game = act(game,f.f.target,guide); + const promise = game.phaseAnyBidPromises?.find(row => row.player === f.f.target); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.f.target, + [], {position:'first',method}); + const later = viewGame(game,f.f.target).phaseAnyBidGuide; assert.ok(later); + assert.equal(later.action.type,'bid'); assert.ok(Number(later.action.amount) >= 6); + game = act(game,f.f.target,later.action); + assert.ok(game.phaseAnyBidPromises?.some(row => row.event === promise.event && row.fulfilled)); + assert.deepEqual(inventory(game),f.f.originalCards); + }); + +void test('legacy ordinary-only No does not restrict the physical Richese cache bid', () => { + const f = baseFixture({advanced:false}); + let game = act(structuredClone(f.earlySource),f.asker,f.declarationStep.action); + game = advance(game,state => state.truthtrance?.stage === 'ask'); + game = act(game,f.asker,{type:'truthAsk',question:{kind:'phaseBid',target:f.emperor,turn:game.turn,minimum:4}}); + game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'no'})); + game = advance(game,state => clean(state) && !!state.richeseAuction && !state.richeseAuction.outcome, + [], {position:'first',method:'silent'}); + const lot = game.richeseAuction!; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0}); + const legacy = game.phaseBidPromises?.find(row => row.player === f.emperor); assert.ok(legacy); + assert.equal(legacy.answer,false); assert.equal(!!legacy.fulfilled,false); assert.equal(!!legacy.released,false); + assert.deepEqual(inventory(game),f.originalCards); +}); + +for (const advanced of [false,true]) for (const method of ['onceAround','silent'] as const) + for (const first of ['phase','lot'] as const) for (const claim of [false,true]) void test( + `${advanced ? 'Advanced' : 'Basic'} ${method} ${first} first: second queued Truth offers Semuta ${claim ? 'claim' : 'pass'}`, () => { + const f = source(method,advanced), cache = f.game.richeseCache!; + const at = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(at >= 0); + // Additional conserved supplement: move the original Semuta from the + // cache to Richese's hand; the native offered cache card is untouched. + const [semuta] = cache.splice(at,1); player(f.game,f.f.owner).hand.push(semuta); + assert.deepEqual(inventory(f.game),f.f.originalCards); + const lot = structuredClone(f.game.richeseAuction), funding = structuredClone(f.game.richeseFunding); + const q = questions(f.f,f.game,'richeseBid','yes','yes'); + let game = act(f.game,f.f.asker,{type:'card',card:f.f.truth,cards:[f.second]}); + for (let n = 0; game.truthtrance?.stage === 'priority' && n < game.players.length; n++) { + const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor); + game = act(game,actor.id,{type:'truthPass'}); + } + assert.equal(game.truthtrance?.stage,'ask'); + assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.f.truth,f.second]); + game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? q.phase : q.lot}); + game = act(game,f.f.target,{type:'truthAnswer',answer:'yes'}); + assert.equal(game.pendingTreacheryDiscard?.continuation.kind,'truthtranceDiscard'); + game = passTruthRicheseFreshDiscard(game); + assert.equal(game.truthtrance?.stage,'ask'); + assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.second]); + game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? q.lot : q.phase}); + game = act(game,f.f.target,{type:'truthAnswer',answer:'yes'}); + const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction); + assert.equal(pending.continuation.kind,'truthtranceDiscard'); + assert.equal(pending.batch.entries[0].card.id,f.second); + assert.equal(viewGame(game,f.f.owner).semutaReaction?.canCommit,true); + const phase = structuredClone(game.phaseAnyBidPromises), native = structuredClone(game.richeseBidPromises); + assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding); + game = claim ? act(game,f.f.owner,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game); + assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null); + assert.deepEqual(game.phaseAnyBidPromises,phase); assert.deepEqual(game.richeseBidPromises,native); + assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding); + assert.equal(player(game,f.f.owner).hand.some(card => card.id === f.second),claim); + assert.equal(game.discard.some(card => card.id === semuta.id),claim); + const guide = viewGame(game,f.f.target).phaseAnyBidGuide?.action ?? viewGame(game,f.f.target).richeseBidPromiseGuide?.action; + assert.ok(guide); assert.equal(guide.amount,6); + game = act(game,f.f.target,guide); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.f.target && row.fulfilled)); + assert.ok(game.richeseBidPromises?.some(row => row.player === f.f.target && row.fulfilled)); + assert.deepEqual(inventory(game),f.f.originalCards); + }); + +void test('an opposing raise releases the impossible local Yes but preserves and later fulfills phase-wide Yes', () => { + const f = createTruthRicheseBidFixture(false); + let game = structuredClone(f.game); + // The original second Truth is moved from the unopened deck, without + // injecting a bid, wallet, promise or later auction state. + const index = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(index >= 0); + const [second] = game.deck.splice(index,1); player(game,f.asker).hand.push(second); + assert.deepEqual(inventory(game),f.originalCards); + assert.equal(game.richeseAuction?.active,f.asker); + game = ask(game,f,f.truth,{kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:4},'yes'); + game = ask(game,f,second.id,{kind:'richeseBid',target:f.target,turn:game.turn,event:f.lot,minimum:4},'yes'); + const lot = game.richeseBidPromises?.find(row => row.player === f.target); assert.ok(lot); + const phase = game.phaseAnyBidPromises?.find(row => row.player === f.target); assert.ok(phase); + game = act(game,f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0}); + assert.equal(game.richeseAuction?.active,f.target); + const released = game.richeseBidPromises?.find(row => row.id === lot.id); assert.ok(released); + assert.equal(!!released.released,true); assert.equal(!!released.fulfilled,false); + const retained = game.phaseAnyBidPromises?.find(row => row.event === phase.event); assert.ok(retained); + assert.equal(!!retained.released,false); assert.equal(!!retained.fulfilled,false); + game = act(game,f.target,{type:'richeseBid',event:f.lot,amount:null}); + game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.target, + [], {position:'first',method:'onceAround'}); + const guide = viewGame(game,f.target).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'bid'); assert.ok(Number(guide.action.amount) >= 4); + game = act(game,f.target,guide.action); + assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phase.event && row.fulfilled)); + assert.ok(game.richeseBidPromises?.some(row => row.id === lot.id && row.released)); + assert.deepEqual(inventory(game),f.originalCards); +}); + +/** Genuine last-position cache, preceded by a real ordinary purchase. The + * undealt second Truth is the only physical custody supplement. */ +void test('final Once Around cache clock executes one bid satisfying both live Yes answers', () => { + const f = baseFixture({advanced:false}), options = {position:'last' as const,method:'onceAround' as const}; + let game = advance(structuredClone(f.earlySource),state => clean(state) && !!state.auction,[],options); + const secondIndex = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); assert.ok(secondIndex >= 0); + const [second] = game.deck.splice(secondIndex,1); player(game,f.asker).hand.push(second); + assert.deepEqual(inventory(game),f.originalCards); + game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0}); + game = advance(game,state => clean(state) && !!state.richeseAuction && !state.richeseAuction.outcome,[],options); + const lot = game.richeseAuction!; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0}); + assert.equal(game.richeseAuction?.active,f.asker); + const sf = {game,asker:f.asker,target:f.richese,owner:f.richese,lot:lot.event,card:lot.cardId,truth:f.truth, + original:f,originalCards:f.originalCards,staging:f.staging}; + game = ask(game,sf,f.truth,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:3},'yes'); + game = ask(game,sf,second.id,{kind:'richeseBid',target:f.richese,turn:game.turn,event:lot.event,minimum:4},'yes'); + game = act(game,f.asker,{type:'richeseBid',event:lot.event,amount:null}); + assert.equal(game.richeseAuction?.active,f.richese); + reject(game,f.richese,{type:'richeseBid',event:lot.event,amount:null}); + const guide = viewGame(game,f.richese).phaseAnyBidGuide?.action ?? viewGame(game,f.richese).richeseBidPromiseGuide?.action; + assert.ok(guide); assert.equal(guide.amount,4); + const armed = synchronizeAuctionClock(game,1_000,'joint-richese:0'); + const expired = advanceAuctionClock(armed,11_000,'joint-richese:0'); + assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.richese && row.fulfilled)); + assert.ok(expired.richeseBidPromises?.some(row => row.player === f.richese && row.fulfilled)); + assert.deepEqual(inventory(expired),f.originalCards); +});