Dice rolling question

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Post by Azhrei »

Orchard wrote:Really, until we have looping, there is no fix.
Well, not really.

This could be done with recursion instead of a loop. Define a property that contains all of the needed formula, along with an IF statement that says if the formula isn't done yet, it should invoke the same property again. ;)

I'm not sure how careful the expression parser is when it comes to recursion, but there are alternatives.

User avatar
Mathemagician
Dragon
Posts: 666
Joined: Tue May 22, 2007 2:27 pm

Post by Mathemagician »

TK has the right idea, I think.

If we forever reroll ones, since each roll is independent of the previous, we're only stopping on one of 3 numbers, each with equal probability on the original (4 sided) die. If they had skewed probability originally, yeah, I think we'd be in a stickier situation.

User avatar
TK
Giant
Posts: 162
Joined: Fri Jun 27, 2008 12:02 am

Post by TK »

Mathemagician wrote: {damage=1d3e}
{damage= damage+ceil(damage/3)}

Should do it, as was proposed above, without the e :P
Right.. the e, the whole reason we have this problem in the first place ::feels sheepish for forgetting::

User avatar
Orchard
Great Wyrm
Posts: 1852
Joined: Fri May 09, 2008 10:45 am
Location: Doylestown PA
Contact:

Post by Orchard »

Mathemagician wrote:TK has the right idea, I think.

If we forever reroll ones, since each roll is independent of the previous, we're only stopping on one of 3 numbers, each with equal probability on the original (4 sided) die. If they had skewed probability originally, yeah, I think we'd be in a stickier situation.
I agree that if you reroll ones infinitely, then yes, it is the same, but otherwise, it is much more complex, and you need to know how many time you are rerolling ones.

For instance, the 3d6 reroll 1's method of stat generation ORIGINALLY said if you roll a second 1, you were stuck with it. Which is a very different proposition than what we had before.
0+0=1, for very unstable CPUs.

User avatar
Mathemagician
Dragon
Posts: 666
Joined: Tue May 22, 2007 2:27 pm

Post by Mathemagician »

Orchard wrote: For instance, the 3d6 reroll 1's method of stat generation ORIGINALLY said if you roll a second 1, you were stuck with it. Which is a very different proposition than what we had before.
Ah, I understood the original post as infinitely rerolling 1s (well, hopefully not infinitely...), if that's not the case, then yes, we have a slight (read: major) problem

bobthedog
Cave Troll
Posts: 85
Joined: Sun Aug 03, 2008 7:17 pm

Post by bobthedog »

I do believe that the Gauntlets allow for infinite rerolls so the "1d3+1" solution should work in this case; but if you want a challenge, here it is:
Staff of Fiery Might wrote:After rolling damage, you can reroll a number of damage dice equal to or less than the staff's enhancement bonus. You must keep the new results, and you can't reroll any die more than once.
Three sticky situations:

1- choice to reroll: I can only see this working with separate variables (stored in properties) for each die rolled, using a second macro to let the player reroll.

2- rerolled dice limited by item: so, we're not rerolling specific die results (reroll 1s, supported by the parser) nor rerolling a set number of dice (might work with some tweaking), since the player can choose how many he wants to reroll up to the limit.

3- reroll once: as you have been discussing, reroll and keep presents a completely different challenge.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Post by Azhrei »

Hmm. I still think recursion could do this.

Define a property that holds the enhancement bonus of the staff (say the number "3").

Store that value in a variable and invoke a property whose formula is the following:
  1. If the value in the variable is 0, do nothing but return "0" as the result of the formula.
  2. Otherwise, multiply the result of a die roll (say "1d6" for each damage die) by a non-existent property, causing a prompt to come up.
    • The user enters "0" to reroll.
    • The user enters "1" to keep the result.
  3. The previous result is multiplied by the value they enter (zero or one)
  4. An IF statement checks for zero as the result of the multiplication and rerolls the "1d6".
  5. Add the result of the IF statement to the result of calling the same property again, but this time with the variable in step #1 decremented by one.
I'm not entirely positive that will work, but the idea is sound even if MT can't do the recursion (yet).

bobthedog
Cave Troll
Posts: 85
Joined: Sun Aug 03, 2008 7:17 pm

Post by bobthedog »

Azhrei wrote:Hmm. I still think recursion could do this.

Define a property that holds the enhancement bonus of the staff (say the number "3").

Store that value in a variable and invoke a property whose formula is the following:
  1. If the value in the variable is 0, do nothing but return "0" as the result of the formula.
  2. Otherwise, multiply the result of a die roll (say "1d6" for each damage die) by a non-existent property, causing a prompt to come up.
    • The user enters "0" to reroll.
    • The user enters "1" to keep the result.
  3. The previous result is multiplied by the value they enter (zero or one)
  4. An IF statement checks for zero as the result of the multiplication and rerolls the "1d6".
  5. Add the result of the IF statement to the result of calling the same property again, but this time with the variable in step #1 decremented by one.
I'm not entirely positive that will work, but the idea is sound even if MT can't do the recursion (yet).
Problem is, you normally only see the results of some macro AFTER everything is calculated, so a macro like this:

Code: Select all

[DieRoll = 1d6]
[RerollPrompt = RerollFirstDie]
[DieRoll = if(RerollFirstDie != 0, 1d6, DieRoll)]
Would first prompt you for RerollFirstDie, then roll the 1d6. If you made it roll 5 times and prompt 5 times, it would prompt 5 times in a row, then run the macro.

User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Post by Azhrei »

Hmm, good point. I was thinking that the macro expansion happened first, then the formula was executed.

In fact, even if it worked as I thought it did, it would still fail because the first time a value was prompted for it would "stick" to the next time the same variable was needed. Meaning that entering a "0" or "1" would apply to all dice, not just the "current" one.

Oh well.

Post Reply

Return to “Documentation Requests/Discussion”