Language: C++

#include <bits/stdc++.h>
#define pb push_back
#define lli unsigned long long int
using namespace std;
int x,y;
int tfx,tfy;
int h,w;
char maze[1005][1005];
bool vis[1005][1005];
    
int dfs(int ttx,int tty)
{
    if(ttx==tfx && tty==tfy)
    return 0;
    
    int ansfinal=INT_MAX;
    
    queue<pair<pair<int,int>,int>> q;
    q.push({{ttx,tty},0});
    vis[ttx][tty]=1;
    
    while(!q.empty())
    {
        int tx=q.front().first.first;
        int ty=q.front().first.second;
        int ans=q.front().second;
        vis[tx][ty]=1;
        
        q.pop();
        //cout<<tx<<" "<<ty<<" "<<ans<<endl;
        if(tx==tfx && ty==tfy)
        ansfinal=min(ansfinal,ans);
        
        if(tx<w && maze[tx+1][ty]=='.' && vis[tx+1][ty]==0)
        q.push({{tx+1,ty},ans}), vis[tx+1][ty]=1;
        
        if(ty<h && maze[tx][ty+1]=='.'&& vis[tx][1+ty]==0)
        q.push({{tx,ty+1},ans}), vis[tx][ty+1]=1;
        
        if(tx>1 && maze[tx-1][ty]=='.'&& vis[tx-1][ty]==0)
        q.push({{tx-1,ty},ans}), vis[tx-1][ty]=1;
        
        if(ty>1 && maze[tx][ty-1]=='.'&& vis[tx][ty-1]==0)
        q.push({{tx,ty-1},ans}), vis[tx][ty-1]=1;
        
        if(abs(x-tx)<=2 && abs(y-ty)<=2 && vis[x][y]==0)
        {
            q.push({{x,y},ans+1});
           
        }
        
        for(int i=tx;i>=max(1,tx-2);i--)
        {
            for(int j=ty;j>=max(1,ty-2);j--)
            if(vis[i][j]==0 && maze[i][j]=='.')
                q.push({{i,j},ans+1}), vis[i][j]=1;
                
            for(int j=ty;j<=min(h,ty+2);j++)
            if(vis[i][j]==0 && maze[i][j]=='.')
                q.push({{i,j},ans+1}), vis[i][j]=1;
        }
        
        for(int i=tx;i<=min(w,tx+2);i++)
        {
            for(int j=ty;j>=max(1,ty-2);j--)
            if(vis[i][j]==0 && maze[i][j]=='.')
                q.push({{i,j},ans+1}), vis[i][j]=1;
                
            for(int j=ty;j<=min(h,ty+2);j++)
            if(vis[i][j]==0 && maze[i][j]=='.')
                q.push({{i,j},ans+1}), vis[i][j]=1;
        }
        
        
        // for(int i=ty;i>=max(1,ty-2);i--)
        // if(vis[tx][i]==0 && maze[tx][i]=='.')
        // q.push({{tx,i},ans+1});
        
        // for(int i=tx;i<=min(w,tx+2);i++)
        // if(vis[i][ty]==0 && maze[i][ty]=='.')
        // q.push({{i,ty},ans+1});
        
        // for(int i=ty;i<=min(h,ty+2);i++)
        // if(vis[tx][i]==0 && maze[tx][i]=='.')
        // q.push({{tx,i},ans+1});
        
        
        
    }
    return ansfinal==INT_MAX?-1:ansfinal;
    
}
    
int main() {
	// your code goes here
   cin>>h>>w;
    cin>>x>>y;
    cin>>tfx>>tfy;
    
    for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++)
    cin>>maze[i][j];
    if(maze[tx][ty]=='#' || maze[x][y]=='#')
    cout<<"-1\n";
    else
    cout<<dfs(x,y)<<endl;
    
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:103:13: error: 'tx' was not declared in this scope; did you mean 'x'?
  103 |     if(maze[tx][ty]=='#' || maze[x][y]=='#')
      |             ^~
      |             x
a.cc:103:17: error: 'ty' was not declared in this scope; did you mean 'y'?
  103 |     if(maze[tx][ty]=='#' || maze[x][y]=='#')
      |                 ^~
      |                 y