在一个六边形地图运动算法 [英] Movement algorithm on a hexagon map

查看:166
本文介绍了在一个六边形地图运动算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个网站的一个问题: HTTP://www.dark- project.cz/wesnoth/map-view/1 (点击的单位)。在我的JavaScript源 http://www.dark-project.cz/wesnoth /js/map/base.js (最后 $('div.unitImg)。点击(函数()函数),我想,以纪念所有六边形该单位不能去。

I have a problem on this site: http://www.dark-project.cz/wesnoth/map-view/1 (click on the unit). In my Javascript source http://www.dark-project.cz/wesnoth/js/map/base.js (last $('div.unitImg').click(function() function) I want to mark all hexagons to which the unit can't go.

我有一个相当复杂的算法,工作权当运动是1,但如果是高它不工作(试行运动2)。

I have quite a complex algorithm that works right when the movement is 1, but if it is higher it doesn't work (try movement 2).

你有一些想法对一个算法来找到合适的不吉利的东西?

Do you have some idea about an algorithm to find the right hexes?

下面是坐标的编号的例子: HTTP://www.dark-project .CZ /韦诺/ coor.png

Here is an example of the coordinate numbering: http://www.dark-project.cz/wesnoth/coor.png

感谢您的所有答复。

推荐答案

起初,我建议你重新设计的坐标。很好的例子是在<提供的href="http://stackoverflow.com/questions/2049196/generating-triangular-hexagonal-coordinates-xyz">this问题。

At first, I suggest you redesign the coordinates. Good example is provided in this question.

但不管坐标系的,我认为你必须反正在未来的领域的一些障碍(一些岩石,龙等),所以你应该设计ppared对于一般的算法,$ P $。我建议调查 BFS ,但你并不需要显式地构建图,只是当你需要的边缘,你知道你有你的领域(深度的,这是工作)什么是相邻的六边形和遍历那里。这是一般的方法。有一个DFS过,但BFS常常被认为是可到达性问题的更有效的时相邻的边的数目是相当有限的。

But regardless of the coordinate system, I assume you'll have some obstacles on the field anyway in the future (some rocks, dragons, etc), so you should design a general algorithm prepared for that. I would suggest investigating the BFS, but you don't need to build the graph explicitly, just when you need edges, you know what the adjacent hexagons you have on your field (depth one, which is working) and traverse there. It's the general approach. There's a DFS too, but BFS is often considered more efficient for reachability problems when the number of adjacent edges is fairly limited.

这篇关于在一个六边形地图运动算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆