-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutline
26 lines (26 loc) · 930 Bytes
/
outline
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
current_node_i = 0
current_node_j = 0
stack_i = [0]
stack_j = [0]
stack_ctr = 1
any_neighbors = 0
while (stack_ctr >= 0) {
any_neighbors = 0
if (current_node_i + 1 < HEIGHT && cells[i + 1, j].visited == false) any_neighbors |= 1
if (current_node_j + 1 < WIDTH && cells[i, j+1].visited == false) any_neighbors |= 2
if (current_node_i - 1 >= 0 && cells[i - 1, j].visited == false) any_neighbors |= 4
if (current_node_j - 1 >= 0 && cells[i, j-1].visited == false) any_neighbors |= 8
if (any_neighbors == 0) {
current_node_i <= stack_i[stack_ctr - 1]
current_node_j <= stack_j[stack_ctr - 1]
stack_ctr <= stack_ctr - 1
} else {
n = random_neighbor(any_neighbors)
stack_i[stack_ctr] <= current_node_i
stack_j[stack_ctr] <= current_node_j
stack_ctr <= stack_ctr + 1
remove_walls()
cells[current_node_i][current_node_j] |= visited;
current_node_i <= n.i
current_node_j <= n.j
}