jarcane / rouler

An easy to use dice rolling library for Rust
Mozilla Public License 2.0
17 stars 6 forks source link

Exploding dice #4

Open Ygg01 opened 7 years ago

Ygg01 commented 7 years ago

I need to do some simulation, where there are exploding dice. I.e. when you roll the highest dice, your dice explode and you roll again. And if your dice roll again, it explodes, etc.

jarcane commented 7 years ago

This will take some consideration. It's a good feature idea. The main question I have is, to do this will mean additional syntax to the dice DSL. I don't know that there's any standard common notation for this; most games that use exploding dice tend to just apply it as an automatic rule.

Also, do we need to allow specifying what ranges to explode on? I know most games that I've played that use exploding dice tend to explode on the max result (ie. 6 on 1d6), but presumably some games might use others?

Ygg01 commented 7 years ago

The Crit Dice program I've used, only explodes on highest side there is notation d3! for exploding dice and d3!! for exploding compounding dice. Also see this. But perhaps there could be more advanced generators.

Personally, I'd have a Dice struct that only has side for example:

struct Dice {
  side: i64
}

Then have a complex dice generator like

struct DiceGenerator {
   die: Dice,
   number_of_dies: i64,
}

Where Generator and Dice implements trait Generator, which notes when dice generator has finished.

 trait Generator {
    fn is_finished(&mut self) -> bool;
    fn roll(&mut self) -> i64;
 }

 struct ExplodingDiceGenerator<T:Generator> {
    generator:  T,
    limit: Dice::max(),
 }

Then exploding dice is a more complex generator, that terminates when certain limit is met.

jarcane commented 7 years ago

Mm. That's a good idea. Possibly though, Die could itself be a Trait, which die types implement, that way we can later implement all kinds of different types of custom dice easily. I already had custom die sequences on the road map (so you can do stuff like Fudge dice as, say, 4d[-1, 0, 1].

I think ! is a great idea for the syntax as well; I like that there's existing tools using it, so there's precedent.

jarcane commented 7 years ago

And just like that, I've got a rough proof of concept of generic die generators: https://github.com/jarcane/rouler/blob/235483dd039239f84bc46d46aacf0c2bb6176f25/src/random.rs

Ygg01 commented 7 years ago

Any update on this?

jarcane commented 7 years ago

Hey, sorry. I have rather got caught up in some personal stuff of late. I actually did get a working implementation for generic dice types (see the generic-dice branch: https://github.com/jarcane/rouler/blob/generic-dice/src/random.rs), but I stalled out at figuring out how to extend the grammar to support the new exploding dice.