Skip to content

Instantly share code, notes, and snippets.

@lukeyeager
Created June 25, 2024 18:55
Show Gist options
  • Save lukeyeager/3ce5ebf2f3828460695883c004fa5369 to your computer and use it in GitHub Desktop.
Save lukeyeager/3ce5ebf2f3828460695883c004fa5369 to your computer and use it in GitHub Desktop.
SWADE: odds of rolling target number for wild cards, based on trait die
#!/usr/bin/env python3
MAX = 16
TRAIT_DICE = (4, 6, 8, 10, 12)
WILD_DIE = 6
def main():
# CSV header
print(','.join([''] + [f'{i}' for i in range(1, MAX+1)]))
for trait_die in TRAIT_DICE:
probs = [0 for _ in range(MAX)]
# recursive
def _handle_rolls(roll_trait, prev_trait, roll_wild, prev_wild, prev_prob):
nonlocal trait_die, probs
current_prob = prev_prob
trait_rolls = [0]
wild_rolls = [0]
if roll_trait:
current_prob /= trait_die
trait_rolls = range(1, trait_die+1)
if roll_wild:
current_prob /= WILD_DIE
wild_rolls = range(1, WILD_DIE+1)
for trait_roll in trait_rolls:
for wild_roll in wild_rolls:
trait_value = trait_roll + prev_trait
wild_value = wild_roll + prev_wild
if trait_value >= MAX or wild_value >= MAX:
# end case: we hit the max with one die or the other
for i in range(MAX):
probs[i] += current_prob
elif trait_roll < trait_die and wild_roll < WILD_DIE:
# simple case: take the max and update the array
value = max(trait_value, wild_value)
for i in range(value):
probs[i] += current_prob
elif trait_roll == trait_die and wild_roll < WILD_DIE:
# trait explodes
_handle_rolls(True, trait_value, False, wild_value, current_prob)
elif trait_roll < trait_die and wild_roll == WILD_DIE:
# wild explodes
_handle_rolls(False, trait_value, True, wild_value, current_prob)
elif trait_roll == trait_die and wild_roll == WILD_DIE:
# both explode
_handle_rolls(True, trait_value, True, wild_value, current_prob)
_handle_rolls(True, 0, True, 0, 1.0)
# CSV row
print(','.join([f'd{trait_die}'] + [f'{100*p:.1f}' for p in probs]))
if __name__ == '__main__':
main()
@lukeyeager
Copy link
Author

image

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