private int bowl = 0;
public Action Bowl(int pins)
{
if (pins < 0 || pins > 10) { throw new UnityException("Invalid Pin Count"); }
bowl++;
bowls[bowl - 1] = pins;
switch (bowl)
{
// FRAME 10
case 19:
if (pins == 10) return Action.Reset; // strike in bowl 19
return Action.Tidy;
case 20:
if (bowls[19 - 1] == 10 && pins < 10) return Action.Tidy; // Open 20 after strike in 19
if (pins == 10 || pins + bowls[19 - 1] == 10) return Action.Reset; // Strike or spare in bowl 20
return Action.EndGame;
case 21:
return Action.EndGame; // Definitely no more after bowl 21
default:
// FRAMES 1 To 9
if (bowl % 2 == 0) return Action.EndTurn; // Second bowl of frame 1-9 always ends turn
else if (pins != 10) return Action.Tidy; // First bowl of frame 1-9 is open
else // First bowl of frame 1-9 is Strike
{
bowls[bowl] = 0; // Mark next roll as zero
bowl++; // Skip next roll
return Action.EndTurn;
}
}
}