Skip to content

Commit

Permalink
Add example scenarios and configurable score multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Sep 15, 2023
1 parent 0c22ff2 commit ebdc501
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
45 changes: 40 additions & 5 deletions osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,12 @@ namespace osu.Game.Rulesets.Osu.Tests
[TestFixture]
public partial class TestSceneScoring : ScoringTestScene
{
private Bindable<double> scoreMultiplier { get; } = new BindableDouble
{
Default = 4,
Value = 4
};

protected override IBeatmap CreateBeatmap(int maxCombo)
{
var beatmap = new OsuBeatmap();
Expand All @@ -25,20 +32,48 @@ protected override IBeatmap CreateBeatmap(int maxCombo)
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;

private class ScoreV1 : IScoringAlgorithm
{
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);
Expand All @@ -56,7 +91,7 @@ private void applyHitV1(int baseScore)

// 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++;
}
Expand Down
22 changes: 13 additions & 9 deletions osu.Game/Tests/Visual/Gameplay/ScoringTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +12,7 @@
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;
Expand All @@ -36,6 +36,10 @@ public abstract partial class ScoringTestScene : OsuTestScene
protected abstract IScoringAlgorithm CreateScoreV2(int maxCombo);
protected abstract ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode);

protected Bindable<int> MaxCombo => sliderMaxCombo.Current;
protected BindableList<double> NonPerfectLocations => graphs.NonPerfectLocations;
protected BindableList<double> MissLocations => graphs.MissLocations;

private GraphContainer graphs = null!;
private SettingsSlider<int> sliderMaxCombo = null!;
private SettingsCheckbox scaleToMax = null!;
Expand All @@ -50,8 +54,8 @@ public abstract partial class ScoringTestScene : OsuTestScene
[Resolved]
private OsuColour colours { get; set; } = null!;

[Test]
public void TestBasic()
[SetUpSteps]
public void SetUpSteps()
{
AddStep("setup tests", () =>
{
Expand Down Expand Up @@ -130,24 +134,24 @@ public void TestBasic()
}
};
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();
Expand Down

0 comments on commit ebdc501

Please sign in to comment.