Skip to content

Commit 10fca05

Browse files
committed
Add explanation that infinite maze generation loop is always guaranteed to exit
1 parent 57763b2 commit 10fca05

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

pelita/maze_generator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ def add_wall_and_split(partition, walls, ngaps, vertical, rng=None):
128128
# partition index
129129
p = 0
130130

131+
# The infinite loop is always exiting, since the position of the walls
132+
# `pos` is in `[xmin + 1, xmax - (xmin + 1)]` or
133+
# in `[ymin + 1, ymax - (ymin + 1)]`, respectively, and thus always
134+
# yielding partitions smaller than the current partition.
135+
# The checks for `height < 3`, `width < 3` and
136+
# `partition_length < rng.randint(3, 5)` ensure no further addition of
137+
# partitions, and `p += 1` in those checks and after partitioning ensure
138+
# that we always advance in the list of partitions.
139+
#
140+
# So, partitions always shrink, no new partitions are added once they
141+
# shrank below a threshold, and the loop increases the list index in
142+
# every case.
131143
while True:
132144
# get the next partition of any is available
133145
try:

0 commit comments

Comments
 (0)