Valley map: start from any place and see every dragon's best route from there

Click a place name before choosing a dragon to see your chance of each dragon
from that point on, one coloured route per dragon, with a panel that ranks them
and links into each route kept through that place. Deep link: #valley/at/<place>.

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 19:24:27 +00:00
co-authored by Claude Opus 5.5
parent e8c177fc15
commit 68587a55f0
19 changed files with 2766 additions and 13 deletions
+173 -9
View File
@@ -59,13 +59,14 @@
/* ---------- state ---------- */
const st = {
point: null, // a place picked before any dragon: show the best way from there to every dragon
policy: null, runs: null, counts: {}, colour: null, focus: null, expanded: null, over: {},
objective: "eventually", sample: "all", traffic: false, cache: new Map(), pendingHash: null, info: null,
};
const model = () => st.policy.samples[st.sample];
function advisorFor(enc) {
const k = `${st.sample}|${st.colour}|${st.objective}|${enc}`;
if (!st.cache.has(k)) st.cache.set(k, S.advisor(model(), st.colour, st.objective, { only: [enc] }));
function advisorFor(enc, colour = st.colour) {
const k = `${st.sample}|${colour}|${st.objective}|${enc}`;
if (!st.cache.has(k)) st.cache.set(k, S.advisor(model(), colour, st.objective, { only: [enc] }));
return st.cache.get(k);
}
let encParams = null;
@@ -74,6 +75,95 @@
return encParams.p.encounter(enc);
};
/* ---------- starting from a place ---------- */
// What being at a place means: the choices (and, for the shadow, the roll) that put you there, and the step you
// face next ("at"). Choices before it that are not listed stay free, and the best play is assumed for them.
const INV = "Investigate the scream", HELPC = "Help your squadmate";
const POINTS = {
"comp:Alone": { force: { company: "Alone" }, at: "direction" },
"comp:1 Squadmate": { force: { company: "1 Squadmate" }, at: "direction" },
"comp:2 Squadmates": { force: { company: "2 Squadmates" }, at: "direction" },
"dir:West": { force: { direction: "West" }, at: "fs" },
"dir:Center": { force: { direction: "Center" }, at: "fs" },
"dir:East": { force: { direction: "East" }, at: "fs" },
scream: { force: {}, at: "scream" },
bully: { force: { scream: INV }, at: "clearing" },
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" },
"res:Squadmate's revenge": { force: { scream: INV, clearing: HELPC, fate: "Squadmate's revenge" }, at: "post" },
"res:Left bullies to the dragons": { force: { scream: INV, clearing: HELPC, fate: "Left bullies to the dragons" }, at: "post" },
"res:Tourniquet": { force: { scream: "Keep walking", wounded: "Tourniquet" }, at: "hour" },
"res:Left injured cadet": { force: { scream: "Keep walking", wounded: "Left injured cadet" }, at: "hour" },
"res:Took their weapons": { force: { scream: "Keep walking", wounded: "Took their weapons" }, at: "hour" },
"fork:West": { force: { scream: INV, clearing: HELPC, post: "West" }, at: "hour" },
"fork:Forest": { force: { scream: INV, clearing: HELPC, post: "Forest" }, at: "hour" },
"fork:East": { force: { scream: INV, clearing: HELPC, post: "East" }, at: "hour" },
hour: { force: {}, at: "hour" },
tree: { force: { hour: "Tree" }, at: "shadow" },
valley: { force: { hour: "Valley" }, at: "valley" },
stream: { force: { hour: "Tree", shadow: "yes" }, at: "shadowColour" },
meadow: { force: { hour: "Valley", valley: "Pass the Red (meadow)" }, at: "meadow" },
};
/**
* Chance of bonding the advisor's colour once you are at a place: everything before it that the place implies is
* fixed, earlier rolls are averaged over the ways of getting there, and from there on the best play is used.
* Returns null when the place cannot lead to that dragon.
*/
function valueFrom(adv, pt) {
const rec = (h, reached) => {
const s = adv.step(h);
if (s.kind === "end") return { x: 0, w: reached ? 1 : 0 };
const live = reached && s.risk ? 1 - s.risk.p : 1;
const atPoint = !reached && s.var === pt.at && Object.keys(pt.force).every((k) => h[k] != null || k === pt.at);
if (reached || atPoint) {
if (s.kind === "decision") return { x: live * Math.max(...Object.values(s.options).map((v) => v.pX)), w: 1 };
let x = 0;
for (const [b, p] of Object.entries(s.probs)) if (p) x += p * rec({ ...h, [s.var]: b }, true).x;
return { x: live * x, w: 1 };
}
const forced = pt.force[s.var];
if (s.kind === "decision") {
const o = forced != null ? forced : s.choice;
if (!s.options[o]) return { x: 0, w: 0 };
const r = rec({ ...h, [s.var]: o }, false);
return { x: r.x, w: r.w * (s.risk ? 1 - s.risk.p : 1) };
}
// a roll before the place: only branches that can still get there count
let xw = 0, w = 0;
for (const [b, p] of Object.entries(s.probs)) {
if (!p || (forced != null && b !== forced)) continue;
const r = rec({ ...h, [s.var]: b }, false);
xw += p * r.w * r.x; w += p * r.w;
}
return { x: w ? xw / w : 0, w: w * (s.risk ? 1 - s.risk.p : 1) };
};
const r = rec({}, false);
return r.w > 1e-9 ? r.x : null;
}
/** For a picked place: per colour, the encounter with the best chance from there, and its route. */
function routesFrom(id) {
const pt = POINTS[id];
return COLOURS.map((c) => {
let best = null;
// the Greens rescue only counts for Orange/Brown when their own meadow is out of reach from here
const encs = S.ENCOUNTERS[c].filter((e) => RESCUE[c] !== e || c === "Green");
for (const pass of [encs, S.ENCOUNTERS[c].filter((e) => !encs.includes(e))]) {
for (const enc of pass) {
const v = valueFrom(advisorFor(enc, c), pt);
if (v != null && v > 0 && (!best || v > best.v)) best = { enc, v };
}
if (best) break;
}
if (!best) return { colour: c, v: null };
const r = walk(best.enc, c, pt.force);
r.geo = routePoints(r);
return { colour: c, enc: best.enc, v: best.v, route: r };
}).sort((a, b) => (b.v || 0) - (a.v || 0));
}
/* ---------- walking one route ---------- */
const encColour = (enc) => (enc === "tree-Greens" ? "Green" : enc.split("-")[1]);
function defaultOutcome(s, enc) {
@@ -82,8 +172,8 @@
if (s.var === "shadowColour" || s.var === "meadow") { const c = encColour(enc); if (s.probs[c] != null) return c; }
return ent[0][0];
}
function walk(enc) {
const adv = advisorFor(enc), over = st.over[enc] || {}, steps = [], h = {};
function walk(enc, colour = st.colour, over = st.over[enc] || {}) {
const adv = advisorFor(enc, colour), steps = [], h = {};
for (let i = 0; i < 20; i++) {
const s = adv.step(h);
s.before = { ...h };
@@ -282,6 +372,17 @@
const t = el("text", { x: P.x + (pos === "right" ? 10 : pos === "left" ? -10 : 0), y: P.y + (pos === "above" ? -10 : 4), "text-anchor": pos === "right" ? "start" : pos === "left" ? "end" : "middle", "font-family": "var(--font-display)", "font-size": strong ? 14 : 13,
fill: PAPER.ink, "fill-opacity": strong ? 1 : 0.8, "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3.5, "stroke-linejoin": "round" }, g);
t.textContent = LANDMARK_NAME[id] || P.name;
// before a dragon is chosen, any place can be a starting point: "from here, how do I reach each dragon?"
if (!st.colour && POINTS[id] && st.policy) {
if (st.point === id) el("circle", { cx: P.x, cy: P.y, r: 11, fill: "none", stroke: PAPER.ink, "stroke-width": 2.5 }, g);
const hit = el("g", { class: "ex-place", tabindex: 0, role: "button", "aria-label": `${t.textContent}: show the best way from here to every dragon` }, g);
el("circle", { cx: P.x, cy: P.y, r: 14, fill: "transparent" }, hit);
hit.appendChild(t);
el("title", {}, hit).textContent = `${t.textContent}: from here to every dragon`;
const go = () => { st.point = st.point === id ? null : id; st.info = null; writeHash(); render(); };
hit.addEventListener("click", go);
hit.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); go(); } });
}
});
el("text", { x: GATE.x, y: GATE.y + 14, "text-anchor": "middle", "font-size": 11, "letter-spacing": "0.16em", fill: PAPER.ink, "font-family": "var(--font-label)", "paint-order": "stroke", stroke: PAPER.halo, "stroke-width": 3 }, g).textContent = "ENTER THE VALLEY";
}
@@ -395,6 +496,34 @@
pills.forEach((p) => { if (p.dy) p.g.setAttribute("transform", `translate(0 ${p.dy.toFixed(1)})`); });
}
/** All six dragons from one place: the way there in ink, then one line per dragon in its colour. */
function drawFrom(gRoute, gLab, list) {
const onRoute = new Set([st.point]);
const ok = list.filter((x) => x.route);
if (!ok.length) return onRoute;
const best = Math.max(1e-12, ...ok.map((x) => x.v));
// the way to the place (from the most likely dragon's route)
const lead = ok[0].route.geo.pts;
const at = lead.findIndex((p) => p.id === st.point);
for (let i = 1; i <= at; i++) {
el("path", { d: curve(lead[i - 1].P, lead[i].P, 0.08), fill: "none", stroke: PAPER.ink, "stroke-width": 4, "stroke-opacity": 0.55, "stroke-dasharray": "2 8", "stroke-linecap": "round" }, gRoute);
onRoute.add(lead[i].id);
}
[...ok].reverse().forEach((x, k) => {
const pts = x.route.geo.pts, i0 = pts.findIndex((p) => p.id === st.point);
if (i0 < 0) return;
const f0 = pts[i0].flow || 1, rel = x.v / best, off = (COLOURS.indexOf(x.colour) - 2.5) * 5;
for (let i = i0 + 1; i < pts.length; i++) {
const w = 2.5 + 12 * Math.min(1, pts[i].flow / f0);
el("path", { d: curve(pts[i - 1].P, pts[i].P, 0.08, off), fill: "none", stroke: INK[x.colour], "stroke-width": w, "stroke-opacity": 0.45 + 0.45 * rel, "stroke-linecap": "round" }, gRoute);
onRoute.add(pts[i].id);
}
const end = pts[pts.length - 1];
pill(gLab, end.P.x, end.P.y + 30, `${x.colour} ${pct(x.v)}`, { edge: INK[x.colour], strong: rel === 1 });
});
return onRoute;
}
/* ---------- tooltip ---------- */
function showTip(e, html) { const t = $("#ex-tip"); t.innerHTML = html; t.hidden = false; moveTip(e); }
function moveTip(e) {
@@ -422,12 +551,28 @@
}
return `<span class="eyebrow">Unofficial atlas · built from ${st.runs ? st.runs.length.toLocaleString() : "thousands of"} logged runs</span>
<h2 id="h-valley">The valley</h2>
<p class="small muted">Every dragon is drawn where riders meet it. The fainter it is, the fewer riders reach it. Choose one to see every way to it, and how likely each is.</p>
<p class="small muted">Every dragon is drawn where riders meet it. The fainter it is, the fewer riders reach it. Choose one to see every way to it, and how likely each is. Or click a place name on the map to see your best chance at each dragon from there.</p>
${chooser()}${info}
${trafficToggle()}
<p class="small muted">Prefer the numbers? <a href="#odds">The Odds</a> has the statistics behind the map.</p>`;
}
function panelFrom(list) {
const name = LANDMARK_NAME[st.point] || (L[st.point] && L[st.point].name) || st.point;
const top = Math.max(1e-12, ...list.map((x) => x.v || 0));
const rows = list.map((x) => x.v == null
? `<div class="ex-from-row off" style="--c: var(${DV[x.colour]})">${mini(x.colour, POSE_OF[x.colour])}<span class="nm">${x.colour}</span><small>not reachable from here</small></div>`
: `<button type="button" class="ex-from-row" data-c="${x.colour}" data-enc="${x.enc}" style="--c: var(${DV[x.colour]}); --w: ${(100 * x.v / top).toFixed(1)}%">${mini(x.colour, POSE_OF[x.colour])}
<span class="nm">${x.colour}<small>${esc(ENC_NAME[x.enc])}${RESCUE[x.colour] === x.enc && x.colour !== "Green" ? " (rescue)" : ""}</small></span><b>${pct(x.v)}</b><i></i></button>`).join("");
return `<div class="ex-head"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="5" fill="var(--accent)"/><circle cx="12" cy="12" r="10" fill="none" stroke="var(--accent)" stroke-width="2"/></svg>
<div><span class="eyebrow">Starting from</span><h2 id="h-valley">${esc(name)}</h2></div>
<button type="button" class="ex-close" id="ex-clear-point" aria-label="Back to the whole valley">×</button></div>
<p class="small muted">If you are here, this is your best chance of bonding each dragon from here on, playing the best route after this point. Earlier rolls are averaged over the ways of getting here. Pick a dragon to follow its route step by step.</p>
<div class="ex-from">${rows}</div>
<div class="seg" role="group" aria-label="Goal"><button type="button" data-o="eventually" aria-pressed="${st.objective === "eventually"}">Only this dragon</button><button type="button" data-o="thisAttempt" aria-pressed="${st.objective === "thisAttempt"}">Best odds this run</button></div>
${trafficToggle()}`;
}
function panelRoutes(routes) {
const best = Math.max(1e-12, ...routes.map((r) => r.value.x));
const T = model().targets[st.colour], b = T[st.objective];
@@ -479,12 +624,20 @@
$$("[data-s]", p).forEach((b) => b.addEventListener("click", () => { st.sample = b.dataset.s; render(); }));
const tr = $("#ex-traffic", p); if (tr) tr.addEventListener("change", () => { st.traffic = tr.checked; render(); });
const cl = $("#ex-clear", p); if (cl) cl.addEventListener("click", () => select(null));
const cp = $("#ex-clear-point", p); if (cp) cp.addEventListener("click", () => { st.point = null; writeHash(); render(); });
$$(".ex-from-row[data-c]", p).forEach((b) => b.addEventListener("click", () => {
// follow that dragon's route, keeping this place on it
const enc = b.dataset.enc;
st.over[enc] = { ...POINTS[st.point].force };
select(b.dataset.c, enc);
}));
const rr = $("#ex-reset-route", p); if (rr) rr.addEventListener("click", () => { delete st.over[st.focus]; st.expanded = null; render(); });
}
/* ---------- actions ---------- */
function select(colour, enc) {
st.colour = colour; st.info = null; st.expanded = null;
if (colour) st.point = null;
st.focus = colour ? enc || null : null;
writeHash();
render();
@@ -502,12 +655,18 @@
}
function writeHash() {
if (!$("#panel-valley") || $("#panel-valley").hidden) return;
const h = "#valley" + (st.colour ? "/" + st.colour.toLowerCase() + (st.focus ? "/" + st.focus : "") : "");
const h = "#valley" + (st.colour ? "/" + st.colour.toLowerCase() + (st.focus ? "/" + st.focus : "")
: st.point ? "/at/" + encodeURIComponent(st.point) : "");
try { history.replaceState(null, "", h); } catch (e) { /* ignore */ }
}
function fromHash() {
const parts = (location.hash || "").replace(/^#/, "").split("/");
if (parts[0] !== "valley") return;
if (parts[1] === "at") {
const id = decodeURIComponent(parts.slice(2).join("/"));
if (POINTS[id]) { st.colour = null; st.focus = null; st.point = id; if (st.policy) render(); }
return;
}
const c = parts[1] ? COLOURS.find((x) => x.toLowerCase() === parts[1].toLowerCase()) : null;
const enc = parts[2] && c && S.ENCOUNTERS[c].includes(parts[2]) ? parts[2] : null;
// plain "#valley" (e.g. the tab itself) keeps whatever the reader was looking at
@@ -541,6 +700,11 @@
pills = [];
onRoute = drawRoutes(gRoute, gLab, routes);
spreadPills();
} else if (st.point && st.policy && POINTS[st.point]) {
pills = [];
st.fromList = routesFrom(st.point);
onRoute = drawFrom(gRoute, gLab, st.fromList);
spreadPills();
}
drawLandmarks(gLand, onRoute);
drawScenery(gScene, onRoute);
@@ -549,10 +713,10 @@
const fin = document.createElementNS(NS, "svg");
V.finish(fin);
svg.insertAdjacentHTML("beforeend", fin.innerHTML.replace(/vm-/g, "ex-"));
$("#ex-hint").hidden = !!st.colour || !st.policy;
$("#ex-hint").hidden = !!st.colour || !!st.point || !st.policy;
$("#ex-shell").style.setProperty("--vt", st.colour ? `var(${DV[st.colour]})` : "var(--accent)");
// the panel scrolls inside the map's height on wide screens (see .ex-scroll)
$("#ex-panel").innerHTML = `<div class="ex-scroll">${st.colour && st.policy ? panelRoutes(routes) : panelIdle()}</div>`;
$("#ex-panel").innerHTML = `<div class="ex-scroll">${st.colour && st.policy ? panelRoutes(routes) : st.point && st.fromList ? panelFrom(st.fromList) : panelIdle()}</div>`;
bindPanel();
writeHash();
// on narrow screens the map scrolls sideways: start centred rather than at the far west