mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
Generator class rework
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -2,6 +2,7 @@ from dataclasses import dataclass
|
||||
|
||||
import numpy
|
||||
from .Cell import Cell
|
||||
from ..MazeGenerator import MazeGenerator
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user