import random
-maze = Maze(50, 20)
+dims = (30, 30)
+
+maze = Maze(*dims)
maze.outline()
-pattern = Pattern(Pattern.FT_PATTERN).centered_for((50, 20))
+pattern = Pattern(Pattern.FT_PATTERN).centered_for(dims)
pattern.fill(maze)
empty = list(maze.walls_empty())
random.shuffle(empty)
for wall in empty:
- if not maze.wall_bisects(wall):
- maze.fill_wall(wall)
+ if maze.wall_bisects(wall): # or maze.wall_cuts_cycle(wall):
+ continue
+ maze.fill_wall(wall)
-backend = TTYBackend(50, 20)
-backend.set_style("#")
+backend = TTYBackend(*dims, style="\x1b[48;5;240m \x1b[0m")
+backend.set_style("\x1b[48;5;248m \x1b[0m")
for wall in maze.walls_full():
for pixel in wall.pixel_coords():
backend.draw_pixel(pixel)
)
return (PixelCoord(x, y) for x in x_iter for y in y_iter)
+ def neighbour_cells(self) -> list["CellCoord"]:
+ if self.orientation == Orientation.HORIZONTAL:
+ return [CellCoord(self.b, self.a), CellCoord(self.b, self.a - 1)]
+ return [CellCoord(self.a, self.b), CellCoord(self.a - 1, self.b)]
+
class CellCoord:
def __init__(self, x: int, y: int) -> None:
if neighbour.is_full()
}
return len(a & b) != 0
+
+ def wall_cuts_cycle(self, wall: WallCoord) -> bool:
+ return any(
+ len(
+ [
+ ()
+ for wall in self.get_walls_checked(list(cell.walls()))
+ if wall.is_full()
+ ]
+ )
+ >= 2
+ for cell in wall.neighbour_cells()
+ )