#include <iostream>
// The algorithm starts at 0x0045ecfc in USA Rev1
int calculateHiddenScore(
unsigned int raceTime,
unsigned int raceTimeInFirstPlace,
bool rocketStart,
unsigned int raceTimeInFirstPerson,
unsigned int timeUsingGyroControls,
int miniturboLevel1,
int miniturboLevel2,
int numEnemiesHitWithItems,
int respawns,
int trick
) {
if (raceTime == 0) {
return 0;
}
int score = static_cast<int>((raceTimeInFirstPlace * 350.0f) / raceTime);
if (rocketStart) {
score += 25;
}
float gyroPenalty = (timeUsingGyroControls * 180.0f) / raceTime;
float miniturboBonus = (miniturboLevel1 + miniturboLevel2 * 2) * 7.0f;
float trickBonus = trick * 4.0f;
float enemyBonus = numEnemiesHitWithItems * 10.0f;
float respawnPenalty = respawns * -70.0f;
float firstPersonScorePart = ((raceTimeInFirstPerson - timeUsingGyroControls) * 100.0f) / raceTime;
float totalScore = firstPersonScorePart + gyroPenalty + miniturboBonus + trickBonus + enemyBonus + respawnPenalty + score;
int finalScore = static_cast<int>(totalScore);
if (finalScore < 0) {
finalScore = 0;
} else if (finalScore > 250) {
finalScore = 250;
}
return finalScore;
}
int main() {
// Racetime in frames, starting from the countdown
unsigned int raceTime = 5000;
// Frames in first place, starting from the countdown
unsigned int raceTimeInFirstPlace = 4500;
// Successfully done a rocket start at any level
bool rocketStart = true;
// Frames while in first person view, starting from the countdown
unsigned int raceTimeInFirstPerson = 4800;
// Frames using gyro controls to move while in first person view, starting from the countdown
// Note that this timer won't count whenever you use the stick to move
unsigned int timeUsingGyroControls = 200;
// Number of blue miniturbo performed
int miniturboLevel1 = 3;
// Number of orange miniturbo performed
int miniturboLevel2 = 2;
// Number of times you've hit CPUs using items
int numEnemiesHitWithItems = 5;
// Number of times you've fell out of bounds and picked up by Lakitu
int respawns = 1;
// Number of tricks performed
int trick = 4;
int hiddenScore = calculateHiddenScore(
raceTime,
raceTimeInFirstPlace,
rocketStart,
raceTimeInFirstPerson,
timeUsingGyroControls,
miniturboLevel1,
miniturboLevel2,
numEnemiesHitWithItems,
respawns,
trick
);
std::cout << "Hidden Score: " << hiddenScore << std::endl;
return 0;
}