Generator class rework

This commit is contained in:
2026-03-19 14:59:18 +01:00
parent 84c4b63a6c
commit c6c7e6e47e
2 changed files with 77 additions and 74 deletions
+14 -12
View File
@@ -1,11 +1,19 @@
from abc import ABC, abstractmethod
from typing import Generator from typing import Generator
import numpy as np import numpy as np
from .classes.Cell import Cell from .classes.Cell import Cell
import math import math
class MazeGenerator: class MazeGenerator(ABC):
class Kruskal: @abstractmethod
@classmethod
def generator(
cls, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]: ...
class Kruskal(MazeGenerator):
@staticmethod @staticmethod
def walls_to_maze( def walls_to_maze(
walls: list[tuple[int, int]], height: int, width: int walls: list[tuple[int, int]], height: int, width: int
@@ -20,12 +28,8 @@ class MazeGenerator:
maze[math.trunc((x / width))][x % width].set_est(True) maze[math.trunc((x / width))][x % width].set_est(True)
maze[math.trunc((y / width))][y % width].set_west(True) maze[math.trunc((y / width))][y % width].set_west(True)
case width: case width:
maze[math.trunc((x / width))][x % width].set_south( maze[math.trunc((x / width))][x % width].set_south(True)
True maze[math.trunc((y / width))][y % width].set_north(True)
)
maze[math.trunc((y / width))][y % width].set_north(
True
)
for x in range(height): for x in range(height):
for y in range(width): for y in range(width):
if x == 0: if x == 0:
@@ -39,9 +43,7 @@ class MazeGenerator:
return maze return maze
@staticmethod @staticmethod
def is_in_same_set( def is_in_same_set(sets: list[list[int]], wall: tuple[int, int]) -> bool:
sets: list[list[int]], wall: tuple[int, int]
) -> bool:
a, b = wall a, b = wall
for set in sets: for set in sets:
if a in set and b in set: if a in set and b in set:
@@ -62,7 +64,7 @@ class MazeGenerator:
sets.remove(set) sets.remove(set)
@classmethod @classmethod
def kruskal( def generator(
cls, height: int, width: int cls, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]: ) -> Generator[np.ndarray, None, np.ndarray]:
sets = [[i] for i in range(height * width)] sets = [[i] for i in range(height * width)]
+1
View File
@@ -2,6 +2,7 @@ from dataclasses import dataclass
import numpy import numpy
from .Cell import Cell from .Cell import Cell
from ..MazeGenerator import MazeGenerator
@dataclass @dataclass