]> Untitled Git - axy/ft/a-maze-ing.git/commitdiff
Small fixes
authorAxy <gilliardmarthey.axel@gmail.com>
Fri, 27 Mar 2026 16:58:14 +0000 (17:58 +0100)
committerAxy <gilliardmarthey.axel@gmail.com>
Fri, 27 Mar 2026 16:58:14 +0000 (17:58 +0100)
a_maze_ing.py
mazegen/config/config_parser.py
mazegen/maze/output.py
mazegen/utils/coords.py

index fcc26dbc655055c4696ca32e15ba9fcbbf998d77..d72b0f6b31d598c8cc498d3f1b55f73edeb0bc1a 100644 (file)
@@ -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:
index e6e522877a1fb2926c641ce06e32cfd86e513c85..c0a02237e4fbfa647bcb4f2220c2c0e70f2ead1b 100644 (file)
@@ -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),
index 266510f5b8e6cd93a22367c312b1797355c18cc1..e710adad0e40f95d88d4271db3ce05da78e78346 100644 (file)
@@ -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"
 
 
index 1e484ff826773473a53635ab6dc25ddcb6a6bb62..ee7d0f5cd7719b6c0921e53065b6b9ad590d176c 100644 (file)
@@ -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"