3

I'm new to anydice, so forgive me if I've overlooked something obvious, but I can't seem to figure this one out.

I'm working on a dice mechanic that allows the player to choose whether or not they add or subtract their base die roll to/from another die roll.

I can do d10 + d6, I can do d10 - d6, how do I do d10 +|- d6?

2 Answers2

3

The formula that will achieve what I think is your desired output:

output 1d10 + d{-6,-5,-4,-3,-2,-1,1,2,3,4,5,6}

This will show you the range of odds for any value -6 to +6 added to a d10 roll.

Based on the feedback received from Michael in the comments, I am adding this here as well to make my answer more complete:

An anydice script that has two outputs:

output 1d10 + 1d6 output 1d10 - 1d6

Individually these will give the odds of any value coming up for that specific output. When the data are transposed, however, it will transpose the data across the results rather than across the outputs, which will show the relative probabilities for each result for each output.

LegendaryDude
  • 24,379
  • 6
  • 108
  • 154
  • @doppelgreener, Right! Sorry, I was rolling 3d10 for some of my figures. So here's a proper example. Again, I really appreciate the help! While that will give the proper range, I'm pretty sure it skews the probabilities. For example: d10 + d6 gives me a 1.67% chance of getting an 2, d10 - d6 gives me a 10% chance of getting an 2. Given the mechanic, I've got an 11.67% chance of getting a 2 on any roll. The output you suppied shows a 5.83% chance for it since I'm essentially rolling a custom d12 instead of a d6. – Michael Conn Feb 27 '17 at 20:09
  • @MichaelConn Actually, it's right on the money. The odds of getting a 2 with a +d6 are 1.67%, the odds with the -d6 is 10%. The average of those two values is, in fact, 5.835% which is right where it falls with the +/- output. – LegendaryDude Feb 27 '17 at 20:21
  • @MichaelConn 11.67% divided by two (we've doubled the size of the pool of possibilities) is 5.83%. Also, that custom d12 represents +-d6, which has twelve equally likely possibilities, each one represented on that d12. – doppelgreener Feb 27 '17 at 20:22
  • @doppelgreener, LegendaryDude, I respectfully disagree. The pool of possibilities remains static in terms of probability. There are 60 possible combinations of rolls for a d10 and d6 together (10*6). If you allow for both addition and subtraction of the two resulting values, there are 7 possible combinations that can equal 2. 7/60 = 11.67%. Remember, we're only allowing for the addition or subtraction of the d6 to/from the d10. Even if we allowed the reverse as well, it would only increase the probability (to 11 possible combinations, I think). There's only 60 ways for these two dice to fall. – Michael Conn Feb 27 '17 at 21:19
  • @MichaelConn Respectfully, 7 possible combinations if you roll both + and - . However, you don't get to roll both the +1d6 and -1d6. At the time you choose, you have cut your odds to 3.5/60 (5.835%) possible values. – LegendaryDude Feb 27 '17 at 21:29
  • 1
    @MichaelConn There are actually 120 combinations since you have the 60 from +d6 and 60 from -d6. So you have 1/60 for +d6 and 6/60 for -d6 – diego Feb 27 '17 at 21:29
  • @LegendaryDude, I was pretty sure Both and Either were the crux of our disagreement. :) I would agree with you if the mechanic required the declaration of subtraction or addition before rolling, but since it does not, the operation chosen by the player is arbitrary. It is not a +d6 or a -d6, it is simply a d6 with which you may choose to do either after the roll. Maybe I'm too far out in the weeds and should just use a spreadsheet, but anydice is just so useful. – Michael Conn Feb 27 '17 at 21:39
  • @MichaelConn My comment is more theoretical. diego's comment shows you the practical application, which treats the +/-d6 as a simulated d12 (which is in line with your explanation in your most recent comment), and shows you that there are actually 120 possible combinations, not 60. If you are looking for some sort of quantum calculation where the +/- is determined at some arbitrary point after both dice are rolled I'm afraid that's beyond my skill level. ;) – LegendaryDude Feb 27 '17 at 21:47
  • @LegendaryDude, LOL, that kind of is what I'm asking for isn't it? Let me ask in a way that I think might get me what I need. Is there a way to combine the results of two output statements, say add the percentages calculated from the first to the second? – Michael Conn Feb 27 '17 at 21:58
  • 1
    @MichaelConn Two separate output statements: output 1d10 + 1d6 and output 1d10 - 1d6, then for data type select 'transposed.' Ironically, this was going to be my first answer before I decided it probably wasn't what you're looking for. It won't add the results but it will transpose the data across the results rather than across the outputs, which will allow you to analyze in the way you're looking to. – LegendaryDude Feb 27 '17 at 22:00
  • @LegendaryDude, I was hoping it'd sum the outputs for me, but that's close enough. It looks like I don't have the points to upvote your comment, so I'll simply provide the frowned upon "Thanks!" to both you and doppelgreener for the help. :) – Michael Conn Feb 27 '17 at 22:09
3

Here's a generic AnyDice function for evenly mixing two different possible dice rolls:

function: mix A:d and B:d weighted by X:n {
  if X = 1 { result: A } else { result: B }
}
function: mix A:d and B:d {
  result: [mix A and B weighted by d2]
}

For example, the expression [mix 1d10 + 1d6 and 1d10 - 1d6] will return the distribution of outcomes obtained by rolling a d10 and a d6, and randomly choosing whether to add or subtract the d6 from the d10. The resulting probability distribution, plotted as a line graph, will look like this:

Screenshot

Of course, in your question you say that the player gets to choose whether to add or subtract the d6, and they probably won't be doing so at random. Since you didn't tell us what the player is trying to achieve with the roll, it's hard to give any specific answer, but a general technique for modeling such player choice mechanics in AnyDice is to write a function that takes the possible outcomes of the two rolls (i.e. two number parameters, tagged with :n), and returns the one more favorable to the player (whichever that might be).

For a random example, if the player is trying to roll as close to 10 as possible, you could write your decision function like this:

function: better of A:n and B:n {
  if [absolute A - 10] < [absolute B - 10] { result: A }
  else { result: B }
}

However, note that there's a catch: if you call this function as [better of 1d10 + 1d6 and 1d10 - 1d6], then you're actually modeling a mechanic where the player first rolls 1d10 + 1d6, and then separately rolls 1d10 − 1d6, and chooses the better of those two independent rolls. If you instead want the player to roll a single d10 and a single d6, and then choose whether to add or subtract them, then you need a helper function to "freeze" the d10 and d6 rolls before adding and subtracting them, like this:

function: better of A:n plus minus B:n {
  result: [better of A+B and A-B]
}

The resulting probability distributions, for various target numbers, will then look like this:

Screenshot

Actually analyzing the gameplay effects of all those funky-looking probability distributions is left as an exercise for the reader. ;)


Ps. The [better of A and B] function I gave above is slightly biased, in that it will always choose the second option if both are equally good (i.e. the same distance from 10). You can make the bias go the other way just by changing the < into <=, but if you want to completely eliminate it (by breaking ties at random), you can rewrite the function like this:

function: better of A:n and B:n {
  if [absolute A - 10] < [absolute B - 10] { result: A }
  if [absolute A - 10] > [absolute B - 10] { result: B }
  result: 1d{A, B}
}

This code first checks if either roll is strictly better than the other, and if so, chooses that. If the rolls A and B are equally good, it instead returns a custom die that will roll either A or B with equal probability, simulating a random choice. (Of course, if you have some other criteria for breaking ties, you can insert additional if statements before the last line of the function above, or even replace the last line entirely if you know that it will never run.)

A bit surprisingly, making that change to the example code above changes the appearance of the graphs quite a bit:

Screenshot

Actually, with that particular example, it's perhaps not all that surprising: with a target number between 1 and 10, you have a 10% chance of rolling exactly that number on the d10, at which point (if you're just aiming as close as possible to the target, like the example assumes) it makes no difference whether you add or subtract the d6 roll. Thus, breaking such ties randomly, instead of always preferring subtraction, increases 5% of all rolls by an average of 7 points (twice the average roll of the d6). Sure enough, setting the target number to 0 or 11 causes the tie-breaking rule not to matter.

Of course, if it really makes no difference in your actual mechanics whether the player rolls N points below or N points above the target, then you'd really want to plot you results in such a way as to group those outcomes together. One possibility would be to actually plot the distance of the player's roll to the target, like this:

output [absolute 10 - [better of 1d10 plus minus 1d6]]

This change makes the output a lot more readable (IMO, at least):

Screenshot

It also highlights the symmetry of this example mechanic: it's equally easy to aim for 1 as it is to aim for 10 with a roll of 1d10 &pm; 1d6, and thus the graphs for those two target values overlap exactly in the plot above.

Ilmari Karonen
  • 24,384
  • 7
  • 64
  • 97
  • This is a spectacular answer. You've answered every aspect of my question, including some I didn't know I had. Thank you for the work you've put in. – Michael Conn Mar 03 '17 at 16:40
  • No problem, I rather like these kinds of questions; AnyDice, even with all its quirks, is a fun toy to play with. BTW, I expanded my answer a little bit, noting that (at least for the example mechanic I used) tie-breaking can make a noticeable difference, as can the way the results are presented. – Ilmari Karonen Mar 04 '17 at 12:30