用块代替墙的深度优先搜索迷宫生成算法

发布于 2024-11-08 20:51:55 字数 290 浏览 0 评论 0原文

我正在尝试将深度优先搜索算法应用到我的游戏中。我一直在研究这个网页: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-11-15 20:51:55

根据您实际希望实现的目标,我为您提供两种解决方案。
它们基本上都是您引用的网站上提供的算法。

1.) 迷宫中的预定义位置有块,

  • 您在 2*k+1 网格上运行算法,
  • 假设单元格编号从左上角开始 (0,0)。
    将所有具有 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

  • you run the algorithm on a 2*k+1 grid
  • assume the numbering of your cells starts top left with (0,0).
    mark all cells with 2 odd coordinates ( (2*p+1, 2*q+1); p,q < k ) as blocks.
  • you run the modified algorithm from your source on the remaining cells ('even cells').
    the modifications are:

    • start with an even cell picked at random
    • a 'neighbour cell' is the second but next cell in any grid direction;
      i.e. you 'jump' over a brick.
    • instead of knocking down the wall between cells,
      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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文