Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force return of average result? #140

Closed
dixhuit opened this issue Jun 16, 2020 · 15 comments · Fixed by #162
Closed

Force return of average result? #140

dixhuit opened this issue Jun 16, 2020 · 15 comments · Fixed by #162
Milestone

Comments

@dixhuit
Copy link

dixhuit commented Jun 16, 2020

Great looking library here! Is there a way to return the average result for the input notation, rather than the actual result of each instance of the input notation?

E.g. Inputting 3d3 might return something like this:

3d3: [3, 1, 1] = 5
3d3: [3, 2, 1] = 6
3d3: [3, 3, 2] = 8

Whereas I'm interested in a way to force it to return the average outcome every time:

3d3: [2, 2, 2] = 6
3d3: [2, 2, 2] = 6
3d3: [2, 2, 2] = 6

My use case is to hopefully use this library in a game probability calculator rather than as an actual roller in a game. I was looking at https://github.com/thebinarypenguin/droll but it's not seen much development of late and rpg-dice-roller has extra functionality that is really relevant to what I need.

@GreenImp
Copy link
Collaborator

Do you mean each individual roll should return the average value between the lowest and highest possible values?
So, for a d3, the roll will always be 2, a d10 will always roll 5.5 etc.?

Something like:

4d3: [2, 2, 2, 2] = 8
2d10: [5.5, 5.5] = 11

Or do you want to be able to average the results of several dice rolls?

4d3: [1, 1, 3, 3] = 2
2d10: [2, 8] = 5

@dixhuit
Copy link
Author

dixhuit commented Jun 19, 2020

For my use case I'd be after the former - each die involved would roll an average result and any modifiers specified by the notation would be applied.

I've read all of your excellent documentation but it seems that this is not something that's offered at present.

As a short term solution I've opted to use droll just to have it translate the dice notation into an average result. droll makes this available via the output of its parse() method. But I still need to do all the heavy lifting to figure out the outcomes of re-rolls, exploding dice and all that jazz. Your library already appears to do an excellent job of this, it's just missing the average output!

@GreenImp
Copy link
Collaborator

I'm glad you like the docs!

You're right, there's currently no way of calculating average values, but I've got a few ideas:

  1. We could add an average property to all the die objects. They already have a min and max value, so calculating the average would be fairly simple.
    The downside of that is that you'd have to calculate thet results yourself, like you're doing with Droll.
  2. There are currently 3 type of Die; Standard, Percentile, and Fudge. We could add a new one that always returns it's own average, maybe with a notation like (Where md stands for "mean die"):
    3md3: [2, 2, 2] = 6
    
    The downside of this is that it would only really work with simple numerical dice, in the same way the Standard die does. For example, you couldn't use it for Fudge dice (Although I'm not sure you'd want to anyway).
  3. We could add a modifier that forces the die value to the average. This could even work in combination with having the average as a property on the die as well. This would mean that the die is rolled for a random value, and then the modifier adjusts the value to the average.
    This would probably have to run before other modifiers, so things like exploding dice use the average value to compare with.
    It also seems odd, as we'd be rolling an initial value that we never want.
    Not sure what the notation for that would be though.

What are your thoughts?

@dixhuit
Copy link
Author

dixhuit commented Jun 19, 2020

I appreciate your thoughts on this.

Ideally, I'd like to leave the input notation untouched for it to remain as standard as possible. My application will allow users to enter some notation, so not messing with this would be in my interest. I guess that rules out option 2 and possibly option 3 as it sounds like that may be heading in the direction of further custom notation. Unfortunately, option 1 doesn't get me any closer to benefiting from modifiers available in your library.

What about the DiceRoll object? Is there potential for it to accept a further property to instruct it to parse the notation but then just calculate/return average results rather than simulate rolling the dice? Granted, I'm assuming a lot about how this all works under the hood, I've only read the docs, not the codebase! :)

@GreenImp
Copy link
Collaborator

Yeah, I thought number 1 wouldn't really be an improvement on what you're getting with Droll. I may add it at some point anyway, just because I could see it potentially being useful for some things.

I know you're not wanting to change the notation that you use but, the simplest thing to implement at the moment would be option 2 or 3 - personally I prefer option 3, as it will work with any dice.

In terms of adding a property to the DiceRoll object, I'm currently in the process of investigating the best way to pass through a set of options to either the DiceRoller or DiceRoll object so you can specify things like what random number generator to use (#141) or swapping the output handler with another (#132).
So, although it's not an option at the moment, I could potentially look at implementing it as an option there.

Out of interest, are you using the DiceRoll object directly, or are you using the DiceRoller?

@dixhuit
Copy link
Author

dixhuit commented Jun 28, 2020

Out of interest, are you using the DiceRoll object directly, or are you using the DiceRoller?

Currently I'm using neither :) Looking back at my initial evaluation of rpg-dice-roller though it seems I was using DiceRoll directly.

Looking back over option 2 above, I guess I could parse more standard notation and then convert this to use "mean dice" notation behind the scenes and before using it with DiceRoll. I only need standard numerical dice so the drawback you've highlighted wouldn't be an issue in my case.

I appreciate you still entertaining this idea! If it helps I could share a demo of what I'm working on, though I'll need to do that more privately atm.

@GreenImp
Copy link
Collaborator

Yeah, seeing an example of what your doing would definitely be of benefit. Might help me think of some better solutions.

How would you want to share?

@dixhuit
Copy link
Author

dixhuit commented Jun 28, 2020

Great, thanks. I just pinged you a message through your website's contact form.

@GreenImp
Copy link
Collaborator

Cheers Dan

@GreenImp
Copy link
Collaborator

GreenImp commented Jul 1, 2020

Just to say, I've implemented option 1 in PR #149 which will go out in 4.2.0. So dice now have an average property.
I know it's not what you're after, but as it was easy to implement, I thought I'd add it in.

I'm still looking at the best solutions for your situation, so don't worry, It's not been forgotten!

@GreenImp
Copy link
Collaborator

Just as a follow up from our conversation yesterday, I'm thinking this could work well in combination with #150. The requirement there is to have a min and max possible totals for a given notation, so I could use that to calculate the average.

I'm thinking the average will be as a new property on the DiceRoll object, probably called averageTotal, or meanTotal.

@GreenImp GreenImp added this to the 4.3.0 milestone Jul 22, 2020
@GreenImp
Copy link
Collaborator

I've finished work on #150, which means I should be able to get this sorted now.

@GreenImp
Copy link
Collaborator

GreenImp commented Jul 23, 2020

And I've now added an averageTotal property to the DiceRoll object, that'll give you the average total for the entire notation, including any modifiers.

You can use it like so:

const diceRoll = new DiceRoll('4d8+1');

console.log(roller.averageTotal); // outputs 19

I'll be adding it to the docs, and it will go out in v4.3.0.

Hopefully it will come in handy. Let me know if it's not what you're after.

@dixhuit
Copy link
Author

dixhuit commented Jul 23, 2020

Yay! This and the changes in #150 are just the ticket. Can't wait to try it out.

@dixhuit
Copy link
Author

dixhuit commented Jul 23, 2020

Ooof, just seen the timestamp from your last comment. Don't over do it! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants