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
config = Config.parse(open("./example.conf").read())
backend.draw_tile(pixel)
maze.clear_dirty()
backend.present()
- poll_events(0)
+ poll_events(2)
def poll_events(timeout_ms: int = -1) -> None:
maze_make_pacman(maze, walls_const, callback=display_maze)
while True:
maze_make_perfect(maze, callback=display_maze)
- maze_make_pacman(maze, walls_const, callback=display_maze)
+ poll_events(200)
+ # maze_make_pacman(maze, walls_const, callback=display_maze)
+ maze_make_empty(maze, walls_const, callback=display_maze)
+ poll_events(200)
maze._rebuild()
poll_events()
from amazeing.maze_display.layout import (
BInt,
Box,
+ DBox,
FBox,
HBox,
VBox,
) -> None:
if size.x <= 0 or size.y <= 0:
return
- print(src, dst, size, window.getmaxyx(), file=stderr)
self.__pad.overwrite(
window, *src.yx(), *dst.yx(), *(dst + size - IVec2.splat(1)).yx()
)
IVec2(BInt(dims.x), BInt(dims.y)),
lambda at, into: self.__pad.present(at, into, self.__scratch),
)
- filler_box = FBox(
- IVec2(BInt(0, True), BInt(0, True)),
- lambda at, into: (
- None
- if self.__filler is None
- else self.__tilemap.draw_at_wrapping(
- at, at, into, self.__filler, self.__scratch
+
+ self.__filler_boxes: list[DBox] = []
+
+ def filler_box() -> Box:
+ self.__filler_boxes.append(
+ res := DBox(
+ FBox(
+ IVec2(BInt(0, True), BInt(0, True)),
+ lambda at, into: (
+ None
+ if self.__filler is None
+ else self.__tilemap.draw_at_wrapping(
+ at, at, into, self.__filler, self.__scratch
+ )
+ ),
+ )
)
- ),
- )
+ )
+ return res
+
f: Callable[[int], int] = lambda e: e
layout = layout_split(
layout_fair, layout_sort_chunked(layout_fair, layout_priority, f)
self.__layout: Box = VBox(
layout,
[
- (filler_box, 0),
+ (filler_box(), 0),
(
HBox(
layout,
- [(filler_box, 0), (maze_box, 1), (filler_box, 0)],
+ [(filler_box(), 0), (maze_box, 1), (filler_box(), 0)],
),
1,
),
- (filler_box, 0),
+ (filler_box(), 0),
],
)
def set_filler(self, style: int) -> None:
self.__filler = style
+ for box in self.__filler_boxes:
+ box.mark_dirty()
def add_style(self, style: Tile) -> int:
return self.__tilemap.add_tile(style)
if self.__resize:
self.__resize = False
self.__screen.erase()
+ for box in self.__filler_boxes:
+ box.mark_dirty()
self.__screen.refresh()
y, x = self.__screen.getmaxyx()
self.__scratch.resize(y, x)
heights = [(get_height(dim.y), assoc) for dim, assoc in dims]
for (height, _), width, (box, _) in zip(heights, widths, self.boxes):
- box.laid_out(at, IVec2(width, height))
+ # ditto error that i forgot to fix :>
+ box.laid_out(at.copy(), IVec2(width, height))
at.x += width
self.__cb(at, into)
+class DBox(Box):
+ def __init__(self, inner: Box) -> None:
+ self.__inner: Box = inner
+ self.__prev: tuple[IVec2, IVec2] | None = None
+
+ def mark_dirty(self) -> None:
+ self.__prev = None
+
+ def dims(self) -> BVec2:
+ return self.__inner.dims()
+
+ def laid_out(self, at: IVec2, into: IVec2) -> None:
+ if self.__prev == (at, into):
+ return
+ self.__prev = (at, into)
+ self.__inner.laid_out(at, into)
+
+
def vpad_box(min_pad: int = 0, cb=lambda _at, _into: None) -> FBox:
return FBox(IVec2(BInt(0), BInt(min_pad, True)), cb)
--- /dev/null
+from collections.abc import Callable
+from amazeing.maze_class.maze import Maze
+from amazeing.maze_class.maze_walls import WallCoord
+import random
+
+
+def maze_make_empty(
+ maze: Maze,
+ walls_const: set[WallCoord],
+ callback: Callable[[Maze], None] = lambda _: None,
+) -> None:
+ walls = [wall for wall in maze.walls_full() if wall not in walls_const]
+ random.shuffle(walls)
+ for wall in walls:
+ maze._remove_wall(wall)
+ callback(maze)
-WIDTH=50
-HEIGHT=50
+WIDTH=25
+HEIGHT=25
ENTRY=2,5
#EXIT=100,100
OUTPUT_FILE=test
TILEMAP_EMPTY="{0,0,0:0,0,0} "
TILEMAP_EMPTY="{0,0,0:0,0,0} "
TILEMAP_EMPTY="{0,0,0:0,0,0} "
-TILEMAP_BACKGROUND_SIZE=4,4
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}# "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}### "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0} # "
-TILEMAP_BACKGROUND="{100,100,100:0,0,0}# # "
+TILEMAP_BACKGROUND_SIZE=8,4
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}## "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}###### "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0} ## "
+TILEMAP_BACKGROUND="{1000,1000,1000:0,0,0}## ## "
MAZE_PATTERN=" # # "
MAZE_PATTERN=" # # "
MAZE_PATTERN=" # "