// Verteilung der Probekampf-Ergebnisse (Simulator-Chunk): eigene Restkampfkraft in 10-%-Klassen, // Siege in Moos, Niederlagen in Siegelrot, im Stil der Seekarte (Tintenachse, feine Raster). import { useId } from "react"; import type { SimStats } from "../lib/sim.ts"; const BINS = 10; const W = 300; const H = 110; const PAD = { l: 22, r: 6, t: 8, b: 22 }; export function SimHistogram({ stats }: { stats: SimStats }) { const hatch = `sim-hatch-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`; const wins = new Array(BINS).fill(0); const losses = new Array(BINS).fill(0); for (const r of stats.runsDetail) { const i = Math.min(BINS - 1, Math.max(0, Math.floor(r.remaining * BINS))); if (r.won) wins[i]++; else losses[i]++; } const max = Math.max(1, ...wins.map((w, i) => w + losses[i])); const iw = W - PAD.l - PAD.r; const ih = H - PAD.t - PAD.b; const bw = iw / BINS; const y = (n: number) => PAD.t + ih - (n / max) * ih; const avg = stats.runsDetail.reduce((s, r) => s + r.remaining, 0) / Math.max(1, stats.runsDetail.length); return (
Verteilung über {stats.runs} Durchläufe · eigene Restkampfkraft
{[0.5, 1].map((f) => ( {Math.round(max * f)} ))} {wins.map((w, i) => { const x = PAD.l + i * bw + 1.5; const l = losses[i]; return ( {l > 0 && } {w > 0 && } ); })} {[0, 50, 100].map((t) => ( {t} % ))}
Sieg Niederlage gestrichelt: Ø {Math.round(avg * 100)} %
); }