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 creating a game where two players try to roll two die that equal the current round. For example, if the round is 3, the players must roll a 2 and a 1. I have written this code so far, but I am not getting the end result I need. I was hoping to see if I made an error in my code.

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
icon
Related questions
Question

● 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 creating a game where two players try to roll two die that equal the current round. For example, if the round is 3, the players must roll a 2 and a 1. I have written this code so far, but I am not getting the end result I need. I was hoping to see if I made an error in my code.

end
P2_roll
randi (6);
t = t + 1; %Increment the trial counter by a value of 1 after every roll
if Pl_roll
end
=
== r
PlWins (r) = 1 % Player 1 wins the round
PlWins_Talley (r) = P1Wins(r)+1; %Update player 1's cumulative wins
P2Wins Talley (r) P2Wins (r)+1; %Update player 2's cumulative wins
else P2_roll == r
store_results(r, :)
=
end
r = r + 1;
end
=
P2Wins (r) = 1 % Player 2 wins the round
PlWins Talley (r) P1Wins (r)+1; %Update player 1's cumulative wins
P2Wins_Talley (r) = P2Wins(r)+1; %Update player 2's cumulative wins
store_results (r, :)
=
[rt 1 Pl_roll P2_roll Pl_roll+P2_roll]; %Stores the game result:
[rt 2 Pl_roll P2_roll Pl_roll+P2_roll]; %Stores the game result:
end
if P1Wins Talley (r) > round_total/2 || P2Wins_Talley(r) > round_total/2
break;
Transcribed Image Text:end P2_roll randi (6); t = t + 1; %Increment the trial counter by a value of 1 after every roll if Pl_roll end = == r PlWins (r) = 1 % Player 1 wins the round PlWins_Talley (r) = P1Wins(r)+1; %Update player 1's cumulative wins P2Wins Talley (r) P2Wins (r)+1; %Update player 2's cumulative wins else P2_roll == r store_results(r, :) = end r = r + 1; end = P2Wins (r) = 1 % Player 2 wins the round PlWins Talley (r) P1Wins (r)+1; %Update player 1's cumulative wins P2Wins_Talley (r) = P2Wins(r)+1; %Update player 2's cumulative wins store_results (r, :) = [rt 1 Pl_roll P2_roll Pl_roll+P2_roll]; %Stores the game result: [rt 2 Pl_roll P2_roll Pl_roll+P2_roll]; %Stores the game result: end if P1Wins Talley (r) > round_total/2 || P2Wins_Talley(r) > round_total/2 break;
while r <= round_total
t = 0; %Initialize the game trial counter
P1_roll = randi (6); %Rolls the dice for player 1
randi (6); %Rolls the dice for player 2
P2_roll
t = t + 1; %Increment the trial counter by a value of 1 after every roll
%Determine which player wins the round
=
if Pl_roll ==
PlWins (r) = 1 %Player 1 wins the round
PlWins Talley (r)
P1Wins (r)+1; %Update player 1's cumulative wins
P2Wins Talley (r) = P2Wins(r)+1; %Update player 2's cumulative wins
store_results(r, :) [r,t,1,Pl_roll, P2_roll, Pl_roll+P2_roll]; % Stores the game results
elseif P2_roll == r
P2Wins (r) = 1 %Player 2 wins the round
PlWins Talley(r)
P1Wins (r)+1; %Update player 1's cumulative wins
P2Wins Talley(r) = P2Wins(r)+1; %Update player 2's cumulative wins
=
=
store_results(r,:) = [rt 2 Pl_roll P2_roll Pl_roll+P2_roll]; % Stores the game results
t = t + 1; %Increment the trial counter by a value of 1 after every roll
else %Neither player wins the round because Pl_roll and P2_roll didn't equal r
while Pl_roll
NE r || P2_roll
=
P1_roll randi (6);
P2_roll randi (6);
NE
Transcribed Image Text:while r <= round_total t = 0; %Initialize the game trial counter P1_roll = randi (6); %Rolls the dice for player 1 randi (6); %Rolls the dice for player 2 P2_roll t = t + 1; %Increment the trial counter by a value of 1 after every roll %Determine which player wins the round = if Pl_roll == PlWins (r) = 1 %Player 1 wins the round PlWins Talley (r) P1Wins (r)+1; %Update player 1's cumulative wins P2Wins Talley (r) = P2Wins(r)+1; %Update player 2's cumulative wins store_results(r, :) [r,t,1,Pl_roll, P2_roll, Pl_roll+P2_roll]; % Stores the game results elseif P2_roll == r P2Wins (r) = 1 %Player 2 wins the round PlWins Talley(r) P1Wins (r)+1; %Update player 1's cumulative wins P2Wins Talley(r) = P2Wins(r)+1; %Update player 2's cumulative wins = = store_results(r,:) = [rt 2 Pl_roll P2_roll Pl_roll+P2_roll]; % Stores the game results t = t + 1; %Increment the trial counter by a value of 1 after every roll else %Neither player wins the round because Pl_roll and P2_roll didn't equal r while Pl_roll NE r || P2_roll = P1_roll randi (6); P2_roll randi (6); NE
Expert Solution
steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Intelligent Machines
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
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education