Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

10 Minute Guide To Accounting For Non Accountants

Authors: Wayne A. Label

1st Edition

0028614070, 978-0028614076

Students also viewed these Databases questions