private boolean legalMove(int x, int y, int player, int[][] board) {
    int opponent;
    if (player == 1) {
      opponent = -1;
    } else {
      opponent = 1;
    }
    if (board[x][y] != 0) {
      return false;
    }
    boolean N = checkN(x, y, player, opponent, board);
    boolean NW = checkNW(x, y, player, opponent, board);
    boolean W = checkW(x, y, player, opponent, board);
    boolean SW = checkSW(x, y, player, opponent, board);
    boolean S = checkS(x, y, player, opponent, board);
    boolean SE = checkSE(x, y, player, opponent, board);
    boolean E = checkE(x, y, player, opponent, board);
    boolean NE = checkNE(x, y, player, opponent, board);
    return (N) || (NW) || (W) || (SW) || (S) || (SE) || (E) || (NE);
  }