Hey guys. I have a tic tac toe game that plots random X's and O's on a 2d matrix array called theBoard[row][col].
I want to check to see if one X is placed on 1 spot, and if another point is plotted in the same spot, to check if it is occupied or empty, and whether to put a piece down.
Mostly I want to know how to check if char[][] theBoard is empty.
Here is the code I have so far.
Random myRand = new Random();
int myRow = myRand.nextInt(3);
int myCol = myRand.nextInt(3);
if (theBoard[myRow][myCol]==theBoard[' '][' ']){// if the array is empty, go ahead and mark myPiece
theBoard[myRow][myCol] = myPiece; //this marks myPiece.
}
else {
//otherwise, do nothing.
}
When I run this, oddly I receive an array out of bounds error...
char[][] theBoard is set to length 3...so I don't know why I am getting this error.