Step 2 of the Python-first, declarative core. - core/spec/game.yaml: the game as data: every decision and its options, every roll and the earlier steps its odds may depend on, every bonding encounter, and the flow of a run from the entrance to the dragons (set / keep / drop / go / end / encounter). Also how the form's coded answers map onto the game. - core/atlas/model.py: what each coded run reveals about each step, count tables, empirical-Bayes shrinkage, and the posterior draws (same random numbers as before, reproducible from the seed). - core/atlas/solver.py: one interpreter of game.yaml used three ways (solve, evaluate a fixed policy, export the published tree) instead of the tree written out five times. Vectorised over the 200 posterior draws: the build takes about 2 minutes instead of 4, with no memory flag. - planner/build_policy.py and policy_report.py replace the JS build and report. Checked against the JavaScript model: every number in policy.json agrees to within 4e-12 (last-digit differences in log/cos). Three "still best" shares differ by one draw in 200, at near-ties under the "eventually" objective. POLICY.md is otherwise identical. tests/parity/compare_solver.py keeps checking JS against Python in CI until the site's JS advisor replaces solver.js; tests/core/test_game.py checks game.yaml is complete and consistent. Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
"""The game tree in core/spec/game.yaml must be complete and consistent."""
|
|
import unittest
|
|
|
|
from atlas import spec
|
|
|
|
G = spec.game()
|
|
|
|
|
|
class GameSpec(unittest.TestCase):
|
|
def test_every_step_is_reachable_and_every_go_exists(self):
|
|
seen, todo = set(), [G["start"]]
|
|
while todo:
|
|
s = todo.pop()
|
|
if s in seen:
|
|
continue
|
|
seen.add(s)
|
|
self.assertIn(s, G["steps"], f"go: {s} has no step")
|
|
for t in G["steps"][s]["then"].values():
|
|
if "go" in t:
|
|
todo.append(t["go"])
|
|
self.assertEqual(seen, set(G["steps"]), "steps nobody goes to")
|
|
|
|
def test_decisions_and_rolls_are_defined(self):
|
|
for name, st in G["steps"].items():
|
|
if "decision" in st:
|
|
d = G["decisions"][st["decision"]]
|
|
for opt in st["then"]:
|
|
self.assertTrue(opt == "default" or opt in d["options"], f"{name}: unknown option {opt}")
|
|
else:
|
|
c = G["chance"][st["chance"]]
|
|
for out in st["then"]:
|
|
self.assertTrue(out == "default" or out in c["outcomes"], f"{name}: unknown outcome {out}")
|
|
|
|
def test_every_branch_says_what_happens(self):
|
|
for name, st in G["steps"].items():
|
|
for k, t in st["then"].items():
|
|
self.assertEqual(sum(x in t for x in ("go", "end", "encounter")), 1, f"{name}/{k}")
|
|
|
|
def test_encounters_exist(self):
|
|
for name, st in G["steps"].items():
|
|
for t in st["then"].values():
|
|
if "encounter" in t and "$" not in t["encounter"]:
|
|
self.assertIn(t["encounter"], G["encounters"])
|
|
for c, encs in G["by_colour"].items():
|
|
for e in encs:
|
|
self.assertIn(e, G["encounters"])
|
|
|
|
def test_chance_contexts_are_earlier_steps(self):
|
|
known = {"company", "left", "direction", "fs", "react", "scream", "clearing", "fight", "dagger", "cadet", "post",
|
|
"hour", "shadow", "descend", "red", "valley", "meadow"}
|
|
for k, c in G["chance"].items():
|
|
self.assertTrue(set(c["context"]) <= known, k)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|