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

Write a MATLAB program to simulate the Tenzi game automatically that can: Use te

ID: 3886832 • Letter: W

Question

Write a MATLAB program to simulate the Tenzi game automatically that can: Use ten (10) 6-sided dice to automatically play the Tenzi game for one player. Generate ten (10) random integers between 1 and 6 to represent the face value of rolling ten dice. Print the ten (10) dice values on screen. Ask the player to look at the first roll and input the number to roll all 10 dice to be. Set aside the dice rolled with the number by counting and printing "the number of dice on the side" in the command window. Print the face values of the dice that are set aside on screen. Roll the remaining dice by generating as many random integers between 1 and 6 as the dice that are not set aside. Print the remaining dice rolled values on screen. Set aside the dice with the desired value (like in step 5) and print "the total number of dice on the side" in the command window. Print the face values of the dice that are set aside on screen. Keep rolling the remaining dice until all 10 dice show the same number. Print "TENZI" on screen.

Explanation / Answer

match = 0;
val = [];
% generate a vector with random 10 numbers
for i=1:10
val(i) = (randi(6));
end
% ask user input
prompt = "Enter number:";
x = input(prompt);
while(match<10)
disp(val);
t1 = length(val);
val = val(val~=x);
t2 = length(val);
% get absolute value of number of elements deleted and add it to match
if(t1<t2)
match = match + t2 - t1;
elseif(t1>t2)
match = match + t1 - t2;
end
fprintf("The total number of dice on the side :%d ",match);
% roll remaining dice
for i=1:t2
val(i) = (randi(6));
end
end
disp('Tenzi');

% --------------- End of Program -------------------------

% sample output

Enter number: 5

5 6 6 2 6 5 3 2 6 4
The total number of dice on the side :2
4 1 2 2 3 2 5 5
The total number of dice on the side :4
5 5 6 5 6 2
The total number of dice on the side :7
2 3 3
The total number of dice on the side :7
1 4 4
The total number of dice on the side :7
4 4 6
The total number of dice on the side :7
5 5 6
The total number of dice on the side :9
3
The total number of dice on the side :9
3
The total number of dice on the side :9
1
The total number of dice on the side :9
2
The total number of dice on the side :9
2
The total number of dice on the side :9
6
The total number of dice on the side :9
4
The total number of dice on the side :9
1
The total number of dice on the side :9
6
The total number of dice on the side :9
6
The total number of dice on the side :9
1
The total number of dice on the side :9
1
The total number of dice on the side :9
5
The total number of dice on the side :10
Tenzi

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote