Stuck in the mud is a popular dice game in UK The game uses

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.)

>>

Solution

.globl main
.data
msgprompt: .word msgprompt_data
msgres1: .word msgres1_data
msgres2: .word msgres2_data

msgprompt_data: .asciiz \"Positive integer: \"
msgres1_data: .asciiz \"The worth of factorial(\"
msgres2_data: .asciiz \") is \"

# each call includes a stack section of twelve bytes, or 3 words.
# the house is reserved as follows:
# 0($sp) is reserved for the initial worth given to the current decision
# 4($sp) is that the house reserved for a come back worth
# 8($sp) is that the house reserved for the name and address.
# calls could manipulate their parent\'s information, however oldsters might not
# manipulate their child\'s information.
# i.e: if we\'ve got a decision A WHO includes a kid decision B:
# B could run:
# sw $t0, 16($sp)
# which might store information from $t0 into the parent\'s come back worth register
# A, however, ought to not(and, altogether cases I will consider, cannot) manipulate
# any information that belongs to a toddler decision.


.text
main:
# printing the prompt
#printf(\"Positive integer: \");
la $t0, msgprompt # load address of msgprompt into $t0
chemical element $a0, 0($t0) # load information from address in $t0 into $a0
li $v0, four # decision code for print_string
syscall # run the print_string syscall

# reading the input int
# scanf(\"%d\", &number);
li $v0, five # decision code for read_int
syscall # run the read_int syscall
move $t0, $v0 # store input in $t0

move $a0, $t0 # move input to argument register $a0
addi $sp, $sp, -12 # move stackpointer up three words
point $t0, 0($sp) # store input in prime of stack
point $ra, 8($sp) # store counter in spite of appearance of stack
jal factorial # decision factorial

# after we get here, we\'ve got the ultimate come back worth in 4($sp)

chemical element $s0, 4($sp) # load final come back val into $s0

# printf(\"The worth of \'factorial(%d)\' is: %d\ \",
la $t1, msgres1 # load msgres1 address into $t1
chemical element $a0, 0($t1) # load msgres1_data worth into $a0
li $v0, four # call for print_string
syscall # print worth of msgres1_data to screen

chemical element $a0, 0($sp) # load original worth into $a0
li $v0, one # call for print_int
syscall # print original worth to screen

la $t2, msgres2 #load msgres2 address into $t1
chemical element $a0, 0($t2) # load msgres_data worth into $a0
li $v0, four # call for print_string
syscall # print worth of msgres2_data to screen

move $a0, $s0 # move final come back worth from $s0 to $a0 for come back
li $v0, one # call for print_int
syscall # print final come back worth to screen

addi $sp, $sp, twelve # move stack pointer backpedal wherever we tend to started

# come back 0;
li $v0, ten # call for exit
syscall # exit!

.text
factorial:
# base case - still in parent\'s stack section
chemical element $t0, 0($sp) # load input from prime of stack into register $t0
#if (x == 0)
beq $t0, 0, returnOne # if $t0 is adequate zero, branch to returnOne
addi $t0, $t0, -1 # figure one from $t0 if not adequate zero

# algorithmic case - move to the current call\'s stack section
addi $sp, $sp, -12 # move stack pointer up three words
point $t0, 0($sp) # store current operating range into the highest of the stack section
point $ra, 8($sp) # store counter in spite of appearance of stack section

jal factorial # algorithmic decision

# if we tend to get here, then we\'ve got the kid come back worth in 4($sp)
chemical element $ra, 8($sp) # load this call\'s $ra again(we simply got in from a jump)
chemical element $t1, 4($sp) # load child\'s come back worth into $t1

chemical element $t2, 12($sp) # load parent\'s begin worth into $t2
# come back x * factorial(x-1); (not the come back statement, however the multiplication)
mul $t3, $t1, $t2 # multiply child\'s come back worth by parent\'s operating worth, store in $t3.

point $t3, 16($sp) # take result(in $t3), store in parent\'s come back worth.

addi $sp, $sp, twelve # move stackpointer backpedal for the parent decision

boy $ra # jump to parent decision

.text
#return 1;
returnOne:
li $t0, one # load one into register $t0
point $t0, 4($sp) # store one into the parent\'s come back worth register
boy $ra # jump to parent decision

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
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
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
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
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
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
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
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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site