public EloResult CalcElo(int playerOneElo, int playerTwoElo, MatchWinner winner) { // A2 = A1 + 32 (G-(1/(1+10 ** ((B1-A1)/400)))) float G = 0; float A1 = System.Convert.ToSingle(playerOneElo); float B1 = System.Convert.ToSingle(playerTwoElo); if (winner == MatchWinner.PlayerOne) { G = 1; } if (winner == MatchWinner.PlayerTwo) { G = 0; } double changeValue = factor * (G - (1 / (1 + System.Math.Pow(10, ((B1 - A1) / divisor))))); int changeValueInt = System.Convert.ToInt32(changeValue); EloResult result = new EloResult(); if (winner == MatchWinner.PlayerOne) { result.PlayerOneElo = playerOneElo + changeValueInt; result.PlayerTwoElo = playerTwoElo - changeValueInt; } if (winner == MatchWinner.PlayerTwo) { result.PlayerOneElo = playerOneElo + changeValueInt; result.PlayerTwoElo = playerTwoElo - changeValueInt; } result.changeValue = changeValueInt; return(result); }
private EloPlayerMatchResultVM GetEloPlayerMatchResultVM(EloResult eloResult) { return(new EloPlayerMatchResultVM() { OpeningRating = eloResult.OpeningRating, TransformedRating = eloResult.TransformedRating, ExpectedScore = eloResult.ExpectedScore, ActualScore = eloResult.ActualScore, KFactor = eloResult.KFactor, ClosingRating = eloResult.ClosingRating }); }
private EloResult CalculateEloRatings(int playerId, int opponentId, bool winner, AllTimeCompetition competition) { var ratings = new EloResult(); var mostRecentRating = GetMatchParticipations(true) .Where(mp => mp.PlayerID == playerId) .FirstOrDefault(); var opponentRating = GetMatchParticipations(true) .Where(mp => mp.PlayerID == opponentId) .FirstOrDefault(); var openingRating = (mostRecentRating == null) ? RATING_SEED_VALUE : mostRecentRating.AllTimeCompetitionResult.ClosingRating; var opptRating = (opponentRating == null) ? RATING_SEED_VALUE : opponentRating.AllTimeCompetitionResult.ClosingRating; return(_ratingCalc.CalculateRatings(openingRating, opptRating, winner, competition.KFactor)); }
public EloResult CalculateRatings(int playerRating, int opponentRating, bool playerWon, int KFactor) { var ratings = new EloResult(); ratings.OpeningRating = playerRating; ratings.TransformedRating = Math.Pow(10, ((double)ratings.OpeningRating / ELO_N_VALUE)); ratings.OpponentRating = opponentRating; ratings.OpponentTransformedRating = Math.Pow(10, (double)ratings.OpponentRating / ELO_N_VALUE); ratings.ExpectedScore = ratings.TransformedRating / (ratings.TransformedRating + ratings.OpponentTransformedRating); ratings.KFactor = KFactor; ratings.ActualScore = playerWon ? 1 : 0; ratings.ClosingRating = Convert.ToInt32(Math.Round(ratings.OpeningRating + ratings.KFactor * (ratings.ActualScore - ratings.ExpectedScore))); return(ratings); }