## bin+lib rfyl

A dice roller accepting dice notation

### 5 unstable releases

Uses old Rust 2015

 0.3.1 Jun 15, 2019 Mar 4, 2018 Aug 12, 2017 Aug 11, 2017 Aug 11, 2017

#321 in Games

26KB
500 lines

# rfyl - An RPG dice roller.

A dice roller accepting dice notation written in Rust. Not maintained.

## 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`.

rfyl is Public Domain software available under the Creative Commons 0. See LICENSE and COPYING for more information.

### `lib.rs`:

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.

~1MB
~20K SLoC