示例#1
0
        public static int GetColor(double rating)
        {
            RatingCategory category = GetCategory(rating);

            if (category == RatingCategory.PAWN)
            {
                return(0xAAAAAA);
            }

            if (category == RatingCategory.BISHOP)
            {
                return(0x55FF55);
            }

            if (category == RatingCategory.ROOK)
            {
                return(0x5555FF);
            }

            if (category == RatingCategory.QUEEN)
            {
                return(0xFFFF55);
            }

            if (category == RatingCategory.KING)
            {
                return(0xFF5555);
            }

            throw new ArgumentException();
        }
示例#2
0
        private static bool IsCategory(SpringBattle battle, RatingCategory category)
        {
            int battleID = -1;

            try
            {
                battleID = battle.SpringBattleID;
                switch (category)
                {
                case RatingCategory.Casual:
                    return(!(battle.IsMission || battle.HasBots || (battle.PlayerCount < 2) || (battle.ResourceByMapResourceID?.MapIsSpecial == true) ||
                             battle.ResourceByMapResourceID?.MapSupportLevel < MapSupportLevel.Supported || battle.Duration < GlobalConst.MinDurationForElo));

                case RatingCategory.MatchMaking:
                    return(battle.IsMatchMaker);

                case RatingCategory.Planetwars:
                    return(battle.Mode == PlasmaShared.AutohostMode.Planetwars);    //how?
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("WHR: Error while checking battle category (B" + battleID + ")" + ex);
            }
            return(false);
        }
        private static bool IsCategory(SpringBattle battle, RatingCategory category)
        {
            int battleID = -1;

            try
            {
                if (battle.HasBots)
                {
                    return(false);
                }
                battleID = battle.SpringBattleID;
                switch (category)
                {
                case RatingCategory.Casual:
                    return(battle.ApplicableRatings.HasFlag(RatingCategoryFlags.Casual));

                case RatingCategory.MatchMaking:
                    return(battle.ApplicableRatings.HasFlag(RatingCategoryFlags.MatchMaking));

                case RatingCategory.Planetwars:
                    return(battle.ApplicableRatings.HasFlag(RatingCategoryFlags.Planetwars));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("WHR: Error while checking battle category (B" + battleID + ")" + ex);
            }
            return(false);
        }
示例#4
0
            public BalanceItem(bool isMatchMaker, params Account[] accounts)
            {
                LobbyId = accounts.Select(x => x.AccountID).ToList();

                RatingCategory category = isMatchMaker ? RatingCategory.MatchMaking : RatingCategory.Casual;

                EloElements = accounts.Select(x => (double)x.GetRating(category).Elo).ToList();
            }
示例#5
0
 public static IRatingSystem GetRatingSystem(RatingCategory category)
 {
     if (DisableRatingSystems)
     {
         return(null);
     }
     return(whr[category]);
 }
示例#6
0
 public RatingHistory(int accountID, RatingCategory category)
 {
     this.AccountID = accountID;
     this.Category  = category;
     using (var db = new ZkDataContext())
     {
         AccountName = db.Accounts.Where(x => x.AccountID == accountID).FirstOrDefault().Name;
     }
 }
 public static IRatingSystem GetRatingSystem(RatingCategory category)
 {
     if (!whr.ContainsKey(category))
     {
         Trace.TraceWarning("WHR: Unknown category " + category + " " + new StackTrace());
         return(whr[RatingCategory.MatchMaking]);
     }
     return(whr[category]);
 }
示例#8
0
        public override string Arm(ServerBattle battle, Say e, string arguments = null)
        {
            int ratingInt;

            if (int.TryParse(arguments, out ratingInt) && Enum.IsDefined(typeof(RatingCategory), ratingInt))
            {
                rating = (RatingCategory)ratingInt;
                return($"Set applicable ratings to {rating}?");
            }
            else
            {
                return(null);
            }
        }
示例#9
0
            public BalanceItem(bool isMatchMaker, params Account[] accounts)
            {
                LobbyId = accounts.Select(x => x.AccountID).ToList();
                Count   = accounts.Length;

                if (RatingSystems.DisableRatingSystems)
                {
                    EloSum = isMatchMaker ? accounts.Sum(x => x.EffectiveMmElo) : accounts.Sum(x => x.EffectiveElo);
                }
                else
                {
                    RatingCategory category = isMatchMaker ? RatingCategory.MatchMaking : RatingCategory.Casual;
                    EloSum = accounts.Sum(x => x.GetRating(category).Elo);
                }
            }
        private async void GraphTypeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RatingCategory Selection = GraphTypeCombo.SelectedItem as RatingCategory;

            if (Selection != null && Selection.Name != "" && Selection.Name[0] != '-')
            {
                List <int> GraphData = await business.LoadGraphAsync(MediaType.Video, Selection, 0);

                DisplayGraph(GraphData);
            }
            else
            {
                DisplayGraph(null);
            }
            MediaList.Clear();
        }
 public void AddRating(string name, MediaRating rating, List <RatingCategory> categories)
 {
     if (!string.IsNullOrEmpty(name) && (rating.Height.HasValue || rating.Depth.HasValue))
     {
         RatingCategory Rating = categories.Find(c => c.Name.ToLower() == name.ToLower());
         //if (Rating == null) {
         //    Rating = new RatingCategory() { Name = name, Custom = true };
         //    context.RatingCategories.Add(Rating);
         //}
         if (Rating != null)
         {
             video.MediaRatings.Add(new MediaRating()
             {
                 RatingCategory = Rating, Height = rating.Height, Depth = rating.Depth
             });
         }
     }
 }
示例#12
0
        public static float UpdateLadderRating(Account acc, RatingCategory cat, float targetRating, bool allowGain, bool allowLoss, float classicEloChange, ZkDataContext db)
        {
            var rating    = acc.AccountRatings.Where(x => x.RatingCategory == cat).FirstOrDefault();
            var ladderElo = rating?.LadderElo ?? WholeHistoryRating.DefaultRating.LadderElo;

            if (!allowLoss && !allowGain)
            {
                Trace.TraceWarning("No rating change allowed for player " + acc.Name + "(" + acc.AccountID + ")");
                return((float)ladderElo);
            }
            if (float.IsNaN(targetRating))
            {
                Trace.TraceWarning("Target rating for player " + acc.Name + "(" + acc.AccountID + ") is NaN");
                return((float)ladderElo);
            }
            var delta = targetRating - ladderElo;

            delta *= GlobalConst.LadderEloSmoothingFactor;            //smooth out elo changes
            delta  = Math.Min(GlobalConst.LadderEloMaxChange, delta); //clip rating change to allowed limits
            delta  = Math.Max(-GlobalConst.LadderEloMaxChange, delta);
            if (!allowGain)
            {
                delta = Math.Min(-GlobalConst.LadderEloMinChange, delta);
            }
            if (!allowLoss)
            {
                delta = Math.Max(GlobalConst.LadderEloMinChange, delta);
            }

            double ladderEloBefore = ladderElo;

            ladderElo += delta * (1 - GlobalConst.LadderEloClassicEloWeight) + GlobalConst.LadderEloClassicEloWeight * classicEloChange;
            if (rating != null)
            {
                rating.UpdateLadderElo(ladderElo);
                db.Entry(rating).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                Trace.TraceInformation(string.Format("WHR LadderElo update for player {0} not directly saved to db", acc.Name));
            }
            Trace.TraceInformation(string.Format("WHR LadderElo update for player {0} ({1}) from {2} -> {3}, targeting {4}. WHR Change: {5}, Elo Change: {6}", acc.Name, acc.AccountID, ladderEloBefore, ladderElo, targetRating, delta, classicEloChange));
            return((float)ladderElo);
        }
        private void CustomCombo_LostFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            ComboBox       Obj     = sender as ComboBox;
            RatingCategory ObjItem = Obj.SelectedItem as RatingCategory;

            if (ObjItem != null)
            {
                Obj.Text = ObjItem.Name;
            }
            else
            {
                Obj.Text = "";
            }

            if (Obj.Text.Length > 0 && Custom1Combo.Text == Custom2Combo.Text)
            {
                Obj.Text = "";
            }
        }
        /// <summary>
        /// Returns a list of video count for each graph bar.
        /// </summary>
        /// <param name="mediaType">The type of media to return.</param>
        /// <param name="graphType">The rating type to generate the graph for.</param>
        /// <param name="ratio">The ratio to use when multiplying Height and Depth.</param>
        /// <returns>A list of 14 integers.</returns>
        public List <int> LoadGraph(MediaType mediaType, RatingCategory graphType, double ratio)
        {
            List <int> Result = new List <int>();

            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[0], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[1], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[2], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[3], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[4], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[5], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[6], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[7], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[8], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[9], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[10], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[11], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[12], ratio));
            Result.Add(DistributionGraphAccess.GetMediaCount(mediaType, graphType, bars[13], ratio));
            return(Result);
        }
示例#15
0
 public WholeHistoryRating(RatingCategory category)
 {
     this.category            = category;
     w2                       = GlobalConst.EloDecayPerDaySquared;
     ladderRecalculationTimer = new Timer((t) => { UpdateRatings(); }, this, 15 * 60000, (int)(GlobalConst.LadderUpdatePeriod * 3600 * 1000 + 4242));
 }
示例#16
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            var b = battle;
            List <IEnumerable <Account> > teams;

            RatingCategory cat = RatingCategory.Casual;

            if (b.IsMatchMakerBattle)
            {
                cat = RatingCategory.MatchMaking;
            }
            if (b.Mode == PlasmaShared.AutohostMode.Planetwars)
            {
                cat = RatingCategory.Planetwars;
            }

            using (var db = new ZkDataContext())
            {
                if (battle.IsInGame)
                {
                    teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator)
                            .GroupBy(u => u.AllyID)
                            .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                }
                else
                {
                    switch (battle.Mode)
                    {
                    case PlasmaShared.AutohostMode.Game1v1:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.Name)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;

                    case PlasmaShared.AutohostMode.Teams:
                        teams = PartitionBalance.Balance(battle.IsCbalEnabled ? Balancer.BalanceMode.ClanWise : Balancer.BalanceMode.Normal, b.Users.Values.Where(u => !u.IsSpectator).Select(x => x.LobbyUser).Select(x => new PartitionBalance.PlayerItem(x.AccountID, x.EffectiveElo, x.Clan, x.PartyID)).ToList())
                                .Players
                                .GroupBy(u => u.AllyID)
                                .Select(x => x.Select(p => db.Accounts.Where(a => a.AccountID == p.LobbyID).FirstOrDefault())).ToList();
                        break;

                    default:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.AllyNumber)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;
                    }
                }

                if (teams.Count < 2)
                {
                    await battle.SayBattle($"!predict needs at least two human teams to work");

                    return;
                }

                var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow);
                for (int i = 0; i < teams.Count; i++)
                {
                    await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).Select(x => x.Name).Aggregate((a, y) => a + ", " + y)} has a {Math.Round(1000 * chances[i]) / 10}% chance to win");
                }
            }
        }
示例#17
0
 public AccountRating(int AccountID, RatingCategory ratingCategory)
 {
     this.RatingCategory = ratingCategory;
     this.AccountID      = AccountID;
     UpdateFromRatingSystem(WholeHistoryRating.DefaultRating);
 }
示例#18
0
 public PlayerRating GetRating(RatingCategory category)
 {
     return(RatingSystems.GetRatingSystem(category).GetPlayerRating(AccountID));
 }
示例#19
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            var b = battle;
            List <IEnumerable <Account> > teams;

            RatingCategory cat = RatingCategory.Casual;

            if (b.IsMatchMakerBattle)
            {
                cat = RatingCategory.MatchMaking;
            }
            if (b.Mode == PlasmaShared.AutohostMode.Planetwars)
            {
                cat = RatingCategory.Planetwars;
            }

            using (var db = new ZkDataContext())
            {
                if (battle.IsInGame)
                {
                    teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator)
                            .GroupBy(u => u.AllyID)
                            .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                }
                else
                {
                    switch (battle.Mode)
                    {
                    case PlasmaShared.AutohostMode.Game1v1:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.Name)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;

                    case PlasmaShared.AutohostMode.Teams:
                        await battle.SayBattle($"The battle will be balanced when it starts");

                        return;

                    default:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.AllyNumber)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;
                    }
                }

                if (teams.Count < 2)
                {
                    await battle.SayBattle($"!predict needs at least two human teams to work");

                    return;
                }

                var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow);
                for (int i = 0; i < teams.Count; i++)
                {
                    await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).First().Name} has a {Math.Round(1000 * chances[i]) / 10}% chance to win");
                }
            }
        }
示例#20
0
 public PlayerRating GetRating(RatingCategory category)
 {
     return(RatingSystems.GetRatingSystem(category).GetPlayerRating(this));
 }
 /// <summary>
 /// Returns a list of video count for each graph bar.
 /// </summary>
 /// <param name="mediaType">The type of media to return.</param>
 /// <param name="graphType">The rating type to generate the graph for.</param>
 /// <param name="ratio">The ratio to use when multiplying Height and Depth.</param>
 /// <returns>A list of 14 integers.</returns>
 public async Task <List <int> > LoadGraphAsync(MediaType mediaType, RatingCategory graphType, double ratio)
 {
     return(await Task.Run(() => LoadGraph(mediaType, graphType, ratio)));
 }
示例#22
0
 public float GetBalancerRating(RatingCategory category)
 {
     return(GetRating(category).Elo - Math.Max(GlobalConst.MaxLevelForMalus - Level, 0) * GlobalConst.MaxMalus / GlobalConst.MaxLevelForMalus);
 }