A game of ten-pin bowling is divided into ten rounds (called "frames"). In a frame, each player is given two opportunities to knock down the skittle targets (called "pins"). The player rolls the first ball at the pins. If the first ball knocks down all ten pins, it is called a strike and the frame is completed. When pins are left standing after the first ball, the player rolls a second ball and if all the remaining pins are knocked down, it is called a spare.
You can get more info about ten-pin bowling, its rules of play and scoring from here.
Next I will give u two methods to calculate score for a entire game:
1. A strike wins you ten points plus the points for the next two balls thrown (for example if you got a strike then followed with a 7 then 2 your value for the strike would be 10+7+2, or 19). A spare wins you ten points plus the points for the next ball thrown (again, if you get a spare then follow it with 7 pins down your value for the spare would be 10+7, or 17). Open frames are added normally (example: you knock down 5 on your first ball and 3 on your second your open frame would be worth 5+3, or 8 points). The maximum score in tenpin bowling is 300. Below is the function to get score:
Get Score
/**//// <summary>
/// Take the number of pins for each roll as input
/// Return the score of the entire game
/// </summary>
/// <param name="pinNum">Number of pins for each roll</param>
/// <returns>Score</returns>
int GetScore(int[] pinNum)
{
//Score of the entire game.
int sum = 0;
//score:The score of each round.
int score;
//round: 09: The index for 10 rounds.
//pinNum[roll]: The number of pins for each ball thrown.
for (int round = 1, roll = 0; round <= 10; ++ round)
{
//Strike
if (pinNum[roll] == 10)
{
score = 10 + pinNum[roll + 1] + pinNum[roll + 2];
sum += score;
roll++;
}
//Spare
else if (pinNum[roll] + pinNum[roll + 1] == 10)
{
score = 10 + pinNum[roll + 2];
sum += score;
roll += 2;
}
//Open
else
{
score = pinNum[roll] + pinNum[roll + 1];
sum += score;
roll += 2;
}
}
return sum;
}
2. There does exist an alternative method for keeping score. It is used by scoreboards at some tournaments, and by some bowling software programs. It is exactly the same as the conventional scoring described above, except that the score is always current.
The basic rules are as follows:
- Spare = Points scored for the next ball are doubled (2 points per pin knocked down);
- Strike = Points scored for the next two balls are doubled (2 points per pin);
- Two or more strikes in a row = Points scored for the next ball are tripled (3 points per pin). If this roll is not a strike then the next ball is counted with doubled points.
- If all ten pins are not knocked down, no bonuses are scored on subsequent throws - only actual pinfall.
The scoring for the tenth frame goes as follows:
- If a spare was earned in the ninth frame, score double on the first ball in the tenth frame and face value (single) for the second and third balls, if there is a third ball.
- If a strike was earned in the ninth frame, score double on the first two balls in the tenth frame and single on the third ball.
- If strikes were earned in the 8th and 9th frames (as in our sample), score triple on the first ball in the tenth, double on the second ball, and single on the third.
- If the ninth frame was open (all 10 pins not down on 2 balls), then all three balls in the tenth count single.
Below is the function to get score:
Get Score
public static int GetScore(int[] pinNum)
{
int roll, round;
int totalScore = 0;
//score:The score of each.
int score;
//index: 09: The index for 10 rounds.
//pinNum[roll]: The number of pins for each ball thrown.
int[] multiple = new int[pinNum.Count()];
for (int i = 0; i < pinNum.Count(); ++i)
{
multiple[i] = 1;
}
try
{
for (round = 1, roll = 0; round <= 9; ++round)
{
//Strike
if (pinNum[roll] == 10)
{
if (roll - 1 >= 0 && pinNum[roll - 1] == 10)
{
multiple[roll + 1] = 3;
multiple[roll + 2] = 2;
}
else
{
multiple[roll + 1] = 2;
multiple[roll + 2] = 2;
}
score = pinNum[roll] * multiple[roll];
totalScore += score;
roll++;
}
//Spare
else if (pinNum[roll] + pinNum[roll + 1] == 10)
{
multiple[roll + 2] = 2;
score = pinNum[roll] * multiple[roll] + pinNum[roll + 1] * multiple[roll + 1];
totalScore += score;
roll += 2;
}
//Open
else if (pinNum[roll] + pinNum[roll + 1] < 10)
{
score = pinNum[roll] * multiple[roll] + pinNum[roll + 1] * multiple[roll + 1];
totalScore += score;
roll += 2;
}
else
{
throw new Exception("Invalid numbers for round " + round);
}
}
//For the ninth frame
//Strikes are earned if the 8th and 9th frames
if (multiple[roll] >= 2 && pinNum[roll-1] == 10 &&
multiple[roll - 1] >= 2 && pinNum[roll-2] == 10)
{
score = pinNum[roll] * 3;
if (roll + 1 < pinNum.Count())
score += pinNum[roll + 1] * 2;
if (roll + 2 < pinNum.Count())
score += pinNum[roll + 2];
totalScore += score;
}
//A strike in the ninth frame
else if (multiple[roll] == 2 &&
pinNum[roll-1] == 10 &&
pinNum[roll-2]!=0)
{
score = pinNum[roll] * 2;
if(roll+1<pinNum.Count())
score += pinNum[roll+1] * 2;
if (roll + 2 < pinNum.Count())
score += pinNum[roll + 2];
totalScore += score;
}
//A spare in the ninth frame
else if (multiple[roll] == 2)
{
score = pinNum[roll] * 2;
if (roll + 1 < pinNum.Count())
score += pinNum[roll + 1];
if (roll + 2 < pinNum.Count())
score += pinNum[roll + 2];
totalScore += score;
}
else
{
score = pinNum[roll];
if (roll + 1 < pinNum.Count())
score += pinNum[roll + 1];
if (roll + 2 < pinNum.Count())
score += pinNum[roll + 2];
totalScore += score;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return totalScore;
}
Go to my home page for more posts