Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you looking for <a href="http://en.wikipedia.org/wiki/Maze_generation_algorithm" rel="noreferrer">Maze generation algorithms</a> (<a href="http://www.astrolog.org/labyrnth/algrithm.htm" rel="noreferrer">more</a>)? Is your problem with the algorithms, or graphics? </p> <p>The typical algorithms work by considering each "cell" in the maze as a vertex of a graph, start with all "walls", and remove a set of walls that corresponds to a spanning tree. (So in order to randomize it, many of them start with random weights and find the minimum spanning tree.) For small mazes at least, you don't need any special data structure to represent the cells; you can just think of each cell as a pair <code>(x,y)</code> (its coördinates). And you don't need any data structure (adjacency matrix / adjacency list) to store the edges of the graph either, because the neighbours of <code>(x,y)</code> are just <code>(x,y±1)</code> and <code>(x±1,y)</code> (ignoring those that fall outside the boundaries).</p> <p>In any case, once you have the spanning tree, you know exactly which of the walls "exist" and which do not, so you have a complete description of the maze. If you're going to draw the maze, you know which ones to draw.</p> <p>To draw with ASCII characters, you just pass through each row one by one: draw the "upper walls" (put a "<code>--</code>" if the wall between <code>(x,y)</code> and <code>(x,y+1)</code> exists), then draw the actual row (put a "<code>|</code>" if the wall between <code>(x,y)</code> and <code>(x+1,y)</code> exists). Finally draw the bottom boundary.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload