Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Random; public class TicTacToe { public void getMove(char[][] t

ID: 3619764 • Letter: I

Question

import java.util.Random;

public class TicTacToe {

public void getMove(char[][] theBoard, char myPiece) {

// this method should update the game board to place 'myPiece' (X or O)
// in a space on the board.

// As-is, this method just places an X or O randomly, without even considering
// if the square is already taken.

Random myRand = new Random();

int myRow = myRand.nextInt(3);
int myCol = myRand.nextInt(3);

theBoard[myRow][myCol] = myPiece;

}

}
HERE IS THE CODE
Random myRand = new Random();
int myRow=0,myCol=0;
do
{
myRow = myRand.nextInt(3);
myCol = myRand.nextInt(3);

}while(theBoard[myRow][myCol]!= ' ');
theBoard[myRow][myCol] = myPiece;
System.out.println(myPiece+ "your move" "+myRow+","+myCol);
}
Instruction say Change this method to intelligently play tic-tac-toe (for whatever piece it has been passed – X or O). Whats the problem with this to play this game intelligently?

Explanation / Answer

please rate - thanks Instruction say Change this method to intelligently play tic-tac-toe (for whatever piece it has been passed – X or O). Whats the problem with this to play this game intelligently? this randomly picks an empty spot regardless of the other pieces on the board for example lets say the board looks like X O X
         O  
and it's X's turn. X should block O however the move will be randomly chosen to possibly get a board that looks like X O X    O X now O should win on it's next turn, but since the spot to go is randomly chosen, O may go in the left corner X O X    O X O leaving X to possibly win