Dice beside every roll; click them for the odds of each outcome
CI / test (pull_request) Successful in 44s

- site/atlas/dice.js: a pair of dice marks a step the game decides at random (not the rider's choice). Clicking
  (or Enter on) the dice opens a small popover with every outcome of that roll and its odds; Escape, scrolling or
  a click elsewhere closes it. Dice.html for text, Dice.svg for the maps, Dice.legend for the keys.
- Route map: dice after each "game roll" heading (first sighting, encounter), with the share of riders at each
  outcome in the runs shown. Legend: dice and gold headings = steps the game rolls.
- Valley map: dice on the "roll" / "shadow" labels of a route (the model's odds given the route so far), on the
  "First dragon" step of the route list, in the first-sighting card, on the guide's own roll notes (no odds:
  the guide gives none) and on the bot's answers that led to different screens. Legend under the route key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
2026-11-19 21:23:07 +00:00
co-authored by Claude Opus 5.5
parent 6d52a2548e
commit a1966bfa2c
4 changed files with 137 additions and 8 deletions
+10 -2
View File
@@ -272,7 +272,15 @@
const chance = s.chance;
const t = svgEl("text", { x: colX(i), y: 18, class: "stage-label" + (chance ? " stage-chance" : "") }, svg);
t.textContent = s.label;
if (chance) { const r = svgEl("text", { x: colX(i), y: 31, class: "stage-label stage-chance" }, svg); r.textContent = "game roll"; }
if (chance) {
const r = svgEl("text", { x: colX(i), y: 31, class: "stage-label stage-chance" }, svg);
r.textContent = "game roll";
const here = G.nodes.filter((n) => n.stage === i), tot = here.reduce((a, n) => a + n.n, 0) || 1;
const w = r.getComputedTextLength ? r.getComputedTextLength() : 70; // the headings are left-aligned
Dice.svg(svg, colX(i) + w + 15, 27, { title: `${s.label}: the game's roll`, n: tot,
options: here.map((n) => [n.value, n.n / tot]),
note: "Share of riders who reached this step, in the runs shown. The game decides it; earlier choices can shift the odds." });
}
});
// links
@@ -342,7 +350,7 @@
<span>${state.widthMode === "traffic" ? "Band width = number of runs" : "Line width = chance of the outcome"}</span>
<span style="display:inline-flex;gap:6px;align-items:center">0% <span class="ramp" style="background:linear-gradient(90deg, ${low}, ${tcol})"></span> ${pct(pmax, 0)}</span>
<span>Grey = fewer than ${state.minN} runs</span>
<span><span style="color:var(--accent)">Gold headings</span> = steps the game rolls, not you</span>`;
<span>${Dice.legend('and <span style="color:var(--accent)">gold headings</span> = steps the game rolls at random, not your choice. Click the dice for the odds of each outcome.')}</span>`;
}
function renderBestRoutes() {
+97
View File
@@ -0,0 +1,97 @@
/*
* Rolls of the dice. Wherever the page shows a step the game decides at random (not the rider's choice), a pair of
* dice sits next to it. Clicking the dice shows the odds of every outcome of that roll.
*
* Dice.html(roll) an inline button for HTML text
* Dice.svg(parent, x, y, roll) the same glyph inside an SVG map
* Dice.legend(text?) the legend line ("a roll: the game decides ...")
*
* roll = { title, options: [[label, p], ...], note?, n? } (p between 0 and 1; options may be empty with a note)
*/
(function () {
"use strict";
const NS = "http://www.w3.org/2000/svg";
// two dice, the back one showing two, the front one five
const GLYPH = `<svg class="dice-glyph" viewBox="0 0 22 16" width="22" height="16" aria-hidden="true">
<rect x="1" y="1.5" width="10" height="10" rx="2.2" transform="rotate(-12 6 6.5)" fill="var(--raised)" stroke="currentColor" stroke-width="1.2"/>
<circle cx="4" cy="4.8" r="1.05" fill="currentColor" transform="rotate(-12 6 6.5)"/><circle cx="8" cy="8.6" r="1.05" fill="currentColor" transform="rotate(-12 6 6.5)"/>
<rect x="9.5" y="4.5" width="10.5" height="10.5" rx="2.2" fill="var(--raised)" stroke="currentColor" stroke-width="1.2"/>
<circle cx="12.4" cy="7.4" r="1.05" fill="currentColor"/><circle cx="17.1" cy="7.4" r="1.05" fill="currentColor"/>
<circle cx="14.75" cy="9.75" r="1.05" fill="currentColor"/>
<circle cx="12.4" cy="12.1" r="1.05" fill="currentColor"/><circle cx="17.1" cy="12.1" r="1.05" fill="currentColor"/></svg>`;
const TIP = "A roll: the game decides, not you. Click for the odds of each outcome.";
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]));
const pack = (roll) => encodeURIComponent(JSON.stringify(roll || {}));
const pct = (p) => (p == null ? "–" : p < 0.001 && p > 0 ? "<0.1%" : `${(100 * p).toFixed(p < 0.1 ? 1 : 0)}%`);
function html(roll) {
return `<button type="button" class="dice" data-roll="${pack(roll)}" title="${TIP}" aria-label="${esc((roll && roll.title) || "A roll")}: show the odds">${GLYPH}</button>`;
}
function svg(parent, x, y, roll) {
const g = document.createElementNS(NS, "g");
g.setAttribute("class", "dice dice-svg");
g.setAttribute("data-roll", pack(roll));
g.setAttribute("transform", `translate(${x - 11},${y - 8})`);
g.setAttribute("tabindex", "0");
g.setAttribute("role", "button");
g.setAttribute("aria-label", `${(roll && roll.title) || "A roll"}: show the odds`);
const t = document.createElementNS(NS, "title");
t.textContent = TIP;
g.appendChild(t);
const halo = document.createElementNS(NS, "rect");
for (const [k, v] of Object.entries({ x: -3, y: -3, width: 28, height: 22, rx: 6, fill: "var(--map-halo, var(--bg))", "fill-opacity": 0.9 })) halo.setAttribute(k, v);
g.appendChild(halo);
g.insertAdjacentHTML("beforeend", GLYPH.replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, ""));
parent.appendChild(g);
return g;
}
function legend(text) {
return `<span class="dice-legend">${GLYPH.replace('class="dice-glyph"', 'class="dice-glyph legend" style="display:inline-block;vertical-align:-3px"')} ${text || "= a roll: the game decides at random, not your choice. Click any dice for the odds of each outcome."}</span>`;
}
// ---- the popover
let pop = null;
function hide() { if (pop) pop.hidden = true; }
function show(roll, x, y) {
if (!pop) {
pop = document.createElement("div");
pop.id = "dice-pop";
pop.setAttribute("role", "dialog");
document.body.appendChild(pop);
}
const opts = (roll.options || []).filter(([, p]) => p != null).sort((a, b) => b[1] - a[1]);
pop.innerHTML = `<b>${esc(roll.title || "A roll")}</b>
${opts.length ? `<ul>${opts.map(([k, p]) => `<li><span>${esc(k)}</span><span class="bar"><i style="width:${Math.max(1, 100 * p).toFixed(1)}%"></i></span><span class="p">${pct(p)}</span></li>`).join("")}</ul>` : ""}
<p>${esc(roll.note || "The game decides this at random. Your earlier choices can change the odds, but not the outcome.")}${roll.n ? ` From ${Number(roll.n).toLocaleString()} runs.` : ""}</p>`;
pop.hidden = false;
const r = pop.getBoundingClientRect();
pop.style.left = `${Math.max(8, Math.min(window.innerWidth - r.width - 8, x - r.width / 2))}px`;
pop.style.top = `${y + 14 + r.height > window.innerHeight ? Math.max(8, y - r.height - 14) : y + 14}px`;
}
function open(e, t) {
e.preventDefault();
e.stopPropagation();
let roll = {};
try { roll = JSON.parse(decodeURIComponent(t.getAttribute("data-roll"))); } catch { /* an empty roll */ }
const b = t.getBoundingClientRect();
show(roll, b.left + b.width / 2, b.bottom - 6);
}
// capture phase: a dice inside a map or a card must not also select what is under it
document.addEventListener("click", (e) => {
const t = e.target.closest && e.target.closest("[data-roll]");
if (t) return open(e, t);
if (pop && !pop.hidden && !pop.contains(e.target)) hide();
}, true);
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") return hide();
const t = (e.key === "Enter" || e.key === " ") && e.target.closest && e.target.closest(".dice-svg[data-roll]");
if (t) open(e, t);
}, true);
window.addEventListener("scroll", hide, { passive: true });
window.Dice = { html, svg, legend };
})();
+15 -6
View File
@@ -325,6 +325,13 @@
pills.push({ g, x, y, w, h, dy: 0 });
el("rect", { x: x - w / 2, y: y - h / 2, width: w, height: h, rx: h / 2, fill: bg, "fill-opacity": 0.95, stroke: edge || ink, "stroke-opacity": edge ? 0.95 : 0.4, "stroke-width": edge ? 2 : 1 }, g);
el("text", { x, y: y + (strong ? 4.5 : 4), "text-anchor": "middle", "font-size": strong ? 12.5 : 11, "font-weight": strong ? 700 : 500, fill: ink, "font-family": "var(--font-data)" }, g).textContent = text;
return { g, w };
}
/** What a roll on the route can come out as: every outcome with its odds, for the dice. */
function rollOf(s, title) {
return { title: title || s.label || "A roll", options: Object.entries(s.probs || {}).filter(([, p]) => p > 0.0005),
note: "The game decides this at random. The odds are the model's, given the choices on this route so far." };
}
function drawDragons(g, routesOn) {
@@ -527,7 +534,8 @@
if (p > 0.995) return;
// the last roll leads straight into the dragon, whose own label sits there: put the roll under the fork point
const at = !ro.at ? { x: ro.P.x + 34, y: ro.P.y - 22 } : ro.at === pts.length - 1 ? { x: pts[ro.at - 1].P.x, y: pts[ro.at - 1].P.y + 24 } : mid(pts[ro.at - 1].P, pts[ro.at].P, 0.38);
pill(gLab, at.x, at.y, ro.s.var === "shadow" ? (ro.s.taken === "yes" ? `shadow ${pct(p)}` : `no shadow ${pct(p)}`) : `roll ${pct(p)}`);
const lab = pill(gLab, at.x, at.y, ro.s.var === "shadow" ? (ro.s.taken === "yes" ? `shadow ${pct(p)}` : `no shadow ${pct(p)}`) : `roll ${pct(p)}`);
Dice.svg(lab.g, at.x - lab.w / 2 - 14, at.y, rollOf(ro.s, ro.s.var === "shadow" ? "Does the shadow show at the tree?" : null));
});
// destination label
const end = pts[pts.length - 1];
@@ -715,7 +723,7 @@
const sp = st.info, dir = sp.place.split(":")[1];
const fs = st.policy ? S.makeParams(model().model.tables, { alphas: model().model.alphas }).chance("fs", { direction: dir }) : null;
info = `<div class="ex-card"><span class="eyebrow">First sighting · ${dir === "Center" ? "forest centre" : dir.toLowerCase()}</span>
<p class="small">The first dragon is a roll of the dice: nobody bonds here, it decides what you face next.${fs ? ` Going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}, riders met: ${Object.entries(fs).sort((a, b) => b[1] - a[1]).filter(([, p]) => p > 0.005).map(([k, p]) => `${k} ${pct(p)}`).join(", ")}.` : ""}</p></div>`;
<p class="small">The first dragon is a roll of the dice${fs ? ` ${Dice.html({ title: `First dragon, going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}`, options: Object.entries(fs).filter(([, p]) => p > 0.0005), note: "The game decides which dragon you see first. Which way you went changes the odds." })}` : ""}: nobody bonds here, it decides what you face next.${fs ? ` Going ${dir === "Center" ? "to the forest centre" : dir.toLowerCase()}, riders met: ${Object.entries(fs).sort((a, b) => b[1] - a[1]).filter(([, p]) => p > 0.005).map(([k, p]) => `${k} ${pct(p)}`).join(", ")}.` : ""}</p></div>`;
}
return `<span class="eyebrow">Unofficial atlas · built from ${st.nRuns ? st.nRuns.toLocaleString() : "thousands of"} logged runs</span>
<h2 id="h-valley">The valley</h2>
@@ -784,7 +792,7 @@
}
const endOf = (o) => (o.end ? o.end : "continues");
function treeList(options) {
return `<ul>${options.map((o) => o.roll ? `<li class="roll"><em>${esc(o.roll)}</em></li>` :
return `<ul>${options.map((o) => o.roll ? `<li class="roll">${Dice.html({ title: "A roll (from the community guide)", note: `The guide notes: ${o.roll}. It gives no odds for it.` })}<em>${esc(o.roll)}</em></li>` :
`<li class="${o.best ? "best" : ""}${o.unconfirmed ? " pale" : ""}">${esc(o.say)}${o.pct ? ` <small>${esc(o.pct)}</small>` : ""}${o.end ? ` → <b>${esc(o.end)}</b>` : ""}${o.then ? treeList(o.then) : ""}</li>`).join("")}</ul>`;
}
function guideAnswers(enc) {
@@ -798,7 +806,7 @@
if (!E) return "";
const next = keys[ki + 1] ? (g.encounters[keys[ki + 1]] || {}).title || "" : "";
const steps = guidePath(E.options, st.colour, next ? next.replace(/^The /, "") : null);
const rows = steps.map((s, i) => `<li><span class="n">${i + 1}</span><div><b>${esc(s.pick.say)}</b>${s.roll ? `<small class="ex-roll">The guide notes: ${esc(s.roll)}.</small>` : ""}
const rows = steps.map((s, i) => `<li><span class="n">${i + 1}</span><div><b>${esc(s.pick.say)}</b>${s.roll ? `<small class="ex-roll">${Dice.html({ title: "A roll (from the community guide)", note: `The guide notes: ${s.roll}. It gives no odds for it.` })}The guide notes: ${esc(s.roll)}.</small>` : ""}
<small>${s.pick.pct ? `the guide's rate: ${esc(s.pick.pct)}` : ""}${s.pick.unconfirmed ? " · unconfirmed" : ""}${s.pick.end ? `${s.pick.pct ? " · " : ""}${esc(s.pick.end)}` : ""}</small>
${s.others.length ? `<details><summary>Other answers here</summary><ul>${s.others.map((o) => `<li>${esc(o.say)}${o.pct ? ` <small>${esc(o.pct)}</small>` : ""} → ${esc(endOf(o))}</li>`).join("")}</ul></details>` : ""}</div></li>`).join("");
return `<p class="small"><b>${esc(E.title)}</b>: <em>${esc(E.scene)}</em>${E.warning ? ` <span class="ex-warn">${esc(E.warning)}</span>` : ""}</p>
@@ -831,7 +839,7 @@
const others = Object.entries(sc.options).filter(([k]) => k !== p.option).map(([, o]) =>
`<li>${esc(o.text)} <small>${o.n ? `died ${died(o)} of ${o.n}` : "untested"}</small></li>`).join("");
return `<li><span class="n">${i + 1}</span><div><b>${esc(p.text)}</b>
<small>${me.n ? `got through ${lived} of ${me.n} times` : ""}${me.kind === "fixed" && me.n ? " · always the same so far" : me.kind === "dice" ? " · a roll" : ""}</small>
<small>${me.n ? `got through ${lived} of ${me.n} times` : ""}${me.kind === "fixed" && me.n ? " · always the same so far" : me.kind === "dice" ? ` · a roll ${Dice.html({ title: p.text, n: me.n, options: Object.entries(me.to || {}).map(([k, o]) => [k === "DIED" ? "died" : k.startsWith("BONDED") ? k.replace("BONDED_", "bonded ").toLowerCase() : (t.screens[k] ? `then: ${t.screens[k].stage.toLowerCase().replace(/_/g, " ")}${t.screens[k].tint ? ` (${t.screens[k].tint})` : ""}` : k), o.n / me.n]), note: "The same answer led to different screens in the bot's runs: the game rolled." })}` : ""}</small>
${others ? `<details><summary>Other answers here</summary><ul>${others}</ul></details>` : ""}</div></li>`;
}).join("");
const end = Object.keys((t.screens[picks[picks.length - 1].screen] || { options: {} }).options[picks[picks.length - 1].option]?.to || {}).find((k) => k.startsWith("BONDED"));
@@ -855,7 +863,7 @@
<b>${pct(r.value.x)}</b><small>${st.colour === "Black" ? "on a first attempt" : "per attempt"} · ${bond}${n < 30 ? ` · only ${n} attempts logged` : ""}${r.value.o > 0.005 ? ` · ends on another dragon ${pct(r.value.o)}` : ""}</small></button>`;
};
const steps = focus.steps.filter((s) => s.kind === "decision" || s.kind === "chance").map((s) => {
if (s.kind === "chance") return `<li class="chance"><span>${esc(s.label)}</span><b>${esc(String(s.taken))}</b><small>roll ${pct(s.probs[s.taken])}</small></li>`;
if (s.kind === "chance") return `<li class="chance"><span>${esc(s.label)} ${Dice.html(rollOf(s))}</span><b>${esc(String(s.taken))}</b><small>roll ${pct(s.probs[s.taken])}</small></li>`;
const open = st.expanded === s.var;
const opts = open ? `<div class="ex-opts">${Object.entries(s.options).sort((a, c) => c[1].pX - a[1].pX).map(([v, val]) =>
`<button type="button" class="ex-opt${v === s.taken ? " on" : ""}" data-var="${s.var}" data-v="${esc(v)}"><span>${esc(v)}${v === s.choice ? ' <em class="rec">best</em>' : ""}</span><b>${pct(val.pX)}</b></button>`).join("")}</div>` : "";
@@ -871,6 +879,7 @@
${st.blocked ? `<p class="small ex-warn">Your choices so far can't reach a ${st.colour} dragon. <button type="button" class="linklike" id="ex-reset-route">Reset your choices</button></p>` : ""}
<div class="ex-routes">${routes.map(card).join("")}</div>
<p class="small muted ex-key"><span class="solid"></span> best route <span class="dashed"></span> under half as likely <span class="dotted"></span> under a tenth · line width: chance you are still on the route</p>
<p class="small muted">${Dice.legend()}</p>
<span class="eyebrow">${esc(ENC_NAME[focus.enc])}: step by step</span>
<ol class="ex-steps">${steps}</ol>
<p class="small muted">Diamonds on the map are choices: click one to see where the other options lead. ${st.blocked ? "" : `Your choices apply to every route to this dragon. Changed your mind? <button type="button" class="linklike" id="ex-reset-route">Reset your choices</button>`}</p>
+15
View File
@@ -89,6 +89,20 @@ button.primary, a.btnlike.primary { background: var(--accent); color: var(--acce
#map text { font-family: var(--font-body); font-size: 11px; fill: var(--ink); }
#map .stage-label { font-family: var(--font-data); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; fill: var(--muted); }
#map .stage-chance { fill: var(--accent); }
/* rolls of the dice (dice.js): a step the game decides, not the rider */
.dice { display: inline-flex; align-items: center; vertical-align: middle; padding: 0 2px; margin: 0 2px; border: 0; background: none; color: var(--accent); cursor: pointer; line-height: 1; border-radius: 4px; }
.dice:hover, .dice:focus-visible, .dice-svg:hover, .dice-svg:focus-visible { color: var(--ink); outline: 1px solid var(--accent); outline-offset: 1px; }
.dice-svg { color: var(--accent); cursor: pointer; }
.dice-glyph { display: inline-block; vertical-align: middle; }
.dice-glyph.legend { color: var(--accent); margin-right: 2px; }
.dice-legend { display: inline; }
#dice-pop { position: fixed; z-index: 60; max-width: min(320px, calc(100vw - 16px)); padding: 10px 12px; background: var(--raised); color: var(--ink); border: 1px solid var(--accent); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.45); font-size: var(--step--1, 0.85rem); }
#dice-pop ul { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 4px; }
#dice-pop li { display: grid; grid-template-columns: minmax(0, 1fr) 70px 46px; gap: 8px; align-items: center; }
#dice-pop .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#dice-pop .bar i { display: block; height: 100%; background: var(--accent); }
#dice-pop .p { font-family: var(--font-data); text-align: right; }
#dice-pop p { margin: 6px 0 0; color: var(--muted); }
#map .node rect { stroke: color-mix(in srgb, var(--ink) 40%, transparent); stroke-width: 0.6; cursor: pointer; }
#map .node.sel rect { stroke: var(--accent); stroke-width: 2.4; }
#map .node.dim { opacity: 0.35; }
@@ -749,6 +763,7 @@ adjusted OR = exp(βⱼ), 95% CI = exp(βⱼ ± 1.96·SEⱼ)</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="solver.js"></script>
<script src="register.js"></script>
<script src="dice.js"></script>
<script src="app.js"></script>
<script src="valley.js"></script>
<script src="dragons.js"></script>