예제 #1
0
        public double calculateRatingChangeForPlayer(RatingsPlayer player, IEnumerable <RatingsSet> sets, IEnumerable <RatingsPlayer> players)
        {
            var playerSets = (from s in sets
                              where s.WinnerID == player.PlayerId || s.LoserID == player.PlayerId
                              select s).Distinct();
            HashSet <int> playerOpponentIDs = new HashSet <int>();

            foreach (RatingsSet set in playerSets)
            {
                playerOpponentIDs.Add(set.WinnerID);
                playerOpponentIDs.Add(set.LoserID);
            }
            playerOpponentIDs.Remove(player.PlayerId);
            var playerOpponents = from p in players
                                  where playerOpponentIDs.Contains(p.PlayerId)
                                  select p;

            double expectedScore = getExpectedScoreForTournament(player, playerOpponents, playerSets);
            double actualScore   = getActualScore(playerSets, player.PlayerId);
            var    ratingChange  = getRatingChange(getKFactor(player.ELO), actualScore, expectedScore);

            playerSets = null;
            GC.Collect();
            return(ratingChange);
        }
예제 #2
0
        private double getExpectedScoreForTournament(RatingsPlayer player, IEnumerable <RatingsPlayer> playerOpponents, IEnumerable <RatingsSet> playerSets)
        {
            double expectedScore = 0;

            foreach (RatingsSet set in playerSets)
            {
                var opponent = set.WinnerID == player.PlayerId ? playerOpponents.First(p => p.PlayerId == set.LoserID) :
                               playerOpponents.First(p => p.PlayerId == set.WinnerID);
                expectedScore += getExpectedScore(player.ELO, opponent.ELO);
            }
            return(expectedScore);
        }