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

  • 大小: 9KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-12
  • 語言: 其他
  • 標簽: C++??AStar算法??

資源簡介

使用AStar算法實現(xiàn)了一個簡單的demo,親測可用,代碼不多流程簡單,一看就會

資源截圖

代碼片段和文件信息

#include?“astar.h“
#include?
#include?

AStar::AStar(int?row?int?col)
{
????m_col?=?col;
????m_row?=?row;
}

AStar::~AStar()
{
????openList.clear();
????closeList.clear();
????obstacleList.clear();
}


void?AStar::lookPath(NodeItem?&start?NodeItem?&goal)
{
????this->goal?=?goal;
????openList.clear();
????closeList.clear();
????//把起點插入到開啟列表本函數(shù)插入元素按照元素的f(x)值進行升序排序保證第一個元素的f(x)值最小
????addToOpenList(start);
????list::iterator?it;
????while?(openList.size())?{
????????it?=?openList.begin();
????????//取出f(x)值最小的元素
????????NodeItem?first?=?*it;
????????qDebug()<<“node?X:“<????????if(*it?==?goal)
????????{
????????????qDebug()<<(*it).parent->x<<(*it).parent->y;
????????????addPathNodeListByGoal(*it);
????????????qDebug()<<“finished=============addPathNodeListByGoal“;
????????????break;
????????}
????????openList.pop_front();
????????//把這個元素周圍能到達的點添加進開啟列表添加后按照元素的f(x)值的大小進行排序(建議使用二分法把當前元素插入開啟列表)
????????closeList.push_back(*it);
????????addNeighBorNode(first);
????}
????printPathNodeList();
}

void?AStar::addNode(const?NodeItem?¢er?int?direct)
{

}

void?AStar::addNeighBorNode(const?NodeItem?¢er)
{
????qDebug()<<“Center?x:?“<????for(int?i=0;?i<8;?i++)
????{
????????if((center.x+dir[i][0])<0?||?(center.x+dir[i][0])>=m_col?||?(center.y+dir[i][1])<0?||?(center.y+dir[i][1])>=m_row)
????????{
????????????qDebug()<<“hehehehehehehheehe“<????????????continue;
????????}else
????????{
????????????NodeItem?item;
????????????item.x?=?center.x+dir[i][0];
????????????item.y?=?center.y+dir[i][1];

????????????if(i%2==0)
????????????{
????????????????item.g?=?center.g+10;
????????????}else
????????????{
????????????????item.g?=?center.g+14;
????????????}
????????????int?xGap?=?abs(goal.x-item.x);
????????????int?yGap?=?abs(goal.y-item.y);
????????????int?minValue?=?xGap>yGap??yGap?:?xGap;
????????????item.h?=?abs(xGap-yGap)*10+minValue*14;
????????????item.f?=?item.fx();
????????????item.parent?=?new?NodeItem;
????????????item.parent->x?=?center.x;
????????????item.parent->y?=?center.y;
????????????item.parent->g?=?center.g;
????????????item.parent->h?=?center.h;
????????????item.parent->f?=?center.f;

????????????if(isOnCloseList(item))
????????????{
????????????????continue;
????????????}

????????????if(!isOnOpenList(item))
????????????{
????????????????addToOpenList(item);
????????????}else
????????????{
????????????????list::iterator?it;
????????????????for(it?=?openList.begin();?it?!=?openList.end();?it++)
????????????????{
????????????????????if(item?==?(*it))
????????????????????{
????????????????????????if(center.g+(i%2==0??10:14)<(*it).g)
????????????????????????{
????????????????????????????addToOpenList(item);
????????????????????????}
????

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-29?16:23??AStar\
?????文件????????1101??2018-08-13?17:45??AStar\AStar.pro
?????文件???????45687??2018-11-29?16:23??AStar\AStar.pro.user
?????文件????????5862??2018-08-22?10:43??AStar\astar.cpp
?????文件????????1898??2018-08-18?14:02??AStar\astar.h
?????文件?????????177??2018-08-16?15:19??AStar\main.cpp
?????文件????????1798??2018-08-17?17:15??AStar\rect.cpp
?????文件?????????761??2018-08-17?17:15??AStar\rect.h
?????文件????????1778??2018-08-18?14:02??AStar\widget.cpp
?????文件?????????533??2018-08-16?15:39??AStar\widget.h
?????文件?????????441??2018-08-13?17:42??AStar\widget.ui

評論

共有 條評論