Answer To: GE1101 ML-3 MATLAB ADVANCED GAME DESIGN: TIC TAC TOE LAB OBJECTIVES In this lab, you will: • Work...
Rahul answered on Feb 14 2021
Prompt = 'Enter Heads/Tails 0/1 ';
x=input(Prompt);
y=randi([0 1],1,1);
if x==y
fprintf('Player 1 wins toss');
a=1;
b=0;
else
fprintf('Player 2 wins toss');
b=1;
a=0;
end
board = zeros(3,3);
% Draw Board
figure
plot([.5 3.5],[-1.5 -1.5], 'k','linewidth',2);
hold on
plot([.5 3.5],[-2.5 -2.5], 'k','linewidth',2)
plot([1.5 1.5],[-.5 -3.5], 'k','linewidth',2)
plot([2.5 2.5],[-.5 -3.5], 'k','linewidth',2)
hold off
axis off
% Obtain first move
while a==1
move = input('enter player 1 move [r,c] ');
r = move(1);
c = move(2);
board(r,c) = 1;
text(c,-r,'X','horizontalalignment','center','fontsize',20)
a=0;
b=0;
for turn = 1:4
move = input('enter player 2 move [r,c] ');
r = move(1);
c = move(2);
board(r,c) = -1;
text(c,-r,'O','horizontalalignment','center','fontsize',20)
% Check for victory by 0, 2nd player
result = [sum(board), sum(board) ];
result(1) = board(1,1) + board(1,2) + board(1,3);
result(2) = board(2,1) + board(2,2) + board(2,3);
...