title: Determining a winner in a NXN Tic Tac Toe game
body: <p>I've tried to create a Tic Tac Toe game class with the play and hasWon methods.</p>
  
  <pre><code>public class TicTacToe {
  
  private enum State{Blank, X, O}
  private int grid;
  private State[][] board = new State[grid][grid];
  private int moves;
  
  
  //Default Constructor
  public TicTacToe(int grid){
  
      board = new State[grid][grid];
      moves = 0;
  }
  public void play(State s, int m, int n){
  
      if (board[m][n] == State.Blank){
          board[m][n] = s;
      }
      moves++;
  }
  
  
  
  
  public boolean hasWon(State[][] board){
  
      //check winner in rows
      boolean state = false;
      int j = 0;
      int i = 0;
      while(j &lt;= grid) {
          for (i = 0; i &lt;= grid; i++) {
              if (board[j][i] == board[j][i + 1])
                  state = true;
              else state = false;
              break;
  
          }
          if(state == false)
              j++;
          else return true;
  
      }
      //check winner in columns
      while(j &lt;= grid) {
          for (i = 0; i &lt; grid; i++) {
              if (board[i][j] == board[i + 1][j])
                  state = true;
              else state = false;
              break;
  
          }
          if (state == true)
              j++;
          else return true;
      }
      //check winner in top diagonal
      while(j &lt;= grid &amp;&amp; i &lt;= grid){
          if (board[i][j] == board[i+1][j+1])
              state = true;
          else state = false;
          break;
  
          i++;
          j++;
          return true;
      }
  
  
      //check winner in bottom diagonal
      int k = grid;
      int l = grid;
      while(k &gt;= 0 &amp;&amp; l &gt;= 0){
          if (board[k][l] == board[k-1][l-1])
              state = true;
          else state = false;
          break;
          k--;
          l--;
          return true;
      }
  
  
      return false;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However when called in the Main class the program behaves erratically. Is there a logical problem in the code.</p>