Help With Homework Question
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
Been trying to figure out this homework question for a while so I've decided I'd just come here fro some help. Here's the question:
"Two players, A and B, play a game called Eights. They take it in turns to choose a number 1, 2, or 3, which may not be the same as the last number chosen (so if A starts with 2, B may only choose 1 or 3 at the next move). A starts, and may choose any of the three numbers for the first move. After each move, the number chosen is added to a common running total. If the total reaches 8 exactly, the player whose turn it was wins the game. If a player causes the total to go over 8, the other player wins. Write a script to simulate each player's chances of winning, if they always play at random."
E = 0;
x = round(3*rand);
N = 0;
M = 1;
for X = 1
if N == 1
for B = 1
if E == 8
E
display('Player B is the winner!')
break
elseif E > 8
E
display('Player A is the winner!')
break
elseif x(B) == 2
E = E + 2;
M == 2;
else
E = E + 3;
M == 3
end
end
elseif N == 2
for B = 1
if E == 8
E
display('Player B is the winner!')
break
elseif E > 8
E
display('Player A is the winner!')
break
elseif x(B) == 1
E = E + 1;
M == 1;
else
E = E + 3;
M == 3
end
end
elseif N == 3
for B = 1
if E == 8
E
display('Player B is the winner!')
break
elseif E > 8
E
display('Player A is the winner!')
break
elseif x(B) == 1
E = E + 1;
M == 1;
else
E = E + 2;
M == 2
end
end
elseif M == 1
for A = 1
if E == 8
E
display('Player A is the winner!')
break
elseif E > 8
E
display('Player B is the winner!')
break
elseif x(A) == 2
E = E + 2;
M == 2;
else
E = E + 3;
M == 3;
end
end
elseif M == 2
for A = 1
if E == 8
E
display('Player A is the winner!')
break
elseif E > 8
E
display('Player B is the winner!')
break
elseif x(A) == 1
E = E + 1;
M == 1;
else
E = E + 3;
M == 3;
end
end
elseif M == 3
for A = 1
if E == 8
E
display('Player A is the winner!')
break
elseif E > 8
E
display('Player B is the winner!')
break
elseif x(A) == 1
E = E + 1;
M == 1;
else
E = E + 2;
M == 2;
end
end
end
end
This can probably be made a lot shorter, but this was all I could think of. Unfortunately, it doesn't seem to work at all.
Thank You!
Antworten (1)
Walter Roberson
am 28 Nov. 2016
You have a bunch of tests against M and N, but the only time you assign them values is your initialisation.
M == 3
is not assignment statement
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!