Problem in 10th frame AllanW 25th July, 2006 20:26 (UTC)

The 10th frame won't work correctly in your version.

If the first ball of the 10th frame is 10, then there are TWO more balls. If the second one is also 10, then the total for the 10th frame will be at least 20, up to 30 total. Otherwise, if the first two balls of the 10th frame add up to 10, then there is a THIRD ball. The total is at least 10, up to 20 total. Otherwise, the 10th frame has only 2 balls, the total is anywhere from 0 to 9.

One of the tests you should include is a "perfect game". - A perfect game has exactly 12 balls, and they each get 10 pins. 10 10 10 10 10 10 10 10 10 10 10 10 >=> Total is 300 (Highest possible)

A valid game always has at least 11 balls, and can't have more than 21. - To have 11 balls, the first 9 balls would knock down 10 each. The last two balls would add up to 9 or less. 10 10 10 10 10 10 10 10 10 0 0 >=> Total is 240 (Lowest possible with 11 balls) 10 10 10 10 10 10 10 10 10 9 0 >=> Total is 267 (Highest possible with 11 balls)

- To have 21 balls, the first 9 frames would start with a ball of 9 or less. In the 10th frame, either the first ball would be a 10, or the first two balls would add up to 10. The total score could be anywhere from 10 to 202. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 >=> Total is 10 (Lowest possible with 21 balls) 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 10 10 10 >=> Total is 202 (Highest possible with 21 balls)

There should also be at least one test case where there are no "marks" (never sink all 10 pins in the same frame). There are always exactly 20 balls. - 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 >=> 90 (Highest possible with no marks)

The justification for these rules is: In general, the score for any frame matches the number of pins knocked down in that frame. There are two exceptions: - If you knock down all 10 pins with 2 balls, this is called a "spare". The score for the frame is 10, plus whatever your next ball knocks down. (That ball then counts twice — once in the frame where it is played, and once in the frame with the spare). As a special case, if you get a "spare" in the 10th frame, you get to roll an extra ball. That extra ball doesn't count for the 11th frame (because there is no 11th frame), but it is nevertheless added to your 10th frame score. - If you knock down all 10 pins with one ball, this is called a "strike". The score for the frame is 10, plus whatever your next TWO balls knock down. (Those two balls are then counted at least twice… if you get two strikes in a row, then the very next ball is counted THREE times.) Again, if this occurs in the 10th frame, you get two extra balls, which are not counted for the 11th (or 12th) frames, but are counted in the 10th frame score.

So, the reason that a "perfect game" score is 300 is that each frame counts 10 for the main score, plus the next two balls (which are 10 each). After the first 10 strikes, there are two extra balls… but they only count for the 10th frame. So there are a total of 10 frames, each one scores 30, grand total is 300.

Problem in 10th frame Kirit Sælensminde 26th July, 2006 13:48 (UTC)
AllanW said

The 10th frame won't work correctly in your version.

If the first ball of the 10th frame is 10, then there are TWO more balls. If the second one is also 10, then the total for the 10th frame will be at least 20, up to 30 total. Otherwise, if the first two balls of the 10th frame add up to 10, then there is a THIRD ball. The total is at least 10, up to 20 total. Otherwise, the 10th frame has only 2 balls, the total is anywhere from 0 to 9.

One of the tests you should include is a "perfect game". - A perfect game has exactly 12 balls, and they each get 10 pins. 10 10 10 10 10 10 10 10 10 10 10 10 >=> Total is 300 (Highest possible)

This test was already included. Take a look at the third from last test. This test has validated against both version from my article. To see a version which didn't calculate the tenth frame correctly look at Christopher Smith's versions. I discussed this in a bit more detail in my round-up for June.

A valid game always has at least 11 balls, and can't have more than 21. - To have 11 balls, the first 9 balls would knock down 10 each. The last two balls would add up to 9 or less. 10 10 10 10 10 10 10 10 10 0 0 >=> Total is 240 (Lowest possible with 11 balls) 10 10 10 10 10 10 10 10 10 9 0 >=> Total is 267 (Highest possible with 11 balls)

- To have 21 balls, the first 9 frames would start with a ball of 9 or less. In the 10th frame, either the first ball would be a 10, or the first two balls would add up to 10. The total score could be anywhere from 10 to 202. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 >=> Total is 10 (Lowest possible with 21 balls) 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 10 10 10 >=> Total is 202 (Highest possible with 21 balls)

There should also be at least one test case where there are no "marks" (never sink all 10 pins in the same frame). There are always exactly 20 balls. - 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 9 0 >=> 90 (Highest possible with no marks)

Thanks for the extra tests. As I said in the article, I wasn't sure about making my own tests as I couldn't be sure I understood the rules well enough. Your edge conditions are a useful addition.

Here is the new set of test cases — I've added your new ones to the end:

Test( 0, [] );
Test( 0, [ 0, 0, 0 ] );
Test( 10, [ 10 ] );
Test( 10, [ 10, 0 ] );
Test( 30, [ 10, 10 ] );
Test( 90, [ 8,1, 7,2, 6,3, 5,4, 4,5, 3,6, 2,7, 1,8, 2,7, 3,6 ] );
Test( 24, [ 6,4, 6,2 ] );
Test( 24, [ 6,4, 6,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 ] );
Test( 300, [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] );
Test( 200, [ 10, 5,5, 10, 6,4, 10, 7,3, 10, 4,6, 10, 3,7, 10, 9,1 ] );
Test( 200, [ 9,1, 10, 5,5, 10, 6,4, 10, 7,3, 10, 4,6, 10, 3,7, 10 ] );
Test( 240, [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0 ] );
Test( 267, [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 0 ] );
Test( 10, [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0 ] );
Test( 202, [ 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 10, 10 ] );
Test( 90, [ 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0 ] );

All of these pass with the two versions that I wrote and they all pass on the debugged version of Christopher Smith's functional version that I've got in my test suite now.

I feel happier that the algorithms really are correct with those extra tests in there.

K

To join in the discussion you should register or log in