"""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", "attempt_group": "Later attempt", "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())))