Esempio n. 1
0
        private float getNewElo(List <Ranking> ownRankingHistory, int ownPosition, Ranking[] otherPlayerRankings, LeagueConfig cf, float ownScore = (float)0)
        {
            float oldRank       = OldRank.HasValue ? cf.InitialElo : OldRank.Value;
            int   nbOpponents   = otherPlayerRankings.Length;
            int   nbTotalGames  = ownRankingHistory.Count;
            float avgOpponentRk = (otherPlayerRankings.Sum(x => x.NewRank)) / nbOpponents;

            float[] UMA = nbOpponents == 3
                ? new float[] { cf.Uma4p1, cf.Uma4p2, cf.Uma4p3, cf.Uma4p4 }
                : new float[] { cf.Uma3p1, cf.Uma3p2, cf.Uma3p3 };

            //Rank affected by score
            float basePts =
                UMA[ownPosition - 1]                                        //UMA
                + (ownPosition == 1 ? cf.Oka * nbOpponents : -cf.Oka)       //OKA
                - (ownPosition == nbOpponents + 1 ? cf.PenaltyLast : 0);    //PENALTY

            basePts += cf.CountPoints ? (ownScore - cf.StartingPoints) : 0; //SCORE

            float rankChange = basePts;

            //ELO bonus/penalty depending on opponents average ELO
            if (cf.UseEloSystem)
            {
                float baseEloChange     = avgOpponentRk - oldRank;
                float dampenedEloChange = (baseEloChange / cf.BaseEloChangeDampening);               //Moderating the bonus
                float finalEloChange    = Math.Max(dampenedEloChange, -1 * (UMA[0] + 3 * cf.Oka));   //First player cannot lose more than his UMA+OK
                finalEloChange = Math.Min(finalEloChange, -1 * (UMA[nbOpponents] - cf.PenaltyLast)); //Last player cannot win more than his UMA+PENALTY
                rankChange    += finalEloChange;
            }

            //Moderating the whole rank change
            float currentDeltaRatio = cf.EloChangeStartRatio + (cf.EloChangeEndRatio - cf.EloChangeStartRatio) * (Math.Max(nbTotalGames, cf.TrialPeriodDuration) / cf.TrialPeriodDuration);
            float finalRankChange   = rankChange * currentDeltaRatio;

            var newRank = oldRank + finalRankChange;

            if (cf.UseEloSystem)
            {
                newRank = Math.Max(cf.MinElo, newRank);
            }
            return(newRank);
        }
Esempio n. 2
0
 public Ranking(string userId, List <Ranking> userOldRks, Ranking oldRk2, Ranking oldRk3, Ranking oldRk4, int position, string gameId, string serverId, LeagueConfig config)
 {
     UserId   = userId;
     Position = position;
     GameId   = gameId;
     ServerId = serverId;
     OldRank  = userOldRks.LastOrDefault().NewRank;
     NewRank  = getNewElo(userOldRks, position, new Ranking[] { oldRk2, oldRk3, oldRk4 }, config);
 }