資源簡介
cocox3.15.12.zip

代碼片段和文件信息
#include?“Astar.h“
struct?Astar::AstartNode
{
//此節(jié)點在堆中的位置
int?iHeapPosition?=?-1;
int?iG?=?-1;
int?iH?=?-1;
int?iF?=?-1;
//檢測是否可以通過
int?iColor?=?-1;
//檢測是否在開啟列表中
int?isOpen?=?0;
Astar::VecInt?father;
int?getF(){?return?iH?+?iG;?}
};
void?Astar::cHeap::removeFront(Astar::AstartNode**g_Map)
{
if?(vecs.size()?==?0)
return;
g_Map[vecs[vecs.size()?-?1].x][vecs[vecs.size()?-?1].y].iHeapPosition?=?0;
g_Map[vecs[0].x][vecs[0].y].iHeapPosition?=?-1;
vecs[0]?=?vecs[vecs.size()?-?1];??????//用最后一個元素把第一個元素覆蓋掉,即為刪除
vecs.pop_back();????????????????//刪除容器尾巴元素
int?currentIndex?=?0;
while?(currentIndex? {
int?leftChildIndex?=?2?*?currentIndex?+?1;
int?rightChildIndex?=?2?*?currentIndex?+?2;
//已經(jīng)到最底層,結(jié)束
if?(rightChildIndex?>?vecs.size())
break;
int?minIndex?=?leftChildIndex;
//有兩個孩子,找出兩個孩子節(jié)點中F值最低的元素
if?(rightChildIndex?g_Map[vecs[rightChildIndex].x][vecs[rightChildIndex].y].getF()))
{
minIndex?=?rightChildIndex;
}
//如果當(dāng)前節(jié)點的F值?大于?他孩子節(jié)點的F值,則交換
if?(g_Map[vecs[currentIndex].x][vecs[currentIndex].y].getF()?>?g_Map[vecs[minIndex].x][vecs[minIndex].y].getF())
{
VecInt?temp?=?vecs[minIndex];
vecs[minIndex]?=?vecs[currentIndex];
vecs[currentIndex]?=?temp;
//同步保存地圖中該坐標(biāo)在堆中的最新位置
g_Map[vecs[currentIndex].x][vecs[currentIndex].y].iHeapPosition?=?currentIndex;
g_Map[vecs[minIndex].x][vecs[minIndex].y].iHeapPosition?=?minIndex;
currentIndex?=?minIndex;
}
else
{
break;
}
}
}
void?Astar::cHeap::push_back(const?VecInt&?element?Astar::AstartNode**g_Map)
{
vecs.push_back(element);//把新節(jié)點添加到堆的末尾
int?currentIndex?=?vecs.size()?-?1;
g_Map[vecs[currentIndex].x][vecs[currentIndex].y].iHeapPosition?=?currentIndex;?//保存該坐標(biāo)在堆中的位置
while?(currentIndex?>?0)?//不斷的與他的父節(jié)點比較,直到該新節(jié)點的F值大于他的父節(jié)點的F值為止?或者?該新節(jié)點到了堆首
{
int?parentIndex?=?(currentIndex?-?1)?/?2;
if?(g_Map[vecs[currentIndex].x][vecs[currentIndex].y].getF()? {
VecInt?temp?=?vecs[currentIndex];
vecs[currentIndex]?=?vecs[parentIndex];
vecs[parentIndex]?=?temp;
//同步保存地圖中該坐標(biāo)在堆中的最新位置
g_Map[vecs[currentIndex].x][vecs[currentIndex].y].iHeapPosition?=?currentIndex;
g_Map[vecs[parentIndex].x][vecs[parentIndex].y].iHeapPosition?=?parentIndex;
currentIndex?=?parentIndex;
continue;
}
else
{
break;
}
}
}
void?Astar::cHeap::newHeap(int?position?Astar::AstartNode**g_Map)
{
int?currentIndex?=?position;
int?parentIndex;
//while?(currentIndex?>?0)?//如果該元素新的F值比他的父節(jié)點的F值小,交換
//{
// parentIndex?=?(currentIndex?-?1)?/?2;
// if?(g_Map[v[currentIndex].sx][v[currentIndex].sy].getF()?? // {
// Coordinate?temp?=?v[currentIndex];
// v[currentIndex]?=?v[parentIndex];
// v[parentIndex]?=?temp;
// g_Map[v[
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-09-30?05:02??cocox3.15.1\ba
?????文件????????1111??2017-07-04?12:12??cocox3.15.1\ba
?????文件???????11015??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????1330??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????375??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????3176??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????280??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????431??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????6608??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????155??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????817??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????146??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????3924??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????1274??2017-07-04?12:12??cocox3.15.1\ba
?????文件????????1308??2017-07-04?12:12??cocox3.15.1\ba
?????文件??????372809??2017-07-04?12:12??cocox3.15.1\ba
?????文件?????????420??2017-07-04?12:12??cocox3.15.1\ba
?????目錄???????????0??2017-09-30?05:02??cocox3.15.1\coco\
?????文件????????1871??2017-07-04?12:12??cocox3.15.1\coco\ccc.h
?????文件????????1193??2017-07-04?12:12??cocox3.15.1\coco\cfg2.cpp
?????文件?????????463??2017-07-04?12:12??cocox3.15.1\coco\cfg2.h
?????文件???????10462??2017-09-30?03:26??cocox3.15.1\coco\cocoMacro.h
?????目錄???????????0??2017-09-30?05:02??cocox3.15.1\cocos\
?????目錄???????????0??2017-09-30?05:02??cocox3.15.1\cocos\2d\
?????文件????????7692??2017-05-04?09:54??cocox3.15.1\cocos\2d\CCAction.cpp
?????文件???????13793??2017-09-29?17:33??cocox3.15.1\cocos\2d\CCAction.h
?????文件????????6529??2017-05-04?09:54??cocox3.15.1\cocos\2d\CCActionCamera.cpp
?????文件????????5057??2017-05-04?09:54??cocox3.15.1\cocos\2d\CCActionCamera.h
?????文件???????13955??2017-05-04?09:54??cocox3.15.1\cocos\2d\CCActionCatmullRom.cpp
?????文件????????9878??2017-05-04?09:54??cocox3.15.1\cocos\2d\CCActionCatmullRom.h
?????文件???????10009??2017-09-30?04:08??cocox3.15.1\cocos\2d\CCActionEase.cpp
............此處省略739個文件信息
評論
共有 條評論