mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
Compare commits
6 Commits
mlx_menu
...
628bb8a94b
| Author | SHA1 | Date | |
|---|---|---|---|
| 628bb8a94b | |||
| dc19b526fa | |||
| 68d710e313 | |||
| b682274102 | |||
| d534993f4c | |||
| b317f7a3a0 |
+51
-8
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Generator
|
||||
from typing import Any
|
||||
from src.AMazeIng import AMazeIng
|
||||
from src.parsing import Parsing
|
||||
from mlx import Mlx
|
||||
@@ -43,8 +43,8 @@ class MazeMLX:
|
||||
def put_pixel(self, x, y) -> None:
|
||||
offset = y * self.size_line + x * (self.bpp // 8)
|
||||
|
||||
self.buf[offset + 0] = 0xFF
|
||||
self.buf[offset + 1] = 0xFF
|
||||
self.buf[offset + 0] = 0x00
|
||||
self.buf[offset + 1] = 0x00
|
||||
self.buf[offset + 2] = 0xFF
|
||||
if self.bpp >= 32:
|
||||
self.buf[offset + 3] = 0xFF
|
||||
@@ -52,6 +52,17 @@ class MazeMLX:
|
||||
def clear_image(self) -> None:
|
||||
self.buf[:] = b"\x00" * len(self.buf)
|
||||
|
||||
def random_color() -> Any:
|
||||
colors = [
|
||||
[0x00, 0x00, 0xFF, 0xFF], # red
|
||||
[0x00, 0xFF, 0xFF, 0xFF], # yellow
|
||||
[0x00, 0xFF, 0x40, 0xFF], # green
|
||||
[0xFF, 0xBF, 0x00, 0xFF], # blue
|
||||
[0xFF, 0x00, 0x80, 0xFF], # purple
|
||||
[0xFF, 0x00, 0xFF, 0xFF], # rose
|
||||
]
|
||||
return np.random.choice(colors)
|
||||
|
||||
def put_line(self, start: tuple[int, int], end: tuple[int, int]) -> None:
|
||||
sx, sy = start
|
||||
ex, ey = end
|
||||
@@ -116,6 +127,7 @@ class MazeMLX:
|
||||
)
|
||||
)
|
||||
self.update_maze(maze)
|
||||
self.draw_ft(maze)
|
||||
for i in range(len(path)):
|
||||
ul = (
|
||||
(actual[0]) * cell_size + margin + 12,
|
||||
@@ -157,6 +169,38 @@ class MazeMLX:
|
||||
self.redraw_image()
|
||||
return
|
||||
|
||||
def draw_ft(self, maze: np.ndarray):
|
||||
self.clear_image()
|
||||
margin = math.trunc(
|
||||
math.sqrt(self.width if self.width > self.height else self.height)
|
||||
// 2
|
||||
)
|
||||
line_len = math.trunc(
|
||||
(
|
||||
(self.height - margin) // len(maze)
|
||||
if self.height > self.width
|
||||
else (self.width - margin) // len(maze[0])
|
||||
)
|
||||
)
|
||||
for y in range(len(maze)):
|
||||
for x in range(len(maze[0])):
|
||||
x0 = x * line_len + margin
|
||||
y0 = y * line_len + margin
|
||||
x1 = x * line_len + line_len + margin
|
||||
y1 = y * line_len + line_len + margin
|
||||
|
||||
if maze[y][x].get_north():
|
||||
self.put_line((x0, y0), (x1, y0))
|
||||
if maze[y][x].get_est():
|
||||
self.put_line((x1, y0), (x1, y1))
|
||||
if maze[y][x].get_south():
|
||||
self.put_line((x0, y1), (x1, y1))
|
||||
if maze[y][x].get_west():
|
||||
self.put_line((x0, y0), (x0, y1))
|
||||
if maze[y][x].value == 15:
|
||||
self.put_block((x0, y0), (x1, y1))
|
||||
self.redraw_image()
|
||||
|
||||
def close_loop(self, _: Any):
|
||||
self.mlx.mlx_loop_exit(self.mlx_ptr)
|
||||
|
||||
@@ -198,12 +242,11 @@ class MazeMLX:
|
||||
self.update_maze(amazing.maze.get_maze())
|
||||
# time.sleep(0.01)
|
||||
except StopIteration:
|
||||
# self.color_ft(amazing)
|
||||
if self.path_printer is not None:
|
||||
try:
|
||||
next(self.path_printer)
|
||||
time.sleep(0.03)
|
||||
except StopIteration:
|
||||
pass
|
||||
self.render_path()
|
||||
else:
|
||||
self.color_ft(amazing.maze.get_maze())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
WIDTH=11
|
||||
HEIGHT=11
|
||||
WIDTH=15
|
||||
HEIGHT=15
|
||||
ENTRY=1,1
|
||||
EXIT=11,11
|
||||
OUTPUT_FILE=maze.txt
|
||||
PERFECT=True
|
||||
GENERATOR=Kruskal
|
||||
SOLVER=AStar
|
||||
PERFECT=False
|
||||
GENERATOR=DFS
|
||||
SOLVER=DFS
|
||||
|
||||
@@ -166,6 +166,13 @@ class DepthFirstSearchSolver(MazeSolver):
|
||||
|
||||
def solve(self, maze: Maze, height: int = None,
|
||||
width: int = None) -> str:
|
||||
res = list()
|
||||
for _ in range(50):
|
||||
res.append(self.get_path(maze, height, width))
|
||||
return min(res, key=lambda x: len(x))
|
||||
|
||||
def get_path(self, maze: Maze, height: int = None,
|
||||
width: int = None) -> str:
|
||||
path_str = ""
|
||||
visited = np.zeros((height, width), dtype=bool)
|
||||
path = list()
|
||||
|
||||
Reference in New Issue
Block a user