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
import numpy as np
from .classes.Cell import Cell
import math
class MazeGenerator:
class Kruskal:
class MazeGenerator(ABC):
@abstractmethod
@classmethod
def generator(
cls, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]: ...
class Kruskal(MazeGenerator):
@staticmethod
def walls_to_maze(
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((y / width))][y % width].set_west(True)
case width:
maze[math.trunc((x / width))][x % width].set_south(
True
)
maze[math.trunc((y / width))][y % width].set_north(
True
)
maze[math.trunc((x / width))][x % width].set_south(True)
maze[math.trunc((y / width))][y % width].set_north(True)
for x in range(height):
for y in range(width):
if x == 0:
@@ -39,9 +43,7 @@ class MazeGenerator:
return maze
@staticmethod
def is_in_same_set(
sets: list[list[int]], wall: tuple[int, int]
) -> bool:
def is_in_same_set(sets: list[list[int]], wall: tuple[int, int]) -> bool:
a, b = wall
for set in sets:
if a in set and b in set:
@@ -62,7 +64,7 @@ class MazeGenerator:
sets.remove(set)
@classmethod
def kruskal(
def generator(
cls, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]:
sets = [[i] for i in range(height * width)]
+1
View File
@@ -2,6 +2,7 @@ from dataclasses import dataclass
import numpy
from .Cell import Cell
from ..MazeGenerator import MazeGenerator
@dataclass