diff --git a/components/bid-promises.tsx b/components/bid-promises.tsx index 3d937bbd..737e7b10 100644 --- a/components/bid-promises.tsx +++ b/components/bid-promises.tsx @@ -24,6 +24,10 @@ export function BidPromiseGuideButton(props: BidPromiseProps) { promise.turn === turn && promise.lot === number && !promise.fulfilled && !promise.released) || current.mixedBidPromises.some(promise => promise.event === event && promise.player === actor && promise.turn === turn && promise.lot === number && !promise.fulfilled && !promise.released)) && + (action.phaseAnyBidPromiseEvent === undefined || + (typeof action.phaseAnyBidPromiseEvent === 'string' && action.phaseAnyBidLot === number && + current.phaseAnyBidPromises.some(promise => promise.event === action.phaseAnyBidPromiseEvent && + promise.player === actor && promise.turn === turn && !promise.fulfilled && !promise.released))) && !!me && !me.autopilot && !current.truthtrance && !current.response && !current.decision && !current.phaseOpening && !current.automaticContinuationPending && !current.roomControl?.paused && !current.roomControl?.closed; }; diff --git a/components/phase-any-bid-promises.tsx b/components/phase-any-bid-promises.tsx index dff6498a..c4c47dbc 100644 --- a/components/phase-any-bid-promises.tsx +++ b/components/phase-any-bid-promises.tsx @@ -31,6 +31,14 @@ export function PhaseAnyBidGuideButton(props: Props) { promise.id === action.richeseBidPromiseId && promise.player === actor && promise.turn === turn && promise.event === special.event && !promise.fulfilled && !promise.released)) return false; } + if (action.bidPromiseEvent !== undefined) { + if ((action.type !== 'bid' && action.type !== 'passBid') || typeof action.bidPromiseEvent !== 'string' || + typeof action.phaseAnyBidLot !== 'number' || current.bidPromiseLot?.turn !== turn || + current.bidPromiseLot.lot !== action.phaseAnyBidLot || + ![...current.bidPromises, ...current.mixedBidPromises].some(promise => + promise.event === action.bidPromiseEvent && promise.player === actor && promise.turn === turn && + promise.lot === action.phaseAnyBidLot && !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/docs/CURRENT_STATUS.md b/docs/CURRENT_STATUS.md index 09e83027..e97e8bf9 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 ordinary bid answers — 16 November. Prototyped / +Partial.** Current ordinary and all-auction Truthtrance bid answers can +coexist in either order, including mixed factual questions. A shared guide +uses native bidding and funding; a later phase Yes requires a separately funded +forecast, including a real last Richese cache where available. Forty-nine +focused cases cover native play, shared controls, Semuta and the last cache. +Early-cache commitments, other combinations, complete games and deployed +acceptance remain open. +[Scope](TRUTHTRANCE_BID_PROMISES.md#all-auction-and-current-ordinary-bids--16-november-2026). + **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 diff --git a/docs/RULE_DECISIONS.md b/docs/RULE_DECISIONS.md index 30a37d50..ebead690 100644 --- a/docs/RULE_DECISIONS.md +++ b/docs/RULE_DECISIONS.md @@ -1,5 +1,12 @@ # Rule decision index +## Joint phase-wide and ordinary bid answers — 16 November 2026 + +Current ordinary and all-auction phase bid answers share the native bid; +a separate later witness must reserve the actual purchase and funding. The +online forecast and timing remain provisional. +[Scope](TRUTHTRANCE_BID_PROMISES.md#all-auction-and-current-ordinary-bids--16-november-2026). + ## Joint phase-wide and Richese bid answers — 16 November 2026 Current Richese Once Around/Silent and all-auction phase bid answers can share diff --git a/docs/TRUTHTRANCE_BID_PROMISES.md b/docs/TRUTHTRANCE_BID_PROMISES.md index 8c5f7d77..276ecdc9 100644 --- a/docs/TRUTHTRANCE_BID_PROMISES.md +++ b/docs/TRUTHTRANCE_BID_PROMISES.md @@ -1,5 +1,25 @@ # Truthtrance ordinary bid commitments +## All-auction and current ordinary bids — 16 November 2026 + +**Prototyped / Partial.** Current ordinary and all-auction bid answers, including +mixed factual questions, can coexist in either order. One native declaration +may satisfy both; the local No applies to its lot and the phase No throughout +Bidding. A later Yes requires an independently funded witness. The forecast +reserves the present purchase, aid and hand space and can include a real last +Richese cache; it does not assume rival bids, income or refunds. The shared +event-bound guide serves both controls, minimal bots and the auction clock. +Supported Advanced Semuta preserves the original commitments and question queue. + +The FAQ and supplied Advanced revision support current-turn questions and +compliance while possible; this online forecast and ordering are provisional. +Early-cache and older ordinary-only phase combinations, other commitments, +optional modules, complete games and deployed acceptance remain open. +[Runtime](../tests/truth-phase-any-ordinary-joint.test.ts), +[last cache](../tests/truth-phase-any-ordinary-last-cache.test.ts), +[controls](../tests/truth-phase-any-ordinary-joint-controls.test.tsx) and +[Semuta](../tests/truth-phase-any-ordinary-joint-semuta.test.ts) cover 49 cases. + ## All-auction and current Richese bids — 16 November 2026 **Prototyped / Partial.** A player may hold both an all-auction phase bid @@ -17,7 +37,7 @@ 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 +authority below. Early-cache and legacy ordinary-only phase 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 @@ -44,8 +64,8 @@ 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. Current Richese bid answers now compose as -described above; early-cache, ordinary-only and other unsupported financial or +assert a publisher prohibition. Current Richese and ordinary bid answers now compose as +described above; early-cache, legacy ordinary-only phase and other unsupported financial or action promise combinations remain separate. Broader modules, full games and deployed acceptance remain open. diff --git a/game/engine.ts b/game/engine.ts index 20fd4f97..157a5acc 100644 --- a/game/engine.ts +++ b/game/engine.ts @@ -2005,6 +2005,8 @@ export type Game = { advancedAuctionTruth?: true; /** Fresh joint Richese/all-auction answer; absent on older receipts. */ jointRichesePhaseBid?: true; + /** Fresh joint ordinary/all-auction answer; absent on older receipts. */ + jointOrdinaryPhaseBid?: true; resume: NonNullable['resume']; promise: | { kind: 'shipment'; index: number; value: ShipmentPromise } @@ -8058,6 +8060,8 @@ function truthtranceDiscardSignature(g: Game, next: TruthDiscardContinuation) { ...(next.record.question.kind === 'phaseAnyBid' ? {phaseAnyBidPromises:g.phaseAnyBidPromises} : {}), ...(next.jointRichesePhaseBid ? {jointRichesePhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises, richeseBidPromises:g.richeseBidPromises,mixedRicheseBidQuestions:g.mixedRicheseBidQuestions} : {}), + ...(next.jointOrdinaryPhaseBid ? {jointOrdinaryPhaseBid:true,phaseAnyBidPromises:g.phaseAnyBidPromises, + bidPromises:g.bidPromises,mixedBidQuestions:g.mixedBidQuestions} : {}), ...(next.record.question.kind === 'mixedRevival' ? { mixedRevivalQuestions: g.mixedRevivalQuestions, revivalExpressionPromises: g.revivalExpressionPromises, } : {}), @@ -8147,6 +8151,10 @@ function finishTruthtranceAnswer(g: Game) { 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} : {}), + ...(bidOpportunity(g) && ['phaseAnyBid','bid','mixedBid'].includes(record.question.kind) && + livePhaseBidPromises(g.phaseAnyBidPromises ?? [],record.question.target,g.turn).length && + liveBidPromises(g.bidPromises ?? [],record.question.target,bidOpportunity(g)!).length + ? {jointOrdinaryPhaseBid:true as const} : {}), resume, promise, parentSignature: '', @@ -9174,6 +9182,14 @@ function treacheryDiscardIntegrity(g: Game) { 'The consumed Truthtrance does not match its completed answer history.', ); const remaining = c.remaining; + if (c.jointOrdinaryPhaseBid) { + const lot = bidOpportunity(g), target = record.question.target; + requireRule(c.jointOrdinaryPhaseBid === true && !!lot && + ['phaseAnyBid','bid','mixedBid'].includes(record.question.kind) && + livePhaseBidPromises(g.phaseAnyBidPromises ?? [],target,g.turn).length > 0 && + liveBidPromises(g.bidPromises ?? [],target,lot).length > 0, + 'The completed Truthtrance lost its joint ordinary auction commitments.'); + } if (c.jointRichesePhaseBid) { const lot = g.richeseAuction, target = record.question.target; requireRule(c.jointRichesePhaseBid === true && !!lot && @@ -19013,8 +19029,10 @@ function phaseAnyBidWindow(g: Game): boolean { (g.phase < 3 || !!bidOpportunity(g) || !!g.richeseAuction && !g.richeseAuction.outcome); } function phaseAnyBidConflict(g: Game, p: Player): boolean { + const current = bidOpportunity(g); 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.bidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released && + (!current || row.source !== current.source)) || (g.earlyRicheseBidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) || (g.pledgePromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) || @@ -19039,6 +19057,20 @@ 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; } +/** A declared last cache follows the ordinary pool even if its last lot is + * unbid. Keep a current winning invoice and card slot reserved. */ +function phaseAnyLastCache(g: Game,p: Player): PhaseBidOpportunity | null { + const round = g.richeseBidding, auction = g.auction; + if (g.phase !== 3 || !round || round.turn !== g.turn || round.stage !== 'normal' || + round.position !== 'last' || !auction || g.richeseAuction || !richeseCacheRuns(g)) return null; + const own = auction.bidder === p.id && !g.currentAuctionSale; + const added = own ? 1 + Number(p.faction === 'harkonnen') : 0; + if (p.hand.length + added >= handLimit(p)) return null; + const lockedAid = own ? (auction.allyPayment ?? 0) : 0; + const maximum = Math.max(0,uncommittedSpice(g,p) + Math.max(0,(aidFor(g,p)?.amount ?? 0)-lockedAid)); + return Number.isSafeInteger(maximum) && maximum > 0 + ? {turn:g.turn,player:p.id,kind:'future',minimum:1,maximum} : null; +} /** 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[], @@ -19079,8 +19111,24 @@ function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPro } } const futureCache = phaseAnyFutureCache(g,p); + let lastCache = phaseAnyLastCache(g,p); + const ordinaryLot = bidOpportunity(g); + if (lastCache && ordinaryLot && bidRequired(g.bidPromises ?? [],p.id,ordinaryLot)) { + const caps: BidPromise[] = livePhaseBidPromises(promises,p.id,g.turn).filter(row => !row.answer) + .map((row,index) => ({turn:g.turn,lot:ordinaryLot.lot,minimum:row.minimum,event:`any-cache-cap-${index}`, + source:ordinaryLot.source,player:p.id,asker:row.asker,answer:false})); + const action = bidPromiseCompletion(g,p,[...(g.bidPromises ?? []),...caps]); + if (!action || action.type !== 'bid') lastCache = null; + else { + const trial = structuredClone(g); + trial.auction!.bid = Number(action.amount); trial.auction!.bidder = p.id; + trial.auction!.allyPayment = Number(action.allyPayment ?? 0); + lastCache = phaseAnyLastCache(trial,getPlayer(trial,p.id)); + } + } const ordinary = viablePhaseBidWitnesses(g,p,promises); - return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),...ordinary]; + return [...(special ? [special] : []),...(futureCache ? [futureCache] : []), + ...(lastCache ? [lastCache] : []),...ordinary]; } function richesePhaseJointPossible(g: Game,p: Player,phase: readonly PhaseBidPromise[]): boolean { const lot = g.richeseAuction; @@ -19100,7 +19148,8 @@ function phaseAnyBidTruthAnswers(g: Game, p: Player, claim: PhaseBidClaim): Trut 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) || + const ordinary = bidOpportunity(g), localRequired = ordinary && bidRequired(g.bidPromises ?? [],p.id,ordinary); + return !localRequired && !livePhaseBidPromises(all,p.id,g.turn).some(row => row.answer) || phaseAnyBidWitnesses(g,p,all).some(witness => !!phaseBidCompletionRange(all,witness)); }); } @@ -19157,10 +19206,29 @@ 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; if (g.auction) { - const ordinary = projectedPhaseBidGuide({...g,phaseBidPromises:live},id)?.action; + let ordinary = projectedPhaseBidGuide({...g,phaseBidPromises:live},id)?.action; + const lot = bidOpportunity(g); + if (!ordinary && lot && g.auction.active === id && phaseAnyLastCache(g,p)) { + const caps: BidPromise[] = live.filter(row => !row.answer).map((row,index) => ({ + turn:g.turn,lot:lot.lot,minimum:row.minimum,event:`any-cache-guide-${index}`, + source:lot.source,player:id,asker:row.asker,answer:false})); + const action = bidPromiseCompletion(g,p,[...(g.bidPromises ?? []),...caps]); + if (action) { + const trial = structuredClone(g); + if (action.type === 'bid') { + trial.auction!.bid = Number(action.amount); trial.auction!.bidder = id; + trial.auction!.allyPayment = Number(action.allyPayment ?? 0); + trial.bidPromises = recordPromisedBid(trial.bidPromises ?? [],id,lot,Number(action.amount)); + } else if (!trial.auction!.passed.includes(id)) trial.auction!.passed.push(id); + if (phaseAnyBidWitnesses(trial,getPlayer(trial,id),live).some(witness => + witness.kind === 'future' && !!phaseBidCompletionRange(live,witness))) ordinary = action; + } + } if (!ordinary) return null; const action = {...ordinary}; delete action.phaseBidPromiseEvent; delete action.phaseBidPromiseLot; - return {action:{...action,phaseAnyBidPromiseEvent:live[0].event,phaseAnyBidLot:g.auction.index + 1}}; + const native = lot && liveBidPromises(g.bidPromises ?? [],id,lot)[0]; + return {action:{...action,...(native ? {bidPromiseEvent:native.event} : {}), + phaseAnyBidPromiseEvent:live[0].event,phaseAnyBidLot:g.auction.index + 1}}; } const lot = g.richeseAuction; if (!lot || (lot.method === 'silent' ? Object.hasOwn(lot.sealed,id) : lot.active !== id)) return null; @@ -19212,10 +19280,10 @@ function bidPromiseCompletion(g: Game, p: Player, promises = g.bidPromises ?? [] function bidTruthAnswers(g: Game, p: Player, claim: BidClaim): ('yes' | 'no' | 'unknown')[] { const opportunity = bidOpportunity(g); if (!opportunity || !bidQuestionWindow(g) || claim.turn !== opportunity.turn || claim.lot !== opportunity.lot || - livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length || !opportunity.eligible.includes(p.id) || opportunity.passed.includes(p.id) || opportunity.bidder === p.id) return []; return (['yes', 'no'] as const).filter(answer => { - const phases = livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn); + const phases = [...livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn), + ...livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn)]; const caps: BidPromise[] = phases.filter(row => !row.answer).map((row,index) => ({ turn:g.turn,lot:opportunity.lot,minimum:row.minimum,event:`phase-cap-${index}`, source:opportunity.source,player:p.id,asker:row.asker,answer:false, @@ -19228,8 +19296,11 @@ function bidTruthAnswers(g: Game, p: Player, claim: BidClaim): ('yes' | 'no' | ' const phaseYes = phases.filter(row => row.answer); const trial = structuredClone(g); trial.bidPromises = claims; - if (!phaseYes.length || viablePhaseBidWitnesses(trial,getPlayer(trial,p.id),trial.phaseBidPromises ?? []).some(w => w.kind === 'future' && - !!phaseBidCompletionRange(g.phaseBidPromises ?? [],w))) return true; + const future = livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length + ? phaseAnyBidWitnesses(trial,getPlayer(trial,p.id),phases) + : viablePhaseBidWitnesses(trial,getPlayer(trial,p.id),phases); + if (!phaseYes.length || future.some(w => w.kind === 'future' && + !!phaseBidCompletionRange(phases,w))) return true; const required: BidPromise[] = phaseYes.map((row,index) => ({ turn:g.turn,lot:opportunity.lot,minimum:row.minimum,event:`phase-yes-${index}`, source:opportunity.source,player:p.id,asker:row.asker,answer:true, @@ -19254,7 +19325,6 @@ function compileMixedBid(g: Game, p: Player, claim: MixedBidClaim, answer: boole function mixedBidTruthAnswers(g: Game, p: Player, claim: MixedBidClaim): TruthAnswer[] { const opportunity = bidOpportunity(g); if (!opportunity || !mixedBidQuestionWindow(g) || claim.turn !== opportunity.turn || claim.lot !== opportunity.lot || - livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length || !opportunity.eligible.includes(p.id) || opportunity.passed.includes(p.id) || opportunity.bidder === p.id) return []; const answers: TruthAnswer[] = []; for (const answer of [true, false]) { @@ -19307,7 +19377,10 @@ function reconcileBidPromises(g: Game, voluntary?: { actor: string; action: Acti if (!promise.answer && same) continue; const own = voluntary?.actor === promise.player && ['bid', 'passBid', 'card', 'bribe', 'pledgeAid', 'emperorGift', 'richeseGift', 'richeseBid', 'decision', 'karama', 'specialKarama'].includes(voluntary.action.type); - const possible = same && bidPromiseCompletion(g, getPlayer(g, promise.player), [...no, ...kept, promise]); + const caps: BidPromise[] = same ? livePhaseBidPromises(g.phaseAnyBidPromises ?? [],promise.player,g.turn) + .filter(row => !row.answer).map((row,index) => ({turn:g.turn,lot:opportunity.lot,minimum:row.minimum, + event:`phase-any-reconcile-${index}`,source:opportunity.source,player:promise.player,asker:row.asker,answer:false})) : []; + const possible = same && bidPromiseCompletion(g, getPlayer(g, promise.player), [...no, ...kept, promise,...caps]); if (promise.answer && !possible) { requireRule(!own, 'You cannot voluntarily evade your Truthtrance bid answer.'); promise.released = true; @@ -19327,6 +19400,8 @@ function projectedBidPromises(g: Game, player: string) { function projectedBidPromiseGuide(g: Game, player: string): { action: Action } | null { // The phase-wide guide combines both sets of live bounds into one packet. if (livePhaseBidPromises(g.phaseBidPromises ?? [],player,g.turn).length) return null; + if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],player,g.turn).length) + return projectedPhaseAnyBidGuide(g,player); const opportunity = bidOpportunity(g); if (!opportunity || !bidQuestionWindow(g) || g.truthtrance || g.auction?.active !== player) return null; const promise = liveBidPromises(g.bidPromises ?? [], player, opportunity)[0]; @@ -19347,6 +19422,8 @@ function guardPromisedBid(g: Game, p: Player, action: Action, amount?: number) { if (amount !== undefined) { trial.auction!.bid = amount; trial.auction!.bidder = p.id; trial.auction!.allyPayment = normalBidQuote(g,p,amount,action.allyPayment).allyPayment; + try { trial.bidPromises = recordPromisedBid(trial.bidPromises ?? [],p.id,opportunity,amount); } + catch (error) { if (error instanceof BidPromiseError) throw new RuleError(error.message); throw error; } } else if (!trial.auction!.passed.includes(p.id)) trial.auction!.passed.push(p.id); const future = phaseAnyBidWitnesses(trial,getPlayer(trial,p.id),trial.phaseAnyBidPromises ?? []) .find(witness => witness.kind === 'future' && !!phaseBidCompletionRange(trial.phaseAnyBidPromises ?? [],witness)); diff --git a/game/reference.ts b/game/reference.ts index ae5f718d..b2bfdc32 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -3789,7 +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.', + 'A current ordinary, 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/truth-phase-any-ordinary-joint-controls.test.tsx b/tests/truth-phase-any-ordinary-joint-controls.test.tsx new file mode 100644 index 00000000..49d78a1d --- /dev/null +++ b/tests/truth-phase-any-ordinary-joint-controls.test.tsx @@ -0,0 +1,82 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createElement } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { BidPromiseGuideButton, BidPromises } from '../components/bid-promises'; +import { MixedBidPromises } from '../components/mixed-bid-promises'; +import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises'; +import { viewGame, type Action, type Game } from '../game/engine'; +import { actTruthBid as act, createTruthBidFixture, truthBidInventory as inventory, + type TruthBidFixture } from './fixture-truth-bid'; + +function answer(game:Game,f:TruthBidFixture,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 act(state,f.target,{type:'truthAnswer',answer:'yes'}); +} + +/** Real public-start game with native cards and bids. The shared fixture selects + * unopened deal, auction and Spice order and scalar rolls without inventing + * cards, money, bids or answers. */ +function joint(advanced:boolean,kind:'bid'|'mixedBid') { + const f=createTruthBidFixture({advanced,window:'active'}); + const phase={kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:4}; + const lot=kind === 'bid' ? {kind,target:f.target,turn:f.game.turn,lot:1,minimum:6} : + {kind,target:f.target,turn:f.game.turn,lot:1,mixed:{kind:'and',terms:[ + {kind:'fact',fact:{kind:'spice',compare:'gte',value:10}}, + {kind:'action',action:{minimum:6}}, + ]}}; + let game=answer(f.game,f,f.truths[0],phase); + game=answer(game,f,f.truths[1],lot); + return {game,f}; +} + +for (const advanced of [false,true]) for (const kind of ['bid','mixedBid'] as const) void test( + `${advanced?'Advanced':'Basic'} ${kind} and any-auction controls share a live dual-tagged action`,() => { + const {game,f}=joint(advanced,kind), view=viewGame(game,f.target), sent:Action[]=[]; + assert.ok(view.phaseAnyBidGuide && view.bidPromiseGuide); + const action=view.phaseAnyBidGuide.action; + assert.deepEqual(action,view.bidPromiseGuide.action); + assert.equal(action.type,'bid'); assert.equal(action.amount,6); + assert.equal(action.phaseAnyBidPromiseEvent,game.phaseAnyBidPromises?.find(row => row.player === f.target)?.event); + assert.equal(action.bidPromiseEvent,game.bidPromises?.find(row => row.player === f.target)?.event); + assert.equal(action.phaseAnyBidLot,1); + const props={game:view,busy:false,send(value:Action){sent.push(value);}}; + const phaseHtml=renderToStaticMarkup(createElement(PhaseAnyBidPromises,props)); + const localHtml=renderToStaticMarkup(createElement(kind === 'bid' ? BidPromises : MixedBidPromises,props)); + assert.match(phaseHtml,/Your any-auction bid promises/); + assert.match(phaseHtml,/data-testid="phase-any-bid-guide"/); + assert.match(localHtml,kind === 'bid' ? /Your bid promises/ : /Your mixed bid promises/); + assert.match(localHtml,/data-testid="bid-promise-guide"/); + const phaseButton=PhaseAnyBidGuideButton(props), localButton=BidPromiseGuideButton(props); + assert.ok(phaseButton && localButton); + const clickPhase=() => phaseButton.props.onClick(); + const clickLocal=() => localButton.props.onClick(); + clickPhase(); clickLocal(); + assert.deepEqual(sent,[action,action]); + props.busy=true; clickPhase(); clickLocal(); + assert.equal(sent.length,2,'A pending action suppresses either stale callback'); + props.busy=false; + const lotNumber=view.bidPromiseLot!.lot; + view.bidPromiseLot!.lot=lotNumber+1; clickPhase(); clickLocal(); + assert.equal(sent.length,2,'A different ordinary lot invalidates both callbacks'); + view.bidPromiseLot!.lot=lotNumber; + const phaseReceipt=view.phaseAnyBidPromises.find(row => row.event === action.phaseAnyBidPromiseEvent); assert.ok(phaseReceipt); + phaseReceipt.fulfilled=true; clickPhase(); clickLocal(); + assert.equal(sent.length,2,'A closed phase receipt invalidates the local callback too'); + phaseReceipt.fulfilled=false; + const localReceipt=(kind === 'bid' ? view.bidPromises : view.mixedBidPromises) + .find(row => row.event === action.bidPromiseEvent); assert.ok(localReceipt); + localReceipt.fulfilled=true; clickPhase(); clickLocal(); + assert.equal(sent.length,2,'A closed local receipt invalidates the phase callback too'); + localReceipt.fulfilled=false; + const applied=act(game,f.target,sent[0]); + assert.ok(applied.phaseAnyBidPromises?.some(row => row.event === action.phaseAnyBidPromiseEvent && row.fulfilled)); + assert.ok(applied.bidPromises?.some(row => row.event === action.bidPromiseEvent && row.fulfilled)); + assert.deepEqual(inventory(applied),f.originalCards); + }); diff --git a/tests/truth-phase-any-ordinary-joint-semuta.test.ts b/tests/truth-phase-any-ordinary-joint-semuta.test.ts new file mode 100644 index 00000000..0db1738b --- /dev/null +++ b/tests/truth-phase-any-ordinary-joint-semuta.test.ts @@ -0,0 +1,84 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { viewGame, type Game } from '../game/engine'; +import { + actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, + createTruthtranceRichesePromisesFixture as fixture, passTruthRicheseFreshDiscard, + truthtranceRichesePromisesClean as clean, truthtranceRichesePromisesInventory as inventory, + truthtranceRichesePromisesPlayer as player, +} from './fixture-truthtrance-richese-promises'; + +/** Real Advanced CHOAM/Richese setup and ordinary auction. The conserved + * supplements move the second original Truthtrance from the unopened deck to + * Atreides and Semuta from Richese's cache to Richese; no bid, wallet, answer + * or reaction is installed. */ +function source() { + const f = fixture({advanced:true}); + let game = structuredClone(f.earlySource); + const secondAt = game.deck.findIndex(card => card.effect === 'truthtrance' && card.id !== f.truth); + assert.ok(secondAt >= 0); + const [second] = game.deck.splice(secondAt,1); + player(game,f.asker).hand.push(second); + game = advance(game,state => state.phase === 3 && !!state.auction && clean(state)); + if (game.auction!.active === f.asker) game = act(game,f.asker,{type:'passBid'}); + const target = game.auction!.active; + assert.ok(target && target !== f.asker); + const cache = game.richeseCache!; + const semutaAt = cache.findIndex(card => card.effect === 'semutaDrug'); assert.ok(semutaAt >= 0); + const [semuta] = cache.splice(semutaAt,1); + player(game,f.richese).hand.push(semuta); + assert.deepEqual(inventory(game),f.originalCards); + return {f,game,target,second:second.id,semuta:semuta.id}; +} + +function parent(game: Game) { + return structuredClone({auction:game.auction,richeseAuction:game.richeseAuction, + richeseBidding:game.richeseBidding,richeseFunding:game.richeseFunding,aid:game.aid, + turn:game.turn,phase:game.phase,active:game.active,order:game.order}); +} + +for (const first of ['phase','lot'] as const) for (const claim of [false,true]) void test( + `Advanced ordinary ${first} first: second Truth Semuta ${claim ? 'claim' : 'pass'} preserves joint promises`, () => { + const f = source(); + const lot = f.game.auction!.index+1; + const phase = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:1}; + const native = {kind:'bid',target:f.target,turn:f.game.turn,lot,minimum:1}; + const auction = parent(f.game); + let game = act(f.game,f.f.asker,{type:'card',card:f.f.truth,cards:[f.second]}); + while (game.truthtrance?.stage === 'priority') { + const actor = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(actor); + game = act(game,actor.id,{type:'truthPass'}); + } + 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' ? phase : native}); + game = act(game,f.target,{type:'truthAnswer',answer:'yes'}); + game = passTruthRicheseFreshDiscard(game); + assert.deepEqual(game.truthtrance?.queue.map(row => row.card),[f.second]); + game = act(game,f.f.asker,{type:'truthAsk',question:first === 'phase' ? native : phase}); + game = act(game,f.target,{type:'truthAnswer',answer:'yes'}); + const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction); + assert.equal(pending.continuation.kind,'truthtranceDiscard'); + assert.equal(pending.continuation.jointOrdinaryPhaseBid,true); + assert.equal(pending.batch.entries[0].card.id,f.second); + assert.equal(viewGame(game,f.f.richese).semutaReaction?.canCommit,true); + const phasePromises = structuredClone(game.phaseAnyBidPromises), lotPromises = structuredClone(game.bidPromises); + assert.deepEqual(parent(game),auction); + for (const family of ['phaseAnyBidPromises','bidPromises'] as const) { + const tampered = structuredClone(game); + tampered[family]![0].minimum++; + assert.throws(() => act(tampered,f.f.richese,{type:'semutaCommit',event:pending.batch.event}), + `The completed answer binds its ${family} receipts`); + } + game = claim ? act(game,f.f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game); + assert.equal(game.pendingTreacheryDiscard,null); assert.equal(game.truthtrance,null); + assert.equal(player(game,f.f.richese).hand.some(card => card.id === f.second),claim); + assert.equal(game.discard.some(card => card.id === f.semuta),claim); + assert.deepEqual(game.phaseAnyBidPromises,phasePromises); assert.deepEqual(game.bidPromises,lotPromises); + assert.deepEqual(parent(game),auction); + const view = viewGame(game,f.target), guide = view.phaseAnyBidGuide?.action; + assert.ok(guide); assert.deepEqual(guide,view.bidPromiseGuide?.action); + game = act(game,f.target,guide); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.ok(game.bidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.deepEqual(inventory(game),f.f.originalCards); + }); diff --git a/tests/truth-phase-any-ordinary-joint.test.ts b/tests/truth-phase-any-ordinary-joint.test.ts new file mode 100644 index 00000000..831922f9 --- /dev/null +++ b/tests/truth-phase-any-ordinary-joint.test.ts @@ -0,0 +1,172 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { advanceAuctionClock, hasAuctionClockOpportunity, synchronizeAuctionClock, viewGame, + type Action, type Game } from '../game/engine'; +import { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { actTruthBid as act, advanceTruthBid as advance, continueTruthBidLot as closeLot, + createTruthBidFixture as fixture, truthBidClean as clean, truthBidInventory as inventory, + truthBidPlayer as player, type TruthBidFixture } from './fixture-truth-bid'; +import { purchaseTruthTurnBidLot } from './fixture-truth-turn-bid'; + +type Answer = 'yes' | 'no'; +type Kind = 'bid' | 'mixedBid'; + +function reject(game: Game, actor: string, action: Action) { + const before = structuredClone(game); + assert.throws(() => act(game,actor,action)); + assert.deepEqual(game,before,'A rejected bid or stale guide leaves the original game untouched'); +} +/** The Harkonnen/Atreides/Emperor game, both original Truth cards and all bids + * are native. The source fixture selects only unopened deal, auction and Spice + * order and scalar lotteries; it stages no hand, purse, bid or answer. */ +function ask(game: Game, f: TruthBidFixture, 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 answers = question.kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : + question.kind === 'phaseBid' ? view.truthPhaseBidAnswers : + question.kind === 'bid' ? view.truthBidAnswers : view.truthMixedBidAnswers; + assert.ok(answers?.includes(answer),`The compatible ${String(question.kind)} ${answer} must be offered`); + return act(current,f.target,{type:'truthAnswer',answer}); +} +function questions(f: TruthBidFixture, game: Game, kind: Kind, phaseAnswer: Answer) { + assert.ok(game.auction); + const phaseMinimum = phaseAnswer === 'yes' ? 4 : 6, lotMinimum = phaseAnswer === 'yes' ? 6 : 4; + const phase = {kind:'phaseAnyBid',target:f.target,turn:game.turn,minimum:phaseMinimum}; + const lot = kind === 'bid' ? {kind,target:f.target,turn:game.turn,lot:game.auction.index + 1,minimum:lotMinimum} : + {kind,target:f.target,turn:game.turn,lot:game.auction.index + 1,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 advanced of [false,true]) for (const kind of ['bid','mixedBid'] 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( + `${advanced?'Advanced':'Basic'} ordinary ${kind} ${first} first: phase ${phaseAnswer} and lot ${lotAnswer}`, () => { + const f = fixture({advanced,window:'active'}), q = questions(f,f.game,kind,phaseAnswer); + let game = ask(f.game,f,f.truths[0],first === 'phase' ? q.phase : q.lot, + first === 'phase' ? phaseAnswer : lotAnswer); + game = ask(game,f,f.truths[1],first === 'phase' ? q.lot : q.phase, + first === 'phase' ? lotAnswer : phaseAnswer); + const phase = game.phaseAnyBidPromises?.find(row => row.player === f.target); assert.ok(phase); + const local = game.bidPromises?.find(row => row.player === f.target); assert.ok(local); + assert.equal(phase.answer,phaseAnswer === 'yes'); assert.equal(local.answer,lotAnswer === 'yes'); + const view = viewGame(game,f.target), phaseGuide = view.phaseAnyBidGuide?.action, lotGuide = view.bidPromiseGuide?.action; + assert.ok(phaseGuide && lotGuide,'Both promise panels have one jointly legal native guide'); + assert.deepEqual(phaseGuide,lotGuide); + assert.equal(phaseGuide.phaseAnyBidPromiseEvent,phase.event); + assert.equal(phaseGuide.bidPromiseEvent,local.event); + assert.doesNotThrow(() => act(game,f.target,phaseGuide)); + reject(game,f.target,{...phaseGuide,phaseAnyBidPromiseEvent:'stale-phase'}); + reject(game,f.target,{...phaseGuide,bidPromiseEvent:'stale-local'}); + for (const difficulty of DIFFICULTIES) { + const bot = viewGame(game,f.target); bot.players.find(row => row.id === f.target)!.bot = difficulty; + const action = botActions(bot)[0]; assert.ok(action,difficulty); + assert.ok(action.type === 'bid' || action.type === 'passBid'); + assert.doesNotThrow(() => act(game,f.target,action),difficulty); + } + if (phaseAnswer === 'no') reject(game,f.target,{type:'bid',amount:q.phaseMinimum,allyPayment:0}); + if (lotAnswer === 'no') reject(game,f.target,{type:'bid',amount:q.lotMinimum,allyPayment:0}); + const amount = lotAnswer === 'yes' ? q.lotMinimum : phaseAnswer === 'yes' ? q.phaseMinimum : 2; + const before = player(game,f.target).spice, card = game.auction!.cards[game.auction!.index].id; + game = act(game,f.target,{type:'bid',amount,allyPayment:0}); + assert.equal(player(game,f.target).spice,before,'The declaration does not prepay the invoice'); + assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === phase.event)?.fulfilled,phaseAnswer === 'yes'); + if (lotAnswer === 'yes') assert.ok(game.bidPromises?.find(row => row.event === local.event)?.fulfilled); + game = closeLot(game); + assert.ok(player(game,f.target).hand.some(row => row.id === card)); + assert.equal(player(game,f.target).spice,before-amount); + assert.deepEqual(inventory(game),f.originalCards); + }); + +for (const first of ['phase','lot'] as const) for (const kind of ['bid','mixedBid'] as const) void test( + `current ordinary ${kind} No permits phase Yes in a later funded lot, ${first} first`, () => { + const f = fixture({window:'waiting'}); + const phase = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:6}; + const lot = kind === 'bid' ? {kind,target:f.target,turn:f.game.turn,lot:1,minimum:4} : + {kind,target:f.target,turn:f.game.turn,lot:1,mixed:{kind:'and',terms:[ + {kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},{kind:'action',action:{minimum:4}}, + ]}}; + // A real funded Harkonnen bid makes the following physical lot reachable; + // no hypothetical opposing raise is invented to justify the phase Yes. + let game = act(f.game,f.asker,{type:'bid',amount:1,allyPayment:0}); + game = act(game,f.opponent,{type:'passBid'}); + game = ask(game,f,f.truths[0],first === 'phase' ? phase : lot,first === 'phase' ? 'yes' : 'no'); + game = ask(game,f,f.truths[1],first === 'phase' ? lot : phase,first === 'phase' ? 'no' : 'yes'); + assert.equal(game.auction?.active,f.target); + const guide = viewGame(game,f.target).phaseAnyBidGuide?.action; assert.ok(guide); + assert.deepEqual(guide,viewGame(game,f.target).bidPromiseGuide?.action); + reject(game,f.target,{type:'bid',amount:4,allyPayment:0}); + if (guide.type === 'bid') assert.ok(Number(guide.amount) < 4); + game = act(game,f.target,guide); + const phaseRow = game.phaseAnyBidPromises?.find(row => row.player === f.target); assert.ok(phaseRow); + assert.equal(!!phaseRow.fulfilled,false); assert.equal(!!phaseRow.released,false); + game = advance(game,state => clean(state) && !!state.auction && state.auction.index === 1 && state.auction.active === f.target); + const later = viewGame(game,f.target).phaseAnyBidGuide?.action; assert.ok(later); + assert.equal(later.type,'bid'); assert.ok(Number(later.amount) >= 6); + game = act(game,f.target,later); + assert.ok(game.phaseAnyBidPromises?.some(row => row.event === phaseRow.event && row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); + }); + +void test('an opposing raise releases only the impossible ordinary-lot Yes while a later phase Yes remains', () => { + const f = fixture({window:'waiting'}); + const phase = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:4}; + const lot = {kind:'bid',target:f.target,turn:f.game.turn,lot:1,minimum:9}; + let game = ask(f.game,f,f.truths[0],phase,'yes'); + game = ask(game,f,f.truths[1],lot,'yes'); + game = act(game,f.asker,{type:'bid',amount:10,allyPayment:0}); + const native = game.bidPromises?.find(row => row.player === f.target); assert.ok(native); + const wider = game.phaseAnyBidPromises?.find(row => row.player === f.target); assert.ok(wider); + assert.equal(!!native.released,true); assert.equal(!!wider.released,false); + game = act(game,f.opponent,{type:'passBid'}); + assert.equal(game.auction?.active,f.target); + game = act(game,f.target,{type:'passBid'}); + game = advance(game,state => clean(state) && !!state.auction && state.auction.index === 1 && state.auction.active === f.target); + const guide = viewGame(game,f.target).phaseAnyBidGuide?.action; assert.ok(guide); + assert.equal(guide.type,'bid'); assert.ok(Number(guide.amount) >= 4); + game = act(game,f.target,guide); + assert.ok(game.phaseAnyBidPromises?.some(row => row.event === wider.event && row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); +}); + +void test('an expiring final ordinary clock executes a bid satisfying both live Yes answers', () => { + const f = fixture({window:'waiting'}); + let game = purchaseTruthTurnBidLot(f.game,f.opponent).game; + game = purchaseTruthTurnBidLot(game,f.opponent).game; + game = advance(game,state => clean(state) && state.auction?.active === f.target); + assert.equal(game.auction?.index,2); assert.ok(hasAuctionClockOpportunity(game)); + const q = questions(f,game,'bid','yes'); + game = ask(game,f,f.truths[0],q.phase,'yes'); + game = ask(game,f,f.truths[1],q.lot,'yes'); + reject(game,f.target,{type:'passBid'}); + const guide = viewGame(game,f.target).phaseAnyBidGuide?.action; assert.ok(guide); + assert.equal(guide.type,'bid'); assert.equal(guide.amount,6); + const armed = synchronizeAuctionClock(game,1_000,'joint-ordinary-test:0'); + const expired = advanceAuctionClock(armed,11_000,'joint-ordinary-test:0'); + assert.equal(expired.auction?.bidder,f.target); assert.equal(expired.auction?.bid,6); + assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.ok(expired.bidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.deepEqual(inventory(expired),f.originalCards); +}); + +void test('a legacy ordinary-only No still composes with an ordinary lot Yes', () => { + const f = fixture({window:'active'}), lot = {kind:'bid',target:f.target,turn:f.game.turn,lot:1,minimum:4}; + let game = ask(f.game,f,f.truths[0],{kind:'phaseBid',target:f.target,turn:f.game.turn,minimum:6},'no'); + game = ask(game,f,f.truths[1],lot,'yes'); + reject(game,f.target,{type:'bid',amount:6,allyPayment:0}); + const guide = viewGame(game,f.target).phaseBidPromiseGuide?.action; assert.ok(guide); + assert.equal(guide.type,'bid'); assert.equal(guide.amount,4); + game = act(game,f.target,guide); + assert.ok(game.bidPromises?.some(row => row.player === f.target && row.fulfilled)); + assert.ok(game.phaseBidPromises?.some(row => row.player === f.target && !row.answer && !row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); +}); diff --git a/tests/truth-phase-any-ordinary-last-cache.test.ts b/tests/truth-phase-any-ordinary-last-cache.test.ts new file mode 100644 index 00000000..5cc27bc2 --- /dev/null +++ b/tests/truth-phase-any-ordinary-last-cache.test.ts @@ -0,0 +1,112 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { viewGame, type Game } from '../game/engine'; +import type { TruthQuestion } from '../game/truthtrance'; +import { + actTruthtranceRichesePromises as act, advanceTruthtranceRichesePromises as advance, + createTruthtranceRichesePromisesFixture as fixture, nextTruthtranceRichesePromisesStep as next, + passTruthRicheseFreshDiscard, truthtranceRichesePromisesClean as clean, + truthtranceRichesePromisesInventory as inventory, truthtranceRichesePromisesPlayer as player, +} from './fixture-truthtrance-richese-promises'; + +type Fixture = ReturnType; +const options = {position:'last' as const, method:'silent' as const}; + +/** Genuine Advanced setup and auctions; stage only the second original Truth in + * Atreides' hand, conserving the physical deck. */ +function source() { + const f = fixture({advanced:true}); + let game = structuredClone(f.earlySource); + 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); + game = advance(game,state => clean(state) && !!state.auction,[],options); + assert.equal(game.auction?.active,f.richese); + game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0}); + // Reach the real target's ordinary turn without fabricating a current bid. + for (let n = 0; game.auction?.active !== f.emperor && n < game.players.length; n++) { + const actor = game.auction?.active; assert.ok(actor); + game = act(game,actor,{type:'passBid'}); + } + assert.equal(game.auction?.active,f.emperor); + return {f,game,second:second.id}; +} +function ask(game:Game, f:Fixture, card:string, question:TruthQuestion, answer:'yes'|'no') { + game = act(game,f.asker,{type:'card',card}); + game = advance(game,state => state.truthtrance?.stage === 'ask',[],options); + game = act(game,f.asker,{type:'truthAsk',question}); + const view = viewGame(game,f.emperor); + const choices = question.kind === 'phaseAnyBid' ? view.truthPhaseAnyBidAnswers : view.truthBidAnswers; + assert.ok(choices?.includes(answer),`Must offer ${question.kind} ${answer}; offered ${JSON.stringify(choices)}`); + return passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer})); +} +function bind(local:'yes'|'no') { + const {f,second,...rest} = source(); + let game = rest.game; + const lot = game.auction!.index+1; + game = ask(game,f,f.truth,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum:6},'yes'); + game = ask(game,f,second,{kind:'bid',target:f.emperor,turn:game.turn,lot,minimum:local === 'yes' ? 2 : 4},local); + return {f,game}; +} +/** Continue through native actions, deliberately passing later ordinary lots + * so the all-auction promise must be fulfilled in the real final cache. */ +function reachCache(game:Game) { + for (let n = 0; n < 1000; n++) { + if (clean(game) && game.richeseAuction?.source === 'cache' && !game.richeseAuction.outcome) return game; + if (clean(game) && game.auction?.active) { + game = act(game,game.auction.active,{type:'passBid'}); + continue; + } + const step = next(game,options); assert.ok(step,'Native path must reach the last cache'); + game = act(game,step.actor,step.action); + } + throw Error('The real final cache did not open'); +} +function bidAtCache(game:Game, f:Fixture) { + const lot = game.richeseAuction; assert.ok(lot); + assert.equal(lot.source,'cache'); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,6); + const purse = player(game,f.emperor).spice; + game = act(game,f.emperor,guide.action); + assert.equal(player(game,f.emperor).spice,purse,'A declaration is not an invoice'); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled && !row.released)); + assert.deepEqual(inventory(game),f.originalCards); + game = advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId),[],options); + assert.equal(player(game,f.emperor).spice,purse-6); + assert.deepEqual(inventory(game),f.originalCards); +} + +void test('ordinary No and all-auction Yes reach and fulfill the native last cache',() => { + const {f,...bound} = bind('no'); let game = bound.game; + const rejected = structuredClone(game); + assert.throws(() => act(game,f.emperor,{type:'bid',amount:4,allyPayment:0})); + assert.deepEqual(game,rejected); + game = act(game,f.emperor,{type:'passBid'}); + const promise = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + game = reachCache(game); + bidAtCache(game,f); +}); + +void test('ordinary lower Yes purchases its real card while reserving funding for the last cache Yes',() => { + const {f,...bound} = bind('yes'); let game = bound.game; + const lotCard = game.auction!.cards[game.auction!.index].id; + const purse = player(game,f.emperor).spice; + game = act(game,f.emperor,{type:'bid',amount:2,allyPayment:0}); + assert.ok(game.bidPromises?.some(row => row.player === f.emperor && row.fulfilled)); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.fulfilled && !row.released)); + assert.equal(player(game,f.emperor).spice,purse); + const reserved = structuredClone(game); + assert.throws(() => act(game,f.emperor,{type:'bribe',target:f.asker,amount:3}), + 'The pending ordinary invoice and six-spice cache bid must both remain funded'); + assert.deepEqual(game,reserved); + assert.doesNotThrow(() => act(game,f.emperor,{type:'bribe',target:f.asker,amount:2})); + game = reachCache(game); + assert.ok(player(game,f.emperor).hand.some(card => card.id === lotCard)); + assert.equal(player(game,f.emperor).spice,purse-2); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.fulfilled && !row.released)); + bidAtCache(game,f); +});