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

Topics: Writing a “classic” Program in MATLAB Game Specification: Write a progra

ID: 3682397 • Letter: T

Question

Topics: Writing a “classic” Program in MATLAB

Game Specification: Write a program that allows a single Player (the user) to play a simple four dice game of chance against "The Odds".

There is a single player, with four six sided die.

The sides of each die are labeled with the numbers from 1 to 6, we will call this the value of the die.

A game is made up of rounds, a single round is played as such:

The player rolls their four dice – you may use randi() The dice are displayed, in some reasonable format. A determination is made as to whether or not the player won the round, this determination is made via the following rules:

A Quad is when all the dice have the same number on their top faces. If the player has any Quad then they win the round.

A Triple is when exactly three of the dice have the same number on their top faces. If the player has any Triple then they win the round.

A Straight is when the numbers on the three dice faces can be arranged to form a consecutive sequence like 1 2 3 4 or 3 4 5 6 If the player has any Straight then they win the round.

A Two-Pair is when exactly two dice have the number n1 on their top faces, exactly two dice have the number n2 on their top faces, and n1 is not equal to n2. If the player has any Two-Pair then they win the round.

A Pair is when (exactly) two dice have the same number on their top faces. If the player has any Pair then they neither win nor lose the round.

A Junker is then anything that is not listed above. If the player has any Junker then they lose the round.

The result of the round (with respect to the Player) is reported. The player is asked if they wish to play another round. Once the player indicates that they do not wish to play another round: Before exiting, the program displays a short report stating how many rounds were played, of those - how many were won and how many were lost.

Outline: Create a MATLAB Script .m file Write the necessary MATLAB commands to meet the game specification given above

You will need to use the = randi( [1, 6], 1 );

Sample Run(s): Welcome to Computer Dice ------------------------------------- You will first roll your dice Next the outcome of your roll will be determined: any Quad and you Win any Triple and you Win any Straight and you Win any Two-Pair and you Win any Pair and you just roll again anything else and you Lose -------------------------------------

Player ---------- 1 4 5 6 Junker - Sorry, you lose

! Do you wish to play again [y, n] : 6

Do you wish to play again [y, n] : sure Do you wish to play again [y, n] : y

Player ---------- 1 2 5 5

Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 3 3 4 5 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 1 3 6 6 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 3 3 3 4 Trip - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 2 5 6 6 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 2 2 2 3 Trip - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 3 3 3 6 Trip - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 1 3 3 6 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 1 2 4 5 Junker - Sorry, you lose! Do you wish to play again [y, n] : y

Player ---------- 1 2 4 5 Junker - Sorry, you lose! Do you wish to play again [y, n] : y

Player ---------- 1 4 4 6 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 1 2 3 4 Straight - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 1 3 3 5 Pair - Its a push! Do you wish to play again [y, n] : y

Player ---------- 2 3 4 5 Straight - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 2 2 2 6 Trip - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 3 4 4 4 Trip - Congrats, you win! Do you wish to play again [y, n] : y

Player ---------- 1 2 4 5 Junker - Sorry, you lose! Do you wish to play again [y, n] : y

Player ---------- 3 3 5 5 Two-Pair - Congrats, you win! Do you wish to play again [y, n] : n

Computer Dice Results --------------------- You played 19 rounds Rounds won :8 Rounds lost :4 ---------------------

Explanation / Answer

// Check if a Straight
function randi = randiStraight(n1, n2, n3)
if(n2=n1+1)
if(n3=n2+1)
  return true;
end
else
if(n1=n2+1)
if(n3=n1+1)
  return true;
end
else
if(n3=n1+1)
if(n1=n2+1)
  return true;
end
else return false;
end

// Check if a Triple
function randi = randiTriple(n1, n2, n3)
if(n3=n2)
if(n3=n1)
  if(n2=n1)
  return true;
  end
end
else return false;
end

// Check if a Pair
function randi = randiPair(n1, n2, n3)
if(n1=n2)
return true;
end
else if (n2=n3)
return true;
end
else if (n1=n3)
return true;
end
else return false;
end

// Now to check , use like this
<var> x= randi([1,6],1)
<var> y= randi([1,6],1)
<var> z= randi([1,6],1)

disp("Welcome to Computer Dice

-------------------------------------

You will first roll your dice"
)

disp(" Player

--------")

disp(x y z)

if(randiTriple(x,y,z))
disp("Congrats, you win!")
else if(randiStraight(x,y,z))
disp("Congrats, you win!")
else if (randiPair(x,y,z))
disp("Its a push!")
else disp("Sorry, you lose!")