2022-10-16 17:39:25 +08: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-10-17 22:41:07 +08:00
|
|
|
using System;
|
2022-10-16 17:39:25 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Bindables;
|
2022-10-17 22:41:07 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-10-17 22:27:26 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-10-17 22:41:07 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-10-17 22:27:26 +08:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
2022-10-17 22:41:07 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2022-10-18 15:55:04 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
public class TestSceneScoring : OsuTestScene
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
private GraphContainer graphs = null!;
|
2022-10-16 17:39:25 +08:00
|
|
|
private SettingsSlider<int> sliderMaxCombo = null!;
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
private FillFlowContainer legend = null!;
|
|
|
|
|
2022-10-16 17:39:25 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBasic()
|
|
|
|
{
|
|
|
|
AddStep("setup tests", () =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-10-18 15:50:30 +08:00
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
2022-10-16 17:39:25 +08:00
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
graphs = new GraphContainer
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-10-16 17:39:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
2022-10-17 22:41:07 +08:00
|
|
|
{
|
|
|
|
legend = new FillFlowContainer
|
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
Padding = new MarginPadding(20),
|
2022-10-17 22:41:07 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-10-18 15:50:30 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-10-17 22:41:07 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-10-16 17:39:25 +08:00
|
|
|
Direction = FillDirection.Full,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
sliderMaxCombo = new SettingsSlider<int>
|
|
|
|
{
|
|
|
|
Width = 0.5f,
|
2022-10-17 22:41:07 +08:00
|
|
|
TransferValueOnCommit = true,
|
2022-10-16 17:39:25 +08:00
|
|
|
Current = new BindableInt(1024)
|
|
|
|
{
|
|
|
|
MinValue = 96,
|
|
|
|
MaxValue = 8192,
|
|
|
|
},
|
|
|
|
LabelText = "max combo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
sliderMaxCombo.Current.BindValueChanged(_ => rerun());
|
2022-10-17 22:27:26 +08:00
|
|
|
graphs.MissLocations.BindCollectionChanged((_, __) => rerun());
|
|
|
|
|
|
|
|
graphs.MaxCombo.BindTo(sliderMaxCombo.Current);
|
2022-10-16 17:39:25 +08:00
|
|
|
|
|
|
|
rerun();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
private void rerun()
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
graphs.Clear();
|
2022-10-17 22:41:07 +08:00
|
|
|
legend.Clear();
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2022-10-18 16:28:13 +08:00
|
|
|
runForProcessor("lazer-standardised", Color4.Cyan, new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Standardised } });
|
|
|
|
runForProcessor("lazer-classic", Color4.Orange, new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Classic } });
|
2022-10-18 16:23:23 +08:00
|
|
|
|
|
|
|
int totalScore = 0;
|
|
|
|
int currentCombo = 0;
|
|
|
|
|
2022-10-18 16:28:13 +08:00
|
|
|
runForAlgorithm("stable-v1", Color4.Beige, () =>
|
2022-10-18 16:23:23 +08:00
|
|
|
{
|
|
|
|
const int base_score = 300;
|
|
|
|
const float score_multiplier = 1;
|
|
|
|
|
|
|
|
totalScore += base_score;
|
|
|
|
|
|
|
|
// combo multiplier
|
|
|
|
// ReSharper disable once PossibleLossOfFraction
|
|
|
|
totalScore += (int)(Math.Max(0, currentCombo - 1) * (base_score / 25 * score_multiplier));
|
|
|
|
|
|
|
|
currentCombo++;
|
|
|
|
}, () =>
|
|
|
|
{
|
|
|
|
currentCombo = 0;
|
|
|
|
}, () => totalScore);
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
|
2022-10-18 16:28:13 +08:00
|
|
|
private void runForProcessor(string name, Color4 colour, ScoreProcessor processor)
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
int maxCombo = sliderMaxCombo.Current.Value;
|
|
|
|
|
|
|
|
var beatmap = new OsuBeatmap();
|
|
|
|
for (int i = 0; i < maxCombo; i++)
|
|
|
|
beatmap.HitObjects.Add(new HitCircle());
|
|
|
|
|
|
|
|
processor.ApplyBeatmap(beatmap);
|
|
|
|
|
2022-10-18 16:28:13 +08:00
|
|
|
runForAlgorithm(name, colour,
|
2022-10-18 16:23:23 +08:00
|
|
|
() => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Great }),
|
|
|
|
() => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Miss }),
|
|
|
|
() => (int)processor.TotalScore.Value);
|
|
|
|
}
|
|
|
|
|
2022-10-18 16:28:13 +08:00
|
|
|
private void runForAlgorithm(string name, Color4 colour, Action applyHit, Action applyMiss, Func<int> getTotalScore)
|
2022-10-18 16:23:23 +08:00
|
|
|
{
|
|
|
|
int maxCombo = sliderMaxCombo.Current.Value;
|
|
|
|
|
2022-10-16 17:39:25 +08:00
|
|
|
List<float> results = new List<float>();
|
|
|
|
|
|
|
|
for (int i = 0; i < maxCombo; i++)
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
if (graphs.MissLocations.Contains(i))
|
2022-10-18 16:23:23 +08:00
|
|
|
applyMiss();
|
2022-10-16 17:39:25 +08:00
|
|
|
else
|
2022-10-18 16:23:23 +08:00
|
|
|
applyHit();
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2022-10-18 16:23:23 +08:00
|
|
|
results.Add(getTotalScore());
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
graphs.Add(new LineGraph
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-10-17 22:41:07 +08:00
|
|
|
LineColour = colour,
|
2022-10-16 17:39:25 +08:00
|
|
|
Values = results
|
|
|
|
});
|
2022-10-17 22:41:07 +08:00
|
|
|
|
|
|
|
legend.Add(new OsuSpriteText
|
|
|
|
{
|
|
|
|
Colour = colour,
|
|
|
|
Text = $"{FontAwesome.Solid.Circle.Icon} {name}"
|
|
|
|
});
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
|
|
|
|
public class GraphContainer : Container
|
|
|
|
{
|
|
|
|
public readonly BindableList<double> MissLocations = new BindableList<double>();
|
|
|
|
|
|
|
|
public Bindable<int> MaxCombo = new Bindable<int>();
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
|
|
|
private readonly Box hoverLine;
|
|
|
|
|
|
|
|
private readonly Container missLines;
|
2022-10-17 22:49:15 +08:00
|
|
|
private readonly Container verticalGridLines;
|
2022-10-17 22:27:26 +08:00
|
|
|
|
|
|
|
public GraphContainer()
|
|
|
|
{
|
|
|
|
InternalChild = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.1f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-10-17 22:49:15 +08:00
|
|
|
verticalGridLines = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-10-17 22:27:26 +08:00
|
|
|
Content,
|
|
|
|
hoverLine = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Yellow,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Alpha = 0,
|
|
|
|
Width = 1,
|
|
|
|
},
|
|
|
|
missLines = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-17 22:49:15 +08:00
|
|
|
MissLocations.BindCollectionChanged((_, _) => updateMissLocations());
|
|
|
|
|
|
|
|
MaxCombo.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
updateMissLocations();
|
|
|
|
updateVerticalGridLines();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVerticalGridLines()
|
|
|
|
{
|
|
|
|
verticalGridLines.Clear();
|
2022-10-17 22:27:26 +08:00
|
|
|
|
2022-10-17 22:49:15 +08:00
|
|
|
for (int i = 0; i < MaxCombo.Value; i++)
|
|
|
|
{
|
|
|
|
if (i % 100 == 0)
|
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
verticalGridLines.AddRange(new Drawable[]
|
2022-10-17 22:49:15 +08:00
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
|
|
|
Width = 1,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)i / MaxCombo.Value,
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)i / MaxCombo.Value,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Text = $"{i:#,0}",
|
|
|
|
Rotation = -30,
|
|
|
|
Y = -20,
|
|
|
|
}
|
2022-10-17 22:49:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMissLocations()
|
|
|
|
{
|
|
|
|
missLines.Clear();
|
|
|
|
|
|
|
|
foreach (int miss in MissLocations)
|
|
|
|
{
|
|
|
|
missLines.Add(new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Red,
|
|
|
|
Width = 1,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)miss / MaxCombo.Value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
hoverLine.Show();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
hoverLine.Hide();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
{
|
|
|
|
hoverLine.X = e.MousePosition.X;
|
|
|
|
return base.OnMouseMove(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
MissLocations.Add((int)(e.MousePosition.X / DrawWidth * MaxCombo.Value));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|