-
Notifications
You must be signed in to change notification settings - Fork 262
algorithm
qiannian edited this page Jul 3, 2026
·
2 revisions
算法
- AStarFindPath: A 星算法
- FindNearestPos: 查找最近的位置
根据 A 星算法,获取地图上从源坐标到目的坐标的一条最短路径
string AStarFindPath(mapWidth, mapHeight, disable_points, beginX, beginY, endX, endY)| 参数 | 类型 | 描述 |
|---|---|---|
| mapWidth | int | 地图宽度 |
| mapHeight | int | 地图高度 |
| disable_points | string | 不可通行的坐标,以 "|" 分割,例如 "10,15|20,30" |
| beginX | int | 源坐标 X |
| beginY | int | 源坐标 Y |
| endX | int | 目的坐标 X |
| endY | int | 目的坐标 Y |
返回值
类型:string
找到的路径结果
示例
path=op.AStarFindPath(10,10,"1,0|1,1|1,2|1,3",0,0,9,9)在一组位置中查找最近的位置
string FindNearestPos(all_pos,type,x,y)| 参数 | 类型 | 描述 |
|---|---|---|
| all_pos | string | 位置列表,以 "|" 分割 |
| type | int | 0:每项格式为 name,x,y;1:每项格式为 x,y
|
| x | int | 参考点 X 坐标 |
| y | int | 参考点 Y 坐标 |
返回值
类型:string
返回最接近指定坐标 (x,y) 的位置。type=0 时返回 name,x,y,type=1 时返回 x,y。
示例
pos = op.FindNearestPos("10,10|20,30|40,50",1,18,28)