Example #1
0
        public void GlickoUpdateNoOpponents()
        {
            var expectedValue = 0.06;

            var player1Opponents = new List <GlickoOpponent>();

            player1 = GlickoCalculator.CalculateRanking(player1, player1Opponents);
            var actualValue = player1.Volatility;

            Assert.Equal(expectedValue, actualValue);
        }
Example #2
0
        public void GlickoUpdateRatingDeviationNoOpponents()
        {
            var expectedValue = 200.27;

            var player1Opponents = new List <GlickoOpponent>();

            player1 = GlickoCalculator.CalculateRanking(player1, player1Opponents);
            var actualValue = Math.Round(player1.RatingDeviation, 2);

            Assert.Equal(expectedValue, actualValue);
        }
Example #3
0
        public void GlickoUpdateRatingDeviationCorrect()
        {
            var expectedValue = 151.52;

            var player1Opponents = new List <GlickoOpponent>
            {
                new GlickoOpponent(player2, 1),
                new GlickoOpponent(player3, 0),
                new GlickoOpponent(player4, 0)
            };

            player1 = GlickoCalculator.CalculateRanking(player1, player1Opponents);
            var actualValue = Math.Round(player1.RatingDeviation, 2);

            Assert.Equal(expectedValue, actualValue);
        }
Example #4
0
        public void GlickoUpdateCorrect()
        {
            var expectedValue = 0.059995984286488495;

            var player1Opponents = new List <GlickoOpponent>
            {
                new GlickoOpponent(player2, 1),
                new GlickoOpponent(player3, 0),
                new GlickoOpponent(player4, 0)
            };

            player1 = GlickoCalculator.CalculateRanking(player1, player1Opponents);
            var actualValue = player1.Volatility;

            Assert.Equal(expectedValue, actualValue);
        }
Example #5
0
        static void Main(string[] args)
        {
            var player1 = new GlickoPlayer(ratingDeviation: 200);
            var player2 = new GlickoPlayer(1400, 30);
            var player3 = new GlickoPlayer(1550, 100);
            var player4 = new GlickoPlayer(1700, 300);

            var player1Opponents = new List <GlickoOpponent>
            {
                new GlickoOpponent(player2, 1),
                new GlickoOpponent(player3, 0),
                new GlickoOpponent(player4, 0)
            };

            Console.WriteLine(String.Format("Player ranking: {0}", player1.Rating));
            Console.WriteLine(String.Format("Player ranking deviation: {0}", player1.RatingDeviation));

            player1 = GlickoCalculator.CalculateRanking(player1, player1Opponents);

            Console.WriteLine(String.Format("Player ranking: {0}", player1.Rating));
            Console.WriteLine(String.Format("Player ranking deviation: {0}", player1.RatingDeviation));

            Console.ReadKey();
        }
Example #6
0
 private GlickoPlayer CalculateNewRating(GlickoPlayer player, List <GlickoOpponent> opponents)
 {
     return(GlickoCalculator.CalculateRanking(player, opponents));
 }
Example #7
0
        public void GenerateGlicko(GameMode gameMode)
        {
            ulong guildId = 689504722163335196;

            var db = new PerudoBot.Data.GameBotDbContext();

            var games = db.Games.AsQueryable()
                        .Include(g => g.GamePlayers)
                        .ThenInclude(gp => gp.Player)
                        .Where(g => g.GuildId == guildId)
                        //.Where(g => g.Id >= 81)
                        .Where(g => g.IsRanked && g.State == 3)
                        .Where(g => g.Penalty == (int)(object)gameMode)
                        .Where(g => g.GamePlayers.Count() >= 4) //&& g.GamePlayers.Count() < 8)
                                                                //.OrderByDescending(g => g.Id)
                                                                //.Take(5)
                        .OrderBy(g => g.Id)
                                                                //.Take(2)
                        .ToList();

            //Debug.WriteLine($"========================================");
            Debug.WriteLine($"Generating Glicko Ratings for {gameMode}");

            var ratings = new Dictionary <string, GlickoRating>();
            var players = new Dictionary <string, GlickoPlayer>();

            games.ForEach(game =>
            {
                var preGameRatings = new Dictionary <string, GlickoPlayer>();
                Debug.WriteLine($"========= GAME {game.Id} ========= ");
                foreach (var gamePlayer in game.GamePlayers.OrderBy(gp => gp.Rank))
                {
                    var nickname = gamePlayer.Player.Nickname;
                    if (!ratings.ContainsKey(nickname))
                    {
                        ratings.Add(nickname, new GlickoRating());
                    }

                    if (!players.ContainsKey(nickname))
                    {
                        players.Add(nickname, new GlickoPlayer(ratingDeviation: 60));
                    }

                    //create a copy
                    preGameRatings.Add(nickname, new GlickoPlayer(
                                           players[nickname].Rating,
                                           players[nickname].RatingDeviation,
                                           players[nickname].Volatility)
                                       );
                }

                foreach (var gamePlayer in game.GamePlayers.OrderBy(gp => gp.Rank))
                {
                    var nickname = gamePlayer.Player.Nickname;
                    //       Debug.WriteLine($"Adding {nickname} with {preGameRatings[nickname].Rating} rating and rank of {gamePlayer.Rank}");

                    //if (!ratings.ContainsKey(nickname))
                    //{
                    //    ratings.Add(nickname, new GlickoRating());
                    //}

                    var opponents = new List <GlickoOpponent>();

                    foreach (var x in game.GamePlayers.OrderBy(gp => gp.Rank))
                    {
                        var xNick = x.Player.Nickname;
                        if (xNick == nickname)
                        {
                            continue;
                        }

                        var result = gamePlayer.Rank < x.Rank ? 1 : 0;

                        // Debug.WriteLine($"Adding opponent {xNick} with {preGameRatings[xNick].Rating} rating and rank of {x.Rank} (result: {result}");
                        opponents.Add(new GlickoOpponent(preGameRatings[xNick], result)); //working
                    }

                    players[nickname] = GlickoCalculator.CalculateRanking(players[nickname], opponents);
                    ratings[nickname].PreviousRating = ratings[nickname].Rating;
                    ratings[nickname].Rating         = Math.Round(players[nickname].Rating, 3);
                    ratings[nickname].Deviation      = Math.Round(players[nickname].RatingDeviation, 3);
                    ratings[nickname].Volatility     = Math.Round(players[nickname].Volatility, 3);
                    ratings[nickname].GamesPlayed++;
                }

                foreach (var gamePlayer in game.GamePlayers.OrderBy(gp => gp.Rank))
                {
                    var nickname = gamePlayer.Player.Nickname;

                    //gamePlayer.EloRatingChange = match.GetEloChange(nickname);

                    Debug.WriteLine($"{nickname} ({gamePlayer.Rank}) has new rating of {ratings[nickname].Rating} ({ratings[nickname].RatingChange}) and dev of {ratings[nickname].Deviation}");
                }
            });

            //var changes = db.SaveChanges();

            Debug.WriteLine($"========================================");
            Debug.WriteLine($"Final {gameMode} ratings:");

            var i = 1;

            foreach (var rating in ratings.OrderByDescending(x => x.Value.Rating))
            {
                Debug.WriteLine($"{i}: {rating.Key}: {Math.Round(rating.Value.Rating)} | {rating.Value.GamesPlayed}GP | φ: {Math.Round(rating.Value.Deviation)} | σ: {rating.Value.Volatility}");
                i++;
            }
            //Debug.WriteLine($"========================================");

            //Debug.WriteLine(String.Format("Player ranking: {0}", dave.Rating));
            //Debug.WriteLine(String.Format("Player ranking deviation: {0}", dave.RatingDeviation));

            //dave = GlickoCalculator.CalculateRanking(dave, player1Opponents);

            //Debug.WriteLine(String.Format("Player ranking: {0}", dave.Rating));
            //Debug.WriteLine(String.Format("Player ranking deviation: {0}", dave.RatingDeviation));
        }