Something went wrong. Try again.
A Social Deduction / Deception Game
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148// Deduction mode — evidence-engine showcase (server-side, runnable).//// tsx server/src/deduction/showcase.ts # random draw from the cached real pool// SEED=42 NOISE=5 tsx server/src/deduction/showcase.ts//// Generates a full case from REAL rpg.actor suspects (the disk-cached reference pool), then simulates// two players working the same case:// • a DISCIPLINED detective — questions only the suspects who match each fake → the notebook resolves// to a unique culprit;// • a SLOPPY one — also questions a non-matcher about a fake → the same intersection goes ambiguous.// This is the §4 "discipline matters" wrinkle, proven end-to-end on generated data.
import { readFile } from 'node:fs/promises'import { fileURLToPath } from 'node:url'import { dirname, join } from 'node:path'import { allClues, answerLine, emptyNotebook, generateCase, inspectLine, inspectMood, phraseFragment, question, questionResult, selectCulprit, tokensOf, verifyCase, type DeductionCase, type EvidencePiece, type MapInfo, type Notebook, type SuspectAttributes,} from '../../../engine/deduction/index.js'
const CACHE = join(dirname(fileURLToPath(import.meta.url)), '.poolcache.json')
function mulberry32(seed: number): () => number { let a = seed >>> 0 return () => { a = (a + 0x6d2b79f5) | 0 let t = Math.imul(a ^ (a >>> 15), 1 | a) t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t return ((t ^ (t >>> 14)) >>> 0) / 4294967296 }}
// A small fixed map: five resource stations (the meeting/interview hub is not inspectable, so it's not// listed). Clues stack onto these; there's no separate debris any more.const MAP: MapInfo = { stations: [ { id: 'st-ore', resource: 'ore', verb: 'collect' }, { id: 'st-crates', resource: 'crates', verb: 'deposit' }, { id: 'st-water', resource: 'water', verb: 'collect' }, { id: 'st-mail', resource: 'mail', verb: 'deposit' }, { id: 'st-tally', resource: 'eggs', verb: 'scoreboard' }, ],}
function attire(s: SuspectAttributes): string { return s.worn.map((w) => `${w.colorBucket ? w.colorBucket + ' ' : ''}${w.title}`).join(', ') || '(plain)'}
/** Question every suspect whose visible attire matches a fake — the disciplined detective's routine. */function questionMatchers(nb: Notebook, case_: DeductionCase, fake: EvidencePiece): Notebook { for (const s of case_.suspects) if (tokensOf(s).has(fake.fragment)) nb = question(nb, fake, s.did) return nb}
async function main() { const seed = Number(process.env.SEED ?? 7) const noise = process.env.NOISE ? Number(process.env.NOISE) : undefined const rng = mulberry32(seed)
const pool = JSON.parse(await readFile(CACHE, 'utf8')) as SuspectAttributes[] console.log(`\n🔎 Sabotage Town — Deduction showcase (seed=${seed}, pool=${pool.length} real suspects)\n`)
let case_: DeductionCase | null = null for (let s = seed; s < seed + 50 && !case_; s++) case_ = generateCase(pool, MAP, mulberry32(s), { noise }) if (!case_) { console.error('Could not build a case from this pool/seed. Try another SEED.') process.exit(1) }
const problems = verifyCase(case_) if (problems.length) { console.error('Generated case violates an invariant:', problems) process.exit(1) }
const alias = new Map(case_.suspects.map((s, i) => [s.did, String.fromCharCode(65 + i)])) const name = (did: string) => alias.get(did) ?? did const clues = allClues(case_) const fakes = clues.filter((e) => e.incriminating)
console.log(`The cast — ${case_.suspects.length} suspects (you judge matches by their attire):\n`) for (const s of case_.suspects) console.log(` ${name(s.did)}: ${attire(s)}`)
const clean = case_.stations.filter((st) => st.clues.length === 0).length console.log(`\nThe map — ${case_.stations.length} stations (${clues.length} clues stacked; ${clean} stations clean):\n`) for (const st of case_.stations) { console.log(` ${st.id} [${st.condition}]${st.clues.length ? '' : ' — clean'}`) st.clues.forEach((e) => { const tag = e.incriminating ? ' «fake»' : '' console.log(` d${e.depth}: ${inspectLine(inspectMood(e, e.depth), e.verb, e.resource, e.fragment)}${tag}`) }) } console.log(`\n (The «fake» tags are SERVER-ONLY truth — the player never sees them.)`) console.log(` The three fakes all trace to ${name(case_.culpritDid)}; only their 3-way intersection proves it:`) for (const f of fakes) console.log(` • [${f.id}] ${phraseFragment(f.fragment)} → matches {${f.matchSet.map(name).join(', ')}}`)
// --- disciplined play: only question matchers of each fake -------------------- let disciplined = emptyNotebook() for (const f of fakes) disciplined = questionMatchers(disciplined, case_, f) const cleanSolve = selectCulprit(disciplined, case_.incriminatingClueIds)
console.log(`\n— Disciplined detective: questions only the matchers of each fake —`) for (const f of fakes) { const asked = case_.suspects.filter((s) => tokensOf(s).has(f.fragment)) console.log(` [${f.id}] ${asked.map((s) => `${name(s.did)}: "${answerLine(questionResult(f, s.did).line, f.verb, f.resource)}"`).join(' ')}`) } console.log(` → notebook intersection of the 3 fakes = {${cleanSolve.map(name).join(', ')}}`) console.log(` ${cleanSolve.length === 1 && cleanSolve[0] === case_.culpritDid ? '✅ unique — accuse ' + name(case_.culpritDid) : '❌ did not resolve'}`)
// --- sloppy play: also question a non-matcher about a fake ------------------- // Find an innocent who matches exactly two fakes and ask them about the third (a stray denial). const fakeMatch = (did: string) => fakes.filter((f) => f.matchSet.includes(did)).length const victim = case_.suspects.find((s) => s.did !== case_.culpritDid && fakeMatch(s.did) === 2) console.log(`\n— Sloppy detective: same questions, plus one careless extra —`) if (!victim) { console.log(' (no innocent matched exactly two fakes this draw — nothing to over-ask)') } else { const thirdFake = fakes.find((f) => !f.matchSet.includes(victim.did))! let sloppy = disciplined sloppy = question(sloppy, thirdFake, victim.did) // ask a non-matcher → writes a stray Denied const pollutedSolve = selectCulprit(sloppy, case_.incriminatingClueIds) console.log(` also asked ${name(victim.did)} about [${thirdFake.id}] (which they DON'T match): "${answerLine(questionResult(thirdFake, victim.did).line, thirdFake.verb, thirdFake.resource)}"`) console.log(` → notebook intersection = {${pollutedSolve.map(name).join(', ')}}`) console.log(` ${pollutedSolve.length > 1 ? '❌ ambiguous — ' + name(victim.did) + ' is now a false positive alongside the culprit' : '✅ (still unique this draw)'}`) } console.log()}
main().catch((err) => { console.error(err) process.exit(1)})