Core: a small JS advisor reads the game from policy.json; engine.js is gone (#13)

Step 4b of the Python-first core.

- core/solver.js is now a 250-line advisor (was 900 lines): it reads the game (core/spec/game.yaml,
  published inside policy.json as model.game) and the count tables, and re-solves from any point in
  a run with the same interpreter as the Python model. Same API for the site and Ken's bot
  (advisor, recommendOption, solverHistory). The bot's on-screen text for each option moves to
  game.yaml (bot_text); the deadly rolls carry their risk labels there too.
- tests/core/advisor.test.js: the advisor gives exactly the Python model's values and choices for
  every colour and goal (to 1e-12, every decision on every published route), walks a run in the
  game's order, and maps advice onto the bot's screen.
- Removed core/engine.js and everything that only compared it with Python (tests/parity/run_engine,
  compare_runs, compare_results, compare_routes, compare_solver, compare_stats, analysis/stats/
  analyze.py). In their place: tests/core/test_stats.py checks the statistics against known answers,
  test_solver.py checks the route model on a synthetic world (tests/fixtures/synthetic_policy.py).
- analysis/network/build-graph.js reads the Python-coded runs; graph.json is byte-identical.
- docs/BOT_INTEGRATION.md: what changed for the bot (history keys, new choices, re-sync all three files).


Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ekcSchiano
2026-11-03 22:01:32 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent d04b88e7b4
commit 11b4a0398e
27 changed files with 578 additions and 2260 deletions
+61
View File
@@ -0,0 +1,61 @@
"""A small synthetic world for testing the route model, and its policy.
The meadow shows Blue 30% of the time, the shadow appears 2% of the time, facing the valley Red always bonds it,
the Greens burn half the time and bond Brown (rescue) a quarter of the time.
python tests/fixtures/synthetic_policy.py OUT.json (used by tests/core/advisor.test.js)
"""
import json
import random
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "core"))
from atlas import solver # noqa: E402
def world(n=4000, seed=7):
r = random.Random(seed).random
runs = []
for i in range(n):
run = {"company": "Alone", "direction": ["East", "West", "Center"][i % 3], "first_sighting": ["Red", "Brown"][i % 2],
"scream": "Investigate & help", "resolution": ["Killed the bullies yourself", "Squadmate's revenge"][i % 2],
"post_path": "Forest", "goal": "Any (for fun)", "malek_intent": "No", "left_squadmates": False,
"sighting_action": "Unknown", "combat_first": "(not recorded)", "combat_second": "(not recorded)", "rare_reported": "No",
**{f"enc_{c}": None for c in ("Red", "Green", "Orange", "Brown", "Blue", "Black")}}
run["hour"] = "Tree" if r() < 0.5 else "Valley"
if run["hour"] == "Tree":
if r() < 0.02:
run.update(branch="Shadow (rare)", enc_Black="Bonded!", outcome="Bonded", outcome_color="Black")
elif r() < 0.5:
run.update(branch="Descend quickly: Red", enc_Red="Incinerated", outcome="Incinerated", outcome_color="Red")
else:
run["branch"] = "Descend slowly: two Greens"
u = r()
if u < 0.5:
run.update(enc_Green="Incinerated", outcome="Incinerated", outcome_color="Green")
elif u < 0.75:
run.update(enc_Green="Bonded!", outcome="Bonded", outcome_color="Green")
else:
run.update(enc_Green="Saved by another", enc_Brown="Bonded!", outcome="Bonded", outcome_color="Brown")
elif r() < 0.2:
run.update(branch="Valley Red", enc_Red="Bonded!", outcome="Bonded", outcome_color="Red")
else:
run["branch"] = "Passed the Red: meadow"
u = r()
c = "Blue" if u < 0.3 else "Orange" if u < 0.65 else "Brown"
bond = r() < 0.5
run.update({"enc_" + c: "Bonded!" if bond else "Incinerated", "outcome": "Bonded" if bond else "Incinerated", "outcome_color": c})
runs.append(run)
return runs
def policy(draws=10, colours=("Blue", "Black", "Red", "Brown")):
return solver.build_policy(world(), draws=draws, colours=list(colours))
if __name__ == "__main__":
sys.path.insert(0, str(ROOT / "planner"))
from build_policy import clean
Path(sys.argv[1]).write_text(json.dumps(clean(policy())))