Advertisement
Chiddix

RuneScape combat calculator

Apr 19th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. package fearme;
  2.  
  3. public final class RuneScape {
  4.  
  5.     private static void combat(final double[] health, final double oaccuracy, final double obase_damage) {
  6.         for (int i = 1; i < health.length; i++) {
  7.             for (int j = 1; j < obase_damage; j++) {
  8.                 if (i - j >= 0) {
  9.                     health[i + j] += oaccuracy * health[j] / obase_damage;
  10.                 } else {
  11.                     health[0] += oaccuracy * health[j] / obase_damage;
  12.                 }
  13.                 health[j] *= 1 - oaccuracy;
  14.                 health[j] += oaccuracy * health[j] / obase_damage;
  15.             }
  16.         }
  17.     }
  18.  
  19.     private static void statistics(double p, double win, double loss, final double[] health, final double[] ohealth) {
  20.         double temp = 1 - (1 - health[0]) * (1 - ohealth[0]);
  21.         temp -= p;
  22.         if (health[0] > 0 || ohealth[0] > 0) {
  23.             win += temp * (ohealth[0] / (ohealth[0] + health[0]));
  24.             loss += temp * (health[0] / (ohealth[0] + health[0]));
  25.         }
  26.         p += temp;
  27.     }
  28.  
  29.     private static void create_health(final double[] health, final double constitution) {
  30.         for (int i = 0; i < constitution * 10; i++) {
  31.             health[i] = 0;
  32.         }
  33.         health[health.length - 1] = 1;
  34.     }
  35.  
  36.     public static void main(final String[] args) {
  37.         // you
  38.         final double attack = 99;
  39.         final double strength = 99;
  40.         final double defence = 99;
  41.         final double constitution = 99;
  42.  
  43.         // opponent
  44.         final double oattack = 99;
  45.         final double ostrength = 99;
  46.         final double odefence = 99;
  47.         final double oconstitution = 99;
  48.  
  49.         final double effective_attack = 10 * (attack + 8 + 3); // 5/8 from standard formula, 3 from style bonus
  50.         final double effective_strength = strength + 8;
  51.         final double base_damage = effective_strength + 5;
  52.         final double effective_defence = 10 * (defence + 8);
  53.         final double oeffective_attack = 10 * (oattack + 8 + 3);
  54.         final double oeffective_strength = ostrength + 8;
  55.         final double obase_damage = oeffective_strength + 5;
  56.         final double oeffective_defence = 10 * (odefence + 8);
  57.         double accuracy;
  58.         double oaccuracy;
  59.  
  60.         if (attack < odefence) {
  61.             accuracy = (effective_attack - 1) / (2 * oeffective_defence);
  62.         } else {
  63.             accuracy = 1 - (oeffective_defence + 1) / (2 * effective_attack);
  64.         }
  65.         if (oattack < defence) {
  66.             oaccuracy = (oeffective_attack - 1) / (2 * effective_defence);
  67.         } else {
  68.             oaccuracy = 1 - (effective_defence + 1) / (2 * oeffective_attack);
  69.         }
  70.  
  71.         System.out.println("Your accuarcy: " + accuracy);
  72.         System.out.println("Opponnent's accuracy: " + oaccuracy);
  73.  
  74.         final double[] health = new double[(int) (constitution * 10)];
  75.         final double[] ohealth = new double[(int) (oconstitution * 10)];
  76.  
  77.         create_health(health, constitution);
  78.         create_health(ohealth, oconstitution);
  79.  
  80.         final double p = 0;
  81.         final double win = 0;
  82.         final double loss = 0;
  83.         for (int hit = 0; win + loss < 0.99 && hit < 1000; hit++) {
  84.             combat(health, oaccuracy, obase_damage);
  85.             combat(ohealth, accuracy, base_damage);
  86.             statistics(p, win, loss, health, ohealth);
  87.         }
  88.         System.out.println("Your win chance: " + win);
  89.         System.out.println("Opponent's win cahnce: " + loss);
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement