exercism bowling challenge
Posted by Pharo Smalltalk Users mailing list on Sep 21, 2020; 4:49pm
URL: https://forum.world.st/exercism-bowling-challenge-tp5122317.html
hello,
I need now to make code that calculates the full score of a bowling
game like one of the tests shown.
test09_ConsecutiveStrikesEachGetTheTwoRollBonus
| result |
result := bowlingCalculator
scoreAfterRolling: #(10 10 10 5 3 0 0 0 0 0 0 0 0 0 0 0 0).
self assert: result equals: 81
What I thougt of solving this is to make a class BowlingCalculator
and a class Frame
and first convert the numbers to a frame.
the Frame class should then have two instance variables throw1 and
throw2 where throw2 can be null if the first throw is 10.
Then to calculate the total score I can check if the first number is
10
if so, take the next frame and sum them up.
if not, check if the total of a frame is 10
if so, take the first number out of the next frame and sum them up
if both are not true , then sum only the frame
and then in all cases goto the next frame.
Can this plan be working or is there improvements to this plan.
Roelof