mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
ifpjefp
This commit is contained in:
+59
-2
@@ -76,7 +76,64 @@ class MazeMLX:
|
|||||||
if maze[y][x].get_west():
|
if maze[y][x].get_west():
|
||||||
self.put_line((x0, y0), (x0, y1))
|
self.put_line((x0, y0), (x0, y1))
|
||||||
self.mlx.mlx_put_image_to_window(
|
self.mlx.mlx_put_image_to_window(
|
||||||
self.mlx_ptr, self.win_ptr, self.img_ptr, 0, 0)
|
self.mlx_ptr, self.win_ptr, self.img_ptr, 0, 0
|
||||||
|
)
|
||||||
|
|
||||||
|
def put_block(self, ul: tuple[int, int], dr: tuple[int, int]) -> None:
|
||||||
|
for y in range(ul[1], dr[1]):
|
||||||
|
self.put_line((min(ul[0], dr[0]), y), (max(ul[0], dr[0]), y))
|
||||||
|
|
||||||
|
def put_path(self, amazing: AMazeIng) -> None:
|
||||||
|
path = amazing.solve_path()
|
||||||
|
print(path)
|
||||||
|
actual = amazing.entry
|
||||||
|
maze = amazing.maze.get_maze()
|
||||||
|
if maze is None:
|
||||||
|
return
|
||||||
|
margin = math.trunc(
|
||||||
|
math.sqrt(self.width if self.width > self.height else self.height)
|
||||||
|
// 2
|
||||||
|
)
|
||||||
|
cell_size = math.trunc(
|
||||||
|
(
|
||||||
|
(self.height - margin) // len(maze)
|
||||||
|
if self.height > self.width
|
||||||
|
else (self.width - margin) // len(maze[0])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in range(len(path)):
|
||||||
|
ul = (
|
||||||
|
(actual[0]) * cell_size + margin + 6,
|
||||||
|
(actual[1]) * cell_size + 6 + margin,
|
||||||
|
)
|
||||||
|
dr = (
|
||||||
|
(actual[0]) * cell_size + cell_size + margin - 12,
|
||||||
|
(actual[1]) * cell_size + cell_size - 12 + margin,
|
||||||
|
)
|
||||||
|
self.put_block(ul, dr)
|
||||||
|
x0 = actual[0] * cell_size + margin + 3
|
||||||
|
y0 = actual[1] * cell_size + margin + 3
|
||||||
|
x1 = actual[0] * cell_size + cell_size + margin - 6
|
||||||
|
y1 = actual[1] * cell_size + cell_size + margin - 6
|
||||||
|
if i == len(path) - 1:
|
||||||
|
continue
|
||||||
|
match path[i]:
|
||||||
|
case "N":
|
||||||
|
self.put_line((x0, y0), (x1, y0))
|
||||||
|
actual = (actual[0], actual[1] - 1)
|
||||||
|
case "E":
|
||||||
|
self.put_line((x1, y0), (x1, y1))
|
||||||
|
actual = (actual[0] + 1, actual[1])
|
||||||
|
case "S":
|
||||||
|
self.put_line((x0, y1), (x1, y1))
|
||||||
|
actual = (actual[0], actual[1] + 1)
|
||||||
|
case "W":
|
||||||
|
self.put_line((x0, y0), (x0, y1))
|
||||||
|
actual = (actual[0] - 1, actual[1])
|
||||||
|
self.mlx.mlx_put_image_to_window(
|
||||||
|
self.mlx_ptr, self.win_ptr, self.img_ptr, 0, 0
|
||||||
|
)
|
||||||
|
|
||||||
def close_loop(self, _: Any):
|
def close_loop(self, _: Any):
|
||||||
self.mlx.mlx_loop_exit(self.mlx_ptr)
|
self.mlx.mlx_loop_exit(self.mlx_ptr)
|
||||||
@@ -96,7 +153,7 @@ class MazeMLX:
|
|||||||
self.update_maze(amazing.maze.get_maze())
|
self.update_maze(amazing.maze.get_maze())
|
||||||
# time.sleep(0.01)
|
# time.sleep(0.01)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
pass
|
self.put_path(amazing)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|||||||
+6
-6
@@ -1,8 +1,8 @@
|
|||||||
WIDTH=20
|
WIDTH=10
|
||||||
HEIGHT=20
|
HEIGHT=10
|
||||||
ENTRY=1,1
|
ENTRY=1,1
|
||||||
EXIT=2,2
|
EXIT=9,9
|
||||||
OUTPUT_FILE=maze.txt
|
OUTPUT_FILE=maze.txt
|
||||||
PERFECT=False
|
PERFECT=True
|
||||||
GENERATOR=DFS
|
GENERATOR=Kruskal
|
||||||
SOLVER=AStar
|
SOLVER=DFS
|
||||||
|
|||||||
@@ -1,24 +1,14 @@
|
|||||||
B9153957955513953953
|
B953BD3917
|
||||||
AEA96A9569792C6BAAD6
|
C478416EC3
|
||||||
C5443AA9169281102C53
|
957ABEBD3A
|
||||||
95556A82816C2AC2A952
|
817AC16D42
|
||||||
A93916A86A956C3A86D6
|
E87C107BD2
|
||||||
AEC6C542944513806953
|
B8552A9456
|
||||||
C395553AC393C2AC787A
|
82BBAEC157
|
||||||
BC69512C7AAC56855692
|
EEAA855417
|
||||||
A952BAAF96AFFFAD53AE
|
B96C2D3903
|
||||||
A810686FC5057FC516C3
|
C45547C6EE
|
||||||
AAC4543FFFAFFFB96952
|
|
||||||
AC5553817FAFD52ABC3A
|
|
||||||
815552843FEFFF80296A
|
|
||||||
AC553A85413D55406C12
|
|
||||||
C53BAAC392C3953C13AA
|
|
||||||
9386AC386A9683C56AAA
|
|
||||||
846903AE96C568517C2A
|
|
||||||
AD3A82C385397C3C5546
|
|
||||||
C12AA87AA94293AD5513
|
|
||||||
D46C6C5446D46C45556E
|
|
||||||
|
|
||||||
1,1
|
1,1
|
||||||
2,2
|
9,9
|
||||||
SSEEENENWWWS
|
SENEESSSSESSSEEEES
|
||||||
|
|||||||
Reference in New Issue
Block a user