91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

這是A*算法的最短路徑搜索代碼,代碼完整,可以直接打開運行,也可以直接拷貝到需要用的項目中。 注釋非常詳細,小白一看就能懂,附帶偽代碼 一步步看 大家多多學習又不明白可以聯系

資源截圖

代碼片段和文件信息

#include?“afx.h“
#include?“math.h“
#include?


#define X_MAX 15
#define Y_MAX 15
int?map[X_MAX][Y_MAX]?={000111100001001//0
010111100001001//1
011111100001001//2
011111100001001//3
000111100001001//4
000101111001001//5
000001101001001//6
000111111001001//7
000111101101001//8
000111110001001//9
000111101101001//10
000111110101001//10
000111101011001//12
000111110001001//13
000111100001001//14
};

struct?Node
{
Node()
{
Parant=NULL;
Child=NULL;
}
~Node()
{
delete?Parant;
delete?Child;
}
int x;
int y;
double g; //權值
double h; //到終點的距離
double f; //估價值

Node * Parant;
Node * Child;

};

std::vector m_OpenList;
std::vector::iterator m_OpenListIter;
std::vector m_CloseList;
std::vector::iterator m_CloseListIter;
std::vector m_ResultList;
std::vector::iterator m_ResultListIter;


//搜索Open中估價值最小的點
Node?*?SearchOpenSmallestNode()
{
Node?*?p;

m_OpenListIter=m_OpenList.begin();
p=*m_OpenListIter;
for?(;m_OpenListIter!=m_OpenList.end();m_OpenListIter++)
{
if((*m_OpenListIter)->ff)
{
p=*m_OpenListIter;
}
}
return?p;
}


bool?FindInOpen(Node?*?param)
{
m_OpenListIter=m_OpenList.begin();
for?(;m_OpenListIter!=m_OpenList.end();m_OpenListIter++)
{
if?((*m_OpenListIter)->x==param->x&&(*m_OpenListIter)->y==param->y)
{
return?true;
}
}
return?false;
}

bool?FindInClose(Node?*?param)
{
m_CloseListIter=m_CloseList.begin();
for?(;m_CloseListIter!=m_CloseList.end();m_CloseListIter++)
{
if?((*m_CloseListIter)->x==param->x&&(*m_CloseListIter)->y==param->y)
{
return?true;
}
}
return?false;
}

void?UpdateValue(Node?*?Param)
{

}

void?ChildNode(Node?*?parnodeint?xint?yint?xendint?yend)
{
if?(x<0||y<0||x>=X_MAX||y>=Y_MAX||map[x][y]!=1) //超出邊界
{
return;
}
Node?*?NewNode=new?Node;
NewNode->x=x;
NewNode->y=y;


bool?inOpentip=FindInOpen(NewNode);
bool?inClosetip=FindInClose(NewNode);

//不在OPEN表和CLOSE表中
if?(!inOpentip&&!inClosetip)
{
//求估價值
NewNode->g=parnode->g+1;
NewNode->h=(double)sqrtf((NewNode->x-xend)*(NewNode->x-xend)+(NewNode->y-yend)*(NewNode->y-yend));
NewNode->f=NewNode->g+NewNode->h;
NewNode->Parant=parnode;
parnode->Child=NewNode;

//加入Open鏈表
m_OpenList.push_back(NewNode);
}
else?if?(inOpentip)
{
//求估價值
double?g=parnode->g+1;
double?h=(double)sqrtf((NewNode->x-xend)*(NewNode->x-xend)+(NewNode->y-yend)*(NewNode->y-yend));
double?f=g+h;

bool?Updatetip=false;
m_OpenListIter=m_OpenList.begin();
for?(;m_OpenListI

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????3983??2014-11-17?09:16??FindPath\FindPath\FindPath.vcxproj

?????文件????????143??2014-11-15?11:32??FindPath\FindPath\FindPath.vcxproj.user

?????文件????????955??2014-11-15?11:44??FindPath\FindPath\FindPath.vcxproj.filters

?????文件???????8911??2014-11-17?10:07??FindPath\FindPath\main.cpp

?????文件????????891??2014-11-15?11:32??FindPath\FindPath.sln

????..A..H.?????12800??2014-11-17?10:09??FindPath\FindPath.suo

?????文件???????1140??2014-11-17?10:13??FindPath\偽代碼.txt

?????目錄??????????0??2014-11-15?11:32??FindPath\FindPath

?????目錄??????????0??2014-11-15?11:32??FindPath

-----------?---------??----------?-----??----

????????????????28823????????????????????9


評論

共有 條評論