Allow Advanced Auditor inspection choice
Verify and publish checkpoint container / container (push) Successful in 11m25s

This commit is contained in:
Quintine committed 2026-10-29 05:52:58 +11:00
1 parent 0681529e8e
commit 7e6e8c2d12
9 files changed
+292 -31

No files matched your search

+15 -1
View File
@@ -55,23 +55,37 @@ export function auditCount(
);
}
/** Validate the holder's chosen size against the actual eligible maximum.
* An omitted choice preserves the legacy maximum, including an empty audit. */
export function selectedAuditCount(maximum: number, selectedCount?: number): number {
if (!Number.isInteger(maximum) || maximum < 0 || maximum > 2)
throw new Error('Auditor requires a valid inspection maximum.');
if (selectedCount === undefined) return maximum;
if (!Number.isInteger(selectedCount) || selectedCount < 1 || selectedCount > maximum)
throw new Error('Auditor inspection count must be between one and the eligible maximum.');
return selectedCount;
}
/**
* Call once after the engine resolves cancellation/payment, and persist the
* resulting private snapshot. A read or projection must never call this helper.
* Partial Fisher-Yates samples physical cards uniformly without replacement.
* Selecting the entire eligible pool consumes no randomness.
* Omit selectedCount for the legacy maximum; a supplied count must be at
* least one and no greater than the current eligible inspection maximum.
*/
export function sampleAuditCards(
hand: readonly Card[],
usedIds: readonly string[],
survived: boolean,
random: () => number,
selectedCount?: number,
): Card[] {
const limit = inspectionLimit(survived);
const eligible = auditCandidates(hand, usedIds);
if (typeof random !== 'function')
throw new Error('Auditor requires a server-supplied random source.');
const count = Math.min(limit, eligible.length);
const count = selectedAuditCount(Math.min(limit, eligible.length), selectedCount);
if (count === eligible.length) return eligible;
for (let i = 0; i < count; i++) {
const draw = random();