Solver: best decisions per dragon colour, and the bot advisor

- packages/core/src/solver.js: decision tree with perfect recall over the
  community form's choices; chance events (first dragon, deaths, shadow,
  meadow dragon, encounter outcome) depend on earlier choices through
  hierarchical Dirichlet back-off with empirical-Bayes concentration per
  event; backward induction for P(colour this attempt) and Dinkelbach for
  P(colour) / (P(colour) + P(other colour)); 200 posterior draws for
  credible intervals and "still best" rates; cross-fitted held-out check.
- Only genuine attempts inform encounter outcomes (goal / Malek intent).
- data/public/policy.json (all runs and a low-bias sample) and the readable
  docs/POLICY.md; published on Pages with solver.js for the bot.
- Bot advisor: re-solves from any history, maps advice onto screen text,
  reports margins so ties can be randomised. docs/BOT_INTEGRATION.md.
- Tests on a synthetic world with known answers; daily source update now
  rebuilds the policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
ekcSchiano
2026-11-01 22:34:38 +00:00
co-authored by Claude Opus 5.5
parent 46ee08a56b
commit d2ffb84b5e
12 changed files with 1842 additions and 5 deletions
+1
View File
@@ -25,6 +25,7 @@ jobs:
if: steps.check.outputs.changed == 'true' if: steps.check.outputs.changed == 'true'
run: | run: |
node scripts/build-graph.js node scripts/build-graph.js
npm run policy
npm test npm test
- name: Open a pull request with the new data - name: Open a pull request with the new data
if: steps.check.outputs.changed == 'true' if: steps.check.outputs.changed == 'true'
+12
View File
@@ -13,11 +13,14 @@ packages/core/ @threshing-atlas/core, no dependencies, runs in Node and
src/engine.js coding rules and statistics for the community form src/engine.js coding rules and statistics for the community form
src/graph.js the shared route graph: scene graph, decision-variable graph, src/graph.js the shared route graph: scene graph, decision-variable graph,
bot-to-form crosswalk, Beta credible intervals bot-to-form crosswalk, Beta credible intervals
src/solver.js best decisions per dragon colour (history-dependent decision tree,
empirical-Bayes back-off, two objectives) + the bot advisor
packages/ingest/ @threshing-atlas/ingest: DragonKind bot importer (fingerprints and choice text only) packages/ingest/ @threshing-atlas/ingest: DragonKind bot importer (fingerprints and choice text only)
research/python/ independent Python implementation of the coding rules and statistics research/python/ independent Python implementation of the coding rules and statistics
tests/ JS/Python parity tests (they fail loudly if the two disagree) tests/ JS/Python parity tests (they fail loudly if the two disagree)
scripts/build-site.js assembles the static site into dist/ scripts/build-site.js assembles the static site into dist/
scripts/build-graph.js combines every source into data/public/graph.json scripts/build-graph.js combines every source into data/public/graph.json
scripts/build-policy.js solves for every colour -> data/public/policy.json; policy-report.js -> docs/POLICY.md
data/raw/ source exports (form .xlsx; the register export stays local, git-ignored) data/raw/ source exports (form .xlsx; the register export stays local, git-ignored)
data/public/ what the page loads: form_responses.json, register.json, graph.json data/public/ what the page loads: form_responses.json, register.json, graph.json
data/sources.json where the community spreadsheets and the PDF are downloaded from data/sources.json where the community spreadsheets and the PDF are downloaded from
@@ -44,6 +47,15 @@ the PDF the pages and lines that are new. The PDF itself is never committed, onl
(`data/derived/pdf_fingerprint.json`). If a link stops working, the Action opens an issue. You can also (`data/derived/pdf_fingerprint.json`). If a link stops working, the Action opens an issue. You can also
run it by hand from the Actions tab, or locally with `npm run check-sources`. run it by hand from the Actions tab, or locally with `npm run check-sources`.
## Best routes (the solver)
`npm run policy` rebuilds `data/public/policy.json` and the readable `docs/POLICY.md` (about 2.5 minutes:
200 posterior draws for two data samples). For every colour it gives the best decision at every point under two
objectives: the chance of bonding that colour on this attempt, and the chance the account eventually ends on that
colour when you die on purpose whenever a run goes wrong. Chance events (which dragon appears, whether the shadow
shows) may depend on earlier choices; how much is learned from the data. See the top of
`packages/core/src/solver.js` for the model and `docs/BOT_INTEGRATION.md` for how the bot uses it.
## Bot data ## Bot data
The private DragonKind bot's files are converted locally, and only the anonymised result is committed: The private DragonKind bot's files are converted locally, and only the anonymised result is committed:
File diff suppressed because one or more lines are too long
+133
View File
@@ -0,0 +1,133 @@
# Connecting the DragonKind bot to the atlas
Data flows both ways:
```
community form, register, PDF ──┐
├─► threshing-atlas ──► policy.json + solver.js ──► bot (advice per screen)
bot runs (anonymised) ──────────┘ ▲ │
└──────────── import-bot + pull request ◄──┘
```
## 1. From the atlas to the bot
### What is published
GitHub Pages serves these files (they update whenever new data is merged):
| File | What it is |
|---|---|
| `https://ekcschiano.github.io/threshing-atlas/data/policy.json` | The model: count tables, fitted shrinkage, allowed options, and for every colour the recommended decision tree under both objectives, with credible intervals. About 400 KB. Has an `id` (content hash). |
| `https://ekcschiano.github.io/threshing-atlas/solver.js` | The solver and the bot helper (`advisor`, `recommendOption`, `solverHistory`). No dependencies, CommonJS or browser. |
| `https://ekcschiano.github.io/threshing-atlas/graph.js` | `trajectoryVariables()`: turns the bot's step trail into the community form's variables. |
### Getting them into the bot
Keep a pinned local copy, so a bad publish can never change the bot mid-run. A small sync script in the bot
repo (for example `scripts/sync-atlas.js`):
```js
// node scripts/sync-atlas.js -> vendor/threshing-atlas/{solver.js,graph.js,policy.json}
const fs = require('node:fs');
const path = require('node:path');
const BASE = 'https://ekcschiano.github.io/threshing-atlas/';
const OUT = path.join(__dirname, '..', 'vendor', 'threshing-atlas');
(async () => {
fs.mkdirSync(OUT, { recursive: true });
for (const f of ['solver.js', 'graph.js', 'data/policy.json']) {
const res = await fetch(BASE + f);
if (!res.ok) throw new Error(`${f}: HTTP ${res.status}`);
const body = await res.text();
if (f.endsWith('.json')) JSON.parse(body); // refuse a broken file
fs.writeFileSync(path.join(OUT, path.basename(f)), body);
}
const { id } = JSON.parse(fs.readFileSync(path.join(OUT, 'policy.json'), 'utf8'));
console.log('atlas policy', id);
})();
```
Run it by hand, or once a day before the first attempt. Commit `vendor/threshing-atlas/` in the bot repo if you
want the exact policy in its history.
### Asking for advice on a screen
```js
const Solver = require('../vendor/threshing-atlas/solver.js');
const Graph = require('../vendor/threshing-atlas/graph.js');
const policy = require('../vendor/threshing-atlas/policy.json');
// once per attempt: target colour from settings, "eventually" because the bot burns on purpose
const advisor = Solver.advisor(policy.samples.all, 'Black', 'eventually');
// on every decision screen
function atlasAdvice(run, offeredChoiceTexts, seen) {
const { vars } = Graph.trajectoryVariables({ steps: run.steps, outcome: {} });
const h = Solver.solverHistory(vars, seen); // seen: { shadow: 'yes'|'no', shadowColour, meadow }
return Solver.recommendOption(advisor, h, offeredChoiceTexts);
}
```
`recommendOption` returns `null` when the next step is chance (nothing to decide), or
`{ index, decision, choice, margin, options, reason }`:
- `index` is the option to click, or `null` when the advice cannot be matched to this screen. Then use the bot's own rules.
- `decision === 'encounter'` comes without an index: `choice` is `"Attempt the bond"` or `"Die on purpose"`, and the
bot already knows which of its options do each.
- `margin` is the gap in P(target) between the best and second-best option. `options` has every option's value.
`seen` is what only the bot can observe: whether the shadow was at the treetop (`shadow: 'yes' | 'no'`), its colour
(`shadowColour`), and the colour waiting in the meadow (`meadow`), all from the scene tint.
The advisor re-solves the model on the bot's machine (a few milliseconds), so it gives advice from any history,
including runs that have already left the recommended route.
### Where it goes in the decision order
The atlas is advice. The bot's own safety rules stay in charge:
1. Account Lock Guard and the intentional-burn protection (never risk a non-target bond).
2. Atlas advice, when `index` is not null and the margin is clear (see ties below).
3. The bot's PDF strategy and learned rules.
Log every atlas pick with `rule: 'ATLAS_POLICY'`, `source: 'atlas'`, and the run-level `policyId: policy.id`
(see `docs/BOT_DATA_PROTOCOL.md`), so we can tell which policy produced which runs.
### Ties are free experiments
Many choices barely matter by the data we have (for Black, the first direction differs by a tenth of a percentage
point). When `margin` is below the tie threshold (start with 0.002, i.e. 0.2 percentage points), pick at random
among the tied options and log `propensity` (1 / number of tied options). That costs nothing in expected success,
and it is exactly the randomised data the atlas needs to tell real history effects from guide-copying.
### Which numbers to trust
`policy.json` has two samples:
- `samples.all`: every run. Use it for the advisor (more data, decisions are about relative differences).
- `samples.lowBias`: bulk logs and riders not chasing a rare dragon. Use it for absolute expectations, such as how
many attempts a Blue should take. Rare sightings are over-reported in form posts, so `all` is optimistic for Blue.
Current headline (from `docs/POLICY.md`): Black about 1.7% per attempt (about 60 attempts), Blue 3.7–7% per attempt
(14–28 attempts), depending on the sample.
## 2. From the bot to the atlas
Already in place: `npm run import-bot -- --bot /path/to/DragonKind` in the atlas repo converts the bot's
`knowledge.json`, `runs.jsonl` and `logs/encounters.jsonl` into anonymised files under `data/bot/`, and refuses to
write prose or account names. Commit them by pull request; CI rebuilds the graph and checks everything.
What would make the bot's data far more useful (details in `docs/BOT_DATA_PROTOCOL.md`):
- record the options on screen, what was seen (tint, shadow), `policyId`, `propensity` and `decisionMode` on every step;
- split goal accounts (follow the advisor) from research accounts (run the tie experiments and the
experiment list);
- add `accountKey` (salted hash), and the reason for every deliberate burn.
## 3. Limits to keep in mind
- The community form does not record the answers inside each bonding encounter, so the bond chance at an encounter is
the community average. The bot's own scene-level data will refine that over time.
- The model learns how much history matters from the data. Today it finds that the meadow colour does not depend on
earlier choices at all, and the shadow only weakly. The bot's randomised runs are what can confirm or overturn that.
- The policy is only as good as the crosswalk between the bot's screen text and the form's variables. If the game
changes its wording, `OPTION_PATTERNS` in `solver.js` and `CROSSWALK` in `graph.js` need updating.
+846
View File
@@ -0,0 +1,846 @@
# Best routes by dragon colour
Generated from 5651 community runs by `scripts/build-policy.js`. Machine-readable version: `data/public/policy.json`.
**How to read this.** "This attempt" maximises the chance of bonding the colour on one run. "Eventually" assumes you will die on purpose and try again whenever the run goes wrong, so it avoids any choice that can end the account on a different dragon. Percentages are posterior means with 95% credible intervals. "Held-out" is the same policy chosen on half of the runs and scored on the other half: when it is much lower than the in-sample number, the route's advantage is mostly noise.
**Caveats.** The form records choices only at the level of company, direction, first dragon, cadet encounter, fork, tree or valley, and which dragon you met. Choices inside each encounter are not recorded, so the bond chance at an encounter is the community's average with whatever answers people used. Riders chasing a rare dragon report sightings more often than riders who log every run; the "low-bias" columns use only bulk logs and non-chasers.
| Colour | This attempt | Low-bias sample | Held-out | Eventually: chance the account ends on this colour | Attempts needed (about) |
|---|---|---|---|---|---|
| Red | 92% (86%–97%) | 93% (87%–97%) | 92% | 100% | 1 |
| Orange | 16% (13%–19%) | 15% (12%–18%) | 16% | 98% | 6 |
| Brown | 8.1% (6.7%–9.8%) | 9.1% (6.8%–11%) | 7.8% | 96% | 13 |
| Green | 23% (19%–27%) | 21% (18%–26%) | 23% | 68% | 4 |
| Blue | 7.1% (6.1%–8.4%) | 3.7% (2.6%–5.0%) | 7.2% | 100% | 14 |
| Black | 1.7% (1.0%–2.6%) | 2.1% (0.8%–4.5%) | 1.4% | 100% | 63 |
## How much do earlier choices matter?
Each chance event can depend on the choices before it. The model learns how much from the data (empirical-Bayes concentration; larger means the history matters less):
| Chance event | Depends on (most important first) | Concentration |
|---|---|---|
| fs | direction, company | 10 |
| dieSight | fs, direction, company | 20 |
| dieCombat | fs, direction | 200 |
| dieHour | cadet, post | 100 |
| shadow | cadet, post, fs, direction, company | 1000 |
| shadowColour | nothing | 20 |
| meadow | cadet, post, fs, direction, company | 100000 |
## Red: this attempt
- **Company: Alone** (still best in 49% of posterior draws) — no clear winner. If chosen, then best play after: Alone 92%, 1 Squadmate 92%, 2 Squadmates 91%
- **First direction: Center** (still best in 83% of posterior draws). If chosen, then best play after: Center 92%, West 92%, East 91%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 91%, Killed the bullies yourself 91%, Left bullies to the dragons 91%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.2%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 91%, Killed the bullies yourself 91%, Left bullies to the dragons 91%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.2%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 88%, Killed the bullies yourself 88%, Left bullies to the dragons 88%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.2%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 89%, Killed the bullies yourself 89%, Left bullies to the dragons 89%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.2%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
## Red: eventually
- **Company: Alone** (still best in 49% of posterior draws) — no clear winner. If chosen, then best play after: Alone 92%, 1 Squadmate 92%, 2 Squadmates 91%
- **First direction: Center** (still best in 83% of posterior draws). If chosen, then best play after: Center 92%, West 92%, East 91%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 91%, Killed the bullies yourself 91%, Left bullies to the dragons 91%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 91%, Killed the bullies yourself 91%, Left bullies to the dragons 91%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 88%, Killed the bullies yourself 88%, Left bullies to the dragons 88%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 93%, Tourniquet 93%, Took their weapons 92%, Left them to it 92%, Squadmate's revenge 89%, Killed the bullies yourself 89%, Left bullies to the dragons 89%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 93%, Tree 3.8%
- **Valley centre: Face the Red** (still best in 100% of posterior draws). If chosen, then best play after: Face the Red 93%, Pass the Red (meadow) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 93%, Die on purpose 0.0%
- Outcome if you attempt: bond Red 93%, incinerated 7.1%
## Orange: this attempt
- **Company: Alone** (still best in 57% of posterior draws) — no clear winner. If chosen, then best play after: Alone 16%, 1 Squadmate 16%, 2 Squadmates 16%
- **First direction: Center** (still best in 64% of posterior draws) — no clear winner. If chosen, then best play after: Center 16%, West 16%, East 16%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 41% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Left bullies to the dragons 16%, Squadmate's revenge 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 6.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 44% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Squadmate's revenge 16%, Left bullies to the dragons 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 6.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 43% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Squadmate's revenge 16%, Left bullies to the dragons 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 6.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 41% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Left bullies to the dragons 16%, Squadmate's revenge 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 6.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Orange: eventually
- **Company: Alone** (still best in 57% of posterior draws) — no clear winner. If chosen, then best play after: Alone 16%, 1 Squadmate 16%, 2 Squadmates 16%
- **First direction: Center** (still best in 64% of posterior draws) — no clear winner. If chosen, then best play after: Center 16%, West 16%, East 16%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 41% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Left bullies to the dragons 16%, Squadmate's revenge 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 44% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Squadmate's revenge 16%, Left bullies to the dragons 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 43% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Squadmate's revenge 16%, Left bullies to the dragons 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 41% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 16%, Tourniquet 16%, Took their weapons 16%, Left them to it 16%, Killed the bullies yourself 16%, Left bullies to the dragons 16%, Squadmate's revenge 16%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 16%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 16%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 39%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Brown: this attempt
- **Company: Alone** (still best in 56% of posterior draws) — no clear winner. If chosen, then best play after: Alone 8.1%, 1 Squadmate 8.1%, 2 Squadmates 8.0%
- **First direction: Center** (still best in 74% of posterior draws) — no clear winner. If chosen, then best play after: Center 8.1%, West 8.1%, East 8.0%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 30% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 8.2%, Tourniquet 8.2%, Took their weapons 8.1%, Left them to it 8.1%, Killed the bullies yourself 8.0%, Left bullies to the dragons 8.0%, Squadmate's revenge 8.0%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 8.2%, Tree 4.6%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 8.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 35% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 8.2%, Tourniquet 8.2%, Took their weapons 8.1%, Left them to it 8.1%, Killed the bullies yourself 8.0%, Left bullies to the dragons 8.0%, Squadmate's revenge 8.0%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 8.2%, Tree 4.6%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 8.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 33% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 8.2%, Tourniquet 8.2%, Took their weapons 8.1%, Left them to it 8.1%, Killed the bullies yourself 7.8%, Left bullies to the dragons 7.8%, Squadmate's revenge 7.8%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 8.2%, Tree 4.6%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 8.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 32% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 8.2%, Tourniquet 8.2%, Took their weapons 8.1%, Left them to it 8.1%, Killed the bullies yourself 7.8%, Left bullies to the dragons 7.8%, Squadmate's revenge 7.8%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 8.2%, Tree 4.6%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 8.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 60%, bond Orange 39%, bond Brown 0.7%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
## Brown: eventually
- **Company: Alone** (still best in 56% of posterior draws) — no clear winner. If chosen, then best play after: Alone 7.8%, 1 Squadmate 7.8%, 2 Squadmates 7.7%
- **First direction: Center** (still best in 75% of posterior draws) — no clear winner. If chosen, then best play after: Center 7.8%, West 7.8%, East 7.7%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Left injured cadet** (still best in 28% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 7.9%, Tourniquet 7.9%, Took their weapons 7.8%, Left them to it 7.8%, Killed the bullies yourself 7.7%, Left bullies to the dragons 7.7%, Squadmate's revenge 7.7%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.9%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.9%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Die on purpose** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 33% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 7.9%, Tourniquet 7.9%, Took their weapons 7.8%, Left them to it 7.8%, Killed the bullies yourself 7.7%, Left bullies to the dragons 7.7%, Squadmate's revenge 7.7%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.9%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.9%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Die on purpose** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 32% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 7.9%, Tourniquet 7.9%, Took their weapons 7.8%, Left them to it 7.8%, Killed the bullies yourself 7.5%, Left bullies to the dragons 7.5%, Squadmate's revenge 7.5%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.9%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.9%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Die on purpose** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Left injured cadet** (still best in 31% of posterior draws) — no clear winner. If chosen, then best play after: Left injured cadet 7.9%, Tourniquet 7.9%, Took their weapons 7.8%, Left them to it 7.8%, Killed the bullies yourself 7.5%, Left bullies to the dragons 7.5%, Squadmate's revenge 7.5%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.9%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.9%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- **Bonding encounter: Die on purpose** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 0.7%, Die on purpose 0.0%
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 27%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 72%, bond Brown 27%, bond Red 0.5%, bond Green 0.5%
## Green: this attempt
- **Company: Alone** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Alone 23%, 1 Squadmate 23%, 2 Squadmates 22%
- **First direction: Center** (still best in 80% of posterior draws). If chosen, then best play after: Center 23%, West 23%, East 22%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Tourniquet** (still best in 63% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Squadmate's revenge 22%, Left bullies to the dragons 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.2%
- Shadow at the tree: no 99%, yes 0.8%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 55% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.2%
- Shadow at the tree: no 99%, yes 0.8%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.2%
- Shadow at the tree: no 99%, yes 0.9%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 53% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.2%
- Shadow at the tree: no 99%, yes 0.9%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Green: eventually
- **Company: Alone** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Alone 23%, 1 Squadmate 23%, 2 Squadmates 22%
- **First direction: Center** (still best in 80% of posterior draws). If chosen, then best play after: Center 23%, West 23%, East 22%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Tourniquet** (still best in 63% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Squadmate's revenge 22%, Left bullies to the dragons 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.0%
- Shadow at the tree: no 99%, yes 0.8%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 55% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.0%
- Shadow at the tree: no 99%, yes 0.8%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.0%
- Shadow at the tree: no 99%, yes 0.9%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 53% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 23%, Left injured cadet 23%, Took their weapons 23%, Left them to it 22%, Killed the bullies yourself 22%, Left bullies to the dragons 22%, Squadmate's revenge 22%
- Survive the hour: 100% survive
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 23%, Valley 0.0%
- Shadow at the tree: no 99%, yes 0.9%
- if **no**:
- **Climb down: Slowly (two Greens)** (still best in 100% of posterior draws). If chosen, then best play after: Slowly (two Greens) 23%, Quickly (Red) 0.0%
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 23%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 66%, bond Green 23%, bond Orange 6.1%, bond Brown 4.6%
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Blue: this attempt
- **Company: Alone** (still best in 57% of posterior draws) — no clear winner. If chosen, then best play after: Alone 7.2%, 1 Squadmate 7.2%, 2 Squadmates 7.1%
- **First direction: Center** (still best in 67% of posterior draws) — no clear winner. If chosen, then best play after: Center 7.2%, West 7.2%, East 7.1%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Tourniquet** (still best in 23% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Killed the bullies yourself 7.1%, Squadmate's revenge 7.1%, Left bullies to the dragons 7.1%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 35% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 7.1%, Killed the bullies yourself 7.1%, Left bullies to the dragons 7.1%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 40% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 6.9%, Killed the bullies yourself 6.9%, Left bullies to the dragons 6.9%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 32% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 6.9%, Killed the bullies yourself 6.9%, Left bullies to the dragons 6.9%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Blue: eventually
- **Company: Alone** (still best in 57% of posterior draws) — no clear winner. If chosen, then best play after: Alone 7.2%, 1 Squadmate 7.2%, 2 Squadmates 7.1%
- **First direction: Center** (still best in 67% of posterior draws) — no clear winner. If chosen, then best play after: Center 7.2%, West 7.2%, East 7.1%
- First dragon: Red 51%, Brown 46%, Orange 1.3%, Green 1.1%
- if **Red**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Tourniquet** (still best in 23% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Killed the bullies yourself 7.1%, Squadmate's revenge 7.1%, Left bullies to the dragons 7.1%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Brown**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 35% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 7.1%, Killed the bullies yourself 7.1%, Left bullies to the dragons 7.1%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 40% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 6.9%, Killed the bullies yourself 6.9%, Left bullies to the dragons 6.9%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Tourniquet** (still best in 32% of posterior draws) — no clear winner. If chosen, then best play after: Tourniquet 7.2%, Left injured cadet 7.2%, Took their weapons 7.2%, Left them to it 7.1%, Squadmate's revenge 6.9%, Killed the bullies yourself 6.9%, Left bullies to the dragons 6.9%
- Survive the hour: 100% survive
- **After an hour: Valley** (still best in 100% of posterior draws). If chosen, then best play after: Valley 7.2%, Tree 0.0%
- **Valley centre: Pass the Red (meadow)** (still best in 100% of posterior draws). If chosen, then best play after: Pass the Red (meadow) 7.2%, Face the Red 0.0%
- Meadow dragon: Orange 42%, Blue 29%, Brown 29%
- if **Orange**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Blue**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 25%, Die on purpose 0.0%
- Outcome if you attempt: incinerated 75%, bond Blue 25%
- if **Brown**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Black: this attempt
- **Company: Alone** (still best in 62% of posterior draws) — no clear winner. If chosen, then best play after: Alone 1.7%, 1 Squadmate 1.4%, 2 Squadmates 1.4%
- **First direction: West** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: West 1.7%, Center 1.4%, East 1.3%
- First dragon: Brown 48%, Green 48%, Red 3.9%, Orange 0.6%
- if **Brown**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Squadmate's revenge** (still best in 73% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.8%, Left bullies to the dragons 1.0%, Killed the bullies yourself 0.9%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 96% survive
- **Fork in the road: West** (still best in 84% of posterior draws). If chosen, then best play after: West 1.9%, Forest 1.0%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.9%, Valley 0.0%
- Shadow at the tree: no 97%, yes 3.0%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Squadmate's revenge** (still best in 59% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.6%, Left bullies to the dragons 1.1%, Killed the bullies yourself 1.0%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 52% of posterior draws) — no clear winner. If chosen, then best play after: West 1.7%, Forest 1.5%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.7%, Valley 0.0%
- Shadow at the tree: no 97%, yes 2.7%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Red**:
- Survive the first dragon: 98% survive
- **Cadet encounter: Squadmate's revenge** (still best in 48% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.5%, Left bullies to the dragons 1.0%, Killed the bullies yourself 0.9%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 60% of posterior draws) — no clear winner. If chosen, then best play after: West 1.5%, Forest 1.0%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.5%, Valley 0.0%
- Shadow at the tree: no 98%, yes 2.5%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 98% survive
- **Cadet encounter: Squadmate's revenge** (still best in 51% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.4%, Left bullies to the dragons 1.1%, Left them to it 0.9%, Killed the bullies yourself 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.6%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 52% of posterior draws) — no clear winner. If chosen, then best play after: West 1.4%, Forest 1.2%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.4%, Valley 0.0%
- Shadow at the tree: no 98%, yes 2.3%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
## Black: eventually
- **Company: Alone** (still best in 62% of posterior draws) — no clear winner. If chosen, then best play after: Alone 1.7%, 1 Squadmate 1.4%, 2 Squadmates 1.4%
- **First direction: West** (still best in 54% of posterior draws) — no clear winner. If chosen, then best play after: West 1.7%, Center 1.4%, East 1.3%
- First dragon: Brown 48%, Green 48%, Red 3.9%, Orange 0.6%
- if **Brown**:
- Survive the first dragon: 100% survive
- **Cadet encounter: Squadmate's revenge** (still best in 73% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.8%, Left bullies to the dragons 1.0%, Killed the bullies yourself 0.9%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 96% survive
- **Fork in the road: West** (still best in 84% of posterior draws). If chosen, then best play after: West 1.9%, Forest 1.0%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.9%, Valley 0.0%
- Shadow at the tree: no 97%, yes 3.0%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Green**:
- Survive the first dragon: 99% survive
- **Cadet encounter: Squadmate's revenge** (still best in 59% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.6%, Left bullies to the dragons 1.1%, Killed the bullies yourself 1.0%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 52% of posterior draws) — no clear winner. If chosen, then best play after: West 1.7%, Forest 1.5%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.7%, Valley 0.0%
- Shadow at the tree: no 97%, yes 2.7%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Red**:
- Survive the first dragon: 98% survive
- **Cadet encounter: Squadmate's revenge** (still best in 48% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.5%, Left bullies to the dragons 1.0%, Killed the bullies yourself 0.9%, Left them to it 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.5%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 60% of posterior draws) — no clear winner. If chosen, then best play after: West 1.5%, Forest 1.0%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.5%, Valley 0.0%
- Shadow at the tree: no 98%, yes 2.5%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **Orange**:
- Survive the first dragon: 98% survive
- **Cadet encounter: Squadmate's revenge** (still best in 51% of posterior draws) — no clear winner. If chosen, then best play after: Squadmate's revenge 1.4%, Left bullies to the dragons 1.1%, Left them to it 0.9%, Killed the bullies yourself 0.9%, Took their weapons 0.8%, Left injured cadet 0.8%, Tourniquet 0.6%
- Survive the fight: 95% survive
- **Fork in the road: West** (still best in 52% of posterior draws) — no clear winner. If chosen, then best play after: West 1.4%, Forest 1.2%, East 1.0%
- **After an hour: Tree** (still best in 100% of posterior draws). If chosen, then best play after: Tree 1.4%, Valley 0.0%
- Shadow at the tree: no 98%, yes 2.3%
- if **no**:
- Climb down: any (no difference for this colour)
- Bonding encounter: any (no difference for this colour)
- die on purpose
- if **yes**:
- Shadow dragon: Black 91%, Blue 9.4%
- if **Black**:
- **Bonding encounter: Attempt the bond** (still best in 100% of posterior draws). If chosen, then best play after: Attempt the bond 69%, Die on purpose 0.0%
- Outcome if you attempt: bond Black 69%, incinerated 31%
- if **Blue**:
- Bonding encounter: any (no difference for this colour)
- die on purpose
+2 -2
View File
@@ -13,7 +13,7 @@ policy that maximises the chance of bonding it, with honest uncertainty.
Markov / context tree with BIC; temporal-tiered DAG structure learning (BDeu/BIC); latent Markov / context tree with BIC; temporal-tiered DAG structure learning (BDeu/BIC); latent
"character" model vs specific triggers vs memoryless baseline, compared on held-out likelihood; "character" model vs specific triggers vs memoryless baseline, compared on held-out likelihood;
hierarchical Dirichlet back-off pooling. hierarchical Dirichlet back-off pooling.
4. **Solver**: backward induction on the augmented state (scene, history summary), i.e. an influence 4. **Solver** (first version done: `packages/core/src/solver.js`, `docs/POLICY.md`; still to do: richer history models from step 3): backward induction on the augmented state (scene, history summary), i.e. an influence
diagram with perfect recall. Two objectives side by side per colour: diagram with perfect recall. Two objectives side by side per colour:
- P(target colour on this attempt); - P(target colour on this attempt);
- eventual success when deliberate deaths are free: maximise p_X / (p_X + p_other bond), - eventual success when deliberate deaths are free: maximise p_X / (p_X + p_other bond),
@@ -21,5 +21,5 @@ policy that maximises the chance of bonding it, with honest uncertainty.
Monte Carlo credible intervals, top-k routes, required steps and bottlenecks. Monte Carlo credible intervals, top-k routes, required steps and bottlenecks.
5. **Valley graph UI**: every option at every point, with P(survive) and P(bond) per colour, the 5. **Valley graph UI**: every option at every point, with P(survive) and P(bond) per colour, the
policy overlay for a chosen colour, and untested branches marked. policy overlay for a chosen colour, and untested branches marked.
6. **Bot loop**: the atlas publishes `policy.json` and `experiments.json` (ranked by value of 6. **Bot loop** (advisor and sync published, see `docs/BOT_INTEGRATION.md`; experiments.json to do): the atlas publishes `policy.json` and `experiments.json` (ranked by value of
information); the private DragonKind bot consumes them and returns anonymised runs. information); the private DragonKind bot consumes them and returns anonymised runs.
+3 -2
View File
@@ -11,10 +11,11 @@
"dev": "node scripts/build-site.js && python3 -m http.server 8000 -d dist", "dev": "node scripts/build-site.js && python3 -m http.server 8000 -d dist",
"test:js": "node tests/run_engine.js data/public/form_responses.json tests/out", "test:js": "node tests/run_engine.js data/public/form_responses.json tests/out",
"test:py": "cd research/python && python3 clean.py && python3 analyze.py", "test:py": "cd research/python && python3 clean.py && python3 analyze.py",
"test": "npm run test:js && npm run test:py && python3 tests/compare_runs.py && python3 tests/compare_results.py && python3 tests/compare_routes.py && node --test tests/graph.test.js", "test": "npm run test:js && npm run test:py && python3 tests/compare_runs.py && python3 tests/compare_results.py && python3 tests/compare_routes.py && node --test tests/graph.test.js tests/solver.test.js",
"graph": "node scripts/build-graph.js", "graph": "node scripts/build-graph.js",
"import-bot": "node packages/ingest/bin/import-bot.js", "import-bot": "node packages/ingest/bin/import-bot.js",
"check-sources": "python3 research/python/update_sources.py" "check-sources": "python3 research/python/update_sources.py",
"policy": "node scripts/build-policy.js && node scripts/policy-report.js"
}, },
"engines": { "engines": {
"node": ">=18" "node": ">=18"
+647
View File
@@ -0,0 +1,647 @@
/*
* solver.js: best decisions for bonding each dragon colour.
*
* Model: the threshing as a decision tree with perfect recall (an influence diagram).
* decision nodes company, direction, cadet encounter, fork in the road, tree or valley, how to climb down,
* whether to face the valley Red, and at every bonding encounter: attempt the bond or die on purpose
* chance nodes first dragon colour, dying at the sighting / in the bully fight / before the hour,
* the shadow at the tree and its colour, which dragon waits in the meadow, the encounter outcome
*
* Chance probabilities depend on the history that came before them (not Markov). Each one is estimated with
* hierarchical Dirichlet back-off: the estimate for a full history is shrunk toward the estimate for a shorter
* history, which is shrunk toward the overall rate (concentration ALPHA). Uncertainty comes from Monte Carlo
* draws of all those Dirichlet posteriors; each draw is solved again so we can say how often the recommended
* choice is still the best one.
*
* Two objectives per target colour X, reported side by side:
* 1. "this attempt": maximise P(bond X on this attempt).
* 2. "eventually": deaths are free (you can always try again after a cooldown), so what matters is not to
* end the account on the wrong dragon: maximise P(X) / (P(X) + P(another colour)).
* Solved by Dinkelbach iteration; ties broken by P(X), and the expected number of attempts
* (1 / P(X)) is reported with it.
*
* UMD: window.ThreshSolver in the browser, module.exports in Node. No dependencies.
*/
(function (root, factory) {
if (typeof module === "object" && module.exports) module.exports = factory();
else root.ThreshSolver = factory();
})(typeof self !== "undefined" ? self : this, function () {
"use strict";
const COLOURS = ["Red", "Orange", "Brown", "Green", "Blue", "Black"];
const RARE_GOALS = ["Blue", "Black", "Blue or Black"];
const ALPHA = 20;
/* ---------- 1. From coded form runs to solver variables ---------- */
const HELP = { "Killed the bullies yourself": 1, "Squadmate's revenge": 1, "Left bullies to the dragons": 1 };
const IGNORE = { "Tourniquet": 1, "Left injured cadet": 1, "Took their weapons": 1 };
const DECISIONS = {
company: ["Alone", "1 Squadmate", "2 Squadmates"],
direction: ["East", "West", "Center"],
cadet: ["Killed the bullies yourself", "Squadmate's revenge", "Left bullies to the dragons",
"Tourniquet", "Left injured cadet", "Took their weapons", "Left them to it"],
post: ["Forest", "West", "East"],
hour: ["Tree", "Valley"],
descend: ["Quickly (Red)", "Slowly (two Greens)"],
valley: ["Face the Red", "Pass the Red (meadow)"],
encounter: ["Attempt the bond", "Die on purpose"],
};
const LABEL = {
company: "Company", direction: "First direction", fs: "First dragon", dieSight: "Survive the first dragon",
cadet: "Cadet encounter", dieCombat: "Survive the fight", post: "Fork in the road", dieHour: "Survive the hour",
hour: "After an hour", shadow: "Shadow at the tree", shadowColour: "Shadow dragon", descend: "Climb down",
valley: "Valley centre", meadow: "Meadow dragon", encounter: "Bonding encounter",
};
const encColour = (ctx) => (ctx === "tree-Greens" ? "Green" : ctx.split("-")[1]);
/** The colour (or colours) a rider's stated goal commits them to, for deciding whether an attempt was genuine. */
function genuineAttempt(r, ctx) {
const c = encColour(ctx);
const g = r.goal || "";
const matches = g === c || g.startsWith("Any") || (g === "Blue or Black" && (c === "Blue" || c === "Black")) ||
(g === "Red (tree)" && ctx === "tree-Red");
if (matches) return true;
if (r.malek_intent === "No") return true;
if (r.malek_intent === "Yes") return false;
const specificOther = (COLOURS.includes(g) && g !== c) || (g === "Blue or Black") || g === "Red (tree)";
return !specificOther;
}
function prepareRun(r) {
const v = { company: DECISIONS.company.includes(r.company) ? r.company : null,
direction: DECISIONS.direction.includes(r.direction) ? r.direction : null,
fs: ["Red", "Brown", "Green", "Orange"].includes(r.first_sighting) ? r.first_sighting : null };
v.diedSight = r.scream === "DIED at first sighting";
if (v.diedSight) return v;
const res = r.resolution;
if (r.scream === "Investigate & help") {
v.help = true;
v.diedCombat = res === "DIED in combat";
v.cadet = HELP[res] ? res : null;
if (v.diedCombat) return v;
v.post = DECISIONS.post.includes(r.post_path) ? r.post_path : null;
} else if (r.scream === "Ignore the scream") {
v.cadet = IGNORE[res] ? res : null; v.post = "(no fork)";
} else if (r.scream === "Investigate & leave") {
v.cadet = "Left them to it"; v.post = "(no fork)";
} else return v;
v.survivedCadets = true;
v.diedHour = r.hour === "DIED before the hour";
if (v.diedHour) return v;
v.hour = DECISIONS.hour.includes(r.hour) ? r.hour : null;
const b = r.branch;
if (v.hour === "Tree" && b) {
v.shadow = b === "Shadow (rare)";
if (v.shadow) { v.shadowColour = r.enc_Black ? "Black" : "Blue"; v.encCtx = "shadow-" + v.shadowColour; }
else if (b === "Descend quickly: Red") { v.descend = "Quickly (Red)"; v.encCtx = "tree-Red"; }
else if (b === "Descend slowly: two Greens") { v.descend = "Slowly (two Greens)"; v.encCtx = "tree-Greens"; }
} else if (v.hour === "Valley" && b) {
if (b === "Valley Red") { v.valley = "Face the Red"; v.encCtx = "valley-Red"; }
else if (b === "Passed the Red: meadow") {
v.valley = "Pass the Red (meadow)";
// the meadow dragon: Blue if one appeared, otherwise the one the rider ended the run with
const ended = (c) => r["enc_" + c] && r["enc_" + c] !== "Changed my mind";
v.meadow = r.enc_Blue || r.rare_reported === "Blue (valley)" ? "Blue" :
ended("Orange") ? "Orange" : ended("Brown") ? "Brown" : r.enc_Orange ? "Orange" : r.enc_Brown ? "Brown" : null;
if (v.meadow) v.encCtx = "meadow-" + v.meadow;
}
}
if (v.encCtx) {
v.encOutcome = r.outcome === "Bonded" && r.outcome_color ? r.outcome_color : r.outcome === "Incinerated" ? "burn" : null;
if (v.encOutcome && !genuineAttempt(r, v.encCtx)) v.encOutcome = null;
}
return v;
}
/* ---------- 2. Chance nodes with hierarchical Dirichlet back-off ---------- */
// ctx: earlier variables the probability may depend on, most important first. Back-off drops from the end.
const CHANCE = {
fs: { cats: ["Red", "Brown", "Green", "Orange"], ctx: ["direction", "company"], get: (v) => v.fs },
dieSight: { cats: ["die", "live"], ctx: ["fs", "direction", "company"], get: (v) => (v.fs ? (v.diedSight ? "die" : "live") : null) },
dieCombat: { cats: ["die", "live"], ctx: ["fs", "direction"], get: (v) => (v.help ? (v.diedCombat ? "die" : "live") : null) },
dieHour: { cats: ["die", "live"], ctx: ["cadet", "post"], get: (v) => (v.survivedCadets ? (v.diedHour ? "die" : "live") : null) },
shadow: { cats: ["yes", "no"], ctx: ["cadet", "post", "fs", "direction", "company"], get: (v) => (v.shadow === undefined ? null : v.shadow ? "yes" : "no") },
shadowColour: { cats: ["Black", "Blue"], ctx: [], get: (v) => v.shadowColour || null },
meadow: { cats: ["Orange", "Brown", "Blue"], ctx: ["cadet", "post", "fs", "direction", "company"], get: (v) => v.meadow || null },
};
const ENC_CATS = ["burn"].concat(COLOURS);
const ctxKey = (v, vars) => vars.map((k) => (v[k] == null ? "?" : v[k])).join("|");
/** Counts for every chance node at every back-off level. */
function countTables(prepared) {
const T = {};
for (const [node, spec] of Object.entries(CHANCE)) {
const t = (T[node] = {});
for (const v of prepared) {
const y = spec.get(v);
if (!y) continue;
for (let L = 0; L <= spec.ctx.length; L++) {
const vars = spec.ctx.slice(0, L);
if (vars.some((k) => v[k] == null)) break;
const key = L + ":" + ctxKey(v, vars);
const c = t[key] || (t[key] = {});
c[y] = (c[y] || 0) + 1;
}
}
}
const enc = (T.encounter = {});
for (const v of prepared) {
if (!v.encCtx) continue;
const c = enc[v.encCtx] || (enc[v.encCtx] = { outcomes: {}, seen: {} });
if (v.encOutcome) c.outcomes[v.encOutcome] = (c.outcomes[v.encOutcome] || 0) + 1;
}
// which colours can ever end a run in this context (from all runs, genuine or not)
for (const v of prepared) if (v.encCtx && v.encOutcome && v.encOutcome !== "burn") enc[v.encCtx].seen[v.encOutcome] = 1;
return T;
}
/* ---------- Empirical-Bayes concentration for each chance node ---------- */
function lgamma(x) {
const c = [76.18009172947146, -86.50532032941677, 24.01409824083091, -1.231739572450155, 0.1208650973866179e-2, -0.5395239384953e-5];
let y = x, tmp = x + 5.5, ser = 1.000000000190015;
tmp -= (x + 0.5) * Math.log(tmp);
for (const v of c) ser += v / ++y;
return -tmp + Math.log(2.5066282746310005 * ser / x);
}
const ALPHA_GRID = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 20000, 100000];
/**
* How much should a specific history be allowed to differ from the shorter history above it?
* Choose the concentration alpha that maximises the Dirichlet-multinomial marginal likelihood of the counts
* at every back-off level given the level above. A large alpha means the data show little history dependence,
* so the solver will not chase noise in small groups (the "optimiser's curse").
*/
function fitAlpha(T, node) {
const spec = CHANCE[node], t = T[node], K = spec.cats.length;
const pooled = (key) => { const c = t[key] || {}; const a = spec.cats.map((k) => (c[k] || 0) + 0.5); const n = a.reduce((x, y) => x + y, 0); return a.map((x) => x / n); };
const pairs = [];
for (const key of Object.keys(t)) {
const L = +key.split(":")[0];
if (L === 0) continue;
const ctx = key.slice(key.indexOf(":") + 1).split("|");
const parent = (L - 1) + ":" + ctx.slice(0, L - 1).join("|");
pairs.push([spec.cats.map((k) => t[key][k] || 0), pooled(parent)]);
}
if (!pairs.length) return { alpha: ALPHA, logLik: null };
let bestA = ALPHA, bestLL = -Infinity;
const lls = {};
for (const a of ALPHA_GRID) {
let ll = 0;
for (const [c, p] of pairs) {
const n = c.reduce((x, y) => x + y, 0);
ll += lgamma(a) - lgamma(n + a);
for (let i = 0; i < K; i++) ll += lgamma(c[i] + a * p[i]) - lgamma(a * p[i]);
}
lls[a] = ll;
if (ll > bestLL) { bestLL = ll; bestA = a; }
}
return { alpha: bestA, logLik: lls };
}
/* random numbers: seeded, so results are reproducible */
function rng(seed) {
let s = seed >>> 0 || 1;
return () => { s ^= s << 13; s >>>= 0; s ^= s >>> 17; s ^= s << 5; s >>>= 0; return s / 4294967296; };
}
function gamma(shape, rand) {
if (shape < 1) return gamma(shape + 1, rand) * Math.pow(rand() || 1e-12, 1 / shape);
const d = shape - 1 / 3, c = 1 / Math.sqrt(9 * d);
for (;;) {
let x, v;
do {
const u1 = rand() || 1e-12, u2 = rand();
x = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
v = 1 + c * x;
} while (v <= 0);
v = v * v * v;
const u = rand();
if (u < 1 - 0.0331 * x ** 4 || Math.log(u) < 0.5 * x * x + d * (1 - v + Math.log(v))) return d * v;
}
}
function dirichlet(alpha, rand) {
const g = alpha.map((a) => gamma(Math.max(a, 1e-6), rand));
const s = g.reduce((a, b) => a + b, 0);
return g.map((x) => x / s);
}
/**
* A probability source. mode "mean" gives posterior means; mode "draw" gives one joint posterior draw
* (each distribution is drawn once and reused, so a draw is a consistent world).
*/
function makeParams(T, { mode = "mean", seed = 1, alpha = ALPHA, alphas = {} } = {}) {
const rand = mode === "draw" ? rng(seed) : null;
const memo = new Map();
function chance(node, h) {
const spec = CHANCE[node];
// deepest level with this exact context, then build top-down
const levels = [];
for (let L = 0; L <= spec.ctx.length; L++) {
const vars = spec.ctx.slice(0, L);
if (vars.some((k) => h[k] == null)) break;
levels.push(L + ":" + ctxKey(h, vars));
}
let p = null;
for (const key of levels) {
const mk = node + "#" + key;
if (memo.has(mk)) { p = memo.get(mk); continue; }
const c = T[node][key] || {};
const al = alphas[node] || alpha;
const a = spec.cats.map((k, i) => (c[k] || 0) + (p ? al * p[i] : 0.5));
p = rand ? dirichlet(a, rand) : a.map((x) => x / a.reduce((s, y) => s + y, 0));
memo.set(mk, p);
}
return Object.fromEntries(spec.cats.map((k, i) => [k, p[i]]));
}
function encounter(ctx) {
const mk = "enc#" + ctx;
if (!memo.has(mk)) {
const e = T.encounter[ctx] || { outcomes: {}, seen: {} };
const cats = ENC_CATS.filter((k) => k === "burn" || e.seen[k] || (e.outcomes[k] || 0) > 0 || k === encColour(ctx));
const a = cats.map((k) => (e.outcomes[k] || 0) + 0.5);
const p = rand ? dirichlet(a, rand) : a.map((x) => x / a.reduce((s, y) => s + y, 0));
memo.set(mk, Object.fromEntries(cats.map((k, i) => [k, p[i]])));
}
return memo.get(mk);
}
return { chance, encounter };
}
/* ---------- 3. The decision tree and backward induction ---------- */
const ZERO = { x: 0, o: 0 };
const add = (a, b, w) => ({ x: a.x + w * b.x, o: a.o + w * b.o });
/**
* Solve for target colour X. score(v) = (1 - lam) * P(X) - lam * P(other) (+ tiny tie-break on P(X)).
* Returns the value at the root and a decide(name, h) function giving the best option at any history.
* `support` lists the options allowed at each decision (options without enough data are left out).
*/
function solve(params, X, { lam = 0, support = DECISIONS, record = false } = {}) {
const score = (v) => (1 - lam) * v.x - lam * v.o + 1e-9 * v.x - 1e-12 * v.o;
const memo = new Map();
const choices = new Map();
const optVals = record ? new Map() : null;
function best(name, h, options, next) {
const key = name + "@" + JSON.stringify(h);
if (memo.has(key)) return memo.get(key);
let top = null, arg = null;
const vals = {};
for (const o of options) {
const v = next(o);
vals[o] = v;
if (!top || score(v) > score(top)) { top = v; arg = o; }
}
memo.set(key, top);
choices.set(key, arg);
if (optVals) optVals.set(key, vals);
return top;
}
const mix = (dist, f) => Object.entries(dist).reduce((acc, [k, p]) => (p ? add(acc, f(k), p) : acc), ZERO);
const die = () => ZERO;
const encounter = (h, ctx) => best("encounter", { ...h, enc: ctx }, support.encounter, (o) => {
if (o === "Die on purpose") return ZERO;
const d = params.encounter(ctx);
let x = 0, oth = 0;
for (const [k, p] of Object.entries(d)) if (k !== "burn") { if (k === X) x += p; else oth += p; }
return { x, o: oth };
});
const tree = (h) => mix(params.chance("shadow", h), (s) => s === "yes"
? mix(params.chance("shadowColour", h), (c) => encounter({ ...h, shadow: "yes" }, "shadow-" + c))
: best("descend", { ...h, shadow: "no" }, support.descend, (o) => encounter({ ...h, shadow: "no", descend: o }, o.startsWith("Quickly") ? "tree-Red" : "tree-Greens")));
const valley = (h) => best("valley", h, support.valley, (o) => o === "Face the Red"
? encounter({ ...h, valley: o }, "valley-Red")
: mix(params.chance("meadow", h), (c) => encounter({ ...h, valley: o, meadow: c }, "meadow-" + c)));
const hour = (h) => mix(params.chance("dieHour", h), (s) => s === "die" ? die() :
best("hour", h, support.hour, (o) => (o === "Tree" ? tree : valley)({ ...h, hour: o })));
const cadet = (h) => best("cadet", h, support.cadet, (o) => {
const h2 = { ...h, cadet: o };
if (HELP[o]) return mix(params.chance("dieCombat", h2), (s) => s === "die" ? die() :
best("post", h2, support.post, (p) => hour({ ...h2, post: p })));
return hour({ ...h2, post: "(no fork)" });
});
const sighting = (h) => mix(params.chance("fs", h), (c) => {
const h2 = { ...h, fs: c };
return mix(params.chance("dieSight", h2), (s) => (s === "die" ? die() : cadet(h2)));
});
const root = best("company", {}, support.company, (c) =>
best("direction", { company: c }, support.direction, (d) => sighting({ company: c, direction: d })));
const decide = (name, h) => choices.get(name + "@" + JSON.stringify(h));
return { value: root, decide, optionValues: (name, h) => optVals && optVals.get(name + "@" + JSON.stringify(h)) };
}
/** Objective 2 by Dinkelbach: find lam* = max P(X) / (P(X) + P(other)). */
function solveRatio(params, X, opts = {}) {
let lam = 0, s = solve(params, X, { ...opts, lam });
for (let i = 0; i < 30; i++) {
const v = s.value, r = v.x + v.o > 0 ? v.x / (v.x + v.o) : 0;
if (Math.abs(r - lam) < 1e-10) break;
lam = r;
s = solve(params, X, { ...opts, lam });
}
return { ...s, lam };
}
/* ---------- 4. Evaluate a fixed policy (for credible intervals) ---------- */
function evaluate(params, X, decide) {
// same tree as solve(), but decisions come from `decide` (the policy chosen on the posterior means)
const pick = (name, h, f) => f(decide(name, h));
const mix = (dist, f) => Object.entries(dist).reduce((acc, [k, p]) => (p ? add(acc, f(k), p) : acc), ZERO);
const encounter = (h, ctx) => pick("encounter", { ...h, enc: ctx }, (o) => {
if (o === "Die on purpose") return ZERO;
const d = params.encounter(ctx);
let x = 0, oth = 0;
for (const [k, p] of Object.entries(d)) if (k !== "burn") { if (k === X) x += p; else oth += p; }
return { x, o: oth };
});
const tree = (h) => mix(params.chance("shadow", h), (s) => s === "yes"
? mix(params.chance("shadowColour", h), (c) => encounter({ ...h, shadow: "yes" }, "shadow-" + c))
: pick("descend", { ...h, shadow: "no" }, (o) => encounter({ ...h, shadow: "no", descend: o }, o.startsWith("Quickly") ? "tree-Red" : "tree-Greens")));
const valley = (h) => pick("valley", h, (o) => o === "Face the Red"
? encounter({ ...h, valley: o }, "valley-Red")
: mix(params.chance("meadow", h), (c) => encounter({ ...h, valley: o, meadow: c }, "meadow-" + c)));
const hour = (h) => mix(params.chance("dieHour", h), (s) => s === "die" ? ZERO :
pick("hour", h, (o) => (o === "Tree" ? tree : valley)({ ...h, hour: o })));
const cadet = (h) => pick("cadet", h, (o) => {
const h2 = { ...h, cadet: o };
if (HELP[o]) return mix(params.chance("dieCombat", h2), (s) => s === "die" ? ZERO :
pick("post", h2, (p) => hour({ ...h2, post: p })));
return hour({ ...h2, post: "(no fork)" });
});
const sighting = (h) => mix(params.chance("fs", h), (c) => {
const h2 = { ...h, fs: c };
return mix(params.chance("dieSight", h2), (s) => (s === "die" ? ZERO : cadet(h2)));
});
return pick("company", {}, (c) => pick("direction", { company: c }, (d) => sighting({ company: c, direction: d })));
}
/* ---------- 5. The published policy tree ---------- */
/**
* Walk the point-estimate policy and write it out as a tree: at decisions, the chosen option plus the value of
* every option (each followed by the best play afterwards) and how often it stays best across posterior draws;
* at chance nodes, every branch with its probability. Only the chosen option's subtree is expanded.
*/
function exportTree(params, X, sol, draws, minShow = 1e-4) {
const vals = (name, h) => sol.optionValues(name, h) || {};
const conf = (name, h, chosen) => (draws.length ? draws.filter((d) => d.decide(name, h) === chosen).length / draws.length : null);
const fmt = (v) => ({ pX: v.x, pOther: v.o });
const decision = (name, h, cont) => {
const chosen = sol.decide(name, h);
const ov = vals(name, h);
const xs = Object.values(ov).map((v) => v.x).sort((p, q) => q - p);
const tie = xs.length > 1 && xs[0] - xs[1] < 1e-12; // nothing to choose between (e.g. every option ends the run)
return {
type: "decision", var: name, label: LABEL[name], choice: chosen, tie, stillBest: tie ? null : conf(name, h, chosen),
options: Object.fromEntries(Object.entries(ov).map(([o, v]) => [o, fmt(v)])),
next: cont(chosen),
};
};
const chance = (name, dist, cont) => ({
type: "chance", var: name, label: LABEL[name],
branches: Object.fromEntries(Object.entries(dist).filter(([, p]) => p >= minShow).map(([k, p]) => [k, { p, next: cont(k) }])),
});
const end = (what) => ({ type: "end", what });
const encounter = (h, ctx) => decision("encounter", { ...h, enc: ctx }, (o) => o === "Die on purpose" ? end("die on purpose") :
({ type: "end", what: `encounter: ${ctx}`, outcomes: params.encounter(ctx) }));
const tree = (h) => chance("shadow", params.chance("shadow", h), (s) => s === "yes"
? chance("shadowColour", params.chance("shadowColour", h), (c) => encounter({ ...h, shadow: "yes" }, "shadow-" + c))
: decision("descend", { ...h, shadow: "no" }, (o) => encounter({ ...h, shadow: "no", descend: o }, o.startsWith("Quickly") ? "tree-Red" : "tree-Greens")));
const valley = (h) => decision("valley", h, (o) => o === "Face the Red"
? encounter({ ...h, valley: o }, "valley-Red")
: chance("meadow", params.chance("meadow", h), (c) => encounter({ ...h, valley: o, meadow: c }, "meadow-" + c)));
const hour = (h) => chance("dieHour", params.chance("dieHour", h), (s) => s === "die" ? end("incinerated") :
decision("hour", h, (o) => (o === "Tree" ? tree : valley)({ ...h, hour: o })));
const cadet = (h) => decision("cadet", h, (o) => {
const h2 = { ...h, cadet: o };
if (HELP[o]) return chance("dieCombat", params.chance("dieCombat", h2), (s) => s === "die" ? end("killed in the fight") :
decision("post", h2, (p) => hour({ ...h2, post: p })));
return hour({ ...h2, post: "(no fork)" });
});
const sighting = (h) => chance("fs", params.chance("fs", h), (c) => {
const h2 = { ...h, fs: c };
return chance("dieSight", params.chance("dieSight", h2), (s) => (s === "die" ? end("incinerated at the first sighting") : cadet(h2)));
});
return decision("company", {}, (c) => decision("direction", { company: c }, (d) => sighting({ company: c, direction: d })));
}
const quantile = (xs, q) => {
const s = xs.slice().sort((a, b) => a - b);
const i = (s.length - 1) * q, lo = Math.floor(i), hi = Math.ceil(i);
return s[lo] + (s[hi] - s[lo]) * (i - lo);
};
const summarise = (xs) => ({ mean: xs.reduce((a, b) => a + b, 0) / xs.length, lo: quantile(xs, 0.025), hi: quantile(xs, 0.975) });
/** Options seen fewer than `min` times in the data are not recommended. */
function supportFrom(prepared, min) {
const n = {};
const bump = (k, o) => { n[k] = n[k] || {}; n[k][o] = (n[k][o] || 0) + 1; };
for (const v of prepared) {
for (const k of ["company", "direction", "cadet", "hour", "descend", "valley"]) if (v[k]) bump(k, v[k]);
if (v.post && v.post !== "(no fork)") bump("post", v.post);
}
const s = { encounter: DECISIONS.encounter };
for (const k of ["company", "direction", "cadet", "post", "hour", "descend", "valley"])
s[k] = DECISIONS[k].filter((o) => ((n[k] || {})[o] || 0) >= min);
return { support: s, counts: n };
}
/**
* Build the full policy for every colour.
* runs: coded runs from engine.codeRows(); opts.draws: Monte Carlo draws for intervals.
*/
function buildPolicy(runs, { draws = 200, seed = 20261101, minSupport = 20, alpha = null, colours = COLOURS } = {}) {
const prepared = runs.map(prepareRun);
const T = countTables(prepared);
const { support, counts } = supportFrom(prepared, minSupport);
const fitted = Object.fromEntries(Object.keys(CHANCE).map((k) => [k, fitAlpha(T, k)]));
const alphas = alpha ? Object.fromEntries(Object.keys(CHANCE).map((k) => [k, alpha])) : Object.fromEntries(Object.entries(fitted).map(([k, f]) => [k, f.alpha]));
const mean = makeParams(T, { mode: "mean", alphas });
const drawParams = Array.from({ length: draws }, (_, i) => makeParams(T, { mode: "draw", seed: seed + i * 7919, alphas }));
// Cross-fitting: choose the policy on one random half of the runs and score it on the other half.
// The gap between the in-sample and held-out values shows how much of a route's edge is noise.
const r = rng(seed);
const fold = prepared.map(() => (r() < 0.5 ? 0 : 1));
const halves = [0, 1].map((f) => countTables(prepared.filter((_, i) => fold[i] === f)));
const halfParams = halves.map((Th) => makeParams(Th, { mode: "mean", alphas }));
const targets = {};
for (const X of colours) {
const one = solve(mean, X, { support, record: true });
const ratio = solveRatio(mean, X, { support });
const ratioRec = solve(mean, X, { support, lam: ratio.lam, record: true });
const dOne = drawParams.map((p) => solve(p, X, { support }));
const dRatio = drawParams.map((p) => solveRatio(p, X, { support }));
const evOne = drawParams.map((p) => evaluate(p, X, one.decide));
const evRatio = drawParams.map((p) => evaluate(p, X, ratioRec.decide));
const block = (sol, ev, dr) => ({
pX: { ...summarise(ev.map((v) => v.x)), point: sol.value.x },
pOther: { ...summarise(ev.map((v) => v.o)), point: sol.value.o },
ratio: summarise(ev.map((v) => (v.x + v.o ? v.x / (v.x + v.o) : 0))),
expectedAttempts: summarise(ev.map((v) => (v.x > 0 ? 1 / v.x : Infinity))),
tree: exportTree(mean, X, sol, dr),
});
const cross = [0, 1].map((f) => {
const pol = solve(halfParams[f], X, { support });
return { chosenOn: f, inSample: pol.value.x, heldOut: evaluate(halfParams[1 - f], X, pol.decide).x };
});
targets[X] = { thisAttempt: block(one, evOne, dOne), eventually: block(ratioRec, evRatio, dRatio),
crossFit: { inSample: (cross[0].inSample + cross[1].inSample) / 2, heldOut: (cross[0].heldOut + cross[1].heldOut) / 2 } };
}
return {
schema: 1,
model: {
description: "Decision tree with perfect recall; chance probabilities depend on earlier choices via hierarchical Dirichlet back-off.",
alphas, alphaFit: Object.fromEntries(Object.entries(fitted).map(([k, f]) => [k, f.logLik])), draws, seed, minSupport,
chanceContext: Object.fromEntries(Object.entries(CHANCE).map(([k, s]) => [k, s.ctx])),
decisions: DECISIONS, support, supportCounts: counts,
tables: T,
},
data: { runs: runs.length },
targets,
};
}
/* ---------- 6. Bot helper: what to pick on this screen ---------- */
const SCREAM_OF = (cadet) => (HELP[cadet] ? "help" : IGNORE[cadet] ? "ignore" : cadet === "Left them to it" ? "leave" : null);
const OPTION_PATTERNS = {
company: { "Alone": /^enter the valley alone/, "1 Squadmate": /^enter the valley with one/, "2 Squadmates": /^enter the valley with two/ },
direction: { East: /^head east/, West: /^head west/, Center: /^head toward the center of the forest/ },
post: { East: /^walk toward the east/, West: /^walk toward the west/, Forest: /^walk farther into the forest/ },
hour: { Valley: /^continue toward the center of the valley/, Tree: /^find the tallest tree/ },
descend: { "Quickly (Red)": /^descend quickly/, "Slowly (two Greens)": /^climb down slowly/ },
resolution: {
"Killed the bullies yourself": /^end the lives of the bullies/, "Squadmate's revenge": /^allow your squadmate to exact/,
"Left bullies to the dragons": /^leave the bullies alive/, "Tourniquet": /tourniquet/, "Took their weapons": /weapon/,
},
scream: { help: /^(investigate the scream|help your squadmate)/, leave: /^(investigate the scream|play it safe and leave them)/, ignore: /^keep walking/ },
};
const norm = (t) => String(t || "").toLowerCase().replace(/[‘’']/g, "'").replace(/[–—-]/g, " ").replace(/[^a-z0-9'\s]/g, " ").replace(/\s+/g, " ").trim();
/**
* Convert the community-form variables of a (possibly unfinished) run into the solver's history keys.
* For the bot: graph.trajectoryVariables(trajectory).vars gives the form variables; add what the bot saw
* on screen itself: `meadow` (colour in the meadow), `shadow` ("yes"/"no" at the treetop), `shadowColour`.
*/
function solverHistory(vars, seen = {}) {
const h = {};
if (DECISIONS.company.includes(vars.company)) h.company = vars.company;
if (DECISIONS.direction.includes(vars.direction)) h.direction = vars.direction;
if (["Red", "Brown", "Green", "Orange"].includes(vars.first_sighting)) h.fs = vars.first_sighting;
if (DECISIONS.cadet.includes(vars.resolution)) h.cadet = vars.resolution;
if (DECISIONS.post.includes(vars.post_path)) h.post = vars.post_path;
else if (h.cadet && !HELP[h.cadet]) h.post = "(no fork)";
if (DECISIONS.hour.includes(vars.hour)) h.hour = vars.hour;
if (vars.branch === "Descend quickly: Red") h.descend = "Quickly (Red)";
if (vars.branch === "Descend slowly: two Greens") h.descend = "Slowly (two Greens)";
if (vars.branch === "Valley Red") h.valley = "Face the Red";
if (vars.branch === "Passed the Red: meadow") h.valley = "Pass the Red (meadow)";
for (const k of ["meadow", "shadow", "shadowColour"]) if (seen[k]) h[k] = seen[k];
if (h.hour === "Tree" && h.descend && !h.shadow) h.shadow = "no";
return h;
}
/** Follow a published policy tree along a partial history; returns the node where the rider now stands. */
function locate(tree, h) {
let node = tree;
while (node && node.type !== "end") {
if (node.type === "decision") {
const val = h[node.var];
if (val == null) return node; // the next decision to make
if (val !== node.choice) return { type: "off-policy", var: node.var, recommended: node.choice, actual: val };
node = node.next;
} else {
// a rider who is asking for advice survived every earlier risk
const val = node.var.startsWith("die") ? "live" : h[node.var];
if (val == null) return node; // waiting for chance to resolve
node = node.branches[val] ? node.branches[val].next : { type: "unknown-branch", var: node.var, value: val };
}
}
return node;
}
/**
* The next decision a rider faces after history h, as the (name, key) used inside solve().
* Returns null when the next step is chance (e.g. the first dragon has not appeared yet) or the run is over.
* Keys are built in the same order as in solve() so they match its memo keys.
*/
function nextDecision(h) {
if (!h.company) return ["company", {}];
if (!h.direction) return ["direction", { company: h.company }];
if (!h.fs) return null;
const a = { company: h.company, direction: h.direction, fs: h.fs };
if (!h.cadet) return ["cadet", a];
const b = { ...a, cadet: h.cadet };
if (HELP[h.cadet] && !h.post) return ["post", b];
const c = { ...b, post: HELP[h.cadet] ? h.post : "(no fork)" };
if (!h.hour) return ["hour", c];
const d = { ...c, hour: h.hour };
if (h.hour === "Tree") {
if (!h.shadow) return null;
if (h.shadow === "yes") return h.shadowColour ? ["encounter", { ...d, shadow: "yes", enc: "shadow-" + h.shadowColour }] : null;
if (!h.descend) return ["descend", { ...d, shadow: "no" }];
return ["encounter", { ...d, shadow: "no", descend: h.descend, enc: h.descend.startsWith("Quickly") ? "tree-Red" : "tree-Greens" }];
}
if (!h.valley) return ["valley", d];
if (h.valley === "Face the Red") return ["encounter", { ...d, valley: h.valley, enc: "valley-Red" }];
return h.meadow ? ["encounter", { ...d, valley: h.valley, meadow: h.meadow, enc: "meadow-" + h.meadow }] : null;
}
/**
* An advisor for one colour and objective, built from a published policy sample (policy.json -> samples.all).
* It re-solves the model locally (a few milliseconds), so it can advise from ANY history, including histories
* that already left the recommended route.
*/
function advisor(sample, X, objective = "eventually") {
const m = sample.model;
const params = makeParams(m.tables, { mode: "mean", alphas: m.alphas });
const sol = objective === "eventually"
? (() => { const r = solveRatio(params, X, { support: m.support }); return solve(params, X, { support: m.support, lam: r.lam, record: true }); })()
: solve(params, X, { support: m.support, record: true });
return {
colour: X, objective, value: sol.value,
next(h) {
const nd = nextDecision(h);
if (!nd) return null;
const [name, key] = nd;
const ov = sol.optionValues(name, key) || {};
return { decision: name, label: LABEL[name], choice: sol.decide(name, key),
options: Object.fromEntries(Object.entries(ov).map(([o, v]) => [o, { pX: v.x, pOther: v.o }])) };
},
};
}
/**
* Given an advisor, the rider's history and the options on screen, return
* { index, decision, choice, reason } where index is null when there is no advice for this screen
* (the bot should then use its own rules). The encounter decision ("Attempt the bond" / "Die on purpose")
* is returned without an index: the bot knows which of its options attempt the bond and which burn.
*/
function recommendOption(adv, h, offered) {
const rec = adv.next(h);
if (!rec) return null;
const texts = offered.map(norm);
const find = (re) => texts.findIndex((t) => re.test(t));
let idx = -1;
if (rec.decision === "cadet") {
idx = find(OPTION_PATTERNS.resolution[rec.choice] || /$^/);
const scream = SCREAM_OF(rec.choice);
if (idx < 0 && scream) idx = find(OPTION_PATTERNS.scream[scream]);
} else if (OPTION_PATTERNS[rec.decision]) {
idx = find(OPTION_PATTERNS[rec.decision][rec.choice] || /$^/);
}
const values = Object.values(rec.options).map((v) => v.pX).sort((a, b) => b - a);
const margin = values.length > 1 ? values[0] - values[1] : null;
return { index: idx < 0 ? null : idx, decision: rec.decision, choice: rec.choice, margin, options: rec.options,
reason: idx < 0 && rec.decision !== "encounter" ? "the recommended choice is not on this screen; use the bot's own rules" : `${rec.label}: ${rec.choice}` };
}
return { COLOURS, DECISIONS, CHANCE, prepareRun, countTables, makeParams, fitAlpha, solverHistory, nextDecision, advisor, solve, solveRatio, evaluate, buildPolicy, locate, recommendOption, genuineAttempt };
});
+39
View File
@@ -0,0 +1,39 @@
// Build data/public/policy.json: the best decisions for each dragon colour, under both objectives.
// node scripts/build-policy.js [--draws 200]
const fs = require("fs");
const path = require("path");
const E = require("../packages/core/src/engine.js");
const S = require("../packages/core/src/solver.js");
const root = path.resolve(__dirname, "..");
const arg = (k, d) => { const i = process.argv.indexOf("--" + k); return i > 0 ? process.argv[i + 1] : d; };
const draws = +arg("draws", 200);
const raw = JSON.parse(fs.readFileSync(path.join(root, "data/public/form_responses.json"), "utf8"));
const { runs } = E.codeRows(raw.rows, raw.headers);
const isRare = (g) => ["Blue", "Black", "Blue or Black"].includes(g);
const samples = {
// every run
all: runs,
// runs least affected by selective reporting: bulk logs, plus form runs from riders not chasing a rare dragon
lowBias: runs.filter((r) => r.source !== "Form" || !isRare(r.goal)),
};
const t0 = Date.now();
const out = { schema: 1, source: { form_rows: raw.rows.length }, samples: {} };
for (const [name, rs] of Object.entries(samples)) {
out.samples[name] = S.buildPolicy(rs, { draws });
console.log(`${name}: ${rs.length} runs, ${((Date.now() - t0) / 1000).toFixed(1)} s`);
}
// a content id, so the bot can record which policy produced each run (no timestamps: the build is reproducible)
out.id = require("crypto").createHash("sha1").update(JSON.stringify(out.samples)).digest("hex").slice(0, 12);
fs.writeFileSync(path.join(root, "data/public/policy.json"), JSON.stringify(out));
console.log("policy id", out.id);
const pct = (p) => (100 * p).toFixed(p < 0.01 ? 2 : 1) + "%";
for (const [name, s] of Object.entries(out.samples)) {
console.log(`\n${name} alphas ${JSON.stringify(s.model.alphas)}`);
for (const [X, t] of Object.entries(s.targets)) {
const a = t.thisAttempt, b = t.eventually;
console.log(` ${X.padEnd(6)} this attempt ${pct(a.pX.mean)} [${pct(a.pX.lo)}, ${pct(a.pX.hi)}] other bond ${pct(a.pOther.mean)}` +
` | eventually: ratio ${pct(b.ratio.mean)}, P(X) ${pct(b.pX.mean)}, ~${b.expectedAttempts.mean.toFixed(0)} attempts` +
` | cross-fit ${pct(t.crossFit.inSample)} -> held-out ${pct(t.crossFit.heldOut)}`);
}
}
+2 -1
View File
@@ -14,7 +14,8 @@ fs.rmSync(out, { recursive: true, force: true });
for (const f of fs.readdirSync(path.join(root, "apps/atlas"))) copy(`apps/atlas/${f}`, f); for (const f of fs.readdirSync(path.join(root, "apps/atlas"))) copy(`apps/atlas/${f}`, f);
copy("packages/core/src/engine.js", "engine.js"); copy("packages/core/src/engine.js", "engine.js");
copy("packages/core/src/graph.js", "graph.js"); copy("packages/core/src/graph.js", "graph.js");
for (const f of ["form_responses.json", "register.json", "graph.json"]) copy(`data/public/${f}`, `data/${f}`); copy("packages/core/src/solver.js", "solver.js");
for (const f of ["form_responses.json", "register.json", "graph.json", "policy.json"]) copy(`data/public/${f}`, `data/${f}`);
// Source files shown in the page's "view the code" panel // Source files shown in the page's "view the code" panel
for (const f of ["analyze.py", "clean.py", "stats_core.py"]) copy(`research/python/${f}`, `python/${f}`); for (const f of ["analyze.py", "clean.py", "stats_core.py"]) copy(`research/python/${f}`, `python/${f}`);
copy("README.md", "README.md"); copy("README.md", "README.md");
+62
View File
@@ -0,0 +1,62 @@
// Write docs/POLICY.md: a readable summary of data/public/policy.json.
// node scripts/policy-report.js
const fs = require("fs");
const path = require("path");
const root = path.resolve(__dirname, "..");
const P = JSON.parse(fs.readFileSync(path.join(root, "data/public/policy.json"), "utf8"));
const pct = (p) => (p == null ? "–" : (100 * p).toFixed(p < 0.1 ? 1 : 0) + "%");
const conf = (n) => (n.stillBest == null ? "" : ` (still best in ${pct(n.stillBest)} of posterior draws)`);
function walk(n, out, indent = "") {
if (!n) return;
if (n.type === "decision") {
const alts = Object.entries(n.options).sort((a, b) => b[1].pX - a[1].pX)
.map(([k, v]) => `${k} ${pct(v.pX)}`).join(", ");
if (n.tie) out.push(`${indent}- ${n.label}: any (no difference for this colour)`);
else out.push(`${indent}- **${n.label}: ${n.choice}**${conf(n)}${n.stillBest != null && n.stillBest < 0.75 ? " — no clear winner" : ""}. If chosen, then best play after: ${alts}`);
walk(n.next, out, indent);
} else if (n.type === "chance") {
const br = Object.entries(n.branches).sort((a, b) => b[1].p - a[1].p);
const live = br.filter(([k]) => !["die"].includes(k));
if (br.some(([k]) => k === "die")) {
const d = br.find(([k]) => k === "die");
out.push(`${indent}- ${n.label}: ${pct(1 - d[1].p)} survive`);
for (const [, b] of live) walk(b.next, out, indent);
return;
}
if (live.length === 1) return walk(live[0][1].next, out, indent);
out.push(`${indent}- ${n.label}: ${br.map(([k, b]) => `${k} ${pct(b.p)}`).join(", ")}`);
for (const [k, b] of br) {
out.push(`${indent} - if **${k}**:`);
walk(b.next, out, indent + " ");
}
} else if (n.outcomes) {
out.push(`${indent}- Outcome if you attempt: ${Object.entries(n.outcomes).sort((a, b) => b[1] - a[1]).map(([k, p]) => `${k === "burn" ? "incinerated" : "bond " + k} ${pct(p)}`).join(", ")}`);
} else out.push(`${indent}- ${n.what}`);
}
const s = P.samples.all, lb = P.samples.lowBias;
const L = [];
L.push("# Best routes by dragon colour", "");
L.push(`Generated from ${s.data.runs} community runs by \`scripts/build-policy.js\`. Machine-readable version: \`data/public/policy.json\`.`, "");
L.push("**How to read this.** \"This attempt\" maximises the chance of bonding the colour on one run. \"Eventually\" assumes you will die on purpose and try again whenever the run goes wrong, so it avoids any choice that can end the account on a different dragon. Percentages are posterior means with 95% credible intervals. \"Held-out\" is the same policy chosen on half of the runs and scored on the other half: when it is much lower than the in-sample number, the route's advantage is mostly noise.", "");
L.push("**Caveats.** The form records choices only at the level of company, direction, first dragon, cadet encounter, fork, tree or valley, and which dragon you met. Choices inside each encounter are not recorded, so the bond chance at an encounter is the community's average with whatever answers people used. Riders chasing a rare dragon report sightings more often than riders who log every run; the \"low-bias\" columns use only bulk logs and non-chasers.", "");
L.push("| Colour | This attempt | Low-bias sample | Held-out | Eventually: chance the account ends on this colour | Attempts needed (about) |");
L.push("|---|---|---|---|---|---|");
for (const X of Object.keys(s.targets)) {
const t = s.targets[X], a = t.thisAttempt, e = t.eventually, l = lb.targets[X].thisAttempt;
L.push(`| ${X} | ${pct(a.pX.mean)} (${pct(a.pX.lo)}–${pct(a.pX.hi)}) | ${pct(l.pX.mean)} (${pct(l.pX.lo)}–${pct(l.pX.hi)}) | ${pct(t.crossFit.heldOut)} | ${pct(e.ratio.mean)} | ${Math.round(e.expectedAttempts.mean)} |`);
}
L.push("", "## How much do earlier choices matter?", "");
L.push("Each chance event can depend on the choices before it. The model learns how much from the data (empirical-Bayes concentration; larger means the history matters less):", "");
L.push("| Chance event | Depends on (most important first) | Concentration |", "|---|---|---|");
for (const [k, ctx] of Object.entries(s.model.chanceContext)) L.push(`| ${k} | ${ctx.join(", ") || "nothing"} | ${s.model.alphas[k]} |`);
for (const X of Object.keys(s.targets)) {
for (const [obj, title] of [["thisAttempt", "this attempt"], ["eventually", "eventually"]]) {
const out = [];
walk(s.targets[X][obj].tree, out);
L.push("", `## ${X}: ${title}`, "", ...out);
}
}
fs.writeFileSync(path.join(root, "docs/POLICY.md"), L.join("\n") + "\n");
console.log("wrote docs/POLICY.md", L.length, "lines");
+94
View File
@@ -0,0 +1,94 @@
// node --test tests/solver.test.js
const test = require("node:test");
const assert = require("node:assert");
const S = require("../packages/core/src/solver");
// A synthetic world: 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.
function world(n = 4000, seed = 7) {
let s = seed;
const r = () => ((s = (s * 1103515245 + 12345) % 2147483648) / 2147483648);
const runs = [];
for (let i = 0; i < n; i++) {
const 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", enc_Red: null, enc_Green: null, enc_Orange: null, enc_Brown: null, enc_Blue: null, enc_Black: null };
run.hour = r() < 0.5 ? "Tree" : "Valley";
if (run.hour === "Tree") {
if (r() < 0.02) { run.branch = "Shadow (rare)"; run.enc_Black = "Bonded!"; run.outcome = "Bonded"; run.outcome_color = "Black"; }
else if (r() < 0.5) { run.branch = "Descend quickly: Red"; run.enc_Red = "Incinerated"; run.outcome = "Incinerated"; run.outcome_color = "Red"; }
else {
run.branch = "Descend slowly: two Greens";
const u = r();
if (u < 0.5) { run.enc_Green = "Incinerated"; run.outcome = "Incinerated"; run.outcome_color = "Green"; }
else if (u < 0.75) { run.enc_Green = "Bonded!"; run.outcome = "Bonded"; run.outcome_color = "Green"; }
else { run.enc_Green = "Saved by another"; run.enc_Brown = "Bonded!"; run.outcome = "Bonded"; run.outcome_color = "Brown"; }
}
} else if (r() < 0.2) { run.branch = "Valley Red"; run.enc_Red = "Bonded!"; run.outcome = "Bonded"; run.outcome_color = "Red"; }
else {
run.branch = "Passed the Red: meadow";
const u = r(), c = u < 0.3 ? "Blue" : u < 0.65 ? "Orange" : "Brown";
const bond = r() < 0.5;
run["enc_" + c] = bond ? "Bonded!" : "Incinerated"; run.outcome = bond ? "Bonded" : "Incinerated"; run.outcome_color = c;
}
runs.push(run);
}
return runs;
}
const policy = S.buildPolicy(world(), { draws: 10, colours: ["Blue", "Black", "Red", "Brown"] });
const choice = (X, h, obj = "thisAttempt") => S.advisor(policy, X, obj).next(h).choice;
test("Blue: go to the valley, pass the Red, attempt only the Blue", () => {
const t = policy.targets.Blue.thisAttempt;
const h = { company: "Alone", direction: "Center", fs: "Red", cadet: "Killed the bullies yourself", post: "Forest" };
assert.strictEqual(choice("Blue", h), "Valley");
assert.strictEqual(choice("Blue", { ...h, hour: "Valley" }), "Pass the Red (meadow)");
const meadow = { ...h, hour: "Valley", valley: "Pass the Red (meadow)" };
assert.strictEqual(choice("Blue", { ...meadow, meadow: "Blue" }), "Attempt the bond");
assert.strictEqual(choice("Blue", { ...meadow, meadow: "Orange" }), "Die on purpose");
assert.strictEqual(S.locate(t.tree, {}).var, "company");
// 30% Blue in the meadow x 50% bond
assert.ok(Math.abs(t.pX.point - 0.15) < 0.03, t.pX.point);
});
test("Black: climb the tree; the value is about the shadow rate x bond rate", () => {
const t = policy.targets.Black.thisAttempt;
const h = { company: "Alone", direction: "East", fs: "Red", cadet: "Squadmate's revenge", post: "Forest" };
assert.strictEqual(choice("Black", h), "Tree");
assert.ok(t.pX.point > 0.01 && t.pX.point < 0.035, t.pX.point);
});
test("Red: face the valley Red", () => {
const h = { company: "Alone", direction: "West", fs: "Brown", cadet: "Killed the bullies yourself", post: "Forest", hour: "Valley" };
assert.strictEqual(choice("Red", h), "Face the Red");
});
test("Brown 'eventually' never risks a non-Brown bond that 'this attempt' accepts", () => {
const a = policy.targets.Brown.thisAttempt, e = policy.targets.Brown.eventually;
assert.ok(e.pOther.point <= a.pOther.point + 1e-12);
assert.ok(e.ratio.mean >= a.ratio.mean - 1e-9);
});
test("no history dependence in the data -> large fitted concentration", () => {
assert.ok(policy.model.alphas.meadow >= 500, JSON.stringify(policy.model.alphas));
});
test("recommendOption maps the policy onto the bot's screen text", () => {
const adv = S.advisor(policy, "Blue", "thisAttempt");
const rec = S.recommendOption(adv, { company: "Alone", direction: "Center", fs: "Red", cadet: "Killed the bullies yourself", post: "Forest" },
["Continue toward the center of the valley", "Find the tallest tree and climb for a better view"]);
assert.strictEqual(rec.index, 0);
const none = S.recommendOption(adv, {}, ["Something we have never seen"]);
assert.strictEqual(none.index, null);
});
test("advisor matches the solver's own decisions on the recommended route", () => {
const adv = S.advisor(policy, "Blue", "eventually");
assert.strictEqual(adv.next({}).choice, policy.targets.Blue.eventually.tree.choice);
});
test("solverHistory converts form variables", () => {
const h = S.solverHistory({ company: "Alone", direction: "Center", first_sighting: "Red", resolution: "Tourniquet", hour: "Tree", branch: "Descend slowly: two Greens" });
assert.deepStrictEqual(h, { company: "Alone", direction: "Center", fs: "Red", cadet: "Tourniquet", post: "(no fork)", hour: "Tree", descend: "Slowly (two Greens)", shadow: "no" });
});