abbarnes

hit debuff rng sim

Feb 27th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. import random
  2.  
  3. def run_test(swings, trials, miss_chance):
  4.     base_miss_chance = 20
  5.     damage = 1.0
  6.     trial_max_damage = damage * swings
  7.    
  8.     #initialize values calculated in trials
  9.     slowed_damage = 0.0    #average calculated on fly during trials
  10.     average_damage = 0.0    
  11.  
  12.     #tallys for keeping track of # of trials that damage reduction surpassed that of the slow and of 10% of base        
  13.     damage_reduction_matched_slow = 0
  14.     damage_reduction_over_10 = 0
  15.  
  16.     #TRIALS FOR SLOW + 20% MISS
  17.     slow_swings = int(float(swings)/1.1)                    #calculate number of swings made while slowed.  int function rounds it off.
  18.     for trial in range(trials):                             #iterate trials
  19.         trial_damage = 0                        
  20.         for swing in range(slow_swings):  
  21.             if hit(base_miss_chance):          
  22.                 trial_damage += 1.0                         #add to trial damage if hit returns True
  23.         slowed_damage += trial_damage/float(trials)         #trial's damage to the average for all trials
  24.        
  25.    
  26.     #TRIAL FOR 10% MISS AND 20% MISS
  27.     for trial in range(trials):
  28.         trial_damage = 0
  29.         for swing in range(swings):
  30.             if hit(miss_chance + base_miss_chance):
  31.                 trial_damage += 1.0
  32.  
  33.         #Check if the damage from the hit debuff trial matches the average from the slow debuff trials.  If so, increment tally.        
  34.         matched_slow = trial_damage <= slowed_damage
  35.         if matched_slow:
  36.              damage_reduction_matched_slow += 1
  37.  
  38.         #Check if the additional (over base case) damage reduction from the hit debuff is >= 10% of base damage.  If so, increment tally.
  39.         trial_diff = trial_max_damage * 0.8 - trial_damage
  40.         mached_10_percent = (trial_diff)/trial_max_damage >= 0.1
  41.         if mached_10_percent:
  42.             damage_reduction_over_10 += 1
  43.  
  44.         #Add trial's damage to the average for all trials                          
  45.         average_damage += trial_damage / float(trials)
  46.  
  47.     #PRINT RESULTS    
  48.     print("Expected damage without debuffs: ", trial_max_damage * .8)
  49.     print("Damage reduction exceeded 10% of expected damage (80% hit, 0% slow) on", damage_reduction_over_10, " trials out of ", trials)
  50.     print("Damage reduction exceeded slow (80% hit, 10% slow) on", damage_reduction_matched_slow, " trials out of ", trials)
  51.     print("Net Percent Damage reduction from hit debuff (70% hit, 0% slow): ", ((1-average_damage/trial_max_damage)*100))
  52.     print("Net Percent Damage reduction from slow debuff (80% hit, 10% slow): ", ((1-slowed_damage/trial_max_damage)*100))
  53.  
  54.     return
  55.  
  56. def hit(miss_chance):
  57.     '''Helper function.  returns true if RNG results in a hit, false if not'''
  58.     return random.randrange(1, 101) > miss_chance
  59.  
  60.  
  61. run_test(100,10000,10)
Advertisement
Add Comment
Please, Sign In to add comment