r/programmingchallenges • u/aveganzombie • Sep 09 '11
Make a perfect maze.
A perfect maze is one that has one and only one path between any two points in it (without backtracking).
There are quite a few algorithms out there for this, but trying to make your own is good fun.
28
Upvotes
View all comments
3
u/PlainSight Sep 10 '11
Union Find: http://codepad.org/qfkBv7lf Kinda messy code but half of it is printing. The way I did it meant walls are rendered not tiles. ________________________________________ | |______ | _ | | | | |____ | | | | | | _____ | | | _ | | _ _ ___ | | | | |___| |_____|_| _ |__ |_| __| | __| | | | | | | _ _ | | | __| _ ____| | ___ | _ |___| |___| |_|_| |_____| |___| | | | | | | ___ _ | | |_| | | | _ | | _______ |_|_| | | | | |___| |_| | | | | _ | | | _ _ |___| | |___| | | | | | | ___________ _ | | | | | | | _ |___| | _ |_| | | |___| | |_| | | |_| _____ | | | _____ | | _ | _ | |_| | |_| | | | _ | _ | | |_| | | _ _ | | __| |___| | |_|_| | | | | | | | | _____ | | |_| | _ | | | |___| __| | | | | _ _ |_| | _ | _ | | __| | ____| |_| | | | | | | |_| | _ | | _____ | | | |_________|_|_____|_|_______|_________|_|