用块代替墙的深度优先搜索迷宫生成算法
我正在尝试将深度优先搜索算法应用到我的游戏中。我一直在研究这个网页: http://www.mazeworks.com/mazegen/mazetut /index.htm ,却发现我无法将它与块而不是墙一起使用。我所说的块是指覆盖整个单元格的正方形,而不仅仅是边缘。我认为这样做会更容易,但现在我不太确定。有人这样做过吗?如果是这样,怎么办? (伪代码很好)。或者,如果更容易的话,我应该采用墙壁方法吗?
I am trying to implement the depth first search algorithm into my game. I have been studying this web page: http://www.mazeworks.com/mazegen/mazetut/index.htm , only to find that I wouldn't be able to use it with blocks instead of Walls. What I mean by blocks is a square that covers the whole cell, instead of just the edges. I thought that it would be easier to do it this way, but now I am not so sure. Has anyone done this? If so, how? (psuedocode is fine). Or, should I just go with the walls method, if it is easier?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您实际希望实现的目标,我为您提供两种解决方案。
它们基本上都是您引用的网站上提供的算法。
1.) 迷宫中的预定义位置有块,
2*k+1
网格上运行算法,将所有具有 2 个奇数坐标 (
(2*p+1, 2*q+1); p,q < k
)的单元格标记为块。修改是:
即你“跳过”一块砖。
您将块变成可访问的单元格。
但是,选择时不会考虑该单元格
和回溯
2.)而不是分隔单元格的墙壁,你需要的是块。
在开始算法之前,将任意数量的单元格标记为块。
按照源中所述进行操作,但切勿考虑任何块单元。
如果你想保证,你必须采取特殊的预防措施
迷宫中完全可访问。一个简单的方案是永远不标记单元格
作为一个有超过 1 个街区作为邻居的街区。
希望这些想法适合您的需求,
最诚挚的问候,卡斯滕
depending on what you actually wish to achieve i've two solutions for you.
they are both basically the algorithm presented on the website you've referenced.
1.) there are blocks at predefined positions in your maze
2*k+1
gridmark all cells with 2 odd coordinates (
(2*p+1, 2*q+1); p,q < k
) as blocks.the modifications are:
i.e. you 'jump' over a brick.
you turn the block into an accesible cell.
however, this cell will not be considered by the selection
and backtracking
2.) instead of walls separating cells you want blocks.
before starting the algorithm mark any number of cells as blocks.
proceed as outlined in your source but never consider any of the block cells.
you will have to take special precautions if you want want to guarantee
complete accessibility in your maze. a simple scheme would be to never mark a cell
as a block that has more than 1 blocks as neighbours.
hope these ideas suit your needs,
best regards, carsten