From 5f66b9647ac04cdbceff8c0e0800f2c7cd86eb77 Mon Sep 17 00:00:00 2001 From: ekcSchiano Date: Mon, 2 Nov 2026 20:09:13 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ --- apps/atlas/explorer.js | 136 +++++--- apps/atlas/index.html | 4 +- data/public/policy.json | 2 +- docs/POLICY.md | 594 +++++++++++++++++++++------------- package.json | 2 +- packages/core/src/graph.js | 4 +- packages/core/src/solver.js | 68 +++- tests/solver.test.js | 9 +- undefined/desktop-data.png | Bin 703971 -> 755780 bytes undefined/desktop-deep.png | Bin 2628114 -> 2685164 bytes undefined/desktop-dragons.png | Bin 2127113 -> 2214524 bytes undefined/desktop-odds.png | Bin 827601 -> 857872 bytes undefined/desktop-valley.png | Bin 1350860 -> 1351007 bytes undefined/log.json | 6 +- undefined/phone-data.png | Bin 619680 -> 619581 bytes undefined/phone-deep.png | Bin 1936603 -> 1936687 bytes undefined/phone-dragons.png | Bin 3688818 -> 3688977 bytes undefined/phone-odds.png | Bin 713603 -> 712531 bytes undefined/phone-valley.png | Bin 552967 -> 552855 bytes undefined/text-odds.txt | 14 +- 20 files changed, 548 insertions(+), 291 deletions(-) diff --git a/apps/atlas/explorer.js b/apps/atlas/explorer.js index f7ccbb5..a9147a1 100644 --- a/apps/atlas/explorer.js +++ b/apps/atlas/explorer.js @@ -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. */ diff --git a/apps/atlas/index.html b/apps/atlas/index.html index 5fe8e33..97996af 100644 --- a/apps/atlas/index.html +++ b/apps/atlas/index.html @@ -672,10 +672,10 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)