Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import collections, itertools
- gray_die = [0,1,1,1,2,3]
- black_die = [0,2,2,2,3,4]
- row_template = """\
- |-
- | style="text-align:center;"| {}
- | style="text-align:right;" | {}
- | style="text-align:right;" | {}
- | style="text-align:right;" | {}\
- """
- def print_row(attribute):
- # to calculate the plain odds, count how many of the 36 outcomes are favorable
- hitogram = collections.Counter(sum(x) for x in itertools.product(gray_die, black_die))
- chance = sum(frequency for (roll,frequency) in hitogram.items() if roll <= attribute) / 36.0
- # lucky charm lets you reroll if you fail, so it's the inverse probability of losing twice in a row
- lucky_chance = 1 - (1 - chance)**2
- # dark fortune makes things complicated. we need to pick one of the dice to reroll
- fortune_numerator = 0
- for (g, b) in itertools.product(gray_die, black_die):
- if g + b <= attribute:
- # no need to use dark fortune. effectively the reroll is guaranteed success
- fortune_numerator += 6
- else:
- # see what would happen if we rerolled either one, and choose the best outcome
- new_chances = 0
- for keep, reroll_die in [(b, gray_die), (g, black_die)]:
- new_chances = max(new_chances, sum(1 for new_value in reroll_die if keep + new_value <= attribute))
- fortune_numerator += new_chances
- fortune_chance = fortune_numerator / (36*6.0)
- print(row_template.format(attribute,
- format_percent(chance),
- format_percent(lucky_chance),
- format_percent(fortune_chance)))
- def format_percent(x):
- if x == 1: return "100%"
- return "{:.1%}".format(x)
- for n in range(8):
- print_row(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement