title: Passed a 2D Array to another class but can't get the object returned
body: <p>I'm currently developing an algorithm for my Tictactoe Android App (using Java) with Minimax, but first, I just want to make sure the algorithm works, so I made the algorithm to &quot;suggests&quot; the next move to the player.</p>
  <p>The player is declared as <code>String player = &quot;x&quot;;</code> in the Minimax class.</p>
  <blockquote>
  <p>Minimax.java</p>
  </blockquote>
  <pre><code>package com.firaz.tictactoe;
  
  public class Minimax {
      public static class Move {
          int row, col;
      }
  
      static String player = &quot;x&quot;;
      static String opponent = &quot;o&quot;;
      String[][] board = new String[3][3];
  
      // This function returns true if there are moves
  // remaining on the board. It returns false if
  // there are no moves left to play.
      static Boolean isMovesLeft(String[][] board) {
          for (int i = 0; i &lt; 3; i++)
              for (int j = 0; j &lt; 3; j++)
                  if (board[i][j].equals(&quot;_&quot;))
                      return true;
          return false;
      }
  
      // This is the evaluation function
      static int evaluate(String[][] b) {
          // Checking for Rows for X or O victory.
          for (int row = 0; row &lt; 3; row++) {
              if (b[row][0].equals(b[row][1]) &amp;&amp;
                      b[row][1].equals(b[row][2])) {
                  if (b[row][0].equals(player))
                      return +10;
                  else if (b[row][0].equals(opponent))
                      return -10;
              }
          }
  
          // Checking for Columns for X or O victory.
          for (int col = 0; col &lt; 3; col++) {
              if (b[0][col].equals(b[1][col])
                      &amp;&amp; b[1][col].equals(b[2][col])) {
                  if (b[0][col].equals(player))
                      return +10;
  
                  else if (b[0][col].equals(opponent))
                      return -10;
              }
          }
  
          // Checking for Diagonals for X or O victory.
          if (b[0][0].equals(b[1][1])
                  &amp;&amp; b[1][1].equals(b[2][2])) {
              if (b[0][0].equals(player))
                  return +10;
              else if (b[0][0].equals(opponent))
                  return -10;
          }
  
          if (b[0][2].equals(b[1][1])
                  &amp;&amp; b[1][1].equals(b[2][0])) {
              if (b[0][2].equals(player))
                  return +10;
              else if (b[0][2].equals(opponent))
                  return -10;
          }
  
          // Else if none of them have won then return 0
          return 0;
      }
  
      // This is the minimax function. It considers all
  // the possible ways the game can go and returns
  // the value of the board
      static int minimax(String[][] board,
                         int depth, Boolean isMax) {
          int score = evaluate(board);
  
          // If Maximizer has won the game
          // return his/her evaluated score
          if (score == 10)
              return score;
  
          // If Minimizer has won the game
          // return his/her evaluated score
          if (score == -10)
              return score;
  
          // If there are no more moves and
          // no winner then it is a tie
          if (isMovesLeft(board) == false)
              return 0;
  
          // If this maximizer's move
          if (isMax) {
              int best = -1000;
  
              // Traverse all cells
              for (int i = 0; i &lt; 3; i++) {
                  for (int j = 0; j &lt; 3; j++) {
                      // Check if cell is empty
                      if (board[i][j].equals(&quot;_&quot;)) {
                          // Make the move
                          board[i][j] = player;
  
                          // Call minimax recursively and choose
                          // the maximum value
                          best = Math.max(best, minimax(board,
                                  depth + 1, !isMax));
  
                          // Undo the move
                          board[i][j] = &quot;_&quot;;
                      }
                  }
              }
              return best;
          }
  
          // If this minimizer's move
          else {
              int best = 1000;
  
              // Traverse all cells
              for (int i = 0; i &lt; 3; i++) {
                  for (int j = 0; j &lt; 3; j++) {
                      // Check if cell is empty
                      if (board[i][j].equals(&quot;_&quot;)) {
                          // Make the move
                          board[i][j] = opponent;
  
                          // Call minimax recursively and choose
                          // the minimum value
                          best = Math.min(best, minimax(board,
                                  depth + 1, !isMax));
  
                          // Undo the move
                          board[i][j] = &quot;_&quot;;
                      }
                  }
              }
              return best;
          }
      }
  
      // This will return the best possible
  // move for the player
      static Move findBestMove(String[][] board) {
          int bestVal = -1000;
          Move bestMove = new Move();
          bestMove.row = -1;
          bestMove.col = -1;
  
          // Traverse all cells, evaluate minimax function
          // for all empty cells. And return the cell
          // with optimal value.
          for (int i = 0; i &lt; 3; i++) {
              for (int j = 0; j &lt; 3; j++) {
                  // Check if cell is empty
                  if (board[i][j].equals(&quot;_&quot;)) {
                      // Make the move
                      board[i][j] = player;
  
                      // compute evaluation function for this
                      // move.
                      int moveVal = minimax(board, 0, false);
  
                      // Undo the move
                      board[i][j] = &quot;_&quot;;
  
                      // If the value of the current move is
                      // more than the best value, then update
                      // best/
                      if (moveVal &gt; bestVal) {
                          bestMove.row = i;
                          bestMove.col = j;
                          bestVal = moveVal;
                      }
                  }
              }
          }
  
          return bestMove;
      }
  
      public void setBoard(String[][] Board){
          this.board = Board;
          Move bestMove = findBestMove(board);
  
          PlayerVersusComputer playerVersusComputer = new PlayerVersusComputer();
          playerVersusComputer.setRow(bestMove.row);
          playerVersusComputer.setCol(bestMove.col);
      }
  }
  </code></pre>
  <p>I'm expecting a return integer (row and col) from the <code>Minimax.java</code> to the <code>PlayerVersusComputer.java</code> in this code snippet.</p>
  <blockquote>
  <p>PlayerVersusComputer.java</p>
  </blockquote>
  <pre><code>String buttonID = getResources().getResourceEntryName(v.getId()); //button_ij
          int pointerOne = Integer.parseInt(buttonID.substring(7, buttonID.length()-1)); //obtain i
          int pointerTwo = Integer.parseInt(buttonID.substring(buttonID.length()-1)); //obtain j
  
          if (player1Turn) {
              ((Button) v).setText(&quot;x&quot;);
              board[pointerOne][pointerTwo] = &quot;x&quot;;
          } else {
              ((Button) v).setText(&quot;o&quot;);
              board[pointerOne][pointerTwo] = &quot;o&quot;;
              checkBestMove();
          }
  
   protected void checkBestMove() {
          minimax.setBoard(board);
          row = getCol();
          col = getRow();
          tvAI.setText(row+&quot;R&quot;+&quot; &quot;+col+&quot;C&quot;);
      }
  </code></pre>
  <p>This is the board Array. The board will &quot;update&quot; itself every time I pressed the <code>((Button) v).setText(&quot;x&quot;);</code> or <code>(&quot;o&quot;)</code>, then passed to Minimax.java when it's O's turn.</p>
  <pre><code>String[][] board = {{&quot;_&quot;,&quot;_&quot;,&quot;_&quot;},
                          {&quot;_&quot;,&quot;_&quot;,&quot;_&quot;},
                          {&quot;_&quot;,&quot;_&quot;,&quot;_&quot;}};
  </code></pre>
  <p>Since the <code>row</code> and <code>col</code> is not returned to the <code>checkBestMove()</code> function (I'm not sure if it's not returned or just can't &quot;update&quot; itself), the <code>tvAI.setText</code> keeps saying &quot;0R0C&quot; instead of updating itself (to 2R2C, then 0R1C, etc).</p>
  <p>Update to the <code>row</code> and <code>col</code> are expected because the <code>tvAI.setText</code> is intended to suggest the player's next move. So why it's not updating?</p>