Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ae11259
Remove partition index counter from binary space partitioning routine
jbdyn Nov 10, 2025
364dec2
Define `add_wall_and_split` as pure function
jbdyn Nov 13, 2025
417b374
Restore NumPy compatibility for mazes with odd height
jbdyn Nov 19, 2025
321492e
Redefine a partition to include its surrounding walls
jbdyn Nov 19, 2025
04a3c34
Introduce temporary API wrapper for sampling walls
jbdyn Nov 20, 2025
4e4061b
Use sets to filter out gaps from inner walls
jbdyn Nov 20, 2025
965f1a1
Rework definitions for maze variables
jbdyn Nov 21, 2025
0ac6d44
Take maze partition measurements in the `u`-`v`-space
jbdyn Nov 21, 2025
b4c0b1f
Update comments for the binary space partitioning algorithm
jbdyn Nov 21, 2025
2bda7db
Update comments for the generation of the left half of the maze
jbdyn Nov 21, 2025
ca4d890
Substract the bot positions from sampled walls
jbdyn Nov 21, 2025
1306856
Rename maze space transformations
jbdyn Nov 25, 2025
1415956
Extend partition documentation
jbdyn Nov 28, 2025
8667085
Add test for finding chambers in a half maze
jbdyn Nov 26, 2025
adb8add
Make `walls_to_graph` handle open mazes
jbdyn Nov 28, 2025
a022651
Restrict chamber finding on the left maze half
jbdyn Nov 28, 2025
f7e412c
Add comments for module constants
jbdyn Nov 28, 2025
167eac2
Rename border-related variables
jbdyn Nov 28, 2025
8fddd37
Rename `add_wall_and_split` to `add_inner_walls` and slightly change …
jbdyn Nov 28, 2025
0942dd0
Link the return value signature of `find_trapped_tiles` to keyword ar…
jbdyn Nov 28, 2025
b957cac
Redefine `mirror` to not unite original and mirrored sets
jbdyn Nov 28, 2025
d696912
Remove superfluous set creation for set-like graph node view
jbdyn Nov 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions pelita/maze_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,28 @@ def add_wall_and_split(partition, walls, ngaps, vertical, rng=None):
# alongside the number of gaps in wall and its orientation
partitions = [partition + (ngaps, vertical)]

# partition index
p = 0

# The infinite loop is always exiting, since the position of the walls
# The loop is always exiting, since the position of the walls
# `pos` is in `[xmin + 1, xmax - (xmin + 1)]` or
# in `[ymin + 1, ymax - (ymin + 1)]`, respectively, and thus always
# yielding partitions smaller than the current partition.
# The checks for `height < 3`, `width < 3` and
# `partition_length < rng.randint(3, 5)` ensure no further addition of
# partitions, and `p += 1` in those checks and after partitioning ensure
# that we always advance in the list of partitions.
# partitions, and `partitions.pop()` ensures that the list of partitions
# is always drained.
#
# So, partitions always shrink, no new partitions are added once they
# shrank below a threshold, and the loop increases the list index in
# every case.
while True:
# shrank below a threshold, and the loop draines the list in
# every iteration.
while len(partitions) > 0:
Comment thread
jbdyn marked this conversation as resolved.
# get the next partition of any is available
try:
partition = partitions[p]
except IndexError:
break

(xmin, ymin), (xmax, ymax), ngaps, vertical = partition
(xmin, ymin), (xmax, ymax), ngaps, vertical = partitions.pop()

# the size of the maze partition we work on
width = xmax - xmin + 1
height = ymax - ymin + 1

# if the partition is too small, move on with the next one
if height < 3 and width < 3:
p += 1
continue

# insert a wall only if there is some space in the around it in the
Expand All @@ -165,7 +156,6 @@ def add_wall_and_split(partition, walls, ngaps, vertical, rng=None):
# otherwise move on with the next one
partition_length = width if vertical else height
if partition_length < rng.randint(3, 5):
p += 1
continue

# the row/column to put the horizontal/vertical wall on
Expand Down Expand Up @@ -228,22 +218,22 @@ def add_wall_and_split(partition, walls, ngaps, vertical, rng=None):

if vertical:
new = [
# left
((xmin, ymin), (pos - 1, ymax), ngaps, not vertical),
# right
((pos + 1, ymin), (xmax, ymax), ngaps, not vertical),
]
else:
new = [
# top
((xmin, ymin), (xmax, pos - 1), ngaps, not vertical),
# bottom
((xmin, pos + 1), (xmax, ymax), ngaps, not vertical),
]

# queue the new partitions next;
# queue the new partitions next, appending the left/top one last;
# ensures maze stability
partitions.insert(p + 1, new[1])
partitions.insert(p + 1, new[0])

# increase the partition index
p += 1
partitions.extend(new[::-1])
Comment thread
jbdyn marked this conversation as resolved.
Comment thread
jbdyn marked this conversation as resolved.

return walls
Comment thread
jbdyn marked this conversation as resolved.

Expand Down
Loading