/rustdice

Simple tabletop dice implementation in Rust

Primary LanguageRust

Rustdice

Rustdice is a simple and flexible dice implementation to simulate tabletop dicewhich accept, parse, and roll for any standard string indicating quanity, die, and modifier.

In the simplest case simply call the Dice.roll with:

 let dice = Rustdice::new("3d6+1");
 let result = dice.roll();

Options

A number of options are supported to allow common use cases supported by different game systems using the DiceSetOption struct and the new_with_options method.

best

Take the best n dice from the dice rolled

  let dice_options = DiceSetOptions::new(best: 3);
  let dice = Rustdice::new_with_options("4D6", dice_options);
  let result = dice.roll();

worst

Take the worst n dice from the dice rolled

  let dice_options = DiceSetOptions::new(worst: 3);
  let dice = Rustdice::new_with_options("4d10", dice_options);
  let result = dice.roll();

reroll

Reroll any dice with a value of n

  let dice_options = DiceSetOptions::new(reroll: 1);
  let dice = Rustdice::new_with_options("1d20", dice_options);
  let result = dice.roll();

explode

Any dice with this value get an accumulating reroll found in a few game systems.

  let dice_options = DiceSetOptions::new(explode: 10);
  let dice = Rustdice::new_with_options("3D10", dice_options);
  let result = dice.roll();

Why

Some people may find this library useful for their Rust projects and they're welcome to use it as such.

My larger purpose for this project is to experiment and measure the impact of Ruby-to-Rust bridging. The intention is to replicate the functionality provided by Rubydice using a relatively constant function (random number generation) and see the cost and impact introduced by invoking a function in Rust from Ruby.