diff --git a/core/atlas/model.py b/core/atlas/model.py index a7baccc..f5e335e 100644 --- a/core/atlas/model.py +++ b/core/atlas/model.py @@ -158,6 +158,12 @@ def ctx_key(v, names): # ---------------------------------------------------------------- 2. counts +def can_bond(ctx, colour): + """Whether a bond with this colour is possible at this encounter (game.yaml `encounters`).""" + e = G["encounters"][ctx] + return colour == "burn" or colour == e["colour"] or colour in (e.get("also") or []) + + def count_tables(prepared, weights=None): """Counts for every chance event at every back-off level, plus each encounter's outcomes. weights: per run, {chance event: weight of the outcome it observed} (reporting-bias corrections, core/atlas/bias.py).""" @@ -187,11 +193,11 @@ def count_tables(prepared, weights=None): if not v.get("encCtx"): continue c = enc.setdefault(v["encCtx"], {"outcomes": {}, "seen": {}}) - if v.get("encOutcome"): + if v.get("encOutcome") and can_bond(v["encCtx"], v["encOutcome"]): c["outcomes"][v["encOutcome"]] = c["outcomes"].get(v["encOutcome"], 0) + 1 # which colours can ever end a run in this context (from all runs, genuine or not) for v in prepared: - if v.get("encCtx") and v.get("encOutcome") and v["encOutcome"] != "burn": + if v.get("encCtx") and v.get("encOutcome") and v["encOutcome"] != "burn" and can_bond(v["encCtx"], v["encOutcome"]): enc[v["encCtx"]]["seen"][v["encOutcome"]] = 1 return T diff --git a/core/spec/game.yaml b/core/spec/game.yaml index 0f12a20..c75d586 100644 --- a/core/spec/game.yaml +++ b/core/spec/game.yaml @@ -67,11 +67,13 @@ chance: shadowColour: { label: Shadow dragon, outcomes: [Black, Blue], context: [] } meadow: { label: Meadow dragon, outcomes: [Orange, Brown, Blue], context: [cadet, post, fs, direction, company] } -# Bonding encounters: where each colour can be bonded. tree-Greens can also end in an Orange or Brown rescue. +# Bonding encounters: where each colour can be bonded. A run can only bond the encounter's own colour, except at +# the two Greens, where an Orange or a Brown can swoop in (`also`). A recorded bond with any other colour is a +# data-entry error and is not counted. encounters: valley-Red: { label: The valley Red, colour: Red } tree-Red: { label: The Red below the tree, colour: Red } - tree-Greens: { label: The two Greens, colour: Green } + tree-Greens: { label: The two Greens, colour: Green, also: [Orange, Brown] } meadow-Orange: { label: The meadow Orange, colour: Orange } meadow-Brown: { label: The meadow Brown, colour: Brown } meadow-Blue: { label: The meadow Blue, colour: Blue } diff --git a/tests/core/test_bias.py b/tests/core/test_bias.py index 6a6c032..ec9da99 100644 --- a/tests/core/test_bias.py +++ b/tests/core/test_bias.py @@ -67,3 +67,16 @@ class Gate(unittest.TestCase): 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") + + +class PossibleBonds(unittest.TestCase): + def test_impossible_bond_is_not_counted(self): + good = meadow_run("reddit spreadsheet", "Orange") + good.update(hour="Tree", branch="Shadow (rare)", outcome="Bonded", outcome_color="Black", enc_Black="Bonded!", + enc_Orange=None, goal="Black", scream="Investigate & help", resolution="Killed the bullies yourself", + post_path="Forest", combat_first="Assess the situation", combat_second="Engage the smaller cadet") + bad = dict(good, enc_Black=None, enc_Blue="Incinerated", outcome_color="Green", goal="Any (for fun)") + T = model.count_tables([model.prepare_run(good), model.prepare_run(bad)]) + self.assertEqual(T["encounter"]["shadow-Black"]["outcomes"], {"Black": 1}) + self.assertEqual(T["encounter"]["shadow-Blue"]["outcomes"], {}) # a Green at the Blue: not counted + self.assertTrue(model.can_bond("tree-Greens", "Brown"))