Tic Tac Toe game with functions / processing

I can’t get my code to work to print once and leave the X and O there.

Does anyone have tips?

int nRows = 3, nColumns= 3;
int gameBoard [][]=new int [nRows][nColumns];
int player=3;
int symbol=1;
int x=width/nRows;
int y= height/nColumns;

void setup() {
  size(800, 800);
  rectMode(CORNER);
  ellipseMode(CORNER);
}

void draw() {
  drawGrid();
  oppositePlayer();
  drawSymbols(symbol);
}

void drawGrid() {
  for (int row=0; row<3; row++) {
    for (int column=0; column<3; column++) {
      fill(20, 0, 100);
      rect (row*width/nRows, column*height/nColumns, width/nRows, height/nColumns);
      //drawSymbols(gameBoard[row][column]);
    }
  }
}


void drawSymbols(int a) {
  int row=0;
  int column=0;
  switch(a) {
  default:
    if (mousePressed == false);
    break;
  case 1:
    if (mousePressed == true && player ==1 )
      fill(0);
    textSize(100);
    text(("X"), (width/nRows)*row+x/2, (height/nColumns)*column+y/2);
    ;

  case 2:
    if (mousePressed == true && player == 2)

      fill(255);
    textSize(100);
    text(("O"), (width/nRows), (height/nColumns)*column+y/2);
  }
}

void mouseClicked() {
  int row = mouseY;//ellHeight
  int column= mouseX;//cellWidth


  gameBoard[row][column] = 1;
  player = oppositePlayer();
}



int oppositePlayer() {
  return 3 - player;
}


void clearBoard() {
  for (int row=0; row<2; row++)
    for (int column=0; column<2; column++)
      gameBoard[row][column] =0;
}

When I run this sketch, I get an error when I click. It’s an ArrayIndexOutOfBoundsException on this line:

gameBoard[row][column] = 1;

Which is in your mouseClicked() function:

void mouseClicked() {
  int row = mouseY;//ellHeight
  int column= mouseX;//cellWidth


  gameBoard[row][column] = 1;
  player = oppositePlayer();
}

I think this is happening because you’re using mouseY and mouseX as your indexes. But mouseY and mouseX will have very large numbers, whereas I think you probably want your row and column to be 0, 1, or 2.

In other words, I think you need to translate from mouseY and mouseX to row and column.