-
Notifications
You must be signed in to change notification settings - Fork 4
/
OsuPerformanceCalculator.cs
322 lines (249 loc) · 14 KB
/
OsuPerformanceCalculator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// 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;
using System.Collections.Generic;
using System.Linq;
using MathNet.Numerics;
using MathNet.Numerics.Interpolation;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Rulesets.Osu.Difficulty.MathUtil;
namespace osu.Game.Rulesets.Osu.Difficulty
{
public class OsuPerformanceCalculator : PerformanceCalculator
{
public new OsuDifficultyAttributes Attributes => (OsuDifficultyAttributes)base.Attributes;
/// <summary>
/// Aim, tap and acc values are combined using power mean with this as the exponent.
/// </summary>
private const double total_value_exponent = 1.5;
/// <summary>
/// This exponent is used to convert throughput to aim pp and tap skill to tap pp.
/// </summary>
private const double skill_to_pp_exponent = 2.7;
/// <summary>
/// The first 0.5 miss doesn't count when we penalize misses
/// </summary>
private const double miss_count_leniency = 0.5;
private readonly int countHitCircles;
private readonly int countSliders;
private readonly int countSpinners;
private readonly int beatmapMaxCombo;
private Mod[] mods;
private double accuracy;
private int scoreMaxCombo;
private int countGreat;
private int countGood;
private int countMeh;
private int countMiss;
private double greatWindow;
private double effectiveMissCount;
public OsuPerformanceCalculator(Ruleset ruleset, WorkingBeatmap beatmap, ScoreInfo score)
: base(ruleset, beatmap, score)
{
countHitCircles = Beatmap.HitObjects.Count(h => h is HitCircle);
countSliders = Beatmap.HitObjects.Count(h => h is Slider);
countSpinners = Beatmap.HitObjects.Count(h => h is Spinner);
beatmapMaxCombo = Beatmap.HitObjects.Count;
// Add the ticks + tail of the slider. 1 is subtracted because the "headcircle" would be counted twice (once for the slider itself in the line above)
beatmapMaxCombo += Beatmap.HitObjects.OfType<Slider>().Sum(s => s.NestedHitObjects.Count - 1);
}
public override double Calculate(Dictionary<string, double> categoryRatings = null)
{
mods = Score.Mods;
accuracy = Score.Accuracy;
scoreMaxCombo = Score.MaxCombo;
countGreat = Score.Statistics.GetOrDefault(HitResult.Great);
countGood = Score.Statistics.GetOrDefault(HitResult.Good);
countMeh = Score.Statistics.GetOrDefault(HitResult.Meh);
countMiss = Score.Statistics.GetOrDefault(HitResult.Miss);
greatWindow = 79.5 - 6 * Attributes.OverallDifficulty;
// Don't count scores made with supposedly unranked mods
if (mods.Any(m => !m.Ranked))
return 0;
// Custom multipliers for NoFail and SpunOut.
double multiplier = 2.14; // This is being adjusted to keep the final pp value scaled around what it used to be when changing things
// guess the number of misses + slider breaks from combo
double comboBasedMissCount;
if (countSliders == 0)
{
if (scoreMaxCombo < beatmapMaxCombo)
comboBasedMissCount = (double)beatmapMaxCombo / scoreMaxCombo;
else
comboBasedMissCount = 0;
}
else
{
double fullComboThreshold = beatmapMaxCombo - 0.1 * countSliders;
if (scoreMaxCombo < fullComboThreshold)
comboBasedMissCount = fullComboThreshold / scoreMaxCombo;
else
comboBasedMissCount = Math.Pow((beatmapMaxCombo - scoreMaxCombo) / (0.1 * countSliders), 3);
}
effectiveMissCount = Math.Max(countMiss, comboBasedMissCount);
if (mods.Any(m => m is OsuModNoFail))
multiplier *= Math.Max(0.90, 1.0 - 0.02 * effectiveMissCount);
if (mods.Any(m => m is OsuModSpunOut))
multiplier *= 1.0 - Math.Pow(countSpinners / totalHits, 0.85);
double aimValue = computeAimValue();
double tapValue = computeTapValue();
double accuracyValue = computeAccuracyValue();
double totalValue = Mean.PowerMean(new[] { aimValue, tapValue, accuracyValue }, total_value_exponent) * multiplier;
if (categoryRatings != null)
{
categoryRatings.Add("Aim", aimValue);
categoryRatings.Add("Tap", tapValue);
categoryRatings.Add("Accuracy", accuracyValue);
categoryRatings.Add("OD", Attributes.OverallDifficulty);
categoryRatings.Add("AR", Attributes.ApproachRate);
categoryRatings.Add("Max Combo", beatmapMaxCombo);
}
return totalValue;
}
private double computeAimValue()
{
if (Beatmap.HitObjects.Count <= 1)
return 0;
// Get player's throughput according to combo
int comboTpCount = Attributes.ComboTps.Length;
var comboPercentages = Generate.LinearSpaced(comboTpCount, 1.0 / comboTpCount, 1);
double scoreComboPercentage = ((double)scoreMaxCombo) / beatmapMaxCombo;
double comboTp = LinearSpline.InterpolateSorted(comboPercentages, Attributes.ComboTps)
.Interpolate(scoreComboPercentage);
// Get player's throughput according to miss count
double missTp = LinearSpline.InterpolateSorted(Attributes.MissCounts, Attributes.MissTps)
.Interpolate(effectiveMissCount);
missTp = Math.Max(missTp, 0);
// Combine combo based throughput and miss count based throughput
double tp = Mean.PowerMean(comboTp, missTp, 20);
// Hidden mod
if (mods.Any(h => h is OsuModHidden))
{
double hiddenFactor = Attributes.AimHiddenFactor;
// the buff starts decreasing at AR9.75 and reaches 0 at AR10.75
if (Attributes.ApproachRate > 10.75)
hiddenFactor = 1;
else if (Attributes.ApproachRate > 9.75)
hiddenFactor = 1 + (1 - Math.Pow(Math.Sin((Attributes.ApproachRate - 9.75) * Math.PI / 2), 2)) * (hiddenFactor - 1);
tp *= hiddenFactor;
}
// Account for cheesing
double modifiedAcc = getModifiedAcc();
double accOnCheeseNotes = 1 - (1 - modifiedAcc) * Math.Sqrt(totalHits / Attributes.CheeseNoteCount);
// accOnCheeseNotes can be negative. The formula below ensures a positive acc while
// preserving the value when accOnCheeseNotes is close to 1
double accOnCheeseNotesPositive = Math.Exp(accOnCheeseNotes - 1);
double urOnCheeseNotes = 10 * greatWindow / (Math.Sqrt(2) * SpecialFunctions.ErfInv(accOnCheeseNotesPositive));
double cheeseLevel = SpecialFunctions.Logistic(((urOnCheeseNotes * Attributes.AimDiff) - 3200) / 2000);
double cheeseFactor = LinearSpline.InterpolateSorted(Attributes.CheeseLevels, Attributes.CheeseFactors)
.Interpolate(cheeseLevel);
if (mods.Any(m => m is OsuModTouchDevice))
tp = Math.Min(tp, 1.47 * Math.Pow(tp, 0.8));
double aimValue = tpToPP(tp * cheeseFactor);
// penalize misses
aimValue *= Math.Pow(0.96, Math.Max(effectiveMissCount - miss_count_leniency, 0));
// Buff long maps
aimValue *= 1 + (SpecialFunctions.Logistic((totalHits - 2800) / 500.0) - SpecialFunctions.Logistic(-2800 / 500.0)) * 0.22;
// Buff very high AR and low AR
double approachRateFactor = 1.0;
if (Attributes.ApproachRate > 10)
{
approachRateFactor += (0.05 + 0.35 * Math.Pow(Math.Sin(Math.PI * Math.Min(totalHits, 1250) / 2500), 1.7)) *
Math.Pow(Attributes.ApproachRate - 10, 2);
}
else if (Attributes.ApproachRate < 8.0)
approachRateFactor += 0.01 * (8.0 - Attributes.ApproachRate);
aimValue *= approachRateFactor;
if (mods.Any(h => h is OsuModFlashlight))
{
// Apply object-based bonus for flashlight.
aimValue *= 1.0 + 0.35 * Math.Min(1.0, totalHits / 200.0) +
(totalHits > 200
? 0.3 * Math.Min(1.0, (totalHits - 200) / 300.0) +
(totalHits > 500 ? (totalHits - 500) / 2000.0 : 0.0)
: 0.0);
}
// Scale the aim value down with accuracy
double accLeniency = greatWindow * Attributes.AimDiff / 300;
double accPenalty = (0.09 / (accuracy - 1.3) + 0.3) * (accLeniency + 1.5);
aimValue *= Math.Exp(-accPenalty);
return aimValue;
}
private double computeTapValue()
{
if (Beatmap.HitObjects.Count <= 1)
return 0;
double modifiedAcc = getModifiedAcc();
// Assume SS for non-stream parts
double accOnStreams = 1 - (1 - modifiedAcc) * Math.Sqrt(totalHits / Attributes.StreamNoteCount);
// accOnStreams can be negative. The formula below ensures a positive acc while
// preserving the value when accOnStreams is close to 1
double accOnStreamsPositive = Math.Exp(accOnStreams - 1);
double urOnStreams = 10 * greatWindow / (Math.Sqrt(2) * SpecialFunctions.ErfInv(accOnStreamsPositive));
double mashLevel = SpecialFunctions.Logistic(((urOnStreams * Attributes.TapDiff) - 4000) / 1000);
double tapSkill = mashLevel * Attributes.MashTapDiff + (1 - mashLevel) * Attributes.TapDiff;
double tapValue = tapSkillToPP(tapSkill);
// Buff very high acc on streams
double accBuff = Math.Exp((accOnStreams - 1) * 60) * tapValue * 0.2;
tapValue += accBuff;
// Scale tap value down with accuracy
double accFactor = 0.5 + 0.5 * (SpecialFunctions.Logistic((accuracy - 0.65) / 0.1) + SpecialFunctions.Logistic(-3.5));
tapValue *= accFactor;
// Penalize misses and 50s exponentially
tapValue *= Math.Pow(0.93, Math.Max(effectiveMissCount - miss_count_leniency, 0));
tapValue *= Math.Pow(0.98, countMeh < totalHits / 500.0 ? 0.5 * countMeh : countMeh - totalHits / 500.0 * 0.5);
// Buff very high AR
double approachRateFactor = 1.0;
double ar11LengthBuff = 0.8 * (SpecialFunctions.Logistic(totalHits / 500) - 0.5);
if (Attributes.ApproachRate > 10.33)
approachRateFactor += ar11LengthBuff * (Attributes.ApproachRate - 10.33) / 0.67;
tapValue *= approachRateFactor;
return tapValue;
}
private double computeAccuracyValue()
{
double fingerControlDiff = Attributes.FingerControlDiff;
double modifiedAcc = getModifiedAcc();
// technically accOnCircles = modifiedAcc
// -0.003 exists so that the difference between 99.5% and 100% is not too big
double accOnCircles = modifiedAcc - 0.003;
// accOnCircles can be negative. The formula below ensures a positive acc while
// preserving the value when accOnCircles is close to 1
double accOnCirclesPositive = Math.Exp(accOnCircles - 1);
// add 20 to greatWindow to nerf high OD
double deviationOnCircles = (greatWindow + 20) / (Math.Sqrt(2) * SpecialFunctions.ErfInv(accOnCirclesPositive));
double accuracyValue = Math.Pow(deviationOnCircles, -2.2) * Math.Pow(fingerControlDiff, 0.5) * 46000;
// scale acc pp with misses
accuracyValue *= Math.Pow(0.96, Math.Max(effectiveMissCount - miss_count_leniency, 0));
// nerf short maps
double lengthFactor = Attributes.Length < 120 ? SpecialFunctions.Logistic((Attributes.Length - 300) / 60.0) + SpecialFunctions.Logistic(2.5) - SpecialFunctions.Logistic(-2.5) : SpecialFunctions.Logistic(Attributes.Length / 60.0);
accuracyValue *= lengthFactor;
if (mods.Any(m => m is OsuModHidden))
accuracyValue *= 1.08;
if (mods.Any(m => m is OsuModFlashlight))
accuracyValue *= 1.02;
return accuracyValue;
}
private double getModifiedAcc()
{
// Treat 300 as 300, 100 as 200, 50 as 100
// Assume all 300s on sliders/spinners and exclude them from the calculation. In other words we're
// estimating the scorev2 acc from scorev1 acc.
// Add 2 to countHitCircles in the denominator so that later erfinv gives resonable result for ss scores
double modifiedAcc = ((countGreat - (totalHits - countHitCircles)) * 3 + countGood * 2 + countMeh) /
((countHitCircles + 2) * 3);
return modifiedAcc;
}
private double tpToPP(double tp) => Math.Pow(tp, skill_to_pp_exponent) * 0.118;
private double tapSkillToPP(double tapSkill) => Math.Pow(tapSkill, skill_to_pp_exponent) * 0.115;
private double fingerControlDiffToPP(double fingerControlDiff) => Math.Pow(fingerControlDiff, skill_to_pp_exponent);
private double totalHits => countGreat + countGood + countMeh + countMiss;
private double totalSuccessfulHits => countGreat + countGood + countMeh;
}
}