C++ Darts Simulation help!

Hello,

My name is Hannah. I am currently studying game design and am in the middle of being taught C++.

We've asked for our first assignment to write dart simulation program which lets player's Joe and Cid take 3 turns each at a non-depicted dart board and play a game of '301'- didn't even know what that was till recently lol.

I have to do the program in two ways: using functions i.e. in C style, and using classes i.e. in C++ style.

I have a little code when I was trying to write a program which would have calculated how many times it took "Joe" to hit the bull in ten turns etc, but other than that, I am thoroughly confused, and will take any help or suggestions I can get.

Thanks everyone.

Hannah x
Please don't duplicate posts.

http://www.cplusplus.com/forum/beginner/63816/
I'm guessing the scoring will be random, then. you will have to figure out the chances of one of the player hitting a particular number/bullseye and give them points accordingly, and make sure it uses the same rules as dart 301, whatever those rules may be.

here's a function I use for random numbers, it works quite well, all the others I've tried have been unbalanced.

1
2
3
4
5
6
7
8
9
10
#include <ctime> // time
#include <stdlib.h> // rand/srand

    void randomize(int &random, int max = 99, int min = 1)
    {
        // don't forget to seed once in main with srand(time(NULL));
        max = max + 1;
        max = max - min;
        random = (A)(rand() % max + min);
    }


then just call it like this..

1
2
3
4
5
6
7
8
9
10
11
12
13
...
srand(time(NULL));
int container;
randomize(container, 20, 1);
switch (container)
{
case 1:
    //add points to whoever if 1 represents bullseye for example
    break;
default:
    break;
}
...
Last edited on
You could simulate the positions of the darts using a bivariate normal distribution centred on the triple 20

Give a player a smaller standard deviation if they are better

Should impress your teacher!
you could have a series of x/y coordinates, every time they throw hit a random place, and calculate the distance from the middle

for the function one it could store the coords in an array of integers or floats and just calculate each via a function

for the classes one you could create a class called class ThrownDarts with x/y members and a "player" member
Topic archived. No new replies allowed.