public PlayerResponse Create(Player player)
 {
     return new PlayerResponse(
         name: player.Name,
         dropped: player.Dropped
     );
 }
示例#2
0
        public decimal GetOpponentsGameWinPercentage(Tournament tournament, Player player, int? roundNumber = null)
        {
            var opponents = tournament.GetPlayerOpponents(player, roundNumber);

            return opponents
                .Select(opponent => GetGameWinPercentage(tournament, opponent, roundNumber))
                .DefaultIfEmpty(0)
                .Average();
        }
示例#3
0
 public int GetGamePoints(Tournament tournament, Player player, int? roundNumber = null)
 {
     return tournament
         .GetPlayerGames(player, roundNumber)
         .Select(game => new PlayerStats(
             wins: game.Winner == player ? 1 : 0,
             losses: game.Winner != player && game.Winner != null ? 1 : 0,
             draws: game.Winner == null ? 1 : 0
         ))
         .Aggregate(0, (sum, stats) => sum + (stats.Wins * GameWin + stats.Draws * GameDraw + stats.Losses * GameLoss));
 }
示例#4
0
        public static IEnumerable<Game> GetPlayerGames(this Tournament tournament, Player player, int? roundNumber = null)
        {
            if(tournament == null)
                return null;

            if(player == null)
                return null;

            return tournament
                .GetPlayerMatches(player, roundNumber)
                .SelectMany(match => match.Games);
        }
示例#5
0
        public static Match GetMatch(this Round round, Player player)
        {
            if(round == null)
                return null;

            if(player == null)
                return null;

            return round
                .Matches
                .Where(m => m.Players.Contains(player))
                .FirstOrDefault();
        }
示例#6
0
        public static IEnumerable<Match> GetPlayerMatches(this Tournament tournament, Player player, int? roundNumber = null)
        {
            if(tournament == null)
                return null;

            if(player == null)
                return null;

            return tournament
                .Rounds
                .Where(round => roundNumber == null || round.Number <= roundNumber)
                .SelectMany(round => round.Matches)
                .Where(match => match.Players.Contains(player));
        }
        public PlayerMatchStatsResponse Create(Player player, Match match)
        {
            if(player == null)
                throw new ArgumentNullException("player");

            if(match == null)
                throw new ArgumentNullException("match");

            return new PlayerMatchStatsResponse(
                name: player.Name,
                dropped: player.Dropped,
                wins: match.Games.Where(game => game.Winner == player).Count(),
                losses: match.Games.Where(game => game.Winner != player && game.Winner != null).Count(),
                draws: match.Games.Where(game => game.Winner == null).Count()
            );
        }
示例#8
0
        public decimal GetMatchWinPercentage(Tournament tournament, Player player, int? roundNumber = null)
        {
            var achieved = GetMatchPoints(tournament, player, roundNumber);

            var maximum = tournament
                .GetPlayerMatches(player, roundNumber)
                .Count() * MatchWin;

            if(maximum == 0)
                return 0.33m;

            var rawPercentage = achieved / (decimal)maximum;

            // Match win percentage is capped at 0.33 on the low end
            return Math.Max(0.33m, rawPercentage);
        }
示例#9
0
 public int GetMatchPoints(Tournament tournament, Player player, int? roundNumber = null)
 {
     return tournament
         .GetPlayerMatches(player, roundNumber)
         .Select(match => new PlayerStats(
             wins: match.Games.Where(game => game.Winner == player).Count(),
             losses: match.Games.Where(game => game.Winner != player && game.Winner != null).Count(),
             draws: match.Games.Where(game => game.Winner == player).Count()
         ))
         .Select(stats => stats.Wins > stats.Losses
             ? MatchWin
             : stats.Wins == stats.Losses
                 ? MatchDraw
                 : MatchLoss)
         .Sum();
 }
示例#10
0
        public static IEnumerable<Player> GetPlayerOpponents(this Tournament tournament, Player player, int? roundNumber = null)
        {
            if(tournament == null)
                return null;

            if(player == null)
                return null;

            return tournament
                .GetPlayerMatches(player, roundNumber)
                .SelectMany(match => match.Players)
                .Except(new[] { player })
                .Distinct();
        }