54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
import {
|
|
richeseBidCompletionRange,
|
|
RicheseBidPromiseError,
|
|
type RicheseBidContext,
|
|
type RicheseBidOpportunity,
|
|
type RicheseBidPromise,
|
|
type RicheseBidRange,
|
|
} from './richese-bid-promises';
|
|
import type { PhaseBidPromise } from './turn-bid-promises';
|
|
|
|
export type JointRicheseBidOptions = {
|
|
/** A separately proven later auction may satisfy phase-wide Yes answers.
|
|
* Phase-wide No answers always constrain the current Richese declaration. */
|
|
includePhaseYes?: boolean;
|
|
};
|
|
|
|
/** Represent live phase-wide bounds in one specific Richese lot's native
|
|
* interval. These synthetic rows are quote-only: never save or project them. */
|
|
export function richeseBidsWithPhaseBounds(
|
|
native: readonly RicheseBidPromise[],
|
|
phase: readonly PhaseBidPromise[],
|
|
context: RicheseBidContext,
|
|
options: JointRicheseBidOptions = {},
|
|
): RicheseBidPromise[] {
|
|
if (!Array.isArray(native) || !Array.isArray(phase) || !context ||
|
|
!Number.isSafeInteger(context.turn) || context.turn < 1 ||
|
|
typeof context.event !== 'string' || !context.event || context.event.trim() !== context.event ||
|
|
typeof context.player !== 'string' || !context.player || context.player.trim() !== context.player)
|
|
throw new RicheseBidPromiseError('Retain the original bidder, turn and Richese auction event.');
|
|
const used = new Set(native.map(row => row.id));
|
|
const bounds: RicheseBidPromise[] = [];
|
|
for (const row of phase) {
|
|
if (row.player !== context.player || row.turn !== context.turn || row.fulfilled || row.released ||
|
|
(row.answer && options.includePhaseYes === false)) continue;
|
|
let id = `phase-any:${row.event}`;
|
|
while (used.has(id)) id += ':';
|
|
used.add(id);
|
|
bounds.push({id,turn:context.turn,event:context.event,player:context.player,
|
|
asker:row.asker,minimum:row.minimum,answer:row.answer});
|
|
}
|
|
return [...native,...bounds];
|
|
}
|
|
|
|
/** The native Richese quote owns funding, hand space and the single
|
|
* Once Around/Silent declaration; this helper only intersects obligations. */
|
|
export function jointRicheseBidCompletionRange(
|
|
native: readonly RicheseBidPromise[],
|
|
phase: readonly PhaseBidPromise[],
|
|
opportunity: RicheseBidOpportunity,
|
|
options: JointRicheseBidOptions = {},
|
|
): RicheseBidRange | null {
|
|
return richeseBidCompletionRange(richeseBidsWithPhaseBounds(native,phase,opportunity,options),opportunity);
|
|
}
|