寻找一系列点之间的路径
为了在我的一个简单项目中使用,我遇到了一些障碍。
我在网格中有一系列点,“墙壁”和“开放空间”。网格外部的空间被假定为墙壁。我在这个网格中有任意数量的开放点,如果我将网格中的一个特定块从开放空间更改为墙壁,我必须确定哪些连接的点是否会改变。
执行此操作的有效方法是什么?
示例:确定如果绿色方块是墙壁或开放空间,红色方块之间是否存在路径是否会改变。 (PS:我真诚地为我糟糕的网格道歉)
现在,我假设某种元胞自动机是最好的,但我不确定。我以前研究过寻路,但从未真正见过遇到此类问题的任何东西。
请注意:我不在乎路径有多长,(我知道它们的最大长度)它们必须存在。因此寻找点之间的最佳路径是没有必要的。
哦,虽然这并不重要,但我正在用 Java 编写这个项目,但是任何语言(或伪代码)或算法的英语描述就足够了。 (我知道大部分大括号语言,以及有限的 Haskell 和 LISP,它们都可以。)
For use in a simple project of mine, I've hit a bit of a blockade.
I have a series of points in a grid, "walls" and "open space." Space outside the grid is assumed to be walls. I have an arbitrary number of points in this grid which are open, and I must determine if which ones are connected will change if I make one specific block in the grid change from open space to a wall.
What's an efficient way of doing this?
Example: Determine whether the presence/absence of paths between the red squares will change if the green square is a wall or open space. (PS: I sincerely apologize for my terrible grid)
Right now, I'm assuming some sort of cellular automata is best, but I'm not sure. I've looked at pathfinding before, but never really saw anything that got into this sort of problem.
Please note: I don't care how long the paths are, (I know their maximum length) they just MUST EXIST. So finding the BEST path between points is not necessary.
Oh, and while it shouldn't matter, I'm writing this project in Java, but any language (or pseudo-code) or an English description of an algorithm will suffice. (I know most of the Curly Bracket languages, and limited Haskell and LISP, they'll all do.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不是最好的解决方案,但解决方案如下:
以这种方式检查所有节点相当有效(我认为检查 n*n/2-n/2 路径将花费 O(n^2)),但如果仅创建必要的岛屿,添加新墙可能会更有效没有洪水填充,但这可能更难以实施。
This might not be the best solution, but a solution would be the following:
Checking for all nodes is reasonably efficient in this way (checking n*n/2-n/2 paths will take O(n^2) I think), but adding new walls might be made more efficient if only the necessary islands are created without flood-fill, but that could be more difficult to implement.