abbarnes icon

hit debuff rng sim

abbarnes | PRO | 02/27/19 03:02:09 PM UTC | 0 ⭐ | 215 👁️ | Never ⏰ | []
Python |

2.83 KB

|

None

|

0 👍

/

0 👎

import random
 
def run_test(swings, trials, miss_chance):
    base_miss_chance = 20
    damage = 1.0
    trial_max_damage = damage * swings
    
    #initialize values calculated in trials
    slowed_damage = 0.0    #average calculated on fly during trials
    average_damage = 0.0     
 
    #tallys for keeping track of # of trials that damage reduction surpassed that of the slow and of 10% of base         
    damage_reduction_matched_slow = 0
    damage_reduction_over_10 = 0
 
    #TRIALS FOR SLOW + 20% MISS
    slow_swings = int(float(swings)/1.1)                    #calculate number of swings made while slowed.  int function rounds it off.
    for trial in range(trials):                             #iterate trials
        trial_damage = 0                        
        for swing in range(slow_swings):  
            if hit(base_miss_chance):           
                trial_damage += 1.0                         #add to trial damage if hit returns True
        slowed_damage += trial_damage/float(trials)         #trial's damage to the average for all trials
       
    
    #TRIAL FOR 10% MISS AND 20% MISS
    for trial in range(trials):
        trial_damage = 0
        for swing in range(swings):
            if hit(miss_chance + base_miss_chance):
                trial_damage += 1.0
 
        #Check if the damage from the hit debuff trial matches the average from the slow debuff trials.  If so, increment tally.        
        matched_slow = trial_damage <= slowed_damage
        if matched_slow:
             damage_reduction_matched_slow += 1
 
        #Check if the additional (over base case) damage reduction from the hit debuff is >= 10% of base damage.  If so, increment tally. 
        trial_diff = trial_max_damage * 0.8 - trial_damage
        mached_10_percent = (trial_diff)/trial_max_damage >= 0.1
        if mached_10_percent:
            damage_reduction_over_10 += 1
 
        #Add trial's damage to the average for all trials                           
        average_damage += trial_damage / float(trials)
 
    #PRINT RESULTS    
    print("Expected damage without debuffs: ", trial_max_damage * .8)
    print("Damage reduction exceeded 10% of expected damage (80% hit, 0% slow) on", damage_reduction_over_10, " trials out of ", trials)
    print("Damage reduction exceeded slow (80% hit, 10% slow) on", damage_reduction_matched_slow, " trials out of ", trials)
    print("Net Percent Damage reduction from hit debuff (70% hit, 0% slow): ", ((1-average_damage/trial_max_damage)*100))
    print("Net Percent Damage reduction from slow debuff (80% hit, 10% slow): ", ((1-slowed_damage/trial_max_damage)*100))
 
    return 
 
def hit(miss_chance):
    '''Helper function.  returns true if RNG results in a hit, false if not'''
    return random.randrange(1, 101) > miss_chance
 
 
run_test(100,10000,10)

Comments