Skip to content

Commit

Permalink
Merge pull request #20008 from smoogipoo/scoreprocessor-computescore
Browse files Browse the repository at this point in the history
Refactor/merge `ScoreProcessor.ComputeScore()` methods
  • Loading branch information
peppy authored Aug 29, 2022
2 parents 3e246ca + c0b13c7 commit 2b7b771
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 62 deletions.
4 changes: 2 additions & 2 deletions osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void TestGetScoreWithExternalStatistics(HitResult result, int expectedSco
HitObjects = { new TestHitObject(result) }
});

Assert.That(scoreProcessor.ComputeFinalScore(ScoringMode.Standardised, new ScoreInfo
Assert.That(scoreProcessor.ComputeScore(ScoringMode.Standardised, new ScoreInfo
{
Ruleset = new TestRuleset().RulesetInfo,
MaxCombo = result.AffectsCombo() ? 1 : 0,
Expand Down Expand Up @@ -350,7 +350,7 @@ public void TestLegacyComboIncrease()
}
};

double totalScore = new TestScoreProcessor().ComputeFinalScore(ScoringMode.Standardised, testScore);
double totalScore = new TestScoreProcessor().ComputeScore(ScoringMode.Standardised, testScore);
Assert.That(totalScore, Is.EqualTo(750_000)); // 500K from accuracy (100%), and 250K from combo (50%).
}
#pragma warning restore CS0618
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Task<PerformanceAttributes> getPerfectPerformance(ScoreInfo score, Cance
// calculate total score
ScoreProcessor scoreProcessor = ruleset.CreateScoreProcessor();
scoreProcessor.Mods.Value = perfectPlay.Mods;
perfectPlay.TotalScore = (long)scoreProcessor.ComputeFinalScore(ScoringMode.Standardised, perfectPlay);
perfectPlay.TotalScore = (long)scoreProcessor.ComputeScore(ScoringMode.Standardised, perfectPlay);

// compute rank achieved
// default to SS, then adjust the rank with mods
Expand Down
60 changes: 3 additions & 57 deletions osu.Game/Rulesets/Scoring/ScoreProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public ScoringValues MaximumScoringValues

/// <summary>
/// The maximum <see cref="HitResult"/> of a basic (non-tick and non-bonus) hitobject.
/// Only populated via <see cref="ComputeFinalScore"/> or <see cref="ResetFromReplayFrame"/>.
/// Only populated via <see cref="ComputeScore(osu.Game.Rulesets.Scoring.ScoringMode,osu.Game.Scoring.ScoreInfo)"/> or <see cref="ResetFromReplayFrame"/>.
/// </summary>
private HitResult? maxBasicResult;

Expand Down Expand Up @@ -281,7 +281,7 @@ private void updateScore()
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
[Pure]
public double ComputeFinalScore(ScoringMode mode, ScoreInfo scoreInfo)
public double ComputeScore(ScoringMode mode, ScoreInfo scoreInfo)
{
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
throw new ArgumentException($"Unexpected score ruleset. Expected \"{ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\".");
Expand All @@ -291,60 +291,6 @@ public double ComputeFinalScore(ScoringMode mode, ScoreInfo scoreInfo)
return ComputeScore(mode, current, maximum);
}

/// <summary>
/// Computes the total score of a partially-completed <see cref="ScoreInfo"/>. This should be used when it is unknown whether a score is complete.
/// </summary>
/// <remarks>
/// Requires <see cref="JudgementProcessor.ApplyBeatmap"/> to have been called before use.
/// </remarks>
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
[Pure]
public double ComputePartialScore(ScoringMode mode, ScoreInfo scoreInfo)
{
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
throw new ArgumentException($"Unexpected score ruleset. Expected \"{ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\".");

if (!beatmapApplied)
throw new InvalidOperationException($"Cannot compute partial score without calling {nameof(ApplyBeatmap)}.");

ExtractScoringValues(scoreInfo, out var current, out _);

return ComputeScore(mode, current, MaximumScoringValues);
}

/// <summary>
/// Computes the total score of a given <see cref="ScoreInfo"/> with a given custom max achievable combo.
/// </summary>
/// <remarks>
/// This is useful for processing legacy scores in which the maximum achievable combo can be more accurately determined via external means (e.g. database values or difficulty calculation).
/// <p>Does not require <see cref="JudgementProcessor.ApplyBeatmap"/> to have been called before use.</p>
/// </remarks>
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
/// <param name="maxAchievableCombo">The maximum achievable combo for the provided beatmap.</param>
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
[Pure]
public double ComputeFinalLegacyScore(ScoringMode mode, ScoreInfo scoreInfo, int maxAchievableCombo)
{
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
throw new ArgumentException($"Unexpected score ruleset. Expected \"{ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\".");

double accuracyRatio = scoreInfo.Accuracy;
double comboRatio = maxAchievableCombo > 0 ? (double)scoreInfo.MaxCombo / maxAchievableCombo : 1;

ExtractScoringValues(scoreInfo, out var current, out var maximum);

// For legacy osu!mania scores, a full-GREAT score has 100% accuracy. If combined with a full-combo, the score becomes indistinguishable from a full-PERFECT score.
// To get around this, the accuracy ratio is always recalculated based on the hit statistics rather than trusting the score.
// Note: This cannot be applied universally to all legacy scores, as some rulesets (e.g. catch) group multiple judgements together.
if (scoreInfo.IsLegacyScore && scoreInfo.Ruleset.OnlineID == 3 && maximum.BaseScore > 0)
accuracyRatio = current.BaseScore / maximum.BaseScore;

return ComputeScore(mode, accuracyRatio, comboRatio, current.BonusScore, maximum.CountBasicHitObjects);
}

/// <summary>
/// Computes the total score from scoring values.
/// </summary>
Expand Down Expand Up @@ -454,7 +400,7 @@ public virtual void PopulateScore(ScoreInfo score)
score.MaximumStatistics[result] = maximumResultCounts.GetValueOrDefault(result);

// Populate total score after everything else.
score.TotalScore = (long)Math.Round(ComputeFinalScore(ScoringMode.Standardised, score));
score.TotalScore = (long)Math.Round(ComputeScore(ScoringMode.Standardised, score));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Scoring/ScoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public async Task<long> GetTotalScoreAsync([NotNull] ScoreInfo score, ScoringMod
var scoreProcessor = ruleset.CreateScoreProcessor();
scoreProcessor.Mods.Value = score.Mods;

return (long)Math.Round(scoreProcessor.ComputeFinalLegacyScore(mode, score, beatmapMaxCombo.Value));
return (long)Math.Round(scoreProcessor.ComputeScore(mode, score));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected override async Task PrepareScoreForResultsAsync(Score score)
{
await base.PrepareScoreForResultsAsync(score).ConfigureAwait(false);

Score.ScoreInfo.TotalScore = (int)Math.Round(ScoreProcessor.ComputeFinalScore(ScoringMode.Standardised, Score.ScoreInfo));
Score.ScoreInfo.TotalScore = (int)Math.Round(ScoreProcessor.ComputeScore(ScoringMode.Standardised, Score.ScoreInfo));
}

protected override void Dispose(bool isDisposing)
Expand Down

0 comments on commit 2b7b771

Please sign in to comment.