/// <summary> /// /// </summary> /// <param name="playerA">Player 'A' of Match</param> /// <param name="playerB">Player 'B' of Match</param> /// <param name="outCome">The outcome of the match either win, loss or draw</param> /// <returns>New ratings for both players</returns> public NewRatings Calculate(CurrentPlayerRating playerA, CurrentPlayerRating playerB, MatchOutcome outCome) { PlayerRatingCalculator calculator = new PlayerRatingCalculator(); int playerAExpectedOutcome = calculator.CalculateExpectedOutcome(playerA.Rating, playerB.Rating); int playerBExpectedOutcome = calculator.CalculateExpectedOutcome(playerB.Rating, playerA.Rating); decimal playerAOutcome = 0; switch (outCome) { case MatchOutcome.PlayerAWin: playerAOutcome = 1; break; case MatchOutcome.Draw: playerAOutcome = 0.5M; break; case MatchOutcome.PlayerBWin: playerAOutcome = 0; break; } decimal playerBOutcome = 0; switch (outCome) { case MatchOutcome.PlayerAWin: playerBOutcome = 0; break; case MatchOutcome.Draw: playerBOutcome = 0.5M; break; case MatchOutcome.PlayerBWin: playerBOutcome = 1; break; } var newPLayerRatingA = new NewlayerRatingsDefault() { PlayerId = "A", Rating = calculator.CalculateNewRating(playerA.Rating, _maximumRatingChange, playerAExpectedOutcome, playerAOutcome) }; var newPLayerRatingB = new NewlayerRatingsDefault() { PlayerId = "B", Rating = calculator.CalculateNewRating(playerB.Rating, _maximumRatingChange, playerBExpectedOutcome, playerBOutcome) }; return(new NewRatingsDefault { PlayerA = newPLayerRatingA, PlayerB = newPLayerRatingB }); }
public void CalculateNewPlayerRating(int currentRating, int maximumRatingChange, int expectedOutcome, decimal outcome, int newRating) { var calculator = new PlayerRatingCalculator(); var result = calculator.CalculateNewRating(currentRating, maximumRatingChange, expectedOutcome, outcome); Assert.Equal(newRating, result); }
public void CalculateExpectedOutcome(int result, int playerA, int playerB) { var calculator = new PlayerRatingCalculator(); Assert.Equal(result, calculator.CalculateExpectedOutcome(playerA, playerB)); }