Talk:Repair (equipment)

Proof that it does matter when you repair (by anonymous user)
a. The chance of permanent damage is inversely proportional to the ratio of current durability to maximum durability. b. Many weapons have max durability over 100, such as 115. c. DDO uses simulated dice-rolling for random numbers. d. Dice can only return integers. e. Expressed as an integer, 1/115 is a 0% chance of permanent damage. f. Therefore, repair often enough, and the weapon will never be permanently damaged.


 * I don't know if it's a joke, or a serious attempt at demonstrating something. Since you always repair before the durability is zero, the fraction is always a real number less than 1, and truncating as per usual D&D practice would always return a 0% chance of permanent damage. Thus there would never be any permanent damage in game. Tihocan 11:32, August 16, 2006 (EDT)

Simulation confirming the mathematical analysis
I wrote a short piece of code to simulate DDO repairs. It considers an item of initial durability 100, and compares the lifespan of the object depending on the repair strategy (repairing every x amount of temporary damage). This is done 1 million times, then it outputs the average lifespan, as well as a 95% confidence interval.

The meaning of this confidence interval is as follows: in 95% of cases, the lifespan was comprised between (avg - i) and (avg + i), where avg is the average lifespan and i the value given for the confidence interval: the higher the confidence interval, the less likely you are to be near the average lifespan.

Here are the results:
 * Repair every 1 damage: avg = 1542, i = 675
 * Repair every 2 damage: avg = 1541, i = 670
 * Repair every 5 damage: avg = 1542, i = 658
 * Repair every 10 damage: avg = 1543, i = 639
 * Repair every 20 damage: avg = 1542, i = 592
 * Repair every 50 damage: avg = 1541, i = 400
 * Repair every 90 damage: avg = 1542, i = 133

And here is the code: int main(int argc, char** argv) {    if (argc < 3) { printf("Usage: repair   \n"); return 1; }    // Parse command-line arguments. int c = 1; int n_tries = atoi(argv[c++]); int item_durability = atoi(argv[c++]); int repair_every = atoi(argv[c++]); const char* output_file = argv[c++]; // Initialize random seed. time_t t;    time(&t); srand((unsigned int) t); // Max lifespan we think we can possibly get (only limited by the computer    // memory). If really too low, results may not be accurate. // The i-th element is the number of times the item's lifespan has been // equal to i, among the 'n_tries' tries. int max_lifespan = 1000000; int count_lifespan[max_lifespan]; for (int i = 0; i < max_lifespan; i++) count_lifespan[i] = 0; int n_valid_tries = 0; // Main loop: average over 'n_tries' tries. for (int i = 0; i < n_tries; i++) { int current_max_durability = item_durability; int current_permanent_damage = 0; int current_durability = current_max_durability; int lifespan = 0; int temp_damage = 0; while (current_durability > 0) { // Each iteration brings one additional point of temporary damage. temp_damage++; current_durability--; lifespan++; if (temp_damage == repair_every || current_durability == 0) { // Time to repair. double chance_of_success = current_durability / double(current_max_durability); double random_0_1 = rand / (RAND_MAX + 1.0); if (random_0_1 >= chance_of_success) { // Failure: get new permanent damage. int new_perm_damage; if (current_permanent_damage == 0) new_perm_damage = 1; else new_perm_damage = int(sqrt(current_permanent_damage)); current_max_durability -= new_perm_damage; current_permanent_damage += new_perm_damage; }                // Item is repaired now. temp_damage = 0; current_durability = current_max_durability; }        }         if (lifespan < max_lifespan) { n_valid_tries++; count_lifespan[lifespan]++; }    }     // Scale the results to obtain a frequency, between 0 and 1. if (n_valid_tries == 0) { printf("Could not perform any valid try, something is wrong\n"); return 1; }    int max_lifespan_found = 0; // Will store the highest lifespan encountered. double freq_lifespan[max_lifespan]; for (int i = 0; i < max_lifespan; i++) { int count = count_lifespan[i]; freq_lifespan[i] = count / double(n_valid_tries); if (count > 0) max_lifespan_found = i;    } // Compute average and 95% confidence interval. double avg = 0; for (int i = 0; i <= max_lifespan_found; i++) avg += freq_lifespan[i] * i;    int avg_int = int(round(avg)); double cumul = freq_lifespan[avg_int]; int interval = 0; while (cumul <= 0.95) { interval++; if (avg_int + interval < max_lifespan) cumul += freq_lifespan[avg_int + interval]; if (avg_int - interval >= 0) cumul += freq_lifespan[avg_int - interval]; }    interval--; printf("Average lifespan: %d\n", avg_int); printf("95 percent confidence interval: %d\n", interval); return 0; }
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 