diff --git a/core/atlas/model.py b/core/atlas/model.py index d9df446..a7baccc 100644 --- a/core/atlas/model.py +++ b/core/atlas/model.py @@ -73,6 +73,10 @@ def prepare_run(r): v["sightUnknown"] = True # no answer after the first dragon: whether the rider survived it is not known return v res = r["resolution"] + # the choices at the scream, by their names in game.yaml (gates are written with these) + v["scream"] = "Keep walking" if r["scream"] == "Ignore the scream" else "Investigate the scream" + if r["scream"] in ("Investigate & help", "Investigate & leave"): + v["clearing"] = "Help your squadmate" if r["scream"] == "Investigate & help" else "Walk away" if r["scream"] == "Investigate & help": v["help"] = True v["fight"] = FIGHT_OF.get(r.get("combat_first")) @@ -129,13 +133,19 @@ def prepare_run(r): return v -# what each chance event observed in a prepared run +def gate_open(node, state): + """Whether a gated roll (game.yaml `requires`) can come out any other way than `otherwise`.""" + req = CHANCE[node].get("requires") or {} + return all(state.get(k) == v for k, v in req.items()) + + +# what each chance event observed in a prepared run (a gated roll only where its gate was open) OBSERVE = { "fs": lambda v: v.get("fs"), "dieSight": lambda v: ("die" if v.get("diedSight") else "live") if v.get("fs") and not v.get("sightUnknown") else None, "dieCombat": lambda v: ("die" if v.get("diedCombat") else "live") if v.get("help") else None, "dieHour": lambda v: ("die" if v.get("diedHour") else "live") if v.get("survivedCadets") else None, - "shadow": lambda v: None if "shadow" not in v else ("yes" if v["shadow"] else "no"), + "shadow": lambda v: None if "shadow" not in v or not gate_open("shadow", v) else ("yes" if v["shadow"] else "no"), "shadowColour": lambda v: v.get("shadowColour"), "meadow": lambda v: v.get("meadow"), } @@ -389,6 +399,9 @@ class Params: return self.memo[mk] def chance(self, node, state): + if not gate_open(node, state): # a closed gate: the roll always comes out the same way + other = CHANCE[node]["otherwise"] + return {k: np.full(self.D, 1.0 if k == other else 0.0) for k in CHANCE[node]["outcomes"]} # once every world has been drawn, the answer depends only on the context values: cache it ck = (node, tuple(state.get(k) for k in CHANCE[node]["context"])) if self.world is None and ck in self._cache: diff --git a/core/solver.js b/core/solver.js index baafe34..9e3a660 100644 --- a/core/solver.js +++ b/core/solver.js @@ -55,6 +55,8 @@ const ctxKey = (s, names) => names.map((k) => (s[k] == null ? "?" : s[k])).join("|"); function chance(node, state) { const sp = game.chance[node], cats = sp.outcomes; + // a closed gate (game.yaml `requires`): the roll always comes out as `otherwise` + if (sp.requires && Object.entries(sp.requires).some(([k, v]) => state[k] !== v)) return Object.fromEntries(cats.map((k) => [k, k === sp.otherwise ? 1 : 0])); let p = null; for (let L = 0; L <= sp.context.length; L++) { const names = sp.context.slice(0, L); diff --git a/core/spec/game.yaml b/core/spec/game.yaml index 3360d21..0f12a20 100644 --- a/core/spec/game.yaml +++ b/core/spec/game.yaml @@ -48,14 +48,22 @@ min_support: 20 # ---------------------------------------------------------------- chance events: the game's rolls # outcomes: in a fixed order. context: the earlier steps the odds may depend on, most important first; the # estimate for a full context is shrunk toward the estimate for a shorter one (hierarchical Dirichlet back-off, -# strength learned from the data). +# strength learned from the data). requires: earlier choices without which the roll always comes out as +# `otherwise` (a gate); runs that did not make them say nothing about the roll and are not counted. chance: fs: { label: First dragon, outcomes: [Red, Brown, Green, Orange], context: [direction, company, left] } # rolls that can kill you: risk_label names the danger when the advisor reports it dieSight: { label: Survive the first dragon, outcomes: [die, live], context: [fs, direction, company, left, react], risk_label: Killed at the first sighting } dieCombat: { label: Survive the fight, outcomes: [die, live], context: [fight, dagger, fs, direction], risk_label: Killed in the fight } dieHour: { label: Survive the hour, outcomes: [die, live], context: [cadet, post], risk_label: Killed before the hour } - shadow: { label: Shadow at the tree, outcomes: ["yes", "no"], context: [cadet, post, fs, direction, company] } + shadow: + label: Shadow at the tree + outcomes: ["yes", "no"] + context: [cadet, post, fs, direction, company] + # the "Black Dragon Gates" of the community route PDF (November 2026). The runs agree: in the spreadsheet, + # 78 shadows in 4199 tree runs that investigated and helped, 2 (both form submissions) in 646 that did not. + requires: { scream: Investigate the scream, clearing: Help your squadmate } + otherwise: "no" shadowColour: { label: Shadow dragon, outcomes: [Black, Blue], context: [] } meadow: { label: Meadow dragon, outcomes: [Orange, Brown, Blue], context: [cadet, post, fs, direction, company] } diff --git a/docs/BOT_INTEGRATION.md b/docs/BOT_INTEGRATION.md index 44141a6..eb7c087 100644 --- a/docs/BOT_INTEGRATION.md +++ b/docs/BOT_INTEGRATION.md @@ -165,6 +165,10 @@ Current headline, with the bot's runs and the reporting-bias correction (Novembe attempt (90% range 0–0.15%: the bot and bulk logs have never seen the shadow in about 700 tree runs), Blue about 1.8–2.5% per attempt (40–55 attempts), depending on the sample. +The shadow is gated: it can only appear on runs that investigated the scream and helped the squadmate (the +"Black Dragon Gates" of the community route PDF, and the runs agree). The model knows this +(`core/spec/game.yaml`, `requires`), so it never sends a Black attempt off the gate. + Form submissions over-report rare sightings: riders report a meadow Blue about 4 times more readily than a meadow without one. The model estimates that bias for each kind of source and corrects for it (`planner/policy.yaml`, `reporting_bias`; the estimates are in `policy.json` under `model.reportingBias`). diff --git a/tests/core/test_bias.py b/tests/core/test_bias.py index 908795f..6a6c032 100644 --- a/tests/core/test_bias.py +++ b/tests/core/test_bias.py @@ -50,3 +50,20 @@ class Bias(unittest.TestCase): if __name__ == "__main__": unittest.main() + + +class Gate(unittest.TestCase): + def test_closed_gate_fixes_the_roll_and_is_not_counted(self): + spec = model.CHANCE["shadow"] + self.assertTrue(spec.get("requires")) + state = {"scream": "Keep walking"} + self.assertFalse(model.gate_open("shadow", state)) + p = model.Params({"shadow": {"0:": {"yes": 5, "no": 5}}}, "mean").chance("shadow", state) + self.assertEqual((float(p["yes"][0]), float(p["no"][0])), (0.0, 1.0)) + # a tree run that ignored the scream says nothing about the shadow + run = meadow_run("bot", "Orange") + run.update(hour="Tree", branch="Descend slowly: two Greens", scream="Ignore the scream") + self.assertIsNone(model.OBSERVE["shadow"](model.prepare_run(run))) + run.update(scream="Investigate & help", resolution="Killed the bullies yourself", post_path="Forest", + combat_first="Assess the situation", combat_second="Engage the smaller cadet") + self.assertEqual(model.OBSERVE["shadow"](model.prepare_run(run)), "no")