[][src]Crate rfyl

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 = 0 or 1.

Example

use rfyl::roll;
 
// This would actually probably come from user input, or be computed in some other way.
let requested_roll = String::from("(1d20 * 2) + (1d4 + 1) / 2");
 
// Rolling can fail, for instance if an illegal digit is supplied.
// Therefore, roll() returns a Result which must be unwrapped.
let roll = roll(requested_roll).unwrap();
 
// On a successful roll, roll() returns a DiceRolls struct which can be
// interrogated for its formula and result.
println!("{}: {}", roll.get_rolls_formula_string_as_infix(), roll.get_result());
// 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.

Modules

infix

Provides facilities for parsing input into infix notation.

rpn

Provides facilities for parsing and solving reverse Polish notation dice specifications.

Structs

DiceRolls

The result of rolling some dice.

Functions

roll

Returns a DiceRolls object based on the provided formula.