What's a good algorithm to generate a maze?

后端 未结 9 1488
囚心锁ツ
囚心锁ツ 2020-11-27 09:55

Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks \"right\" (i.e. like someone made it by hand without too

9条回答
  •  眼角桃花
    2020-11-27 10:27

    My favorite way is to use Kruskal's algorithm, but when randomly choosing and edge to remove, weight the choice based on the types of edges it's connected to.

    By varying the weights for different edge types, you can generate mazes with lots of distinct characteristics or "personalities". See my example here:

    https://mtimmerm.github.io/webStuff/maze.html

提交回复
热议问题