Language: C++

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    int C_h,C_w;
    int D_h,D_w;
    cin >> C_h >> C_w;
    cin >> D_h >> D_w;
    int S[H][W];
    string str[H];
    for(int i=0;i<H;i++){
      cin >> str[i];
        for(int j=0;j<W;j++){
          cerr << str[i][j] << endl;
            if(str[i][j]=='#') S[i][j] = 1;
            else S[i][j] = 0;
        }
    }
    if(S[D_h-1][D_w-1]==1) return (-1);
    int count = 0;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            if(i==0 && j==0) continue;
            if(S[D_h-1-i][D_w-1-j]==0) count++;
            if(S[D_h-1+i][D_w-1+j]==0) count++;
        }
    }
    if(count==0) return (-1);
    int next_h = C_h;
    int next_w = C_w;
    int kakutei_h = next_h;
    int kakutei_w = next_w;

    int i = 0;
    int j = 0;
    int a1 = 1:
    int a2 = 1;
    int a3 = 1;
    int a4 = 1;
    while(!(kakutei_h == D_h-1 && kakutei_w == D_w-1)){
        int before_h = 0;
        int before_w = 0;
        if(a1==1 && a2==0 && a3==0 && a4==0){
            kakutei_h = next_h + 1;
            kakutei_w = next_w;
        } else if(a1==0 && a2==1 && a3==0 && a4==0){
            kakutei_h = next_h - 1;
            kakutei_w = next_w;
        }else if(a1==0 && a2==0 && a3==1 && a4==0){
            kakutei_h = next_h;
            kakutei_w = next_w + 1;
        }else if(a1==0 && a2==0 && a3==0 && a4==1){
            kakutei_h = next_h;
            kakutei_w = next_w - 1;
        }
        
        if(a1==1){//n
            before_h = next_h;
            next_h = next_h+1;
            if(S[next_h][next_w]==1 || next_h>H-1){
                next_h = before;
                a1 = 0;
            }
        }else if(a2==1){//s
            before_h = next_h;
            next_h = next_h-1;
            if(S[next_h][next_w]==1 || next_h<0){
                next_h = before;
                a2 = 0;
            }
        }else if(a3==1){//e
            before_w = next_w;
            next_w = next_w+1;
            if(S[next_h][next_w]==1 || next_w>W-1){
                next_w = before;
                a3 = 0;
            }
        }else if(a4==1){//w
            before_w = next_w;
            next_w = next_w-1;
            if(S[next_h][next_w]==1 || next_w<0){
                next_w = before;
                a4 = 0;
            }
        }
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:15: error: expected ',' or ';' before ':' token
   43 |     int a1 = 1:
      |               ^
a.cc:50:21: error: 'a2' was not declared in this scope; did you mean 'a4'?
   50 |         if(a1==1 && a2==0 && a3==0 && a4==0){
      |                     ^~
      |                     a4
a.cc:68:26: error: 'before' was not declared in this scope; did you mean 'before_w'?
   68 |                 next_h = before;
      |                          ^~~~~~
      |                          before_w
a.cc:71:18: error: 'a2' was not declared in this scope; did you mean 'a4'?
   71 |         }else if(a2==1){//s
      |                  ^~
      |                  a4
a.cc:75:26: error: 'before' was not declared in this scope; did you mean 'before_w'?
   75 |                 next_h = before;
      |                          ^~~~~~
      |                          before_w
a.cc:82:26: error: 'before' was not declared in this scope; did you mean 'before_w'?
   82 |                 next_w = before;
      |                          ^~~~~~
      |                          before_w
a.cc:89:26: error: 'before' was not declared in this scope; did you mean 'before_w'?
   89 |                 next_w = before;
      |                          ^~~~~~
      |                          before_w