Skip to content

Commit

Permalink
Apply requested refactorings
Browse files Browse the repository at this point in the history
l -> leftIndex
r -> rightIndex
useFallback is only enabled on odd key count (not counting scratch)
  • Loading branch information
WilliamQiufeng committed Aug 18, 2024
1 parent d2e7241 commit b4481a3
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@ private float CalculateOverallDifficulty()
var mapStart = StrainSolverData.Min(s => s.StartTime);
var mapEnd = StrainSolverData.Max(s => Math.Max(s.StartTime, s.EndTime));

var l = 0;
var r = 0;
var useFallback = Map.GetKeyCount() != 4;
while (l < StrainSolverData.Count && StrainSolverData[l].StartTime < mapStart)
l++;
var leftIndex = 0;
var rightIndex = 0;
var useFallback = Map.GetKeyCount(false) % 2 == 1;
while (leftIndex < StrainSolverData.Count && StrainSolverData[leftIndex].StartTime < mapStart)
leftIndex++;
for (var i = mapStart; i < mapEnd; i += binSize)
{
List<StrainSolverData> valuesInBin;
Expand All @@ -575,21 +575,22 @@ private float CalculateOverallDifficulty()
}
else
{
while (r < StrainSolverData.Count - 1 && StrainSolverData[r + 1].StartTime < i + binSize)
r++;
if (l >= StrainSolverData.Count)
while (rightIndex < StrainSolverData.Count - 1 && StrainSolverData[rightIndex + 1].StartTime < i + binSize)
rightIndex++;

if (leftIndex >= StrainSolverData.Count)
{
bins.Add(0);
continue;
}

valuesInBin = StrainSolverData.GetRange(l, r - l + 1);
valuesInBin = StrainSolverData.GetRange(leftIndex, rightIndex - leftIndex + 1);
}

var averageRating = valuesInBin.Count > 0 ? valuesInBin.Average(s => s.TotalStrainValue) : 0;

bins.Add(averageRating);
l = r + 1;
leftIndex = rightIndex + 1;
}

if (!bins.Any(strain => strain > 0)) return 0;
Expand Down

0 comments on commit b4481a3

Please sign in to comment.