Example #1
0
        /// <summary>
        /// Calculcate score, modify players inline
        /// </summary>
        /// <returns>
        /// List of updated teams. First entry is winning team
        /// </returns>
        public IEnumerable <ScoreTeam> Calculate(ScoreTeam winningTeam, params ScoreTeam[] others)
        {
            var winningTeamPlayer = winningTeam.Players.Aggregate((a, b) => a + b) / (double)winningTeam.Players.Count;
            var otherPlayers      = others.Select(t => t.Players.Aggregate((a, b) => a + b) / (double)t.Players.Count);

            var updatedWinningTeam = new ScoreTeam();

            foreach (var winningPlayer in winningTeam.Players)
            {
                var updatedWinningPlayer = this.Calculate(winningPlayer, otherPlayers.Select(p => Tuple.Create(p, 1.0)), 1.0 / winningTeam.Players.Count);

                updatedWinningTeam.Players.Add(updatedWinningPlayer);
            }

            var updatedLosingTeams = new List <ScoreTeam>();

            foreach (var otherTeam in others)
            {
                var updatedLosingTeam = new ScoreTeam();

                foreach (var player in otherTeam.Players)
                {
                    var otherLosingTeamPlayers = others.Where(x => x != otherTeam).Select(t => t.Players.Aggregate((a, b) => a + b) / (double)t.Players.Count);
                    var opponents = new[] { Tuple.Create(winningTeamPlayer, 0.0) }.Concat(otherLosingTeamPlayers.Select(x => Tuple.Create(x, 0.5)));

                    var updatedOtherPlayer = this.Calculate(player, opponents, 1.0 / otherTeam.Players.Count);
                    updatedLosingTeam.Players.Add(updatedOtherPlayer);
                }

                updatedLosingTeams.Add(updatedLosingTeam);
            }

            return(new[] { updatedWinningTeam }.Concat(updatedLosingTeams));
        }
Example #2
0
        /// <summary>
        /// Calculcate score, modify players inline
        /// </summary>
        /// <returns>
        /// List of updated teams. First entry is winning team
        /// </returns>
        public IEnumerable<ScoreTeam> Calculate(ScoreTeam winningTeam, params ScoreTeam[] others)
        {
            var winningTeamPlayer = winningTeam.Players.Aggregate((a, b) => a + b) / (double)winningTeam.Players.Count;
            var otherPlayers = others.Select(t => t.Players.Aggregate((a, b) => a + b) / (double)t.Players.Count);

            var updatedWinningTeam = new ScoreTeam();

            foreach(var winningPlayer in winningTeam.Players)
            {
                var updatedWinningPlayer = this.Calculate(winningPlayer, otherPlayers.Select(p => Tuple.Create(p, 1.0)), 1.0 / winningTeam.Players.Count);

                updatedWinningTeam.Players.Add(updatedWinningPlayer);
            }

            var updatedLosingTeams = new List<ScoreTeam>();
            foreach(var otherTeam in others)
            {
                var updatedLosingTeam = new ScoreTeam();

                foreach(var player in otherTeam.Players)
                {
                    var otherLosingTeamPlayers = others.Where(x => x != otherTeam).Select(t => t.Players.Aggregate((a,b) => a + b) / (double)t.Players.Count);
                    var opponents = new[] { Tuple.Create(winningTeamPlayer, 0.0) }.Concat(otherLosingTeamPlayers.Select(x => Tuple.Create(x, 0.5)));

                    var updatedOtherPlayer = this.Calculate(player, opponents, 1.0 / otherTeam.Players.Count);
                    updatedLosingTeam.Players.Add(updatedOtherPlayer);
                }

                updatedLosingTeams.Add(updatedLosingTeam);
            }

            return new[] { updatedWinningTeam }.Concat(updatedLosingTeams);
        }