TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How To Build A Maze

125 pointsby AndyBakerabout 11 years ago

19 comments

todd8about 11 years ago
In 1980, while working at Texas Instruments, I wrote a program to draw mazes one night. My first version started out quite simple and elegant, but the mazes it printed (on our departments line printer) weren&#x27;t very difficult to solve. The next night I improved the mazes produced by the program, adding tweaks here and there in the code to make the mazes harder to solve. I added long winding dead ends, corridors with loops and so forth. The mazes caught on and soon many cubicles had the three page mazes with hand drawn solutions as decoration. Marketing folks headed to a trade show saw these mazes and wanted the program to run on a system on the trade show floor so that personalized mazes could be handed out as trade show swag.<p>Unfortunately, version two of program wasn&#x27;t very pretty with all the little hacks and tweaks, but it did make fun mazes. Six or nine months later I got a call from someone wanting help with a Pascal program (I was one of the Pascal experts in the company at the time so I would get calls like this). As they described the program on the phone, I recognized it as my maze program. They said they got it off of the distribution tape for the TI Pascal compiler (I had programmed the program in Pascal). I was mortified that someone had made the ugly program a sample program for a TI product but at least it didn&#x27;t have my name on it!
Deestanabout 11 years ago
If you want to create a maze on paper as a rainy day kind of activity, the process is basically the same but manual:<p>1. Mark a start point and an end point, and draw the solution using yellow marker. A moderately windy path will do fine. Don&#x27;t overdo it, or you&#x27;ll actually make it too easy.<p>2. Using the same yellow marker, draw branching paths off from the solution path, and make branches off the branches until the maze area is too cramped to draw more.<p>3. Draw walls with black marker between and around the yellow paths.<p>4. Amaze your friends.
Vaskivoabout 11 years ago
I actually had some fun reading about maze algorithms some time ago. Here are two good links:<p><a href="http://www.astrolog.org/labyrnth/algrithm.htm" rel="nofollow">http:&#x2F;&#x2F;www.astrolog.org&#x2F;labyrnth&#x2F;algrithm.htm</a><p><a href="http://weblog.jamisbuck.org/2011/2/7/maze-generation-algorithm-recap" rel="nofollow">http:&#x2F;&#x2F;weblog.jamisbuck.org&#x2F;2011&#x2F;2&#x2F;7&#x2F;maze-generation-algorit...</a><p>The first link is interesting because it describes some maze toponomy (types and characteristics of mazes) The second has a lot of algorithm implementations with nice demos.<p>Fun stuff :)
jmdukeabout 11 years ago
My favorite presentation ever, by Jamie Buck at RubyConf2011, is a great interactive survey of maze generation algorithms -- <i>&quot;Algorithm&quot; is Not a Four-Letter Word</i>:<p><a href="http://www.jamisbuck.org/presentations/rubyconf2011/" rel="nofollow">http:&#x2F;&#x2F;www.jamisbuck.org&#x2F;presentations&#x2F;rubyconf2011&#x2F;</a>
评论 #7460388 未加载
评论 #7460305 未加载
thangalinabout 11 years ago
A one-liner maze builder for the C64:<p><pre><code> 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 </code></pre> <a href="http://10print.org/" rel="nofollow">http:&#x2F;&#x2F;10print.org&#x2F;</a><p><a href="http://retroplay.co/c64/" rel="nofollow">http:&#x2F;&#x2F;retroplay.co&#x2F;c64&#x2F;</a> (click the play button for a C64 emulator)
评论 #7461361 未加载
itpabout 11 years ago
Jamis Buck has a fantastic series of blog posts about maze generation[1]. It looks like he&#x27;s no longer updating the blog, but all of the entries are still up. Start at the bottom and work up.<p>[1] <a href="http://weblog.jamisbuck.org/under-the-hood" rel="nofollow">http:&#x2F;&#x2F;weblog.jamisbuck.org&#x2F;under-the-hood</a>
brianpgordonabout 11 years ago
Something interesting about this type of maze is that you can use a flood-fill algorithm on the walls to find a solution. This is because there&#x27;s exactly one path between the start and finish, and that path divides the the maze into two parts.<p>There are some examples at the bottom of this page: <a href="http://www.brian-gordon.name/portfolio/maze.html" rel="nofollow">http:&#x2F;&#x2F;www.brian-gordon.name&#x2F;portfolio&#x2F;maze.html</a>
jffryabout 11 years ago
There are lots of different ways to build mazes [1]. My favorite is Prim&#x27;s Algorithm, which &quot;grows&quot; a maze.<p>[1] <a href="http://en.wikipedia.org/wiki/Maze_generation_algorithm" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Maze_generation_algorithm</a>
评论 #7460948 未加载
greggmanabout 11 years ago
I always recall this one from 1981 Compute Magazine<p><a href="https://archive.org/stream/1981-12-compute-magazine/Compute_Issue_019_1981_Dec#page/n55/mode/2up" rel="nofollow">https:&#x2F;&#x2F;archive.org&#x2F;stream&#x2F;1981-12-compute-magazine&#x2F;Compute_...</a><p>No stack, just generated the mazed directly in screen memory.
jimmaswellabout 11 years ago
One cool way to make a maze is how the old Windows OpenGL maze screensaver did it, starting with every square having full walls, starting somewhere, and making sure every room has at least one broken wall and they&#x27;re all connected, traversing it. I forget how exactly it picked the end point. I used that when I wrote a Javascript game about that maze but it was hosted on nyhacker and it&#x27;s gone now. Might still have it around somewhere on a hard drive though.
doppenheabout 11 years ago
If you want to see one of these working and in action you can check out one of our demos at <a href="https://www.algorithmia.com/demo/pathplan" rel="nofollow">https:&#x2F;&#x2F;www.algorithmia.com&#x2F;demo&#x2F;pathplan</a>
johnwatson11218about 11 years ago
I don&#x27;t have time to read all the links in this thread but I used to draw mazes all the time in school. My approach was to start with an &quot;in&quot; tube and start branching it, so long as I kept one branch open I could split and recombine all the others and know that I still had a valid maze. After I had filled up most of the page I would stop and declare the end position. It might not be clear from my description but I kept adding paths to the maze by doubling back on what was already there and building it out so it looked like a brain. The main point is that I kept one path open, never closing all my paths in a dead end. That way I knew there was a solution but since I did them so fast I wouldn&#x27;t know the solution myself.
intruderabout 11 years ago
I implemented this in JS some time ago to get into JS. I visualized the carving of the maze and still think it&#x27;s pretty cool to look at it.<p>Here&#x27;s the link: <a href="https://googledrive.com/host/0Bzr7EVRN_St0UkhIdUdrQ3o4T0E/index.html" rel="nofollow">https:&#x2F;&#x2F;googledrive.com&#x2F;host&#x2F;0Bzr7EVRN_St0UkhIdUdrQ3o4T0E&#x2F;in...</a> (might load slowly in the beginning, give it a bit of time)<p>Source: <a href="https://github.com/arya-s/A1/blob/master/js/A1Maze.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;arya-s&#x2F;A1&#x2F;blob&#x2F;master&#x2F;js&#x2F;A1Maze.js</a>
waynecochranabout 11 years ago
Looks amazing similar to my sophomore data struct project: <a href="http://ezekiel.vancouver.wsu.edu/~cs223/projects/mazegen/mazegen.pdf" rel="nofollow">http:&#x2F;&#x2F;ezekiel.vancouver.wsu.edu&#x2F;~cs223&#x2F;projects&#x2F;mazegen&#x2F;maz...</a>
primaryobjectsabout 11 years ago
Mazes are certainly fun. Here&#x27;s a javascript maze solver I wrote a while back, including a REST url for building your own maze. <a href="http://www.primaryobjects.com/maze" rel="nofollow">http:&#x2F;&#x2F;www.primaryobjects.com&#x2F;maze</a>
thearn4about 11 years ago
My favorite way to generate a maze (imperfect, but fun): <a href="http://www.conwaylife.com/wiki/Maze" rel="nofollow">http:&#x2F;&#x2F;www.conwaylife.com&#x2F;wiki&#x2F;Maze</a><p>quickstart: <a href="https://github.com/thearn/game-of-life/blob/master/rule_string.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thearn&#x2F;game-of-life&#x2F;blob&#x2F;master&#x2F;rule_stri...</a>
dmooabout 11 years ago
If you want to play around with a maze then there are examples in many languages at Rosetta Code, the python one is nice <a href="http://rosettacode.org/wiki/Maze_generation#Python" rel="nofollow">http:&#x2F;&#x2F;rosettacode.org&#x2F;wiki&#x2F;Maze_generation#Python</a>
tankerdudeabout 11 years ago
Disjoint sets.<p>1) Each cell in the maze is a set. 2) Randomize walls. Check if wall to be removed are already in the same set. Merge the set if wall is removed. 3) Repeat until entire maze is in one set.<p>DFS seems a bit odd for generation. For generating a solution, it would be what I would do.
评论 #7462747 未加载
tibbonabout 11 years ago
Also of note, Eller&#x27;s Algorithm for mazes:<p><a href="http://weblog.jamisbuck.org/2010/12/29/maze-generation-eller-s-algorithm" rel="nofollow">http:&#x2F;&#x2F;weblog.jamisbuck.org&#x2F;2010&#x2F;12&#x2F;29&#x2F;maze-generation-eller...</a>