title: TicTacToe using two dimensional arrays
body: <p>I am trying to create a program that does the game TicTacToe. I have finished creating 
  all the methods and I just need to create the driver program. Before creating the 
  driver program, I tried to just print the board along with a character but I don't 
  think my methods are correct. Here is what my error looks like:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 3
  at TicTacToeBoard.move(TicTacToeBoard.java:75)
  at TicTacToe.main(TicTacToe.java:24)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
  </code></pre>
  
  <p>Here are my two programs: </p>
  
  <p>This is my driver program that I can't seem to complete. The last thing  that will be shown is the
  template so that you have the idea of how each program works. </p>
  
  <pre><code>class TicTacToe
  {
   public static void main(String [] args)
   { 
    //System.out.println("Welcome! Tic-Tac-Toe is a two player game.");
    //System.out.println("Enter player one's name: ");
  
    TicTacToeBoard game = new TicTacToeBoard();
    System.out.println(game.toString());
  
    //int count = 0;
  
  
    game.move('x', 1, 3); 
    // game.move('o', 1, 1);
  
    /* while (game.gameWon() !true || count != 9)
       {
        System.out.print(game.move()); 
        System.out.print(game.isEmpty()); 
        }*/   
       }
      }
  </code></pre>
  
  <p>This is where all the methods are......</p>
  
  <pre><code>class TicTacToeBoard
  {
   private char [][] board = new char[3][3];
   String b;
  
   // This a new constructor that creates a tic-tac-toe board
   public TicTacToeBoard()
   {
    for (int rows = 0; rows &lt; board.length; rows++)// creates rows
    {
     for (int columns = 0; columns &lt;board[rows].length;columns++)// creates columns
     {
      //System.out.println("| ");
       board[rows][columns] = ' ';
      //System.out.println(" |\n" );
      }
     }
   }
  
    // creates a string form of the tic-tac-toe board and allows the user
    // to access it during the game.
    public String toString()
    {
     String b = "";
  
     // creates a vertical bar at the beginning and the end of each row
     for (int rows = 0; rows &lt; board.length; rows++)
     {
       b += "| ";
       // adds a space for each row and column character in tic-tac-toe board.
       for (int columns = 0; columns &lt; board[rows].length; columns++)
       {
        b += board[rows][columns] + " ";  
        }
         b += "|\n";// prints a | space space space | and breaks off to create two new lines.
        }
         return b; // prints the tic-tac-toe board to be accessed by the user.
       }
  
  String move(char x, int rows, int columns)
  { 
   String b = "";
  
   // creates a vertical bar at the beginning and the end of each row
   for (int r = 0; r &lt; board.length; r++)
   {
     b += "| ";
  
    for (int c = 0; c &lt; board[r].length; c++)
    {
     b += board[r][c] + " ";  //prints 3 spaces on each line. 
      // prints string character from user input if row and column not equal to zero 
     if (board[rows - 1][columns - 1] &gt;= 0 &amp;&amp; board[rows - 1][columns - 1] &lt;= 2 )
     {
      board[rows - 1][columns - 1] = x;// prints character in the specified index from user input 
      b += board[rows - 1][columns - 1];// prints out the board and the new character in specified space.
       } 
        else if (board[rows - 1][columns - 1] &lt; 0)   // makes user pick another choice
        return "ILLEGAL MOVE, TRY AGAIN!"; 
        // adds a space for each row and column character in tic-tac-toe board.
       }
        b += "|\n";// prints a | space space space | and breaks off to create two new lines.
      }  
       return b; // prints the tic-tac-toe board to be accessed by the user.
  
     }
  
    // checks if a space character is empty
    void isEmpty(char x, int row, int col)
    {
     if (board [row - 1][col - 1] == ' ')
      board[row - 1][col - 1] = x;
     else // makes user pick another row and column if space character is not empty
     System.out.println("ILLEGAL CHOICE, PICK AGAIN!");
     }
    // checks if game is won   
   public boolean gameWon(int row, int col)
   {  
    if ((board[2][0] == board[1][1]) &amp;&amp; (board[2][0] == board[0][2]))
     return true;
    else if ((board[2][0] != board[1][1]) &amp;&amp; (board[2][0] != board[0][2]))
     return false;   
  
    if ((board[2][2] == board[1][1])&amp;&amp; (board[2][2] == board[0][0]))
     return true;
    else if ((board[2][2] != board[1][1])&amp;&amp; (board[2][2] != board[0][0]))
     return false;   
  
    if ((board[0][0] == board[1][0]) &amp;&amp; (board[0][0] == board[2][0]))
     return true;
    else if ((board[0][0] != board[1][0]) &amp;&amp; (board[0][0] != board[2][0]))
     return false;        
  
    if ((board[0][1] == board[1][1]) &amp;&amp; (board[0][1] == board[2][1]))
     return true;
    else if ((board[0][1] != board[1][1]) &amp;&amp; (board[0][1] != board[2][1]))
     return false;        
  
    if ((board[0][2] == board[1][2]) &amp;&amp; (board[0][2] == board[2][2]))
     return true;
    else if ((board[0][2] != board[1][2]) &amp;&amp; (board[0][2] != board[2][2]))
     return false;   
  
    if ((board[0][0] == board[0][1]) &amp;&amp; (board[0][0] == board[0][2]))
     return true;
    else if ((board[0][0] != board[0][1]) &amp;&amp; (board[0][0] != board[0][2]))
     return false;   
  
    if ((board[1][0] == board[1][1]) &amp;&amp; (board[1][0] == board[1][2]))
     return true;
    else if ((board[1][0] != board[1][1]) &amp;&amp; (board[1][0] != board[1][2]))
     return false;     
  
    if ((board[2][0] == board[2][1]) &amp;&amp; (board[2][0] == board[2][2]))
     return true;
    else 
     return false;
   }
  }
  </code></pre>
  
  <p>Here is the template for the whole thing!!!!!</p>
  
  <pre><code>class TicTacToe
  {
    public static void main (String [] args)
    {
         TicTacToeBoard b = new TicTacToeBoard();
  
         while (game not over)
         {
              swtich player
              increment turn counter
  
              until user enters a valid move    
              {
                    prompt for move
               }
  
              make move
              b.makeMove (player, row, col);
  
              print board    
              System.out.println(b);
         }
  
         print outcome
    }
   }
  
  
   class TicTacToeBoard
   {
     private char [][] board = ...;
  
     public TicTacToeBoard()
     {
        initialize board with spaces
      }
  
     public void makeMove (char c, int row, int col)
     {
          store symbol in specified position
      }
  
     public boolean isEmpty(int row, int col)
     {
          return true if square is unfilled
      }
  
     public boolean gameWon()
     {
          check board for a win
      }
  
     public String toString ()
     {
          return String representation of board
      }
  
   }
  </code></pre>