feat: seedable dice core with pools

This commit is contained in:
2026-07-20 13:49:54 +01:00
parent 1861f4512f
commit cf028e9a08
2 changed files with 44 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
export function expandDice(diceSpecs) {
const out = [];
for (const d of diceSpecs) {
const count = d.count ?? 1;
for (let i = 0; i < count; i++) out.push({ sides: d.sides });
}
return out;
}
export function rollDie(sides, rng) {
return Math.floor(rng() * sides) + 1;
}
export function rollPool(diceSpecs, rng) {
const results = expandDice(diceSpecs).map((d) => ({ sides: d.sides, value: rollDie(d.sides, rng) }));
const total = results.reduce((s, r) => s + r.value, 0);
return { results, total };
}