public void Analyse() { var initialRatings = new List <PlayerRating>(); foreach (var playerInformation in _PlayerData.Values) { var rating = new PlayerRating(playerInformation.Identity, InitialRating); initialRatings.Add(rating); } RatingEvaluation bestRatings = EvaluateRatings(initialRatings.ToArray()); for (int i = 0; i < Iterations; i++) { var mutatedRatings = GetMutatedRatings(bestRatings.Ratings); var mutatedRatingEvaluation = EvaluateRatings(mutatedRatings); if (mutatedRatingEvaluation.Error < bestRatings.Error) { bestRatings = mutatedRatingEvaluation; } } Console.WriteLine("Error: {0}", bestRatings.Error); var ratings = bestRatings.Ratings.OrderByDescending(x => x.Rating); foreach (var rating in ratings) { var playerInformation = _PlayerData[rating.Identity.SteamId]; double?killDeathRatio = null; if (playerInformation.DeathCount > 0) { killDeathRatio = (double)playerInformation.KillCount / playerInformation.DeathCount; } Console.WriteLine("{0} ({1}): KDR {2:0.00}, rating {3:0.00}", rating.Identity.Name, rating.Identity.SteamId, killDeathRatio, rating.Rating); } PrintEncounterStatistics(ratings); }
RatingEvaluation EvaluateRatings(PlayerRating[] ratings) { double error = 0.0; foreach (string steamId1 in _PerformanceMatrix.Keys) { foreach (string steamId2 in _PerformanceMatrix.Keys) { if (steamId1 == steamId2) { continue; } double rating1 = ratings.Where(x => x.Identity.SteamId == steamId1).First().Rating; double rating2 = ratings.Where(x => x.Identity.SteamId == steamId2).First().Rating; double expectedValue = ExpectedWinRatio(rating1, rating2); var performance = GetPeformanceEntry(steamId1, steamId2); int totalEncounters = performance.Kills + performance.Deaths; if (totalEncounters == 0) { continue; } double actualValue = (double)performance.Kills / totalEncounters; double errorWeight = Math.Pow(Math.Min((double)totalEncounters / ErrorEvaluationEncounterBarrier, 1.0), 2.0); error += errorWeight * Math.Pow(expectedValue - actualValue, 2.0); } } var evaluation = new RatingEvaluation(ratings, error); return(evaluation); }