From af2b80e0304e9541378fa9fa68caad0ca347a37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 4 Mar 2024 11:28:34 +0100 Subject: [PATCH 1/3] Add failing encode test --- .../Formats/LegacyScoreDecoderTest.cs | 2 +- .../Formats/LegacyScoreEncoderTest.cs | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs index 7e3967dc95..43e471320e 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreDecoderTest.cs @@ -432,7 +432,7 @@ namespace osu.Game.Tests.Beatmaps.Formats CultureInfo.CurrentCulture = originalCulture; } - private class TestLegacyScoreDecoder : LegacyScoreDecoder + public class TestLegacyScoreDecoder : LegacyScoreDecoder { private readonly int beatmapVersion; diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs new file mode 100644 index 0000000000..c0a7285f39 --- /dev/null +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyScoreEncoderTest.cs @@ -0,0 +1,55 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.IO; +using NUnit.Framework; +using osu.Game.Beatmaps.Formats; +using osu.Game.Rulesets.Catch; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; +using osu.Game.Tests.Resources; + +namespace osu.Game.Tests.Beatmaps.Formats +{ + public class LegacyScoreEncoderTest + { + [TestCase(1, 3)] + [TestCase(1, 0)] + [TestCase(0, 3)] + public void CatchMergesFruitAndDropletMisses(int missCount, int largeTickMissCount) + { + var ruleset = new CatchRuleset().RulesetInfo; + + var scoreInfo = TestResources.CreateTestScoreInfo(ruleset); + var beatmap = new TestBeatmap(ruleset); + scoreInfo.Statistics = new Dictionary + { + [HitResult.Great] = 50, + [HitResult.LargeTickHit] = 5, + [HitResult.Miss] = missCount, + [HitResult.LargeTickMiss] = largeTickMissCount + }; + var score = new Score { ScoreInfo = scoreInfo }; + + var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap); + + Assert.That(decodedAfterEncode.ScoreInfo.GetCountMiss(), Is.EqualTo(missCount + largeTickMissCount)); + } + + private static Score encodeThenDecode(int beatmapVersion, Score score, TestBeatmap beatmap) + { + var encodeStream = new MemoryStream(); + + var encoder = new LegacyScoreEncoder(score, beatmap); + encoder.Encode(encodeStream); + + var decodeStream = new MemoryStream(encodeStream.GetBuffer()); + + var decoder = new LegacyScoreDecoderTest.TestLegacyScoreDecoder(beatmapVersion); + var decodedAfterEncode = decoder.Parse(decodeStream); + return decodedAfterEncode; + } + } +} From dcd6b028090a97ea1b2c43a374bb9210417b0adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 4 Mar 2024 11:35:31 +0100 Subject: [PATCH 2/3] Fix incorrect implementation of `GetCountMiss()` for catch --- .../Scoring/Legacy/ScoreInfoExtensions.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs index 07c35a334f..23624401e2 100644 --- a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs +++ b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs @@ -198,10 +198,25 @@ namespace osu.Game.Scoring.Legacy } } - public static int? GetCountMiss(this ScoreInfo scoreInfo) => - getCount(scoreInfo, HitResult.Miss); + public static int? GetCountMiss(this ScoreInfo scoreInfo) + { + switch (scoreInfo.Ruleset.OnlineID) + { + case 0: + case 1: + case 3: + return getCount(scoreInfo, HitResult.Miss); + + case 2: + return (getCount(scoreInfo, HitResult.Miss) ?? 0) + (getCount(scoreInfo, HitResult.LargeTickMiss) ?? 0); + } + + return null; + } public static void SetCountMiss(this ScoreInfo scoreInfo, int value) => + // this does not match the implementation of `GetCountMiss()` for catch, + // but we physically cannot recover that data anymore at this point. scoreInfo.Statistics[HitResult.Miss] = value; private static int? getCount(ScoreInfo scoreInfo, HitResult result) From b896d97a4f844498e0c1c914a0b70c4fdf70449f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 4 Mar 2024 11:45:44 +0100 Subject: [PATCH 3/3] Fix catch pp calculator not matching live with respect to miss handling --- .../Difficulty/CatchPerformanceCalculator.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs index b30b85be2d..d07f25ba90 100644 --- a/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs +++ b/osu.Game.Rulesets.Catch/Difficulty/CatchPerformanceCalculator.cs @@ -2,22 +2,21 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; namespace osu.Game.Rulesets.Catch.Difficulty { public class CatchPerformanceCalculator : PerformanceCalculator { - private int fruitsHit; - private int ticksHit; - private int tinyTicksHit; - private int tinyTicksMissed; - private int misses; + private int num300; + private int num100; + private int num50; + private int numKatu; + private int numMiss; public CatchPerformanceCalculator() : base(new CatchRuleset()) @@ -28,11 +27,11 @@ namespace osu.Game.Rulesets.Catch.Difficulty { var catchAttributes = (CatchDifficultyAttributes)attributes; - fruitsHit = score.Statistics.GetValueOrDefault(HitResult.Great); - ticksHit = score.Statistics.GetValueOrDefault(HitResult.LargeTickHit); - tinyTicksHit = score.Statistics.GetValueOrDefault(HitResult.SmallTickHit); - tinyTicksMissed = score.Statistics.GetValueOrDefault(HitResult.SmallTickMiss); - misses = score.Statistics.GetValueOrDefault(HitResult.Miss); + num300 = score.GetCount300() ?? 0; // HitResult.Great + num100 = score.GetCount100() ?? 0; // HitResult.LargeTickHit + num50 = score.GetCount50() ?? 0; // HitResult.SmallTickHit + numKatu = score.GetCountKatu() ?? 0; // HitResult.SmallTickMiss + numMiss = score.GetCountMiss() ?? 0; // HitResult.Miss PLUS HitResult.LargeTickMiss // We are heavily relying on aim in catch the beat double value = Math.Pow(5.0 * Math.Max(1.0, catchAttributes.StarRating / 0.0049) - 4.0, 2.0) / 100000.0; @@ -45,7 +44,7 @@ namespace osu.Game.Rulesets.Catch.Difficulty (numTotalHits > 2500 ? Math.Log10(numTotalHits / 2500.0) * 0.475 : 0.0); value *= lengthBonus; - value *= Math.Pow(0.97, misses); + value *= Math.Pow(0.97, numMiss); // Combo scaling if (catchAttributes.MaxCombo > 0) @@ -86,8 +85,8 @@ namespace osu.Game.Rulesets.Catch.Difficulty } private double accuracy() => totalHits() == 0 ? 0 : Math.Clamp((double)totalSuccessfulHits() / totalHits(), 0, 1); - private int totalHits() => tinyTicksHit + ticksHit + fruitsHit + misses + tinyTicksMissed; - private int totalSuccessfulHits() => tinyTicksHit + ticksHit + fruitsHit; - private int totalComboHits() => misses + ticksHit + fruitsHit; + private int totalHits() => num50 + num100 + num300 + numMiss + numKatu; + private int totalSuccessfulHits() => num50 + num100 + num300; + private int totalComboHits() => numMiss + num100 + num300; } }