Skip to content

Commit

Permalink
Merge pull request #24933 from bdach/scoring-test-mods
Browse files Browse the repository at this point in the history
Include mod multipliers in scoring test scenes
  • Loading branch information
peppy authored Nov 28, 2023
2 parents ee0494a + efb6c30 commit 644dd68
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 45 deletions.
46 changes: 37 additions & 9 deletions osu.Game.Rulesets.Catch.Tests/TestSceneScoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
Expand All @@ -10,7 +12,9 @@
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Scoring;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Tests.Visual.Gameplay;

namespace osu.Game.Rulesets.Catch.Tests
Expand All @@ -37,11 +41,14 @@ protected override IBeatmap CreateBeatmap(int maxCombo)
return beatmap;
}

protected override IScoringAlgorithm CreateScoreV1() => new ScoreV1 { ScoreMultiplier = { BindTarget = scoreMultiplier } };
protected override IScoringAlgorithm CreateScoreV1(IReadOnlyList<Mod> selectedMods)
=> new ScoreV1(selectedMods) { ScoreMultiplier = { BindTarget = scoreMultiplier } };

protected override IScoringAlgorithm CreateScoreV2(int maxCombo) => new ScoreV2(maxCombo);
protected override IScoringAlgorithm CreateScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
=> new ScoreV2(maxCombo, selectedMods);

protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode) => new CatchProcessorBasedScoringAlgorithm(beatmap, mode);
protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
=> new CatchProcessorBasedScoringAlgorithm(beatmap, mode, selectedMods);

[Test]
public void TestBasicScenarios()
Expand Down Expand Up @@ -69,10 +76,21 @@ public void TestBasicScenarios()

private class ScoreV1 : IScoringAlgorithm
{
private int currentCombo;
private readonly double modMultiplier;

public BindableDouble ScoreMultiplier { get; } = new BindableDouble();

private int currentCombo;

public ScoreV1(IReadOnlyList<Mod> selectedMods)
{
var ruleset = new CatchRuleset();
modMultiplier = ruleset.CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(selectedMods, new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});
}

public void ApplyHit() => applyHitV1(base_great);

public void ApplyNonPerfect() => throw new NotSupportedException("catch does not have \"non-perfect\" judgements.");
Expand All @@ -91,7 +109,7 @@ private void applyHitV1(int baseScore)

// combo multiplier
// ReSharper disable once PossibleLossOfFraction
TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * ScoreMultiplier.Value));
TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * (ScoreMultiplier.Value * modMultiplier)));

currentCombo++;
}
Expand All @@ -104,13 +122,23 @@ private class ScoreV2 : IScoringAlgorithm
private int currentCombo;
private double comboPortion;

private readonly double modMultiplier;

private readonly double comboPortionMax;

private const double combo_base = 4;
private const int combo_cap = 200;

public ScoreV2(int maxCombo)
public ScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
{
var ruleset = new CatchRuleset();
modMultiplier = ruleset.CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(
selectedMods.Append(new ModScoreV2()).ToList(),
new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});

for (int i = 0; i < maxCombo; i++)
ApplyHit();

Expand All @@ -135,13 +163,13 @@ public void ApplyMiss()
}

public long TotalScore
=> (int)Math.Round(1000000 * comboPortion / comboPortionMax); // vast simplification, as we're not doing ticks here.
=> (int)Math.Round((1000000 * comboPortion / comboPortionMax) * modMultiplier); // vast simplification, as we're not doing ticks here.
}

private class CatchProcessorBasedScoringAlgorithm : ProcessorBasedScoringAlgorithm
{
public CatchProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode)
: base(beatmap, mode)
public CatchProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
: base(beatmap, mode, selectedMods)
{
}

Expand Down
41 changes: 31 additions & 10 deletions osu.Game.Rulesets.Mania.Tests/TestSceneScoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Scoring;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Tests.Visual.Gameplay;

namespace osu.Game.Rulesets.Mania.Tests
Expand All @@ -25,9 +29,11 @@ protected override IBeatmap CreateBeatmap(int maxCombo)
return beatmap;
}

protected override IScoringAlgorithm CreateScoreV1() => new ScoreV1(MaxCombo.Value);
protected override IScoringAlgorithm CreateScoreV2(int maxCombo) => new ScoreV2(maxCombo);
protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode) => new ManiaProcessorBasedScoringAlgorithm(beatmap, mode);
protected override IScoringAlgorithm CreateScoreV1(IReadOnlyList<Mod> selectedMods) => new ScoreV1(MaxCombo.Value, selectedMods);
protected override IScoringAlgorithm CreateScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods) => new ScoreV2(maxCombo, selectedMods);

protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
=> new ManiaProcessorBasedScoringAlgorithm(beatmap, mode, selectedMods);

[Test]
public void TestBasicScenarios()
Expand Down Expand Up @@ -59,11 +65,17 @@ private class ScoreV1 : IScoringAlgorithm
private int currentCombo;
private double comboAddition = 100;
private double totalScoreDouble;

private readonly double scoreMultiplier;

public ScoreV1(int maxCombo)
public ScoreV1(int maxCombo, IReadOnlyList<Mod> selectedMods)
{
scoreMultiplier = 500000d / maxCombo;
var ruleset = new ManiaRuleset();

scoreMultiplier = 500000d / maxCombo * ruleset.CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(selectedMods, new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});
}

public void ApplyHit() => applyHitV1(320, add => add + 2, 32);
Expand Down Expand Up @@ -103,13 +115,22 @@ private class ScoreV2 : IScoringAlgorithm

private readonly double comboPortionMax;
private readonly int maxCombo;
private readonly double modMultiplier;

private const double combo_base = 4;

public ScoreV2(int maxCombo)
public ScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
{
this.maxCombo = maxCombo;

var ruleset = new ManiaRuleset();
modMultiplier = new ManiaRuleset().CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(
selectedMods.Append(new ModScoreV2()).ToArray(),
new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});

for (int i = 0; i < this.maxCombo; i++)
ApplyHit();

Expand Down Expand Up @@ -148,18 +169,18 @@ public long TotalScore
float accuracy = (float)(currentBaseScore / maxBaseScore);

return (int)Math.Round
(
((
200000 * comboPortion / comboPortionMax +
800000 * Math.Pow(accuracy, 2 + 2 * accuracy) * ((double)currentHits / maxCombo)
);
) * modMultiplier);
}
}
}

private class ManiaProcessorBasedScoringAlgorithm : ProcessorBasedScoringAlgorithm
{
public ManiaProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode)
: base(beatmap, mode)
public ManiaProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
: base(beatmap, mode, selectedMods)
{
}

Expand Down
52 changes: 42 additions & 10 deletions osu.Game.Rulesets.Osu.Tests/TestSceneScoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
using osu.Game.Tests.Visual.Gameplay;

namespace osu.Game.Rulesets.Osu.Tests
Expand All @@ -32,9 +36,17 @@ protected override IBeatmap CreateBeatmap(int maxCombo)
return beatmap;
}

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);
protected override IScoringAlgorithm CreateScoreV1(IReadOnlyList<Mod> selectedMods)
=> new ScoreV1(selectedMods)
{
ScoreMultiplier = { BindTarget = scoreMultiplier }
};

protected override IScoringAlgorithm CreateScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
=> new ScoreV2(maxCombo, selectedMods);

protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> mods)
=> new OsuProcessorBasedScoringAlgorithm(beatmap, mode, mods);

[Test]
public void TestBasicScenarios()
Expand Down Expand Up @@ -71,9 +83,19 @@ public void TestBasicScenarios()

private class ScoreV1 : IScoringAlgorithm
{
private readonly double modMultiplier;
public BindableDouble ScoreMultiplier { get; } = new BindableDouble();

private int currentCombo;

public BindableDouble ScoreMultiplier { get; } = new BindableDouble();
public ScoreV1(IReadOnlyList<Mod> selectedMods)
{
var ruleset = new OsuRuleset();
modMultiplier = ruleset.CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(selectedMods, new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});
}

public void ApplyHit() => applyHitV1(base_great);
public void ApplyNonPerfect() => applyHitV1(base_ok);
Expand All @@ -91,7 +113,7 @@ private void applyHitV1(int baseScore)

// combo multiplier
// ReSharper disable once PossibleLossOfFraction
TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * ScoreMultiplier.Value));
TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * (ScoreMultiplier.Value * modMultiplier)));

currentCombo++;
}
Expand All @@ -107,13 +129,23 @@ private class ScoreV2 : IScoringAlgorithm
private double maxBaseScore;
private int currentHits;

private readonly double modMultiplier;

private readonly double comboPortionMax;
private readonly int maxCombo;

public ScoreV2(int maxCombo)
public ScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
{
this.maxCombo = maxCombo;

var ruleset = new OsuRuleset();
modMultiplier = ruleset.CreateLegacyScoreSimulator().GetLegacyScoreMultiplier(
selectedMods.Append(new ModScoreV2()).ToList(),
new LegacyBeatmapConversionDifficultyInfo
{
SourceRuleset = ruleset.RulesetInfo
});

for (int i = 0; i < this.maxCombo; i++)
ApplyHit();

Expand Down Expand Up @@ -152,18 +184,18 @@ public long TotalScore
double accuracy = currentBaseScore / maxBaseScore;

return (int)Math.Round
(
((
700000 * comboPortion / comboPortionMax +
300000 * Math.Pow(accuracy, 10) * ((double)currentHits / maxCombo)
);
) * modMultiplier);
}
}
}

private class OsuProcessorBasedScoringAlgorithm : ProcessorBasedScoringAlgorithm
{
public OsuProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode)
: base(beatmap, mode)
public OsuProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
: base(beatmap, mode, selectedMods)
{
}

Expand Down
Loading

0 comments on commit 644dd68

Please sign in to comment.