Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a dice game which has the following rules: You start the game with 3 5 dice and roll them simultaneously Any dice which show

Consider a dice game which has the following rules:
You start the game with 35 dice and roll them simultaneously
Any dice which show a 5 or 6 are removed. If a dice shows a 1, you add one dice back in for your next roll.
The total of the remaining dice (2,3,4) are then added together to give you a score for your first round using the following scoring system:
2-2 points
3-3 points
4-1 point deduction
If there was at least one 5 removed, this will double your score for this round The same process is continued for the next round and your score is calculated again Continue rolling until all dice have been removed
Add the total score of each round together to give you a final score
Use MATLAB while-loop and if-else statements to create a script that calculates the total score that a single player will get in this game. You will need to generate random integers from 1-6 to simulate rolling the dice. Use the skeleton code below to help you. (Note that rolling a single dice n times is acceptable as opposed to rolling n dice)
Clear all
Set: initial number of dice (ie 35), total score (ie o)
While the number of dice left is nonzero, do the following
% Start a new round
Set round score to zero, number of 5's and 6's and number of 1's also to o
For I=1 : number of dice
Roll the die, getting a score between 1 and 6
Count the number of 5's and 6's (ie add 1 to number of 5's and 6's)
Count the number of 1's (ie add 1 to number of 1's)
Count the number of 5's (ie add 1 to number of 5's)
Add score of this die, eg 2 points if its 2,3 points if 3,-1 points if 4, to round score
End
If number of 5's is >0, double round score
Add round score to total score
Subtract the number of 5's and 6's from number of dice
Add the number of 1's to the number of dice
End
Display total score
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

What is the difference between SIMD and SPMD?

Answered: 1 week ago