Created
July 10, 2016 00:54
-
-
Save dugdaniels/4956b84173d42655c10531b77b3060e9 to your computer and use it in GitHub Desktop.
Bowling scoring logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<int> ScoreFrames(List<int> rolls) { | |
List<int> frameList = new List<int>(); | |
int rollNumber = 0; | |
int currentFrame = 0; | |
int rollsRemainingInFrame = 2; | |
foreach (int roll in rolls) if (frameList.Count < 10) { | |
rollNumber++; | |
rollsRemainingInFrame--; | |
currentFrame += roll; | |
if (currentFrame == 10 && rollsRemainingInFrame >= 1) { | |
if (rolls.Count >= rollNumber + 2) { | |
currentFrame += rolls[rollNumber] + rolls[rollNumber + 1]; | |
frameList.Add(currentFrame); | |
} | |
currentFrame = 0; | |
rollsRemainingInFrame = 2; | |
} | |
if (currentFrame == 10 && rollsRemainingInFrame == 0) { | |
if (rolls.Count >= rollNumber + 1) { | |
currentFrame += rolls[rollNumber]; | |
frameList.Add(currentFrame); | |
} | |
currentFrame = 0; | |
rollsRemainingInFrame = 2; | |
} | |
if (rollsRemainingInFrame == 0) { | |
frameList.Add(currentFrame); | |
currentFrame = 0; | |
rollsRemainingInFrame = 2; | |
} | |
} | |
return frameList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment