Simple Java 2d array maze sample

前端 未结 3 1122
轻奢々
轻奢々 2021-02-03 15:46

I am working or understanding how to create a simple java 2d maze that should look like this:

int [][] maze = 
{ {1,1,1,1,1,1,1,1,1,1,1         


        
3条回答
  •  离开以前
    2021-02-03 16:18

    I know this is probably completely outdated, but...

    First, you should realize that the underlying structure of such a maze is an undirected graph on a 2-dimensional grid. Now to create a so called "perfect maze", you just have to create any spanning tree of a full grid graph. And to do that there are plenty of algorithms, from random graph traversals (BFS, DFS) over algorithms derived from the known minimum-spanning tree algorithms (Kruskal, Prim, Boruvka, Reverse-Delete) to algorithms creating "uniformly random" spanning trees (Wilson, Aldous-Broder) to other algorithms that don't fit into these categories like "recursive division", "Eller's" etc.

    I implemented lots of these algorithms based on a grid graph structure and you can find my implementation here:

    https://github.com/armin-reichert/mazes

提交回复
热议问题