1
0
Fork 0
mirror of https://github.com/ppy/osu-tools.git synced 2025-06-09 17:44:46 +09:00

Merge pull request #223 from minisbett/simulate-parameter-handling

Move `SimulateCommand` option implementations to base class
This commit is contained in:
Dan Balasescu 2024-10-22 14:29:31 +09:00 committed by GitHub
commit 1d171381c9
Signed by: github
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 101 deletions

View file

@ -17,29 +17,14 @@ namespace PerformanceCalculator.Simulate
[Command(Name = "catch", Description = "Computes the performance (pp) of a simulated osu!catch play.")] [Command(Name = "catch", Description = "Computes the performance (pp) of a simulated osu!catch play.")]
public class CatchSimulateCommand : SimulateCommand public class CatchSimulateCommand : SimulateCommand
{ {
[UsedImplicitly]
[Option(Template = "-a|--accuracy <accuracy>", Description = "Accuracy. Enter as decimal 0-100. Defaults to 100."
+ " Scales hit results as well and is rounded to the nearest possible value for the beatmap.")]
public override double Accuracy { get; } = 100;
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")] [Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")]
public override int? Combo { get; } public override int? Combo { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option." [Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option. Enter as decimal 0-100.")]
+ " Enter as decimal 0-100.")]
public override double PercentCombo { get; } = 100; public override double PercentCombo { get; } = 100;
[UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mod <mod>", Description = "One for each mod. The mods to compute the performance with."
+ " Values: hr, dt, hd, fl, ez, etc...")]
public override string[] Mods { get; }
[UsedImplicitly]
[Option(Template = "-X|--misses <misses>", Description = "Number of misses. Defaults to 0.")]
public override int Misses { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-T|--tiny-droplets <tinys>", Description = "Number of tiny droplets hit. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-T|--tiny-droplets <tinys>", Description = "Number of tiny droplets hit. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Mehs { get; } public override int? Mehs { get; }

View file

@ -17,35 +17,21 @@ namespace PerformanceCalculator.Simulate
[Command(Name = "mania", Description = "Computes the performance (pp) of a simulated osu!mania play.")] [Command(Name = "mania", Description = "Computes the performance (pp) of a simulated osu!mania play.")]
public class ManiaSimulateCommand : SimulateCommand public class ManiaSimulateCommand : SimulateCommand
{ {
[UsedImplicitly]
[Option(Template = "-a|--accuracy <accuracy>", Description = "Accuracy. Enter as decimal 0-100. Defaults to 100."
+ " Scales hit results as well and is rounded to the nearest possible value for the beatmap.")]
public override double Accuracy { get; } = 100;
[UsedImplicitly]
[Option(Template = "-X|--misses <misses>", Description = "Number of misses. Defaults to 0.")]
public override int Misses { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-M|--mehs <mehs>", Description = "Number of mehs. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-M|--mehs <mehs>", Description = "Number of mehs. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Mehs { get; } public override int? Mehs { get; }
[UsedImplicitly]
[Option(Template = "-O|--oks <oks>", Description = "Number of oks. Will override accuracy if used. Otherwise is automatically calculated.")]
private int? oks { get; set; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Goods { get; } public override int? Goods { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-T|--greats <greats>", Description = "Number of greats. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-O|--oks <oks>", Description = "Number of oks. Will override accuracy if used. Otherwise is automatically calculated.")]
private int? greats { get; set; } private int? oks { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mod <mod>", Description = "One for each mod. The mods to compute the performance with." [Option(Template = "-T|--greats <greats>", Description = "Number of greats. Will override accuracy if used. Otherwise is automatically calculated.")]
+ " Values: hr, dt, fl, 4k, 5k, etc...")] private int? greats { get; }
public override string[] Mods { get; }
public override Ruleset Ruleset => new ManiaRuleset(); public override Ruleset Ruleset => new ManiaRuleset();
@ -82,10 +68,10 @@ namespace PerformanceCalculator.Simulate
// Each great and perfect increases total by 5 (great-meh=5) // Each great and perfect increases total by 5 (great-meh=5)
// There is no difference in accuracy between them, so just halve arbitrarily (favouring perfects for an odd number). // There is no difference in accuracy between them, so just halve arbitrarily (favouring perfects for an odd number).
int greatsAndPerfects = Math.Min(delta / 5, remainingHits); int greatsAndPerfects = Math.Min(delta / 5, remainingHits);
greats = greatsAndPerfects / 2; int countGreat = greatsAndPerfects / 2;
int perfects = greatsAndPerfects - greats.Value; int perfects = greatsAndPerfects - countGreat;
delta -= (greats.Value + perfects) * 5; delta -= (countGreat + perfects) * 5;
remainingHits -= greats.Value + perfects; remainingHits -= countGreat + perfects;
// Each good increases total by 3 (good-meh=3). // Each good increases total by 3 (good-meh=3).
countGood = Math.Min(delta / 3, remainingHits); countGood = Math.Min(delta / 3, remainingHits);
@ -93,8 +79,8 @@ namespace PerformanceCalculator.Simulate
remainingHits -= countGood.Value; remainingHits -= countGood.Value;
// Each ok increases total by 1 (ok-meh=1). // Each ok increases total by 1 (ok-meh=1).
oks = delta; int countOk = delta;
remainingHits -= oks.Value; remainingHits -= countOk;
// Everything else is a meh, as initially assumed. // Everything else is a meh, as initially assumed.
countMeh = remainingHits; countMeh = remainingHits;
@ -102,8 +88,8 @@ namespace PerformanceCalculator.Simulate
return new Dictionary<HitResult, int> return new Dictionary<HitResult, int>
{ {
{ HitResult.Perfect, perfects }, { HitResult.Perfect, perfects },
{ HitResult.Great, greats.Value }, { HitResult.Great, countGreat },
{ HitResult.Ok, oks.Value }, { HitResult.Ok, countOk },
{ HitResult.Good, countGood.Value }, { HitResult.Good, countGood.Value },
{ HitResult.Meh, countMeh.Value }, { HitResult.Meh, countMeh.Value },
{ HitResult.Miss, countMiss } { HitResult.Miss, countMiss }

View file

@ -15,29 +15,6 @@ namespace PerformanceCalculator.Simulate
[Command(Name = "osu", Description = "Computes the performance (pp) of a simulated osu! play.")] [Command(Name = "osu", Description = "Computes the performance (pp) of a simulated osu! play.")]
public class OsuSimulateCommand : SimulateCommand public class OsuSimulateCommand : SimulateCommand
{ {
[UsedImplicitly]
[Option(Template = "-a|--accuracy <accuracy>", Description = "Accuracy. Enter as decimal 0-100. Defaults to 100."
+ " Scales hit results as well and is rounded to the nearest possible value for the beatmap.")]
public override double Accuracy { get; } = 100;
[UsedImplicitly]
[Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")]
public override int? Combo { get; }
[UsedImplicitly]
[Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option."
+ " Enter as decimal 0-100.")]
public override double PercentCombo { get; } = 100;
[UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mod <mod>", Description = "One for each mod. The mods to compute the performance with."
+ " Values: hr, dt, hd, fl, ez, etc...")]
public override string[] Mods { get; }
[UsedImplicitly]
[Option(Template = "-X|--misses <misses>", Description = "Number of misses. Defaults to 0.")]
public override int Misses { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-M|--mehs <mehs>", Description = "Number of mehs. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-M|--mehs <mehs>", Description = "Number of mehs. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Mehs { get; } public override int? Mehs { get; }
@ -46,6 +23,14 @@ namespace PerformanceCalculator.Simulate
[Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")] [Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Goods { get; } public override int? Goods { get; }
[UsedImplicitly]
[Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")]
public override int? Combo { get; }
[UsedImplicitly]
[Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option. Enter as decimal 0-100.")]
public override double PercentCombo { get; } = 100;
public override Ruleset Ruleset => new OsuRuleset(); public override Ruleset Ruleset => new OsuRuleset();
protected override int GetMaxCombo(IBeatmap beatmap) => beatmap.GetMaxCombo(); protected override int GetMaxCombo(IBeatmap beatmap) => beatmap.GetMaxCombo();

View file

@ -25,7 +25,28 @@ namespace PerformanceCalculator.Simulate
public string Beatmap { get; } public string Beatmap { get; }
[UsedImplicitly] [UsedImplicitly]
public virtual double Accuracy { get; } [Option(Template = "-a|--accuracy <accuracy>", Description = "Accuracy. Enter as decimal 0-100. Defaults to 100. Scales hit results as well and is rounded to the nearest possible value for the beatmap.")]
public double Accuracy { get; } = 100;
[UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mod <mod>", Description = "One for each mod. The mods to compute the performance with. Values: hr, dt, hd, fl, etc...")]
public string[] Mods { get; }
[UsedImplicitly]
[Option(Template = "-X|--misses <misses>", Description = "Number of misses. Defaults to 0.")]
public int Misses { get; }
//
// Options implemented in the ruleset-specific commands
// -> Catch renames Mehs/Goods to (tiny-)droplets
// -> Mania does not have Combo
// -> Taiko does not have Mehs
//
[UsedImplicitly]
public virtual int? Mehs { get; }
[UsedImplicitly]
public virtual int? Goods { get; }
[UsedImplicitly] [UsedImplicitly]
public virtual int? Combo { get; } public virtual int? Combo { get; }
@ -33,21 +54,6 @@ namespace PerformanceCalculator.Simulate
[UsedImplicitly] [UsedImplicitly]
public virtual double PercentCombo { get; } public virtual double PercentCombo { get; }
[UsedImplicitly]
public virtual int Score { get; }
[UsedImplicitly]
public virtual string[] Mods { get; }
[UsedImplicitly]
public virtual int Misses { get; }
[UsedImplicitly]
public virtual int? Mehs { get; }
[UsedImplicitly]
public virtual int? Goods { get; }
public override void Execute() public override void Execute()
{ {
var ruleset = Ruleset; var ruleset = Ruleset;
@ -63,8 +69,7 @@ namespace PerformanceCalculator.Simulate
Accuracy = GetAccuracy(statistics), Accuracy = GetAccuracy(statistics),
MaxCombo = Combo ?? (int)Math.Round(PercentCombo / 100 * beatmapMaxCombo), MaxCombo = Combo ?? (int)Math.Round(PercentCombo / 100 * beatmapMaxCombo),
Statistics = statistics, Statistics = statistics,
Mods = mods, Mods = mods
TotalScore = Score,
}; };
var difficultyCalculator = ruleset.CreateDifficultyCalculator(workingBeatmap); var difficultyCalculator = ruleset.CreateDifficultyCalculator(workingBeatmap);

View file

@ -18,32 +18,17 @@ namespace PerformanceCalculator.Simulate
public class TaikoSimulateCommand : SimulateCommand public class TaikoSimulateCommand : SimulateCommand
{ {
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-a|--accuracy <accuracy>", Description = "Accuracy. Enter as decimal 0-100. Defaults to 100." [Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")]
+ " Scales hit results as well and is rounded to the nearest possible value for the beatmap.")] public override int? Goods { get; }
public override double Accuracy { get; } = 100;
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")] [Option(Template = "-c|--combo <combo>", Description = "Maximum combo during play. Defaults to beatmap maximum.")]
public override int? Combo { get; } public override int? Combo { get; }
[UsedImplicitly] [UsedImplicitly]
[Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option." [Option(Template = "-C|--percent-combo <combo>", Description = "Percentage of beatmap maximum combo achieved. Alternative to combo option. Enter as decimal 0-100.")]
+ " Enter as decimal 0-100.")]
public override double PercentCombo { get; } = 100; public override double PercentCombo { get; } = 100;
[UsedImplicitly]
[Option(CommandOptionType.MultipleValue, Template = "-m|--mod <mod>", Description = "One for each mod. The mods to compute the performance with."
+ " Values: hr, dt, hd, fl, ez, etc...")]
public override string[] Mods { get; }
[UsedImplicitly]
[Option(Template = "-X|--misses <misses>", Description = "Number of misses. Defaults to 0.")]
public override int Misses { get; }
[UsedImplicitly]
[Option(Template = "-G|--goods <goods>", Description = "Number of goods. Will override accuracy if used. Otherwise is automatically calculated.")]
public override int? Goods { get; }
public override Ruleset Ruleset => new TaikoRuleset(); public override Ruleset Ruleset => new TaikoRuleset();
protected override int GetMaxCombo(IBeatmap beatmap) => beatmap.HitObjects.OfType<Hit>().Count(); protected override int GetMaxCombo(IBeatmap beatmap) => beatmap.HitObjects.OfType<Hit>().Count();