]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
cleanup
authorAxy <gilliardmarthey.axel@gmail.com>
Mon, 9 Mar 2026 19:59:49 +0000 (20:59 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Mon, 9 Mar 2026 19:59:49 +0000 (20:59 +0100)
__main__.py
amazeing/__init__.py
amazeing/config/config_parser.py
amazeing/maze_class/maze.py
amazeing/maze_class/maze_pattern.py
amazeing/maze_display/TTYdisplay.py
amazeing/maze_display/layout.py

index 22d26e940c1b826767ef470f16bca1dbe6a0ffa0..cd2d05ddb3fae5e5dc4c8a00fe602d2aaef723fc 100644 (file)
@@ -1,4 +1,3 @@
-import curses
 import time
 from amazeing import (
     Maze,
@@ -6,15 +5,14 @@ from amazeing import (
     Pattern,
     maze_make_pacman,
     maze_make_perfect,
+    maze_make_empty,
 )
 import random
 
-from sys import stderr
 from amazeing.config.config_parser import Config
-from amazeing.maze_class.maze_walls import Cardinal, CellCoord
-from amazeing.maze_display.TTYdisplay import Tile, TileMaps, extract_pairs
-from amazeing.maze_display.backend import BackendEvent, CloseRequested, IVec2
-from amazeing.maze_make_empty import maze_make_empty
+from amazeing.maze_class.maze_walls import CellCoord
+from amazeing.maze_display.TTYdisplay import TileMaps, extract_pairs
+from amazeing.maze_display.backend import CloseRequested, IVec2
 
 config = Config.parse(open("./example.conf").read())
 
@@ -29,9 +27,9 @@ maze.outline()
 
 excluded = set()
 if config.entry is not None:
-    excluded.add(config.entry)
+    excluded.add(CellCoord(config.entry))
 if config.exit is not None:
-    excluded.add(config.exit)
+    excluded.add(CellCoord(config.exit))
 
 pattern = Pattern(config.maze_pattern).centered_for(dims, excluded)
 pattern.fill(maze)
@@ -99,9 +97,8 @@ def poll_events(timeout_ms: int = -1) -> None:
 
 maze_make_perfect(maze, callback=display_maze)
 maze_make_pacman(maze, walls_const, callback=display_maze)
-print(
-    maze.pathfind(CellCoord(config.entry), CellCoord(config.exit)), file=stderr
-)
+if config.entry is not None and config.exit is not None:
+    path = maze.pathfind(CellCoord(config.entry), CellCoord(config.exit))
 while False:
     maze_make_perfect(maze, callback=display_maze)
     # poll_events(200)
index 7b2c0d22beefddb5bb924bef330be88098fafa2d..2557f93375e87b023aa1d3afc78c2e5478c6fc07 100644 (file)
@@ -5,6 +5,7 @@ from amazeing.maze_class import WallCoord, Maze, Pattern
 from amazeing.maze_display import Backend, IVec2, TTYBackend
 from .maze_make_pacman import maze_make_pacman
 from .maze_make_perfect import maze_make_perfect
+from .maze_make_empty import maze_make_empty
 
 __all__ = [
     "WallCoord",
@@ -15,4 +16,5 @@ __all__ = [
     "TTYBackend",
     "maze_make_pacman",
     "maze_make_perfect",
+    "maze_make_empty",
 ]
index b6bd56c77afe6e8195fef750c7c82dba85ccb76d..8332eabc576706bf4b6c420909ea9fc005a08c6a 100644 (file)
@@ -1,6 +1,6 @@
 from abc import ABC, abstractmethod
-from collections.abc import Callable, Generator
-from typing import Any, Type
+from collections.abc import Callable
+from typing import Any, Type, cast
 
 from amazeing.maze_display.backend import IVec2
 from .parser_combinator import (
@@ -14,7 +14,6 @@ from .parser_combinator import (
     many,
     many_count,
     none_of,
-    null_parser,
     one_of,
     pair,
     parser_complete,
@@ -89,20 +88,26 @@ type ColoredLine = list[tuple[ColorPair, str]]
 
 
 def parse_color(s: str) -> ParseResult[Color]:
-    return alt(
-        parser_map(
-            lambda l: (l[0], l[1], l[2]),
-            many(parse_int, 3, 3, spaced(tag(","))),
-        ),
-        parse_varname,
-    )(s)
+    return cast(
+        ParseResult[Color],
+        alt(
+            parser_map(
+                tuple,
+                many(parse_int, 3, 3, spaced(tag(","))),
+            ),
+            parse_varname,
+        )(s),
+    )
 
 
 def parse_color_pair(s: str) -> ParseResult[ColorPair]:
-    return parser_map(
-        lambda l: (l[0], l[1]),
-        many(parse_color, 2, 2, spaced(tag(":"))),
-    )(s)
+    return cast(
+        ParseResult[ColorPair],
+        parser_map(
+            tuple,
+            many(parse_color, 2, 2, spaced(tag(":"))),
+        )(s),
+    )
 
 
 def parse_colored_line(
@@ -219,7 +224,7 @@ def OptionalField[T](cls: Type[ConfigField[T]]) -> Type[ConfigField[T | None]]:
 def DefaultedField[T](
     cls: Type[ConfigField[T]], default: T
 ) -> Type[ConfigField[T]]:
-    class Inner(cls):
+    class Inner(cls):  # type: ignore
         def __init__(
             self,
             name: str,
@@ -233,7 +238,7 @@ def DefaultedField[T](
 def DefaultedStrField[T](
     cls: Type[ConfigField[T]], default_strs: list[str]
 ) -> Type[ConfigField[T]]:
-    class Inner(cls):
+    class Inner(cls):  # type: ignore
         def __init__(
             self,
             name: str,
@@ -267,7 +272,7 @@ def ListParser[T](parser: Parser[T]) -> Type[ConfigField[list[T]]]:
 
         def merge(self, vals: list[list[T]]) -> list[T]:
             return (
-                [e for l in vals for e in l]
+                [e for val in vals for e in val]
                 if len(vals) > 0
                 else self.default()
             )
index 28804cee9c93a596db57a61ae8f05ecb93fa2dee..1d303b3108aa0725cae3439bf84fc8e2702f56e8 100644 (file)
@@ -1,4 +1,3 @@
-from sys import stderr
 from typing import Callable, Generator, Iterable, cast
 
 from amazeing.maze_display.backend import IVec2
index 69ff2b6ecc52c50b8d6c71085e6239ad9e1040dc..04d889e72a43d40f5c7dfbadd2254f3573af3483 100644 (file)
@@ -15,10 +15,11 @@ class Pattern:
     ]
 
     def __init__(self, pat: list[str] | set[CellCoord]) -> None:
+        self.__cells: set[CellCoord]
         if isinstance(pat, set):
-            self.__cells: set[CellCoord] = pat
+            self.__cells = pat
             return
-        self.__cells: set[CellCoord] = {
+        self.__cells = {
             CellCoord(x, y)
             for y, line in enumerate(pat)
             for x, char in enumerate(line)
@@ -99,7 +100,9 @@ class Pattern:
         if len(slots) == 0:
             return Pattern([])
         ideal = (canvas - dims) // 2
-        slot = min(slots, key=lambda e: sum(((e := e - ideal) * e).xy()))
+        slot = min(
+            slots, key=lambda c: int.__add__(*((e := c - ideal) * e).xy())
+        )
 
         return normalized.offset(slot)
 
index a9fa9e15c028a4df8cada9d7c92b165883d5e0bb..57c15d05dbbf60d3c75bfca76d1bb657720826a2 100644 (file)
@@ -1,5 +1,4 @@
 from collections.abc import Callable, Generator, Iterable
-from sys import stderr
 from ..config.config_parser import Color, Config, ColoredLine, ColorPair
 from amazeing.maze_display.layout import (
     BInt,
@@ -11,10 +10,7 @@ from amazeing.maze_display.layout import (
     layout_fair,
     layout_priority,
     layout_sort_chunked,
-    layout_sort_shuffled,
     layout_split,
-    vpad_box,
-    hpad_box,
 )
 from .backend import Backend, IVec2, BackendEvent, KeyboardInput
 import curses
@@ -234,11 +230,11 @@ def extract_pairs(
     }
     available_colors = {i for i in range(0, curses.COLORS)}
     res_colors: dict[Color, int] = {}
-    for color in var_colors:
-        if color not in color_lookup:
-            raise BackendException("Unknown color " + color + " in config")
-        res_colors[color] = color_lookup[color]
-        available_colors -= {color_lookup[color]}
+    for var_color in var_colors:
+        if var_color not in color_lookup:
+            raise BackendException("Unknown color " + var_color + " in config")
+        res_colors[var_color] = color_lookup[var_color]
+        available_colors -= {color_lookup[var_color]}
     if len(available_colors) < len(value_colors):
         raise BackendException(
             "Too many value color values in config: "
@@ -421,3 +417,4 @@ class TTYBackend(Backend[int]):
             case _:
                 return KeyboardInput(key)
         self.present()
+        return None
index 45118cefe4aa684ad55f759c3dffbfdfc2b5aba9..248280181f9fb39a10df2932e214cab41b83c351 100644 (file)
@@ -1,6 +1,5 @@
 from abc import ABC, abstractmethod
 from collections.abc import Callable
-from sys import stderr
 from .backend import IVec2