Maze generation: Difference between revisions

m
→‎{{header|Erlang}}: Shortened section titles, fixed typos + added whitespace
m (→‎{{header|Erlang}}: Removed unnecessary "out" templates)
m (→‎{{header|Erlang}}: Shortened section titles, fixed typos + added whitespace)
Line 1,869:
Erlang is single assignment. To get mutability I use processes. The code is over-enginered for this task, but the extra is used for [[Maze_solving]]. Also, Erlang starts counting at 1, not 0, so the co-ordinate of the lower left corner is 1,1.
 
===Original example (implemented withUsing multiple processes)===
<lang Erlang>
-module( maze ).
Line 2,038:
</pre>
 
===Using 2 digraphs===
===Alternative example (implemented with 2 diagraphs)===
Uses 2 diagraphdigraph "objects": a) the 'matrix', a fully connected digraph of MxN vertices and b) the 'maze', an unconnected digraph, also MxN, that is populated while walking.
 
Employs a faux Visitor pattern to populate the maze while traversing the matrix in depth-first order.
 
Vertices: 0 .. MxN - 1
 
Rows: 0 .. M - 1
 
Cols: 0 .. N - 1
 
Usage: start with generate_default/0. Use generate_MxN() to test other maze sizes.
<lang Erlang>