Pascal: Calculating darts result

I believe that all of us seen or maybe even played darts. Everyone knows the circles which are numbered with points which you get by throwing the arrow. How could we calculate the result of our game if we get 10 points by hitting the center and then a minus one on each other circle on the darts board. And if we do not hit the board, we do not get any points which simply corresponds to zero.

You can see an example at this picture:

Darts board example

Our input information is the number of taken shots and the coordinates of shoots in coordinate system. And the main point of this program is to calculate a sum of our taken shots and output it on screen.

Our first step should be making a function which will count points given for one shot. We will be using a mathematical equation of circle. The equation:  x*x + y*y = r*r where x and y are the coordinates of point in coordinates system. So we are checking where our dart is pointed (the right circle) and how many points we need to give for that circle. For example, if we hit the seventh circle, we get 7 points and so on. I left two variables to determine this action for learning purposes. You can see whole function below:

Now we just need to add all shots to one sum variable and that’s all. Here is the main program code:

All variables are integers.

This program example also gets an initial circle radius from the person using the program, so it is handy for different types of dart’s boards. In addition, as I mentioned earlier we can abandon which variable which is the same as points in our calc_points function.

,

About Richard Smaizys

I am a freelance PHP developer working mostly on projects using PrestaShop for ecommerce (modules, theme integration, projects from 0 etc.) and WordPress as CMS solution.
No comments yet.

Leave a Reply