In the land of Puzzlevania, Aaron, Bob, and Charlie had an argument over which one ofthem was the greatest puzzle-solver of all time. To end the argument once and for all,they agreed on a duel to the death (this makes sense?). Aaron was a poor shot and onlyhit this target with a probability of 1/3. Bob was a bit better and hit his target with aprobability of 1/2. Charlie was an expert marksman and never missed. A hit means a killand the person hit drops out of the duel.To compensate for the inequities in their marksmanship skills, the three decided thatthey would fire in turns, starting with Aaron, followed by Bob, and then by Charlie. Thecycle would repeat until there was one man standing. That man would be rememberedfor all time as the Greatest Puzzle-Solver of All Time.An obvious and reasonable strategy is for each man to shoot at the most accurateshooter still alive, on the grounds that this shooter is the deadliest and has the bestchance of hitting back.Write a program to simulate the duel using this strategy. Your program should userandom numbers and the probabilities given in the problem to determine whether ashooter hits his target. You will likely want to create multiple functions to complete theproblem. My solution had only one function to simulate the duels and it passed in theodds and the three guys as pass-by-reference parameters. Once you can simulate a duel,add a loop to your program that simulates 10,000 duels. Count the number of times thateach contestant wins and print the probability of winning for each contestant (e.g., forAaron your might output Aaron won 3612/10000 duels or 36.12%).Strategy 2: An alternative strategy for Araon is to intentionally miss on his first shot.Write a function to simulate Strategy 2. Your program will determine which strategy isbetter for Aaron.2Note: You must provide the following user interface. Red text might be different fordifferent runs due to the random number. You do not need to display text in red. Pleasereplace Li with your name.*** Welcome to Lis Duel Simulator ***Unit Testing 1: Function at_least_two_alive()Case 1: Aaron alive, Bob alive, Charlie aliveCase passed Case 2: Aaron dead, Bob alive, Charlie aliveCase passed Case 3: Aaron alive, Bob dead, Charlie aliveCase passed Case 4: Aaron alive, Bob alive, Charlie deadCase passed Case 5: Aaron dead, Bob dead, Charlie aliveCase passed Case 6: Aaron dead, Bob alive, Charlie deadCase passed Case 7: Aaron alive, Bob dead, Charlie deadCase passed Case 8: Aaron dead, Bob dead, Charlie deadCase passed Press any key to continueUnit Testing 2: Function Aaron_shoots1(Bob_alive, Charlie_alive)Case 1: Bob alive, Charlie aliveAaron is shooting at CharlieAaron misses.Case 2: Bob dead, Charlie aliveAaron is shooting at CharlieCharlie is dead.Case 3: Bob alive, Charlie deadAaron is shooting at BobAaron misses.Press any key to continueUnit Testing 3: Function Bob_shoots(Aaron_alive, Charlie_alive)Case 1: Aaron alive, Charlie aliveBob is shooting at CharlieCharlie is dead.Case 2: Aaron dead, Charlie aliveAaron is shooting at CharlieBob missedCase 3: Aaron alive, Charlie deadBob is shooting at AaronAaron is dead.Press any key to continue3Unit Testing 4: Function Charlie_shoots(Aaron_alive, Charlie_alive)Case 1: Aaron alive, Bob aliveCharlie is shooting at BobBob is dead.Case 2: Aaron dead, Bob aliveCharlie is shooting at BobBob is deadCase 3: Aaron alive, Bob deadCharlie is shooting at AaronAaron is dead.Press any key to continueUnit Testing 5: Function Aaron_shoots2(Bob_alive, Charlie_alive)Case 1: Bob alive, Charlie aliveAaron intentionally misses his first shotBoth Bob and Charlie are alive.Case 2: Bob dead, Charlie aliveAaron is shooting at CharlieCharlie is dead.Case 3: Bob alive, Charlie deadAaron is shooting at BobAaron misses.Press any key to continueReady to test strategy 1 (run 10000 times):Press any key to continueAaron won 3612/10000 duels or 36.12%Bob won 4137/10000 duels or 41.37%Charlie won 2251/10000 duels or 22.51%Ready to test strategy 2 (run 10000 times):Press any key to continueAaron won 4099/10000 duels or 40.99%Bob won 2552/10000 duels or 25.52%Charlie won 3349/10000 duels or 33.49%Strategy 2 is better than strategy 1.4Requirements:1. You must following the above user interface to implement your program.2. You must implement the following functions:1) bool at_least_two_alive(bool A_alive, bool B_alive,C_alive)/* Input: A_alive indicates whether Aaron is alive *//* B_alive indicates whether Bob is alive *//* C_alive indicates whether Charlie is alive *//* Return: true if at least two are alive *//* otherwise return false */2) void Aaron_shoots1(bool& B_alive, bool& C_alive)/* Strategy 1: Use call by reference* Input: B_alive indicates whether Bob alive or dead* C_alive indicates whether Charlie is alive or dead* Return: Change B_alive into false if Bob is killed.* Change C_alive into false if Charlie is killed.*/3) void Bob_shoots(bool& A_alive, bool& C_alive)/* Call by reference* Input: A_alive indicates if Aaron is alive or dead* C_alive indicates whether Charlie is alive or dead* Return: Change A_alive into false if Aaron is killed.* Change C_alive into false if Charlie is killed.*/4) void Charlie_shoots(bool& A_alive, bool& B_alive)/* Call by reference* Input: A_alive indicates if Aaron is alive or dead* B_alive indicates whether Bob is alive or dead* Return: Change A_alive into false if Aaron is killed.* Change B_alive into false if Bob is killed.*/5) void Aaron_shoots2(bool& B_alive, bool& C_alive)/* Strategy 2: Use call by reference* Input: B_alive indicates whether Bob alive or dead* C_alive indicates whether Charlie is alive or dead* Return: Change B_alive into false if Bob is killed.* Change C_alive into false if Charlie is killed.*/3. You must implement five unit test drivers (five functions) to test the above fivefunctions. (see also the user interface on pages 2 and 3)4. You must use assert in your test driver.5. You must define four constants in your implementation. For example, the totalnumber (i.e., 10,000) of runs can be defined as a constan
COMP2710
[Solved] COMP2710 Project 2- the greatest puzzle-solver of all time
$25
File Name: COMP2710_Project_2-_the_greatest_puzzle-solver_of_all_time.zip
File Size: 546.36 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.