Skip to content

Commit

Permalink
Merge pull request ppy#21517 from smoogipoo/fix-scoreprocessor-accuracy
Browse files Browse the repository at this point in the history
Fix loss of precision in ScoreProcessor.ComputeAccuracy()
  • Loading branch information
peppy authored Dec 5, 2022
2 parents c288873 + 9e64f8d commit 01ceaa0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
Expand Down Expand Up @@ -355,6 +356,28 @@ public void TestLegacyComboIncrease()
}
#pragma warning restore CS0618

[Test]
public void TestAccuracyWhenNearPerfect()
{
const int count_judgements = 1000;
const int count_misses = 1;

double actual = new TestScoreProcessor().ComputeAccuracy(new ScoreInfo
{
Statistics = new Dictionary<HitResult, int>
{
{ HitResult.Great, count_judgements - count_misses },
{ HitResult.Miss, count_misses }
}
});

const double expected = (count_judgements - count_misses) / (double)count_judgements;

Assert.That(actual, Is.Not.EqualTo(0.0));
Assert.That(actual, Is.Not.EqualTo(1.0));
Assert.That(actual, Is.EqualTo(expected).Within(Precision.FLOAT_EPSILON));
}

private class TestRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type) => throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Rulesets/Scoring/ScoreProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public double ComputeAccuracy(ScoreInfo scoreInfo)
// We only extract scoring values from the score's statistics. This is because accuracy is always relative to the point of pass or fail rather than relative to the whole beatmap.
extractScoringValues(scoreInfo.Statistics, out var current, out var maximum);

return maximum.BaseScore > 0 ? current.BaseScore / maximum.BaseScore : 1;
return maximum.BaseScore > 0 ? (double)current.BaseScore / maximum.BaseScore : 1;
}

/// <summary>
Expand Down

0 comments on commit 01ceaa0

Please sign in to comment.