Add comments

This commit is contained in:
2025-03-19 11:46:19 +01:00
parent 5b61f0e5d9
commit 3fd7328f66
2 changed files with 13 additions and 8 deletions
+8 -6
View File
@@ -7,7 +7,7 @@ int ScoreCalculator::getScore(vector<int> rolls) {
while (true) {
// Strike
if (rolls[frame] == 10) {
// If we're on our last frame, and roll a 10.
// If we're on our last frame, and roll a strike, we're given two bonus rolls.
if (frame + 3 == rolls.size() && rolls[frame - 3] == 10) {
score += 10 + rolls[frame + 1] + rolls[frame + 2];
break;
@@ -15,11 +15,11 @@ int ScoreCalculator::getScore(vector<int> rolls) {
score += 10 + rolls[frame + 1] + rolls[frame + 2];
frame += 1;
continue;
}
// Spare
if (rolls[frame] + rolls[frame + 1] == 10) {
else if (rolls[frame] + rolls[frame + 1] == 10) {
// If we're on our last frame, and roll a spare, we're given a bonus roll.
if (frame + 3 == rolls.size() && rolls[frame] + rolls[frame + 1] == 10)
{
score += 10 + rolls[frame + 1];
@@ -28,13 +28,15 @@ int ScoreCalculator::getScore(vector<int> rolls) {
score += 10 + rolls[frame + 2];
frame += 2;
continue;
}
// Open Frame
score += rolls[frame] + rolls[frame + 1];
frame += 2;
else {
score += rolls[frame] + rolls[frame + 1];
frame += 2;
}
// No more frames
if (frame == rolls.size()) {
break;
}