Guest User

app.js

a guest
Dec 4th, 2021
1,471
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // source: https://stackoverflow.com/a/49434653
  2. function randn_bm() {
  3.   let u = 0, v = 0;
  4.   while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
  5.   while(v === 0) v = Math.random();
  6.   let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
  7.   num = num / 10.0 + 0.5; // Translate to 0 -> 1
  8.   if (num > 1 || num < 0) return randn_bm() // resample between 0 and 1
  9.   return num
  10. }
  11.  
  12. // source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
  13. function getRandomIntInclusive(min, max) {
  14.   min = Math.ceil(min);
  15.   max = Math.floor(max);
  16.   return Math.floor(Math.random() * (max - min + 1) + min); //The maximum is inclusive and the minimum is inclusive
  17. }
  18.  
  19. function getRandomIntInclusiveNormal(min, max) {
  20.     min = Math.ceil(min);
  21.     max = Math.floor(max);
  22.     return Math.floor(randn_bm() * (max - min + 1) + min); //The maximum is inclusive and the minimum is inclusive
  23. }
  24.  
  25. // random game time in minutes [min, max] uniform distribution
  26. function gameTimeMins(min, max) {
  27.     var minMin = Math.round(min) * 60;
  28.     var maxMin = Math.round(max) * 60;
  29.     var gameTimeSeconds = getRandomIntInclusive(minMin, maxMin);
  30.     return gameTimeSeconds / 60;
  31. }
  32.  
  33. // random game time in minutes [min, max] normal distribution
  34. function gameTimeMinsNormal(min, max) {
  35.     var minMin = Math.round(min) * 60;
  36.     var maxMin = Math.round(max) * 60;
  37.     var gameTimeSeconds = getRandomIntInclusiveNormal(minMin, maxMin);
  38.     return gameTimeSeconds / 60;
  39. }
  40.  
  41. // wr: win rate [0,1]
  42. function game(wr) {
  43.     if (Math.random() < wr) {
  44.         return 1;
  45.     }
  46.     return 0;
  47. }
  48.  
  49. // points: mission points
  50. function completeBasicMission(points) {
  51.     var games = 0;
  52.     while (points > 0) {
  53.         points -= 2 + 3 * game(0.5);
  54.         games ++;
  55.     }
  56.     return games;
  57. }
  58.  
  59. // target: misison points
  60. // win: points rate for win
  61. // loss: points rate for loss
  62. // avg: average game length
  63. // (un)comment the different length generation and rounding types to change the simulation
  64. function completePoints(target, win, loss, avg) {
  65.     var games = 0;
  66.     var points = 0;
  67.     var length = avg;
  68.  
  69.     while (points < target) {
  70.  
  71.         // uniform
  72.         length = gameTimeMins(avg * 0.5, avg * 1.5);
  73.         // normal
  74.         // length = gameTimeMinsNormal(avg * 0.5, avg * 1.5);
  75.  
  76.         // different rounding methods
  77.         length = Math.round(length);
  78.         // length = Math.ceil(length);
  79.         // length = Math.floor(length);
  80.  
  81.         if (game(0.5)) {
  82.             points += win * length;
  83.         }
  84.         else {
  85.             points += loss * length;
  86.         }
  87.         games ++;
  88.     }
  89.  
  90.     return games;
  91. }
  92.  
  93. // tries: iterations to run
  94. // mission: mission points
  95. // avg: average game length
  96. function sim(tries, mission, avg){
  97.     var totalGames = 0;
  98.     for (var i = 0; i < tries; i ++) {
  99.         totalGames += completePoints(mission, 6, 4, avg);
  100.     }
  101.     return totalGames/tries;
  102. }
  103.  
  104. // tries: iterations to run
  105. // mission: mission points
  106. // avg: average game length
  107. // reward: tokens for completing mission
  108. function simTokens(tries, mission, avg, reward) {
  109.     var gamesPerTokens = 0;
  110.     for (var i = 0; i < tries; i ++) {
  111.         gamesPerTokens += completePoints(mission, 6, 4, avg);
  112.     }
  113.     gamesPerTokens /= tries;
  114.     return reward / gamesPerTokens;
  115. }
  116.  
  117. // tries: iterations to run
  118. // mission: mission points
  119. function simOld(tries, mission){
  120.     var totalGames = 0;
  121.     for (var i = 0; i < tries; i ++) {
  122.         totalGames += completeBasicMission(mission);
  123.     }
  124.     return totalGames / tries;
  125. }
  126.  
  127. // tries: iterations to run
  128. // win: tokens for win
  129. // loss: tokens for loss
  130. function tokensOld(tries, win, loss) {
  131.     var total = 0;
  132.     for (var i = 0; i < tries; i ++) {
  133.         if (game(0.5)) {
  134.             total += win;
  135.         } else {
  136.             total += loss;
  137.         }
  138.     }
  139.     return total / tries;
  140. }
  141.  
  142. console.log("Old Weekly: ", simOld(25000000, 40));
  143. console.log("New Weekly ARAM: ", sim(25000000, 1650, 20));
  144. console.log("New Weekly SR: ", sim(25000000, 1650, 30));
  145.  
  146. console.log("Old Orb Mission: 30");
  147. console.log("New Orb Mission ARAM: ", sim(25000000, 4500, 20));
  148. console.log("New Orb Mission SR: ", sim(25000000, 4500, 30));
  149.  
  150. console.log("Old Tokens EV ARAM: ", tokensOld(25000000, 6, 3));
  151. console.log("New Tokens EV ARAM: ", simTokens(25000000, 400, 20, 20));
  152.  
  153. console.log("Old Tokens EV SR: ", tokensOld(25000000, 10, 5));
  154. console.log("New Tokens EV SR: ", simTokens(25000000, 400, 30, 20));
RAW Paste Data