Advertisement
ferraridriveby

WG Ranked Battle Simulator

Sep 6th, 2019
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.35 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WGRankedSim
  4. {
  5.     class Program
  6.     {
  7.         static Random r = new Random();
  8.  
  9.         //WG's bracket league system
  10.         static int[] brackets = new int[] { 300, 400, 500, 600, 700, 800, 900, 1000 };
  11.  
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             //number of trials to run
  16.             int games = 100000;
  17.  
  18.             //average player
  19.  
  20.             /*
  21.             int winrate = 50;
  22.  
  23.             double[] probability = {
  24.                 100.0 / 7, //1st
  25.                 100.0 / 7,
  26.                 100.0 / 7,
  27.                 100.0 / 7,
  28.                 100.0 / 7,
  29.                 100.0 / 7,
  30.                 100.0 / 7
  31.             };
  32.             */
  33.  
  34.             //uni player
  35.  
  36.             int winrate = 60;
  37.  
  38.             double[] probability = {
  39.                 20, //1st
  40.                 20,
  41.                 20,
  42.                 10,
  43.                 10,
  44.                 10,
  45.                 10
  46.             };
  47.            
  48.             //run simulations
  49.  
  50.             double avgOldGames = runOldSimulation(games, winrate, probability[0]);
  51.             Console.WriteLine("Average Old Games {0}", avgOldGames);
  52.  
  53.             double avgNewGames = runNewSimulation(100000, winrate, probability);
  54.             Console.WriteLine("Average New Games {0}", avgNewGames);
  55.         }
  56.  
  57.         static double runOldSimulation(int trials, double avgWinRate, double avgTopRate)
  58.         {
  59.             //collate results
  60.             int[] results = new int[trials];
  61.  
  62.             for(int i = 0; i < trials; i++)
  63.             {
  64.                 int totalPoints = 0; //sanity check -- adding to 5200 is correct. <--- this passed.
  65.  
  66.                 //default player configuration
  67.                 int curPoints = 0;
  68.                 int curBracket = 0;
  69.  
  70.                 int totalGames = 0;
  71.  
  72.                 //run simulation until final league is reached
  73.                 do
  74.                 {
  75.                     //win = under probability distri of rate
  76.                     bool win = r.Next(1, 101) <= avgWinRate;
  77.  
  78.                     if (win)
  79.                     {
  80.                         curPoints += 100;
  81.                         totalPoints += 100;
  82.                     }
  83.                     else
  84.                     {
  85.                         //top roll is separate from win roll (for obvious reasons)
  86.                         bool top = r.Next(1, 101) <= avgTopRate;
  87.                         if (curPoints > 0 && !top)
  88.                         {
  89.                             curPoints -= 100;
  90.                             totalPoints -= 100;
  91.                         }
  92.                     }
  93.  
  94.                     totalGames++;
  95.  
  96.                     if (curPoints == brackets[curBracket])
  97.                     {
  98.                         curPoints = 100;
  99.                         curBracket++;
  100.                     }
  101.                 }
  102.                 while (curBracket != brackets.Length);
  103.  
  104.                 results[i] = totalGames;
  105.                
  106.             }
  107.  
  108.             //compute average number of games
  109.  
  110.             double avgGames = 0;
  111.  
  112.             for(int i = 0; i < trials; i++)
  113.             {
  114.                 avgGames += results[i];
  115.             }
  116.  
  117.             return avgGames / trials;
  118.  
  119.         }
  120.  
  121.         //WG's new system
  122.         static int[] winPoints = new int[] { 100, 85, 70, 55, 40, 25, 10 };
  123.         static int[] lossPoints = new int[] { 0, -15, -30, -45, -60, -75, -90 };
  124.  
  125.         static double runNewSimulation(int trials, double avgWinRate, double[] probSet)
  126.         {
  127.             int[] results = new int[trials];
  128.  
  129.             for (int i = 0; i < trials; i++)
  130.             {
  131.                 int curPoints = 0;
  132.                 int curBracket = 0;
  133.  
  134.                 int totalGames = 0;
  135.  
  136.                 do
  137.                 {
  138.                     bool win = r.Next(1, 101) <= avgWinRate;
  139.                     double placevalue = r.Next(1, 101);
  140.  
  141.                     double sumprob = 0;
  142.  
  143.                     int spot = 0;
  144.  
  145.                     for(int j = 0; j < 7; j++)
  146.                     {
  147.                         sumprob += probSet[j];
  148.                         if (sumprob > placevalue)
  149.                         {
  150.                             spot = j;
  151.                             break;
  152.                         }
  153.                     }
  154.  
  155.                     if (win)
  156.                     {
  157.                         curPoints += winPoints[spot];
  158.                     }
  159.                     else
  160.                     {
  161.                         //only deduct points if it brings us above zero
  162.                         if(curPoints + lossPoints[spot] >= 0)
  163.                             curPoints += lossPoints[spot];
  164.                     }
  165.  
  166.                     totalGames++;
  167.  
  168.                     //need to check greater condition here since it's no longer a clean divisor of 100
  169.                     if (curPoints >= brackets[curBracket])
  170.                     {
  171.                         curPoints = 100;
  172.                         curBracket++;
  173.                     }
  174.                 }
  175.                 while (curBracket != brackets.Length);
  176.  
  177.                 results[i] = totalGames;
  178.  
  179.             }
  180.  
  181.             double avgGames = 0;
  182.  
  183.             for (int i = 0; i < trials; i++)
  184.             {
  185.                 avgGames += results[i];
  186.             }
  187.  
  188.             return avgGames / trials;
  189.  
  190.         }
  191.  
  192.  
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement