dice 1.0.0
Dice notation parsing and resolving
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
dice
Parse and roll dice notation strings in D. It aspires to support everything that Roll20 does (eventually).
Installation
Add the dependency via the usual way with DUB.
The short version is: add dependency "dice" version="~>1.0.0"
to your project's dub.sdl
or "dependences": { "dice": "~>1.0.0" }
to your project's dub.json
(depending on which one you have).
Usage
The package has two public functions:
roll(input) > float
Parse a dice notation string and roll it. The notation supports:
 Dice rolling
roll("1d20"); // Rolls a twentysided die
roll("3d6"); // Rolls 3 sixsided dice
roll("4dF"); // Rolls 4 FATE/FUDGE dice
 Arithmetic (addition, subtraction, division, and multiplication)
roll("(3*2)9/3"); // Performs basic math
roll("1d20+83"); // Performs math after resolving die roll
 Dropping and keeping
roll("6d6d3"); // Drops the lowest 3 rolls
roll("6d6dl3"); // Same as the preceding roll
roll("6d6k3"); // Keeps the 3 highest rolls
roll("6d6kh3"); // Same as the preceding roll
roll("6d6kl3"); // Keeps the 3 lowest rolls
roll("{3d6,3d6}k1"); // Rolls two groups of 3 sixsided dice and keeps the highest group
 Exploding dice (rolling the maximum on a die causes another roll)
roll("3d6!"); // If any of the 3 d6 rolls result in a 6, roll another one
 Math functions
roll("ceil(100/75)d6"); // Rounds up to the nearest integer (2) and rolls that many d6 dice
roll("floor(1/2)"); // Rounds down to the nearest integer (0)
roll("round(1/2)"); // Rounds down if less than 0.5 and up if 0.5 or more
roll("abs(1d6100)"); // Returns the absolute value of the result
 Success/Failure count
roll("4d6>3"); // Number of dice rolled that were greater than 3
roll("4d6f<3"); // Number of dice rolled that were less than 3
roll("4d6>3f>5"); // Number of dice rolled that were greater than 3 but less than 6
roll("3d20=11"); // Number of dice rolled that were equal to 11
roll("3d20f=19"); // Number of dice rolled that were not equal to 19
Order of Operations
Parts of the notation are solved in the following order:
 Math functions (
ceil
,floor
,round
,abs
)  Notation inside parentheses (
(2+2)d6
)  Multiplication and division (
100*2/10
)  Addition and subtraction (
100+1020
)  Grouped dice (
{2d6,2d6}
)  Success/failure checks (
4d6>2
)  FATE dice (
4dF
)  Drop/keep dice (
6d6k3
)  Exploding dice (
4d6!
)  Regular dice (
1d20
)
rollDie(sides) > int
Rolls a die with a number of sides and returns the result
rollDie(20); // Rolls a twentysided die
rollDie(6); // Rolls a sixsided die
 1.0.0 released 5 years ago
 hellowelcome/dice
 github.com/evanwalsh/dice
 AGPL3.0
 Authors:
 Dependencies:
 pegged
 Versions:

1.0.0 2019Feb12 ~master 2019Feb13  Download Stats:


0 downloads today

0 downloads this week

0 downloads this month

13 downloads total

 Score:
 1.6
 Short URL:
 dice.dub.pm