Skip to content

Comment on Practical algorithms and code optimization: maze generation

Comments

One can also use a disjoint-set data structure. Make a list of walls as tuples containing the "room number" (cell index) of both adjacent cells. Add all cells as disjoint sets in a disjoint-set data structure. Shuffle all the doors (tuples) randomly. Then go through the shuffled list and for each door: IF both sides are not part of the same set already: remove the wall. ELSE save the wall, it is part of the final maze.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.