コード例 #1
0
        private GameResult CalculateAndUpdateResult(GameResult result = GameResult.NoResult)
        {
            if (ValilGameS.IsEnded && result == GameResult.NoResult)
            {
                if (ValilGameS.CurrentBoard.BlackKingInCheck() && ValilGameS.Status == GameStatus.Checkmate)
                {
                    result = GameResult.WhiteWin;
                }
                else if (ValilGameS.CurrentBoard.WhiteKingInCheck() && ValilGameS.Status == GameStatus.Checkmate)
                {
                    result = GameResult.BlackWin;
                }
                else
                {
                    result = GameResult.Tie;
                }
            }

            if (result != GameResult.NoResult)
            {
                var whiteRating = MatchS.White.Rating;
                var blackRating = MatchS.Black.Rating;

                EloRatingCalculator.UpdateScores(ref whiteRating, ref blackRating, result);

                // update ratings in database
                _updateUserRatingCommandHandler.Handle(new UpdateUserRatingCommand(MatchS.White.UserName, whiteRating));
                _updateUserRatingCommandHandler.Handle(new UpdateUserRatingCommand(MatchS.Black.UserName, blackRating));
                _updateGameResultCommandHandler.Handle(new UpdateGameResultCommand(MatchS.MatchId, result));
            }

            return(result);
        }
コード例 #2
0
 public CatmashImageControllerTest()
 {
     this.repository          = new CatmashRepository(context);
     this.pairGenerator       = new PatternedPairGenerator();
     this.pairNumTracker      = new PairNumberTracker();
     this.eloRatingCalculator = new EloRatingCalculator();
     this.constants           = new Constants();
 }
コード例 #3
0
 public CatmashImageController(ICatmashRepository repository,
                               IPairGeneratorStrategy pairGenerator,
                               PairNumberTracker pairNumTracker,
                               EloRatingCalculator eloRatingCalculator,
                               Constants constants)
 {
     this.repository          = repository;
     this.pairGenerator       = pairGenerator;
     this.pairNumTracker      = pairNumTracker;
     this.eloRatingCalculator = eloRatingCalculator;
     this.constants           = constants;
 }
コード例 #4
0
        public void ComputeExpectation_ratingsGiven_ShouldReturnExpectation()
        {
            // Arrange
            decimal             ratingA          = 123.4M;
            decimal             ratingB          = 865.23M;
            decimal             expectation      = (decimal)(1 / (1 + Math.Pow(10, (double)((ratingB - ratingA) / 400))));
            EloRatingCalculator ratingCalculator = new EloRatingCalculator();

            // Act
            decimal computedExpectation = ratingCalculator.ComputeExpectation(ratingA, ratingB);

            // Assert
            Assert.Equal(expectation, computedExpectation);
        }
コード例 #5
0
        public void ComputeRating_CurrentRatingAndExpectedAndActualScoresAndKFactorGiven_ShouldReturnNewRating()
        {
            // Arrange
            decimal currentRating = 757.34M;
            decimal expectedScore = 0.74M;
            decimal actualScore   = 1;
            decimal kFactor       = 24;

            decimal             newRating        = currentRating + kFactor * (actualScore - expectedScore);
            EloRatingCalculator ratingCalculator = new EloRatingCalculator();

            // Act
            decimal computedRating = ratingCalculator.ComputeRating(
                currentRating,
                expectedScore,
                actualScore,
                kFactor);

            // Assert
            Assert.Equal(newRating, computedRating);
        }
コード例 #6
0
 public MatchService(LeagueContext leagueContext)
 {
     db          = leagueContext;
     _ratingCalc = new EloRatingCalculator();
 }
コード例 #7
0
 public MatchService()
 {
     db          = new LeagueContext();
     _ratingCalc = new EloRatingCalculator();
 }