-import curses
import time
from amazeing import (
Maze,
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())
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)
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)
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",
"TTYBackend",
"maze_make_pacman",
"maze_make_perfect",
+ "maze_make_empty",
]
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 (
many,
many_count,
none_of,
- null_parser,
one_of,
pair,
parser_complete,
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(
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,
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,
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()
)
-from sys import stderr
from typing import Callable, Generator, Iterable, cast
from amazeing.maze_display.backend import IVec2
]
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)
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)
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,
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
}
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: "
case _:
return KeyboardInput(key)
self.present()
+ return None
from abc import ABC, abstractmethod
from collections.abc import Callable
-from sys import stderr
from .backend import IVec2