Question: MATLAB help please! function [ points ] = DartGame( num_darts ) theta = linspace(0,2*pi); % Plotting the circles for your dart board xbull = 1*cos(theta);

MATLAB help please!

function [ points ] = DartGame( num_darts )

theta = linspace(0,2*pi);

% Plotting the circles for your dart board xbull = 1*cos(theta); ybull = 1*sin(theta); % Creating the plot figure plot(xbull,ybull,'k'); % don't erase the previous figure hold on

xred = 2*cos(theta); yred = 2*sin(theta); plot(xred,yred,'r');

xgreen = 4*cos(theta); ygreen = 4*sin(theta); plot(xgreen,ygreen,'g');

xpurple = 6*cos(theta); ypurple = 6*sin(theta); plot(xpurple,ypurple,'b');

points = 0; for i = 1: num_darts

x_cor = -6+rand*12; y_cor = -6+rand*12;

% Calculating the radius of your throw dist = sqrt(x_cor^2 + y_cor^2);

% Calculating where you land on the board if dist <= 1 fprintf('Bullseye. You get 50 pts. ') points = points + 50; elseif dist <= 2 fprintf('Red. You get 30 pts. ') points = points + 30; elseif dist <= 4 fprintf('Green. You get 15 pts. ') points = points + 15; elseif dist <= 6 fprintf('Blue. You get 5 pts. ') points = points + 5; else fprintf('Missed the board. Do not quit your day job. ') end

% Plotting the dart throw onto the dart board plot(x_cor,y_cor,'x');

end

You are to modify your DartsGame function to implement the following changes:

a) not only will you have a dart throw on each turn, the COMPUTER gets to randomly generate a dart throw too. You will need to plot the computer;s dart throw as well as yours (plot this in black but with a small circle 'o'(

b) keep track of the computers points separately from your points.

c) at the end of each round, determine who wins... you or the computer, and print a message to the screen telling WHICH ROUND it is and who won.

d) after all of the rounds have been played, you have your array of your scores for each round. In addition to returning this array, you should calculate your AVERAGE SCORE per round (not using the build in SUM function in MATLAB, but using a loop) and print out your average score in an appropriate sentence.

Please come up with the MATLAB function for throwing darts by modifying the following MATLAB function:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!