Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace RatingSimulator
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- Player[] players;
- int k = 36;
- int F = 400;
- public MainWindow()
- {
- InitializeComponent();
- }
- public void makePlayers()
- {
- Random rand = new Random(); //reuse this if you are generating many
- players = new Player[Convert.ToInt32(textBox1.Text)];
- int one = 0, two = 0, three = 0, four = 0, five = 0;
- for (int i = 0; i < players.Length; i++)
- {
- double u1 = rand.NextDouble(); //these are uniform(0,1) random doubles
- double u2 = u1 * 100;
- double x = 0;
- if (u2 < 31.46)
- {
- double x1 = rand.NextDouble();
- double x2 = x1 * 100;
- int tierNum = 800;
- if (x2 < 9.3)
- {
- x = (x1 * 70) + tierNum;
- }
- else if (x2 < 27.8)
- {
- x = (x1 * 70) + 70 + tierNum;
- }
- else if (x2 < 49.7)
- {
- x = (x1 * 70) + 140 + tierNum;
- }
- else if (x2 < 71.0)
- {
- x = (x1 * 70) + 210 + tierNum;
- }
- else
- {
- x = (x1 * 70) + 280 + tierNum;
- }
- }
- else if (u2 < 74.3)
- {
- double x1 = rand.NextDouble();
- double x2 = x1 * 100;
- int tierNum = 1150;
- if (x2 < 30.1)
- {
- x = (x1 * 70) + tierNum;
- }
- else if (x2 < 49.4)
- {
- x = (x1 * 70) + 70 + tierNum;
- }
- else if (x2 < 68.0)
- {
- x = (x1 * 70) + 140 + tierNum;
- }
- else if (x2 < 82.5)
- {
- x = (x1 * 70) + 210 + tierNum;
- }
- else
- {
- x = (x1 * 70) + 280 + tierNum;
- }
- }
- else if (u2 < 91.7)
- {
- double x1 = rand.NextDouble();
- double x2 = x1 * 100;
- int tierNum = 1500;
- if (x2 < 47.9)
- {
- x = (x1 * 70) + tierNum;
- }
- else if (x2 < 60.9)
- {
- x = (x1 * 70) + 70 + tierNum;
- }
- else if (x2 < 76.5)
- {
- x = (x1 * 70) + 140 + tierNum;
- }
- else if (x2 < 86.8)
- {
- x = (x1 * 70) + 210 + tierNum;
- }
- else
- {
- x = (x1 * 70) + 280 + tierNum;
- }
- }
- else if (u2 < 98.1)
- {
- double x1 = rand.NextDouble();
- double x2 = x1 * 100;
- int tierNum = 1850;
- if (x2 < 42.7)
- {
- x = (x1 * 70) + tierNum;
- }
- else if (x2 < 56.4)
- {
- x = (x1 * 70) + 70 + tierNum;
- }
- else if (x2 < 71.0)
- {
- x = (x1 * 70) + 140 + tierNum;
- }
- else if (x2 < 81.6)
- {
- x = (x1 * 70) + 210 + tierNum;
- }
- else
- {
- x = (x1 * 70) + 280 + tierNum;
- }
- }
- else
- {
- double x1 = rand.NextDouble();
- double x2 = x1 * 100;
- int tierNum = 2200;
- if (x2 < 44.3)
- {
- x = (x1 * 70) + tierNum;
- }
- else if (x2 < 57.6)
- {
- x = (x1 * 70) + 70 + tierNum;
- }
- else if (x2 < 69.1)
- {
- x = (x1 * 70) + 140 + tierNum;
- }
- else if (x2 < 78.7)
- {
- x = (x1 * 70) + 210 + tierNum;
- }
- else
- {
- x = (x1 * 70) + 280 + tierNum;
- }
- }
- players[i] = new Player((int)Math.Floor(x));
- int x3 = (int)Math.Floor(x);
- if(x3 > 2200) {
- one++;
- } else if(x3 > 1850) {
- two++;
- } else if (x3 > 1500) {
- three++;
- } else if (x3 > 1150) {
- four++;
- } else {
- five++;
- }
- }
- Array.Sort(players);
- label1.Content = one;
- label2.Content = two;
- label3.Content = three;
- label4.Content = four;
- label5.Content = five;
- doOutInSide();
- }
- public void playGames()
- {
- Random ran = new Random();
- for (int i = 0; i < players.Length; i = i + 10)
- {
- int teamOne = players[i].TrueRating + players[i + 1].TrueRating + players[i + 2].TrueRating + players[i + 3].TrueRating + players[i + 4].TrueRating;
- int teamTwo = players[i + 5].TrueRating + players[i + 6].TrueRating + players[i + 7].TrueRating + players[i + 8].TrueRating + players[i + 9].TrueRating;
- double team1 = teamOne / 5;
- double team2 = teamTwo / 5;
- double winChance1 = 1 / (1 + (Math.Pow(10, (team2 - team1) / 400)));
- double winChance2 = 1 / (1 + (Math.Pow(10, (team1 - team2) / 400)));
- double x = ran.NextDouble();
- if (x < winChance1) //team one win.
- {
- players[i].Rating = players[i].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i].Rating) / F)))))));
- players[i + 1].Rating = players[i + 1].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 1].Rating) / F)))))));
- players[i + 2].Rating = players[i + 2].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 2].Rating) / F)))))));
- players[i + 3].Rating = players[i + 3].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 3].Rating) / F)))))));
- players[i + 4].Rating = players[i + 4].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 4].Rating) / F)))))));
- players[i + 5].Rating = players[i + 5].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 5].Rating) / F)))))));
- players[i + 6].Rating = players[i + 6].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 6].Rating) / F)))))));
- players[i + 7].Rating = players[i + 7].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 7].Rating) / F)))))));
- players[i + 8].Rating = players[i + 8].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 8].Rating) / F)))))));
- players[i + 9].Rating = players[i + 9].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 9].Rating) / F)))))));
- }
- else //team two win.
- {
- players[i].Rating = players[i].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i].Rating) / F)))))));
- players[i + 1].Rating = players[i + 1].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 1].Rating) / F)))))));
- players[i + 2].Rating = players[i + 2].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 2].Rating) / F)))))));
- players[i + 3].Rating = players[i + 3].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 3].Rating) / F)))))));
- players[i + 4].Rating = players[i + 4].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 4].Rating) / F)))))));
- players[i + 5].Rating = players[i + 5].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 5].Rating) / F)))))));
- players[i + 6].Rating = players[i + 6].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 6].Rating) / F)))))));
- players[i + 7].Rating = players[i + 7].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 7].Rating) / F)))))));
- players[i + 8].Rating = players[i + 8].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 8].Rating) / F)))))));
- players[i + 9].Rating = players[i + 9].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 9].Rating) / F)))))));
- }
- }
- Array.Sort(players);
- }
- private void doOutInSide() {
- int inside = 0;
- int outside = 0;
- int x = 0;
- int y = 0;
- int[] z = new int[players.Length];
- int q = 0;
- foreach (Player i in players)
- {
- if (Math.Abs(i.Rating - i.TrueRating) < 100)
- {
- inside++;
- }
- else
- {
- outside++;
- }
- x = x + i.Rating;
- y = y + Math.Abs(i.Rating - i.TrueRating);
- z[q] = Math.Abs(i.Rating - i.TrueRating);
- q++;
- }
- labelInside.Content = "Inside: " + inside;
- labelOutside.Content = "Outside: " + outside;
- labelStuff.Content = (x / players.Length) + " - " + (z.Max());
- }
- private void bPopulate_Click(object sender, RoutedEventArgs e)
- {
- makePlayers();
- }
- private void bSimulate_Click(object sender, RoutedEventArgs e)
- {
- int c = Convert.ToInt32(textBox2.Text);
- int one = 0, two = 0, three = 0, four = 0, five = 0;
- labelGame.Content = "On Game 1";
- for (int i = 0; i < c; i++)
- {
- labelGame.Content = "On Game " + (i + 1);
- one = 0; two = 0; three = 0; four = 0; five = 0;
- foreach (Player d in players)
- {
- int x3 = d.Rating;
- if (x3 > 2200)
- {
- one++;
- }
- else if (x3 > 1850)
- {
- two++;
- }
- else if (x3 > 1500)
- {
- three++;
- }
- else if (x3 > 1150)
- {
- four++;
- }
- else
- {
- five++;
- }
- }
- label11.Content = one;
- label22.Content = two;
- label33.Content = three;
- label44.Content = four;
- label55.Content = five;
- doOutInSide();
- System.Windows.Forms.Application.DoEvents();
- playGames();
- }
- one = 0; two = 0; three = 0; four = 0; five = 0;
- foreach (Player d in players)
- {
- int x3 = d.Rating;
- if (x3 > 2200)
- {
- one++;
- }
- else if (x3 > 1850)
- {
- two++;
- }
- else if (x3 > 1500)
- {
- three++;
- }
- else if (x3 > 1150)
- {
- four++;
- }
- else
- {
- five++;
- }
- }
- label11.Content = one;
- label22.Content = two;
- label33.Content = three;
- label44.Content = four;
- label55.Content = five;
- }
- private void bOutside_Click(object sender, RoutedEventArgs e)
- {
- doOutInSide();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment