Bully fight: add the first move and the dagger choice to the solver and the map

After helping your squadmate the game asks your first move (pause to assess, charge the
smaller cadet, or get between your squadmate and the bigger one) and, after pausing, what to
do about the smaller cadet's dagger. Both are now decisions in the solver, and the chance of
dying in the fight depends on them (about 3 in 10 riders who charged in died; almost none who
paused). With that split, helping now beats walking away.

On the map, several choices made at one place share one diamond, which opens a card listing
each choice in the game's order. Policy rebuilt; the policy build gets a larger heap.

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-02 20:09:13 +00:00
co-authored by Claude Opus 5.5
parent 1646844fa6
commit 5f66b9647a
20 changed files with 548 additions and 291 deletions
+99 -37
View File
@@ -87,7 +87,7 @@
"dir:Center": { force: { direction: "Center" }, at: "fs" },
"dir:East": { force: { direction: "East" }, at: "fs" },
scream: { force: {}, at: "scream" },
bully: { force: { scream: INV, clearing: HELPC }, at: "fate", risk: true, note: "You stepped in to help your squadmate, so these chances include the risk of being killed in the fight. Walking away instead leads to the hour's walk." },
bully: { force: { scream: INV, clearing: HELPC }, at: "fight", note: "You stepped in to help your squadmate. Each dragon's chance assumes your best first move in the fight (pause to assess) and includes the risk of being killed there; charging straight in kills about a third of riders. Walking away instead leads to the hour's walk." },
wounded: { force: { scream: "Keep walking" }, at: "wounded" },
away: { force: { scream: INV, clearing: "Walk away" }, at: "hour" },
"res:Killed the bullies yourself": { force: { scream: INV, clearing: HELPC, fate: "Killed the bullies yourself" }, at: "post" },
@@ -257,6 +257,7 @@
company: "comp:" + v, direction: "dir:" + v, post: "fork:" + v,
scream: v === "Keep walking" ? "wounded" : "bully",
clearing: v === "Walk away" ? "away" : "bully",
fight: "bully", dagger: "bully",
fate: "res:" + v, wounded: "res:" + v,
hour: v === "Tree" ? "tree" : "valley", descend: v.startsWith("Quickly") ? "treeRed" : "greens",
valley: v === "Face the Red" ? "valleyRed" : "meadow",
@@ -340,7 +341,7 @@
const SCENERY = [
{ at: "bully", fig: "defender", dx: -150, dy: 62, sc: 0.42, tip: "The bully fight", text: "Your squadmate holds off two cadets who have bullied them since Parapet. Help them, or walk away." },
{ at: "bully", fig: "lunging", dx: -126, dy: 62, sc: 0.42, tip: "The bully fight", text: "The bigger cadet swings a sword; the smaller one has a dagger ready to throw." },
{ at: "bully", fig: "throwing", dx: -98, dy: 62, sc: 0.42, tip: "The bully fight", text: "Assess first, even the numbers, or put yourself in the middle. Then decide the bullies' fate." },
{ at: "bully", fig: "throwing", dx: -98, dy: 62, sc: 0.42, tip: "The bully fight", text: "Pause to assess, charge the smaller cadet, or get between your squadmate and the bigger one. After pausing, the smaller cadet's dagger. Then the bullies' fate." },
{ at: "wounded", fig: "lying", dx: -72, dy: 4, sc: 0.56, tip: "The wounded cadet", text: "Ignore the scream and you find a badly wounded cadet. Tie a tourniquet, leave them, or take their weapons." },
{ at: "hour", fig: "thorns", dx: -66, dy: 6, sc: 0.44, tip: "An hour's walk", text: "No dragon for an hour, and a thorn cuts the back of your hand. Then: climb the tallest tree, or walk on to the valley centre." },
];
@@ -410,6 +411,7 @@
const best = Math.max(1e-12, ...routes.map((r) => r.value.x));
const onRoute = new Set();
const tc = INK[st.colour];
const cards = [];
// weaker routes first so the best one sits on top
[...routes].sort((a, b) => a.value.x - b.value.x).forEach((r) => {
const rel = r.value.x / best;
@@ -436,45 +438,105 @@
// destination label
const end = pts[pts.length - 1];
pill(gLab, end.P.x, end.P.y + 30, `${pct(r.value.x)} per attempt`, { edge: tc, strong: rel === 1 });
// choice points on the focused route
if (focus) marks.forEach((m) => {
if (!m.at || m.s.var === "encounter") return;
const P = m.at.P, open = st.expanded === m.s.var;
const g = el("g", { class: "ex-mark", tabindex: 0, role: "button", "aria-label": `${m.s.label}: ${m.s.taken}. Show the other options.`, "aria-expanded": open }, gLab);
el("path", { d: `M${P.x} ${P.y - 9} L${P.x + 9} ${P.y} L${P.x} ${P.y + 9} L${P.x - 9} ${P.y} Z`, fill: open ? tc : PAPER.halo, stroke: tc, "stroke-width": 2.5 }, g);
el("title", {}, g).textContent = `${m.s.label}: ${m.s.taken} (click for the other options)`;
const go = () => { st.expanded = open ? null : m.s.var; render(); };
g.addEventListener("click", go);
g.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); go(); } });
if (open) {
const best2 = Math.max(1e-12, ...Object.values(m.s.options).map((v) => v.pX));
Object.entries(m.s.options).forEach(([v, val]) => {
const pid = optionPlace(m.s, v);
if (!pid || !L[pid] || v === m.s.taken) return;
if (L[pid] === P) {
// this option stays where you are (e.g. help your squadmate, right here in the clearing)
pill(gLab, P.x, P.y - 30, `${v} ${pct(val.pX)}`, { edge: tc });
const hit = pills[pills.length - 1].g;
hit.setAttribute("class", "ex-alt"); hit.setAttribute("tabindex", 0); hit.setAttribute("role", "button");
hit.setAttribute("aria-label", `${v}: ${pct(val.pX)}. Take this instead.`);
const go = () => choose(m.s.var, v);
hit.addEventListener("click", go);
hit.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); go(); } });
return;
}
const B = L[pid], rel2 = val.pX / best2;
const p = el("path", { d: curve(P, B, 0.1), fill: "none", stroke: tc, "stroke-width": 2 + 4 * rel2, "stroke-opacity": 0.35 + 0.5 * rel2, "stroke-dasharray": "6 6", "stroke-linecap": "round", class: "ex-alt", tabindex: 0, role: "button", "aria-label": `${v}: ${pct(val.pX)}. Take this instead.` }, gLab);
// the option's own place is labelled on the map, so its chance sits just under that place
onRoute.add(pid);
pill(gLab, B.x, B.y + 17, pct(val.pX));
const pick = () => choose(m.s.var, v);
p.addEventListener("click", pick);
p.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); pick(); } });
// choice points on the focused route: one diamond per place, even when several choices are made there
// (at the bully fight: help or walk away, your first move, the dagger, then the bullies' fate)
if (focus) {
const groups = [];
marks.forEach((m) => {
if (!m.at || m.s.var === "encounter") return;
const g0 = groups.find((x) => x.at.id === m.at.id);
if (g0) g0.list.push(m); else groups.push({ at: m.at, list: [m] });
});
groups.forEach((grp) => {
const P = grp.at.P, vars = grp.list.map((m) => m.s.var), open = vars.includes(st.expanded);
const label = grp.list.map((m) => `${m.s.label}: ${m.s.taken}`).join("; ");
const g = el("g", { class: "ex-mark", tabindex: 0, role: "button", "aria-label": `${label}. Show the other options.`, "aria-expanded": open }, gLab);
el("path", { d: `M${P.x} ${P.y - 9} L${P.x + 9} ${P.y} L${P.x} ${P.y + 9} L${P.x - 9} ${P.y} Z`, fill: open ? tc : PAPER.halo, stroke: tc, "stroke-width": 2.5 }, g);
if (grp.list.length > 1) {
const t = el("text", { x: P.x + 11, y: P.y - 8, "font-size": 10, "font-weight": 700, fill: tc, "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3, "font-family": "var(--font-data)" }, g);
t.textContent = grp.list.length;
}
el("title", {}, g).textContent = `${label} (click for the other options)`;
const go = () => { st.expanded = open ? null : vars[0]; render(); };
g.addEventListener("click", go);
g.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); go(); } });
if (!open) return;
const rows = [];
grp.list.forEach((m) => {
const opts = Object.entries(m.s.options);
const best2 = Math.max(1e-12, ...opts.map(([, v]) => v.pX));
// a choice made right here (no other place to point at) is listed in a small card
const here = opts.some(([v]) => { const pid = optionPlace(m.s, v); return !pid || !L[pid] || L[pid] === P; });
if (here) { rows.push(m); return; }
opts.forEach(([v, val]) => {
const pid = optionPlace(m.s, v);
if (!pid || !L[pid] || v === m.s.taken) return;
const B = L[pid], rel2 = val.pX / best2;
const pth = el("path", { d: curve(P, B, 0.1), fill: "none", stroke: tc, "stroke-width": 2 + 4 * rel2, "stroke-opacity": 0.35 + 0.5 * rel2, "stroke-dasharray": "6 6", "stroke-linecap": "round", class: "ex-alt", tabindex: 0, role: "button", "aria-label": `${v}: ${pct(val.pX)}. Take this instead.` }, gLab);
// the option's own place is labelled on the map, so its chance sits just under that place
onRoute.add(pid);
pill(gLab, B.x, B.y + 17, pct(val.pX));
const pick = () => choose(m.s.var, v);
pth.addEventListener("click", pick);
pth.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); pick(); } });
});
});
if (rows.length) cards.push({ P, rows, tc });
});
}
});
cards.forEach((c) => drawCard(gLab, c));
return onRoute;
}
// short names for the choice card (the panel keeps the full ones)
const SHORT = {
"Help your squadmate": "Help them", "Walk away": "Walk away",
"Pause to assess": "Pause to assess", "Charge the smaller cadet": "Charge the smaller one",
"Charge between the bigger cadet and your squadmate": "Get between them",
"Engage the smaller cadet": "Engage the smaller one", "Charge the bigger cadet anyway": "Charge the bigger one",
};
const CAPTION = { clearing: "Your squadmate vs two bullies", fight: "Your first move", dagger: "The smaller cadet has a dagger" };
/**
* The choices made at one place, in the game's order, as a small card beside it: one row per choice, every
* option with its chance (the one on this route is filled). Clicking an option takes it instead.
*/
function drawCard(g0, { P, rows, tc }) {
const W = 300, pad = 10, gap = 6, rowH = 22, capH = 15;
const lay = rows.map((m) => {
const items = [];
let x = 0, y = 0;
Object.entries(m.s.options).forEach(([v, val]) => {
const text = `${SHORT[v] || v} ${pct(val.pX)}`, w = 14 + text.length * 6.3;
if (x && x + w > W - 2 * pad) { x = 0; y += rowH; }
items.push({ v, val, text, w, x, y }); x += w + gap;
});
return { m, items, h: capH + y + rowH };
});
const H = pad + lay.reduce((a, r) => a + r.h + 6, 0) + pad - 6;
let x0 = P.x + 22, y0 = P.y - H / 2;
if (x0 + W > 992) x0 = P.x - 22 - W;
y0 = Math.max(8, Math.min(782 - H, y0));
const g = el("g", { class: "ex-card-map" }, g0);
el("rect", { x: x0, y: y0, width: W, height: H, rx: 10, fill: PAPER.halo, "fill-opacity": 0.97, stroke: tc, "stroke-width": 2 }, g);
let y = y0 + pad;
lay.forEach(({ m, items, h }) => {
el("text", { x: x0 + pad, y: y + 10, "font-size": 10.5, "font-weight": 700, "letter-spacing": ".06em", fill: PAPER.ink, "fill-opacity": 0.75, "font-family": "var(--font-data)" }, g)
.textContent = (CAPTION[m.s.var] || m.s.label).toUpperCase();
items.forEach((it) => {
const on = it.v === m.s.taken, bx = x0 + pad + it.x, by = y + capH + it.y;
const b = el("g", { class: "ex-alt", tabindex: 0, role: "button", "aria-pressed": on, "aria-label": `${m.s.label}: ${it.v}, ${pct(it.val.pX)}${on ? " (on this route)" : ". Take this instead."}` }, g);
el("rect", { x: bx, y: by, width: it.w, height: 18, rx: 9, fill: on ? tc : PAPER.halo, stroke: tc, "stroke-width": 1.5 }, b);
el("text", { x: bx + it.w / 2, y: by + 13, "text-anchor": "middle", "font-size": 11, "font-weight": on ? 700 : 500, fill: on ? "#fff" : PAPER.ink, "font-family": "var(--font-data)" }, b).textContent = it.text;
el("title", {}, b).textContent = it.v;
if (!on) {
const pick = () => choose(m.s.var, it.v);
b.addEventListener("click", pick);
b.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); pick(); } });
}
});
y += h + 6;
});
return onRoute;
}
/** Push overlapping labels apart vertically (a few relaxation passes), so no two chances sit on top of each other. */
+2 -2
View File
@@ -672,10 +672,10 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
</div>
<div class="mpanel method" role="tabpanel" id="mt-5-panel" aria-labelledby="mt-5" hidden>
<h3>6. Best routes, the valley map and The Odds</h3>
<p>The valley map and The Odds come from a solver (<code>solver.js</code>) that treats a run as a decision tree. Your choices are decisions (company, direction, the cadet encounter in the game's order — investigate the scream or keep walking, help your squadmate or walk away, then the bullies' fate or what to do for the wounded cadet — the fork, tree or valley, how to climb down, whether to face the valley Red, and at every bonding encounter whether to attempt the bond or die on purpose). The game's rolls are chance events: which dragon appears first, whether you die at the sighting, in the fight or before the hour, whether the shadow appears and which dragon it is, which dragon waits in the meadow, and how the bonding encounter ends.</p>
<p>The valley map and The Odds come from a solver (<code>solver.js</code>) that treats a run as a decision tree. Your choices are decisions (company, direction, the cadet encounter in the game's order — investigate the scream or keep walking, help your squadmate or walk away, your first move in the fight (pause to assess, charge the smaller cadet, or get between your squadmate and the bigger one) and, after pausing, what to do about the smaller cadet's dagger, then the bullies' fate or what to do for the wounded cadet — the fork, tree or valley, how to climb down, whether to face the valley Red, and at every bonding encounter whether to attempt the bond or die on purpose). The game's rolls are chance events: which dragon appears first, whether you die at the sighting, in the fight or before the hour, whether the shadow appears and which dragon it is, which dragon waits in the meadow, and how the bonding encounter ends.</p>
<p>Each roll's probability may depend on the choices before it. It is estimated with <b>hierarchical <a href="https://en.wikipedia.org/wiki/Dirichlet-multinomial_distribution" target="_blank" rel="noopener">Dirichlet</a> back-off</b>: the estimate for a full history is pulled toward the estimate for a shorter history, which is pulled toward the overall rate. How strongly is chosen from the data for each roll (<a href="https://en.wikipedia.org/wiki/Empirical_Bayes_method" target="_blank" rel="noopener">empirical Bayes</a>), so the solver does not chase noise in small groups. The best route is then found by <b><a href="https://en.wikipedia.org/wiki/Backward_induction" target="_blank" rel="noopener">backward induction</a></b>, for two goals: the chance of bonding the dragon on this attempt, and, for riders who die on purpose whenever a run goes wrong, the chance that the account eventually ends on that dragon rather than another (maximised by <a href="https://en.wikipedia.org/wiki/Fractional_programming" target="_blank" rel="noopener">Dinkelbach iteration</a>). Ranges come from 200 posterior draws; "stays best in N%" is how often the recommended choice is still best across those draws.</p>
<p>Encounter outcomes use only <b>genuine attempts</b>: runs where the rider wanted that colour, any dragon, or said they would not seek Malek. The two summary cards on The Odds use the same rule in reverse: runs where the rider died on purpose at an encounter they did not want are left out, so they describe cadets who went into the valley and either bonded or died. The "low-bias" numbers use only bulk logs and form runs from riders who were not chasing a rare dragon.</p>
<p><b>Starting from a place.</b> Clicking a place on the map before choosing a dragon shows your chance of each dragon <i>from there on</i>. Choices before that place are the ones that lead to it (or the solver's best, where several do); rolls before it are averaged over the outcomes that can still reach it, weighted by how often they happen and by survival. From the place onward the solver plays the best route for each dragon. A dragon is "not reachable from here" when no logged run went from that place to it. Clicking the bully fight means you stepped in to help, so those chances include the risk of dying in the fight and the routes run through the bullies' fate; walking away is the hour's walk. For Orange and Brown, the Greens rescue is used only when their own meadow is out of reach.</p>
<p><b>Starting from a place.</b> Clicking a place on the map before choosing a dragon shows your chance of each dragon <i>from there on</i>. Choices before that place are the ones that lead to it (or the solver's best, where several do); rolls before it are averaged over the outcomes that can still reach it, weighted by how often they happen and by survival. From the place onward the solver plays the best route for each dragon. A dragon is "not reachable from here" when no logged run went from that place to it. Clicking the bully fight means you stepped in to help: the chances assume your best first move and include the risk of dying in the fight. The move matters: about 3 in 10 riders who charged straight in were killed, against almost none who paused to assess. Several choices made at one place (as at the bully fight) share one diamond on the map, which opens a small card with each choice in order. For Orange and Brown, the Greens rescue is used only when their own meadow is out of reach.</p>
</div>
<div class="mpanel method" role="tabpanel" id="mt-6-panel" aria-labelledby="mt-6" hidden>
<h3>Missing answers</h3>