add Cell tester + FIX: west setter for Cell class

This commit is contained in:
2026-03-19 16:42:45 +01:00
parent ac13df160f
commit 97b35fe3eb
6 changed files with 47 additions and 31 deletions
+2 -17
View File
@@ -41,25 +41,10 @@ class Cell(BaseModel):
return self.value & 4 == 4
def set_west(self, is_wall: bool) -> None:
if (not is_wall and self.value | 8 == 15) or (
is_wall and self.value | 8 != 15
if (not is_wall and self.value | 7 == 15) or (
is_wall and self.value | 7 != 15
):
self.value = self.value ^ (8)
def get_west(self) -> bool:
return self.value & 8 == 8
def main() -> None:
c = Cell(value=1)
print(c.get_north())
c.set_north(True)
print(c.get_north())
c.set_north(True)
print(c.get_north())
c.set_north(False)
print(c.get_north())
if __name__ == "__main__":
main()
+7 -9
View File
@@ -7,9 +7,8 @@ import math
class MazeGenerator(ABC):
@abstractmethod
@classmethod
def generator(
cls, height: int, width: int
self, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]: ...
@@ -63,9 +62,8 @@ class Kruskal(MazeGenerator):
base_set += set
sets.remove(set)
@classmethod
def generator(
cls, height: int, width: int
self, height: int, width: int
) -> Generator[np.ndarray, None, np.ndarray]:
sets = [[i] for i in range(height * width)]
walls = []
@@ -77,13 +75,13 @@ class Kruskal(MazeGenerator):
walls += [(w + (width * h), w + (width * h) + width)]
np.random.shuffle(walls)
yield cls.walls_to_maze(walls, height, width)
yield self.walls_to_maze(walls, height, width)
for wall in walls:
if not cls.is_in_same_set(sets, wall):
cls.merge_sets(sets, wall)
if not self.is_in_same_set(sets, wall):
self.merge_sets(sets, wall)
walls.remove(wall)
yield cls.walls_to_maze(walls, height, width)
return cls.walls_to_maze(walls, height, width)
yield self.walls_to_maze(walls, height, width)
return self.walls_to_maze(walls, height, width)
def main():
+1 -2
View File
@@ -4,5 +4,4 @@ from .Maze import Maze
class MazeSolver(ABC):
@abstractmethod
@classmethod
def solve(cls, maze: Maze) -> str: ...
def solve(self, maze: Maze) -> str: ...