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); }
public CatmashImageControllerTest() { this.repository = new CatmashRepository(context); this.pairGenerator = new PatternedPairGenerator(); this.pairNumTracker = new PairNumberTracker(); this.eloRatingCalculator = new EloRatingCalculator(); this.constants = new Constants(); }
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; }
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); }
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); }
public MatchService(LeagueContext leagueContext) { db = leagueContext; _ratingCalc = new EloRatingCalculator(); }
public MatchService() { db = new LeagueContext(); _ratingCalc = new EloRatingCalculator(); }