]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
Acyclic generation
authorAxy <gilliardmarthey.axel@gmail.com>
Thu, 5 Feb 2026 23:17:57 +0000 (00:17 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Thu, 5 Feb 2026 23:17:57 +0000 (00:17 +0100)
__main__.py
amazeing/maze.py

index 6989c13dc38136195c5168c16757055b3eeb55d5..4ccbd6ffa899e02f422b0a0b1f336caea19e49d0 100644 (file)
@@ -2,21 +2,24 @@ from amazeing import Maze, TTYBackend, Pattern
 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)
index 65b69565ed227da1d507a99b5adf45a9eacde005..9777e4b8a31eebbc07cfd2e89689ad2f50905bd6 100644 (file)
@@ -64,6 +64,11 @@ class WallCoord:
         )
         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:
@@ -278,3 +283,16 @@ class Maze:
             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()
+        )