destiny

Crates.iodestiny
lib.rsdestiny
version0.2.1
sourcesrc
created_at2019-09-24 13:52:54.438631
updated_at2019-09-24 18:54:47.066921
descriptionA library for rolling dice and calculating dice distributions.
homepage
repositoryhttps://github.com/MarcChesebro/destiny
max_upload_size
id167288
size18,606
Marc Chesebro (MarcChesebro)

documentation

README

destiny

A simple library for parsing and evaluating dice strings for use in tabletop gaming.

Examples

Roll some dice using destiny::parse_dice_string:

use destiny::parse_dice_string;

println!("{}", parse_dice_string("1d4"));
println!("{}", parse_dice_string("1d6"));
println!("{}", parse_dice_string("2d6"));
println!("{}", parse_dice_string("1d8 + 3"));
println!("{}", parse_dice_string("1d6 + 2d8"));

Calculate distributions using destiny::DiceDistribution:

use destiny::DiceDistribution;

let dd = DiceDistribution::new("2d6");
dd.ptable();

/* this will output:
+------+--------+--------+---------+--------+
| Roll | #Rolls | Roll%  | Roll>=% | Roll<% |
+======+========+========+=========+========+
| 2    | 1      | 2.78%  | 100.00% | 0.00%  |
+------+--------+--------+---------+--------+
| 3    | 2      | 5.56%  | 97.22%  | 2.78%  |
+------+--------+--------+---------+--------+
| 4    | 3      | 8.33%  | 91.67%  | 8.33%  |
+------+--------+--------+---------+--------+
| 5    | 4      | 11.11% | 83.33%  | 16.67% |
+------+--------+--------+---------+--------+
| 6    | 5      | 13.89% | 72.22%  | 27.78% |
+------+--------+--------+---------+--------+
| 7    | 6      | 16.67% | 58.33%  | 41.67% |
+------+--------+--------+---------+--------+
| 8    | 5      | 13.89% | 41.67%  | 58.33% |
+------+--------+--------+---------+--------+
| 9    | 4      | 11.11% | 27.78%  | 72.22% |
+------+--------+--------+---------+--------+
| 10   | 3      | 8.33%  | 16.67%  | 83.33% |
+------+--------+--------+---------+--------+
| 11   | 2      | 5.56%  | 8.33%   | 91.67% |
+------+--------+--------+---------+--------+
| 12   | 1      | 2.78%  | 2.78%   | 97.22% |
+------+--------+--------+---------+--------+
*/
Commit count: 26

cargo fmt