ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:21.40KB ,
资源ID:7166605      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7166605.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(智能控制作业.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

智能控制作业.docx

1、智能控制作业一、A*寻路算法Attribute VB_Name = mFindPathOption ExplicitDim 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 fsPoi

2、nt 目标点 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

3、寻路 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 P

4、athErr: 判断地图 If lWidth 1 Or lHeight 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 Exit Function End If If pGotoPoint.Y =

5、pStartPoint.Y And pGotoPoint.X = pStartPoint.X Then fPath = 4 Exit Function End If 设置常数数组 该数组决定了寻路的优先顺序 arrXofs(0) = -1 arrXofs(1) = 1 arrXofs(2) = -1 arrXofs(3) = 1 arrXofs(4) = -1 arrXofs(5) = 1 arrXofs(6) = 0 arrXofs(7) = 0 arrYofs(0) = -1 arrYofs(1) = 1 arrYofs(2) = 1 arrYofs(3) = -1 arrYofs(4)

6、= 0 arrYofs(5) = 0 arrYofs(6) = -1 arrYofs(7) = 1 tmpOfs = 0 - lWidth arrIofs(0) = tmpOfs - 1 arrIofs(1) = lWidth + 1 arrIofs(2) = lWidth - 1 arrIofs(3) = tmpOfs + 1 arrIofs(4) = -1 arrIofs(5) = 1 arrIofs(6) = tmpOfs arrIofs(7) = lWidth 初始化数据 Count = lWidth * lHeight 地图总点数 ReDim arrBap(Count) 清空所有需要

7、用到的列表 ReDim arrOpen(Count) 起始点进入开放列表 Count = pStartPoint.Y * lWidth + pStartPoint.X pStartPoint.Index = Count tmpX = Abs(pStartPoint.X - pGotoPoint.X) tmpY = Abs(pStartPoint.Y - pGotoPoint.Y) pStartPoint.G = 0 If tmpX tmpY Then pStartPoint.H = tmpX Else pStartPoint.H = tmpY End If pStartPoint.F = pS

8、tartPoint.G + pStartPoint.H arrBap(Count).Parent = 0 arrBap(Count).aIndex = 1 arrOpen(1) = pStartPoint lOpenSize = 1 Do While lOpenSize 0 pCurrentPoint = pBinaryHeapDelete() Count = pCurrentPoint.Index arrBap(Count).bClose = True arrBap(Count).aIndex = 0 For i = 0 To 7 pSearchPoint.X = pCurrentPoint

9、.X + arrXofs(i) pSearchPoint.Y = pCurrentPoint.Y + arrYofs(i) Count = pCurrentPoint.Index + arrIofs(i) pSearchPoint.Index = Count If Count = TCount Then 就是终点 arrBap(Count).Parent = pCurrentPoint.Index 保存路径 lPathCount = -1 Do While arrBap(Count).Parent 0 lPathCount = lPathCount + 1 arrPath(lPathCount

10、) = Count Count = arrBap(Count).Parent Loop 起始点放入最后 arrPath(lPathCount + 1) = Count fPath = 1 Exit Function Else If arrMap(Count).B And arrMap(Count).lNpcId = 0 Then 不是障碍点 If Not arrBap(Count).bClose Then 不在关闭列表 pSearchPoint.G = pCurrentPoint.G + 1 tmpX = Abs(pSearchPoint.X - pGotoPoint.X) tmpY = Ab

11、s(pSearchPoint.Y - pGotoPoint.Y) pStartPoint.G = 0 If tmpX tmpY Then pSearchPoint.H = tmpX Else pSearchPoint.H = tmpY End If pSearchPoint.F = pSearchPoint.G + pSearchPoint.H If arrBap(Count).aIndex 0 Then If pSearchPoint.F 0 Then If arrOpen(lSelectIndex).F 0 Then arrOpen(1) = arrOpen(lOpenSize + 1)

12、lSelectIndex = 1 arrBap(arrOpen(lSelectIndex).Index).aIndex = lSelectIndex 比较子节点 Do While True lLeftChildIndex = lSelectIndex * 2 lRightChildIndex = lLeftChildIndex + 1 If lLeftChildIndex lOpenSize Then 没有左子节点 则结束 Exit Do Else If lLeftChildIndex = lOpenSize Then 只有左子节点 If arrOpen(lSelectIndex).F arr

13、Open(lLeftChildIndex).F Then 父节点F值大 则交换 tmpPoint = arrOpen(lSelectIndex) arrOpen(lSelectIndex) = arrOpen(lLeftChildIndex) arrOpen(lLeftChildIndex) = tmpPoint arrBap(arrOpen(lSelectIndex).Index).aIndex = lLeftChildIndex arrBap(arrOpen(lLeftChildIndex).Index).aIndex = lSelectIndex lSelectIndex = lLeft

14、ChildIndex Else 父节点比子节点F值小 则结束 Exit Do End If Else If lRightChildIndex = lOpenSize Then If arrOpen(lLeftChildIndex).F arrOpen(lLeftChildIndex).F Then 父节点F值大 则交换 tmpPoint = arrOpen(lSelectIndex) arrOpen(lSelectIndex) = arrOpen(lLeftChildIndex) arrOpen(lLeftChildIndex) = tmpPoint arrBap(arrOpen(lSelec

15、tIndex).Index).aIndex = lLeftChildIndex arrBap(arrOpen(lLeftChildIndex).Index).aIndex = lSelectIndex lSelectIndex = lLeftChildIndex Else 父节点比子节点F值小 则结束 Exit Do End If Else If arrOpen(lSelectIndex).F arrOpen(lRightChildIndex).F Then 父节点F值大 则交换 tmpPoint = arrOpen(lSelectIndex) arrOpen(lSelectIndex) =

16、arrOpen(lRightChildIndex) arrOpen(lRightChildIndex) = tmpPoint arrBap(arrOpen(lSelectIndex).Index).aIndex = lRightChildIndex arrBap(arrOpen(lRightChildIndex).Index).aIndex = lSelectIndex lSelectIndex = lRightChildIndex Else 父节点比子节点F值小 则结束 Exit Do End If End If End If End If End If Loop End If pBinar

17、yHeapDelete = tmpResultEnd Function更新一个点 并重新排序Private Sub pBinaryHeapUpdate(Index As Long) Dim lParentIndex As Long Dim lSelectIndex As Long Dim tmpPoint As fsPoint lSelectIndex = Index Do While True lParentIndex = Int(lSelectIndex / 2) If lParentIndex 0 Then If arrOpen(lSelectIndex).F 0 Then ReDim

18、bytChar(iLen - 1) Get #2, 1, bytChar() Close #2 iMapHeight = Val(GetValue(Index_ & strMsg, Height, fMapSet) iMapWidth = Val(GetValue(Index_ & strMsg, Width, fMapSet) nMap(lMapDataID).lWidth = iMapWidth nMap(lMapDataID).lHeight = iMapHeight nMap(lMapDataID).lDataSize = iMapWidth * iMapHeight If nMap(

19、lMapDataID).lDataSize iLen Then Exit Sub 地图数据不正确 ReDim nMap(lMapDataID).cMapData(nMap(lMapDataID).lDataSize - 1) iCount = -1 For i = 0 To iMapHeight - 1 For j = 0 To iMapWidth - 1 iCount = iCount + 1 nMap(lMapDataID).cMapData(iCount).X = j nMap(lMapDataID).cMapData(iCount).Y = i If bytChar(iCount) =

20、 0 Then nMap(lMapDataID).cMapData(iCount).B = False Else nMap(lMapDataID).cMapData(iCount).B = True End If Next Next nMap(lMapDataID).bData = True 读取固定门点 Dim arrData() As String Dim brrData() As String strMsg = GetValue(bDoor, CStr(lMapDataID), fMapSet) arrData = Split(strMsg, _) For m = 0 To UBound

21、(arrData) brrData = Split(arrData(m), ,) If UBound(brrData) 0 Then i = CLng(brrData(1) j = CLng(brrData(0) iCount = iMapWidth * i + j nMap(lMapDataID).cMapData(iCount).B = False nMap(lMapDataID).cMapData(iCount).D = True End If Next 读取死点 strMsg = GetValue(bFault, CStr(lMapDataID), fMapSet) arrData =

22、 Split(strMsg, _) For m = 0 To UBound(arrData) brrData = Split(arrData(m), ,) If UBound(brrData) 0 Then i = CLng(brrData(1) j = CLng(brrData(0) iCount = iMapWidth * i + j nMap(lMapDataID).cMapData(iCount).B = False End If Next 读取活点 strMsg = GetValue(bThrough, CStr(lMapDataID), fMapSet) arrData = Split(strMsg, _) For m = 0 To UBound(arrData) brrData = Split(arrData(m), ,) If UBound(brrData) 0 Then i = CLng(brrData(1) j = CLng(brrData(0) iCount = iMapWidth * i + j nMap(lMapDataID).cMapData(iCount).B = True End If Next Else Close #2 Exit Sub

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1