- 1、本文档共32页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
TPMK standardization office【 TPMK5AB- TPMK08- TPMK2C- TPMK18】
TPMK standardization office【 TPMK5AB- TPMK08- TPMK2C- TPMK18】
智能控制作业
一、A*寻路算法
Attribute VB_Name = mFindPath
Option Explicit
Dim arrBap() As bPoint 地图状态
Dim arrOpen() As fsPoint 开放列表
Dim lOpenSize As Long 开放列表元素个数
Dim TCount As Long 目标序号
※※※※ A*寻路函数※※※※※※※※※
输入参数
arrMap() as fsPoint 地图障碍物数据
arrPath() as long 路径列表
lPathCount as long 路径长度
pStartPoint as fsPoint 起始点
pGotoPoint as fsPoint 目标点
lWidth as long 地图宽度
lHeight as long 地图高度
输出参数
类型:long 寻路结果
3 地图格式不正确
2 目标为障碍点
1 寻路成功
0 寻路失败 无法到达
4 已经到达终点
5 目标被占
6 寻路过程中发生错误
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
Public Function fPath(arrMap() As fsPoint, arrPath() As Long, lPathCount As Long, pStartPoint As fsPoint, pGotoPoint As fsPoint, lWidth As Long, lHeight As Long) As Long 寻路
Dim i As Long 循环用变量
Dim Count As Long 点的序号或者总数
Dim pCurrentPoint As fsPoint
Dim pSearchPoint As fsPoint
Dim pSearchX As Long, pSearchY As Long
Dim tmpX As Long, tmpY As Long
Dim arrXofs(8) As Long, arrYofs(8) As Long XY变化常量数组
Dim arrIofs(8) As Long 序号变化常量数组
Dim tmpOfs As Long 序号变化量
On Error GoTo PathErr:
判断地图
If lWidth 1 Or lHeight 1 Then
fPath = 3 地图数据不正确
Exit Function
End If
TCount = pGotoPoint.Y * lWidth + pGotoPoint.X 目标序号
TCount = pGotoPoint.Index
判断是否为障碍物
If pGotoPoint.Y lHeight - 1 Or pGotoPoint.X lWidth - 1 Then
fPath = 2
Exit Function
End If
If arrMap(TCount).B Or arrMap(TCount).D Then
可以通过或者是门点
fPath = 0
Else 否则退出寻路
fPath = 2
Exit Function
End If
If arrMap(TCount).lNpcId 0 Then
fPath = 5
文档评论(0)