From ebdc501e5b6f3dbea0af959ca4fdbb96e3b3ba13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 13 Sep 2023 14:19:49 +0200 Subject: [PATCH] Add example scenarios and configurable score multiplier --- .../TestSceneScoring.cs | 45 ++++++++++++++++--- .../Tests/Visual/Gameplay/ScoringTestScene.cs | 22 +++++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs index 36485b93ab..bb09328ab7 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs @@ -3,6 +3,7 @@ using System; using NUnit.Framework; +using osu.Framework.Bindables; using osu.Game.Beatmaps; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Osu.Beatmaps; @@ -17,6 +18,12 @@ namespace osu.Game.Rulesets.Osu.Tests [TestFixture] public partial class TestSceneScoring : ScoringTestScene { + private Bindable scoreMultiplier { get; } = new BindableDouble + { + Default = 4, + Value = 4 + }; + protected override IBeatmap CreateBeatmap(int maxCombo) { var beatmap = new OsuBeatmap(); @@ -25,10 +32,40 @@ namespace osu.Game.Rulesets.Osu.Tests return beatmap; } - protected override IScoringAlgorithm CreateScoreV1() => new ScoreV1(); + protected override IScoringAlgorithm CreateScoreV1() => new ScoreV1 { ScoreMultiplier = { BindTarget = scoreMultiplier } }; protected override IScoringAlgorithm CreateScoreV2(int maxCombo) => new ScoreV2(maxCombo); protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode) => new OsuProcessorBasedScoringAlgorithm(beatmap, mode); + [Test] + public void TestBasicScenarios() + { + AddStep("set up score multiplier", () => + { + scoreMultiplier.BindValueChanged(_ => Rerun()); + }); + AddStep("set max combo to 100", () => MaxCombo.Value = 100); + AddStep("set perfect score", () => + { + NonPerfectLocations.Clear(); + MissLocations.Clear(); + }); + AddStep("set score with misses", () => + { + NonPerfectLocations.Clear(); + MissLocations.Clear(); + MissLocations.AddRange(new[] { 24d, 49 }); + }); + AddStep("set score with misses and OKs", () => + { + NonPerfectLocations.Clear(); + MissLocations.Clear(); + + NonPerfectLocations.AddRange(new[] { 9d, 19, 29, 39, 59, 69, 79, 89, 99 }); + MissLocations.AddRange(new[] { 24d, 49 }); + }); + AddSliderStep("adjust score multiplier", 0, 10, (int)scoreMultiplier.Default, multiplier => scoreMultiplier.Value = multiplier); + } + private const int base_great = 300; private const int base_ok = 100; @@ -36,9 +73,7 @@ namespace osu.Game.Rulesets.Osu.Tests { private int currentCombo; - // this corresponds to stable's `ScoreMultiplier`. - // value is chosen arbitrarily, towards the upper range. - private const float score_multiplier = 4; + public BindableDouble ScoreMultiplier { get; } = new BindableDouble(); public void ApplyHit() => applyHitV1(base_great); public void ApplyNonPerfect() => applyHitV1(base_ok); @@ -56,7 +91,7 @@ namespace osu.Game.Rulesets.Osu.Tests // combo multiplier // ReSharper disable once PossibleLossOfFraction - TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * score_multiplier)); + TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * ScoreMultiplier.Value)); currentCombo++; } diff --git a/osu.Game/Tests/Visual/Gameplay/ScoringTestScene.cs b/osu.Game/Tests/Visual/Gameplay/ScoringTestScene.cs index 331f1bb9aa..c213a17185 100644 --- a/osu.Game/Tests/Visual/Gameplay/ScoringTestScene.cs +++ b/osu.Game/Tests/Visual/Gameplay/ScoringTestScene.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -13,6 +12,7 @@ using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Events; +using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -36,6 +36,10 @@ namespace osu.Game.Tests.Visual.Gameplay protected abstract IScoringAlgorithm CreateScoreV2(int maxCombo); protected abstract ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode); + protected Bindable MaxCombo => sliderMaxCombo.Current; + protected BindableList NonPerfectLocations => graphs.NonPerfectLocations; + protected BindableList MissLocations => graphs.MissLocations; + private GraphContainer graphs = null!; private SettingsSlider sliderMaxCombo = null!; private SettingsCheckbox scaleToMax = null!; @@ -50,8 +54,8 @@ namespace osu.Game.Tests.Visual.Gameplay [Resolved] private OsuColour colours { get; set; } = null!; - [Test] - public void TestBasic() + [SetUpSteps] + public void SetUpSteps() { AddStep("setup tests", () => { @@ -130,24 +134,24 @@ namespace osu.Game.Tests.Visual.Gameplay } }; - sliderMaxCombo.Current.BindValueChanged(_ => rerun()); - scaleToMax.Current.BindValueChanged(_ => rerun()); + sliderMaxCombo.Current.BindValueChanged(_ => Rerun()); + scaleToMax.Current.BindValueChanged(_ => Rerun()); standardisedVisible.BindValueChanged(_ => rescalePlots()); classicVisible.BindValueChanged(_ => rescalePlots()); scoreV1Visible.BindValueChanged(_ => rescalePlots()); scoreV2Visible.BindValueChanged(_ => rescalePlots()); - graphs.MissLocations.BindCollectionChanged((_, __) => rerun()); - graphs.NonPerfectLocations.BindCollectionChanged((_, __) => rerun()); + graphs.MissLocations.BindCollectionChanged((_, __) => Rerun()); + graphs.NonPerfectLocations.BindCollectionChanged((_, __) => Rerun()); graphs.MaxCombo.BindTo(sliderMaxCombo.Current); - rerun(); + Rerun(); }); } - private void rerun() + protected void Rerun() { graphs.Clear(); legend.Clear();