Write a program that allows a single Player the user to play
Write a program that allows a single Player (the user) to play a simple three dice game of chance against \"The Odds\".
There is a single player, with three (12 sided) dice.
The sides of each die are labeled with the numbers from 1 to 12, 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 three 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 Triple is when all 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 or 3 4 5 If the player has any Straight then they win the round.
A Pair is when any (exactly) two dice have the same number on their top faces:
If the player\'s Pair is 7\'s or higher, then they win the round.
If the player\'s Pair is 6 \'s or lower, then they lose the round.
A Junker is then anything that is not a Triple, a Straight or a Pair. 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
Make sure to test your “program” when it is done
You really need to run your program a number of time to do this thoroughly
Notes(s):
You will need to use the
= randi( [1, 12], 1 );
to assign a random die roll value.
The last answer to this lab was wrong, it had many errors in multiple lines.
Solution
t = 0;
lose = 0;
in = 1;
while eq(in,1)
t = t+1;
% roll three dies
x = randi( [1, 12], 1 );
y = randi( [1, 12], 1 );
z = randi( [1, 12], 1 );
l = [x,y,z];
l = sort(l);
disp(l);
if(eq(x,y) && eq(x,z) && eq(y,z))
disp(\'You Won!\');
elseif(eq(l(1)+1,l(2)) && eq(l(2)+1,l(3)))
disp(\'You Won!\');
elseif(ge(l(1)+l(2),7) || ge(l(1)+l(3),7) || ge(l(2)+l(3),7))
disp(\'You Won!\');
else
lose = lose+1;
disp(\'You Lose!\')
end
in = input(\"Press 1 to play again:\");
end
disp(\"Total Games Palyed:\");
disp(t);
disp(\"Total Games won:\");
disp(t-lose);
disp(\"Total Games Lost:\");
disp(lose);
% sample output
%You Won!
%Press 1 to play again:1
%You Won!
%Press 1 to play again:1
%You Won!
%Press 1 to play again:0
%Total Games Palyed:
%3
%Total Games won:
%3
%Total Games Lost:
%0

