Question: Above are the matlab scripts I have. I'm writing a code to create a tic tac toe game. Need help to modify the CompMove code





Above are the matlab scripts I have. I'm writing a code to create a tic tac toe game.
Need help to modify the CompMove code above (the second pic), which the computer knows how to block a winning move and makes a winning move when there is one, otherwise make a random move. The code above now is just the computer makes a vaild random move all the time.
Please help me with this, and make sure the answer you give could work with the scripts above. Thank you!
FILE NAVIGATE BREAKPOINTS RUN sTicTacToe main script that will call necessary function to play the game gameBoard [0,0,0; 0,0,0; 0,0,0]; 4 validMoves = 1; winner = 17; while (validMoves > 0) %USER gameBoarduserMove(gameBoard); winner -winnerLoserTie(gameBoard); if (winner= 0) Il (winner=-1) ll (winner= 1) 10- break; 12 13 - 14 15 - 16 - end validMoves = anyMovesRemaining(gameBoard); if (val!dMoves == 0) break end sComputer gameBoard compMove ( gameBoard) winner winnerLoserTie(gameBoard); if (winner= 0) ll (winner=-1) ll (winner= 1) 18 19 - 20- 21 - 22 - 23 - 24 25 26 - 27 - 28 - 29 30 - 31- 32 break; end va idMoves = anyMovesRemaining ( gameBoard); if (validMoves == 0) break end end %Display who won gameBoardgameBoard if (winner := 1) fprintf('You won!An) elseif (winner == -1)
Step by Step Solution
There are 3 Steps involved in it
To modify the compMove function for your Tic Tac Toe game so that the computer can block or make a winning move follow these steps Step 1 Create Utili... View full answer
Get step-by-step solutions from verified subject matter experts
