本文整理汇总了C++中FindPath函数的典型用法代码示例。如果您正苦于以下问题:C++ FindPath函数的具体用法?C++ FindPath怎么用?C++ FindPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FindPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenFile
CString XMLSerialized::LoadInfo(const CString& sName,TagType tagType,const CString parent=L""){
CMarkup xml = OpenFile();
if(tagType== TagType::Element){
if(FindPath(sName,&xml))
return xml.GetData();
}
if(tagType== TagType::Attribute){
if(FindPath(parent,&xml))
return xml.GetAttrib(sName);
}
return L"";
}
示例2: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
unsigned char pMap[] = { 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 };
int pOutBuffer[12];
const int result1 = FindPath(0, 0, 1, 2, pMap, 4, 3, pOutBuffer, 12);
Output(pOutBuffer, result1);
unsigned char pMap2[] = { 0, 0, 1, 0, 1, 1, 1, 0, 1 };
int pOutBuffer2[7];
const int result2 = FindPath(2, 0, 0, 2, pMap2, 3, 3, pOutBuffer2, 7);
Output(pOutBuffer, result2);
system("PAUSE");
return 0;
}
示例3: startPos
bool NavGrid::FindPath(const CU::Vector3f& aStartPoint, const CU::Vector3f& aEndPoint, CU::GrowingArray<CU::Vector2f>& aOutPath)
{
CU::Vector2i startPos(static_cast<int>(aStartPoint.x), static_cast<int>(aStartPoint.z));
CU::Vector2i endPos(static_cast<int>(aEndPoint.x), static_cast<int>(aEndPoint.z));
return FindPath(startPos, endPos, aOutPath);
}
示例4: TestSparsePerformance
void TestSparsePerformance(bool outputMap)
{
int cellSize = 16;
int w = 40;
int h = 100;
double map = CreateSparseMap(w*cellSize,h*cellSize,cellSize);
//map = CreateMap(w*cellSize,h*cellSize,cellSize);
SetCellMap(map, 4*cellSize, 4*cellSize, 1);
SetCellMap(map, 5*cellSize, 4*cellSize, 1);
SetCellMap(map, 5*cellSize, 5*cellSize, 1);
SetCellMap(map, 5*cellSize, 6*cellSize, 1);
SetCellMap(map, 5*cellSize, 7*cellSize, 1);
SetCellMap(map, 4*cellSize, 7*cellSize, 1);
SetCellMapRegion(map, (w/2)*cellSize, 0*cellSize, 2*cellSize, (h*0.75)*cellSize, 1);
//SetCellMapRegion(map, (w/2)*cellSize, (h/2+1)*cellSize, 2*cellSize, (h/2-2)*cellSize, 1);
#ifndef _DEBUG
double pathFinder = CreatePathFinder(map);
#else
double mapDebug = CreateMap(w*cellSize,h*cellSize,cellSize);
double pathFinder = CreatePathFinderDebug(map, mapDebug);
#endif
double path = FindPath(pathFinder, 2.0*cellSize, 8.0*cellSize, (w-2)*cellSize, 2.0*cellSize);
if (outputMap)
{
OutputPath(map, path);
}
DestroyMap(map);
DestroyPathFinder(pathFinder);
DestroyPath(path);
#ifdef _DEBUG
DestroyMap(mapDebug);
#endif
}
示例5: ComputeDir
void CRole::SetDst(Pos pos)
{
m_bBeginFindPath = false;
m_fdst = m_dst = pos;
ComputeDir();
int x = (int)(m_fdst.x/m_pMap->m_tileWidth);
int y = (int)(m_fdst.y/m_pMap->m_tileHeight);
if(!m_pMap->Passable(x, y))//如果目标不可到达
{
int bestx;int besty;
m_bestPosFinder->FindBestPos(x, y, &bestx, &besty, m_pMap->m_map);//寻找最近可走点
m_fdst.x = (float)bestx*m_pMap->m_tileWidth;
m_fdst.y = (float)besty*m_pMap->m_tileHeight;
//printf("%d %d\n", bestx, besty);
}
ClearPath();
//int t=timeGetTime(); //计算寻路时间
FindPath(&m_pos, &m_fdst);
//printf("寻路消耗时间: %d\n",timeGetTime()-t); //
if(GetNextPos(&m_dst,
(float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2))
ComputeDir();
else
SetStop();
}
示例6: FindPath
void Operator::CalcPEC_Curves()
{
//special treatment for primitives of type curve (treated as wires)
double p1[3];
double p2[3];
struct Grid_Path path;
vector<CSProperties*> vec_prop = CSX->GetPropertyByType(CSProperties::METAL);
for (size_t p=0; p<vec_prop.size(); ++p)
{
CSProperties* prop = vec_prop.at(p);
for (size_t n=0; n<prop->GetQtyPrimitives(); ++n)
{
CSPrimitives* prim = prop->GetPrimitive(n);
CSPrimCurve* curv = prim->ToCurve();
if (curv)
{
for (size_t i=1; i<curv->GetNumberOfPoints(); ++i)
{
curv->GetPoint(i-1,p1);
curv->GetPoint(i,p2);
path = FindPath(p1,p2);
if (path.dir.size()>0)
prim->SetPrimitiveUsed(true);
for (size_t t=0; t<path.dir.size(); ++t)
{
SetVV(path.dir.at(t),path.posPath[0].at(t),path.posPath[1].at(t),path.posPath[2].at(t), 0 );
SetVI(path.dir.at(t),path.posPath[0].at(t),path.posPath[1].at(t),path.posPath[2].at(t), 0 );
++m_Nr_PEC[path.dir.at(t)];
}
}
}
}
}
}
示例7: start
//移动地图到目的坐标,同可移动对象的移动类似
void CGameMap::MoveTo(Point goal)
{
m_Paths.clear();
std::vector<Point>* Paths = &m_Paths;
Point start((int)m_CurrentXY.x, (int)m_CurrentXY.y);
FindPath(start, goal, Paths, m_pMapAstar);
//寻路失败,寻不到路或者寻路地址即为源地址
if(m_Paths.empty())
{
m_bArrived = true;
}
//寻路成功
else
{
//平滑路径
CActiveObject::SmoothPath(m_Paths, 50);
//当前Paths最后一个元素为当前位置
m_Paths.pop_back();
__Move1Step();
m_bArrived = false;
}
}
示例8: KillLoop
virtual void KillLoop(VertexId start, VertexId finish, const set<VertexId> &component) {
vector<EdgeId> path = FindPath(start, finish, component);
set<EdgeId> edges(path.begin(), path.end());
if(path.size() > 0 || start == finish) {
// if(start != finish || component.size() > 2)
if(/*!CheckStrong(component) || */!CheckNotMuchRemoved(edges, component)) {
return;
}
/*
cout << this->g().int_id(start) << " " << this->g().int_id(finish) << endl;
cout << this->g().VertexNucls(start) << endl;
for(auto it = component.begin(); it != component.end(); ++it) {
vector<EdgeId> outgoing = this->g().OutgoingEdges(*it);
for(auto eit = outgoing.begin(); eit != outgoing.end(); ++eit) {
if(component.count(this->g().EdgeEnd(*eit)) == 1) {
cout << this->g().int_id(*it) << " -> " << this->g().int_id(this->g().EdgeEnd(*eit)) << " : " << this->g().length(*eit) << " : " << edges.count(*eit) << " : " << this->g().int_id(*eit) << endl;
}
}
}
*/
RemoveExtraEdges(edges, component);
RemoveIsolatedVertices(component);
}
}
示例9: FindPath
void
ProfileListWidget::SelectPath(const TCHAR *path)
{
auto i = FindPath(path);
if (i >= 0)
GetList().SetCursorIndex(i);
}
示例10: main
void main(void)
{
welcome();
InputMaze();
if (FindPath()) OutputPath();
else cout << "No path" << endl;
}
示例11: FindPath
void BinTree::FindPath(int expectedSum) {
if (pHead == NULL)
return ;
std::vector<int> path;
int currentSum = 0;
FindPath (pHead,expectedSum,path,currentSum);
}
示例12: path_check2
void path_check2(){
printf("Testing FindPath(...) on World2\n");
int i, j;
Grid *g;
g = ReadWorld("world2.txt");
Search *s;
s = FindPath(g);
assert_i(s->Length, -1, "Shortest path length - World2");
assert_i(stack_size(s->s), s->Length+1, "Stack size - World2");
int actual[14][17] = {{5000, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT},
{5000, 10, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, MAX_INT, MAX_INT, MAX_INT},
{5000, 9, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, MAX_INT, MAX_INT, MAX_INT},
{5000, 8, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, MAX_INT},
{5000, 7, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, MAX_INT},
{5000, 6, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, MAX_INT},
{5000, 5, 4, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, 16, 17, MAX_INT},
{5000, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, MAX_INT, 17, 18, MAX_INT},
{5000, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, MAX_INT, 18, 19, MAX_INT},
{5000, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, MAX_INT, 19, 20, MAX_INT},
{5000, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT, MAX_INT}};
int correct_dist = 1;
// Compare Calculated Distances to Model Solution.
for(i = 0; i < g->rows; i++){
for(j = 0; j < g->cols; j++){
if(actual[i][j] != s->Distance[i][j]){
correct_dist = 0;
}
}
}
assert_i(correct_dist, 1, "Distance Array - World2");
}
示例13: updateMap
void updateMap() {
for(int i = 0; i < mapWidth; ++i) {
for(int j = 0; j < mapHeight; ++j) {
QGraphicsRectItem* rect = rects[RectsKey(j, i)];
if(pMap[i*mapWidth+j] == 0)
rect->setBrush(QBrush(Qt::blue));
if(pMap[i*mapWidth+j] == 1)
rect->setBrush(QBrush(Qt::red));
}
}
int pOutBuffer[128];
int nNumSteps = FindPath(startX, startY, endX, endY, pMap, mapWidth, mapHeight, pOutBuffer, 128);
for(int i = 0; i < nNumSteps; i++) {
int y = pOutBuffer[i]/mapWidth;
int x = pOutBuffer[i] - y*mapWidth;
QGraphicsRectItem* rect = rects[RectsKey(x, y)];
rect->setBrush(QBrush(Qt::green));
}
if(startX != -1 && startY != -1)
{
QGraphicsRectItem* rect = rects[RectsKey(startX, startY)];
rect->setBrush(QBrush(Qt::green));
}
if(endX != -1 && endY != -1)
{
QGraphicsRectItem* rect = rects[RectsKey(endX, endY)];
rect->setBrush(QBrush(Qt::gray));
}
}
示例14: rand
void Enemy::GenerateRandomPath()
{
pathStatus = PathFinder::NONEXISTENT;
for( int i = 0 ; i < numberOfRandomPathPoints ; i++ )
{
do{
target.x = rand()%( 2 * MovementVector.x ) + ( startPosition.x - MovementVector.x );
target.y = rand()%( 2 * MovementVector.y ) + ( startPosition.y - MovementVector.y );
// std::cout<<target.x<<" "<<target.y<<"\n";
pathSearched = false;
if( (target.x/32 != myPosition.x/32) &&
(target.y/32 != myPosition.y/32) )
{
if( FindPath( target ) == PathFinder::FOUND )
{
pathStatus = PathFinder::NONEXISTENT;
randomPatrolPath[i] = pathfinderPath;
break;
}
}
}while( pathStatus != PathFinder::FOUND );
}
}
示例15: bm_Periodical_1s
void bm_Periodical_1s()
{
for (u32 i=0;i<del_blocks.size();i++)
delete del_blocks[i];
del_blocks.clear();
if (rebuild_counter>0) rebuild_counter--;
#if HOST_OS==OS_WINDOWS && 0
std::sort(all_blocks.begin(),all_blocks.end(),UDgreaterX);
map<u32,u32> vmap;
map<u32,u32> calls;
u32 total_runs=0;
for(int i=0;i<all_blocks.size();i++)
{
RuntimeBlockInfo* rbi=all_blocks[i];
total_runs+=rbi->runs;
if (rbi->BranchBlock!=-1 && rbi->BranchBlock < rbi->addr)
{
if (rbi->BlockType==BET_Cond_0 || rbi->BlockType==BET_Cond_1 || rbi->BlockType==BET_StaticJump)
{
RuntimeBlockInfo* bbi=bm_GetBlock(all_blocks[i]->BranchBlock);
if (bbi && bbi->runs)
{
vmap[all_blocks[i]->BranchBlock]=bbi->runs;
}
}
if (rbi->BlockType==BET_StaticCall)
{
RuntimeBlockInfo* bbi=bm_GetBlock(all_blocks[i]->BranchBlock);
if (bbi && bbi->runs)
{
calls[all_blocks[i]->BranchBlock]+=rbi->runs;
}
}
}
verify(rbi->NextBlock>rbi->addr);
}
map<u32,u32>::iterator iter=vmap.begin();
total_saved=0;
u32 total_l_runs=0;
while(iter!=vmap.end())
{
FindPath(iter->first);
total_l_runs+=iter->second;
iter++;
}
for(int i=0;i<all_blocks.size();i++)
all_blocks[i]->runs=0;
printf("Total Saved: %.2f || Total Loop Runs: %.2f || Total Runs: %.2f\n",total_saved/1000.f,total_l_runs/1000.f,total_runs/1000.f);
#endif
}