Language: C++

#include <stdio.h>
#include <stdlib.h>

#define N 4
#define NN N*N
#define LIMIT 100

int H[NN][NN];//マンハッタン距離の組み合わせの集合
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0}; //方向
int states_count = 0;

void swap(int *x,int *y){
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

typedef struct puzzle
{
  int field[NN];//どの場所になんの数字が入っているか
  int space;//空マス
  int h_value;//マンハッタン距離
}Puzzle;

Puzzle state;//現在の状態
int limit;//深さの制限
int path[LIMIT];

int heuristic(Puzzle pz){
  int sum = 0;
  int i;
  for(i=0; i<NN; i++){
    if(pz.field[i] == NN)continue; //正しい位置にあればそのまま
    sum += H[i][pz.field[i] - 1];//マンハッタン距離を加える
  }
  return sum;
}

int isSolved(){
  int i;
  for (int i = 0; i < N2; ++i)if(state.field[i] != i+1)return 0;
  return 1;
}

int dfs(int depth, int prev){
  states_count++;
  if(state.h_value == 0)return 1; //終了
  if(depth + state.h_value > limit)return 0;

  int sx = state.space / N; //空のマスのx座標;
  int sy = state.space % N; //空のマスのy座標;

  Puzzle tmp;
  int r;
  for(r = 0;r < 4;r++){
    int tx = sx + dx[r]; //空のマスの次の位置
    int ty = sy + dy[r];
    if(tx < 0|| ty <0||tx >= N||ty >= N)continue; //行けないマスはスルー
    if((prev - r == 2)||(prev - r == -2))continue;//一個前の状態に戻る操作はスルー
    tmp = state;
    state.h_value -= H[tx * N + ty][state.field[tx * N + ty]-1];//入れ替わった分のマンハッタンん距離の増減を加算
    state.h_value += H[sx * N + sy][state.field[tx * N + ty]-1];
    swap(&state.field[tx * N + ty],&state.field[sx * N + sy]);
    state.space = tx * N + ty;
    if(dfs(depth+1,r) != 0){path[depth] = r; return 1;}
    state = tmp;
  }
  return 0;
}

int iterative_deepening(Puzzle in){
  in.MD = heuristic(in);

  for(limit = in.h_value;limit <= LIMIT; limit++){//limit = c
    state = in;
    if(dfs(0,-100) != 0){
      //pathに入っている文字数を数えたい
      int count = 0,l;
      for(l=0;l<limit;l++){
        if(path[l] != ' ')count++;
      }
      return count;

    }
  }
  return -1;
}

int main(void){
  int i,j;
  for(i=0;i<NN;i++){
    for(j=0;j<NN;j++){
      H[i][j] = abs(i/N - j/N) + abs(i%N -j%N);//マンハッタン距離の組み合わせの初期化
    }
  }

  Puzzle in;//初期のパズル

  for(i=0;i<N2;i++){
    scanf("%d", &in.f[i]);
    if(in.f[i]==0){
      in.f[i] = N2;
      in.space = i;
    }
  }

  int ans = iterative_deepening(in);
  printf("%d\n",ans);
  //printf("states_count = %d\n", states_count);
  return 0;

}


Compiler output:
a.cc: In function 'int isSolved()':
a.cc:43:23: error: 'N2' was not declared in this scope; did you mean 'NN'?
   43 |   for (int i = 0; i < N2; ++i)if(state.field[i] != i+1)return 0;
      |                       ^~
      |                       NN
a.cc: In function 'int iterative_deepening(Puzzle)':
a.cc:74:6: error: 'Puzzle' {aka 'struct puzzle'} has no member named 'MD'
   74 |   in.MD = heuristic(in);
      |      ^~
a.cc: In function 'int main()':
a.cc:101:13: error: 'N2' was not declared in this scope; did you mean 'NN'?
  101 |   for(i=0;i<N2;i++){
      |             ^~
      |             NN
a.cc:102:21: error: 'Puzzle' {aka 'struct puzzle'} has no member named 'f'
  102 |     scanf("%d", &in.f[i]);
      |                     ^
a.cc:103:11: error: 'Puzzle' {aka 'struct puzzle'} has no member named 'f'
  103 |     if(in.f[i]==0){
      |           ^
a.cc:104:10: error: 'Puzzle' {aka 'struct puzzle'} has no member named 'f'
  104 |       in.f[i] = N2;
      |          ^