Maze generation: Difference between revisions

Content added Content deleted
m (→‎{{header|Erlang}}: Removed unnecessary "out" templates)
m (→‎{{header|Erlang}}: Shortened section titles, fixed typos + added whitespace)
Line 1,869: 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.
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 with multiple processes)===
===Using multiple processes===
<lang Erlang>
<lang Erlang>
-module( maze ).
-module( maze ).
Line 2,038: Line 2,038:
</pre>
</pre>


===Using 2 digraphs===
===Alternative example (implemented with 2 diagraphs)===
Uses 2 diagraph "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.
Uses 2 digraph "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.
Employs a faux Visitor pattern to populate the maze while traversing the matrix in depth-first order.

Vertices: 0 .. MxN - 1
Vertices: 0 .. MxN - 1

Rows: 0 .. M - 1
Rows: 0 .. M - 1

Cols: 0 .. N - 1
Cols: 0 .. N - 1

Usage: start with generate_default/0. Use generate_MxN() to test other maze sizes.
Usage: start with generate_default/0. Use generate_MxN() to test other maze sizes.
<lang Erlang>
<lang Erlang>