The Pig Dice Game Party MATLAB program should have the following functions: 1. 2
ID: 3752521 • Letter: T
Question
The Pig Dice Game Party MATLAB program should have the following functions: 1. 2. 3. Ask the game host to input how many human players will play Pig. Ask the game host to input how many computer players will join the competition. Sum up the total number of human and computer players and use player 1, player 2, player 3, .. to represent each human and computer player. We will let the human players to play before the computer players 4. Welcome the players and briefly explain how to play the game when the program starts 5. 6. Track and print the player number in the command window to indicate which 7. If this is a human player, the program should ask the player to decide if the player 8. For computer players, the program should automatically decide to roll or to pass Track and print the current turn number in the command window player should play. For example, "Player 3, it is your turn to play! wants to roll or pass the turn. using the following winning strategy and print the player's decision on screen. a. If one of the opponents has a game score that is 96 or higher and the computer player game score is 76 or higher, keep rolling until the computer player accumulate enough points to sum to 100, and then pass. b. Else if the computer player's game score is less than or equal to 80 points, keep rolling until the computer player accumulate 20 points and then pass. Else, keep rolling until the computer player accumulate enough points to sum to 100, and then pass c. 9. If the human or computer player wants to roll the dice, generate one random integer between 1 and 6 to represent the face value of the dice and print the dice value in the command window a. If the value of the dice is equivalent to 1, set the player's turn score to 0, print a message to tell the player's turn is over with 0 score from this turn, and automatically let the next player playExplanation / Answer
clc
clear
home
load Dice
playerss=input('How many playerss would you like?: ');
playerr=1;
roll=[2 2];
roll_again=1;
%while playerr wants to play again
while roll_again==1
if playerss > 7
fprintf('Pick a value between 2-7 ')
playerss=input('How many playerss would you like?: ');
else
end
%empty vector for game types of playerss
tot_val=[];
person_name={};
for pr=1:playerss;
plr2=num2str(pr);
tst=strcat('What mode is playerr ', plr2,' in?');
val=menu(tst,' Player','Computer');
if val == 1
person_name(pr)=cellstr(input('What is your name?','s'));
else
person_name(pr)=cellstr('computer');
end
tot_val=[tot_val,val];
end
score = zeros(1,playerss);
x=1;
roll_again=1;
compchoice=1;
while all(score<100)
for x=1:playerss;
if tot_val(x) == 1
while roll_again ==1
figure_1=figure('WindowStyle','docked');
roll_dic = randi([1 6],[1 2]);
figure_1=figure('WindowStyle','docked');
close;
imshow([Dice{roll_dic}],'InitialMagnification','fit');
if roll_dic(1)==1 || roll_dic(2)==1
fprintf('You rolled a 1, you lose points. Next playerss turn.')
score(x)=score(x)-sum(roll_dic)
roll_again=2
elseif roll_dic(1)==roll_dic(2)
fprintf('You rolled doubles! You got 2x the points!')
score(x)=score(x)+2*sum(roll_dic)
roll_again=menu('Would you like to roll_dic roll_again?','Yes','No')
else
score(x)=score(x)+sum(roll_dic)
roll_again=menu('Would you like to roll_dic roll_again?','Yes','No');
end
end
else tot_val(x) ==2
while compchoice == 1
figure_1=figure('WindowStyle','docked');
roll_dic = randi([1 6],[1 2]);
figure_1=figure('WindowStyle','docked');
close;
imshow([Dice{roll_dic}],'InitialMagnification','fit')
if roll_dic(1)==1 || roll_dic(2)==1
fprintf('Computer %i rolled a 1, they lose points. Next playerss turn.',x)
score(x)=score(x)-sum(roll_dic)
compchoice==2
elseif roll_dic(1)==roll_dic(2)
fprintf('Computer %i rolled doubles! They got 2x the points!',x)
score(x)=score(x)+2*sum(roll_dic)
compchoice=randi(1,2)
else
score(x)=score(x)+sum(roll_dic)
compchoice=randsample(2,1)
end
end
end
end
end
winnerIdx = find(score>=100,1)
fprintf('Player', winnerIdx,'has won!')
roll_again=menu('Would you like to play roll_again?','Yes','No')
end
fprintf('Thanks for playing!')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.