迷宫网格生成算法 [英] Maze generating algorithm in grid

查看:391
本文介绍了迷宫网格生成算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的算法来生成网格迷宫?

What is the best algorithm to generate a maze in a grid?

我听到Kruskal算法和递归backtracker除其他的但是这两种依靠walls.What将是最好的算法创建惊奇其中一个整个细胞是壁?

I have heard of Kruskal's algorithm and the recursive backtracker amongst other but both of these rely on walls.What would be the best algorithm to create amaze where one entire cell is a wall?

推荐答案

修改递归回溯或Prim算法应该是很简单的的维基百科

Modifying recursive backtracking or Prim's algorithm should be simple enough (code derived from Wikipedia)

随机Prim算法

  • 在开始用填充单元网格。
  • 选择一个单元格,将其标记为迷宫的一部分。添加的小区的周边填充细胞对小区列表。
  • 虽然有细胞在列表中:
    • 从列表中选择一个随机的单元格。如果该细胞不具备2探索邻居:
      • 清除细胞。
      • 添加邻填充细胞的小区列表。
      • Start with a grid of filled cells.
      • Pick a cell, mark it as part of the maze. Add the surrounding filled cells of the cell to the cell list.
      • While there are cells in the list:
        • Pick a random cell from the list. If the cell doesn't have 2 explored neighbours:
          • Clear the cell.
          • Add the neighbouring filled cells to the cell list.

          这篇关于迷宫网格生成算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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