RFYL implements the common dice notation used in many role playing game systems.
Supported input
- Basic standard dice notation:
d8,2d12. - Addition:
d4 + 2d6. - Subtraction:
d100 - 15. - Multiplication:
d12 * 2. - Division:
d100 / 15. (Note that fractional values are rounded to the nearest integer.) - Brackets:
(d100 + d12) / 15. - Complex dice notation:
1d4 + 2d6 * 3d2 / 4d8 + (2d6 + 3d8) - 16 * (1 / 1d4). - Percentile dice shorthand:
d%=d100. - Boolean dice:
1d1=0or1.
Example
use roll;
// This would actually probably come from user input, or be computed in some other way.
let requested_roll = Stringfrom;
// Rolling can fail, for instance if an illegal digit is supplied.
// Therefore, roll() returns a Result which must be unwrapped.
let roll = roll.unwrap;
// On a successful roll, roll() returns a DiceRolls struct which can be
// interrogated for its formula and result.
println!;
// Should print "[[1d20 * 2] + [[1d4 + 1] * 2]]: 10" (for arbitrary values of 10).
See the included command line program (src/bin.rs) for further examples of how to use the DiceRolls struct.