?? 搜索算法.h
字號:
#include "常數(shù)定義.h"
#define MAXINT 8192 //定義一個最大整數(shù), 地圖上任意兩點(diǎn)距離不會超過它8192
#define STACKSIZE 40000 //保存搜索節(jié)點(diǎn)的堆棧大小65536
#define tile_num(x,y) ((y)*map_w+(x)) //將 x,y 坐標(biāo)轉(zhuǎn)換為地圖上塊的編號
#define tile_x(n) ((n)%map_w) //由塊編號得出 x,y 坐標(biāo)
#define tile_y(n) ((n)/map_w)
//定義結(jié)構(gòu)----------------------------------------------------------------------
typedef struct node *TREE;// 樹結(jié)構(gòu)
struct node
{int h; int tile; TREE father;};
typedef struct node2 *LINK;// 樹結(jié)構(gòu)
struct node2
{ TREE node; int f; LINK next;};
//---------------------------------------------
class findpt
{public: findpt(); //構(gòu)造函數(shù)
virtual~findpt(); //析構(gòu)函數(shù)
public://公有,外部可調(diào)用
int path[MAXINT];
char map[WIDTH*SCRP/GX+2][HEIGHT*SCRP/GY+2]; //地圖障礙格數(shù)據(jù)
short int dis_map[WIDTH*SCRP/GX+2][HEIGHT*SCRP/GY+2];//保存搜索路徑時,中間目標(biāo)地最優(yōu)解
int map_w,map_h; //地圖障礙格寬和高
int start_x,start_y,end_x,end_y; //起點(diǎn)坐標(biāo),終點(diǎn)坐標(biāo)
int findpath(); //路徑尋找主函數(shù)
private://私有,類內(nèi)部使用
LINK queue; //保存沒有處理的行走方法的節(jié)點(diǎn)
TREE stack[STACKSIZE]; //保存已經(jīng)處理過的節(jié)點(diǎn)(搜索完后釋放)
int stacktop;
void init_queue(); // 初始化隊(duì)列
void enter_queue(TREE node,int f); //待處理節(jié)點(diǎn)入隊(duì)列,依靠對目的地估價距離插入排序
TREE get_from_queue(); //將離目的地估計(jì)最近的方案出隊(duì)列
void freetree(); //釋放申請過的所有節(jié)點(diǎn)
int judge(int x,int y); //估價函數(shù),估價x,y到目的地的距離,估計(jì)值必須保證比實(shí)際值小
int trytile(int x,int y,TREE father);//嘗試下一步移動到x,y可行否
};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -