Guest User

Untitled

a guest
Oct 28th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Runtime.InteropServices;
  16. using System.Windows.Forms;
  17.  
  18. namespace RatingSimulator
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window
  24. {
  25.  
  26. Player[] players;
  27. int k = 36;
  28. int F = 400;
  29.  
  30. public MainWindow()
  31. {
  32. InitializeComponent();
  33. }
  34.  
  35. public void makePlayers()
  36. {
  37.  
  38. Random rand = new Random(); //reuse this if you are generating many
  39. players = new Player[Convert.ToInt32(textBox1.Text)];
  40.  
  41.  
  42. int one = 0, two = 0, three = 0, four = 0, five = 0;
  43.  
  44. for (int i = 0; i < players.Length; i++)
  45. {
  46. double u1 = rand.NextDouble(); //these are uniform(0,1) random doubles
  47. double u2 = u1 * 100;
  48. double x = 0;
  49.  
  50. if (u2 < 31.46)
  51. {
  52. double x1 = rand.NextDouble();
  53. double x2 = x1 * 100;
  54.  
  55. int tierNum = 800;
  56.  
  57. if (x2 < 9.3)
  58. {
  59. x = (x1 * 70) + tierNum;
  60. }
  61. else if (x2 < 27.8)
  62. {
  63. x = (x1 * 70) + 70 + tierNum;
  64. }
  65. else if (x2 < 49.7)
  66. {
  67. x = (x1 * 70) + 140 + tierNum;
  68. }
  69. else if (x2 < 71.0)
  70. {
  71. x = (x1 * 70) + 210 + tierNum;
  72. }
  73. else
  74. {
  75. x = (x1 * 70) + 280 + tierNum;
  76. }
  77. }
  78. else if (u2 < 74.3)
  79. {
  80. double x1 = rand.NextDouble();
  81. double x2 = x1 * 100;
  82.  
  83. int tierNum = 1150;
  84.  
  85. if (x2 < 30.1)
  86. {
  87. x = (x1 * 70) + tierNum;
  88. }
  89. else if (x2 < 49.4)
  90. {
  91. x = (x1 * 70) + 70 + tierNum;
  92. }
  93. else if (x2 < 68.0)
  94. {
  95. x = (x1 * 70) + 140 + tierNum;
  96. }
  97. else if (x2 < 82.5)
  98. {
  99. x = (x1 * 70) + 210 + tierNum;
  100. }
  101. else
  102. {
  103. x = (x1 * 70) + 280 + tierNum;
  104. }
  105. }
  106. else if (u2 < 91.7)
  107. {
  108. double x1 = rand.NextDouble();
  109. double x2 = x1 * 100;
  110.  
  111. int tierNum = 1500;
  112.  
  113. if (x2 < 47.9)
  114. {
  115. x = (x1 * 70) + tierNum;
  116. }
  117. else if (x2 < 60.9)
  118. {
  119. x = (x1 * 70) + 70 + tierNum;
  120. }
  121. else if (x2 < 76.5)
  122. {
  123. x = (x1 * 70) + 140 + tierNum;
  124. }
  125. else if (x2 < 86.8)
  126. {
  127. x = (x1 * 70) + 210 + tierNum;
  128. }
  129. else
  130. {
  131. x = (x1 * 70) + 280 + tierNum;
  132. }
  133. }
  134. else if (u2 < 98.1)
  135. {
  136. double x1 = rand.NextDouble();
  137. double x2 = x1 * 100;
  138.  
  139. int tierNum = 1850;
  140.  
  141. if (x2 < 42.7)
  142. {
  143. x = (x1 * 70) + tierNum;
  144. }
  145. else if (x2 < 56.4)
  146. {
  147. x = (x1 * 70) + 70 + tierNum;
  148. }
  149. else if (x2 < 71.0)
  150. {
  151. x = (x1 * 70) + 140 + tierNum;
  152. }
  153. else if (x2 < 81.6)
  154. {
  155. x = (x1 * 70) + 210 + tierNum;
  156. }
  157. else
  158. {
  159. x = (x1 * 70) + 280 + tierNum;
  160. }
  161. }
  162. else
  163. {
  164. double x1 = rand.NextDouble();
  165. double x2 = x1 * 100;
  166.  
  167. int tierNum = 2200;
  168.  
  169. if (x2 < 44.3)
  170. {
  171. x = (x1 * 70) + tierNum;
  172. }
  173. else if (x2 < 57.6)
  174. {
  175. x = (x1 * 70) + 70 + tierNum;
  176. }
  177. else if (x2 < 69.1)
  178. {
  179. x = (x1 * 70) + 140 + tierNum;
  180. }
  181. else if (x2 < 78.7)
  182. {
  183. x = (x1 * 70) + 210 + tierNum;
  184. }
  185. else
  186. {
  187. x = (x1 * 70) + 280 + tierNum;
  188. }
  189. }
  190.  
  191. players[i] = new Player((int)Math.Floor(x));
  192.  
  193. int x3 = (int)Math.Floor(x);
  194.  
  195. if(x3 > 2200) {
  196. one++;
  197. } else if(x3 > 1850) {
  198. two++;
  199. } else if (x3 > 1500) {
  200. three++;
  201. } else if (x3 > 1150) {
  202. four++;
  203. } else {
  204. five++;
  205. }
  206.  
  207. }
  208.  
  209. Array.Sort(players);
  210.  
  211. label1.Content = one;
  212. label2.Content = two;
  213. label3.Content = three;
  214. label4.Content = four;
  215. label5.Content = five;
  216. doOutInSide();
  217.  
  218. }
  219.  
  220. public void playGames()
  221. {
  222. Random ran = new Random();
  223. for (int i = 0; i < players.Length; i = i + 10)
  224. {
  225. int teamOne = players[i].TrueRating + players[i + 1].TrueRating + players[i + 2].TrueRating + players[i + 3].TrueRating + players[i + 4].TrueRating;
  226. int teamTwo = players[i + 5].TrueRating + players[i + 6].TrueRating + players[i + 7].TrueRating + players[i + 8].TrueRating + players[i + 9].TrueRating;
  227.  
  228. double team1 = teamOne / 5;
  229. double team2 = teamTwo / 5;
  230.  
  231. double winChance1 = 1 / (1 + (Math.Pow(10, (team2 - team1) / 400)));
  232. double winChance2 = 1 / (1 + (Math.Pow(10, (team1 - team2) / 400)));
  233.  
  234. double x = ran.NextDouble();
  235.  
  236. if (x < winChance1) //team one win.
  237. {
  238. players[i].Rating = players[i].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i].Rating) / F)))))));
  239. players[i + 1].Rating = players[i + 1].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 1].Rating) / F)))))));
  240. players[i + 2].Rating = players[i + 2].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 2].Rating) / F)))))));
  241. players[i + 3].Rating = players[i + 3].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 3].Rating) / F)))))));
  242. players[i + 4].Rating = players[i + 4].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 4].Rating) / F)))))));
  243. players[i + 5].Rating = players[i + 5].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 5].Rating) / F)))))));
  244. players[i + 6].Rating = players[i + 6].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 6].Rating) / F)))))));
  245. players[i + 7].Rating = players[i + 7].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 7].Rating) / F)))))));
  246. players[i + 8].Rating = players[i + 8].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 8].Rating) / F)))))));
  247. players[i + 9].Rating = players[i + 9].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 9].Rating) / F)))))));
  248. }
  249. else //team two win.
  250. {
  251. players[i].Rating = players[i].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i].Rating) / F)))))));
  252. players[i + 1].Rating = players[i + 1].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 1].Rating) / F)))))));
  253. players[i + 2].Rating = players[i + 2].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 2].Rating) / F)))))));
  254. players[i + 3].Rating = players[i + 3].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 3].Rating) / F)))))));
  255. players[i + 4].Rating = players[i + 4].Rating + (int)Math.Floor((k * (0 - (1 / (1 + (Math.Pow(10, (team2 - players[i + 4].Rating) / F)))))));
  256. players[i + 5].Rating = players[i + 5].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 5].Rating) / F)))))));
  257. players[i + 6].Rating = players[i + 6].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 6].Rating) / F)))))));
  258. players[i + 7].Rating = players[i + 7].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 7].Rating) / F)))))));
  259. players[i + 8].Rating = players[i + 8].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 8].Rating) / F)))))));
  260. players[i + 9].Rating = players[i + 9].Rating + (int)Math.Floor((k * (1 - (1 / (1 + (Math.Pow(10, (team1 - players[i + 9].Rating) / F)))))));
  261. }
  262.  
  263. }
  264.  
  265. Array.Sort(players);
  266. }
  267.  
  268. private void doOutInSide() {
  269. int inside = 0;
  270. int outside = 0;
  271. int x = 0;
  272. int y = 0;
  273. int[] z = new int[players.Length];
  274. int q = 0;
  275.  
  276. foreach (Player i in players)
  277. {
  278. if (Math.Abs(i.Rating - i.TrueRating) < 100)
  279. {
  280. inside++;
  281. }
  282. else
  283. {
  284. outside++;
  285. }
  286. x = x + i.Rating;
  287. y = y + Math.Abs(i.Rating - i.TrueRating);
  288. z[q] = Math.Abs(i.Rating - i.TrueRating);
  289. q++;
  290. }
  291. labelInside.Content = "Inside: " + inside;
  292. labelOutside.Content = "Outside: " + outside;
  293. labelStuff.Content = (x / players.Length) + " - " + (z.Max());
  294. }
  295.  
  296. private void bPopulate_Click(object sender, RoutedEventArgs e)
  297. {
  298. makePlayers();
  299. }
  300.  
  301. private void bSimulate_Click(object sender, RoutedEventArgs e)
  302. {
  303. int c = Convert.ToInt32(textBox2.Text);
  304. int one = 0, two = 0, three = 0, four = 0, five = 0;
  305. labelGame.Content = "On Game 1";
  306. for (int i = 0; i < c; i++)
  307. {
  308. labelGame.Content = "On Game " + (i + 1);
  309. one = 0; two = 0; three = 0; four = 0; five = 0;
  310. foreach (Player d in players)
  311. {
  312.  
  313. int x3 = d.Rating;
  314. if (x3 > 2200)
  315. {
  316. one++;
  317. }
  318. else if (x3 > 1850)
  319. {
  320. two++;
  321. }
  322. else if (x3 > 1500)
  323. {
  324. three++;
  325. }
  326. else if (x3 > 1150)
  327. {
  328. four++;
  329. }
  330. else
  331. {
  332. five++;
  333. }
  334. }
  335. label11.Content = one;
  336. label22.Content = two;
  337. label33.Content = three;
  338. label44.Content = four;
  339. label55.Content = five;
  340. doOutInSide();
  341. System.Windows.Forms.Application.DoEvents();
  342. playGames();
  343.  
  344. }
  345.  
  346. one = 0; two = 0; three = 0; four = 0; five = 0;
  347.  
  348. foreach (Player d in players)
  349. {
  350. int x3 = d.Rating;
  351. if (x3 > 2200)
  352. {
  353. one++;
  354. }
  355. else if (x3 > 1850)
  356. {
  357. two++;
  358. }
  359. else if (x3 > 1500)
  360. {
  361. three++;
  362. }
  363. else if (x3 > 1150)
  364. {
  365. four++;
  366. }
  367. else
  368. {
  369. five++;
  370. }
  371. }
  372. label11.Content = one;
  373. label22.Content = two;
  374. label33.Content = three;
  375. label44.Content = four;
  376. label55.Content = five;
  377. }
  378.  
  379. private void bOutside_Click(object sender, RoutedEventArgs e)
  380. {
  381. doOutInSide();
  382. }
  383. }
  384.  
  385.  
  386. }
Advertisement
Add Comment
Please, Sign In to add comment