%Dice Game Simulation while r <= round_total %Roll the die for each player P1_roll randi (6,2,6); P2_roll randi (6,2, 6); = end = %Determine who wins each round if Pl_roll == r P1Wins (r) P1Wins (r) + 1; %Player 1 wins the round, and increases the win count by ar elseif P2_roll == r P2Wins (r) = P2Wins (r) + 1; % Player 2 wins the round, and increases the win count by ar = %Continue to the next round or end the dice game simulation if r == round_total %Final round of the dice game break; elseif PlWins (r) > round_total/2 || P2Wins (r) > round_total/2 % Player 1 or Player 2 has wo
● Simulate the game (this will require using while and if statements as we learned in class) by using the round and trial counters you have established.
● Store a win for Player 1 or Player 2 after each round (indicate a win by a 1 and a loss by a 0).
● Store the cumulative wins of each player after each round (“P1Wins_Talley” and “P2Wins_Talley”).
● 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 am having trouble incorporating the following things in my code. I have a round counter but also need to add a trial counter. For each round, player 1 or player two must roll with two dice the value of the current round. (For example, if its round 4, the player must roll a 4 by rolling a 3 and a 1 or tow 2's). If neither player rolls the round value, continue until a player rolls the current number with the amount of trials per round to roll the round value. Bascially, the beginning of the code is assigning variables and the amount of sides of a die. I am using a 6 sided die for 11 rounds (2-12).
![%Player 1 or Player 2 wins the round if the player rolls the dice and
%scores the number of the round
%Prompt the user to enter the number of sides of the die
numsides =
input('Enter the number of sides: ');
%Calculate the number of rounds based on the number of sides of the die
min_sum = 2 %Minimum sum of two die
max_sum = 2*numsides %Maximum sum of two die
round_total = (max_sum min_sum) + 1%Formula for round total depending on # of sides on die
%Initalize the variables for "P","r", and "t"
P = 1; %P represents Player; player 1 is represented by 1, while player 2 is represented by 2
r = 2; %Round counter begins at round 2 and ends at round 12 (11 total rounds)
t = 1; %Trial counter begins at trial 1
%Initalize the matrices for player wins
round_total 11; %There is a total of 11 rounds for a six-sided die (determined from calculat
P1Wins = zeros (1, round_total); %Creates a row vector with 11 segments, that is set at 0 (playe
P2Wins = zeros (1, round_total); %Creates a row vector with 11 segments, that is set at 0 (playe](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6ad46b3e-a02f-4382-8de1-0ec501356244%2F2db33de9-2366-4348-aa83-2eca13c68cee%2F6xs6yzj_processed.png&w=3840&q=75)
![%Dice Game Simulation
while r <= round_total
end
%Roll the die for each player
P1_roll = randi (6,2,6);
P2_roll = randi (6,2,6);
%Determine who wins each round
if Pl_roll == r
P1Wins (r) P1Wins(r) + 1;
elseif P2_roll == r
P2Wins (r)
P2Wins (r) + 1;
end
=
end
%Player 1 wins the round, and increases the win count by ar
%Player 2 wins the round, and increases the win count by ar
%Continue to the next round or end the dice game simulation
if r == round_total %Final round of the dice game
break;
elseif PlWins(r) > round_total/2 || P2Wins (r) > round_total/2 %Player 1 or Player 2 has wo
break;
else %Continue to the next round of the game
r = r + 1;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6ad46b3e-a02f-4382-8de1-0ec501356244%2F2db33de9-2366-4348-aa83-2eca13c68cee%2Fspeo2ub_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 5 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)