Usage Die / Usage Dots probability chart help #240
-
Hello, In many TTRPGs, a "Usage Die" is used to track some consumable items in a PC's inventory. d20 → d12 → d10 → d8 → d6 → d4 When you roll a 1 or 2 on a d4 (the lowest die in the chain), the item is expended, and the PC has no more of it left. I would like to make a probability chart like this: given the Usage Die and a number of rolls (number of rolls >= remaining steps on the chain), what is the probability of depletion? If this is possible, I'd like to expand this to cover also "Usage Dots," which is more or less the same idea. d6 → d6 → d6 When you roll a 1 or 2 on a d6, you mark off a dot; after 3 marks, the item is depleted. Thanks for your time and this wonderful library; any help is very much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Glad to get your question. Here's a solution: from icepool import d
die_sizes = [4, 6, 8, 10, 12, 20]
def usage_die(size, explode_depth=None):
if explode_depth is None:
explode_depth = size * 3
index = die_sizes.index(size)
if index == 0:
return 1 + (d(size) > 2).explode(depth=explode_depth)
else:
return 1 + (d(size) > 2).explode(depth=explode_depth) + usage_die(die_sizes[index - 1])
for size in [4, 6, 8, 10, 12, 20]:
output(usage_die(size), f'usage d{size}')
def usage_dot(size, t, explode_depth=None):
if explode_depth is None:
explode_depth = size * 3
return t @ (1 + (d(size) > 2).explode(depth=explode_depth))
output(usage_dot(6, 3), 'usage dot 3d6')
limit(None, 50) Here we use |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick answer! I'll dig into the code, ... I'm still learning to use Icepool. Just one curiosity: how do you get the 3 on "explode_depth = size * 3" (I guess it's for limiting the explode() function). |
Beta Was this translation helpful? Give feedback.
Glad to get your question. Here's a solution: