1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use Algorithm;
use crate;
use *;
/// The "Sidewinder" algorithm for generating mazes
///
/// It’s closely related to the "Binary Tree" algorithm, but manages to get away with
/// only one side being spanned by a passage, instead of two. Space- and performance-wise,
/// the algorithm is quite efficient since it looks at one row at a time.
;
/// An implementation of the "Sidewinder" algorithm for generating mazes
///
/// The steps are as follows:
///
/// 1. Works through the grid row-wise, starting with the cell at 0,0. Initializes the “run” set to
/// be empty.
///
/// 2. Adds the current cell to the “run” set.
///
/// 3. For the current cell, randomly decides whether to carve east or not.
///
/// 4. If a passage was carved, makes the new cell the current cell and repeats steps 2-4.
///
/// 5. If a passage was not carved, chooses any one of the cells in the run set and carves a passage
/// north. Then empties the run set, sets the next cell in the row to be the current cell, and
/// repeats steps 2-5.
///
/// 6. Continues until all rows have been processed.