public ScoreResult Calculate(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, int gamesPrPlayer, DateTime dateTime) { var rating = new EloRating(redOffensive.Score + redDefensive.Score, blueOffensive.Score + blueDefensive.Score, goalsRed, goalsBlue, gamesPrPlayer); var winningPrice = Math.Max(rating.Point1, rating.Point2) + Math.Abs(goalsBlue - goalsRed); return(GetScoreResult(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, winningPrice, dateTime)); }
protected virtual Score GetLoosingScore(PlayarStatisistics playar, double winningPrice) { return(new Score() { Id = playar.Id, ScoreCount = playar.Score - winningPrice }); }
protected override Events.Score GetLoosingScore(PlayarStatisistics playar, double winningPrice) { if (playar.Total.GamesPlayed >= PlayarStatisistics.InplayGames) { return(base.GetLoosingScore(playar, winningPrice)); } return(base.GetLoosingScore(playar, 0)); }
public ScoreResult Calculate(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, int gamesPrPlayer, DateTime dateTime) { var existingRed = redOffensive.Score + redDefensive.Score; var existingBlue = blueOffensive.Score + blueDefensive.Score; int winningPrice; double multiplier = Math.Abs(goalsBlue - goalsRed); if (goalsRed > goalsBlue) { winningPrice = (int)((existingRed / Math.Max(existingBlue, 1)) * multiplier); } else { winningPrice = (int)((existingBlue / Math.Max(existingRed, 1)) * multiplier); } return(GetScoreResult(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, winningPrice, dateTime)); }
public ScoreResult Calculate(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, int gamesPrPlayer, DateTime dateTime) { var existingRed = redOffensive.Score + redDefensive.Score; var existingBlue = blueOffensive.Score + blueDefensive.Score; var a = Math.Abs(goalsBlue - goalsRed); var b = Math.Abs(existingBlue - existingRed); const int minimumScore = 10; var winningPrice = (a * b * 0.1) / 2; if (!FavoriteTeamHasWon(goalsRed, goalsBlue, existingBlue, existingRed)) { winningPrice = b / 2; } winningPrice = Math.Max(minimumScore, winningPrice); return(GetScoreResult(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, winningPrice, dateTime)); }
public void CanCalulateWinPercentage() { var p = new PlayarStatisistics(Guid.Empty, new PlayarName("Test")); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), true, false); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), true, true); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), true, true); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), false, true); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), false, false); p.UpdateScore(8, new Activity("", new DateTime(1, 1, 2)), false, false); Assert.AreEqual(50, p.Total.WinPercentage); //Assert.AreEqual(98, p.WinPercentageAsOffensive + p.WinPercentageAsDefensive + p.LoosePercentageAsOffensive + p.LoosePercentageAsDefensive); Assert.AreEqual(66, p.Offensive.WinPercentage); Assert.AreEqual(33, p.Defensive.WinPercentage); Assert.AreEqual(67, p.Defensive.LoosingPercentage); //Assert.AreEqual(16, p.LoosePercentageAsOffensive); //Assert.AreEqual(33, p.LoosePercentageAsDefensive); }
private Activity GetFormattedStory(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, double winningPrice, DateTime dateTime) { if (goalsRed > goalsBlue) { if (goalsBlue == 0) { return(new Activity(string.Format("{0} and {1} gave vinkekat to {3} and {4} scoreing {2} points.", redOffensive.Name, redDefensive.Name, winningPrice, blueOffensive.Name, blueDefensive.Name), dateTime)); } return(new Activity(string.Format("{0} and {1} won {2} points against {3} and {4} ({5} - {6})", redOffensive.Name, redDefensive.Name, winningPrice, blueOffensive.Name, blueDefensive.Name, goalsRed, goalsBlue), dateTime)); } return(new Activity(string.Format("{0} and {1} won {2} points against {3} and {4} ({5} - {6})", blueOffensive.Name, blueDefensive.Name, winningPrice, redOffensive.Name, redDefensive.Name, goalsBlue, goalsRed), dateTime )); }
protected ScoreResult GetScoreResult(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, double winningPrice, DateTime dateTime) { if (goalsRed > goalsBlue) { return(new ScoreResult( GetWinningScore(redOffensive, winningPrice), GetWinningScore(redDefensive, winningPrice), GetLoosingScore(blueOffensive, winningPrice), GetLoosingScore(blueDefensive, winningPrice), winningPrice, GetFormattedStory(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, winningPrice, dateTime) )); } return(new ScoreResult( GetLoosingScore(redOffensive, winningPrice), GetLoosingScore(redDefensive, winningPrice), GetWinningScore(blueOffensive, winningPrice), GetWinningScore(blueDefensive, winningPrice), winningPrice, GetFormattedStory(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, winningPrice, dateTime) )); }
public ScoreResult Calculate(PlayarStatisistics redOffensive, PlayarStatisistics redDefensive, PlayarStatisistics blueOffensive, PlayarStatisistics blueDefensive, int goalsRed, int goalsBlue, int gamesPrPlayer, DateTime dateTime) { return(GetScoreResult(redOffensive, redDefensive, blueOffensive, blueDefensive, goalsRed, goalsBlue, 10, dateTime)); }