Skip to content

Commit 18c9748

Browse files
Merge pull request #1268 from UltraStar-Deluxe/1-scoring
round scores to whole numbers, but not multiples of 10
2 parents c49a552 + 269293d commit 18c9748

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

src/base/UNote.pas

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,33 @@ procedure TPlayer.SetScoreGolden(newScoreGolden: real);
196196
end;
197197
procedure TPlayer.UpdateIntScores();
198198
begin
199-
// a problem if we use floor instead of round is that a score of
200-
// 10000 points is only possible if the last digit of the total points
201-
// for golden and normal notes is 0.
202-
// if we use round, the max score is 10000 for most songs
203-
// but a score of 10010 is possible if the last digit of the total
204-
// points for golden and normal notes is 5
205-
// the best solution is to use round for one of these scores
206-
// and round the other score in the opposite direction
207-
// so we assure that the highest possible score is 10000 in every case.
208-
_ScoreInt := round(Score / 10) * 10;
209-
if (_ScoreInt < Score) then
210-
//normal score is floored so we have to ceil golden notes score
211-
_ScoreGoldenInt := ceil(ScoreGolden / 10) * 10
212-
else
213-
//normal score is ceiled so we have to floor golden notes score
214-
_ScoreGoldenInt := floor(ScoreGolden / 10) * 10;
215-
216-
// line bonus
217-
_ScoreLineInt := Floor(Round(ScoreLine) / 10) * 10;
218-
219199
// total score
220-
_ScoreTotalInt := ScoreInt + ScoreGoldenInt + ScoreLineInt;
200+
_ScoreTotalInt := round(Score + ScoreGolden + ScoreLine);
201+
// components
202+
_ScoreInt := round(Score);
203+
_ScoreGoldenInt := round(ScoreGolden);
204+
_ScoreLineInt := round(ScoreLine);
205+
// _ScoreTotalInt = as close to the truth as possible, but the components might not add up to it
206+
// this can happen if:
207+
// * all the components are .2 (total is one higher than sum of components)
208+
// * all the components are .6 (total is one less than the sum of components)
209+
// in these cases we just +1/-1 a component so that it fits
210+
if (_ScoreInt + _ScoreGoldenInt + _ScoreLineInt > _ScoreTotalInt) then begin
211+
// prefer decreasing golden notes first, then regular notes, as a last resort just -1 the line bonus
212+
if (_ScoreGoldenInt > 0) then
213+
_ScoreGoldenInt := _ScoreGoldenInt - 1
214+
else if (_ScoreInt > 0) then
215+
_ScoreInt := _ScoreInt - 1
216+
else
217+
_ScoreLineInt := _ScoreLineInt - 1;
218+
end else if (_ScoreInt + _ScoreGoldenInt + _ScoreLineInt < _ScoreTotalInt) then begin
219+
// if the very first note(s) is golden AND this is the very beginning of the song, this might (temporarily) increase the wrong one.
220+
// it is estimated that there are way more songs that simply don't have golden notes at all and where it thus would pick the correct one.
221+
if (_ScoreInt > 0) or (_ScoreGoldenInt = 0) then
222+
_ScoreInt := _ScoreInt + 1
223+
else
224+
_ScoreGoldenInt := _ScoreGoldenInt + 1;
225+
end;
221226
end;
222227
procedure TPlayer.ResetScores();
223228
begin

src/base/USingScores.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ procedure TSingScores.DrawScore(const Index: integer);
11951195
SetFontPos(Position.TextX, Position.TextY);
11961196
SetFontReflection(false, 0);
11971197

1198-
ScoreStr := InttoStr(Players[Index].ScoreDisplayed div 10) + '0';
1198+
ScoreStr := InttoStr(Players[Index].ScoreDisplayed);
11991199
while (Length(ScoreStr) < 5) do
12001200
ScoreStr := '0' + ScoreStr;
12011201

0 commit comments

Comments
 (0)