Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB ONLY********* In this project you will create a program (script) that sim

ID: 3717978 • Letter: M

Question

MATLAB ONLY*********

In this project you will create a program (script) that simulates a game of Darts. The program should display what each player hit with their darts each round and the current score until the game is completed.

Background:

A standard dart board has several scoring areas as displayed in the figure below. There are many types of games that can be played with a dartboard. You need to simulate one of the games that requires at least two players. Details about different dart games and how they are scored are available here: http://www.darting.com/Darts-Rules/. Different games have very different scoring, it is up to you to decide which game you want to implement. All games will be graded equally based on how accurately they simulate a game,

If you are completely unfamiliar with the game of darts, there are several video’s available on YouTube by

searching “How to Play Darts”.

using the rules on the above website. NOTE: You will not get any points for the

project if you simulate your own version of darts, you MUST choose a game from the website listed.

Program Structure:

You will be provided with two 512x512 matrices that represent a dart board. The first includes the value for each wedge around the board, the value in the matrix is the wedge value (or zero if you are off the board). For instance, if you select a number in the upper middle of the board (i.e. location 100,256) the resulting value will be 20. The second matrix indicates where the rings are for single, double or triple. In this case, each location has a value of 1 for single rings, 2 for double ring, 3 for triple ring, and zero if you are off the board.

You should use a random number generator to select one place on the dartboard, by row and column, which represents a dart throw. This location will be the same for both data matrices. Your code must display (i.e. triple – 14) where each dart hits (this can be done with text, it does not require a visual representation) for each round. Then display the current score for all players.

This process should continue until the game is successfully completed. Since you are using random number generators and not incorporating any skill into the throws the game simulation will likely take many rounds. When developing your code it might work better to start with small goals before trying to let the simulation run for an entire game.

MATLAB ONLY*********

Explanation / Answer

SAVE THE FOLLOWING CODE IN MATLAB TO GET THE RESULTS.

function [Values,Valid,Wires,Outside]=dartboard(scale,out,Rw)

% example:

% % Dartboard with high resolution, 10mm frame, 2mm wires

% Points = dartboard(0.1,10,2);

% image(Points); colormap hot;

if nargin==0

scale=1; % resolution mm per pixel

end

if nargin<=1

out=1; % frame mm

end

if nargin<=2

Rw=0.6; % wire diameter mm

end

vallist=[20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5];

% DIMENSIONS in mm

out=out/scale;% outside frame

Rf=8/scale;% width of rings

RT1=107/scale;

RT2=RT1-Rf;% tripple ring

RD1=170/scale;

RD2=RD1-Rf; % double ring

RB=31.8/2/scale; % bull

RE=12.7/2/scale; % bulls eye

Rw=Rw/scale; % wire diameter

N=(2*RD1+2*out)+1;

Nmid=round(N/2);

[x,y]=meshgrid((1:N)-Nmid,(1:N)-Nmid);

R=sqrt(x.^2+y.^2);

ag=atan2(x,y)/2/pi*360+180;

agm=mod(ag-9,18);

ag2=ag-9;ag2(ag2<0)=ag2(ag2<0)+360;

idx=20-floor((ag2)/18);

da=asin(Rw/2./R)/2/pi*360;

MF=~((agm(18-da))); % valid radials

ME=(R<=(RE-Rw/2)); % eye

MB=(R>=(RE+Rw/2))&(R<=(RB-Rw/2)); %bull

MS1=((R>=(RB+Rw/2))&(R<=(RT2-Rw/2)))&MF; % single

MT =((R>=(RT2+Rw/2))&(R<=(RT1-Rw/2)))&MF; % tripple

MS2=((R>=(RT1+Rw/2))&(R<=(RD2-Rw/2)))&MF; % single

MD = ((R >= (RD2 + Rw/2)) & (R <= (RD1 - Rw/2))) & MF; % double

Valid = ME | MB | MS1 | MT | MS2 | MD; % all valid

Wires = (R <= (RD1 + Rw/2)) & ~Valid; % all wires

Values = ME * 50 +...

MB *25 +...

(((MS1 | MS2) * 1 + ...

MT * 3 + ...

MD 2) . vallist(idx)); % values

Outside = (R > (RD1 + Rw/2)); % all outside

assert(sum(Valid()+sum(Wires()+sum(Outside() == N*N,'overlapping maps')

%%

% figure;image(Values),colormap hot

% figure;image(Valid),colormap lines

% figure;image(Wires),colormap lines

% figure;image(Outside),colormap lines