Skip to content

Instantly share code, notes, and snippets.

@joshalanwagner
Created September 28, 2015 04:11
Show Gist options
  • Select an option

  • Save joshalanwagner/3aced80260cbedbdec56 to your computer and use it in GitHub Desktop.

Select an option

Save joshalanwagner/3aced80260cbedbdec56 to your computer and use it in GitHub Desktop.
public static List<int> ScoreFrames (List<int> score)
{
List<int> frame = new List<int> ();
List<string> result = new List<string> ();
bool ball1 = true;
for (int thisRoll = 0; thisRoll < score.Count; thisRoll++)
{
if (ball1 && score[thisRoll] == 10) {result.Add ("strike");}
else if (!ball1 && (score[thisRoll - 1] + score[thisRoll] == 10)) {result.Add ("spare");}
else {result.Add ("");}
if (thisRoll > 1 && (result[thisRoll - 2] == "strike" || (ball1 && result[thisRoll - 1] == "spare")))
{
frame.Add (score[thisRoll] + score[thisRoll - 1] + score[thisRoll - 2]);
}
if (result[thisRoll] == "" && !ball1 && frame.Count != 10)
{
frame.Add (score[thisRoll] + score[thisRoll - 1]);
}
if (ball1 && (result[thisRoll] == "" || frame.Count == 10)) {ball1 = false;}
else {ball1 = true;}
}
return frame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment