void ida_star(node_t cur, int dp, int max_deep) { node_t nxt; int f = dist(cur); int tx, ty, x, y, t, i; if(f + dp > max_deep || found) return; if(f == 0) { output(); found = 1; return; } x = cur.px; y = cur.py; for(i = 0;i < 4; i++) { tx = x + dx[i]; ty = y + dy[i]; if(tx < 1 || tx > 3 || ty < 1 || ty > 3) continue; memcpy(&nxt, &cur, sizeof(cur)); nxt.stat[x][y] = nxt.stat[tx][ty]; nxt.stat[tx][ty] = 9; nxt.px = tx; nxt.py = ty; stack[++top] = i; ida_star(nxt, dp + 1, max_deep); --top; } }
static void run_ida_star(t_sys *sys) { if (ida_star(sys, sys->open->state)) { push(&(sys->win_path), sys->open->state); print_list(sys, sys->win_path); } else printf("npuzzle can't be resolve\n"); }
int main() { int i; init(); if(is_ok(st) == 0) { printf("unsolvable\n"); return 0; } found = 0; while(found == 0) { top = 0; ida_star(st, 0, max_deep); max_deep++; } return 0; }
int main() { while(init()) ida_star(); return 0; }