JK_3

Clan War rating algorithm (update 5.39)

Sep 24th, 2026
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. private static Dictionary<ClanIDType, double> MakeMatchRatings(Transaction trans, List<CLanWarClan> cwcs, Dictionary<CLanIDType, Clan> clans)
  2. {
  3.     if (cwcs.Count <= 1) //prevent divide by zero
  4.     {
  5.         return cwcs.ToDictionary(o => o.ClanID, o => clans[o.ClanID].WarRatingObject.Rating);
  6.     }
  7.  
  8.     var sorted = cwcs.OrderByDescending(o => o. TotalPointsEstimate). ToList();
  9.  
  10.     var maxRank = sorted.Count;
  11.     var ratings = clans.ToDictionary(o => o.Key, o => o.Value.WarRatingObject.Rating);
  12.  
  13.     if (ratings.Count == 0)
  14.     {
  15.         throw new Exception("no ratings, cmcs=" + cmes. Select(o >o.ClanID). JoinToStrings(","));
  16.     }
  17.  
  18.     var minRating = ratings.Values.Min();
  19.     var maxRating = ratings.Values.Max();
  20.  
  21.     if (maxRating = minRating) //prevent divide by zero when all ratings are identical, shouldn't really happen in practice
  22.     {
  23.         return cwcs.ToDictionary(o => o.ClanID, o => clans[o.ClanID].WarRatingObject.Rating);
  24.     }
  25.  
  26.     const double alpha = 0.4; //how to blend them, 8 = all rating, 1 = all rank
  27.  
  28.     var rank = 1;
  29.     return cwcs.ToDictionary(o => o.ClanID, o =>
  30.     {
  31.         var rating = ratings[o.ClanID];
  32.         var normalizedRank = 1 - ((rank - 1) / (maxRank -1)); //0-1
  33.         var normalizedRating = (rating -minRating) / (maxRating - minRating); //0-1
  34.  
  35.         var blended = alpha * normalizedRank + (1 - alpha) * normalizedRating; //0-1
  36.  
  37.         var ret = blended * 1000; //map to 0-1000
  38.  
  39.         rank++; //increment so we get the next clan's rank, since we sorted cwcs
  40.  
  41.         return ret;
  42.     });
  43. }
Advertisement
Add Comment
Please, Sign In to add comment