abelsiqueira / DiceRolls.jl

Julia package defining dice and operations with them
Other
9 stars 4 forks source link

Conditional Rolls #9

Open elihunter173 opened 3 years ago

elihunter173 commented 3 years ago

As far as I can tell, there's no way to describe dice rolls where parts of the roll depend on another, so you can't for example express something like a standard attack and damage roll in D&D, where you roll an attack roll against some AC, doing no damage if you don't roll above a certain number, doing some damage if you do. Alternatively you do extra damage on a 20.

My motivation for this is, for my D&D character, I want to see how much damage each of my attacks do in various situations. So I want to say "Roll a d20 + some modifier, if it's higher than this AC, roll these dice to do this much damage." I've been doing that experimentally since computation is cheap and I can approximate the actual results well enough, but I feel like it should be possible to do analytically.

abelsiqueira commented 3 years ago

Hi Eli. That's a good idea, I was hoping to do exactly that at some point.

I implemented rolllist inside rolllist.jl in the hope of expanding for conditionals later, but I haven't come up with a good solution - not had the time. I've implemented comparisons, like d20 + 5 > 13, which creates a CompactedComparison. You can collect for a list of rolls that satisfy it or compute its probability.

Notice that that's not a roll, so roll and histogram don't work.

Now the question is how we'd do this. What do we want to write, and what output do we want. Is this a roll, or not?

Two possibilities, there can be others: