% Initalize the variables for "t" and "r" r = 2; %Round counter begins at round 2 and ends at round 12 (11 total rounds) t = 0; %Initialize the trial counter (Starts at 0) p = 1; %Player 1 is represented by 1 and player 2 is represented by 2 %Initalize the matrices for player wins and trial counter round_total = 11; %There is a total of 11 rounds for a six-sided die (determined from calculation) P1Wins = zeros (1, round_total); %Creates a row vector with 11 segments, that is set at 0 (player 1) P2Wins = zeros (1, round_total); % Creates a row vector with 11 segments, that is set at 0 (player 2) trialsPerRound = zeros (1, round_total); % Creates a row vector with 11 segments, that is set at 0 %Dice Game Simulation while r <= round_total diel = randi (6) %Player 1 rolls the first die die2 = randi (6) %Player 2 rolls the second die P1_roll diel + die2 %The sum of the two die player 1 rolls t = t + 1; %Resets the trial counter for each new round diel randi (6) %Player 2 rolls the first die die2 = randi (6) %Player 2 rolls the second die P2_roll t = t + 1; %Increment if Pl_roll == r diel + die2 %The sum of the two die player 2 rolls the trial counter by 1 P1Wins (r) = 1; % Player 1 won the round trialsPerRound (r) = t; % Update the number of trials per round PlWins Talley = cumsum (P1Wins) %Update the cumulative wins for player r = r + 1; % Increment the round counter by 1 t = 1 %Resets the trial counter to 1 at the start of every round
% Initalize the variables for "t" and "r" r = 2; %Round counter begins at round 2 and ends at round 12 (11 total rounds) t = 0; %Initialize the trial counter (Starts at 0) p = 1; %Player 1 is represented by 1 and player 2 is represented by 2 %Initalize the matrices for player wins and trial counter round_total = 11; %There is a total of 11 rounds for a six-sided die (determined from calculation) P1Wins = zeros (1, round_total); %Creates a row vector with 11 segments, that is set at 0 (player 1) P2Wins = zeros (1, round_total); % Creates a row vector with 11 segments, that is set at 0 (player 2) trialsPerRound = zeros (1, round_total); % Creates a row vector with 11 segments, that is set at 0 %Dice Game Simulation while r <= round_total diel = randi (6) %Player 1 rolls the first die die2 = randi (6) %Player 2 rolls the second die P1_roll diel + die2 %The sum of the two die player 1 rolls t = t + 1; %Resets the trial counter for each new round diel randi (6) %Player 2 rolls the first die die2 = randi (6) %Player 2 rolls the second die P2_roll t = t + 1; %Increment if Pl_roll == r diel + die2 %The sum of the two die player 2 rolls the trial counter by 1 P1Wins (r) = 1; % Player 1 won the round trialsPerRound (r) = t; % Update the number of trials per round PlWins Talley = cumsum (P1Wins) %Update the cumulative wins for player r = r + 1; % Increment the round counter by 1 t = 1 %Resets the trial counter to 1 at the start of every round
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Store the overall game results in a matrix called “store_results”.
Column 1 lists the round number
Column 2 lists the total number of trials in that round
Column 3 records which player won that round (1 or 2)
Column 4 records the value of Dice 1
Column 5 records the value of Dice 2
Column 6 records the sum of the two dice at the end of that round (which should equal the value in Column 1)
I provided my code below of a dice roll simulation in matlab. How do I add the matrix "store_results" into my code. Thank you.

Transcribed Image Text:end
elseif P2_roll == "
P2Wins (r) = 1 %Player 2 won the round
trialsPerRound (r) = t; %Update the number of trials per round
P2Wins Talley
cumsum (P2Wins); %Update the cumulative wins for player 2
r = r + 1; %Increment the round counter by
t = 1 %Resets the trial counter to 1 at the start of every round
end
=
fprintf('Player 1 has won %d rounds\n', cumsum (P1Wins))
fprintf('Player 2 has won %d rounds\n', cumsum(P2Wins))
Round_total = (2:12) XX-axis values 2:12 for 11 total rounds
plot (Round_total, PlWins_Talley, 'r')
hold on
plot (Round_total, P2Wins_Talley, 'k')
grid on
legend('Player 1', 'Player 2');
title('Cumulative Wins Rounds')
xlabel('Rounds')
ylabel('Cumulative Wins')
figure (2)
bar(trialsPerRound)
title('Number of Trials to Win Each Round')
xlabel('Round')
ylabel('Number of Trials')

Transcribed Image Text:% Initalize the variables for "t" and "r"
r = 2; %Round counter begins at round 2 and ends at round 12 (11 total rounds)
t = 0; %Initialize the trial counter (Starts at 0)
p = 1; %Player 1 is represented by 1 and player 2 is represented by 2
%Initalize the matrices for player wins and trial counter
round_total 11; *There is a total of 11 rounds for a six-sided die (determined from calculation)
P1Wins = zeros (1, round_total); %Creates a row vector with 11 segments, that is set at 0 (player 1)
P2Wins = zeros (1,round_total); %Creates a row vector with 11 segments, that is set at 0 (player 2)
trialsPerRound = zeros (1,round_total); %Creates a row vector with 11 segments, that is set at 0
%Dice Game Simulation
while r <= round_total
=
diel =
% Player 1 rolls the first die
randi (6)
die2 = randi (6) %Player 2 rolls the second die
P1_roll = diel + die2 %The sum of the two die player 1 rolls
t = t + 1; %Resets the trial counter for each new round
diel = randi (6) %Player 2 rolls the first die
die2 = randi (6) %Player 2 rolls the second die
P2_roll = diel + die2 %The sum of the two die player 2 rolls
t = t + 1; %Increment the trial counter by 1
if Pl_roll == r
P1Wins (r) = 1; %Player 1 won the round
trialsPerRound (r) = t; %Update the number of trials per round
P1Wins Talley = cumsum (P1Wins) %Update the cumulative wins for player
r = r + 1; %Increment the round counter by 1
t = 1 %Resets the trial counter to 1 at the start of every round
11
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education