- 24
- 0
- 约1.51万字
- 约 8页
- 2020-09-13 发布于天津
- 举报
#include iostream
#include time.h
#include windows.h
#include vector
#include cmath
using namespace std;
struct node{
int a[3][3]; // 存放矩阵
int father; // 父节点的位置
int gone; // 是否遍历过 ,1 为是 ,0 为否
int fn; // 评价函数的值
int x,y; // 空格的坐标
int deep; // 节点深度
};
vectornode store; // 存放路径节点
int mx[4]={-1,0,1,0};
int my[4]={0,-1,0,1}; // 上下左右移动数组
int top; // 当前节点在 store 中的位置
bool check( int num) // 判断 store[num] 节点与目标节点是否相同 , 目标节点储存在 store[0]
中
{
for ( int i=0;i3;i++){
for ( int j=0;j3;j++){
if (store[num].a[i][j]!=store[0].a[i][j])
return false ;
}
}
return true ;
}
bool search( int num) // 判断 store[num] 节点是否已经扩展过 , 没有扩展返回 true
{
int pre=store[num].father; //pre 指向 store[num] 的父节点位置
bool test= true ;
while (!pre){ // 循环直到 pre 为0, 既初始节点
for ( int i=0;i3;i++){
for ( int j=0;j3;j++){
if (store[pre].a[i][j]!=store[num].a[i][j]){
test= false ;
精选文库
break ;
}
}
if (test== false ) break ;
}
if (test== true ) return false ;
pre=store[pre].father; //pre 继续指向 store[pre]
原创力文档

文档评论(0)