Line: 1 to 1  

 
Line: 33 to 33  
This would simulate someone shooting at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less than accuracy , then the target is hit and targetAlive should be set to false . Below is a link that illustrates how to generate random numbers.
Generating Random Numbers  
Added:  
> >  Click here to see how to generate a random number between 0 and 1;  
You should write a function to seed the random number generator, and another to return the next random number between 0 and 1.
So, for example, if Bob is shooting at Charlie, this could be invoked as: 
Line: 1 to 1  

 
Changed:  
< <  Due: Feb 28, 11:55pm  
> >  Due: Oct 10, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions

Line: 1 to 1  

 
Changed:  
< <  Due: Oct 11, 11:55pm  
> >  Due: Feb 28, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions

Line: 1 to 1  

 
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions
 
Line: 62 to 61  
FunctionsYour code should be broken up into functions to simplify it. I would suggest the following routines to start:  
Added:  
> >  
%CODE{"c++"}% void seedRandom(); // Seed the random number generator double nextRandom(); // Get the next random number (between 0.0 and 1.0) void shoot(bool& targetAlive, double accuracy); // Shoot with accuracy given, and set targetAlive to false if you hit.  
Changed:  
< <  %ENDCODE%</sticky>  
> >  %ENDCODE%  
What to do 
Line: 1 to 1  

 
Added:  
> >  Moodle Link  
Instructions 
Line: 1 to 1  

Added:  
> > 
Lab 42Due: Oct 2, 11:55pm
Instructions
Grading Table
Problem  Duel SimulationIn the land of Puzzlevania, Aaron, Bob, and Charlie had an argument over which one of them was the greatest puzzler of all time. To end the argument once and for all, they agreed on a duel to the death. Aaron is a poor shooter and only hits his target with a probability of 1/3. Bob is a bit better and hits his target with a probability of 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel. To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns starting with Aaron, followed by Bob, then by Charlie, then back to Aaron. The cycle would repeat until there was only one man standing. And that man would be remembered as the greatest puzzler of all time.
a. Write a function to simulate a single shot. It should use the following declaration:
< SyntaxHighlightingPlugin > void shoot(bool& targetAlive, double accuracy); < end SyntaxHighlightingPlugin > This would simulate someone shooting at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less than accuracy , then the target is hit and targetAlive should be set to false . Below is a link that illustrates how to generate random numbers. Generating Random NumbersYou should write a function to seed the random number generator, and another to return the next random number between 0 and 1.
So, for example, if Bob is shooting at Charlie, this could be invoked as:
< SyntaxHighlightingPlugin > shoot(charlieAlive, 0.5); < end SyntaxHighlightingPlugin > Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step b. b. An obvious strategy is for each man to shoot at the most accurate shooter still alive on the grounds that this shooter is the deadliest and has the best chance of hitting back. Write a second function named startDuel that uses the shoot function to simulate an entire duel using this strategy. The function will cycle through the men in the given order (Aaron, Bob, Charlie), dropping each men out of the conetest when they die. It should loop until only one contestant is left, invoking the shoot function with the proper target and probability of hitting the target according to who is shooting. The function should return a variable that indicates who won the duel. For example, you might have the series:
FunctionsYour code should be broken up into functions to simplify it. I would suggest the following routines to start: < SyntaxHighlightingPlugin > void seedRandom(); // Seed the random number generator double nextRandom(); // Get the next random number (between 0.0 and 1.0) void shoot(bool& targetAlive, double accuracy); // Shoot with accuracy given, and set targetAlive to false if you hit. < end SyntaxHighlightingPlugin ></sticky>
What to doYou can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. duel1 (the first strategy) and duel2 (the second strategy), and have it first run the test with duel1, then with duel2. After each set of 1000 duels, print the probability that each contestant will win for that strategy. Example Run:
Strategy one: always shoot at the best shot. Out of a 1000 duels: Aaron wins 374 times, probability of winning 0.374 Bob wins 419 times, probability of winning 0.419 Charlie wins 207 times, probability of winning 0.207 Strategy two: always shoot at the best shot. Aaron misses first shot Out of a 1000 duels: Aaron wins 356 times, probability of winning 0.356 Bob wins 422 times, probability of winning 0.422 Charlie wins 222 times, probability of winning 0.222 (The above answers are examples, not the correct numbers). Turn In
