/** Checks the 비슷한 단어 묶음 (`groups`) of the 라이어 게임 word bank: bun scripts/liar-groups-check.ts [topicId...] */ import { readdirSync } from 'node:fs'; const dir = new URL('../packages/games/src/liar/bank/', import.meta.url).pathname; const want = process.argv.slice(2); let bad = 0; for (const f of readdirSync(dir).filter((f) => f.endsWith('.ts') && f !== 'w.ts')) { const mod = await import(dir + f); const t = Object.values(mod)[0] as { id: string; words: { word: string }[]; groups?: Record }; if (want.length && !want.includes(t.id)) continue; const errs: string[] = []; if (!t.groups) errs.push('groups 없음'); else { const seen = new Map(); const words = new Set(t.words.map((x) => x.word)); for (const [g, ws] of Object.entries(t.groups)) { if (ws.length < 2) errs.push(`'${g}' 묶음이 ${ws.length}개(2개 이상 필요)`); for (const x of ws) { if (!words.has(x)) errs.push(`'${g}'의 '${x}'는 주제에 없는 단어`); if (seen.has(x)) errs.push(`'${x}'가 '${seen.get(x)}'와 '${g}' 두 묶음에 있음`); seen.set(x, g); } } for (const x of words) if (!seen.has(x)) errs.push(`'${x}'가 어느 묶음에도 없음`); const sizes = Object.values(t.groups).map((x) => x.length); console.log(`${t.id}: 단어 ${words.size}, 묶음 ${sizes.length}개 (크기 ${Math.min(...sizes)}~${Math.max(...sizes)})${errs.length ? ' ❌' : ' ✅'}`); } for (const e of errs) console.log(' - ' + e); bad += errs.length; } process.exit(bad ? 1 : 0);