Guest User

Untitled

a guest
Jul 1st, 2016
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. hitogram = collections.Counter(sum(x) for x in itertools.product(gray_die, black_die))
  8.  
  9. row_template = """\
  10. |-
  11. | style="text-align:center;"| {}
  12. | style="text-align:right;" | {}
  13. | style="text-align:right;" | {}
  14. | style="text-align:right;" | {}
  15. | style="text-align:right;" | {}\
  16. """
  17.  
  18. def chance_for_attribute(attribute):
  19.   return sum(frequency for (roll,frequency) in hitogram.items() if roll <= attribute) / 36.0
  20.  
  21. def print_row(attribute):
  22.   # to calculate the plain odds, count how many of the 36 outcomes are favorable
  23.   chance = chance_for_attribute(attribute)
  24.   # lucky charm lets you reroll if you fail, so it's the inverse probability of losing twice in a row
  25.   lucky_chance = 1 - (1 - chance)**2
  26.  
  27.   # dark fortune makes things complicated. we need to pick one of the dice to reroll
  28.   fortune_numerator = 0
  29.   for (g, b) in itertools.product(gray_die, black_die):
  30.     if g + b <= attribute:
  31.       # no need to use dark fortune. effectively the reroll is guaranteed success
  32.       fortune_numerator += 6
  33.     else:
  34.       # see what would happen if we rerolled either one, and choose the best outcome
  35.       new_chances = 0
  36.       for keep, reroll_die in [(b, gray_die), (g, black_die)]:
  37.         new_chances = max(new_chances, sum(1 for new_value in reroll_die if keep + new_value <= attribute))
  38.       fortune_numerator += new_chances
  39.   fortune_chance = fortune_numerator / (36*6.0)
  40.  
  41.   # wicked laughter makes the hero retry at a -1 attribute penalty after succeeding
  42.   wicked_chance = chance * chance_for_attribute(max(attribute - 1, 0))
  43.  
  44.   print(row_template.format(attribute,
  45.       format_percent(chance),
  46.       format_percent(lucky_chance),
  47.       format_percent(fortune_chance),
  48.       format_percent(wicked_chance)))
  49.  
  50. def format_percent(x):
  51.   if x == 1: return "100%"
  52.   return "{:.1%}".format(x)
  53.  
  54. for n in range(8):
  55.   print_row(n)
RAW Paste Data