From 38f1684e03a7917f9f3bbf68a5e9fc73c34ad3c4 Mon Sep 17 00:00:00 2001 From: Quintine <15965533+Quintine@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:17:36 +1100 Subject: [PATCH] Support phase-wide bidding across all auctions --- components/game-table.tsx | 2 + components/phase-any-bid-promises.tsx | 67 +++ components/truthtrance.tsx | 29 +- docs/CURRENT_STATUS.md | 14 +- docs/RULE_DECISIONS.md | 7 + docs/TRUTHTRANCE_BID_PROMISES.md | 33 ++ game/bots.ts | 5 + game/engine.ts | 205 ++++++++- game/phase-any-bid-promises.ts | 39 ++ game/reference.ts | 1 + game/richese-reveal-interruption.ts | 2 +- game/truthtrance.ts | 26 ++ tests/phase-any-bid-controls.test.tsx | 59 +++ tests/phase-any-bid-promises.test.ts | 48 +++ .../truth-phase-any-bid-future-cache.test.ts | 61 +++ tests/truth-phase-any-bid-runtime.test.ts | 399 ++++++++++++++++++ tests/truth-phase-any-bid-spending.test.ts | 91 ++++ 17 files changed, 1070 insertions(+), 18 deletions(-) create mode 100644 components/phase-any-bid-promises.tsx create mode 100644 game/phase-any-bid-promises.ts create mode 100644 tests/phase-any-bid-controls.test.tsx create mode 100644 tests/phase-any-bid-promises.test.ts create mode 100644 tests/truth-phase-any-bid-future-cache.test.ts create mode 100644 tests/truth-phase-any-bid-runtime.test.ts create mode 100644 tests/truth-phase-any-bid-spending.test.ts diff --git a/components/game-table.tsx b/components/game-table.tsx index 399efb0e..2589892c 100644 --- a/components/game-table.tsx +++ b/components/game-table.tsx @@ -53,6 +53,7 @@ import { LeaderRevivalPromises } from './leader-revival-promises'; import { GholaLeaderPromises } from './ghola-leader-promises'; import { BidPromises } from './bid-promises'; import { PhaseBidPromises } from './phase-bid-promises'; +import { PhaseAnyBidPromises } from './phase-any-bid-promises'; import { HomeworldShipment } from './homeworld-shipment'; import { HomeworldRevivalDeployment } from './homeworld-revival-deployment'; import { CaladanReinforcement } from './caladan-reinforcement'; @@ -2171,6 +2172,7 @@ export function GameTable({ {g.status === 'playing' && } {g.status === 'playing' && } {g.status === 'playing' && } + {g.status === 'playing' && } {g.status === 'playing' && } {g.status === 'playing' && } {g.status === 'playing' && } diff --git a/components/phase-any-bid-promises.tsx b/components/phase-any-bid-promises.tsx new file mode 100644 index 00000000..b9a2e7a6 --- /dev/null +++ b/components/phase-any-bid-promises.tsx @@ -0,0 +1,67 @@ +'use client'; + +import type { Action, GameView } from '@/game/engine'; +import { phaseAnyBidClaimText } from '@/game/phase-any-bid-promises'; +import { Button } from './ui/button'; + +type Props = { game: GameView; busy: boolean; send: (action: Action) => void }; + +/** Use only the exact server-selected declaration for the live source and owner. */ +export function PhaseAnyBidGuideButton(props: Props) { + const game = props.game, guide = game.phaseAnyBidGuide; + if (!guide) return null; + const actor = game.me, turn = game.turn, action = guide.action; + const signature = JSON.stringify(action), ordinary = game.auction, special = game.richeseAuction; + const ordinarySignature = ordinary && JSON.stringify([ordinary.bid, ordinary.bidder, ordinary.active, ordinary.remaining]); + const specialSignature = special && JSON.stringify([special.event, special.method, special.active, + special.bid, special.bidder, special.submitted, special.ownBid]); + const canAct = () => { + const current = props.game, me = current.players.find(player => player.id === actor); + if (props.busy || current !== game || current.me !== actor || current.turn !== turn || + current.status !== 'playing' || current.phase !== 3 || current.phaseAnyBidGuide !== guide || + guide.action !== action || JSON.stringify(action) !== signature || !me || me.autopilot || + current.truthtrance || current.response || current.decision || current.phaseOpening || + current.automaticContinuationPending || current.roomControl?.paused || current.roomControl?.closed || + 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.type === 'bid' || action.type === 'passBid') + return !!ordinary && current.auction === ordinary && ordinary.active === actor && + JSON.stringify([ordinary.bid, ordinary.bidder, ordinary.active, ordinary.remaining]) === ordinarySignature && + typeof action.phaseAnyBidLot === 'number' && current.bidPromiseLot?.turn === turn && + current.bidPromiseLot.lot === action.phaseAnyBidLot; + if (action.type !== 'richeseBid' || !special || current.richeseAuction !== special || + special.event !== action.event || special.event !== action.phaseAnyBidLotEvent || + JSON.stringify([special.event, special.method, special.active, special.bid, special.bidder, + special.submitted, special.ownBid]) !== specialSignature) return false; + return special.method === 'silent' ? !special.submitted.includes(actor) : special.active === actor; + }; + return ; +} + +export function PhaseAnyBidPromises(props: Props) { + const game = props.game, own = game.phaseAnyBidPromises.filter(promise => promise.player === game.me); + if (!own.length) return null; + const waiting = own.some(promise => promise.turn === game.turn && !promise.fulfilled && !promise.released); + return
+

Your any-auction bid promises

+
    {own.map(promise =>
  • + Turn {promise.turn}: You answered {promise.answer ? 'Yes' : 'No'} to {phaseAnyBidClaimText(promise)}. + {promise.released ? ' Released: this commitment is no longer possible.' + : promise.fulfilled ? ' Fulfilled: this commitment is complete.' : ' This answer is binding through this Bidding phase.'} +
  • )}
+

Yes requires a qualifying future bid while possible. No forbids qualifying bids through Bidding close. + Ordinary, Richese cache and Black Market auctions count. A bid can fulfill Yes even if another player wins; + its native funding and payment rules still apply.

+

Earlier bids do not count. The answer adds no funds or bidding opportunity. + Some combinations with other bidding commitments remain unavailable.

+ {waiting && !game.phaseAnyBidGuide &&

Your next supported opportunity may still be ahead.

} + {waiting && } +
; +} diff --git a/components/truthtrance.tsx b/components/truthtrance.tsx index d83b9160..97819c20 100644 --- a/components/truthtrance.tsx +++ b/components/truthtrance.tsx @@ -159,7 +159,7 @@ export function Truthtrance({ g.players.find((p) => p.id !== me.id)!.id, ); const [kind, setKind] = useState< - 'fact' | 'freeform' | 'charity' | 'battlePlan' | 'futureBattleLeader' | 'shipment' | 'mixedShipment' | 'movement' | 'traitorCall' | 'bid' | 'phaseBid' | 'richeseBid' | 'earlyRicheseBid' | 'revival' | 'bribe' | 'pledgeAid' | 'alliance' | 'leaderRevival' | 'gholaLeader' | 'revivalExpression' | 'bribeExpression' | 'movementExpression' | 'mixedMovement' | 'mixedBribe' | 'mixedRevival' | 'mixedBid' | 'mixedRicheseBid' | 'allianceExpression' | 'mixedAlliance' | 'mixedBattlePlan' | 'mixedTraitorCall' | 'travel' | 'turnActions' + 'fact' | 'freeform' | 'charity' | 'battlePlan' | 'futureBattleLeader' | 'shipment' | 'mixedShipment' | 'movement' | 'traitorCall' | 'bid' | 'phaseBid' | 'phaseAnyBid' | 'richeseBid' | 'earlyRicheseBid' | 'revival' | 'bribe' | 'pledgeAid' | 'alliance' | 'leaderRevival' | 'gholaLeader' | 'revivalExpression' | 'bribeExpression' | 'movementExpression' | 'mixedMovement' | 'mixedBribe' | 'mixedRevival' | 'mixedBid' | 'mixedRicheseBid' | 'allianceExpression' | 'mixedAlliance' | 'mixedBattlePlan' | 'mixedTraitorCall' | 'travel' | 'turnActions' >('fact'); const [revivalLeader, setRevivalLeader] = useState(g.allLeaders.find(leader => leader.faction === g.players.find(player => player.id === target)?.faction)?.id ?? ''); @@ -312,6 +312,7 @@ export function Truthtrance({ : kind === 'mixedRicheseBid' ? { kind, target, turn: g.turn, event: g.richeseAuction?.event ?? '', mixed: mixedBid } : kind === 'bid' ? { kind, target, ...bidClaim } : kind === 'phaseBid' ? { kind, target, ...phaseBidClaim } + : kind === 'phaseAnyBid' ? { kind, target, ...phaseBidClaim } : kind === 'earlyRicheseBid' ? { kind, target, turn:g.turn, minimum:bidMinimum } : kind === 'richeseBid' ? { kind, target, turn:g.turn, event:g.richeseAuction?.event ?? '', minimum:bidMinimum } : kind === 'charity' ? { kind, target, turn:g.turn } @@ -553,6 +554,13 @@ export function Truthtrance({ {button(`Answer ${answer === 'yes' ? 'Yes' : answer === 'no' ? 'No' : 'I don’t know'}`, { type: 'truthAnswer', answer })} )} + ) : w.question!.kind === 'phaseAnyBid' ? ( + <> +

Yes requires one qualifying accepted bid in any supported auction before this Bidding phase closes, while possible. No forbids qualifying bids in those auctions. A bid does not promise a win; the original funding and payment rules still apply. Some combinations with other bidding commitments are not yet available.

+ {(g.truthPhaseAnyBidAnswers ?? []).map(answer =>
+ {button(`Answer ${answer === 'yes' ? 'Yes' : answer === 'no' ? 'No' : 'I don’t know'}`, { type: 'truthAnswer', answer })} +
)} + ) : w.question!.kind === 'bid' ? ( <>

Yes requires one qualifying bid in this ordinary lot while possible. No forbids qualifying bids until it closes. A bid does not promise a win; winning still requires the original payment. Keep the funding needed by your answer.

@@ -719,6 +727,7 @@ export function Truthtrance({ + @@ -907,6 +916,23 @@ export function Truthtrance({ {!g.truthPhaseBidTargets.includes(target) &&

Choose a supported current-turn Bidding question and finish pending decisions.

}

{truthQuestionText(question, leaderName, locationName, name)}

+ ) : kind === 'phaseAnyBid' ? ( + <> +
+ Bid in any auction during this turn +

Turn {g.turn} · Remaining Bidding phase

+ + { + const next = event.currentTarget.valueAsNumber; + if (!busy && !phaseBidClaimInputError({turn:g.turn,minimum:next})) setBidMinimum(next); + }} /> +

One accepted qualifying bid in an ordinary, Richese cache or Black Market auction counts. Earlier bids do not count. A bid does not promise a win. Some combinations with other bidding commitments remain unavailable.

+
+ {!g.truthPhaseAnyBidTargets.includes(target) &&

Choose a supported participant and finish pending decisions before asking.

} +

{truthQuestionText(question, leaderName, locationName, name)}

+ ) : kind === 'bid' ? ( <> !!records?.some(record => group.members.includes(record.player) && !record.fulfilled && !record.released && (record.turn !== g.turn || record.answer)); - return committedBid || ![g.bidPromises, g.phaseBidPromises, g.turnActionPromises, + return committedBid || ![g.bidPromises, g.phaseBidPromises, g.phaseAnyBidPromises, g.turnActionPromises, g.revivalPromises, g.leaderRevivalPromises, g.revivalExpressionPromises].some(groupHasUnsettled) && !groupHasFundedBribe(g.bribePromises) && !groupHasFundedBribe(g.bribeExpressionPromises); } @@ -18056,6 +18059,7 @@ function basicBribeInterrupt(g: Game, p: Player): boolean { liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [], p.id, g.turn).length || liveTurnActionPromises(g.turnActionPromises ?? [], p.id, g.turn).length || livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).length || + livePhaseBidPromises(g.phaseAnyBidPromises ?? [], p.id, g.turn).length || (g.bidPromises ?? []).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.richeseBidPromises ?? []).some(row => row.player === p.id && row.turn === g.turn && !row.fulfilled && !row.released) || @@ -18354,7 +18358,8 @@ function phaseBidWitnesses(g: Game, p: Player): PhaseBidOpportunity[] { // A definite answer spends the actual held Truthtrance before Bidding. // Count its holder's newly freed slot only when that reserved card is // still in a full hand; an unknown answer retains it and binds nothing. - const committedTruth = g.truthtrance?.question?.kind === 'phaseBid' ? g.truthtrance.queue[0] : undefined; + const committedTruth = g.truthtrance?.question && ['phaseBid','phaseAnyBid'].includes(g.truthtrance.question.kind) + ? g.truthtrance.queue[0] : undefined; const holder = committedTruth && g.players.find(seat => seat.id === committedTruth.player); const freedSlot = !!holder && holder.hand.length === handLimit(holder) && holder.hand.some(card => card.id === committedTruth!.card); @@ -18535,6 +18540,7 @@ function earlyRicheseBidMaximum(g: Game, p: Player): number { } function earlyRicheseBidTruthAnswers(g: Game,p: Player,claim: EarlyRicheseBidClaim): TruthAnswer[] { if (!earlyRicheseBidWindow(g) || claim.turn !== g.turn) return []; + if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) return ['unknown']; if (richeseBidOtherPromises(g,p)) return ['unknown']; const asker = g.truthtrance?.queue[0]?.player ?? g.players.find(row => row.id !== p.id)?.id ?? g.host; const answers = earlyRicheseBidRule(() => earlyRicheseBidAnswerOptions(g.earlyRicheseBidPromises ?? [],claim,p.id,asker, @@ -18599,7 +18605,8 @@ function richeseBidOtherPromises(g: Game, p: Player): boolean { 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.phaseBidPromises ?? [],p.id,g.turn).some(row => row.answer) || + 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 @@ -18614,6 +18621,7 @@ 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); @@ -18640,6 +18648,7 @@ 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[] = []; @@ -18852,6 +18861,7 @@ function viablePhaseBidWitnesses(g: Game, p: Player, promises: readonly PhaseBid * bid impossible. If the future joint planner has no witness, a definite * answer is withheld rather than offered and rejected after binding. */ function phaseBidCompatibleLaterPromises(g: Game, p: Player): boolean { + if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) return false; if (!richeseBidCompatibleLaterPromises(g,p)) return false; const live = livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn); if (!live.some(row => row.answer)) return true; @@ -18869,7 +18879,8 @@ function phaseBidRule(run: () => T): T { catch (error) { if (error instanceof PhaseBidPromiseError) throw new RuleError(error.message); throw error; } } function phaseBidTruthAnswers(g: Game, p: Player, claim: PhaseBidClaim): TruthAnswer[] { - if (!phaseBidQuestionWindow(g) || claim.turn !== g.turn) return []; + if (!phaseBidQuestionWindow(g) || claim.turn !== g.turn || + livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) return []; const base = g.phaseBidPromises ?? []; const answers: TruthAnswer[] = []; for (const answer of [true, false]) { @@ -18900,9 +18911,11 @@ function bindPhaseBidTruth(g: Game, p: Player, claim: PhaseBidClaim, answer: boo } function phaseBidIntegrity(g: Game) { phaseBidRule(() => validatePhaseBidPromises(g.phaseBidPromises ?? [],g.players.map(player => player.id))); + phaseAnyBidIntegrity(g); } function reconcilePhaseBids(g: Game, voluntary?: {actor:string;action:Action}) { phaseBidIntegrity(g); + reconcilePhaseAnyBids(g,voluntary); if (!g.phaseBidPromises?.length || g.truthtrance || g.response || g.decision || g.phaseOpening || g.pendingTreacheryDiscard || g.pendingKarama || g.pendingKull || g.pendingRicheseBetrayal) return; for (const player of g.players) { @@ -18949,6 +18962,112 @@ function projectedPhaseBidGuide(g: Game, player: string): {action:Action} | null } return {action:{...action,phaseBidPromiseEvent:live[0].event,phaseBidPromiseLot:opportunity.lot}}; } +/** A current special-lot witness uses only this seat's own escrow and + * eligibility. In particular it never reads another player's sealed bid. */ +function phaseAnySpecialOpportunity(g: Game, p: Player): PhaseBidOpportunity | null { + const lot = g.richeseAuction; + if (!lot || g.status !== 'playing' || g.phase !== 3 || lot.outcome || g.response || g.decision || + g.phaseOpening || g.pendingKarama || g.pendingTreacheryDiscard || g.pendingKull || + !lot.eligible.includes(p.id) || !richeseBidFitsHand(lot.source,lot.owner,p.id,p.hand.length,handLimit(p))) return null; + if (lot.method === 'silent' ? Object.hasOwn(lot.sealed,p.id) : + lot.method === 'onceAround' ? lot.acted.includes(p.id) || p.id === lot.owner && lot.active !== p.id && !lot.bidder : + lot.passed.includes(p.id) || lot.bidder === p.id) return null; + if (lot.method !== 'silent' && lot.bid >= Number.MAX_SAFE_INTEGER) return null; + const minimum = lot.method === 'silent' ? 1 : lot.bid + 1; + const maximum = Math.min(Number.MAX_SAFE_INTEGER, uncommittedSpice(g,p) + + richeseOwnCommitment(lot,g.richeseFunding ?? {},p.id) + (aidFor(g,p)?.amount ?? 0)); + return Number.isSafeInteger(maximum) && maximum >= minimum + ? {turn:g.turn,player:p.id,kind:'current',minimum,maximum} : null; +} +function phaseAnyBidWindow(g: Game): boolean { + return g.status === 'playing' && g.phase >= 0 && g.phase <= 3 && phaseBidPromiseModeSupported(g) && + !g.response && !g.decision && !g.phaseOpening && !g.pendingKarama && !g.pendingTreacheryDiscard && + !g.pendingKull && !g.ixAuction && !g.currentAuctionSale && + (g.phase < 3 || !!bidOpportunity(g) || !!g.richeseAuction && !g.richeseAuction.outcome); +} +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.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) || + liveEarlyRicheseBidPromises(g.earlyRicheseBidPromises ?? [],p.id,g.turn).length > 0 || + phaseBidFuturePlannerUnsupported(g,p); +} +/** A completed Black Market offer is followed by Richese's real cache lot. + * Reserve this player's possibly winning card and its own committed funds; + * do not speculate about any rival's Silent bid or a future refund. */ +function phaseAnyFutureCache(g: Game, p: Player): PhaseBidOpportunity | null { + const lot = g.richeseAuction, round = g.richeseBidding; + if (g.phase !== 3 || !lot || lot.source !== 'blackMarket' || !round || round.turn !== g.turn || + round.cacheCanceled || round.stage === 'complete' || !(g.richeseCache?.length)) return null; + const ownOffer = lot.outcome?.kind === 'sold' ? lot.outcome.winner === p.id : !lot.outcome && + (lot.method === 'silent' ? (lot.sealed[p.id] ?? 0) > 0 : lot.bidder === p.id); + const addedCards = ownOffer && lot.owner !== p.id ? 1 + Number(p.faction === 'harkonnen') : 0; + if (p.hand.length + addedCards >= handLimit(p)) return null; + const lockedAid = ownOffer ? (g.richeseFunding?.[p.id]?.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; +} +function phaseAnyBidWitnesses(g: Game, p: Player, promises: readonly PhaseBidPromise[]): PhaseBidOpportunity[] { + const special = phaseAnySpecialOpportunity(g,p); + const futureCache = phaseAnyFutureCache(g,p); + const ordinary = viablePhaseBidWitnesses(g,p,promises); + return [...(special ? [special] : []),...(futureCache ? [futureCache] : []),...ordinary]; +} +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'}]; + return !livePhaseBidPromises(all,p.id,g.turn).some(row => row.answer) || + phaseAnyBidWitnesses(g,p,all).some(witness => !!phaseBidCompletionRange(all,witness)); + }); +} +function bindPhaseAnyBidTruth(g: Game,p: Player,claim: PhaseBidClaim,answer: boolean,asker: string): void { + requireRule(phaseAnyBidTruthAnswers(g,p,claim).includes(answer ? 'yes' : 'no'), + 'This all-auction bid answer no longer has a legal completion.'); + (g.phaseAnyBidPromises ??= []).push({...claim,event:crypto.randomUUID(),player:p.id,asker,answer}); +} +function phaseAnyBidIntegrity(g: Game): void { + phaseBidRule(() => validatePhaseBidPromises(g.phaseAnyBidPromises ?? [],g.players.map(player => player.id))); +} +function reconcilePhaseAnyBids(g: Game,voluntary?: {actor:string;action:Action}): void { + phaseAnyBidIntegrity(g); + if (!g.phaseAnyBidPromises?.length || g.truthtrance || g.response || g.decision || g.phaseOpening || + g.pendingTreacheryDiscard || g.pendingKarama || g.pendingKull || g.pendingRicheseBetrayal) return; + for (const p of g.players) { + const live = livePhaseBidPromises(g.phaseAnyBidPromises,p.id,g.turn); + if (!live.length) continue; + const change = voluntary?.actor === p.id ? 'voluntary' : 'external'; + if (g.phase > 3) g.phaseAnyBidPromises = phaseBidRule(() => finishPhaseBidPhase(g.phaseAnyBidPromises!,p.id,g.turn,change)); + else g.phaseAnyBidPromises = phaseBidRule(() => reconcilePhaseBidPromises(g.phaseAnyBidPromises!,p.id,g.turn, + phaseAnyBidWitnesses(g,p,g.phaseAnyBidPromises!),change)); + } +} +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; + 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 lot = g.richeseAuction; + if (!lot || (lot.method === 'silent' ? Object.hasOwn(lot.sealed,id) : lot.active !== id)) return null; + const required = live.some(row => row.answer), opportunity = phaseAnySpecialOpportunity(g,p); + const range = opportunity && phaseBidCompletionRange(live,opportunity); + if (required && !range) return null; + const amount = required ? range!.minimum : lot.method === 'silent' ? 0 : null; + const own = uncommittedSpice(g,p) + richeseOwnCommitment(lot,g.richeseFunding ?? {},id); + return {action:{type:'richeseBid',event:lot.event,amount, + allyPayment:amount === null ? 0 : Math.max(0,amount-own),phaseAnyBidPromiseEvent:live[0].event, + phaseAnyBidLotEvent:lot.event}}; +} function bidPromiseCompletion(g: Game, p: Player, promises = g.bidPromises ?? []): Action | null { const opportunity = bidOpportunity(g); if (!opportunity) return null; @@ -18986,6 +19105,7 @@ 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); @@ -19027,6 +19147,7 @@ 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]) { @@ -19112,6 +19233,18 @@ function guardPromisedBid(g: Game, p: Player, action: Action, amount?: number) { if (action.bidPromiseEvent !== undefined) requireRule(typeof action.bidPromiseEvent === 'string' && live.some(promise => promise.event === action.bidPromiseEvent), 'This bid commitment guide is stale.'); if (!opportunity) return; + if (amount !== undefined && livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) + g.phaseAnyBidPromises = phaseBidRule(() => recordPhaseBid(g.phaseAnyBidPromises!,p.id,g.turn,amount)); + if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).some(row => row.answer)) { + const trial = structuredClone(g); + if (amount !== undefined) { + trial.auction!.bid = amount; trial.auction!.bidder = p.id; + trial.auction!.allyPayment = normalBidQuote(g,p,amount,action.allyPayment).allyPayment; + } 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)); + requireRule(future, 'Keep a funded later lot or place the bid required by your Truthtrance Yes.'); + } const phaseLive = livePhaseBidPromises(g.phaseBidPromises ?? [],p.id,g.turn); if (amount !== undefined && phaseLive.length) g.phaseBidPromises = phaseBidRule(() => recordPhaseBid(g.phaseBidPromises!,p.id,g.turn,amount)); @@ -19254,9 +19387,10 @@ export function advanceAuctionClock(source: Game, now: number, controlEpoch: str if (!(error instanceof RuleError)) throw error; if (lot) { const context = {turn:game.turn,event:lot.event,player:actor}; - const required = richeseBidRequired(game.richeseBidPromises ?? [], context); + const required = richeseBidRequired(game.richeseBidPromises ?? [], context) || + livePhaseBidPromises(game.phaseAnyBidPromises ?? [],actor,game.turn).some(row => row.answer); if (!required) throw error; - const completion = projectedRicheseBidGuide(game, actor)?.action; + const completion = projectedPhaseAnyBidGuide(game, actor)?.action ?? projectedRicheseBidGuide(game, actor)?.action; requireRule(completion?.type === 'richeseBid', 'The expired Richese bid needs a legal completion of its binding Truthtrance answer.'); next = applyAction(game, actor, completion); @@ -19266,7 +19400,7 @@ export function advanceAuctionClock(source: Game, now: number, controlEpoch: str ? turnActionCompletion(game, actor)?.bid : undefined; const opportunity = bidOpportunity(game); const required = opportunity && bidRequired(game.bidPromises ?? [], actor, opportunity); - const phaseGuide = projectedPhaseBidGuide(game, actor)?.action; + const phaseGuide = projectedPhaseAnyBidGuide(game,actor)?.action ?? projectedPhaseBidGuide(game, actor)?.action; if (!whole && !required && phaseGuide?.type !== 'bid') throw error; const completion = phaseGuide?.type === 'bid' ? phaseGuide : minimumCompelledAuctionBid(game, actor); requireRule(completion, 'The expired ordinary bid needs a legal completion of its binding Truthtrance answer.'); @@ -19423,7 +19557,8 @@ function emperorAuctionGiftMaximum(g: Game, p: Player): number { liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [], p.id, g.turn).some(row => row.answer) || liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [], p.id, g.turn).some(row => row.answer) || liveTurnActionPromises(g.turnActionPromises ?? [], p.id, g.turn).length || - livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer)) return 0; + livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer) || + livePhaseBidPromises(g.phaseAnyBidPromises ?? [], p.id, g.turn).some(row => row.answer)) return 0; const maximum = Math.max(0, uncommittedSpice(g, p)); if (!livePledgePromises(g.pledgePromises ?? [], p.id, g.turn, g.phase).some(row => row.answer)) return maximum; // The owner can fulfill the native update within this opportunity, before @@ -21532,7 +21667,7 @@ function choamMarketSkipCommitments(g: Game): boolean { !!rows?.some(row => row.turn === g.turn); return !!g.truthHistory?.some(row => row.turn === g.turn) || recorded(g.travelPromises) || recorded(g.turnActionPromises) || recorded(g.shipmentPromises) || - recorded(g.bidPromises) || recorded(g.phaseBidPromises) || recorded(g.revivalPromises) || + recorded(g.bidPromises) || recorded(g.phaseBidPromises) || recorded(g.phaseAnyBidPromises) || recorded(g.revivalPromises) || recorded(g.leaderRevivalPromises) || recorded(g.revivalExpressionPromises) || recorded(g.bribePromises) || recorded(g.bribeExpressionPromises) || recorded(g.pledgePromises) || recorded(g.alliancePromises) || recorded(g.allianceExpressionPromises) || recorded(g.movementPromises) || recorded(g.movementExpressionPromises) || @@ -24227,6 +24362,7 @@ function turnActionTruthAnswers(g: Game, p: Player, claim: TurnActionClaim): Tru try { promise = turnActionPromise(g, p, claim, answer, 'candidate', g.players.find(other => other.id !== p.id)!.id); } catch (error) { if (error instanceof RuleError) continue; throw error; } if (promise.compiled.kind === 'constant' && promise.compiled.value !== answer) continue; + if (promise.compiled.kind !== 'constant' && livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) continue; const trial = { ...turnActionAnswerSource(g, p.id, !!promise.alliance, !!promise.windowCards, { claim, answer }), turnActionPromises: [...(g.turnActionPromises ?? []), promise], travelPromiseOrder: undefined }; if (!richeseBidCompatibleLaterPromises(trial,p) && promise.compiled.kind !== 'constant') continue; @@ -30944,7 +31080,8 @@ function emperorGuildTimingGiftQuote(g: Game, p: Player): {recipient: string; ma liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [], p.id, g.turn).some(row => row.answer) || liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [], p.id, g.turn).some(row => row.answer) || liveTurnActionPromises(g.turnActionPromises ?? [], p.id, g.turn).length || - livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer)) return null; + (livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer) || + livePhaseBidPromises(g.phaseAnyBidPromises ?? [], p.id, g.turn).some(row => row.answer))) return null; const maximum = Math.max(0, uncommittedSpice(g, p)); return maximum > 0 ? { recipient: p.ally, maximum } : null; } @@ -31043,7 +31180,8 @@ function emperorPhaseOpeningGiftQuote(g: Game, p: Player): {recipient: string; m liveLeaderRevivalPromises(g.leaderRevivalPromises ?? [], p.id, g.turn).some(row => row.answer) || liveRevivalExpressionPromises(g.revivalExpressionPromises ?? [], p.id, g.turn).some(row => row.answer) || liveTurnActionPromises(g.turnActionPromises ?? [], p.id, g.turn).length || - livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer)) return null; + livePhaseBidPromises(g.phaseBidPromises ?? [], p.id, g.turn).some(row => row.answer) || + livePhaseBidPromises(g.phaseAnyBidPromises ?? [], p.id, g.turn).some(row => row.answer)) return null; const maximum = Math.max(0, uncommittedSpice(g, p)); return maximum > 0 ? {recipient: p.ally, maximum} : null; } @@ -34906,7 +35044,7 @@ function futureBattleLeaderTruthAnswers(g: Game, p: Player, q: FutureBattleLeade ...(g.travelPromises ?? []), ...(g.shipmentPromises ?? []), ...(g.movementPromises ?? []), ...(g.movementExpressionPromises ?? []), ...(g.bribePromises ?? []), ...(g.bribeExpressionPromises ?? []), ...(g.revivalPromises ?? []), ...(g.leaderRevivalPromises ?? []), ...(g.revivalExpressionPromises ?? []), - ...(g.bidPromises ?? []), ...(g.phaseBidPromises ?? []), ...(g.richeseBidPromises ?? []), + ...(g.bidPromises ?? []), ...(g.phaseBidPromises ?? []), ...(g.phaseAnyBidPromises ?? []), ...(g.richeseBidPromises ?? []), ...(g.earlyRicheseBidPromises ?? []), ...(g.alliancePromises ?? []), ...(g.allianceExpressionPromises ?? []), ]; if (q.turn !== g.turn || q.target !== p.id || !futureBattleLeaderTiming(g) || @@ -44460,6 +44598,12 @@ function applyActionWithInitiator(state: Game, id: string, action: Action, initi Object.keys(guide.action).every(key => action[key] === guide.action[key]), 'This phase bid guide is stale or belongs to another auction lot.'); } + if (action.phaseAnyBidPromiseEvent !== undefined || action.phaseAnyBidLot !== undefined || action.phaseAnyBidLotEvent !== undefined) { + const guide = projectedPhaseAnyBidGuide(state,id); + requireRule(guide && Object.keys(action).sort().join(',') === Object.keys(guide.action).sort().join(',') && + Object.keys(guide.action).every(key => action[key] === guide.action[key]), + 'This all-auction bid guide is stale or belongs to another lot.'); + } if (action.charityPromiseEvent !== undefined || action.charityPromiseTurn !== undefined) { const guide = projectedCharityTruthGuide(state,id); requireRule(guide && Object.keys(action).sort().join(',') === Object.keys(guide.action).sort().join(',') && @@ -44488,6 +44632,18 @@ function applyActionWithInitiator(state: Game, id: string, action: Action, initi // turn that forced debit into the passer's voluntary payment or expenditure. const voluntary = forcedThumperDraw || action.type === 'passResponse' ? undefined : { actor: id, action }; const pledgeVoluntary = initiator === id ? voluntary : undefined; + // A paid Box can leave a private selection open after spending spice. Quote + // both its cost and later selection before that pending decision can hide + // the loss of this player's last all-auction bid witness. + if (voluntary && livePhaseBidPromises(state.phaseAnyBidPromises ?? [],id,state.turn).some(row => row.answer) && + (state.pendingNullentropy?.player === id || g.pendingNullentropy?.player === id)) { + const trial = structuredClone(g), owner = getPlayer(trial,id); + trial.truthtrance = null; trial.response = null; trial.decision = null; + trial.phaseOpening = null; trial.pendingTreacheryDiscard = null; trial.pendingKarama = null; + requireRule(phaseAnyBidWitnesses(trial,owner,trial.phaseAnyBidPromises ?? []) + .some(witness => !!phaseBidCompletionRange(trial.phaseAnyBidPromises ?? [],witness)), + 'Keep a funded bid available while completing the paid Box search.'); + } // Voluntary actions may create a response owned by somebody else before the // regular reconciler can run. Quote the already-completed action on a // detached state before that response can hide loss of the last witness. @@ -45476,6 +45632,8 @@ function applyActionInner( bindEarlyRicheseBid: bindEarlyRicheseBidTruth, phaseBidAnswers: phaseBidTruthAnswers, bindPhaseBid: bindPhaseBidTruth, + phaseAnyBidAnswers: phaseAnyBidTruthAnswers, + bindPhaseAnyBid: bindPhaseAnyBidTruth, turnActionAnswers: turnActionTruthAnswers, bindTurnAction: bindTurnActionTruth, travelAnswers: travelTruthAnswers, @@ -48310,6 +48468,8 @@ function applyActionInner( if ((lot.method === 'onceAround' || lot.method === 'silent') && g.richeseBidPromises?.length) g.richeseBidPromises = richeseBidRule(() => recordRicheseBid(g.richeseBidPromises!, {turn:g.turn,event:lot.event,player:p.id},lot.method === 'silent' && amount === 0 ? null : amount)); + if (amount !== null && amount > 0 && livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).length) + g.phaseAnyBidPromises = phaseBidRule(() => recordPhaseBid(g.phaseAnyBidPromises!,p.id,g.turn,amount)); g.richeseAuction = submitRicheseBid( lot, { event: stringField(action.event), actor: p.id, amount }, @@ -48321,6 +48481,11 @@ function applyActionInner( allyPayment, donor: allyPayment ? p.ally : null, }; + if (livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).some(row => row.answer)) { + const future = phaseAnyBidWitnesses(g,p,g.phaseAnyBidPromises ?? []) + .some(witness => witness.kind === 'future' && !!phaseBidCompletionRange(g.phaseAnyBidPromises ?? [],witness)); + requireRule(future, 'Keep a funded later lot or place the bid required by your Truthtrance Yes.'); + } g.active = g.richeseAuction.active; log( g, @@ -48410,6 +48575,13 @@ function applyActionInner( maximum, t === 'emperorGift' ? 'Spice' : 'Forces', ); + if (t === 'emperorGift' && livePhaseBidPromises(g.phaseAnyBidPromises ?? [],p.id,g.turn).some(row => row.answer)) { + const trial = structuredClone(g), owner = getPlayer(trial,p.id); + owner.spice -= amount; + requireRule(phaseAnyBidWitnesses(trial,owner,trial.phaseAnyBidPromises ?? []) + .some(witness => !!phaseBidCompletionRange(trial.phaseAnyBidPromises ?? [],witness)), + 'Keep enough spice for your Truthtrance bid answer.'); + } const elite = t === 'emperorRevival' ? eliteChoice( @@ -49970,6 +50142,11 @@ export function viewGame(state: Game, id: string, now?: number) { g.truthtrance.question.kind === 'phaseBid' ? phaseBidTruthAnswers(g,me,g.truthtrance.question) : null, phaseBidPromises: projectedPhaseBidPromises(g,id), phaseBidPromiseGuide: projectedPhaseBidGuide(g,id), + truthPhaseAnyBidTargets: phaseAnyBidWindow(g) ? g.players.map(player => player.id) : [], + truthPhaseAnyBidAnswers: g.truthtrance?.stage === 'answer' && g.truthtrance.question?.target === id && + g.truthtrance.question.kind === 'phaseAnyBid' ? phaseAnyBidTruthAnswers(g,me,g.truthtrance.question) : null, + phaseAnyBidPromises: (g.phaseAnyBidPromises ?? []).filter(row => row.player === id).map(row => ({...row})), + phaseAnyBidGuide: projectedPhaseAnyBidGuide(g,id), alliancePromiseNexus: (() => { const nexus = allianceOpportunity(g); return nexus ? { turn: nexus.turn } : null; })(), truthAllianceTargets: allianceQuestionWindow(g) ? g.players.map(player => player.id) : [], truthAllianceAnswers: g.truthtrance?.stage === 'answer' && g.truthtrance.question?.target === id && diff --git a/game/phase-any-bid-promises.ts b/game/phase-any-bid-promises.ts new file mode 100644 index 00000000..9ecf302d --- /dev/null +++ b/game/phase-any-bid-promises.ts @@ -0,0 +1,39 @@ +import { + PhaseBidPromiseError, + phaseBidPromiseModeSupported, + type PhaseBidClaim, + type PhaseBidOpportunity, + type PhaseBidPromise, +} from './turn-bid-promises'; + +/** A new, separate receipt: unlike legacy phaseBid, a qualifying declaration + * can occur in an ordinary, Richese cache, or Black Market auction. */ +export type PhaseAnyBidClaim = PhaseBidClaim; +export type PhaseAnyBidPromise = PhaseBidPromise; +export type PhaseAnyBidOpportunity = PhaseBidOpportunity; +export { PhaseBidPromiseError as PhaseAnyBidPromiseError }; +export { + livePhaseBidPromises as livePhaseAnyBidPromises, + phaseBidAllowedRange as phaseAnyBidAllowedRange, + phaseBidCompletionRange as phaseAnyBidCompletionRange, + recordPhaseBid as recordPhaseAnyBid, + reconcilePhaseBidPromises as reconcilePhaseAnyBidPromises, + finishPhaseBidPhase as finishPhaseAnyBidPhase, + validatePhaseBidPromises as validatePhaseAnyBidPromises, +} from './turn-bid-promises'; + +export const phaseAnyBidPromiseModeSupported = phaseBidPromiseModeSupported; + +export function parsePhaseAnyBidClaim(value: unknown): PhaseAnyBidClaim { + if (!value || typeof value !== 'object' || Array.isArray(value)) + throw new PhaseBidPromiseError('Choose a Bidding phase bid question.'); + const input = value as Record; + if (typeof input.turn !== 'number' || !Number.isSafeInteger(input.turn) || input.turn <= 0 || + typeof input.minimum !== 'number' || !Number.isSafeInteger(input.minimum) || input.minimum <= 0) + throw new PhaseBidPromiseError('Choose the current turn and a positive whole bid minimum.'); + return {turn:input.turn, minimum:input.minimum}; +} + +export function phaseAnyBidClaimText(claim: PhaseAnyBidClaim): string { + return `place a bid of at least ${claim.minimum} spice in an ordinary, Richese cache, or Black Market auction from now until this turn's Bidding phase closes`; +} diff --git a/game/reference.ts b/game/reference.ts index 76b15078..ad1b796e 100644 --- a/game/reference.ts +++ b/game/reference.ts @@ -3788,6 +3788,7 @@ export const RULE_TOPICS: RuleTopic[] = [ 'Choose Bind a bid in this ordinary lot, another remaining eligible bidder and a positive whole spice minimum. The turn and lot are fixed. Registered native Basic and Advanced tables without optional modules are supported first; broader compositions remain unfinished.', '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.', '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/game/richese-reveal-interruption.ts b/game/richese-reveal-interruption.ts index bbd29233..c959724a 100644 --- a/game/richese-reveal-interruption.ts +++ b/game/richese-reveal-interruption.ts @@ -98,7 +98,7 @@ export function richeseRevealInterruptSupported(g: Game): boolean { const live = (rows: readonly {turn: number; fulfilled?: boolean; released?: boolean}[] | undefined) => !!rows?.some(row => row.turn === g.turn && !row.fulfilled && !row.released); if (live(g.charityPromises) || live(g.travelPromises) || live(g.turnActionPromises) || - live(g.shipmentPromises) || live(g.bidPromises) || live(g.phaseBidPromises) || + live(g.shipmentPromises) || live(g.bidPromises) || live(g.phaseBidPromises) || live(g.phaseAnyBidPromises) || live(g.richeseBidPromises) || live(g.earlyRicheseBidPromises) || live(g.revivalPromises) || live(g.leaderRevivalPromises) || live(g.revivalExpressionPromises) || live(g.bribePromises) || live(g.pledgePromises) || live(g.bribeExpressionPromises) || live(g.alliancePromises) || diff --git a/game/truthtrance.ts b/game/truthtrance.ts index 0dcf2f46..e8bfd1cd 100644 --- a/game/truthtrance.ts +++ b/game/truthtrance.ts @@ -89,6 +89,7 @@ import { parseNoFieldValueFact, noFieldValueFactMatches, noFieldValueFactText, t import { parseFaceDancerFact, faceDancerFactMatches, faceDancerFactText, type FaceDancerFact } from './truthtrance-face-dancer'; import { parseBidClaim, bidClaimText, bidPromiseModeSupported, currentBidPromiseModeSupported, type BidClaim } from './bid-promises'; import { parsePhaseBidClaim, phaseBidClaimText, phaseBidPromiseModeSupported, type PhaseBidClaim } from './turn-bid-promises'; +import { parsePhaseAnyBidClaim, phaseAnyBidClaimText, phaseAnyBidPromiseModeSupported, type PhaseAnyBidClaim } from './phase-any-bid-promises'; import { parseRicheseBidClaim, richeseBidClaimText, type RicheseBidClaim } from './richese-bid-promises'; import { parseEarlyRicheseBidClaim, earlyRicheseBidClaimText, type EarlyRicheseBidClaim } from './early-richese-bid'; @@ -128,6 +129,7 @@ export type TruthQuestion = | ({ kind: 'revival'; target: string } & RevivalClaim) | ({ kind: 'bid'; target: string } & BidClaim) | ({ kind: 'phaseBid'; target: string } & PhaseBidClaim) + | ({ kind: 'phaseAnyBid'; target: string } & PhaseAnyBidClaim) | ({ kind: 'richeseBid'; target: string } & RicheseBidClaim) | ({ kind: 'earlyRicheseBid'; target: string } & EarlyRicheseBidClaim) | { kind: 'traitorCall'; target: string; battle: string; territory: string } @@ -488,6 +490,19 @@ function parseQuestion(g: Game, asker: string, value: unknown): TruthQuestion { 'Choose the current turn and a quiet supported ordinary Bidding opportunity.'); return { kind: 'phaseBid', target: v.target, ...claim }; } + if (v.kind === 'phaseAnyBid') { + check(Object.keys(v).sort().join(',') === 'kind,minimum,target,turn', + 'Supply the current turn, phase bid minimum and respondent.'); + const claim = parsePhaseAnyBidClaim(v), lot = g.richeseAuction; + check(phaseAnyBidPromiseModeSupported(g) && g.status === 'playing' && Number.isInteger(g.phase) && + g.phase >= 0 && g.phase <= 3 && claim.turn === g.turn && !g.currentAuctionSale && !g.ixAuction && + (g.phase < 3 || !!g.auction && !lot || !!lot && !lot.outcome && !g.auction && + (lot.method === 'normal' || lot.method === 'onceAround' || lot.method === 'silent')) && + !g.response && !g.decision && !g.phaseOpening && !g.pendingRevival && !g.pendingKull && + !g.pendingKarama && !g.pendingTreacheryDiscard, + 'Choose a quiet supported current-turn Bidding opportunity.'); + return {kind:'phaseAnyBid',target:v.target,...claim}; + } if (v.kind === 'mixedBid') { check(Object.keys(v).sort().join(',') === 'kind,lot,mixed,target,turn', 'Supply the current ordinary lot, turn, complete mixed bid question and respondent.'); @@ -949,6 +964,7 @@ export function truthQuestionText( if (q.kind === 'revival') return `Will you ${revivalClaimText(q)}?`; if (q.kind === 'bid') return `Will you ${bidClaimText(q)}?`; if (q.kind === 'phaseBid') return `Will you ${phaseBidClaimText(q)}?`; + if (q.kind === 'phaseAnyBid') return `Will you ${phaseAnyBidClaimText(q)}?`; if (q.kind === 'richeseBid') return `Will you ${richeseBidClaimText(q)}?`; if (q.kind === 'earlyRicheseBid') return `Will you ${earlyRicheseBidClaimText(q)}?`; if (q.kind === 'traitorCall') return `In this revealed battle in ${locationName(q.territory)}, will you declare the opposing leader a Traitor?`; @@ -1114,6 +1130,8 @@ export function resolveTruthAction( bindEarlyRicheseBid?: (g: Game, p: Player, claim: EarlyRicheseBidClaim, answer: boolean, asker: string) => void; phaseBidAnswers?: (g: Game, p: Player, claim: PhaseBidClaim) => TruthAnswer[]; bindPhaseBid?: (g: Game, p: Player, claim: PhaseBidClaim, answer: boolean, asker: string) => void; + phaseAnyBidAnswers?: (g: Game, p: Player, claim: PhaseAnyBidClaim) => TruthAnswer[]; + bindPhaseAnyBid?: (g: Game, p: Player, claim: PhaseAnyBidClaim, answer: boolean, asker: string) => void; travelAnswers?: (g: Game, p: Player, claim: TravelClaim) => TruthAnswer[]; bindTravel?: (g: Game, p: Player, claim: TravelClaim, answer: boolean, asker: string) => void; turnActionAnswers?: (g: Game, p: Player, claim: TurnActionClaim) => TruthAnswer[]; @@ -1361,6 +1379,9 @@ export function resolveTruthAction( if (w.question.kind === 'phaseBid') check(effects.phaseBidAnswers?.(g, g.players.find(other => other.id === w.question!.target)!, w.question).length, 'Choose a phase bid question compatible with supported native opportunities and earlier answers.'); + if (w.question.kind === 'phaseAnyBid') + check(effects.phaseAnyBidAnswers?.(g, g.players.find(other => other.id === w.question!.target)!, w.question).length, + 'Choose a phase bid question compatible with supported native opportunities and earlier answers.'); if (w.question.kind === 'travel') check(effects.travelAnswers?.(g, g.players.find(other => other.id === w.question!.target)!, w.question).length, 'Choose an unused or active native Shipment and Movement opportunity.'); @@ -1526,6 +1547,11 @@ export function resolveTruthAction( 'Choose an answer consistent with native bids and earlier phase commitments.'); if (a.answer !== 'unknown') effects.bindPhaseBid(g, p, q, a.answer === 'yes', current.player); } + if (q.kind === 'phaseAnyBid') { + check(effects.phaseAnyBidAnswers && effects.bindPhaseAnyBid && effects.phaseAnyBidAnswers(g, p, q).includes(a.answer), + 'Choose an answer consistent with native bids and earlier phase commitments.'); + if (a.answer !== 'unknown') effects.bindPhaseAnyBid(g, p, q, a.answer === 'yes', current.player); + } if (q.kind === 'travel') { check(effects.travelAnswers && effects.bindTravel && effects.travelAnswers(g, p, q).includes(a.answer), 'Choose a whole travel answer compatible with native actions and earlier commitments.'); diff --git a/tests/phase-any-bid-controls.test.tsx b/tests/phase-any-bid-controls.test.tsx new file mode 100644 index 00000000..e19f8835 --- /dev/null +++ b/tests/phase-any-bid-controls.test.tsx @@ -0,0 +1,59 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createElement } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; +import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises'; +import { createGame, joinGame, newPlayer, viewGame, type Action, type GameView } from '../game/engine'; +import { createRicheseAuction, projectRicheseAuction } from '../game/richese-auction'; + +/** Controlled view tests verify only display and exact callback guards; native + * public-start question, auction and payment evidence belongs to runtime tests. */ +function projected(): GameView { + const source = createGame('PHASEANYBIDCONTROLS',newPlayer('p','Respondent','emperor'),false); + joinGame(source,newPlayer('a','Asker','atreides')); + const game = viewGame(source,'p'); + game.status = 'playing'; game.phase = 3; game.turn = 2; + game.auction = {bid:1,bidder:'a',active:'p',remaining:2,inspectionBlocked:null,card:null}; + game.bidPromiseLot = {turn:2,lot:1}; + game.phaseAnyBidPromises = [{turn:2,minimum:4,event:'promise',player:'p',asker:'a',answer:true}]; + game.phaseAnyBidGuide = {action:{type:'bid',amount:4,allyPayment:0, + phaseAnyBidPromiseEvent:'promise',phaseAnyBidLot:1}}; + return game; +} + +void test('any-auction promise describes all auction sources and exact owned ordinary guide', () => { + const game = projected(), sent: Action[] = []; + const markup = renderToStaticMarkup(createElement(PhaseAnyBidPromises,{game,busy:false,send() {}})); + assert.match(markup,/ordinary, Richese cache, or Black Market auction/); + assert.match(markup,/Some combinations with other bidding commitments remain unavailable/); + const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); + button.props.onClick(); assert.deepEqual(sent,[game.phaseAnyBidGuide!.action]); + game.auction!.bid = 2; button.props.onClick(); assert.equal(sent.length,1); +}); + +void test('busy, completed, wrong owner and stale ordinary guide callbacks do not send', () => { + const game = projected(), sent: Action[] = []; + const busy = PhaseAnyBidGuideButton({game,busy:true,send:action => sent.push(action)}); assert.ok(busy); + assert.equal(busy.props.disabled,true); busy.props.onClick(); + const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); + game.phaseAnyBidPromises[0].fulfilled = true; button.props.onClick(); + game.phaseAnyBidPromises[0].fulfilled = false; game.auction!.active = 'a'; button.props.onClick(); + game.auction!.active = 'p'; game.bidPromiseLot!.lot = 2; button.props.onClick(); + assert.deepEqual(sent,[]); +}); + +for (const method of ['onceAround','silent'] as const) void test(`the ${method} guide checks its exact Richese lot and submission state`, () => { + const game = projected(), sent: Action[] = []; + game.auction = null; + const native = createRicheseAuction({event:'lot',cardId:'card',source:'cache',owner:'a',method, + eligible:['p','a'],order:['p','a'],tieOrder:['p','a']}); + game.richeseAuction = {...projectRicheseAuction(native,'p'),card:null,claim:null, + ownAllyPayment:0,ownAvailable:5,allyAvailable:0,peekKnown:false,inspectionBlocked:null}; + game.phaseAnyBidGuide = {action:{type:'richeseBid',event:'lot',amount:4,allyPayment:0, + phaseAnyBidPromiseEvent:'promise',phaseAnyBidLotEvent:'lot'}}; + const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); + button.props.onClick(); assert.equal(sent.length,1); + if (method === 'silent') game.richeseAuction.submitted.push('p'); + else game.richeseAuction.active = 'a'; + button.props.onClick(); assert.equal(sent.length,1); +}); diff --git a/tests/phase-any-bid-promises.test.ts b/tests/phase-any-bid-promises.test.ts new file mode 100644 index 00000000..8215c4d8 --- /dev/null +++ b/tests/phase-any-bid-promises.test.ts @@ -0,0 +1,48 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { + PhaseAnyBidPromiseError, finishPhaseAnyBidPhase, parsePhaseAnyBidClaim, + phaseAnyBidClaimText, phaseAnyBidCompletionRange, recordPhaseAnyBid, + reconcilePhaseAnyBidPromises, validatePhaseAnyBidPromises, + type PhaseAnyBidPromise, +} from '../game/phase-any-bid-promises'; +import { truthQuestionText, validateTruthQuestionReceipt, type TruthQuestion } from '../game/truthtrance'; +import { createTruthRicheseBidFixture } from './fixture-truth-richese-bid'; + +const row = (event:string, minimum:number, answer:boolean): PhaseAnyBidPromise => + ({event,minimum,answer,turn:2,player:'p',asker:'a'}); + +void test('all-auction claim validates a safe threshold and explicitly includes special lots', () => { + const claim = parsePhaseAnyBidClaim({turn:2,minimum:5}); + assert.deepEqual(claim,{turn:2,minimum:5}); + assert.match(phaseAnyBidClaimText(claim),/ordinary, Richese cache, or Black Market auction/); + for (const value of [null, [], {}, {turn:2,minimum:0}, {turn:NaN,minimum:1}, + {turn:2,minimum:Number.MAX_SAFE_INTEGER+1}, {turn:'2',minimum:1}]) + assert.throws(() => parsePhaseAnyBidClaim(value),PhaseAnyBidPromiseError); +}); + +void test('all-auction ledger preserves distinct physical declarations and No restrictions', () => { + const source = [row('yes',5,true),row('no',8,false)]; + assert.doesNotThrow(() => validatePhaseAnyBidPromises(source,['p','a'])); + const opportunity = {turn:2,player:'p',kind:'current' as const,minimum:2,maximum:9}; + assert.deepEqual(phaseAnyBidCompletionRange(source,opportunity),{minimum:5,maximum:7}); + const small = recordPhaseAnyBid(source,'p',2,3); + assert.equal(small[0].fulfilled,undefined); + assert.throws(() => recordPhaseAnyBid(small,'p',2,8),PhaseAnyBidPromiseError); + const bound = recordPhaseAnyBid(small,'p',2,5); + assert.equal(bound[0].fulfilled,true); + assert.equal(finishPhaseAnyBidPhase(bound,'p',2,'external')[1].fulfilled,true); + assert.throws(() => reconcilePhaseAnyBidPromises(source,'p',2,[],'voluntary'),PhaseAnyBidPromiseError); + assert.equal(reconcilePhaseAnyBidPromises(source,'p',2,[],'external')[0].released,true); + assert.equal(source[0].fulfilled,undefined); +}); + +void test('all-auction question retains a distinct wire kind at a real cache lot', () => { + const f = createTruthRicheseBidFixture(false); + const question: TruthQuestion = {kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:4}; + assert.doesNotThrow(() => validateTruthQuestionReceipt(f.game,f.asker,question)); + assert.match(truthQuestionText(question,id => id,id => id,id => id),/Richese cache, or Black Market/); + assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,turn:f.game.turn+1})); + assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,event:f.lot} as TruthQuestion)); + assert.throws(() => validateTruthQuestionReceipt(f.game,f.asker,{...question,minimum:0})); +}); diff --git a/tests/truth-phase-any-bid-future-cache.test.ts b/tests/truth-phase-any-bid-future-cache.test.ts new file mode 100644 index 00000000..ba07cc37 --- /dev/null +++ b/tests/truth-phase-any-bid-future-cache.test.ts @@ -0,0 +1,61 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { viewGame } from '../game/engine'; +import { + actTruthtranceRichesePromises as act, + advanceTruthtranceRichesePromises as advance, + askTruthtranceRichesePromises as ask, + createTruthtranceRichesePromisesFixture as fixture, + passTruthRicheseFreshDiscard, + truthtranceRichesePromisesClean as clean, + truthtranceRichesePromisesInventory as inventory, + truthtranceRichesePromisesPlayer as player, +} from './fixture-truthtrance-richese-promises'; + +/** Real Advanced setup and early question; the shared source selects only + * unopened deal/Spice cards and native scalar rolls. No purse, answer, lot, + * commitment, card location or force is injected for this scenario. */ +void test('Richese all-auction Yes survives an unbid Black Market and is fulfilled in its actual later cache', () => { + const f = fixture({advanced:true}); + const asked = ask(structuredClone(f.earlySource),f, + {kind:'phaseAnyBid',target:f.richese,turn:f.earlySource.turn,minimum:4}); + assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes')); + let game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'})); + const receipt = game.phaseAnyBidPromises?.find(row => row.player === f.richese); assert.ok(receipt); + const event = receipt.event, originalSpice = player(game,f.richese).spice; + const before = inventory(game); + game = advance(game,state => state.decision?.kind === 'richeseBlackMarket'); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + game = act(game,f.richese,{type:'decision',event:game.richeseBidding!.event, + card:f.targetCard,method:'onceAround',direction:'clockwise'}); + while (game.response) { + const responder = game.players.find(row => !game.response!.passed.includes(row.id)); assert.ok(responder); + game = act(game,responder.id,{type:'passResponse'}); + } + assert.equal(game.richeseAuction?.source,'blackMarket'); + const lot = game.richeseAuction!.event; + while (game.richeseAuction?.event === lot && !game.richeseAuction.outcome) { + const active = game.richeseAuction.active; assert.ok(active); + assert.notEqual(active,f.richese,'Once Around seller has no turn when everyone else passes'); + game = act(game,active,{type:'richeseBid',event:lot,amount:null,allyPayment:0}); + } + const waiting = game.phaseAnyBidPromises?.find(row => row.event === event); assert.ok(waiting); + assert.equal(!!waiting.fulfilled,false); + assert.equal(!!waiting.released,false,'The mandatory cache remains a real future bid opportunity'); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + assert.equal(player(game,f.richese).spice,originalSpice); + assert.deepEqual(inventory(game),before); + game = advance(game,state => clean(state) && !!state.richeseAuction && + state.richeseAuction.source === 'cache' && !state.richeseAuction.outcome, + [], {position:'first',method:'silent'}); + assert.equal(game.phaseAnyBidPromises?.find(row => row.event === event)?.released,undefined); + const cacheEvent = game.richeseAuction!.event; + const guide = viewGame(game,f.richese).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.event,cacheEvent); + assert.equal(guide.action.amount,4); + game = act(game,f.richese,guide.action); + assert.equal(!!game.phaseAnyBidPromises?.find(row => row.event === event)?.fulfilled,true); + assert.equal(player(game,f.richese).spice,originalSpice,'A sealed declaration does not pay early'); + assert.equal(viewGame(game,f.emperor).richeseAuction?.revealedBids,null); + assert.deepEqual(inventory(game),before); +}); diff --git a/tests/truth-phase-any-bid-runtime.test.ts b/tests/truth-phase-any-bid-runtime.test.ts new file mode 100644 index 00000000..40b6219e --- /dev/null +++ b/tests/truth-phase-any-bid-runtime.test.ts @@ -0,0 +1,399 @@ +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 { createTruthAllianceFixture, declareTruthAlliance, finishTruthAlliance, + actTruthAlliance, truthAllianceInventory, truthAlliancePlayer } from './fixture-truth-alliance'; +import { + actTruthtranceRichesePromises as act, + advanceTruthtranceRichesePromises as advance, + askTruthtranceRichesePromises as ask, + createTruthtranceRichesePromisesFixture as fixture, + passTruthRicheseFreshDiscard, + truthtranceRichesePromisesClean as clean, + truthtranceRichesePromisesInventory as inventory, + truthtranceRichesePromisesPlayer as player, +} from './fixture-truthtrance-richese-promises'; + +type Method = 'normal' | 'onceAround' | 'silent'; +type Source = ReturnType; +function reject(game: Game, actor: string, action: Action) { + const before = structuredClone(game); + assert.throws(() => act(game, actor, action)); + assert.deepEqual(game, before); +} +function askAny(source: Game, f: Source) { + return ask(source, f, {kind:'phaseAnyBid', target:f.emperor, turn:source.turn, minimum:4}); +} +function bindAny(asked: Game, f: Source, answer: 'yes'|'no') { + assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes(answer)); + return passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer})); +} +function currentCache(game: Game, f: Source, method: Exclude, position: 'first'|'last' = 'first') { + const options = {position,method}; + let state = advance(game, g => clean(g) && !!g.richeseAuction && + g.richeseAuction.source === 'cache' && !g.richeseAuction.outcome, [], options); + if (method === 'onceAround') + state = advance(state,g => clean(g) && g.richeseAuction?.active === f.emperor, [], options); + return state; +} +function blackMarket(game: Game, f: Source, method: Method) { + let state = advance(game,g => g.decision?.kind === 'richeseBlackMarket'); + const card = f.targetCard, event = state.richeseBidding!.event; + assert.ok(player(state,f.richese).hand.some(item => item.id === card)); + state = act(state,f.richese,{type:'decision',event,card,method, + ...(method === 'onceAround' ? {direction:'clockwise'} : {})}); + while (state.response) { + const actor = state.players.find(row => !state.response!.passed.includes(row.id)); assert.ok(actor); + state = act(state,actor.id,{type:'passResponse'}); + } + assert.equal(state.richeseAuction?.source,'blackMarket'); + return state; +} +function targetTurn(game: Game, f: Source, method: Method) { + if (method === 'silent') return game; + let state = game; + for (let n = 0; state.richeseAuction?.active !== f.emperor && n < 10; n++) { + const lot = state.richeseAuction; assert.ok(lot && !lot.outcome && lot.active); + // Keep the auction alive until the actual target's own opportunity. + state = act(state,lot.active,{type:'richeseBid',event:lot.event,amount:null}); + } + assert.equal(state.richeseAuction?.active,f.emperor); + return state; +} + +/** Genuine R/A/E setup and real turn-one Charity. The fixture stages only + * unopened original deal and Spice order plus native scalar rolls. */ +for (const method of ['onceAround','silent'] as const) for (const answer of ['yes','no'] as const) + void test(`Basic pre-Bidding all-auction ${answer} governs the first real ${method} cache declaration`, () => { + const f = fixture({advanced:false}), asked = askAny(structuredClone(f.earlySource),f); + let game = bindAny(asked,f,answer); + const live = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(live); + game = currentCache(game,f,method); + const lot = game.richeseAuction!; + const held = inventory(game), amount = answer === 'yes' ? 4 : 2; + if (answer === 'yes') { + for (const lower of [3,method === 'silent' ? 0 : null]) { + const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:lower,allyPayment:0}); + const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + } + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4); + for (const difficulty of DIFFICULTIES) { + const bot = viewGame(game,f.emperor); bot.players.find(row => row.id === f.emperor)!.bot = difficulty; + assert.deepEqual(botActions(bot)[0],guide.action); + } + } else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0}); + const before = player(game,f.emperor).spice; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0}); + const result = game.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(result); + assert.equal(!!result.fulfilled,answer === 'yes'); + assert.equal(player(game,f.emperor).spice,before,'Declaring a bid is not the purchase invoice'); + if (method === 'silent' && game.richeseAuction?.event === lot.event) { + assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount); + assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null); + assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null); + } + assert.deepEqual(inventory(game),held); + const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === lot.cardId), + [], {position:'first',method}); + assert.equal(player(purchased,f.emperor).spice,before-amount); + assert.ok(!purchased.richeseCache?.some(card => card.id === lot.cardId)); + assert.deepEqual(inventory(purchased),held); + }); + +for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const) + void test(`Advanced current ${method} Black Market all-auction ${answer} preserves the seller card and native bid`, () => { + const f = fixture({advanced:true}); + const source = blackMarket(structuredClone(f.earlySource),f,method); + const lot = source.richeseAuction!; + const asked = askAny(source,f); + let game = bindAny(asked,f,answer); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + game = targetTurn(game,f,method); + const amount = answer === 'yes' ? 4 : 2; + if (answer === 'yes') { + const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0}); + const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4); + } else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0}); + const purse = player(game,f.emperor).spice, seller = player(game,f.richese).spice; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0}); + assert.equal(player(game,f.emperor).spice,purse); + const row = game.phaseAnyBidPromises?.find(item => item.player === f.emperor); assert.ok(row); + assert.equal(!!row.fulfilled,answer === 'yes'); + if (method === 'silent') { + assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount); + assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null); + assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null); + } + assert.deepEqual(inventory(game),f.originalCards); + const purchased = advance(game,state => player(state,f.emperor).hand.some(card => card.id === f.targetCard)); + assert.equal(player(purchased,f.emperor).spice,purse-amount); + assert.equal(player(purchased,f.richese).spice,seller+amount); + assert.ok(!player(purchased,f.richese).hand.some(card => card.id === f.targetCard)); + assert.deepEqual(inventory(purchased),f.originalCards); + }); + +for (const method of ['onceAround','silent'] as const) void test( + `A saved ordinary-only phaseBid remains ordinary-only during a real ${method} cache lot`, () => { + const f = fixture({advanced:false}); + const asked = ask(structuredClone(f.earlySource),f,{kind:'phaseBid',target:f.emperor,turn:f.earlySource.turn,minimum:4}); + assert.ok(viewGame(asked,f.emperor).truthPhaseBidAnswers?.includes('no')); + let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'})); + game = currentCache(game,f,method); + 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 answer of ['yes','no'] as const) void test( + `${advanced?'Advanced':'Basic'} current ${method} cache accepts an all-auction ${answer}`, () => { + const f = fixture({advanced}); + const source = currentCache(structuredClone(f.earlySource),f,method); + const lot = source.richeseAuction!; + const asked = askAny(source,f); + let game = bindAny(asked,f,answer); + assert.ok(game.richeseCache?.some(card => card.id === lot.cardId)); + const amount = answer === 'yes' ? 4 : 2; + if (answer === 'yes') { + const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0}); + const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'}); + reject(game,f.emperor,{...guide.action,phaseAnyBidLotEvent:'stale-lot'}); + } else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0}); + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0}); + assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes'); + if (method === 'silent') { + assert.equal(viewGame(game,f.emperor).richeseAuction?.ownBid,amount); + assert.equal(viewGame(game,f.richese).richeseAuction?.ownBid,null); + assert.equal(viewGame(game,f.richese).richeseAuction?.revealedBids,null); + } + assert.deepEqual(inventory(game),f.originalCards); + }); + +for (const method of ['normal','onceAround','silent'] as const) for (const answer of ['yes','no'] as const) + void test(`Advanced pre-Bidding all-auction ${answer} binds an actual ${method} Black Market bid`, () => { + const f = fixture({advanced:true}); + const asked = askAny(structuredClone(f.earlySource),f); + let game = bindAny(asked,f,answer); + game = blackMarket(game,f,method); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + game = targetTurn(game,f,method); + const lot = game.richeseAuction!; + if (answer === 'yes') { + const deferred = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0}); + const promise = deferred.phaseAnyBidPromises?.find(row => row.player === f.emperor); assert.ok(promise); + assert.equal(!!promise.fulfilled,false); assert.equal(!!promise.released,false); + } else reject(game,f.emperor,{type:'richeseBid',event:lot.event,amount:4,allyPayment:0}); + const amount = answer === 'yes' ? 4 : 2; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount,allyPayment:0}); + assert.equal(!!game.phaseAnyBidPromises?.find(row => row.player === f.emperor)?.fulfilled,answer === 'yes'); + assert.deepEqual(inventory(game),f.originalCards); + }); + +void test('Advanced all-auction Yes permits the Richese seller to retain its own Silent Black Market card', () => { + const f = fixture({advanced:true}), source = structuredClone(f.earlySource); + const asked = ask(source,f,{kind:'phaseAnyBid',target:f.richese,turn:source.turn,minimum:4}); + assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes')); + let game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'})); + game = blackMarket(game,f,'silent'); + const lot = game.richeseAuction!, originalHand = player(game,f.richese).hand.map(card => card.id); + const seller = player(game,f.richese).spice, emperor = player(game,f.emperor).spice; + const guide = viewGame(game,f.richese).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4); + game = act(game,f.richese,guide.action); + assert.equal(viewGame(game,f.asker).richeseAuction?.ownBid,null); + assert.equal(viewGame(game,f.asker).richeseAuction?.revealedBids,null); + for (const actor of [f.asker,f.emperor]) + game = act(game,actor,{type:'richeseBid',event:lot.event,amount:0,allyPayment:0}); + assert.deepEqual(player(game,f.richese).hand.map(card => card.id),originalHand); + assert.equal(player(game,f.richese).spice,seller-4); + assert.equal(player(game,f.emperor).spice,emperor+4); + assert.equal(game.richeseBidding?.blackMarketSold,true); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); +}); + +void test('Basic all-auction Yes follows the ordinary native bid guide and is fulfilled by its actual declaration', () => { + const f = fixture({advanced:false}); + let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes'); + game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor, + [], {position:'first',method:'onceAround'}); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4); + reject(game,f.emperor,{...guide.action,phaseAnyBidPromiseEvent:'stale-event'}); + reject(game,f.emperor,{...guide.action,phaseAnyBidLot:999}); + const before = player(game,f.emperor).spice; + game = act(game,f.emperor,guide.action); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled)); + assert.equal(player(game,f.emperor).spice,before); + assert.deepEqual(inventory(game),f.originalCards); +}); + +void test('Basic all-auction No is fulfilled only at real Bidding close', () => { + const f = fixture({advanced:false}); + let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'no'); + game = advance(game,state => state.phase > 3 && clean(state), [], {position:'first',method:'silent'}); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && !row.answer && row.fulfilled && !row.released)); + assert.deepEqual(inventory(game),f.originalCards); +}); + +/** Reach the last cache through a real earlier ordinary purchase. Richese has + * four spendable spice and its own eventual Once Around bid becomes possible + * only after the real Emperor's opening bid. No board, balance or lot is staged. */ +function finalCache() { + const f = fixture({advanced:false}), options = {position:'last' as const,method:'onceAround' as const}; + let game = advance(structuredClone(f.earlySource),state => clean(state) && !!state.auction,[],options); + assert.equal(game.auction?.active,f.richese); + game = act(game,f.richese,{type:'bid',amount:1,allyPayment:0}); + game = advance(game,state => clean(state) && state.phase === 3 && !!state.richeseAuction && !state.richeseAuction.outcome,[],options); + const lot = game.richeseAuction!; + assert.equal(lot.source,'cache'); assert.equal(lot.active,f.emperor); + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:1,allyPayment:0}); + assert.equal(game.richeseAuction?.active,f.asker); + const asked = ask(game,f,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:4}); + assert.ok(viewGame(asked,f.richese).truthPhaseAnyBidAnswers?.includes('yes')); + game = passTruthRicheseFreshDiscard(act(asked,f.richese,{type:'truthAnswer',answer:'yes'})); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.richese && row.answer && !row.fulfilled)); + return {f,game,lot:lot.event}; +} + +void test('an actual opposing raise can externally release an impossible all-auction Yes at the final cache', () => { + const f = finalCache(); + let game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:10,allyPayment:0}); + const promise = game.phaseAnyBidPromises?.find(row => row.player === f.f.richese); assert.ok(promise); + assert.equal(!!promise.released,true); assert.equal(!!promise.fulfilled,false); + assert.equal(game.richeseAuction?.active,f.f.richese); + game = act(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0}); + assert.deepEqual(inventory(game),f.f.originalCards); +}); + +void test('an expiring final-cache clock makes the required all-auction Yes bid', () => { + const f = finalCache(); + const game = act(f.game,f.f.asker,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0}); + assert.equal(game.richeseAuction?.active,f.f.richese); + assert.ok(hasAuctionClockOpportunity(game)); + reject(game,f.f.richese,{type:'richeseBid',event:f.lot,amount:null,allyPayment:0}); + const guide = viewGame(game,f.f.richese).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'richeseBid'); assert.equal(guide.action.amount,4); + const armed = synchronizeAuctionClock(game,1_000,'phase-any-bid-test:0'); + const expired = advanceAuctionClock(armed,11_000,'phase-any-bid-test:0'); + assert.ok(expired.phaseAnyBidPromises?.some(row => row.player === f.f.richese && row.answer && row.fulfilled)); + assert.match(expired.log.at(-1)!.text,/legal bid required by their binding Truthtrance answer was submitted/); + assert.deepEqual(inventory(expired),f.f.originalCards); +}); + +for (const first of ['phaseBid','phaseAnyBid'] as const) void test( + `a live ${first} answer prevents an incompatible second bid-family question`, () => { + const f = fixture({advanced:false}); + const source = structuredClone(f.earlySource); + const asked = ask(source,f,{kind:first,target:f.emperor,turn:source.turn,minimum:4}); + let game = passTruthRicheseFreshDiscard(act(asked,f.emperor,{type:'truthAnswer',answer:'no'})); + // The original second physical Truth is moved from the unopened deck into + // its owner's hand solely to exercise two real questions in this same turn. + const index = game.deck.findIndex(card => card.effect === 'truthtrance'); 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 = act(game,f.asker,{type:'card',card:second.id}); + game = advance(game,state => state.truthtrance?.stage === 'ask'); + const kind = first === 'phaseBid' ? 'phaseAnyBid' : 'phaseBid'; + reject(game,f.asker,{type:'truthAsk',question:{kind,target:f.emperor,turn:game.turn,minimum:5}}); + }); + +for (const method of ['onceAround','silent'] as const) void test( + `a smaller ${method} cache bid preserves a later funded ordinary all-auction Yes`, () => { + const f = fixture({advanced:false}), options = {position:'first' as const,method}; + let game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes'); + game = currentCache(game,f,method); + const lot = game.richeseAuction!, spice = player(game,f.emperor).spice; + game = act(game,f.emperor,{type:'richeseBid',event:lot.event,amount:3,allyPayment:0}); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released)); + game = advance(game,state => clean(state) && !!state.auction && state.auction.active === f.emperor,[],options); + assert.ok(player(game,f.emperor).hand.some(card => card.id === lot.cardId)); + assert.equal(player(game,f.emperor).spice,spice-3); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + assert.equal(guide.action.type,'bid'); assert.equal(guide.action.amount,4); + game = act(game,f.emperor,guide.action); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); + }); + +for (const claim of [false,true]) void test( + `Advanced all-auction Truth answer offers Semuta and ${claim ? 'claim' : 'pass'} retains the bid and Black Market lot`, () => { + const f = fixture({advanced:true}); + let source = structuredClone(f.earlySource); + // Conserved supplement: move the original Semuta from Richese's cache to + // its hand. The original dealt Shield remains the actual sale card. + const cache = source.richeseCache!, index = cache.findIndex(card => card.effect === 'semutaDrug'); + assert.ok(index >= 0); + const [semuta] = cache.splice(index,1); player(source,f.richese).hand.push(semuta); + assert.deepEqual(inventory(source),f.originalCards); + source = targetTurn(blackMarket(source,f,'onceAround'),f,'onceAround'); + const lot = structuredClone(source.richeseAuction), funding = structuredClone(source.richeseFunding); + const asked = askAny(source,f); + assert.ok(viewGame(asked,f.emperor).truthPhaseAnyBidAnswers?.includes('yes')); + let game = act(asked,f.emperor,{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.truth); + assert.equal(viewGame(game,f.richese).semutaReaction?.canCommit,true); + const promise = structuredClone(game.phaseAnyBidPromises); + assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + game = claim ? act(game,f.richese,{type:'semutaCommit',event:pending.batch.event}) : passTruthRicheseFreshDiscard(game); + assert.equal(game.pendingTreacheryDiscard,null); + assert.deepEqual(game.richeseAuction,lot); assert.deepEqual(game.richeseFunding,funding); + assert.deepEqual(game.phaseAnyBidPromises,promise); + assert.equal(player(game,f.richese).hand.some(card => card.id === f.truth),claim); + assert.equal(game.discard.some(card => card.id === semuta.id),claim); + assert.ok(player(game,f.richese).hand.some(card => card.id === f.targetCard)); + const guide = viewGame(game,f.emperor).phaseAnyBidGuide; assert.ok(guide); + game = act(game,f.emperor,guide.action); + assert.ok(game.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.fulfilled)); + assert.deepEqual(inventory(game),f.originalCards); + }); + +void test('a voluntary real bribe cannot spend the last money required by an all-auction Yes', () => { + const f = fixture({advanced:false}); + const game = bindAny(askAny(structuredClone(f.earlySource),f),f,'yes'); + assert.equal(player(game,f.emperor).spice,10); + reject(game,f.emperor,{type:'bribe',target:f.richese,amount:7}); + const paid = act(game,f.emperor,{type:'bribe',target:f.richese,amount:6}); + assert.equal(player(paid,f.emperor).spice,4); + assert.ok(paid.phaseAnyBidPromises?.some(row => row.player === f.emperor && row.answer && !row.fulfilled && !row.released)); + assert.deepEqual(inventory(paid),f.originalCards); +}); + +void test('an Emperor cannot give away spice required by an all-auction Yes', () => { + const f = createTruthAllianceFixture({advanced:true,consent:'allied'}); + const charity = finishTruthAlliance(f.game); + const declared = declareTruthAlliance(f,charity).game; + const asked = actTruthAlliance(declared,f.asker,{type:'truthAsk',question:{kind:'phaseAnyBid', + target:f.target,turn:declared.turn,minimum:4}}); + assert.ok(viewGame(asked,f.target).truthPhaseAnyBidAnswers?.includes('yes')); + const game = actTruthAlliance(asked,f.target,{type:'truthAnswer',answer:'yes'}); + assert.equal(truthAlliancePlayer(game,f.target).spice,10); + const before = structuredClone(game); + assert.throws(() => actTruthAlliance(game,f.target,{type:'emperorGift',amount:7})); + assert.deepEqual(game,before); + let shared = actTruthAlliance(game,f.target,{type:'emperorGift',amount:6}); + for (let n = 0; shared.response?.kind === 'emperorGift' && n < 10; n++) { + const actor = shared.players.find(row => !shared.response!.passed.includes(row.id)); assert.ok(actor); + shared = actTruthAlliance(shared,actor.id,{type:'passResponse'}); + } + assert.equal(truthAlliancePlayer(shared,f.target).spice,4); + assert.ok(shared.phaseAnyBidPromises?.some(row => row.player === f.target && row.answer && !row.fulfilled && !row.released)); + assert.deepEqual(truthAllianceInventory(shared),f.originalCards); +}); diff --git a/tests/truth-phase-any-bid-spending.test.ts b/tests/truth-phase-any-bid-spending.test.ts new file mode 100644 index 00000000..45525f16 --- /dev/null +++ b/tests/truth-phase-any-bid-spending.test.ts @@ -0,0 +1,91 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { viewGame, type Game } from '../game/engine'; +import { botActions } from '../game/bots'; +import { DIFFICULTIES } from '../game/bot-profiles'; +import { + actTruthtranceRichesePromises as act, + advanceTruthtranceRichesePromises as advance, + askTruthtranceRichesePromises as ask, + createTruthtranceRichesePromisesFixture as fixture, + passTruthRicheseFreshDiscard, + truthtranceRichesePromisesClean as clean, + truthtranceRichesePromisesInventory as inventory, + truthtranceRichesePromisesPlayer as player, +} from './fixture-truthtrance-richese-promises'; + +/** Original Basic setup and Charity; the original Box is exchanged with the + * respondent's held card and two original unopened cards are moved to the + * discard to make the paid search a genuine multi-choice decision. */ +function source(minimum: number) { + const f = fixture({advanced:false}); + let game = structuredClone(f.earlySource); + const owner = player(game,f.emperor), cache = game.richeseCache!; + const index = cache.findIndex(card => card.effect === 'nullentropyBox'); assert.ok(index >= 0); + const [box] = cache.splice(index,1), [exchange] = owner.hand.splice(0,1); + owner.hand.push(box); cache.push(exchange); + for (let n = 0; n < 2; n++) { const card = game.deck.shift(); assert.ok(card); game.discard.push(card); } + const original = inventory(game); + assert.equal(owner.spice,10); + game = ask(game,f,{kind:'phaseAnyBid',target:f.emperor,turn:game.turn,minimum}); + assert.ok(viewGame(game,f.emperor).truthPhaseAnyBidAnswers?.includes('yes')); + game = passTruthRicheseFreshDiscard(act(game,f.emperor,{type:'truthAnswer',answer:'yes'})); + return {f,game,box:box.id,original}; +} +function promise(g: Game, playerId: string) { + const row = g.phaseAnyBidPromises?.find(item => item.player === playerId); assert.ok(row); return row; +} + +void test('a paid Box search cannot voluntarily spend the last funds for an all-auction Yes', () => { + const f = source(10), before = structuredClone(f.game); + assert.throws(() => act(f.game,f.f.emperor,{type:'card',card:f.box})); + assert.deepEqual(f.game,before); + assert.equal(player(f.game,f.f.emperor).spice,10); + assert.equal(!!promise(f.game,f.f.emperor).released,false); + assert.deepEqual(inventory(f.game),f.original); +}); + +void test('an affordable Box search can finish while preserving the all-auction Yes', () => { + const f = source(8); + let game = act(f.game,f.f.emperor,{type:'card',card:f.box}); + assert.equal(player(game,f.f.emperor).spice,8); + assert.equal(game.decision?.kind,'nullentropy'); + const pending = game.pendingNullentropy; assert.ok(pending); + const card = game.discard.find(item => item.effect !== 'nullentropyBox'); assert.ok(card); + game = act(game,f.f.emperor,{type:'decision',event:pending.event,card:card.id}); + game = passTruthRicheseFreshDiscard(game); + assert.equal(game.pendingNullentropy,null); + assert.equal(player(game,f.f.emperor).spice,8); + assert.equal(!!promise(game,f.f.emperor).released,false); + assert.equal(!!promise(game,f.f.emperor).fulfilled,false); + assert.deepEqual(inventory(game),f.original); +}); + +void test('a No-only Silent guide waits while bots answer a real Emperor gift response', () => { + const f = fixture({advanced:false}); + let game = structuredClone(f.earlySource); + // Stage mutual alliance; move an existing unopened Karama into Richese's + // hand so the real gift response remains open for that player. + player(game,f.emperor).ally = f.richese; + player(game,f.richese).ally = f.emperor; + game = ask(game,f,{kind:'phaseAnyBid',target:f.richese,turn:game.turn,minimum:4}); + assert.ok(viewGame(game,f.richese).truthPhaseAnyBidAnswers?.includes('no')); + game = passTruthRicheseFreshDiscard(act(game,f.richese,{type:'truthAnswer',answer:'no'})); + game = advance(game,state => clean(state) && !!state.richeseAuction && + state.richeseAuction.source === 'cache' && !state.richeseAuction.outcome, + [],{position:'first',method:'silent'}); + const index = game.deck.findIndex(card => card.effect === 'karama'); assert.ok(index >= 0); + const [karama] = game.deck.splice(index,1); player(game,f.richese).hand.push(karama); + const physical = inventory(game); + assert.equal(viewGame(game,f.richese).phaseAnyBidGuide?.action.type,'richeseBid'); + game = act(game,f.emperor,{type:'emperorGift',amount:1}); + assert.equal(game.response?.kind,'emperorGift'); + assert.equal(viewGame(game,f.richese).phaseAnyBidGuide,null); + for (const difficulty of DIFFICULTIES) { + const view = viewGame(game,f.richese); view.players.find(row => row.id === f.richese)!.bot = difficulty; + const action = botActions(view)[0]; assert.ok(action,difficulty); + assert.notEqual(action.type,'richeseBid'); + assert.doesNotThrow(() => act(game,f.richese,action)); + } + assert.deepEqual(inventory(game),physical); +});