osu/osu.Game.Rulesets.Catch.Tests/TestSceneScoring.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

186 lines
6.7 KiB
C#
Raw Normal View History

2023-09-13 12:35:07 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
2023-09-13 12:35:07 +00:00
using NUnit.Framework;
using osu.Framework.Bindables;
2023-09-13 12:35:07 +00:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Scoring;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
2023-09-13 12:35:07 +00:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Scoring.Legacy;
2023-09-13 12:35:07 +00:00
using osu.Game.Tests.Visual.Gameplay;
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public partial class TestSceneScoring : ScoringTestScene
{
public TestSceneScoring()
: base(supportsNonPerfectJudgements: false)
{
}
private Bindable<double> scoreMultiplier { get; } = new BindableDouble
{
Default = 4,
Value = 4
};
2023-09-13 12:35:07 +00:00
protected override IBeatmap CreateBeatmap(int maxCombo)
{
var beatmap = new CatchBeatmap();
for (int i = 0; i < maxCombo; ++i)
beatmap.HitObjects.Add(new Fruit());
return beatmap;
}
protected override IScoringAlgorithm CreateScoreV1(IReadOnlyList<Mod> selectedMods)
=> new ScoreV1(selectedMods) { ScoreMultiplier = { BindTarget = scoreMultiplier } };
2023-09-13 12:35:07 +00:00
protected override IScoringAlgorithm CreateScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
=> new ScoreV2(maxCombo, selectedMods);
2023-09-13 12:35:07 +00:00
protected override ProcessorBasedScoringAlgorithm CreateScoreAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
=> new CatchProcessorBasedScoringAlgorithm(beatmap, mode, selectedMods);
2023-09-13 12:35:07 +00:00
[Test]
public void TestBasicScenarios()
2023-09-13 12:35:07 +00:00
{
AddStep("set up score multiplier", () =>
2023-09-13 12:35:07 +00:00
{
scoreMultiplier.BindValueChanged(_ => Rerun());
});
AddStep("set max combo to 100", () => MaxCombo.Value = 100);
AddStep("set perfect score", () =>
2023-09-13 12:35:07 +00:00
{
NonPerfectLocations.Clear();
MissLocations.Clear();
});
AddStep("set score with misses", () =>
{
NonPerfectLocations.Clear();
MissLocations.Clear();
MissLocations.AddRange(new[] { 24d, 49 });
});
AddSliderStep("adjust score multiplier", 0, 10, (int)scoreMultiplier.Default, multiplier => scoreMultiplier.Value = multiplier);
}
2023-09-13 12:35:07 +00:00
private const int base_great = 300;
private class ScoreV1 : IScoringAlgorithm
{
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.");
public void ApplyMiss() => applyHitV1(0);
private void applyHitV1(int baseScore)
2023-09-13 12:35:07 +00:00
{
if (baseScore == 0)
{
currentCombo = 0;
return;
}
TotalScore += baseScore;
// combo multiplier
// ReSharper disable once PossibleLossOfFraction
TotalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * (ScoreMultiplier.Value * modMultiplier)));
currentCombo++;
2023-09-13 12:35:07 +00:00
}
public long TotalScore { get; private set; }
2023-09-13 12:35:07 +00:00
}
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;
2023-09-13 12:35:07 +00:00
public ScoreV2(int maxCombo, IReadOnlyList<Mod> selectedMods)
2023-09-13 12:35:07 +00:00
{
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();
2023-09-13 12:35:07 +00:00
comboPortionMax = comboPortion;
currentCombo = 0;
comboPortion = 0;
2023-09-13 12:35:07 +00:00
}
public void ApplyHit() => applyHitV2(base_great);
public void ApplyNonPerfect() => throw new NotSupportedException("catch does not have \"non-perfect\" judgements.");
private void applyHitV2(int baseScore)
2023-09-13 12:35:07 +00:00
{
comboPortion += baseScore * Math.Min(Math.Max(0.5, Math.Log(++currentCombo, combo_base)), Math.Log(combo_cap, combo_base));
2023-09-13 12:35:07 +00:00
}
public void ApplyMiss()
{
currentCombo = 0;
2023-09-13 12:35:07 +00:00
}
public long TotalScore
=> (int)Math.Round((1000000 * comboPortion / comboPortionMax) * modMultiplier); // vast simplification, as we're not doing ticks here.
2023-09-13 12:35:07 +00:00
}
private class CatchProcessorBasedScoringAlgorithm : ProcessorBasedScoringAlgorithm
{
public CatchProcessorBasedScoringAlgorithm(IBeatmap beatmap, ScoringMode mode, IReadOnlyList<Mod> selectedMods)
: base(beatmap, mode, selectedMods)
2023-09-13 12:35:07 +00:00
{
}
protected override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor();
protected override JudgementResult CreatePerfectJudgementResult() => new CatchJudgementResult(new Fruit(), new CatchJudgement()) { Type = HitResult.Great };
protected override JudgementResult CreateNonPerfectJudgementResult() => throw new NotSupportedException("catch does not have \"non-perfect\" judgements.");
protected override JudgementResult CreateMissJudgementResult() => new CatchJudgementResult(new Fruit(), new CatchJudgement()) { Type = HitResult.Miss };
}
}
}