Esempio n. 1
0
        public MatchCost(string matchLink, int warmupCount)
        {
            match            = OsuApi.Match(matchLink.Substring(37)).Result;
            this.warmupCount = warmupCount;

            if (match.Games.Length == 0)
            {
                throw new Exception("jij bent echt kankerdom");
            }

            foreach (MultiPlayerGame game in match.Games)
            {
                if (warmupCount != 0)
                {
                    warmupCount--;
                    continue;
                }

                foreach (MultiPlayerScore score in game.Scores)
                {
                    if (score.Score < 5000)
                    {
                        continue;
                    }

                    if (score.Team == 0)
                    {
                        isFfa = true;

                        if (!totalScores.ContainsKey(score.UserId))
                        {
                            totalScores.Add(score.UserId, new List <double>());
                        }

                        totalScores[score.UserId].Add(score.Score);
                    }
                    else if (score.Team == 1)
                    {
                        blueTotal += score.Score;

                        if (!blueScores.ContainsKey(score.UserId))
                        {
                            blueScores.Add(score.UserId, new List <double>());
                        }

                        blueScores[score.UserId].Add(score.Score);
                        blueScoreCount++;
                    }
                    else if (score.Team == 2)
                    {
                        redTotal += score.Score;

                        if (!redScores.ContainsKey(score.UserId))
                        {
                            redScores.Add(score.UserId, new List <double>());
                        }

                        redScores[score.UserId].Add(score.Score);
                        redScoreCount++;
                    }

                    total += score.Score;
                    totalScoreCount++;
                }

                mapCount++;
            }

            totalAverage = total / totalScoreCount;
            blueAverage  = blueTotal / blueScoreCount;
            redAverage   = redTotal / redScoreCount;

            if (isFfa)
            {
                foreach (KeyValuePair <int, List <double> > playerScores in totalScores)
                {
                    double cost = 0;

                    foreach (int score in playerScores.Value)
                    {
                        cost += score / totalAverage;
                    }

                    totalCosts.Add(playerScores.Key, new double[] {
                        cost / playerScores.Value.Count * Math.Pow(1.2, Math.Pow(playerScores.Value.Count / mapCount, 0.4))
                    });
                }
            }
            else
            {
                foreach (KeyValuePair <int, List <double> > playerScores in blueScores)
                {
                    double cost     = 0;
                    double teamcost = 0;

                    foreach (int score in playerScores.Value)
                    {
                        cost     += score / totalAverage;
                        teamcost += score / blueAverage;
                    }

                    blueCosts.Add(playerScores.Key, new double[] {
                        cost / playerScores.Value.Count * Math.Pow(1.2, Math.Pow(playerScores.Value.Count / mapCount, 0.4)),
                        teamcost / playerScores.Value.Count * Math.Pow(1.2, Math.Pow(playerScores.Value.Count / mapCount, 0.4))
                    });
                }

                foreach (KeyValuePair <int, List <double> > playerScores in redScores)
                {
                    double cost     = 0;
                    double teamcost = 0;

                    foreach (int score in playerScores.Value)
                    {
                        cost     += score / totalAverage;
                        teamcost += score / redAverage;
                    }

                    redCosts.Add(playerScores.Key, new double[] {
                        cost / playerScores.Value.Count * Math.Pow(1.2, Math.Pow(playerScores.Value.Count / mapCount, 0.4)),
                        teamcost / playerScores.Value.Count * Math.Pow(1.2, Math.Pow(playerScores.Value.Count / mapCount, 0.4))
                    });
                }
            }
        }