Score Manipulation

From Super Mario World Speedrunning Wiki
Revision as of 22:35, 15 February 2023 by IsoFrieze (talk | contribs) (Created page with "=Overview= '''Score Manipulation''' is a very high-level technique that involves planning out exactly how many points you get in every level, so that your total score is a val...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

Score Manipulation is a very high-level technique that involves planning out exactly how many points you get in every level, so that your total score is a value that takes a minimal time for the game to calculate and draw to the screen. Managing the player's score is a small portion of all of the things the game needs to do every frame, but if the score is not optimal, it can cause the game to lag more often during laggy portions of the run. This mainly includes the spotlight and fadeout at the end of every goal tape march, as well as every keyhole animation. However, certain levels are particularly laggy on their own, such as Back Door, Forest of Illusion 2, and Sunken Ghost Ship. Having an optimal score while playing these levels will reduce lag.

A good score manipulation route will have the player collect or purposefully *not* collect certain items without losing any time (for example, whether to collect a Dragon Coin or to jump over it). However, due to how little of time score manipulation actually saves and how much extra effort it takes to pay attention to your score at all times, most runners forego extremely optimal score manipulation. A couple more general rules are easier to follow to get the most beneficial improvements with the least amount of effort:

Score Calculation Algorithm

The player's score is stored as a 24-bit hexadecimal number in memory. This number is converted into a 6-digit decimal number every frame and displayed on the status bar (the last zero in the score is basically just for looks). There is no hardware in the Super Nintendo to manage numbers this large, so this conversion is done in software. It's not a slow algorithm, but it isn't fast by any means. To make matters worse, it is run every single frame. This means, if you have a score that makes this algorithm take a long time, there is less time for the game to process other game things, like physics, collisions, etc. This makes the game more likely to lag.

Pseudocode

Here is a simplified version of the code that runs to convert the score from hexadecimal to decimal. You can find the original code here.

let tempScore <- score
for i from 5 to 0 do
   let digit = 0
   while tempScore - 10^i > 0 do
      tempScore <- tempScore - 10^i
      digit <- digit + 1
   end
   set status bar score at the 10^i's place to digit
end
let k <- 5
while status bar score at the 10^k's place is 0
   set status bar score at the 10^k's place to an empty tile
   k <- k - 1
end

Essentially, for each of the digits in the score, that number in the score determines how many times the temporary score will be adjusted by a power of 10. For example, a score of 386750 will:

  • (0) subtract 100000 from the score 1 time
  • (3) subtract 10000 from the score 4 times
  • (8) subtract 1000 from the score 9 times
  • (6) subtract 100 from the score 7 times
  • (7) subtract 10 from the score 8 times
  • (5) subtract 1 from the score 6 times.

Notice that there will always be one subtraction first, so the amount of times is that digit plus one.

The game will also have to replace the leading zero with an empty tile, so that the score shows 386750 instead of 0386750.

Theory

As you can see, the higher a digit is in the score, the more times the algorithm has to loop and subtract a power of ten from the score. This means that scores with low digits take the least amount of time to convert and draw. However, the empty tiles that precede smaller scores also take extra time to draw. This means the most optimal score is exactly 1000000. The least optimal score is the maximum score of 9999990. In general, you can estimate how "good" of a score you have by summing all of the digits of the score together. For example, the score of 386750 has a value of about 29. From this, you can tell that a score of 100000 is much better than a score of 99950, since the values for those scores are 1 and 32, which are vastly different. If you had a score of 99950, you can spin jump on an enemy to kill it, gaining 200 points. This would put you at 100150, with a value of 7, which is still much better than 32.