Advisor: never advise an option that makes the target impossible while another keeps it possible
CI / test (pull_request) Successful in 57s
CI / test (pull_request) Successful in 57s
On a later attempt the data put the Black near zero on every route, so every option tied and the bot's tie rule (random among options within 0.2 points) walked away from the squadmate or went to the valley (DragonKind research runs 90, 91 and 102). The advisor now also solves the game with no data (every roll possible except through a closed gate; an encounter bonds its own colour) and marks options after which the target cannot happen at all as `ruledOut`. The choice is never one of them while another option keeps the target possible, and recommendOption leaves them out of the options it gives the bot. For the Black: always investigate, help and climb the tree. Values are unchanged; the published route tree still matches option for option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
+26
-7
@@ -236,14 +236,30 @@
|
||||
if (!worlds) worlds = Array.from({ length: draws }, (_, i) => solveWith(rng(seed * 7919 + i + 1)).sol.choices);
|
||||
return worlds.filter((c) => c.get(key) === choice).length / draws;
|
||||
};
|
||||
// What the game allows, whatever the data say: the same game solved with no runs at all, so every roll can come
|
||||
// out every way except through a closed gate (game.yaml `requires`), and an encounter bonds only its own colour
|
||||
// (and any colour seen there). An option after which X cannot happen at all is never advised while another option
|
||||
// keeps X possible, however small the data make every option's odds. Without this, when the data put X near zero
|
||||
// on every route (the Black on a later attempt), every option ties and a tie-breaking rider or bot may walk away
|
||||
// from the squadmate or go to the valley: the Black needs the gates and the tree (game.yaml, the community PDF and
|
||||
// the developer).
|
||||
const emptyTables = { encounter: {}, ...Object.fromEntries(Object.keys(game.chance).map((k) => [k, {}])) };
|
||||
const reach = solve(makeParams(emptyTables, { game, given: known }), game, support, X, 0, only).optVals;
|
||||
const possibleAt = (key, vals) => Object.keys(vals).filter((o) => vals[o].x > 0 || (((reach.get(key) || {})[o]) || ZERO).x > 0);
|
||||
/** The choice at a history among the options that keep X possible (if any does), and the options ruled out. */
|
||||
const advisedAt = (key) => {
|
||||
let vals = sol.optVals.get(key) || {}, choice = sol.choices.get(key);
|
||||
const can = possibleAt(key, vals), ruledOut = Object.keys(vals).filter((o) => !can.includes(o));
|
||||
if (can.length && ruledOut.length && !can.includes(choice)) choice = can.reduce((b, o) => (vals[o].x > vals[b].x ? o : b), can[0]);
|
||||
return { vals, choice, ruledOut: can.length ? ruledOut : [] };
|
||||
};
|
||||
const VARS = new Set([...Object.keys(game.decisions), ...Object.keys(game.chance), "encounter"]);
|
||||
const fmt = (v) => ({ pX: v.x, pOther: v.o, pReach: v.r });
|
||||
const label = (k) => (game.decisions[k] || game.chance[k]).label;
|
||||
const decisionAt = (name, key, extra) => {
|
||||
const vals = sol.optVals.get(key) || {};
|
||||
const choice = sol.choices.get(key);
|
||||
const { vals, choice, ruledOut } = advisedAt(key);
|
||||
return { kind: "decision", var: name, label: label(name), choice, propensity: propensityAt(key, choice),
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...extra };
|
||||
options: Object.fromEntries(Object.entries(vals).map(([o, v]) => [o, fmt(v)])), ...(ruledOut.length ? { ruledOut } : {}), ...extra };
|
||||
};
|
||||
|
||||
/** The next thing that happens after history h: a decision, a roll, or the end of the run. */
|
||||
@@ -257,7 +273,7 @@
|
||||
if (st.decision) {
|
||||
const name = st.decision, key = name + "@" + canon(state);
|
||||
if (h[name] != null) { value = h[name]; used.add(name); }
|
||||
else if (later()) value = sol.choices.get(key);
|
||||
else if (later()) value = advisedAt(key).choice;
|
||||
else return decisionAt(name, key, risk ? { risk } : {});
|
||||
risk = null;
|
||||
} else {
|
||||
@@ -286,7 +302,7 @@
|
||||
/** the next decision only (null when the next step is a roll or the run is over) */
|
||||
next(h) {
|
||||
const s = step(h);
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options } : null;
|
||||
return s.kind === "decision" ? { decision: s.var, label: s.label, choice: s.choice, propensity: s.propensity, options: s.options, ...(s.ruledOut ? { ruledOut: s.ruledOut } : {}) } : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -322,10 +338,13 @@
|
||||
}
|
||||
const pat = pats[rec.choice];
|
||||
const idx = pat ? texts.findIndex((t) => new RegExp(pat).test(t)) : -1;
|
||||
const values = Object.values(rec.options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
// options after which the target cannot happen at all are not offered to the bot (its tie rule picks among
|
||||
// `options`): see advisor's `ruledOut`
|
||||
const options = rec.ruledOut ? Object.fromEntries(Object.entries(rec.options).filter(([o]) => !rec.ruledOut.includes(o))) : rec.options;
|
||||
const values = Object.values(options).map((v) => v.pX).sort((a, b) => b - a);
|
||||
return { index: idx < 0 ? null : idx, decision: rec.decision, choice: rec.choice, propensity: rec.propensity,
|
||||
margin: values.length > 1 ? values[0] - values[1] : null,
|
||||
options: rec.options,
|
||||
options, ...(rec.ruledOut ? { ruledOut: rec.ruledOut } : {}),
|
||||
reason: idx < 0 && rec.decision !== "encounter" ? "the recommended choice is not on this screen; use the bot's own rules" : `${rec.label}: ${rec.choice}` };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user