Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import collections, itertools
  4.  
  5. gray_die  = [0,1,1,1,2,3]
  6. black_die = [0,2,2,2,3,4]
  7.  
  8. row_template = """\
  9. |-
  10. | style="text-align:center;"| {}
  11. | style="text-align:right;" | {}
  12. | style="text-align:right;" | {}
  13. | style="text-align:right;" | {}\
  14. """
  15. def print_row(attribute):
  16.   # to calculate the plain odds, count how many of the 36 outcomes are favorable
  17.   hitogram = collections.Counter(sum(x) for x in itertools.product(gray_die, black_die))
  18.   chance = sum(frequency for (roll,frequency) in hitogram.items() if roll <= attribute) / 36.0
  19.   # lucky charm lets you reroll if you fail, so it's the inverse probability of losing twice in a row
  20.   lucky_chance = 1 - (1 - chance)**2
  21.  
  22.   # dark fortune makes things complicated. we need to pick one of the dice to reroll
  23.   fortune_numerator = 0
  24.   for (g, b) in itertools.product(gray_die, black_die):
  25.     if g + b <= attribute:
  26.       # no need to use dark fortune. effectively the reroll is guaranteed success
  27.       fortune_numerator += 6
  28.     else:
  29.       # see what would happen if we rerolled either one, and choose the best outcome
  30.       new_chances = 0
  31.       for keep, reroll_die in [(b, gray_die), (g, black_die)]:
  32.         new_chances = max(new_chances, sum(1 for new_value in reroll_die if keep + new_value <= attribute))
  33.       fortune_numerator += new_chances
  34.   fortune_chance = fortune_numerator / (36*6.0)
  35.   print(row_template.format(attribute,
  36.       format_percent(chance),
  37.       format_percent(lucky_chance),
  38.       format_percent(fortune_chance)))
  39. def format_percent(x):
  40.   if x == 1: return "100%"
  41.   return "{:.1%}".format(x)
  42.  
  43. for n in range(8):
  44.   print_row(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement