Example #1
0
        public static (MMgameNG, MMgameNG) RateGame(dsreplay replay, StartUp _mm, string lobby)
        {
            var team1 = new Team();
            var team2 = new Team();

            var rteam1 = new Team();
            var rteam2 = new Team();

            //string lobby = _mm.Games.Where(x => x.ID == replay.ID).FirstOrDefault().Lobby;
            if (lobby == null || lobby == "")
            {
                return(null, null);
            }
            int i = 0;

            foreach (var pl in replay.PLAYERS)
            {
                MMplayerNG mpl = new MMplayerNG();
                if (_mm.MMplayers.ContainsKey(pl.NAME))
                {
                    mpl = _mm.MMplayers[pl.NAME];
                }
                else
                {
                    mpl.Name = "Dummy" + i;
                }

                MMplayerNG rpl   = _mm.MMraces[pl.RACE];
                MMPlRating plrat = mpl.Rating[lobby].LastOrDefault();
                if (plrat == null)
                {
                    plrat = new MMPlRating();
                    mpl.Rating[lobby].Add(plrat);
                }
                MMPlRating cmdrrat = rpl.Rating[lobby].LastOrDefault();
                if (cmdrrat == null)
                {
                    cmdrrat = new MMPlRating();
                    rpl.Rating[lobby].Add(cmdrrat);
                }

                if (pl.TEAM == replay.WINNER)
                {
                    team1.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA));
                    rteam1.AddPlayer(new Player(pl.RACE), new Rating(cmdrrat.MU, cmdrrat.SIGMA));
                }
                else
                {
                    team2.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA));
                    rteam2.AddPlayer(new Player(pl.RACE), new Rating(cmdrrat.MU, cmdrrat.SIGMA));
                }
                i++;
            }
            return(RateGame(team1, team2, lobby, _mm), RateGame(rteam1, rteam2, lobby, _mm, true));
        }
Example #2
0
        public static MMgameNG RateGame(Team team1, Team team2, string lobby, StartUp _mm, bool cmdr = false)
        {
            var gameInfo = GameInfo.DefaultGameInfo;
            var teams    = Teams.Concat(team1, team2);
            var newRatingsWinLoseExpected = TrueSkillCalculator.CalculateNewRatings(gameInfo, teams, 1, 2);

            MMgameNG game = new MMgameNG();

            game.Lobby = lobby;
            int i = 0;

            foreach (var pl in team1.AsDictionary().Keys)
            {
                var        res   = newRatingsWinLoseExpected[pl];
                string     name  = pl.Id.ToString();
                MMplayerNG mpl   = new MMplayerNG();
                MMPlRating plrat = new MMPlRating();
                if (_mm.MMplayers.ContainsKey(name))
                {
                    mpl      = _mm.MMplayers[name];
                    plrat    = mpl.Rating[lobby].LastOrDefault().ShallowCopy();
                    plrat.Db = false;
                }
                else
                {
                    mpl.Name = "Dummy" + i;
                }

                if (cmdr == true)
                {
                    mpl      = _mm.MMraces[name];
                    plrat    = mpl.Rating[lobby].LastOrDefault().ShallowCopy();
                    plrat.Db = false;
                }

                double temp = plrat.EXP;
                plrat.EXP     = res.ConservativeRating;
                mpl.ExpChange = plrat.EXP - temp;
                plrat.MU      = res.Mean;
                plrat.SIGMA   = res.StandardDeviation;
                plrat.Games++;
                plrat.Time = DateTime.UtcNow;
                mpl.Rating[lobby].Add(plrat);
                game.Team1.Add(mpl);
                i++;
            }
            foreach (var pl in team2.AsDictionary().Keys)
            {
                var        res   = newRatingsWinLoseExpected[pl];
                string     name  = pl.Id.ToString();
                MMplayerNG mpl   = new MMplayerNG();
                MMPlRating plrat = new MMPlRating();
                if (_mm.MMplayers.ContainsKey(name))
                {
                    mpl      = _mm.MMplayers[name];
                    plrat    = mpl.Rating[lobby].LastOrDefault().ShallowCopy();
                    plrat.Db = false;
                }
                else
                {
                    mpl.Name = "Dummy" + i;
                }

                if (cmdr == true)
                {
                    mpl      = _mm.MMraces[name];
                    plrat    = mpl.Rating[lobby].LastOrDefault().ShallowCopy();
                    plrat.Db = false;
                }

                double temp = plrat.EXP;
                plrat.EXP     = res.ConservativeRating;
                mpl.ExpChange = plrat.EXP - temp;
                plrat.MU      = res.Mean;
                plrat.SIGMA   = res.StandardDeviation;
                plrat.Games++;
                plrat.Time = DateTime.UtcNow;
                mpl.Rating[lobby].Add(plrat);
                game.Team2.Add(mpl);
                i++;
            }

            return(game);
        }
Example #3
0
        public static async Task <MMgameNG> GenMatch(List <MMplayerNG> qplayers, int size)
        {
            List <MMplayerNG> result = new List <MMplayerNG>();
            int c = 0;

            List <MMplayerNG> players = new List <MMplayerNG>();

            players = qplayers.Where(x => x.Game.ID == 0).ToList();

            if (players.Count < size)
            {
                return(null);
            }

            string lobby = players.First().Mode + players.First().Mode2 + players.First().Ladder;

            double bestquality = 0;

            return(await Task.Run(() => {
                while (true)
                {
                    c++;
                    int i = 0;
                    var team1 = new Team();
                    var team2 = new Team();

                    var rnd = new Random();
                    List <MMplayerNG> thisresult = new List <MMplayerNG>(players.Select(x => new { value = x, order = rnd.Next() })
                                                                         .OrderBy(x => x.order).Select(x => x.value).Take(size).ToList());


                    foreach (var pl in thisresult)
                    {
                        MMPlRating plrat = pl.Rating[lobby].LastOrDefault();
                        if (plrat == null)
                        {
                            plrat = new MMPlRating();
                            pl.Rating[lobby].Add(plrat);
                        }
                        if (i < result.Count() / 2)
                        {
                            team1.AddPlayer(new Player(i), new Rating(plrat.MU, plrat.SIGMA));
                        }
                        else
                        {
                            team2.AddPlayer(new Player(i), new Rating(plrat.MU, plrat.SIGMA));
                        }
                        i++;
                    }

                    var gameInfo = GameInfo.DefaultGameInfo;
                    var teams = Teams.Concat(team1, team2);

                    double thisquality = TrueSkillCalculator.CalculateMatchQuality(gameInfo, teams);

                    if (thisquality > bestquality)
                    {
                        bestquality = thisquality;
                        result = new List <MMplayerNG>(thisresult);
                    }

                    if (c > 10 && bestquality > 0.5)
                    {
                        break;
                    }
                    if (c > 50 && bestquality > 0.4)
                    {
                        break;
                    }
                    if (c > 200)
                    {
                        break;
                    }
                }

                MMgameNG game = new MMgameNG();
                game.Quality = bestquality;
                game.ID = 1;
                int j = 0;
                foreach (var pl in result)
                {
                    if (j < result.Count() / 2)
                    {
                        game.Team1.Add(pl);
                    }
                    else
                    {
                        game.Team2.Add(pl);
                    }
                    j++;
                }

                return game;
            }));
        }
Example #4
0
        public static (MMgameNG, MMgameNG) RateGame(string result, string lobby, StartUp _mm)
        {
            List <RESplayer> pllist = new List <RESplayer>();
            var teams = result.Split(new string[] { " vs " }, StringSplitOptions.None);

            if (teams.Length == 2)
            {
                int t = 0;
                int p = 0;
                foreach (var team in teams)
                {
                    Match m = rx_pl.Match(team);
                    while (m.Success)
                    {
                        RESplayer plres = new RESplayer();
                        plres.Team = t;
                        plres.Pos  = p;
                        var plent = m.Groups[1].ToString().Split(',', StringSplitOptions.None);
                        int i     = 0;
                        foreach (var ent in plent)
                        {
                            string myent = ent.Trim();
                            myent = myent.Replace(" ", string.Empty);
                            myent = myent.Replace("(", string.Empty);
                            myent = myent.Replace(")", string.Empty);
                            if (i == 0)
                            {
                                plres.Name = myent;
                            }
                            if (i == 1)
                            {
                                plres.Race = myent;
                            }
                            if (i == 2)
                            {
                                plres.Kills = int.Parse(myent);
                            }
                            i++;
                        }
                        pllist.Add(plres);
                        m = rx_pl.Match(m.Groups[2].ToString());
                        p++;
                    }
                    t++;
                }
            }
            var team1 = new Team();
            var team2 = new Team();

            var rteam1 = new Team();
            var rteam2 = new Team();

            int j = 0;

            foreach (var pl in pllist)
            {
                MMplayerNG mpl = new MMplayerNG();
                if (_mm.MMplayers.ContainsKey(pl.Name))
                {
                    mpl = _mm.MMplayers[pl.Name];
                }
                else
                {
                    if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy"))
                    {
                        mpl.Name = "Dummy" + j;
                    }
                    else
                    {
                        mpl.Name = pl.Name;
                        _mm.MMplayers.TryAdd(mpl.Name, mpl);
                    }
                }
                MMplayerNG rpl   = _mm.MMraces[pl.Race];
                MMPlRating plrat = mpl.Rating[lobby].LastOrDefault();
                if (plrat == null)
                {
                    plrat = new MMPlRating();
                    mpl.Rating[lobby].Add(plrat);
                }
                MMPlRating cmdrrat = rpl.Rating[lobby].LastOrDefault();
                if (cmdrrat == null)
                {
                    cmdrrat = new MMPlRating();
                    rpl.Rating[lobby].Add(cmdrrat);
                }



                if (pl.Team == 0)
                {
                    team1.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA));
                    rteam1.AddPlayer(new Player(pl.Race), new Rating(cmdrrat.MU, cmdrrat.SIGMA));
                }
                else
                {
                    team2.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA));
                    rteam2.AddPlayer(new Player(pl.Race), new Rating(cmdrrat.MU, cmdrrat.SIGMA));
                }
                j++;
            }
            return(RateGame(team1, team2, lobby, _mm), RateGame(rteam1, rteam2, lobby, _mm, true));
        }