Skip to the content

Korokoroコロコロ

Roll mixed dice or type notation, compare exact probabilities, keep a history and replay seeded rolls.

Korokoro describes something small rolling in Japanese. About the name

Contents

Reference · Rolls and exact odds

Rolltype

One throw of the dice: what was asked for, every die thrown, and the total.

Import it

import type { Roll } from "@johnmorrisdotca/korokoro";

Definition

type Roll = {
    id: string;
    spec: RollSpec;
    faces: number[];
    kept: boolean[];
    total: number;
    at: number;
    seed: string | null;
    dice?: DieRoll[];
    held?: boolean[];
    loaded?: true;
    set?: {
        id: string;
        index: number;
        of: number;
    };
};

Members

NameTypeDescription
idstring

Unique within one history.

specRollSpec
facesnumber[]

Every die's face, in the order thrown: rerolled dice and the dice an explosion added are among them.

keptboolean[]

Which faces count: all of them unless some are dropped or rerolled.

totalnumber

The kept faces added up, plus the bonus.

atnumber

Epoch milliseconds.

seedstring | null

The seed this roll came from, when it is reproducible.

dice (optional)DieRoll[] | undefined

What happened to each die, one entry per face. Every roll this package makes has it; diceOf reads it or works it out.

held (optional)boolean[] | undefined

On a roll that held some dice from the roll before: which faces were held and not thrown again. Left out of an ordinary roll.

loaded (optional)true | undefined

True on a roll of loaded dice, and left out of every other: a loaded roll always says so.

set (optional){ id: string; index: number; of: number; } | undefined

On a roll thrown as one of a set: which set, which roll of it from 0, and how many there are. Left out of a roll thrown on its own.

Examples

import type { Roll } from "@johnmorrisdotca/korokoro";
import { DEFAULT_SPEC, rollFrom } from "@johnmorrisdotca/korokoro";
const value: Roll = rollFrom(DEFAULT_SPEC, [2, 5], "saved", 0, null)!;
console.log(value.total);
7

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/korokoro 1.16.0.