Question: Matlab Program: Help me modify the MyMove matlab script (pic 3-5). This is actually the script for the move of computer, 1-2 script is the
Matlab Program:





Help me modify the MyMove matlab script (pic 3-5). This is actually the script for the move of computer, 1-2 script is the main script for the tic tac toe game.
The goal is to create a move for the computer, which it knows how to block a winning move and make a winning move when there is. Otherwise, make a random move. The code I have, the computer just sometimes blocks the winning move or makes a winning move. In some other times, it just ignores it and make a random move. Please help me fix the code.
FILE NAVIGATE EDIT BREAKPOINTS RUN board = zeros(3,3); % Determines starting player randomly % playerturn 1 indicates Player 1 starting % playe rturn 2 indicates Player 2 starting playerturn = round (rand ) +1 ; step = 0; winplayer = 0; playing=1; %initialize %Display message disp Welcome to E7 tic-tac-toe.'); disp (board); if playe rturn = 1 4 12 disp( 'Player 1 will start first' else 15 disp( Player 2 will start first' end %Iterate the game while playing == 1 8 disp(['Player num2str(playerturn)'1) % Player1's turn if playe rturn 1 1 zeroind find ( board-=0); P1move-index = Human (board); % Change Player 1 function here if -any ( ze ro ind P1move-index P1move-index) zero!nd (1); = end board (P|move-index) playe rturn = 2; currentplayer = 1; step = step + 1; 1; = 28 % Player2's turn 2else zeroind = find ( board=0)
Step by Step Solution
There are 3 Steps involved in it
To modify the MyMove function to ensure the computer prioritizes making a winning move and blocking an opponents winning move before making a random m... View full answer
Get step-by-step solutions from verified subject matter experts
