Guest User

Untitled

a guest
Feb 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. from collections import namedtuple
  2.  
  3. # dice format:
  4.  
  5. Atk = namedtuple('Atk', ['damage', 'surges'])
  6.  
  7. RED_DICE = [Atk(1,0), Atk(2,0), Atk(2,0), Atk(2,1), Atk(3,0), Atk(3,0)]
  8. GREEN_DICE = [Atk(0,1), Atk(1,1), Atk(2,0), Atk(1,1), Atk(2,0), Atk(2,0)]
  9. YELLOW_DICE = [Atk(0,1), Atk(1,2), Atk(2,0), Atk(1,1), Atk(0,1), Atk(1,0)]
  10.  
  11. Def = namedtuple('Def', ['blocks', 'evades'])
  12.  
  13. BLACK_DICE = [Def(1,0), Def(1,0), Def(2,0), Def(2,0), Def(3,0), Def(0,1)]
  14.  
  15. def eval(attack, defense):
  16. total = attack.damage
  17. if (attack.surges - defense.evades) >= 1:
  18. total += 2
  19. total -= defense.blocks
  20. return max(0, total)
  21.  
  22. class Roll:
  23. def __init__(this):
  24. this.combinations = [[]]
  25.  
  26. def add(this, atk_dice):
  27. this.combinations = [existing + [new] for new in atk_dice for existing in this.combinations]
  28.  
  29. def results_against(this, def_dice):
  30. rolls = []
  31. for roll in this.combinations:
  32. current = Atk(0,0)
  33. for side in roll:
  34. current = Atk(current.damage + side.damage, current.surges + side.surges)
  35. rolls += [current]
  36. results = [eval(atk, defense) for atk in rolls for defense in def_dice]
  37. return results
  38.  
  39. def summarize(results):
  40. total = len(results)
  41. print('total: %d rolls' % (total))
  42. for level in range(0, 8):
  43. absolute = sum(1 for each in results if each >= level)
  44. print('>= {} damage: {:.3%} ({})'.format(level, absolute / float(total), absolute))
  45.  
  46. if __name__ == '__main__':
  47. sim = Roll()
  48. sim.add(RED_DICE)
  49. sim.add(GREEN_DICE)
  50. sim.add(YELLOW_DICE)
  51. summarize(sim.results_against(BLACK_DICE))
Add Comment
Please, Sign In to add comment