Ejemplo n.º 1
0
        protected void goThroughMatches()
        {
            foreach (Match ma in matches)
            {
                int team1index = 0, team2index = 0;

                team1index = teams.FindIndex(x => x.name == ma.team1);
                team2index = teams.FindIndex(x => x.name == ma.team2);

                if (!String.IsNullOrWhiteSpace(ma.team1Score) && !String.IsNullOrWhiteSpace(ma.team2Score))
                {
                    int team1score = Convert.ToInt32(ma.team1Score);
                    int team2score = Convert.ToInt32(ma.team2Score);

                    if (team1score == team2score)
                    {
                        for (int i = 0; i < team1score; i++)
                        {
                            results.AddDraw(teams[team2index].rating, teams[team1index].rating);
                        }
                    }
                    if (team1score > team2score)
                    {
                        for (int i = 0; i < team2score; i++)
                        {
                            calculateRatings(teams[team1index].rating, teams[team2index].rating);
                            calculateRatings(teams[team2index].rating, teams[team1index].rating);
                        }
                        for (int i = 0; i < (team1score - team2score); i++)
                        {
                            calculateRatings(teams[team1index].rating, teams[team2index].rating);
                        }
                    }
                    if (team2score > team1score)
                    {
                        for (int i = 0; i < team1score; i++)
                        {
                            calculateRatings(teams[team1index].rating, teams[team2index].rating);
                            calculateRatings(teams[team2index].rating, teams[team1index].rating);
                        }
                        for (int i = 0; i < (team2score - team1score); i++)
                        {
                            calculateRatings(teams[team2index].rating, teams[team1index].rating);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            // Instantiate a RatingCalculator object.
            // At instantiation, you can set the default rating for a player's volatility and
            // the system constant for your game ("τ", which constrains changes in volatility
            // over time) or just accept the defaults.
            var calculator = new RatingCalculator(/* initVolatility, tau */);

            // Instantiate a Rating object for each player.
            var player1 = new Rating(calculator /* , rating, ratingDeviation, volatility */);
            var player2 = new Rating(calculator /* , rating, ratingDeviation, volatility */);
            var player3 = new Rating(calculator /* , rating, ratingDeviation, volatility */);

            // Instantiate a RatingPeriodResults object.
            var results = new RatingPeriodResults();

            // Add game results to the RatingPeriodResults object until you reach the end of your rating period.
            // Use addResult(winner, loser) for games that had an outcome.
            results.AddResult(player1, player2);
            // Use addDraw(player1, player2) for games that resulted in a draw.
            results.AddDraw(player1, player2);
            // Use addParticipant(player) to add players that played no games in the rating period.
            results.AddParticipant(player3);

            // Once you've reached the end of your rating period, call the updateRatings method
            // against the RatingCalculator; this takes the RatingPeriodResults object as argument.
            //  * Note that the RatingPeriodResults object is cleared down of game results once
            //    the new ratings have been calculated.
            //  * Participants remain within the RatingPeriodResults object, however, and will
            //    have their rating deviations recalculated at the end of future rating periods
            //    even if they don't play any games. This is in-line with Glickman's algorithm.
            calculator.UpdateRatings(results);

            // Access the getRating, getRatingDeviation, and getVolatility methods of each
            // player's Rating to see the new values.
            var players = new[] { player1, player2, player3 };

            for (var index = 0; index < players.Length; index++)
            {
                var player = players[index];
                Console.WriteLine("Player #" + index + " values: " + player.GetRating() + ", " +
                                  player.GetRatingDeviation() + ", " + player.GetVolatility());
            }
        }
Ejemplo n.º 3
0
        // Private methods

        private void AddGame(string winner, string loser, bool isDraw)
        {
            // If the players don't already exist, add them
            if (!playerlist.ContainsKey(winner))
            {
                playerlist.Add(winner, new Rating(calculator));
            }
            if (!playerlist.ContainsKey(loser))
            {
                playerlist.Add(loser, new Rating(calculator));
            }

            if (isDraw)
            {
                results.AddDraw(playerlist[winner], playerlist[loser]);
            }
            else
            {
                results.AddResult(playerlist[winner], playerlist[loser]);
            }
        }