// The notebook (PURE) — a suspects×clues grid recording each suspect's answer when questioned about a // clue (DEDUCTION.md §4). EVERY question is written, including the ones the player *shouldn't* have // asked: a non-matcher denies just like a non-source matcher, and that stray Denied is real, not // cosmetic (§4.1). Disciplined play (ask only matchers) keeps each innocent denied in ≤2 of the three // fakes, so the endgame intersection is uniquely the culprit; sloppy play manufactures false positives. import { questionOutcome, type Answer, type EvidencePiece } from './evidence.js' /** suspectDid → clueId → answer. A blank cell (never asked) is an absent key. */ export type Notebook = Record> export function emptyNotebook(): Notebook { return {} } /** Write one answer, immutably. */ export function recordAnswer(nb: Notebook, suspectDid: string, clueId: string, answer: Answer): Notebook { return { ...nb, [suspectDid]: { ...(nb[suspectDid] ?? {}), [clueId]: answer } } } /** * Question `suspectDid` about `piece` and record the outcome — the only intended way to fill the grid. * Records the denial of a non-matcher too (the game never auto-filters who "should" be asked, §4.1). */ export function question(nb: Notebook, piece: EvidencePiece, suspectDid: string): Notebook { return recordAnswer(nb, suspectDid, piece.id, questionOutcome(piece, suspectDid)) } /** * The endgame solve (§4): the suspect(s) recorded as **Denied** for EVERY clue in `clueIds`. Selecting * the 3 incriminating clues on a clean (disciplined) grid yields exactly the culprit; a polluted grid * (a non-matcher was questioned about one of them) yields more than one. A suspect never asked about a * selected clue is not "denied in all" and is excluded. Empty selection selects no one. */ export function selectCulprit(nb: Notebook, clueIds: string[]): string[] { if (clueIds.length === 0) return [] return Object.keys(nb).filter((did) => clueIds.every((id) => nb[did]?.[id] === 'denied')) }