Exemplo n.º 1
0
        public static void AssertChessRating(TwoPlayerEloCalculator calculator,
                                             double player1BeforeRating,
                                             double player2BeforeRating,
                                             PairwiseComparison player1Result,
                                             double player1AfterRating,
                                             double player2AfterRating)
        {
            var player1 = new Player(1);
            var player2 = new Player(2);

            var teams = Teams.Concat(
                new Team(player1, new EloRating(player1BeforeRating)),
                new Team(player2, new EloRating(player2BeforeRating)));

            var chessGameInfo = new GameInfo(1200, 0, 200, 0, 0);

            var result = calculator.CalculateNewRatings(chessGameInfo, teams,
                (player1Result == PairwiseComparison.Win) ? new[] { 1, 2 } :
                (player1Result == PairwiseComparison.Lose) ? new[] { 2, 1 } :
                new[] { 1, 1 });


            Assert.AreEqual(player1AfterRating, result[player1].Mean, ErrorTolerance);
            Assert.AreEqual(player2AfterRating, result[player2].Mean, ErrorTolerance);
        }
        private static void TwoPlayerChessTestNotDrawn(SkillCalculator calculator)
        {
            // Inspired by a real bug :-)
            var player1 = new Player(1);
            var player2 = new Player(2);
            var gameInfo = new GameInfo(1200.0, 1200.0 / 3.0, 200.0, 1200.0 / 300.0, 0.03);

            var team1 = new Team(player1, new Rating(1301.0007, 42.9232));
            var team2 = new Team(player2, new Rating(1188.7560, 42.5570));

            var newRatings = calculator.CalculateNewRatings(gameInfo, Teams.Concat(team1, team2), 1, 2);

            var player1NewRating = newRatings[player1];
            AssertRating(1304.7820836053318, 42.843513887848658, player1NewRating);

            var player2NewRating = newRatings[player2];
            AssertRating(1185.0383099003536, 42.485604606897752, player2NewRating);
        }