資源簡介
具體功能如下:
建立一個m*n的矩陣迷宮并至少有一個入口和出口,0和1分別表示迷宮中的通路和障礙;
探索從迷宮入口到出口有無通路,若有,則計算出通路的路徑,通路以(I,j,d)三元素表示,i、j分別表示迷宮中的坐標,d表示走到下一坐標的方向。若沒有,則給出相應信息;
最后以矩陣形式輸出迷宮和通路。
代碼片段和文件信息
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????//?
//?????????????????????????????????????????????????尋路問題???????????????????????????????????????????????????????????????????//?
//??????????????????????????????????Created?by?王永欣?????All?rights?reserved?????????????????????????????????????????????????//?
//???????????????????????????????????????Last??revised?in?2017/5/19?14:14?????????????????????????????????????????????????????//
//????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include
#include
#include
using?namespace?std;
class?OpenList;
class?CloseList;
class?Map;
class?ReFindWay;
class?Data
{
private:
int?X;//X坐標?
int?Y;//Y坐標?
int?Status;//狀態(tài)?1為不通?0為通?2為通但不是最佳路徑?3為無視該地形?
bool?ISINOPEN;//是否在Open表中?
bool?ISINCLOSE;//是否在Close表中?
int?FCOST;//F值?
int?GCOST;//G值(實際花費)?
int?HCOST;//H值(估計花費,曼哈頓距離)?
int?Level;//第幾步?
Data?*next;//open表的下指針?
Data?*before;//open表的前指針?
Data?*next2;//close表的下指針?
Data?*before2;//close表的前指針?
Data?*father;//它的上一節(jié)點?
Data?*newnext;//ReFindWay?next
public:
friend?class?OpenList;
friend?class?CloseList;
friend?class?Map;
friend?class?ReFindWay;
Data()
{
Status=1;
ISINCLOSE=false;
ISINOPEN=false;
GCOST=0;
HCOST=0;
FCOST=0;
Level=0;
next=NULL;
before=NULL;
next2=NULL;
before2=NULL;
father=NULL;
newnext=NULL;
}
void?printf()//輸出單個數(shù)據(jù)的信息?
{
cout<<“(“< if(ISINOPEN)
{
cout<<“In?Open???“;
}
if(ISINCLOSE)
{
cout<<“In?Close“;
}
cout< }
};
class?CloseList//close表?
{
private:
Data?*first;
Data?*find;
int?length;
public:
friend?class?Map;
CloseList()
{
first=NULL;
find=NULL;
length=0;
}
void?Add(Data?*&p)//將p添加進close表?
{
if(length==0)
{
first=p;
length++;
find=first;
p->ISINCLOSE=true;
}
else
{
find->next2=p;
p->before2=find;
p->ISINCLOSE=true;
length++;
find=find->next2;
}
}
void?Delete(bool?decide)//刪除最近添加的數(shù)據(jù)?decide決定該點是不是2?
{
if(length==0)
{
cout<<“CloseList?is?Empty“< }
else
{
if(length==1)
{
first->ISINCLOSE=false;
if(decide)
{
first->Status=2;
}
first=NULL;
find=NULL;
length--;
}
else
{
if(decide)
{
find->Status=2;
}
find->ISINCLOSE=f
- 上一篇:C語言編寫的猜數(shù)游戲
- 下一篇:定義一個數(shù)組類
評論
共有 條評論