Pauan

Monte Carlo simulation of Faeria damage pings

Jun 16th, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculatePings(pings, targets) {
  2.   var success = 0;
  3.   var failure = 0;
  4.  
  5.   next: for (var i = 0; i < 70000000; ++i) {
  6.     var a = targets.map(function (x, i) {
  7.       return {
  8.         health: x.health,
  9.         index: i
  10.       };
  11.     });
  12.  
  13.     for (var j = 0; j < pings; ++j) {
  14.       var index = Math.floor(Math.random() * (a.length + 1));
  15.  
  16.       var card = a[index];
  17.  
  18.       if (index !== a.length) {
  19.         --card.health;
  20.  
  21.         if (card.health === 0) {
  22.           a.splice(index, 1);
  23.         }
  24.       }
  25.     }
  26.  
  27.     for (var j = 0; j < a.length; ++j) {
  28.       var card = a[j];
  29.  
  30.       if (card.health > targets[card.index].max) {
  31.         ++failure;
  32.         continue next;
  33.       }
  34.     }
  35.  
  36.     ++success;
  37.   }
  38.  
  39.   return (success / (success + failure)) * 100;
  40. }
  41.  
  42. console.log(calculatePings(4, [{ max: 8, health: 10 }]));
Advertisement
Add Comment
Please, Sign In to add comment