Beispiel #1
0
        private void CalculateEloResults(Dictionary <Guid, ResultHelper> a_StartResults, DateTime a_MatchDate, Game.GameType a_GameType)
        {
            // We need to increment the count for all players.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                i_Kvp.Value.AmountGamesPlayed++;
            }

            Dictionary <Guid, KeyValuePair <DateTime, int> > v_TempResults = new Dictionary <Guid, KeyValuePair <DateTime, int> >();

            // We only want to do it ONCE for each entry.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                // Get the standings for given player.
                Dictionary <Modifier, List <Guid> > v_Standings = CalculateStandings(i_Kvp.Key, a_GameType);
                List <double> v_TempEloScores = new List <double>();

                // Iterates over all standings. Standings contains n-1 individual Ids (where n is the amount of players in a match).
                foreach (KeyValuePair <Modifier, List <Guid> > i_KvpInner in v_Standings)
                {
                    double v_ModifierPlayer = EloCalculator.EstablishedStatusToModifier[i_Kvp.Value.IsEstablished][i_KvpInner.Key];

                    foreach (Guid i_OpponentId in i_KvpInner.Value)
                    {
                        /// The +1 is needed because we only increment the amount of played games inside AddResult.
                        /// In the old implementation was actually a defect because the counter for the active player
                        /// was incremented and the calculation used the old value for the opponent.
                        double v_TempEloScore = EloCalculator.CalculateEloRanking(
                            i_Kvp.Value.EloScore,
                            i_Kvp.Value.AmountGamesPlayed,
                            i_Kvp.Value.IsEstablished,
                            a_StartResults[i_OpponentId].EloScore,
                            a_StartResults[i_OpponentId].AmountGamesPlayed,
                            a_StartResults[i_OpponentId].IsEstablished,
                            v_ModifierPlayer
                            );

                        v_TempEloScores.Add(v_TempEloScore);
                    }
                }

                double v_NewEloScore = 0;

                foreach (double i_TempScore in v_TempEloScores)
                {
                    v_NewEloScore += i_TempScore;
                }

                if (v_TempEloScores.Count > 0)
                {
                    v_NewEloScore = v_NewEloScore / v_TempEloScores.Count;
                    // Must NOT be applied immediately! We're putting the reults aside and apply them afterwards.
                    v_TempResults.Add(i_Kvp.Key, new KeyValuePair <DateTime, int>(a_MatchDate, (int)Math.Round(v_NewEloScore, 0)));
                }
            }

            // Now we add the new results.
            foreach (KeyValuePair <Guid, ResultHelper> i_Kvp in a_StartResults)
            {
                i_Kvp.Value.AddResult(v_TempResults[i_Kvp.Key].Key, v_TempResults[i_Kvp.Key].Value);
            }
        }