public static decimal CalculateAvLost(PlayerMeritTableLine line, IGameCalculationEngine engine) { if (line.TotalLost == 0) { return(engine.GameScoreTarget); } else { var possibleChalksInGamesLost = (line.TotalLost * engine.GameScoreTarget); var totalChalksInLostGames = (possibleChalksInGamesLost - line.TotalChalksDropped); return(decimal.Divide(totalChalksInLostGames, line.TotalLost)); } }
private void CalculateForDroppedGames(PlayerMeritTableLine line, List <int> opponentScoresInWonGames, List <int> playerScoresInLostGames, int maximumPossibleGames, int maximumGamesBeforeDropping, IGameCalculationEngine engine) { /* * DataInt1 & DataInt2 used for adjusted values * DataInt3 & DataInt4 used for sorting */ if (line.TotalPlayed > maximumGamesBeforeDropping) { var orderedOpponentScoresInWonGames = opponentScoresInWonGames.OrderByDescending(x => x).ToList(); var orderedPlayerScoresInLostGames = playerScoresInLostGames.OrderBy(x => x).ToList(); this.AdjustChalksForDroppedGames(line, orderedOpponentScoresInWonGames, orderedPlayerScoresInLostGames, maximumGamesBeforeDropping, engine); line.DataInt3 = line.DataInt1; // used for sorting line.DataInt4 = line.DataInt2; // used for sorting } // If player played and won ALL possible games set sort values to their unadjusted values to make sure they are ranked highest if (line.TotalPlayed == maximumPossibleGames && line.TotalWin == maximumPossibleGames) { line.DataInt3 = line.TotalChalksFor; line.DataInt4 = line.TotalChalksAgainst; } }
private void CalculateAdditionalData(PlayerMeritTableLine line, GameXPlayer playerGame, CompetitionEvent competitionEvent, MeritCalculationEngine config, IGameCalculationEngine engine, List <int> opponentScoresInWonGames, List <int> playerScoresInLostGames) { line.DataDecimal1 = CalculationHelper.CalculateAvLost(line, engine); line.DataDecimal2 = CalculationHelper.CalculateAvAll(line); if (config.EnableDropWorseResults) { this.SnapshotTotals(line); this.CalculateForDroppedGames(line, opponentScoresInWonGames, playerScoresInLostGames, competitionEvent.DataInt1.Value, competitionEvent.DataInt2.Value, engine); } line.DataString1 = ListHelper.ListToCsv(opponentScoresInWonGames); line.DataString2 = ListHelper.ListToCsv(playerScoresInLostGames); }
private void AdjustChalksForDroppedGames(PlayerMeritTableLine line, List <int> scoresInWonGames, List <int> scoresInLostGames, int maximumGames, IGameCalculationEngine engine) { var gamesToDrop = line.TotalPlayed - maximumGames; var wonGameDropIndex = 0; var lostGameDropIndex = 0; for (int i = 1; i <= gamesToDrop; i++) { if (line.TotalLost == 0) { line.DataInt1 -= engine.GameScoreTarget; line.DataInt2 -= scoresInWonGames[wonGameDropIndex++]; } else if (line.TotalLost == 1 && i > 1) { line.DataInt1 -= engine.GameScoreTarget; line.DataInt2 -= scoresInWonGames[wonGameDropIndex++]; } else { line.DataInt1 -= scoresInLostGames[lostGameDropIndex++]; line.DataInt2 -= engine.GameScoreTarget; } } }