The Pig Dice Game Party MATLAB program should have the following functions 1. 2.
ID: 3753483 • 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. Wekcome the players and briefly explain how to play the game when the program starts. Track and print the current turn number in the command window. 4. 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 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. 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 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. a. b. 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. 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 tum is over with 0 score from this turn and automatically let the next player play. a. b. For the rest of other dice values (else), add the dice value to the player's turn score and print the turn score for the player in the command window. Print the total game score for this player in the command window. 10. Else if the player decides to pass the pig, sum the player's turn score to the player's total game score, print the player number, print the tun score, print the total game score in the command window, and automatically advance to the next ayer 11. Track all the player scores. The game should keep asking the players to take turn to roll or pass, automatically advance to the next turn when all the players have played, while all of the player's total game score is less than 100 points. 12. When one of the player's total game score reaches 100 points or above, the game should automatically end 13. Automatically pick the winner of the game. The program should be able to identify which player won the game, the winners game score, congratulate the winner, and show the party how many turns it took the winner to win the game. 14. An intelligent program should not allow any player to cheat- the dice value should be random. The game score and turn score should be correct for every player. If a player's turn is over, the program should not let the same player to roll the dice again until the game advance to the next turn for all the players. 5. A resilient program should not crash when the player press other keys on the keyboard e. .a", .1', etc ). 16. A resilient propram should not crash when the game host input a negative number of players, a floating point value, or 0 player wants to play the game (i.e. 0,-1,2.5 etc). 17. The program n treat a negative number of human or computer players like 0 player 18. If the game host input 0 human and 0 computer player wants to play, the game should endExplanation / Answer
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.