Treat an array of blocks as nodes in a graph, with the blocks above, below, to the right and left of each block as adjacent, and assign random edge weights. Then run Prim's minimum spanning tree algorithm. Voila! A block maze!

The spanning tree guarantees that there are no cycles, every square is accessible, and there is exactly one path from the start at the lower left to the end at the upper right.

The other way to do it would be to forget about the edge weights and just build the spanning tree by selecting a random edge from an already-connected block. But then I wouldn't have had to remember all that stuff about priority queues and heaps, and where's the fun in that?

David Baer@david@arktos.socialThe other way to do it would be to forget about the edge weights and just build the spanning tree by selecting a random edge from an already-connected block. But then I wouldn't have had to remember all that stuff about priority queues and heaps, and where's the fun in that?