Exemple #1
0
 private UserStats cloneNewUserStats(IEnumerable<UserStats> stats, int userId, Game game)
 {
     var stat = stats.Where(x => x.UserId == userId).OrderByDescending(x => x.CalcDate).FirstOrDefault();
     if (stat == null)
     {
         stat = new UserStats { UserId = userId };
     }
     else
     {
         stat = new UserStats
             {
                 UserId = userId,
                 Draws = stat.Draws,
                 Elo = stat.Elo,
                 Losses = stat.Losses,
                 WinRate = stat.WinRate,
                 Wins = stat.Wins,
                 Games=stat.Games
             };
     }
     stat.CalcDate = game.Date;
     stat.GameId = game.Id;
     return stat;
 }
Exemple #2
0
 private void calculateGeneralStatsForPlayer(Game game, UserStats stats)
 {
     stats.Games++;
     if (game.ScoreA == game.ScoreB)
     {
         stats.Draws++;
     }
     else
     {
         if (game.PlayerAId == stats.UserId)
         {
             if (game.ScoreA > game.ScoreB)
             {
                 stats.Wins++;
             }
             else
             {
                 stats.Losses++;
             }
         }
         else
         {
             if (game.ScoreB > game.ScoreA)
             {
                 stats.Wins++;
             }
             else
             {
                 stats.Losses++;
             }
         }
     }
     stats.WinRate = decimal.Round((stats.Wins * 1.0000m + stats.Draws * 0.5000m) / stats.Games * 100, 2);
 }
Exemple #3
0
 private void calculateGame(Game game, UserStats statsA, UserStats statsB)
 {
     calculateElo(game, statsA, statsB);
     calculateGeneralStats(game, statsA, statsB);
 }
Exemple #4
0
 private void calculateGeneralStats(Game game, UserStats statsA, UserStats statsB)
 {
     calculateGeneralStatsForPlayer(game, statsA);
     calculateGeneralStatsForPlayer(game, statsB);
 }
Exemple #5
0
        private void calculateElo(Game game, UserStats statsA, UserStats statsB)
        {
            var elo = new EloCalculator(statsA.Elo, statsB.Elo);
            if (game.ScoreA > game.ScoreB)
            {
                elo.WinGamePlayerA();
            }
            else if (game.ScoreA < game.ScoreB)
            {
                elo.WinGamePlayerB();
            }
            else
            {
                elo.DrawGame();
            }

            statsA.Elo = (decimal)elo.RatingPlayerA;
            statsB.Elo = (decimal)elo.RatingPlayerB;
        }