-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathAim.cs
More file actions
182 lines (141 loc) · 7.46 KB
/
Aim.cs
File metadata and controls
182 lines (141 loc) · 7.46 KB
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
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Utils;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Difficulty.Utils;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Difficulty.Evaluators.Aim;
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects;
namespace osu.Game.Rulesets.Osu.Difficulty.Skills
{
/// <summary>
/// Represents the skill required to correctly aim at every object in the map with a uniform CircleSize and normalized distances.
/// </summary>
public class Aim : StrainSkill
{
public readonly bool IncludeSliders;
public Aim(Mod[] mods, bool includeSliders)
: base(mods)
{
IncludeSliders = includeSliders;
}
private double currentStrain;
private double skillMultiplierSnap => 71.3;
private double skillMultiplierAgility => 2.0;
private double skillMultiplierFlow => 245.0;
private double skillMultiplierTotal => 1.1;
private double meanExponent => 1.2;
/// <summary>
/// The number of sections with the highest strains, which the peak strain reductions will apply to.
/// This is done in order to decrease their impact on the overall difficulty of the map for this skill.
/// </summary>
private int reducedSectionCount => 10;
/// <summary>
/// The baseline multiplier applied to the section with the biggest strain.
/// </summary>
private double reducedStrainBaseline => 0.75;
private readonly List<double> sliderStrains = new List<double>();
private double strainDecay(double ms) => Math.Pow(0.15, ms / 1000);
protected override double CalculateInitialStrain(double time, DifficultyHitObject current) =>
currentStrain * strainDecay(time - current.Previous(0).StartTime);
protected override double StrainValueAt(DifficultyHitObject current)
{
double decay = strainDecay(((OsuDifficultyHitObject)current).AdjustedDeltaTime);
double snapDifficulty = SnapAimEvaluator.EvaluateDifficultyOf(current, IncludeSliders) * skillMultiplierSnap;
double agilityDifficulty = AgilityEvaluator.EvaluateDifficultyOf(current) * skillMultiplierAgility;
double flowDifficulty = FlowAimEvaluator.EvaluateDifficultyOf(current, IncludeSliders) * skillMultiplierFlow;
if (Mods.Any(m => m is OsuModTouchDevice))
{
snapDifficulty = Math.Pow(snapDifficulty, 0.89);
// we don't adjust agility here since agility represents TD difficulty in a decent enough way
flowDifficulty = Math.Pow(flowDifficulty, 1.1);
}
if (Mods.Any(m => m is OsuModRelax))
{
agilityDifficulty *= 0.3;
}
double totalDifficulty = calculateTotalValue(snapDifficulty, agilityDifficulty, flowDifficulty);
currentStrain *= decay;
currentStrain += totalDifficulty * (1 - decay);
if (current.BaseObject is Slider)
sliderStrains.Add(currentStrain);
return currentStrain;
}
private double calculateTotalValue(double snapDifficulty, double agilityDifficulty, double flowDifficulty)
{
// We compare flow to combined snap and agility because snap by itself doesn't have enough difficulty to be above flow on streams
// Agility on the other hand is supposed to measure the rate of cursor velocity changes while snapping
// So snapping every circle on a stream requires an enormous amount of agility at which point it's easier to flow
double combinedSnapDifficulty = DifficultyCalculationUtils.Norm(meanExponent, snapDifficulty, agilityDifficulty);
double pSnap = calculateSnapFlowProbability(flowDifficulty / combinedSnapDifficulty);
double pFlow = 1 - pSnap;
double totalDifficulty = combinedSnapDifficulty * pSnap + flowDifficulty * pFlow;
double totalStrain = totalDifficulty * skillMultiplierTotal;
return totalStrain;
}
// A function that turns the ratio of snap : flow into the probability of snapping/flowing
// It has the constraints:
// P(snap) + P(flow) = 1 (the object is always either snapped or flowed)
// P(snap) = f(snap/flow), P(flow) = f(flow/snap) (ie snap and flow are symmetric and reversible)
// Therefore: f(x) + f(1/x) = 1
// 0 <= f(x) <= 1 (cannot have negative or greater than 100% probability of snapping or flowing)
// This logistic function is a solution, which fits nicely with the general idea of interpolation and provides a tuneable constant
private static double calculateSnapFlowProbability(double ratio)
{
const double k = 7.27;
if (ratio == 0)
return 0;
if (double.IsNaN(ratio))
return 1;
return DifficultyCalculationUtils.Logistic(-k * Math.Log(ratio));
}
public double GetDifficultSliders()
{
if (sliderStrains.Count == 0)
return 0;
double maxSliderStrain = sliderStrains.Max();
if (maxSliderStrain == 0)
return 0;
return sliderStrains.Sum(strain => 1.0 / (1.0 + Math.Exp(-(strain / maxSliderStrain * 12.0 - 6.0))));
}
public double CountTopWeightedSliders(double difficultyValue)
{
if (sliderStrains.Count == 0)
return 0;
double consistentTopStrain = difficultyValue * (1 - DecayWeight); // What would the top strain be if all strain values were identical
if (consistentTopStrain == 0)
return 0;
// Use a weighted sum of all strains. Constants are arbitrary and give nice values
return sliderStrains.Sum(s => DifficultyCalculationUtils.Logistic(s / consistentTopStrain, 0.88, 10, 1.1));
}
public override double DifficultyValue()
{
double difficulty = 0;
double weight = 1;
// Sections with 0 strain are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871).
// These sections will not contribute to the difficulty.
var peaks = GetCurrentStrainPeaks().Where(p => p > 0);
List<double> strains = peaks.OrderDescending().ToList();
// We are reducing the highest strains first to account for extreme difficulty spikes
for (int i = 0; i < Math.Min(strains.Count, reducedSectionCount); i++)
{
double scale = Math.Log10(Interpolation.Lerp(1, 10, Math.Clamp((float)i / reducedSectionCount, 0, 1)));
strains[i] *= Interpolation.Lerp(reducedStrainBaseline, 1.0, scale);
}
// Difficulty is the weighted sum of the highest strains from every section.
// We're sorting from highest to lowest strain.
foreach (double strain in strains.OrderDescending())
{
difficulty += strain * weight;
weight *= DecayWeight;
}
return difficulty;
}
}
}