2020-08-18 10:51:26 +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.
|
|
|
|
|
|
2022-01-31 09:54:23 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-07-21 03:01:48 +00:00
|
|
|
|
using System.Linq;
|
2020-08-18 10:51:26 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Testing;
|
2022-12-30 19:52:05 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2020-08-18 10:51:26 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2022-01-31 09:54:23 +00:00
|
|
|
|
using osu.Game.Online.Spectator;
|
2020-08-18 10:51:26 +00:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2022-01-31 09:54:23 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Replays;
|
2020-08-18 10:51:26 +00:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-07-21 03:01:48 +00:00
|
|
|
|
using osu.Game.Scoring;
|
2020-08-18 10:51:26 +00:00
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Gameplay
|
|
|
|
|
{
|
|
|
|
|
[HeadlessTest]
|
|
|
|
|
public partial class TestSceneScoreProcessor : OsuTestScene
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestNoScoreIncreaseFromMiss()
|
|
|
|
|
{
|
2020-09-29 06:25:31 +00:00
|
|
|
|
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitObject() } };
|
2020-08-18 10:51:26 +00:00
|
|
|
|
|
2022-03-14 06:51:10 +00:00
|
|
|
|
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
2020-08-18 10:51:26 +00:00
|
|
|
|
scoreProcessor.ApplyBeatmap(beatmap);
|
|
|
|
|
|
|
|
|
|
// Apply a miss judgement
|
2020-09-29 06:25:31 +00:00
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(new HitObject(), new TestJudgement()) { Type = HitResult.Miss });
|
2020-08-18 10:51:26 +00:00
|
|
|
|
|
2022-11-06 22:59:27 +00:00
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(0));
|
2020-08-18 10:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-10 16:13:55 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestOnlyBonusScore()
|
|
|
|
|
{
|
2020-09-29 06:25:31 +00:00
|
|
|
|
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitObject() } };
|
2020-09-10 16:13:55 +00:00
|
|
|
|
|
2022-03-14 06:51:10 +00:00
|
|
|
|
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
2020-09-10 16:13:55 +00:00
|
|
|
|
scoreProcessor.ApplyBeatmap(beatmap);
|
|
|
|
|
|
|
|
|
|
// Apply a judgement
|
2020-09-29 06:25:31 +00:00
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(new HitObject(), new TestJudgement(HitResult.LargeBonus)) { Type = HitResult.LargeBonus });
|
2020-09-10 16:13:55 +00:00
|
|
|
|
|
2020-09-29 06:25:31 +00:00
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(Judgement.LARGE_BONUS_SCORE));
|
2020-08-18 10:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 09:54:23 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestResetFromReplayFrame()
|
|
|
|
|
{
|
|
|
|
|
var beatmap = new Beatmap<HitObject> { HitObjects = { new HitCircle() } };
|
|
|
|
|
|
2022-03-14 06:51:10 +00:00
|
|
|
|
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
2022-01-31 09:54:23 +00:00
|
|
|
|
scoreProcessor.ApplyBeatmap(beatmap);
|
|
|
|
|
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], new TestJudgement(HitResult.Great)) { Type = HitResult.Great });
|
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(1_000_000));
|
|
|
|
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
2022-06-06 09:01:52 +00:00
|
|
|
|
Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(1));
|
2022-01-31 09:54:23 +00:00
|
|
|
|
|
2022-02-01 07:55:28 +00:00
|
|
|
|
// No header shouldn't cause any change
|
2022-05-31 08:16:23 +00:00
|
|
|
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame());
|
2022-02-01 07:55:28 +00:00
|
|
|
|
|
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(1_000_000));
|
|
|
|
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
2022-06-06 09:01:52 +00:00
|
|
|
|
Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(1));
|
2022-02-01 07:55:28 +00:00
|
|
|
|
|
2022-01-31 09:54:23 +00:00
|
|
|
|
// Reset with a miss instead.
|
2022-05-31 08:16:23 +00:00
|
|
|
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame
|
2022-01-31 09:54:23 +00:00
|
|
|
|
{
|
2023-05-23 09:18:27 +00:00
|
|
|
|
Header = new FrameHeader(0, 0, 0, 0, new Dictionary<HitResult, int> { { HitResult.Miss, 1 } }, new ScoreProcessorStatistics
|
|
|
|
|
{
|
|
|
|
|
MaximumBaseScore = 300,
|
|
|
|
|
BaseScore = 0,
|
2023-05-29 09:38:16 +00:00
|
|
|
|
AccuracyJudgementCount = 1,
|
2023-05-23 09:18:27 +00:00
|
|
|
|
ComboPortion = 0,
|
|
|
|
|
BonusPortion = 0
|
|
|
|
|
}, DateTimeOffset.Now)
|
2022-01-31 09:54:23 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.Zero);
|
|
|
|
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
2022-06-06 09:01:52 +00:00
|
|
|
|
Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(0));
|
2023-05-23 09:18:27 +00:00
|
|
|
|
Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(0));
|
2022-01-31 09:54:23 +00:00
|
|
|
|
|
|
|
|
|
// Reset with no judged hit.
|
2022-05-31 08:16:23 +00:00
|
|
|
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame
|
2022-01-31 09:54:23 +00:00
|
|
|
|
{
|
2023-05-23 09:18:27 +00:00
|
|
|
|
Header = new FrameHeader(0, 0, 0, 0, new Dictionary<HitResult, int>(), new ScoreProcessorStatistics
|
|
|
|
|
{
|
|
|
|
|
MaximumBaseScore = 0,
|
|
|
|
|
BaseScore = 0,
|
2023-05-29 09:38:16 +00:00
|
|
|
|
AccuracyJudgementCount = 0,
|
2023-05-23 09:18:27 +00:00
|
|
|
|
ComboPortion = 0,
|
|
|
|
|
BonusPortion = 0
|
|
|
|
|
}, DateTimeOffset.Now)
|
2022-01-31 09:54:23 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Assert.That(scoreProcessor.TotalScore.Value, Is.Zero);
|
|
|
|
|
Assert.That(scoreProcessor.JudgedHits, Is.Zero);
|
2022-06-06 09:01:52 +00:00
|
|
|
|
Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(0));
|
2023-05-23 09:18:27 +00:00
|
|
|
|
Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(1));
|
2022-01-31 09:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-21 03:01:48 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestFailScore()
|
|
|
|
|
{
|
|
|
|
|
var beatmap = new Beatmap<HitObject>
|
|
|
|
|
{
|
|
|
|
|
HitObjects =
|
|
|
|
|
{
|
|
|
|
|
new TestHitObject(),
|
|
|
|
|
new TestHitObject(HitResult.LargeTickHit),
|
|
|
|
|
new TestHitObject(HitResult.SmallTickHit),
|
2022-07-21 05:12:46 +00:00
|
|
|
|
new TestHitObject(HitResult.SmallBonus),
|
2022-07-21 03:01:48 +00:00
|
|
|
|
new TestHitObject(),
|
|
|
|
|
new TestHitObject(HitResult.LargeTickHit),
|
|
|
|
|
new TestHitObject(HitResult.SmallTickHit),
|
2022-07-21 05:12:46 +00:00
|
|
|
|
new TestHitObject(HitResult.LargeBonus),
|
2022-07-21 03:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
|
|
|
|
scoreProcessor.ApplyBeatmap(beatmap);
|
|
|
|
|
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].CreateJudgement()) { Type = HitResult.Ok });
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].CreateJudgement()) { Type = HitResult.LargeTickHit });
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], beatmap.HitObjects[2].CreateJudgement()) { Type = HitResult.SmallTickMiss });
|
2022-07-21 05:12:46 +00:00
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], beatmap.HitObjects[3].CreateJudgement()) { Type = HitResult.SmallBonus });
|
2022-07-21 03:01:48 +00:00
|
|
|
|
|
|
|
|
|
var score = new ScoreInfo { Ruleset = new OsuRuleset().RulesetInfo };
|
|
|
|
|
scoreProcessor.FailScore(score);
|
|
|
|
|
|
|
|
|
|
Assert.That(score.Rank, Is.EqualTo(ScoreRank.F));
|
2022-07-21 05:12:46 +00:00
|
|
|
|
Assert.That(score.Passed, Is.False);
|
2022-08-29 06:59:57 +00:00
|
|
|
|
Assert.That(score.Statistics.Sum(kvp => kvp.Value), Is.EqualTo(4));
|
|
|
|
|
Assert.That(score.MaximumStatistics.Sum(kvp => kvp.Value), Is.EqualTo(8));
|
|
|
|
|
|
2022-07-21 03:01:48 +00:00
|
|
|
|
Assert.That(score.Statistics[HitResult.Ok], Is.EqualTo(1));
|
|
|
|
|
Assert.That(score.Statistics[HitResult.LargeTickHit], Is.EqualTo(1));
|
2022-08-29 06:59:57 +00:00
|
|
|
|
Assert.That(score.Statistics[HitResult.SmallTickMiss], Is.EqualTo(1));
|
2022-07-21 05:12:46 +00:00
|
|
|
|
Assert.That(score.Statistics[HitResult.SmallBonus], Is.EqualTo(1));
|
2022-08-29 06:59:57 +00:00
|
|
|
|
|
|
|
|
|
Assert.That(score.MaximumStatistics[HitResult.Perfect], Is.EqualTo(2));
|
|
|
|
|
Assert.That(score.MaximumStatistics[HitResult.LargeTickHit], Is.EqualTo(2));
|
|
|
|
|
Assert.That(score.MaximumStatistics[HitResult.SmallTickHit], Is.EqualTo(2));
|
|
|
|
|
Assert.That(score.MaximumStatistics[HitResult.SmallBonus], Is.EqualTo(1));
|
|
|
|
|
Assert.That(score.MaximumStatistics[HitResult.LargeBonus], Is.EqualTo(1));
|
2022-07-21 03:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 19:52:05 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestAccuracyModes()
|
|
|
|
|
{
|
|
|
|
|
var beatmap = new Beatmap<HitObject>
|
|
|
|
|
{
|
|
|
|
|
HitObjects = Enumerable.Range(0, 4).Select(_ => new TestHitObject(HitResult.Great)).ToList<HitObject>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var scoreProcessor = new ScoreProcessor(new OsuRuleset());
|
|
|
|
|
scoreProcessor.ApplyBeatmap(beatmap);
|
|
|
|
|
|
|
|
|
|
Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(1));
|
|
|
|
|
Assert.That(scoreProcessor.MinimumAccuracy.Value, Is.EqualTo(0));
|
|
|
|
|
Assert.That(scoreProcessor.MaximumAccuracy.Value, Is.EqualTo(1));
|
|
|
|
|
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].CreateJudgement()) { Type = HitResult.Ok });
|
|
|
|
|
scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].CreateJudgement()) { Type = HitResult.Great });
|
|
|
|
|
|
|
|
|
|
Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo((double)(100 + 300) / (2 * 300)).Within(Precision.DOUBLE_EPSILON));
|
|
|
|
|
Assert.That(scoreProcessor.MinimumAccuracy.Value, Is.EqualTo((double)(100 + 300) / (4 * 300)).Within(Precision.DOUBLE_EPSILON));
|
|
|
|
|
Assert.That(scoreProcessor.MaximumAccuracy.Value, Is.EqualTo((double)(100 + 3 * 300) / (4 * 300)).Within(Precision.DOUBLE_EPSILON));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 10:51:26 +00:00
|
|
|
|
private class TestJudgement : Judgement
|
|
|
|
|
{
|
2020-09-29 06:25:31 +00:00
|
|
|
|
public override HitResult MaxResult { get; }
|
2020-09-10 16:13:55 +00:00
|
|
|
|
|
2020-09-29 06:25:31 +00:00
|
|
|
|
public TestJudgement(HitResult maxResult = HitResult.Perfect)
|
|
|
|
|
{
|
|
|
|
|
MaxResult = maxResult;
|
|
|
|
|
}
|
2020-09-10 16:13:55 +00:00
|
|
|
|
}
|
2022-07-21 03:01:48 +00:00
|
|
|
|
|
|
|
|
|
private class TestHitObject : HitObject
|
|
|
|
|
{
|
|
|
|
|
private readonly HitResult maxResult;
|
|
|
|
|
|
|
|
|
|
public TestHitObject(HitResult maxResult = HitResult.Perfect)
|
|
|
|
|
{
|
|
|
|
|
this.maxResult = maxResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Judgement CreateJudgement() => new TestJudgement(maxResult);
|
|
|
|
|
}
|
2020-08-18 10:51:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|