Skip to content

Commit

Permalink
Merge pull request ppy#4 from HeBuwei/replace-tuples
Browse files Browse the repository at this point in the history
Replace giant tuples with classes
  • Loading branch information
stanriders authored Sep 4, 2020
2 parents 986a17d + b83b343 commit 56e548b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
32 changes: 15 additions & 17 deletions osu.Game.Rulesets.Osu/Difficulty/OsuDifficultyCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods,
var noteDensities = NoteDensity.CalculateNoteDensities(hitObjects, preemptNoClockRate);

// Tap
var (tapDiff, streamNoteCount, mashTapDiff, strainHistory) =
Tap.CalculateTapAttributes(hitObjects, clockRate);
var tapAttributes = Tap.CalculateTapAttributes(hitObjects, clockRate);

// Finger Control
double fingerControlDiff = FingerControl.CalculateFingerControlDiff(hitObjects, clockRate);

// Aim
var (aimDiff, aimHiddenFactor, comboTps, missTps, missCounts, cheeseNoteCount, cheeseLevels, cheeseFactors) =
Aim.CalculateAimAttributes(hitObjects, clockRate, strainHistory, noteDensities);
var aimAttributes = Aim.CalculateAimAttributes(hitObjects, clockRate, tapAttributes.StrainHistory, noteDensities);

double tapSr = tap_multiplier * Math.Pow(tapDiff, sr_exponent);
double aimSr = aim_multiplier * Math.Pow(aimDiff, sr_exponent);
double tapSr = tap_multiplier * Math.Pow(tapAttributes.TapDifficulty, sr_exponent);
double aimSr = aim_multiplier * Math.Pow(aimAttributes.FcProbabilityThroughput, sr_exponent);
double fingerControlSr = finger_control_multiplier * Math.Pow(fingerControlDiff, sr_exponent);
double sr = Mean.PowerMean(new[] { tapSr, aimSr, fingerControlSr }, 7) * 1.131;

Expand All @@ -77,22 +75,22 @@ protected override DifficultyAttributes Calculate(IBeatmap beatmap, Mod[] mods,
Length = mapLength,

TapSr = tapSr,
TapDiff = tapDiff,
StreamNoteCount = streamNoteCount,
MashTapDiff = mashTapDiff,
TapDiff = tapAttributes.TapDifficulty,
StreamNoteCount = tapAttributes.StreamNoteCount,
MashTapDiff = tapAttributes.MashedTapDifficulty,

FingerControlSr = fingerControlSr,
FingerControlDiff = fingerControlDiff,

AimSr = aimSr,
AimDiff = aimDiff,
AimHiddenFactor = aimHiddenFactor,
ComboTps = comboTps,
MissTps = missTps,
MissCounts = missCounts,
CheeseNoteCount = cheeseNoteCount,
CheeseLevels = cheeseLevels,
CheeseFactors = cheeseFactors,
AimDiff = aimAttributes.FcProbabilityThroughput,
AimHiddenFactor = aimAttributes.HiddenFactor,
ComboTps = aimAttributes.ComboThroughputs,
MissTps = aimAttributes.MissThroughputs,
MissCounts = aimAttributes.MissCounts,
CheeseNoteCount = aimAttributes.CheeseNoteCount,
CheeseLevels = aimAttributes.CheeseLevels,
CheeseFactors = aimAttributes.CheeseFactors,

ApproachRate = preempt > 1200 ? (1800 - preempt) / 120 : (1200 - preempt) / 150 + 5,
OverallDifficulty = (80 - hitWindowGreat) / 6,
Expand Down
21 changes: 15 additions & 6 deletions osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ public static class Aim
/// <summary>
/// Calculates attributes related to aiming difficulty.
/// </summary>
public static (double, double, double[], double[], double[], double, double[], double[])
CalculateAimAttributes(List<OsuHitObject> hitObjects,
double clockRate,
List<Vector<double>> strainHistory,
List<double> noteDensities)
public static AimAttributes CalculateAimAttributes(List<OsuHitObject> hitObjects,
double clockRate,
List<Vector<double>> strainHistory,
List<double> noteDensities)
{
List<OsuMovement> movements = createMovements(hitObjects, clockRate, strainHistory);
List<OsuMovement> movementsHidden = createMovements(hitObjects, clockRate, strainHistory,
Expand All @@ -84,7 +83,17 @@ public static (double, double, double[], double[], double[], double, double[], d
var (cheeseLevels, cheeseFactors) = calculateCheeseLevelsCheeseFactors(movements, fcProbTp);
double cheeseNoteCount = getCheeseNoteCount(movements, fcProbTp);

return (fcProbTp, hiddenFactor, comboTps, missTps, missCounts, cheeseNoteCount, cheeseLevels, cheeseFactors);
return new AimAttributes
{
FcProbabilityThroughput = fcProbTp,
HiddenFactor = hiddenFactor,
ComboThroughputs = comboTps,
MissThroughputs = missTps,
MissCounts = missCounts,
CheeseNoteCount = cheeseNoteCount,
CheeseLevels = cheeseLevels,
CheeseFactors = cheeseFactors
};
}

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions osu.Game.Rulesets.Osu/Difficulty/Skills/AimAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace osu.Game.Rulesets.Osu.Difficulty.Skills
{
public class AimAttributes
{
public double FcProbabilityThroughput;
public double HiddenFactor;
public double[] ComboThroughputs;
public double[] MissThroughputs;
public double[] MissCounts;
public double CheeseNoteCount;
public double[] CheeseLevels;
public double[] CheeseFactors;
}
}
11 changes: 8 additions & 3 deletions osu.Game.Rulesets.Osu/Difficulty/Skills/Tap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static class Tap
/// <summary>
/// Calculates attributes related to tapping difficulty.
/// </summary>
public static (double, double, double, List<Vector<double>>) CalculateTapAttributes
(List<OsuHitObject> hitObjects, double clockRate)
public static TapAttributes CalculateTapAttributes(List<OsuHitObject> hitObjects, double clockRate)
{
var (strainHistory, tapDiff) = calculateTapStrain(hitObjects, 0, clockRate);
double burstStrain = strainHistory.Max(v => v[0]);
Expand All @@ -41,7 +40,13 @@ public static (double, double, double, List<Vector<double>>) CalculateTapAttribu

var (_, mashTapDiff) = calculateTapStrain(hitObjects, 1, clockRate);

return (tapDiff, streamNoteCount, mashTapDiff, strainHistory);
return new TapAttributes
{
TapDifficulty = tapDiff,
StreamNoteCount = streamNoteCount,
MashedTapDifficulty = mashTapDiff,
StrainHistory = strainHistory
};
}

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions osu.Game.Rulesets.Osu/Difficulty/Skills/TapAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra;

namespace osu.Game.Rulesets.Osu.Difficulty.Skills
{
public class TapAttributes
{
public double TapDifficulty;
public double StreamNoteCount;
public double MashedTapDifficulty;
public List<Vector<double>> StrainHistory;
}
}

0 comments on commit 56e548b

Please sign in to comment.