#include "Stdio.h"
#include "Conio.h"
#include "stdlib.h"
#include "math.h"
void Copy_node(struct node *p1,struct node *p2);
void Calculate_f(int deepth,struct node *p);
void Add_to_open(struct node *p);
void Add_to_closed(struct node *p);
void Remove_p(struct node *name,struct node *p);
int Test_A_B(struct node *p1,struct node *p2);
struct node * Solution_Astar(struct node *p);
void Expand_n(struct node *p);
struct node * Search_A(struct node *name,struct node *temp);
void Print_result(struct node *p);
/* 定义 8 数码的节点状态 */
typedef struct node
{
int s[3][3]; //当前 8 数码的状态
int i_0; //当前空格所在行号
int j_0; //当前空格所在列号
int f; //当前代价值
int d; //当前节点深度
int h; //启发信息,采用数码“不在位”距离和
struct node *father; //指向解路径上该节点的父节点
struct node *next; //指向所在 open 或 closed 表中的下一个元素
};
struct node s_0={{3,8,2,1,0,5,7,6,4},1,1,0,0,0,NULL,NULL}; //定义初始状态
struct node s_g={{1,2,3,8,0,4,7,6,5},1,1,0,0,0,NULL,NULL}; //定义目标状态
struct node *open=NULL; //建立 open 表指针
struct node *closed=NULL; //建立 closed 表指针
int sum_node=0; //用于记录扩展节点总数
int main(void)
{
struct node s,*target;
Copy_node(&s_0,&s);
Calculate_f(0,&s); //拷贝 8 数码初始状态,初始化代价值
target=Solution_Astar(&s); //求解主程序
if(target) Print_result(target); //输出解路径
else printf("问题求解失败!");