Question

In: Computer Science

Stuck in the mud is a popular dice game in UK. The game uses five (5)...

Stuck in the mud is a popular dice game in UK. The game uses five (5) 6-sided dice to play. The players play in turns.

Choose one player to start the game. The player will roll all five (5) dice. If the player rolled any 2s or 5s, the player does not score any points for this throw. The player can only score on a roll which does not include the number 2 and 5. Any dice with a 2 or a 5 becomes stuck in the mud. If this throw does not contain any 2s or 5s, the score is incremented by the sum of the dice values.

The player needs to set aside any 2s and 5s and throw the remaining dice. Again, if any 2s or 5s are rolled, the score will not be incremented for this throw. Throws without 2s and 5s are added to the previous total score.

Continue in this way until all the dice are stuck. Save the score and pass the dice to the next player.

Players can agree a total number of rounds to play in advance. Total up the score. The player with the highest score wins the game. The following link contains the detail game description: https://www.activityvillage.co.uk/stuck-in-the-mud.

Write a MATLAB program to simulate the Stuck in the Mud game with additional features that can:

Use five (5) 6-sided dice to automatically play the Stuck in the Mud game against a player.

Greet the player when the game starts.

Let the player to choose the number of rounds to play. Take care of the user input to ensure the program will not crash with inputs like 0, 1.2, -1, 999, and so on...

The program should not play if the user enters a 0 or any negative value.

The program should accurately play the number of rounds specified by the user. The player and the computer play in turns for each round.

The program can always pick one side to start the game first, either the player side or the computer side. Randomly pick a side to start the rotation is optional.

Print the current round number clearly in the command window.

If the player side starts first, the program will automatically roll all five (5) dice for the player. If the player rolled any 2s or 5s, the player does not score any points for this throw. The player can only score on a roll which does not include the number 2 and 5. Any dice with a 2 or a 5 becomes stuck in the mud. If this throw does not contain any 2s or 5s, the score is incremented by the sum of the dice values. The player needs to set aside any 2s and 5s and throw the remaining dice. Again, if any 2s or 5s are rolled, the score will not be incremented for this throw. Throws without 2s and 5s are added to the previous total score. Continue in this way until all the dice are stuck.

The dice rolled for the player, the stuck dice, and the scores during the process should clearly be printed in the command window.

The program then automatically roll all five (5) dice for the computer. Follow the game rules until all five (5) dice are stuck.

The dice rolled for the computer, the stuck dice, and the scores during the process should also be clearly printed in the command window.

Accurately track the total scores for the player and the computer.

After all the rounds have been played, select a winner based on the highest total score. It is also possible that the game ends in a tie.

Add voice to the game to report the details of the game for the player. o Pre-recorded computer voices, computerVoices.zip, can be downloaded from moodle.

o The following websites can convert any text into voices with downloadable mp3 files. § www.fromtexttospeech.com

§ www.text2speech.org

o If you have a mic, you can also record your own voice using the Windows Sound Recorder.

o MATLAB can play any WMA, MP3, MPEG-4 AAC, WAV, FLAC audio files.

[y,Fs] = audioread('fileName.mp3'); % read sound file

sound(y,Fs); % play sound file

o Additional sound effects are welcome.

Add voice to greet the player.

Add voice to ask the player to enter the number of rounds to play.

Add voice to announce the current round number (i.e., round 1, round 2, and so on…).

Add voice to announce the current turn (i.e. the player is rolling or the computer is rolling).

Add voice to announce the current roll number (i.e. roll 1, roll 2, and so on…).

Add voice to announce each dice rolled.

Add voice to announce the sum of the score for the current turn after each throw.

Add voice to announce the number of dice stuck after each throw.

After one side played, add voice to announce the current total score for the side. For example, 35 points can be announced as three-five.

After all the rounds are played, add voice to announce the winner or tie.

Add pause as needed between sentences to ensure one sentence is finished before the next sentence starts.

Use at least one user-defined function in the program to reduce code repetition.

The finished program can look like the following example. Extra components are always welcome.

Games do not make you violent, lag does.

Got lag? Kill the lag with a dice game. (Play a voice greeting.)

(Play a voice to request the user input.)

Enter the number of rounds to play: 2

ROUND 1!!! (Announce round #1.)

The player starts first: (Announce the player’s turn.)

   ROLL 1 (Announce roll #1.)

Rolling: 5 1 4 5 6 (Announce rolling 5-1-4-5-6.)

Stuck in the mud: 5 5

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 2 (Announce the number of dice stuck: 2)

   ROLL 2 (Announce roll #2.)

Rolling: 2 2 2 (Announce rolling 2-2-2.)

Stuck in the mud: 5 2 2 5 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The player scores: 0 (Announce the player score: 0)

The Player Total Scored: 0 (Announce the player total score: 0)

The computer goes next: (Announce the computer’s turn.)

    ROLL 1 (Announce roll #1.)

Rolling: 2 4 3 5 4 (Announce rolling 2-4-3-5-4.)

Stuck in the mud: 2 5

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 2 (Announce the number of dice stuck: 2)

ROLL 2 (Announce roll #2.)

Rolling: 1 2 4 (Announce rolling 1-2-4.)

Stuck in the mud: 2 2 5

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 3 (Announce the number of dice stuck: 3)

   ROLL 3 (Announce roll #3.)

Rolling: 4 2 (Announce rolling 4-2.)

Stuck in the mud: 2 2 5 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 4 (Announce roll #4.)

Rolling: 5 (Announce rolling 5.)

Stuck in the mud: 2 5 2 5 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The computer scores: 0 (Announce the computer score: 0)

The Computer total scored: 0 (Announce the computer total score: 0)

   ROUND 2!!! (Announce round #2.)

The player starts first: (Announce the player’s turn.)

   ROLL 1 (Announce roll #1.)

Rolling: 2 4 4 2 5 (Announce rolling 2-4-4-2-5.)

Stuck in the mud: 2 2 5

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 3 (Announce the number of dice stuck: 3)

   ROLL 2 (Announce roll #2.)

Rolling: 2 2 (Announce rolling 2-2.)

Stuck in the mud: 2 2 2 2 5

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The player scores: 0 (Announce the player score: 0)

The Player Total Scored: 0 (Announce the computer score: 0)

The computer goes next: (Announce the computer’s turn.)

   ROLL 1 (Announce roll #1.)

Rolling: 4 4 1 1 1 (Announce rolling 4-4-1-1-1.)

Stuck in the mud:

   Game score: 11 (Announce the score: 1-1)

   Number of dice stuck: 0 (Announce the number of dice stuck: 0)

   ROLL 2 (Announce roll #2.)

Rolling: 1 4 5 6 4 (Announce rolling 1-4-5-6-4.)

Stuck in the mud: 5

   Game score: 11 (Announce the score: 1-1)

   Number of dice stuck: 1 (Announce the number of dice stuck: 1)

   ROLL 3 (Announce roll #3.)

Rolling: 6 5 1 1 (Announce rolling 6-5-1-1.)

Stuck in the mud: 5 5

   Game score: 11 (Announce the score: 1-1)

   Number of dice stuck: 2 (Announce the number of dice stuck: 2)

   ROLL 4 (Announce roll #4.)

Rolling: 2 5 1 (Announce rolling 2-5-1.)

Stuck in the mud: 2 5 5 5

   Game score: 11 (Announce the score: 1-1)

   Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 5 (Announce roll #5.)

Rolling: 5 (Announce rolling 5.)

Stuck in the mud: 2 5 5 5 5

   Game score: 11 (Announce the score: 1-1)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The computer scores: 11 (Announce the computer score: 1-1)

The Computer total scored: 11 (Announce the computer total score: 1-1)

The computer wins! (Announce the computer wins.)

>>

The program should end when the player wants to play 0 round.

Games do not make you violent, lag does.

Got lag? Kill the lag with a dice game. (Play a voice greeting.)

(Play a voice to request the user input.)

Enter the number of rounds to play: 0

The game ends with a tie (Announce the game ends in a tie.)

>>

The program should be able to handle a negative input.

Games do not make you violent, lag does.

Got lag? Kill the lag with a dice game. (Play a voice greeting.)

(Play a voice to request the user input.)

Enter the number of rounds to play: -1

The game ends with a tie (Announce the game ends with a tie.)

>>

The program should be able to handle a floating point input without crashing.

(The following example takes the floor value of 1.2 and only runs 1 round. )

Games do not make you violent, lag does.

Got lag? Kill the lag with a dice game. (Play a voice greeting.)

(Play a voice to request the user input.)

Enter the number of rounds to play: 1.2

ROUND 1!!! (Announce round #1.)

The player starts first: (Announce the player’s turn.)

   ROLL 1 (Announce roll #1.)

Rolling: 3 6 2 2 6 (Announce rolling 3-6-2-2-6.)

Stuck in the mud: 2 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 2 (Announce the number of dice stuck: 0)

   ROLL 2 (Announce roll #2.)

Rolling: 4 4 4 (Announce rolling 4-4-4.)

Stuck in the mud: 2 2

   Game score: 12 (Announce the score: 1-2)

   Number of dice stuck: 2 (Announce the number of dice stuck: 2)

   ROLL 3 (Announce roll #3.)

Rolling: 3 1 5 (Announce rolling 3-1-5.)

Stuck in the mud: 2 2 5

   Game score: 12 (Announce the score: 1-2)

   Number of dice stuck: 3 (Announce the number of dice stuck: 3)

   ROLL 4 (Announce roll #4.)

Rolling: 6 5 (Announce rolling 6-5.)

Stuck in the mud: 5 2 2 5

   Game score: 12 (Announce the score: 1-2)

   Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 5 (Announce roll #5.)

Rolling: 1 (Announce rolling 1.)

Stuck in the mud: 5 2 2 5

   Game score: 13 (Announce the score: 1-3)

    Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 6 (Announce roll #6.)

Rolling: 1 (Announce rolling 1.)

Stuck in the mud: 5 2 2 5

   Game score: 14 (Announce the score: 1-4)

Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 7 (Announce roll #7)

Rolling: 5 (Announce rolling 5.)

Stuck in the mud: 5 5 2 2 5

   Game score: 14 (Announce the score: 1-4)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The player scores: 14 (Announce the player score: 1-4)

The Player Total Scored: 14 (Announce the player total score: 1-4)

The computer goes next: (Announce the computer’s turn.)

   ROLL 1 (Announce roll #1.)

Rolling: 6 5 6 4 2 (Announce rolling 6-5-6-4-2.)

Stuck in the mud: 5 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 2 (Announce the number of dice stuck: 2)

   ROLL 2 (Announce roll #2.)

Rolling: 2 4 5 (Announce rolling 2-4-5.)

Stuck in the mud: 2 5 5 2

   Game score: 0 (Announce the score: 0)

   Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 3 (Announce roll #3.)

Rolling: 4 (Announce rolling 4.

Stuck in the mud: 2 5 5 2

   Game score: 4 (Announce the score: 4)

   Number of dice stuck: 4 (Announce the number of dice stuck: 4)

   ROLL 4 (Announce roll #4.)

Rolling: 2 (Announce rolling 2.)

Stuck in the mud: 2 5 2 5 2

   Game score: 4 (Announce the score: 4)

   Number of dice stuck: 5 (Announce the number of dice stuck: 5)

The computer scores: 4 (Announce the computer score: 4)

The Computer total scored: 4 (Announce the computer total score: 4)

The player wins! (Announce the player wins.)

>>

Solutions

Expert Solution

% matlab code

disp('Games do not make you violent, lag does. Got lag? Kill the lag with a dice game.');
disp('Enter the number of rounds to play: ');
rounds = input('');

if(rounds <= 0)
disp('The game ends with a tie');
quit
end

player_total_score=0;
comp_total_score=0;

for i=1:rounds
fprintf('ROUND %d !!!\n',i);
n = 5;
roll = 1;
mud = [];
player_score = 0;
while n > 0
fprintf('\nROLL %d\n',roll);

roll = roll+1;
  
r = randi([1 6],1,n);
  
fprintf('Rolling: '),disp(r);

  
count2 = sum(r == 2);
count5 = sum(r == 5);
if (count2 > 0) || (count5 >0)
mud = [ mud , repmat(2,1,count2) repmat(5,1,count5)] ;
n =n - count2-count5;
else
player_score = player_score+ sum(r);
end
fprintf('Stuck in the mud :');disp(mud);
fprintf('game score: %d\n',player_score);

fprintf('Number of dice stuck: %d\n',size(mud,2));

end
player_total_score = player_total_score+ player_score;

fprintf('The player scores: %d\n',player_score);

  
fprintf('The Player Total scored: %d\n',player_total_score);

%computer turn
disp('\n\nThe computer goes next ');
comp_score =0;
n = 5;
roll = 1;
mud = [];
while n > 0
fprintf('\nROLL %d\n',roll);

roll = roll+1;
  
r = randi([1 6],1,n);
  
fprintf('Rolling: '),disp(r);

  
count2 = sum(r == 2);
count5 = sum(r == 5);
if (count2 > 0) || (count5 >0)
mud = [ mud , repmat(2,1,count2) repmat(5,1,count5)] ;
n =n - count2-count5;
else
player_score = player_score+ sum(r);
end
fprintf('Stuck in the mud :');disp(mud);
fprintf('game score: %d\n',comp_score);

fprintf('Number of dice stuck: %d\n',size(mud,2));

end
comp_total_score = comp_total_score+ comp_score;
  
fprintf('The Computer scores: %d\n',comp_score);

  
fprintf('The Computer Total scored: %d\n',comp_total_score);
end
if(player_total_score > comp_total_score)
disp('\nThe computer wins!');
elseif (player_total_score < comp_total_score)
disp('\nThe computer wins!');
else
disp('\nThe game ends with a tie');
end

% end matlab code


Related Solutions

Stuck in the mud is a popular dice game in UK. The game uses five (5)...
Stuck in the mud is a popular dice game in UK. The game uses five (5) 6-sided dice to play. The players play in turns. Choose one player to start the game. The player will roll all five (5) dice. If the player rolled any 2s or 5s, the player does not score any points for this throw. The player can only score on a roll which does not include the number 2 and 5. Any dice with a 2...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains the detail game description: https://www.activityvillage.co.uk/stuck-in-the-mud , with additional features that can: • Use five (5) 6-sided dice to automatically play the Stuck in the Mud game against a player. • Greet the player when the game starts. • Let the player to choose the number of rounds to play. Take care of the user input to ensure the program will not crash with inputs...
A baby elephant is stuck in a mud hole. To help pull it out, game keepers use a rope to apply a...
A baby elephant is stuck in a mud hole. To help pull it out, game keepers use a rope to apply a force FA, as part a of the drawing shows. By itself, however, force FAis insufficient. Therefore, two additional forces FB and FC are applied, as in part b of the drawing. Each of these additional forces has the same magnitude F. Themagnitude of the resultant force acting on the elephant in part b of the drawing is k...
Game of dice - fair dice: If I throw a number >= 5 I win. If...
Game of dice - fair dice: If I throw a number >= 5 I win. If he throws a number =< 4 he wins. I throw the first dice. Given that he loses(throws a number >4) what is the probability of me winning ? What is the expected number of throws before either of us wins?
Java programming One of the most popular games of chance is a dice game known as...
Java programming One of the most popular games of chance is a dice game known as “craps,” which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2,3,4,5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on...
Dice Game Rules: 2 - 4 players Each player has 5 Dice. The dice have 6...
Dice Game Rules: 2 - 4 players Each player has 5 Dice. The dice have 6 sides. Each player rolls their dice, and the dice statistics are reported: Sum, number of pairs (and of what), and "straights" - (all dice in order - e.g. 1,2,3,4,5 or 2,3,4,5,6) Player 1 might roll 2,2,3,4,4 so the results would be: Sum: 15, 1 pair (2), 1 pair (4) Player 2 might roll 1, 1, 4, 6, 6 so the results would be: Sum:...
Question: You have five dice, like in a game of Yahtzee! Suppose you roll the five...
Question: You have five dice, like in a game of Yahtzee! Suppose you roll the five dice once and sum the numbers the five dice show. (a) What is the mean and the standard deviation of the sum of five dice? (b) Suppose you average 60 of such rolls with the five dice. What is the distribution of this average? (c) What is the chance the average of 60 such rolls is larger than 18?
1. A round in the game Yahtzee begins by rolling five fair dice. Find the probability...
1. A round in the game Yahtzee begins by rolling five fair dice. Find the probability of rolling a: a. one pair (ex 33421 but not 33441), two pair (ex 33441 but not 33444), and three of a kind (ex 24252 but not 24242) 2. Consider a 10x10 matrix that consists of all zeros. ten elements of the matrix are selected at random and their value is changed from a zero to a one. find the probability that the ones...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: a) If the player rolls a 1 then the player gets no new points and it becomes the other player’s turn. b) If the player rolls 2-6 then they can either roll again or hold. If the player...
Chicago is a group dice game that requires no skill. The objective of the game is...
Chicago is a group dice game that requires no skill. The objective of the game is to accumulate points by rolling certain combinations (GamezBuff, 2017). How do you play Chicago? There are eleven rounds in the game, one for each combination that can be made by adding two dice, namely the numbers two through 12. Each round has a target combination starting with two and going up all the way to 12. Going clockwise, the players take turns to roll...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT