资源简介
这是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
- 上一篇:STM32读写时钟PCF8563
- 下一篇:卷轴FLASH动画
相关资源
- SVR算法程序可运行
- 计算机图形学 边填充算法实现代码
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- 福建师范大学历年算法考卷
- 栈的实现及应用,六种基本算法
- Bresenham算法绘制线段并利用“橡皮筋
- 介绍几种压缩算法及《笨笨数据压缩
- VC 获得文件属性 获取文件的创建时
- 改进的BP神经网络算法
- 读者写者问题(读者优先,写者优先
- A星算法_原理讲解_例子
- 云模型的相关算法cloud
- 旋转矩阵求欧拉角的简单算法
- 用VC 编写的仿QQ聊天室程序源代码
- 栅栏填充算法源码(VC)
- RSA算法源码
- 关联分析Apriori算法实现
- [免费]relax算法成像
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 操作系统 LRU算法 实验报告 及 程序代
- 分治法快速排序算法QuickSort C
- 现代谱估计算法 music ESPRIT 谐波分解
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
评论
共有 条评论