Known answers for the bot: the guide's encounter answers and the bot's own results, by choice text (#35)
CI / test (pull_request) Successful in 2m3s

analysis/known/build_known.py writes data/public/known_answers.json from pdf_encounters.json and tree.json;
solver.js knownAnswer(known, offered, { target, sceneColour }) matches a screen's choices against it (the guide's
paraphrases by their words, the bot's texts exactly) and returns a pick when one choice is clearly on the guide's
recommended path to the target, plus the evidence for every choice to hand to Clef. Rebuilt daily, checked in CI,
and sent to the bot with the route model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
ekcSchiano
2026-11-19 13:32:09 +00:00
co-authored by Claude Opus 5.5
parent fefc163e09
commit e10312ab02
7 changed files with 2542 additions and 7 deletions
+64 -1
View File
@@ -15,6 +15,9 @@
* shadow odds), `fix` (hold some decisions to given options: an experiment arm) and sampling "uniform" (mapping);
* assign(plan, { accountSeq, attempt }) reads the experiment plan (experiments.json) and says what an attempt is for;
* screenPick(tree, sceneId, offered, { mode }) picks from the screen tree (tree.json): least-tried, or Thompson.
* knownAnswer(known, offered, { target, sceneColour }) looks a screen's choices up in known_answers.json (the guide's
* encounter answers and the bot's own results) for screens nothing else covers: a pick when the evidence is clear,
* and the evidence for every choice either way, to hand to Clef (issue #35).
* UMD: window.ThreshSolver in the browser, module.exports in Node. No dependencies.
*/
(function (root, factory) {
@@ -446,8 +449,68 @@
reason: mode === "thompson" ? `survived ${pick.survived} of ${pick.n} so far` : `played ${pick.n} times, the fewest on this screen` };
}
/* ---------- known answers (analysis/known/build_known.py -> data/public/known_answers.json) ---------- */
const STOP = new Set("a an the to and or of your you its it is for at in on with this that be".split(" "));
const words = (t) => norm(t).split(" ").filter((w) => w && !STOP.has(w));
/** The guide labels a game text carries: the guide paraphrases ("Touch its talon"), the game says it in full ("Reach a
* hand slowly to touch its talon"), so a label matches when every word of it that matters is in the text. Labels of
* fewer than two such words ("Is your dragon") only match a text that is exactly the label. */
function guideMatches(known, text) {
const n = norm(text), have = new Set(words(text)), out = [];
for (const [k, e] of Object.entries(known.answers || {})) {
if (!e.guide) continue;
const w = words(e.text);
const exact = k === n;
if (exact || (w.length >= 2 && w.every((x) => have.has(x)))) e.guide.forEach((g) => out.push({ ...g, label: e.text, exact }));
}
return out;
}
/**
* A screen nothing else covers: what the Atlas knows about each choice, and a pick when it is clear.
* known data/public/known_answers.json
* offered the choice texts on screen, in order
* target the colour the account is after ("Blue"); sceneColour: the colour of this scene's dragon, if the
* bot knows it (only the guide's answers for that dragon's encounters are used then)
* Returns { pick, confidence, reason, choices }: pick is the index to take (null if nothing is clear), confidence
* "strong" (exactly one choice is on the guide's recommended path toward the target, and the bot's own runs don't
* contradict it) or "weak" (several fit, or only the bot's own record speaks for it). choices[i].verdict is "good",
* "bad" (the guide ends it in incineration, or the bot died on it at least 3 times in 4) or "unknown", with the
* evidence behind it. Anything weak or unknown goes to Clef with this evidence; a pick never skips the bot's guard.
*/
function knownAnswer(known, offered, { target, sceneColour = null } = {}) {
const T = target ? target[0].toUpperCase() + target.slice(1).toLowerCase() : null;
const choices = offered.map((text, index) => {
const e = (known.answers || {})[norm(text)] || {};
const bot = e.bot || null;
const guide = guideMatches(known, text).filter((g) => !sceneColour || (g.colours || []).includes(sceneColour));
const onPath = guide.filter((g) => T && (g.on_path || []).includes(T));
const botBad = bot && bot.n >= 2 && bot.died / bot.n >= 0.75;
const botGood = bot && bot.n >= 3 && bot.died === 0;
const guideBad = guide.length > 0 && guide.every((g) => /^Incinerated/.test(g.end));
const verdict = onPath.length && !botBad ? "good" : guideBad || botBad ? "bad" : "unknown";
return { index, text, verdict, guide, bot, onPath: onPath.length > 0, botGood: !!botGood };
});
const good = choices.filter((c) => c.verdict === "good");
let pick = null, confidence = null, reason = "nothing the Atlas knows covers these choices";
if (good.length === 1) {
pick = good[0].index; confidence = "strong";
reason = `on the guide's recommended path to the ${T} ("${good[0].onPath && good[0].guide.find((g) => (g.on_path || []).includes(T)).label}")`;
} else if (good.length > 1) {
const best = good.find((c) => c.botGood) || good[0];
pick = best.index; confidence = "weak"; reason = `${good.length} choices are on the guide's paths; the bot's record favours none clearly`;
} else {
const safe = choices.filter((c) => c.botGood && c.verdict !== "bad");
if (safe.length) {
const b = safe.reduce((x, y) => (y.bot.n > x.bot.n ? y : x));
pick = b.index; confidence = "weak"; reason = `the bot got through it ${b.bot.n} of ${b.bot.n} times`;
}
}
return { pick, confidence, reason, choices };
}
return Object.assign(api, {
advisor, recommendOption, solverHistory, norm, assign, armFor, givenFor, screenPick,
advisor, recommendOption, solverHistory, norm, assign, armFor, givenFor, screenPick, knownAnswer,
makeParams: (T, { alphas, game } = {}) => makeParams(T, { alphas, game: game || api.game }),
/** remember the game of a policy sample (sets ENCOUNTERS) without solving anything */
useGame(sample) { api.game = sample.model.game; api.ENCOUNTERS = api.game.by_colour; return api.game; },