In: Computer Science
Create a single MatLab script named Problem3.m that, when run, does the following: -Defines a blank tic-tac-toe board: a 3-by-3 matrix called board, with blank spots represented by zeros. Echo the blank board to the command window. -Asks Player 1 for a row and a column, then puts a 1 in the given location. Echoes the new board. -Asks Player 2 for a row and a column, then puts a 2 in the given location. Echoes the new board.
Please write it so a person who is new at programming understands. Please note this is for MATLAB
Matlab code:
board = zeros(3,3)
i =0;
while(i<9)
if( mod(i,2) == 0 )
r = input('Player 1 please enter raw number\n');
c = input('Player 1 please enter column number\n');
else
r = input('Player 2 please enter raw number\n');
c = input('Player 2 please enter column number\n');
end
board(r,c) = 1;
board
i = i + 1;
end
Sample output
board =
0 0 0
0 0 0
0 0 0
Player 1 please enter raw number
1
Player 1 please enter column number
1
board =
1 0 0
0 0 0
0 0 0
Player 2 please enter raw number
1
Player 2 please enter column number
2
board =
1 1 0
0 0 0
0 0 0
Player 1 please enter raw number
1
Player 1 please enter column number
3
board =
1 1 1
0 0 0
0 0 0
Player 2 please enter raw number
2
Player 2 please enter column number
1
board =
1 1 1
1 0 0
0 0 0
Player 1 please enter raw number
2
Player 1 please enter column number
2
board =
1 1 1
1 1 0
0 0 0
Player 2 please enter raw number
2
Player 2 please enter column number
3
board =
1 1 1
1 1 1
0 0 0
Player 1 please enter raw number
3
Player 1 please enter column number
1
board =
1 1 1
1 1 1
1 0 0
Player 2 please enter raw number
3
Player 2 please enter column number
2
board =
1 1 1
1 1 1
1 1 0
Player 1 please enter raw number
3
Player 1 please enter column number
3
board =
1 1 1
1 1 1
1 1 1