From: Axy Date: Mon, 23 Mar 2026 02:26:29 +0000 (+0100) Subject: Refactor part two X-Git-Url: https://git.uwuaxy.net/?a=commitdiff_plain;h=3465dfe4ce00f0a8956738804606b51d38b1f18e;p=axy%2Fft%2Fa-maze-ing.git Refactor part two --- diff --git a/__main__.py b/__main__.py index 963a1b1..348fd28 100644 --- a/__main__.py +++ b/__main__.py @@ -1,11 +1,9 @@ import time -from amazeing import ( +from amazeing.maze import ( Maze, - TTYBackend, Pattern, - maze_make_pacman, - maze_make_perfect, ) +from amazeing.display import TTYBackend import random @@ -15,8 +13,10 @@ from amazeing.maze import ( CellCoord, MazeDirtyTracker, MazePacmanTracker, + maze_make_pacman, + maze_make_perfect, ) -from amazeing.maze_display.TTYdisplay import TileCycle, TileMaps, extract_pairs +from amazeing.display import TileCycle, TileMaps, extract_pairs from amazeing.utils import IVec2 config = Config.parse(open("./example.conf").read()) diff --git a/amazeing/__init__.py b/amazeing/__init__.py index b0d3918..945cf3a 100644 --- a/amazeing/__init__.py +++ b/amazeing/__init__.py @@ -1,21 +1,2 @@ __version__ = "0.0.0" __author__ = "luflores & agilliar" - - -from .maze.maze_coords import WallCoord -from .maze.maze import Maze -from .maze.maze_pattern import Pattern -from .maze_display.TTYdisplay import TTYBackend -from .maze_make_empty import maze_make_empty -from .maze_make_perfect import maze_make_perfect -from .maze_make_pacman import maze_make_pacman - -__all__ = [ - "Maze", - "WallCoord", - "TTYBackend", - "Pattern", - "maze_make_empty", - "maze_make_perfect", - "maze_make_pacman", -] diff --git a/amazeing/display/__init__.py b/amazeing/display/__init__.py new file mode 100644 index 0000000..6864f07 --- /dev/null +++ b/amazeing/display/__init__.py @@ -0,0 +1,6 @@ +__version__ = "0.0.0" +__author__ = "luflores & agilliar" + +from .tty import TTYBackend, TileCycle, TileMaps, extract_pairs + +__all__ = ["TTYBackend", "TileCycle", "TileMaps", "extract_pairs"] diff --git a/amazeing/maze_display/layout.py b/amazeing/display/layout.py similarity index 100% rename from amazeing/maze_display/layout.py rename to amazeing/display/layout.py diff --git a/amazeing/maze_display/TTYdisplay.py b/amazeing/display/tty.py similarity index 99% rename from amazeing/maze_display/TTYdisplay.py rename to amazeing/display/tty.py index ad6b08a..d142986 100644 --- a/amazeing/maze_display/TTYdisplay.py +++ b/amazeing/display/tty.py @@ -3,7 +3,7 @@ from collections.abc import Callable, Generator, Iterable from dataclasses import dataclass from amazeing.utils import BiMap from amazeing.config.config_parser import Color, Config, ColoredLine, ColorPair -from amazeing.maze_display.layout import ( +from amazeing.display.layout import ( BInt, Box, DBox, diff --git a/amazeing/maze/__init__.py b/amazeing/maze/__init__.py index 59f7cbf..e7ab7b7 100644 --- a/amazeing/maze/__init__.py +++ b/amazeing/maze/__init__.py @@ -6,6 +6,9 @@ from .maze_coords import Cardinal, Orientation, WallCoord, CellCoord from .maze_dirty_tracker import MazeDirtyTracker from .maze_pacman_tracker import MazePacmanTracker from .maze_network_tracker import MazeNetworkTracker +from .maze_make_empty import maze_make_empty +from .maze_make_pacman import maze_make_pacman +from .maze_make_perfect import maze_make_perfect __all__ = [ "Maze", @@ -17,4 +20,7 @@ __all__ = [ "MazeDirtyTracker", "MazePacmanTracker", "MazeNetworkTracker", + "maze_make_empty", + "maze_make_pacman", + "maze_make_perfect", ] diff --git a/amazeing/maze_make_empty.py b/amazeing/maze/maze_make_empty.py similarity index 100% rename from amazeing/maze_make_empty.py rename to amazeing/maze/maze_make_empty.py diff --git a/amazeing/maze_make_pacman.py b/amazeing/maze/maze_make_pacman.py similarity index 100% rename from amazeing/maze_make_pacman.py rename to amazeing/maze/maze_make_pacman.py diff --git a/amazeing/maze_make_perfect.py b/amazeing/maze/maze_make_perfect.py similarity index 100% rename from amazeing/maze_make_perfect.py rename to amazeing/maze/maze_make_perfect.py diff --git a/amazeing/maze_display/__init__.py b/amazeing/maze_display/__init__.py deleted file mode 100644 index 33dd123..0000000 --- a/amazeing/maze_display/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -__version__ = "0.0.0" -__author__ = "luflores & agilliar" - -__all__ = [] diff --git a/amazeing/maze_display/backend.py b/amazeing/maze_display/backend.py deleted file mode 100644 index fc0ee68..0000000 --- a/amazeing/maze_display/backend.py +++ /dev/null @@ -1,68 +0,0 @@ -from collections.abc import Callable -from typing import Type, cast - - -class IVec2[T = int]: - def copy(self, inner_copy: Callable[[T], T] = lambda e: e) -> "IVec2[T]": - return IVec2(inner_copy(self.x), inner_copy(self.y)) - - def __init__(self, x: T, y: T) -> None: - self.x: T = x - self.y: T = y - - @staticmethod - def splat(n: T) -> "IVec2[T]": - return IVec2(n, n) - - def __repr__(self) -> str: - return f"{self.x, self.y}" - - @staticmethod - def with_op[T2]( - op: Callable[[T, T], T2], - ) -> Callable[["IVec2[T]", "T | IVec2[T]"], "IVec2[T2]"]: - return lambda self, other: IVec2( - op( - self.x, - ( - other - if isinstance(other, IVec2) - else (other := type(self).splat(other)) - ).x, - ), - op(self.y, cast(IVec2[T], other).y), - ) - - def innertype(self) -> Type[T]: - return type(self.x) - - def __mul__(self, other: "IVec2[T]") -> "IVec2[T]": - return IVec2(self.x * other.x, self.y * other.y) # type:ignore - - def __add__(self, other: "IVec2[T]") -> "IVec2[T]": - return IVec2(self.x + other.x, self.y + other.y) # type:ignore - - def __sub__(self, other: "IVec2[T]") -> "IVec2[T]": - return IVec2(self.x - other.x, self.y - other.y) # type:ignore - - def __floordiv__(self, other: "IVec2[T]") -> "IVec2[T]": - return IVec2(self.x // other.x, self.y // other.y) # type:ignore - - def __mod__(self, other: "IVec2[T]") -> "IVec2[T]": - return IVec2(self.x % other.x, self.y % other.y) # type:ignore - - def __eq__(self, value: object, /) -> bool: - return ( - isinstance(value, IVec2) - and self.x == value.x - and self.y == value.y - ) - - def __hash__(self) -> int: - return hash((self.x, self.y)) - - def xy(self) -> tuple[T, T]: - return (self.x, self.y) - - def yx(self) -> tuple[T, T]: - return (self.y, self.x)