In: Mechanical Engineering
Assume that the human player makes the first move against the computer in a game of Tic-Tac-Toe, which has a 3 x 3 grid. Write a MATLAB function that lets the computer respond to that move. The function’s input argument should be the cell location of the human player’s move. The function’s output should be the cell location of the computer’s rst move. Label the cells as 1, 2, 3 across the top row; 4, 5, 6 across the middle row; and 7, 8, 9 across the bottom row.
Program plan:
• To check the given code to find the values of the variable each time the while statement is executed.
Program:
%**********************************************************
%The given matlab code is checked for the values of the
%variables for each time execution of the while statement.
%**********************************************************
%Program codes
%Initialization of value
k = 1;
%Initialization of value
b = -2;
%Initialization of value
x = -1;
%Initialization of value
y = -2;
while k <= 3 %Start of loop
%Displays string
disp([num2str(k), \' \',num2str(b),\' \', num2str(x),\' \', num2str(y)]);
%Computes value
y = x^2 - 3;
if y < b %Conditional statement
%Assign the value
b = y;
end %End of conditional statement
%Increment of value
x = x + 1;
%Increment of loop variable
k = k + 1;
end %End of loop
Output: