本文へ移動

Korokoroコロコロ

ダイスを組み合わせて振り、ダイス表記を読み取り、正確な確率を調べます。履歴の保存やシードを指定した再現もできます。

「コロコロ」は、小さなものが転がる様子を表す言葉です。 名前について(英語)

目次

リファレンス

ロールと正確な確率

import { … } from "@johnmorrisdotca/korokoro";

最小化と gzip 圧縮をしたサイズは 101.0 kB(読み込むものをすべて含み、esbuild で計測)

リファレンスの説明と例は英語です。見出しと目次は日本語です。

Korokoro コロコロ: fair dice, exact odds, and a history that remembers.

The core is plain functions over plain data, with no dependency and no DOM: roll, read the odds, keep a history and summarise it. The tap-to-roll tray is mountRoller in ./ui/mount.ts, exported here too.

エクスポート

名前種類概要
addToHistory関数Add a roll to the end, oldest dropped past the limit.
asChance関数A fraction as a number, for showing.
canHold関数Whether some dice of a roll can be held while the rest are thrown again: plain dice only, none rerolled, exploding, kept or dropped, counted, raised, lowered or sorted.
chanceAnyAtLeast関数The chance that at least one of several throws of a roll reaches a target: a set of six ability scores holding at least one 16, say.
chanceAtLeast関数The chance of this total or more: "what do I need to beat a DC of 15".
chanceAtMost関数The chance of this total or less.
chanceExactly関数The chance of exactly this total.
chancesOf関数The chance of each face of one die of a group, from its lowest face up.
checkMath関数Whether a formula can be used with kinds of dice whose totals run over these ranges: the problem, or null when there is none.
checkNotation関数A spec from notation, or which part of the text was refused and why.
chinchirorinHandWithin関数The chance that three dice make a chinchirorin hand within a number of throws: each throw makes one half the time, so three come to 7 in 8.
chiSquareTail関数The upper tail of a chi-square distribution: the chance that a fair die strays at least this far.
cliLanguage関数The language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else.
CliResult型What the command line came to.
CliSurroundings型What the command line is run in.
Cloth型A cloth's name.
clothVars関数A cloth as the tray's CSS variables; nothing for a name that is not a cloth, so the tray keeps its own.
Compare型A number a die is compared with: at a face (=), at or below it (<=), at or above it (>=), or anything but it (<>).
compareText関数A comparison as notation writes it: >=8, =1, <>3.
countsSuccesses関数Whether a kind of dice is counted for successes, not added up.
crapsPass関数The chance that a craps shooter passes: a natural on the come-out, or a point that comes again before a seven.
createRollSound関数The tray's sound for one window.
cryptoSource関数The platform's cryptographic generator, buffered so a roll of ten dice is one call.
CSV_COLUMNS定数The columns of the CSV export, in order.
csvCell関数One cell of CSV.
CustomFace型One face of a custom die: what it says, what it is worth in a total if it is worth anything, and a colour for it.
customFaces関数A custom die's faces, checked: the faces as given if every one is sound, or undefined.
decodeDiceWar関数Text read back into the game it records, every move played again through the rules, so that what comes back is exactly the game those moves make.
DEFAULT_SPEC定数The dice a tray shows when nothing else is asked for: 2d6.
DICE_WAR_LIMITS定数What a table may be set up with.
diceCount関数How many dice a roll asks for, over all its kinds.
DiceGroup型Some dice of one kind, with their own rules: the 2d20kh1 of 2d20kh1+1d4.
diceOf関数The dice of a roll: as recorded, or worked out from its faces for a roll made by hand or by an older version.
DiceSet型A set of dice with a name: a roll somebody wants to find again, such as "Longsword" for 1d8+3 or "Skirmish" for 2d[Hit=1,Miss=0,Miss=0].
diceText関数The dice of a roll as plain text, in the order thrown: 6 4 2 (1).
DiceWarChances型What a total is worth against the other players' totals in one throw.
diceWarComputerFaces関数A computer's dice for a throw: from the game's seed, the round, the war and the seat, so the same game always rolls the same.
DiceWarGame型A game of Dice War: its table, seed and moves (what is kept), and what they make.
DiceWarGoal型How a game is played to its end.
DiceWarMove型A move: the dice the people at the table rolled, by seat, such as { faces: { "0": [4] } }.
diceWarOdds関数The exact odds of one throw of Dice War among players players, from the package's own odds for the dice: the chance the throw is settled at once and the chance of war, and, for a total you name, how it fares against everybody else's.
DiceWarOptions型What a game of Dice War is set up with.
diceWarOver関数Whether a game is over.
diceWarPeopleToRoll関数The seats whose dice a move must hand in now: the people among those who roll.
DiceWarRoll型One player's roll in a throw: their faces, and what they add up to.
diceWarSpec関数The dice a game rolls, as a spec the rest of the package reads.
DiceWarThrow型One throw of the table: everybody who had to roll, in seat order, the war it was in (0 for the round's first throw), the seats that tied for highest, and who took the stake: null where the throw was a tie and the war goes on, or the round was called off.
diceWarWinners関数The seats that won a game that is over: the player who reached the score, or the most points when the rounds ran out, shared where level.
DIE_SIDES定数The dice the tray offers as buttons: the polyhedral set, the thirty-sided die, and the percentile die.
DIE_SIZE_PX定数The pixels of each size.
DieHandle型What mountDie hands back.
dieName関数What one kind of die is called: d6, dF, a loaded d6{6:3}, a custom d[Yes,No,Maybe].
DieOptions型What a lone die is told when it is made.
dieOutcomes関数One die of a kind worked through its own rules, before any keeping or dropping: the chance of each amount it adds to the total, from least up.
DieRoll型One die of a roll: the face it showed and what became of it.
DieSides型One of the dice the tray has a button for.
DieSize型How big the die is drawn: 48, 96 or 150 pixels across.
DieStatus型One die as it was thrown.
Distribution型Exact odds for a spec, worked out rather than simulated: every total the dice can make and how likely it is.
distributionHolding関数The odds of a roll with some of its dice held: the held faces are settled, and only the rest are still to be thrown.
distributionOf関数Every total a spec can make and its chance.
encodeDiceWar関数A game of Dice War as text: its table, its seed and its moves, which is all there is to keep.
evaluateMath関数What a formula comes to, given each kind's total.
exactCounts関数The odds as exact whole numbers, for the dice that have them: plain dice added up, one die kept from a pool (advantage), loaded and custom dice the same way (their weights are whole numbers, so their odds are exact fractions), and several such kinds added together while that stays quick.
ExactCounts型The odds as whole numbers: how many of the equally likely outcomes make each total.
expectedHighest関数The average of the highest total among several throws of a roll.
expectedTotal関数The average total over many rolls.
ExplodeKind型How exploding dice are added up: each as a die of its own, all into the die that threw them (!!), or with one taken off each extra die (!p), or both (!!p).
EXPORT_FORMAT定数The shape of the JSON this package writes.
Exported型A whole JSON export.
exportedRoll関数One roll as the JSON export writes it.
ExportedRoll型One roll as the JSON export writes it.
FaceChance型One face of a die and how often it comes up, beside how often it would on a fair one.
faceChances関数Every face of one die of a group with its chance, beside the fair die's.
faceRange関数The lowest and highest face of one die.
faceStats関数How often each face of one kind of die came up in a history, with a chi-square test of whether that looks fair.
FaceStats型How often each face of one kind of die came up, and whether that looks fair.
Fairness型What a fairness test makes of a die.
FAIRNESS_MINIMUM_EACH定数The fewest throws of each face a fairness test wants before it will say anything: the usual rule for a chi-square.
fairnessTest関数Is this die fair?
findPresets関数The presets a search finds: every word typed has to be in the name, another name, the one-line description or the notation.
formatNotation関数Notation for a spec: the inverse of parseNotation.
formulaText関数A formula's roll with each kind of dice written as it fell: ([6 1]+3)*2-[3].
fromJSON関数Rolls from JSON that toJSON wrote, or a history that serializeHistory did.
GameFamily型The shelves the games are kept on.
getPreset関数A preset by its id, its name or any of its other names: getPreset("yahtzee") and getPreset("Yacht") are the same game.
groupOf関数The kind of dice one die of a roll belongs to, with its rules, faces and weights.
groupRange関数The least and the most one kind of dice can total, its own rules applied.
groupsOf関数The kinds of dice in a roll, in order: the spec's own first, then the rest.
groupTotals関数What each kind of dice of a roll came to, in order: what a formula puts together.
hasTotal関数Whether a roll's total says anything.
HISTORY_LIMIT定数A history keeps the latest rolls and forgets the oldest past this many.
isCloth関数Whether a text names a cloth.
isDieSides関数One of the dice the tray has a button for.
isFair関数Whether a roll is of plain fair dice and nothing else: no loaded die, and no custom die either, whose faces are whatever somebody made them.
isLoaded関数Whether a roll has a loaded die in it.
isPlainDice関数Whether a kind of dice is plain enough to be rolled in any number: a fair numbered or Fate die, all added or one kept, under no other rule.
isSides関数Any die this package can throw: two to a thousand sides, or a Fate die.
isSuccessRoll関数Whether the first thing a roll says is a number of successes: every kind of dice in it is counted.
Keep型Which dice count towards the total.
keptCount関数How many dice of one group count towards the total.
keptFaces関数Which faces count towards the total when one is kept.
KOROKORO_CLOTHS定数THE CLOTHS A TRAY MAY BE LAID IN: the same five the whole family offers, and itsutsu.com's boards — green (the tray's own, unless said), blue, red, black, and wood.
LOADED_PRESETS定数Three loaded dice to try, each an old trick with a long record.
LoadedPreset型Loaded dice, kept in one place and in plain sight.
loadedWeights関数A loaded die's weights, checked and in lowest terms: one whole number from 0 to MAX_WEIGHT for each face, at least two faces that can come up.
loadHistory関数Read a kept history.
loadingOf関数What a loaded die's loading comes to, as exact fractions, for the face it favours most: { face: 6, loaded: [3, 8], fair: [1, 6] } is "6 comes up 3 in 8, not 1 in 6".
loadSets関数The sets kept on a device.
luckOf関数How lucky a total was, from 0 (the worst the dice can do) to 1 (the best): the share of rolls it beats, counting a tie as half.
makeSet関数A set from a name and a roll, or null when the name is empty or too long or the dice cannot be rolled.
MathFunction型The functions a formula may call.
mathGroups関数Which kinds of dice a formula uses, in the order it names them.
MathNode型Arithmetic over the kinds of dice in a roll: (2d6+3)*2, 1d20-1d4, floor(4d6/2), max(1d6,1d8).
MathProblem型Why a formula cannot be used, when it cannot.
mathRange関数The least and the most a sound formula can come to, given each kind's range.
mathText関数A formula as notation writes it, with brackets only where they are needed.
MAX_DICE定数The most dice in one roll: a fireball's 8d6, Farkle's six and a pool of ten all fit.
MAX_DICE_BY_CODE定数The most dice in one roll made from code, for a caller that asks: parseNotation(text, { maxDice }), normalizeSpec(spec, { maxDice }) and roll(spec, source, { maxDice }) each take a roll past MAX_DICE up to this.
MAX_EXPLODING_SIDES定数The largest die that may explode: past this the exact odds stop being quick to count.
MAX_EXPLOSIONS定数How many more dice one exploding die may throw.
MAX_FACE_VALUE定数The largest number a custom face may be worth, either way.
MAX_FACES定数The most faces a custom die has, and the fewest is two.
MAX_GROUPS定数The most kinds of dice in one roll: 1d20+1d4 is two.
MAX_LABEL定数The longest a custom face's words may be, in characters.
MAX_LOADED_SIDES定数The largest die that may be loaded.
MAX_MATH_AMOUNT定数The largest amount, either way, any step of a formula may come to.
MAX_MATH_DIVISOR定数The largest bottom of a fraction any step may have: what it may be divided by, all told.
MAX_MATH_NODES定数The most steps a formula may have.
MAX_MATH_NUMBER定数The largest whole number written in a formula.
MAX_MATH_PAIRS定数The most pairs of amounts any one step of a formula's odds may have to put together.
MAX_MATH_TOTALS定数The widest span of totals a formula may have.
MAX_MODIFIER定数The largest bonus, either way: a roll adds or takes away at most this.
MAX_REROLLS定数How many times one die is thrown again by a reroll-until (r<).
MAX_ROLL_LABEL定数The longest a roll's label may be, in characters.
MAX_SET_NAME定数The longest a set's name may be, in characters.
MAX_SETS定数The most sets kept on one device.
MAX_SIDES定数The most sides a numbered die has.
MAX_TIMES定数The most times one roll may be repeated as a set: 6#4d6dl1 is six.
MAX_UNIQUE_SIDES定数The largest die whose dice may be asked to all differ (u).
MAX_WEIGHT定数The heaviest a face of a loaded die may be weighted.
mayExplode関数Whether the dice may explode: numbered dice of a hundred sides or fewer, all of them kept.
mayReroll関数Whether a reroll at this face leaves something to do: it must reroll the lowest face and spare the highest.
mayRerollUntil関数Whether a die may be rerolled until it clears this face: the reroll must match the lowest face and no more than half of them.
meets関数Whether a number meets a comparison.
MIN_DICE定数The fewest dice in one roll.
MIN_SIDES定数The fewest sides a numbered die has: a coin.
mostLikely関数The most likely totals: several when the peak is flat, as it is for one die.
mountDie関数Put one die in an element.
mountRoller関数Put a dice tray into an element.
newSeed関数A short seed anybody can read aloud or type: eight letters and digits.
normalizeSpec関数A spec brought into range, so a hand-typed or stored one can never roll eleven dice, five kinds or a die with no faces.
NotationCheck型What checkNotation found: the spec, or the part it refused and why.
NotationOptions型How to read a notation.
NotationProblem型Dice notation, the way a character sheet writes it.
Outcome型How a roll is read in a game.
OutcomeOdds型One line of a game's odds: an outcome, the words for it, and its chance as a whole-number count of the equally likely throws.
parseHistory関数A kept history read back from its text.
parseNotation関数A spec from notation, or null when the text is not dice this roller can throw.
parseSets関数Sets read back from their text.
patternsOf関数Every way the dice of a spec can fall, kind by kind, each with how many of the equally likely throws fall that way.
playDiceWar関数The game after this move, or null for one the rules refuse: the game is over, a person's dice are missing or are not dice of this game, or dice are handed in for a seat that does not roll them.
playsByNewRules関数Whether a kind of dice is played by a rule added in 1.7.0, one that changes what it can total: a reroll or an explosion at a comparison, compounding or penetrating dice, min or max, or counted successes.
PlaySound型Anything that makes a roll's sound: the built-in one, or a page's own.
Preset型The dice for a game, and how the game reads them.
presetOdds関数The exact odds of each outcome of a game's first roll: a natural in craps, each hand in chinchirorin, each result of a Risk battle.
PresetReading型What a game makes of a roll: the outcome, and the words for it.
PresetRoll型A game's dice thrown and read.
presets定数Game presets with their dice, readings and English/Japanese help.
PRESETS定数Game presets with their dice, readings and English/Japanese help.
presetSpec関数A preset's dice, as a spec.
randomInt関数A fair integer in [0, n).
RandomSource型Where the randomness comes from.
rangeOf関数The lowest and highest totals a spec can produce.
readDice関数What happened to each die of a roll, from its faces alone: which were rerolled, which exploded, which were dropped.
readDiceAs関数Read a roll the way a reading does, with the rolls before it in the same game where that matters.
READING_WORDS定数English and Japanese outcome text, keyed by reading.outcome.
ReadingId型The name of a reading.
readPreset関数Read a roll the way a game does.
readResults関数Results typed or pasted from a real die, such as 3 5 6 6 1 or 3,5,6: whole numbers separated by spaces, commas or new lines.
readSet関数A set from a link's query, or null when it holds none or its dice cannot be rolled.
readShared関数A shared roll from a query string, or null when it does not describe one this roller could have thrown.
readSharedMany関数A shared set of rolls from a query string, or null when it does not hold one: as many rolls as the notation's # says, each with faces its dice could show.
resultText関数A roll's result as it would be said: its total, or for dice that are only words, the words.
roll関数Throw the dice.
Roll型One throw of the dice: what was asked for, every die thrown, and the total.
RollerHandle型What mountRoller hands back: the tray, driven from code.
RollerOptions型Everything a tray can be told when it is mounted.
RollerSize型How much of the tray is drawn: the felt alone, the felt and the choice of dice, or all of it.
RollerStrings型Every word the tray says, in English and Japanese.
rollFrom関数A roll put back together from its spec and its faces: for a history read from storage and a roll read from a link.
rollHeld関数Hold some dice of a roll and throw the rest again, as Yacht and Farkle do.
rollLabel関数A roll's label, checked: a few words with no control characters and nothing notation is written with, or undefined.
rollMany関数Throw the same dice several times in one go, as ability scores are rolled: 4d6dl1 six times.
RollOptions型What roll and rollMany may be told beside the dice and the source.
rollPreset関数Throw a game's dice and read them.
RollSet型The same roll thrown several times in one go, with what the set comes to.
RollSound型The tray's own sound: play for each throw, close when the tray goes.
RollSpec型What to roll: the dice, the bonus, and the rules.
rollText関数One roll on one line: 2d20kh1+5: 22 [17 (4)], or for a formula (2d6+3)*2: 20 ([6 1]+3)*2.
rulesText関数The modifiers of one kind of dice as notation writes them, in the one order they are written: >=8f=1!, r<3kh3.
runCli関数Run the command line.
saveHistory関数Keep a history.
seededSource関数sfc32 started from a text seed: the same seed gives the same rolls on every platform, forever.
serializeHistory関数A history as text, to keep in a browser's storage or anywhere else.
serializeSets関数Sets as text, to keep in storage.
setOf関数What a set of rolls comes to: their sum, the highest and the lowest.
setQuery関数A set as a link's query: the dice and the name, for anybody to open and keep.
SHARE_VERSION定数The version of the notation a link is written in.
shareQuery関数A roll as a link.
shareQueryMany関数A set of rolls as a link: the notation with its 6#, and every roll's faces, the rolls parted by semicolons.
Sides型A die of any size from a coin to a d1000, or a Fate die, whose faces are −1, 0 and +1.
sidesOf関数The kind of die one die of a roll is.
soundMath関数A formula given by hand, checked for its shape alone: the nodes are what they say they are.
SoundThrow型The sound of a roll: a shake while the dice tumble and a knock as each one lands.
specOf関数A spec from its kinds of dice and a bonus, brought into range.
spreadMath関数The odds of a formula: the chance of each whole number it can come to, given the chance of each total of each kind of dice.
spreadOf関数How far a typical roll lands from the average.
startDiceWar関数A new game, or null for a table it is not played at: fewer than two or more than eight players, dice or sides out of range, a goal out of range.
Stats型Everything worth saying about a history of rolls.
statsOf関数Stats for a history, oldest roll first.
StorageLike型The storage a browser offers, or anything shaped like it.
storeSets関数Keep the sets.
STRINGS定数The built-in words, in English and Japanese.
toCSV関数Rolls as CSV for a spreadsheet: a header, then a row for each roll, lines ended CRLF as RFC 4180 has them.
toJSON関数Rolls as JSON, two spaces deep, with the format's number first.
totalOf関数The kept faces added up, plus the bonus.
totalStats関数The totals of every roll of one spec in a history, beside what the odds expect.
TotalStats型The totals of one spec: seen against what the odds promise.
toText関数Rolls as plain text, one to a line, each with its time in UTC, oldest first as given.
TypedResults型What readResults found in somebody's typed results.
valueOfFace関数What a face of a group's die is worth in a total: its number, or for a custom face its value, which is 0 when it is only words.
VERSION定数The version of this package, as package.json has it.
waysToShut関数Every way to make a total from different numbers 1 to 9, largest first: the tiles a Shut the Box roll may shut.
withoutSet関数The sets without the one of that name.
withSet関数The sets with one added, newest first.
yahtzeeWithin関数The chance of a Yahtzee (five dice alike) within a number of rolls, holding the largest group each time: 1 roll is 1 in 1296, and the usual three come to 347897 in 7558272, about 4.6%.

ソースを見るGitHub で編集@johnmorrisdotca/korokoro 1.16.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。