TabletopAssistant / DiceKit

Swift framework for expressing and evaluating dice notation (e.g., d20, 4d6+4, 3d8×10+2), which is commonly used in tabletop role-playing games.
Apache License 2.0
14 stars 1 forks source link

Support determining the probability that an expression is a success #4

Open brentleyjones opened 9 years ago

brentleyjones commented 9 years ago

It's very common in TTRPGs that you need to meet a goal with a dice roll (less than or equal to X, greater than Y, etc.). Expressions (see #3) should support a way to determine how likely it is that it will meet a given goal. To be extensible the goal checking should probably be closure based.

CC: @LoganJohnson

brentleyjones commented 9 years ago

I've been thinking more about this and here are my thoughts:

This would mean the meat of the work is determining a probability mass function for a given expression. I don't know how to do that, but I hope there is a way :smile:.

CC: @yammada

JonathanHoffman commented 9 years ago

I have an idea about how we can implement this. Also support advantage/disadvantage in 5e. I'll talk to you later.

brentleyjones commented 9 years ago

Awesome. I assume for advantage/disadvantage it will simply be2d20k-H or 2d20k-L (I'm probably messing up the notation, but pick high or pick low: #28)

JonathanHoffman commented 9 years ago

Probability of success on disadvantage is the probability of success twice in a row= Psuccess ^2. Probability of failure on advantage is probability of failure twice = (1-Psuccess^ 2) or 2Psuccess - Psuccess ^ 2 or something like that. The probability of success on a single die roll is easy, but I haven't thought about how to generalize it to a expression.

brentleyjones commented 9 years ago

The issue isn't success, but chances of each value to be hit. Success can mean different things depending on the context (thus the need to support multiple ranges: some games have ranges of success, odd vs even for success, etc).

Also an expression can be more than just 2d20+4, it can include multiplication before or after the fact as well, exploding dice, min/max/dropping. I think the key is to be able to calculate a probability mass function in a general sense for an expression (see #26 for how general I've made them).

I love that you are thinking about this though. You actually took a probability class (or multiple, I forget), while I only skimmed the internet for the ideas when I need them :smile:.

JonathanHoffman commented 9 years ago

Oh! I think I'm missing some context from trying to keep up on my phone. I misunderstood your question but yes I think we can find a general probability mass / distribution function. I made some notes on it a while back but I don't think my solution then is as general as what you are looking for now.

brentleyjones commented 9 years ago

Boy do I love playgrounds. I believe I have the basis of the implementation for this. I'll be working on it and I should be able to get it in the next day or so.

brentleyjones commented 9 years ago

@TabletopAssistant/dicekit do we feel this is needed for release 0.2?

brentleyjones commented 9 years ago

59 represents determining the raw success or failure. This issue now represents the probability of such success. #59 needs to happen first, of course.