# [Code Kata] Bowling game

About one year ago I found a blog post that was written by a programmer with over 40 years of experience. This is a great story to read, I strongly recommended it. Among the other great things in this blog, there was a tip that says “read at least 6 books per year“. It may sound a lot, but it’s only 1 book in 2 months, nothing special, the great thing is that after 5 years you will have read 30 books, that’s a lot of experience.

When you search for great books on software engineering, you can’t miss Robert C. Martin (Uncle Bob). There is also a series of books written or authored by Uncle Bob. I’ve read several of them, and in almost everyone the Code kata discipline was mentioned. It is a really interesting philosophy about the professional training in computer programming. In short, it is inspired from karate. Kata is an exercise in karate where you repeat a form many, many times, making little improvements in each step. It can be applied on programming technique too.

For this blog I’ve chosen the Bowling Game kata. It is a TDD exercise for a simple console game. In this game, a standard bowling game rules apply.

The game consists of 10 frames as shown above. In each frame, the player has two opportunities to knock down 10 pins. The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares.

A spare is when the player knocks down all 10 pins in two tries. The bonus for that frame is the number of pins knocked down by the next roll. So, in frame 3 above, the score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins knocked down on the next roll.)

A strike is when the player knocks down all 10 pins on his first try. The bonus for that frame is the value of the next two balls rolled.

In the tenth frame, a player who rolls a spare or strike is allowed to roll the extra balls to complete the frame. However no more than three balls can be rolled in the tenth frame.

For the needs of this exercise I’ve been using a C# as language and .net as framework. As an IDE I’m using Visual Studio 2017, you can use older versions of VS, it shouldn’t be any problem.

For the better experience i’m using :

• Vertical Tab Group view (In Visual Studio select Window->New Vertical Tab Group).
• CTRL+SHIFT+B for quick build.
• CTRL+R,A to run all tests.

The TDD principle is simple, quick, small iterations from RED->GREEN->Improve. This means, you first write the test to fall, then write code to pass the test, then improve. Do it in cycles, like a kata.

In this video, you can see how I’ve done it, it is not the only way of doing this kata, you can choose whatever works for you, you can even improve my code and steps.

Here are some improvements of the code that can be added, just to make the code more readable.

The complete source code from this video you can find on my GitHub account, you’re a free to download, edit and improve the code for your own purpose.

If you want to know more about code kata, you can find a lot in this links:

http://codekata.pragprog.com

http://codingdojo.org

http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata

This is my first blog post ever, i hope it will not be the last one. For a long time i want to start writing blog about my programming experience, but finally i found a subject that was very interesting enough to inspire me to write this blog.