リファレンス
ロールと正確な確率
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%. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。