From: Axy Date: Fri, 27 Mar 2026 16:58:14 +0000 (+0100) Subject: Small fixes X-Git-Url: https://git.uwuaxy.net/flexible_layout.mp4?a=commitdiff_plain;h=6251e3e1b859fc1ca07a46e4b2c3a5301afcc1bd;p=axy%2Fft%2Fa-maze-ing.git Small fixes --- diff --git a/a_maze_ing.py b/a_maze_ing.py index fcc26db..d72b0f6 100644 --- a/a_maze_ing.py +++ b/a_maze_ing.py @@ -9,7 +9,7 @@ from mazegen.maze import ( make_perfect, ) from mazegen.config.config_parser import Config -from mazegen.maze.output import format_maze +from mazegen.maze.output import format_output import random config = Config.parse(open("./example.conf").read()) @@ -53,6 +53,9 @@ if config.visual: maze_main() + with open(config.output_file, "w") as f: + f.write(format_output(maze)) + while tty_tracker is not None: tty_tracker.display_maze(wait_for_tick=True) except MazeRegenerate: diff --git a/mazegen/config/config_parser.py b/mazegen/config/config_parser.py index e6e5228..c0a0223 100644 --- a/mazegen/config/config_parser.py +++ b/mazegen/config/config_parser.py @@ -384,7 +384,7 @@ class Config: height: int entry: IVec2 | None exit: IVec2 | None - output_file: str | None + output_file: str perfect: bool seed: int | None screensaver: bool @@ -417,7 +417,7 @@ class Config: "HEIGHT": IntField, "ENTRY": OptionalField(CoordField), "EXIT": OptionalField(CoordField), - "OUTPUT_FILE": OptionalField(PathField), + "OUTPUT_FILE": PathField, "PERFECT": DefaultedField(BoolField, True), "SEED": OptionalField(IntField), "SCREENSAVER": DefaultedField(BoolField, False), diff --git a/mazegen/maze/output.py b/mazegen/maze/output.py index 266510f..e710ada 100644 --- a/mazegen/maze/output.py +++ b/mazegen/maze/output.py @@ -3,13 +3,12 @@ from mazegen.utils import CellCoord, Cardinal from mazegen.maze.path import pathfind_astar -def to_hex(cell: list[bool]): +def to_hex(cell: list[bool]) -> str: val = ( - 1 - if cell[0] - else ( - 0 + 2 if cell[1] else 0 + 4 if cell[2] else 0 + 8 if cell[3] else 0 - ) + (1 if cell[0] else 0) + + (2 if cell[1] else 0) + + (4 if cell[2] else 0) + + (8 if cell[3] else 0) ) return "0123456789ABCDEF"[val] @@ -37,6 +36,8 @@ def format_doors(maze: Maze) -> str: def format_path(maze: Maze) -> str: path = pathfind_astar(maze) + if path is None: + raise Exception("Could not pathfind!") return "".join(map(str, path)) + "\n" diff --git a/mazegen/utils/coords.py b/mazegen/utils/coords.py index 1e484ff..ee7d0f5 100644 --- a/mazegen/utils/coords.py +++ b/mazegen/utils/coords.py @@ -44,7 +44,7 @@ class Cardinal(Enum): def right(self) -> "Cardinal": return self.left().opposite() - def __repr__(self) -> str: + def __str__(self) -> str: match self: case Cardinal.NORTH: return "N"