Related: Here's a C program that draws random dungeons sort of like you use in a roguelike dungeon crawler:
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
-1,u+h+2,t-1 ,t+w+2)if(m[
y][x]=='.' )r;i d=0
;i e,f ;if(!s){l( u-1,u+
h+2,t- 1,t+w+2){i s=x<t ||x>t
+w;i t=y<u|| y> u+h;
if(s ^t&& m[ y]
[x ]=='#' ){d++; if(g (d
) ==0) e=x,f=y; }}if (d
== 0)r; }l(u-1,u +h+2 ,t
-1 ,t+w +2){i s= x< t ||
x> t+w; i t= y<u ||y> u+
h; m[y] [x]= s &&t? '!'
:s^t ?'#' :'.'
;}if (d>0)m [f][
e]=g(2 )?'\'':'+';for(i j=0;j<(s?
1:g(6) +1);j++)m[g(h)+u][g(w)
+t]=s?'@' :g(4) ==0?
'$':65+g(62) ;}i main(i
argc, const char* argv[]) {srand((i)
time(NULL));l(0, H, 0,W)m[y][x]=' ';
for(i j=0;j<1000;j++)cave(j==0);l(0,
H,0,W) {i c=m[y][x]; putchar(c=='!'?
'#':c);if(x==W-1)printf("\n");}r 0;}Sadly neither version works here with an older clang on OS X. Both variants build fine with 9 warnings each. But the old variant dies with a "Bus Error: 10", and the new variant with "Segmentation fault: 11". Same with gcc (albeit only 8 warnings.)
/edit
OK, just wrong user input. You gotta feed it a number, and not a "foobar" or another random string.
Now I should fix the link.
My personal favorite distinction is between the Recursive Backtracker (which creates long, winding corridors with few dead ends which is great for tower defense games) vs. Prim's Algorithm (which creates lots of short cul-de-sacs which is better for roguelikes). The bias of the algorithm dictates the feel of the game more than the graphics do.
To have mazes look more human drawn, cells need to be irregular and the inner walls need naturally follow the contours of the outer shape.
If you actually want more aesthetic freedom, you can compose with an arbitrary diffeomorphism of the square to itself. But I think that might usually look worse.
† - That is, preserving all angles, including right angles. The terminology stems from the output angles conforming (???) to the input angles.
My favorite maze algorithm is a variant of the growing tree algorithm - each time you carve a cell, add it to a random one of N lists. When choosing a cell to visit, pop the last cell off the first non-empty list. It's considerably faster than the standard tree algorithm, but more importantly, changing N has a dramatic impact on the texture of the maze (compare 1 2 4 8 etc on a decently large maze).
Is this intended to be able to be used on a phone? I saw the instructions about guiding a yellow ball but what I experienced was about 10 seconds of chiptune music with a maze that had some icons I couldn't interact with.
After the 10 seconds a series of green spheres and vertical lines washed across the screen but I wasn't able to control them.
I'm using the duck duck go browser on Android if that helps.
Maze Generation: Recursive Division (2011) - https://news.ycombinator.com/item?id=42703816 - Jan 2025 (12 comments)
Maze Algorithms (2011) - https://news.ycombinator.com/item?id=23429368 - June 2020 (22 comments)
Representing a Toroidal Grid - https://news.ycombinator.com/item?id=10608476 - Nov 2015 (2 comments)
Maze Generation: Recursive Backtracking - https://news.ycombinator.com/item?id=4058525 - June 2012 (1 comment)
Maze Generation: Weave mazes - https://news.ycombinator.com/item?id=4052856 - June 2012 (3 comments)
Maze-generation algorithms, with JS demos - https://news.ycombinator.com/item?id=2190017 - Feb 2011 (9 comments)
Generating random mazes with the Growing Tree algorithm (w/ Javascript demo) - https://news.ycombinator.com/item?id=2148348 - Jan 2011 (6 comments)
Maze Generation: Wilson's algorithm - https://news.ycombinator.com/item?id=2123695 - Jan 2011 (11 comments)
Maze Generation: Kruskal's Algorithm - https://news.ycombinator.com/item?id=2062999 - Jan 2011 (9 comments)
Maze Generation: Eller's Algorithm - https://news.ycombinator.com/item?id=2048752 - Dec 2010 (9 comments)
Also:
Wilson's Algorithm - https://news.ycombinator.com/item?id=45549017 - Oct 2025 (9 comments)
Maze Tree - https://news.ycombinator.com/item?id=7746822 - May 2014 (38 comments)
Solving a Maze with D3.js - https://news.ycombinator.com/item?id=7631864 - April 2014 (19 comments)
Think Labyrinth: Maze Algorithms - https://news.ycombinator.com/item?id=10101728 - Aug 2015 (10 comments)
Practical algorithms and code optimization: maze generation - https://news.ycombinator.com/item?id=5431561 - March 2013 (10 comments)
Maze Algorithms - https://news.ycombinator.com/item?id=157266 - April 2008 (1 comment)
Others?
https://news.ycombinator.com/item?id=45549017
Wilson’s Algorithm gives the most pleasing visual results for me.
However, it looks like a good article that could use a repost! Just not soon, since we want to give enough time for the hivemind caches to clear :) - if you want to repost it in (say) a month or two, email us at hn@ycombinator.com and we'll put it in the SCP (https://news.ycombinator.com/item?id=26998308).
https://www.astrolog.org/labyrnth/psych.htm
I think there is a difference if you want to make it only expensive to solve using popular maze solver algorithms, vs to make it difficult for a human to solve. Many of the recommendations on that page are for how to do things that can make a maze more difficult for humans to solve, but will not always matter to an algorithm that just mechanically tries solutions in some order.