From a1966bfa2c4e1835dc9809f426b120109796399e Mon Sep 17 00:00:00 2001 From: kathleen Date: Thu, 19 Nov 2026 21:23:07 +0000 Subject: [PATCH] Dice beside every roll; click them for the odds of each outcome - 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 Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ --- site/atlas/app.js | 12 +++++- site/atlas/dice.js | 97 ++++++++++++++++++++++++++++++++++++++++++ site/atlas/explorer.js | 21 ++++++--- site/atlas/index.html | 15 +++++++ 4 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 site/atlas/dice.js diff --git a/site/atlas/app.js b/site/atlas/app.js index 61ccbee..90ae554 100644 --- a/site/atlas/app.js +++ b/site/atlas/app.js @@ -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 @@ ${state.widthMode === "traffic" ? "Band width = number of runs" : "Line width = chance of the outcome"} 0% ${pct(pmax, 0)} Grey = fewer than ${state.minN} runs - Gold headings = steps the game rolls, not you`; + ${Dice.legend('and gold headings = steps the game rolls at random, not your choice. Click the dice for the odds of each outcome.')}`; } function renderBestRoutes() { diff --git a/site/atlas/dice.js b/site/atlas/dice.js new file mode 100644 index 0000000..75b61d7 --- /dev/null +++ b/site/atlas/dice.js @@ -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 = ``; + const TIP = "A roll: the game decides, not you. Click for the odds of each outcome."; + + const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[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 ``; + } + + 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(/^]*>/, "").replace(/<\/svg>$/, "")); + parent.appendChild(g); + return g; + } + + function legend(text) { + return `${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."}`; + } + + // ---- 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 = `${esc(roll.title || "A roll")} + ${opts.length ? `
    ${opts.map(([k, p]) => `
  • ${esc(k)}${pct(p)}
  • `).join("")}
` : ""} +

${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.` : ""}

`; + 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 }; +})(); diff --git a/site/atlas/explorer.js b/site/atlas/explorer.js index 07d58ce..38d467f 100644 --- a/site/atlas/explorer.js +++ b/site/atlas/explorer.js @@ -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 = `
First sighting · ${dir === "Center" ? "forest centre" : dir.toLowerCase()} -

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(", ")}.` : ""}

`; +

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(", ")}.` : ""}

`; } return `Unofficial atlas · built from ${st.nRuns ? st.nRuns.toLocaleString() : "thousands of"} logged runs

The valley

@@ -784,7 +792,7 @@ } const endOf = (o) => (o.end ? o.end : "continues"); function treeList(options) { - return `
    ${options.map((o) => o.roll ? `
  • ${esc(o.roll)}
  • ` : + return `
      ${options.map((o) => o.roll ? `
    • ${Dice.html({ title: "A roll (from the community guide)", note: `The guide notes: ${o.roll}. It gives no odds for it.` })}${esc(o.roll)}
    • ` : `
    • ${esc(o.say)}${o.pct ? ` ${esc(o.pct)}` : ""}${o.end ? ` → ${esc(o.end)}` : ""}${o.then ? treeList(o.then) : ""}
    • `).join("")}
    `; } 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) => `
  • ${i + 1}
    ${esc(s.pick.say)}${s.roll ? `The guide notes: ${esc(s.roll)}.` : ""} + const rows = steps.map((s, i) => `
  • ${i + 1}
    ${esc(s.pick.say)}${s.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)}.` : ""} ${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)}` : ""} ${s.others.length ? `
    Other answers here
      ${s.others.map((o) => `
    • ${esc(o.say)}${o.pct ? ` ${esc(o.pct)}` : ""} → ${esc(endOf(o))}
    • `).join("")}
    ` : ""}
  • `).join(""); return `

    ${esc(E.title)}: ${esc(E.scene)}${E.warning ? ` ${esc(E.warning)}` : ""}

    @@ -831,7 +839,7 @@ const others = Object.entries(sc.options).filter(([k]) => k !== p.option).map(([, o]) => `
  • ${esc(o.text)} ${o.n ? `died ${died(o)} of ${o.n}` : "untested"}
  • `).join(""); return `
  • ${i + 1}
    ${esc(p.text)} - ${me.n ? `got through ${lived} of ${me.n} times` : ""}${me.kind === "fixed" && me.n ? " · always the same so far" : me.kind === "dice" ? " · a roll" : ""} + ${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." })}` : ""} ${others ? `
    Other answers here
      ${others}
    ` : ""}
  • `; }).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 @@ ${pct(r.value.x)}${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)}` : ""}`; }; const steps = focus.steps.filter((s) => s.kind === "decision" || s.kind === "chance").map((s) => { - if (s.kind === "chance") return `
  • ${esc(s.label)}${esc(String(s.taken))}roll ${pct(s.probs[s.taken])}
  • `; + if (s.kind === "chance") return `
  • ${esc(s.label)} ${Dice.html(rollOf(s))}${esc(String(s.taken))}roll ${pct(s.probs[s.taken])}
  • `; const open = st.expanded === s.var; const opts = open ? `
    ${Object.entries(s.options).sort((a, c) => c[1].pX - a[1].pX).map(([v, val]) => ``).join("")}
    ` : ""; @@ -871,6 +879,7 @@ ${st.blocked ? `

    Your choices so far can't reach a ${st.colour} dragon.

    ` : ""}
    ${routes.map(card).join("")}

    best route under half as likely under a tenth · line width: chance you are still on the route

    +

    ${Dice.legend()}

    ${esc(ENC_NAME[focus.enc])}: step by step
      ${steps}

    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? `}

    diff --git a/site/atlas/index.html b/site/atlas/index.html index fda0874..eed441e 100644 --- a/site/atlas/index.html +++ b/site/atlas/index.html @@ -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ⱼ) + -- 2.54.0