4
\$\begingroup\$

Ok this isn't the most technical question, but I want to create a decaying explode function, and I can't get it to work. here is what I currently have, but the ideas is that every time the die explodes, it rolls a die one size category smaller than it, so essentially if you roll an 8 on a d8 then you roll a d6 and add it to that roll. Then, if that d6 explodes, you roll a d4. Then it stops.

Right now it wont work the way I want it to, and after some messing around, pictured somewhat incoherently here, I isolated the issue to the exploding function I think, but I still can't figure out what I need to change.

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$
set "maximum function depth" to 10

function: cascading X:n MAX:n {
 if MAX <= 4 | X < MAX {
  result: X
 } else {
  result: X + [cascading d(MAX-2) MAX-2]
 }
}


function: cascading D:d {
 result: [cascading D [maximum of D]]
}

output [cascading d12]

AnyDice link.

The first function returns immediately if the number rolled is less than the maximum or the die size is only 4. Otherwise it makes a die of 2 faces smaller and cascades to that.

The second function sets the calculation up given a starting die.

\$\endgroup\$
5
\$\begingroup\$

Here's one fairly straightforward way to do it:

function: ROLL:n add BONUS:d to TARGET:s {
  if ROLL = TARGET { result: ROLL + BONUS }
  result: ROLL
}

function: explode DIE:d as BONUS:d {
  result: [DIE add BONUS to [maximum of DIE]]
}

output
  [explode d12 as
    [explode d10 as
      [explode d8 as
        [explode d6 as
          [explode d4 as d2]
        ]
      ]
    ]
  ]

A nice feature of this approach is that it's easy to specify any sequence of dice to roll on successive explosions. Want a d10 that explodes first as a d4 and then as a d20? Just use [explode d10 as [explode d4 as d20]].

The long nested expression at the end can be written a bit more compactly using a helper variable:

X: d2
X: [explode d4 as X]
X: [explode d6 as X]
X: [explode d8 as X]
X: [explode d10 as X]
X: [explode d12 as X]

output X

…or even more compactly using a loop:

X: 0
loop SIZE over {2, 4, 6, 8, 10, 12} {
  X: [explode dSIZE as X]
}
output X

Of course we can also output all the intermediate results if we want:

X: 0
loop SIZE over {2, 4, 6, 8, 10, 12} {
  X: [explode dSIZE as X]
  output X named "decaying exploding d[SIZE]"
}

Ps. The [ROLL add BONUS to TARGET] helper function is a bit more flexible that the examples above show. In particular, it can take a sequence of multiple target values to add the bonus to.

For example, if you wanted to modify your mechanic to let the two highest rolls of each die (e.g. 5 and 6 on a d6) explode, you could modify the [explode DIE as BONUS] function into:

function: explode DIE:d as BONUS:d {
  MAX: [maximum of DIE]
  result: [DIE add BONUS to {MAX-1 .. MAX}]
}

This should be significantly more efficient than modifying HighDiceRoller's recursive solution to explode on multiple values per roll, since it will still only calculate each intermediate result once, whereas a recursive solution would calculate the d10 result twice, the d8 result for times, the d6 result eight times and so on. (For a normal explosion on the highest roll only, the two solutions should be approximately equally fast.)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .