Question: I was given this matlab code with the following to help someone play yahtzee: %clear, clc %dice = roll_dice(5) ; %dice = [5 5 5

I was given this matlab code with the following to help someone play yahtzee:

%clear, clc %dice = roll_dice(5) ; %dice = [5 5 5 5 5] % to test specific dice combinations %dice % for screen output

upper_section = zeros (1,6);

for k = 1:6 % for each die possibility 1 to 6 upper_section(k) = score_1_to_6 (dice, k); end

kind3 = score_3_of_a_kind (dice); kind4 = score_4_of_a_kind (dice); fh = score_full_house (dice); ss = score_sm_straight (dice); ls = score_lg_straight (dice); y = score_yahtzee (dice); ch = score_chance (dice);

potential_scores = '[ upper_section, kind3, kind4, fh, ss, ls, y, ch ]';

% names of scoring categories,this is a cell array

cat_names = { 'Aces', 'Twos', 'Threes', 'Fours', 'Fives', 'Sixes', ... '3 of a kind', '4 of a kind', 'Full House', 'Sm. Straight',...'Lg. Straight', 'YAHTZEE', 'Chance'};

%printing potential scores to screen for k = 1:length ( potential_scores ) fprintf ('%15s; %3.0f ' , char(cat_names(k)), potential_scores(k)) end

and I need it to do this:

The functions you are to write are all called by the yahtzee helper.m script. The first function roll dice.m will accept an integer N as input and output a vector of N uniformly distributed integers from 1 to 6. The yahtzee helper.m script asks it for 5 dice rolls and stores them in the dice variable.

The rest of the functions called from yahtzee helper.m take dice as an input variable and return the resulting score if someone were to count their turn for that category. For example, if dice contained [5, 5, 5, 2, 1], then score 3 of a kind(dice) would return the sum of dice (which is 5 + 5 + 5 + 2 + 1 = 18) because there are 3 fives, but score 4 of a kind(dice) would return zero because dice does not contain 4 of a kind.

We will not worry about the BONUS categories for the upper or lower sections. Your submission for this lab should contain the following files.

roll dice.m

score 1 to 6.m

score 3 of a kind.m

score 4 of a kind.m

score chance.m

score full house.m

score lg straight.m

score sm straight.m

score yahtzee.m

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!