Sign in with
Sign up | Sign in
Your question

C++ Darts Simulation help!

Last response: in Video Games
Share
February 21, 2012 5:14:32 PM

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

More about : darts simulation

February 21, 2012 7:03:00 PM

Hi Hannah,
well first off you need to have a thorough understanding of what you're trying to code.

Personally I don't know what a game of '301' means.

regardless, you need to figure out a few things:

- how will a user (if applicable) interact with the program?
- how will the program output the results?
- what are the main concepts/algorithms behind the game you're trying to simulate?
- what is the main goal of the game? or in other words what are the conditions in order to win?
- what assumptions can you make to simplify?

Coding is complicated and can be overwhelming, but the most fundamental part that helps is having a good understanding of what you're trying to accomplish. Take a piece of paper and write down the key aspects about the simulation that you think you should have in your program. Then see if you can elaborate on each of the key concepts you just wrote down. It doesn't have to be complicated from the start, you can add complexity later.

As is, I don't have enough info to help you further, but I hope whatever I've wrote down is helpful is some way or another. If not, explain what is unclear and maybe I can provide you with some insight.
February 21, 2012 9:03:07 PM

antizig the game of 301 is a darts game for two more players, starting at 301, player 1 throws 3 darts, subtract result from 301, player 2 throws three darts subtract from 301. player 1 and player 2 then continue to alternate subtracting from thier new scores. To win a player must reach 0, the last dart must be a double, if you go over then that dart does not count and that group of three darts is finished.

Now you could code is that each person hits a random number, but any reasonable darts player would be aiming at a specific area. So you could request that there is an input as to what the player wants to hit, and then do some randomised calcs to determine if they hit, and if not then what do they hit. Perhaps some 'skill' number dictates the likelihood of hitting the target they are aiming for.

The first paragraph is a verbal description of the flow chart, you then 'just' need to code each section and figure out how they hang together.

This actually is a follow on to antizigs advice, you need to break down the problem into lots of little sections that you understand:

what number do they want to hit
what number did they hit
do the subtraction
is the score valid >0
if it is not valid does it =0 and was it a double.
changing players

all little sections that are little problems to solve in their own right.
perhaps start with a darts scoring program, and then add the simulation aspect in instead of manually entering numbers. FYI Skilled darts players will hit exactly what they want maybe 95-99% of the time.

if you are not sure what a darts board looks like then http://en.wikipedia.org/wiki/Darts

Good luck.
Related resources
February 22, 2012 8:03:30 AM

The math and logic behind the base of the game is very simple.
Its the user interface and user input which is hard.

You either have to capture the mouse movement then calculate the trajectory or create a method for simulating it, something like power bars (which move up and down) only for each axis.
February 22, 2012 8:24:46 AM

joe, its a non-depicted board, so its got be probability based, order of magnitude or two simpler at the moment (suspect it will grow)
February 22, 2012 9:31:15 AM

Opps I somehow missed that.

It makes the whole thing a lot more confusing.
Are they expecting the probability based on the surface area of score or merely having 1/61 chance of each outcome?

TC I would personally just ask the tutor/teacher who assigned the task for clarification as there are a ton of different possible ways of reading the task and even more possible outcomes of the system.
February 22, 2012 9:58:56 AM

I agree completely, you could centre a virtual circle around an aiming point, and then create a score based on probability, you'd need one table for of the 61 aiming points in a simplified model.
Or you could assign in a big table of probability a range of random numbers to each of the 61/62 possible results, but thats not how you play darts so it'd be a really poor simulation.
Or you could divide the board into n large blocks that you aim for (a bit like me playng darts), which would be a good simulation of a bad player.
But the overall flow of the program is better defined now I think, its just the process of getting an actual score thats in question, and how 'realistic' with out usng flight calculations do you want it to be.
!