Created
June 25, 2024 18:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Author
lukeyeager
commented
Jun 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment