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())
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:
height: int
entry: IVec2 | None
exit: IVec2 | None
- output_file: str | None
+ output_file: str
perfect: bool
seed: int | None
screensaver: bool
"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),
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]
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"
def right(self) -> "Cardinal":
return self.left().opposite()
- def __repr__(self) -> str:
+ def __str__(self) -> str:
match self:
case Cardinal.NORTH:
return "N"