Skip to content

Commit a64bc2e

Browse files
committed
woohoooooo
1 parent 1b9e12a commit a64bc2e

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

aoc_2024/maze.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def __init__(self, _map: str):
2121
super().__init__(grid_array)
2222

2323
point_to_state = {}
24+
start = end = Point(0, 0)
25+
2426
for y, row in enumerate(self.rows):
2527
for x, value in enumerate(row):
2628
p = Point(x, y)
@@ -29,10 +31,15 @@ def __init__(self, _map: str):
2931
elif value == '.':
3032
point_to_state[p] = State.PATH
3133
elif value == 'S':
34+
start = p
3235
point_to_state[p] = State.START
3336
elif value == 'E':
37+
end = p
3438
point_to_state[p] = State.END
39+
3540
self.point_to_state = point_to_state
41+
self.current_loc = self.start_loc = start
42+
self.end_loc = end
3643

3744
def visualize(self):
3845
"""Visualizes the maze using Matplotlib."""
@@ -55,6 +62,48 @@ def visualize(self):
5562

5663
# Plot the maze
5764
plt.figure(figsize=(8, 8))
58-
plt.imshow(colored_maze, interpolation="nearest")
65+
plt.imshow(colored_maze, interpolation="nearest", cmap="viridis")
5966
plt.axis("off") # Turn off the axes
67+
68+
# Annotate the current location
69+
plt.text(
70+
self.current_loc.x, # X coordinate
71+
self.current_loc.y, # Y coordinate
72+
"X", # Label
73+
color="blue", # Text color
74+
fontsize=16, # Font size
75+
fontweight="bold", # Font weight
76+
ha="center", # Horizontal alignment
77+
va="center", # Vertical alignment
78+
alpha=0.8,
79+
bbox=dict(facecolor="black", edgecolor="none", boxstyle="round,pad=0.4", alpha=0.6)
80+
)
81+
82+
# Annotate the start location
83+
plt.text(
84+
self.start_loc.x,
85+
self.start_loc.y,
86+
"S", # Label for Start
87+
color="white",
88+
fontsize=16,
89+
fontweight="bold",
90+
ha="center",
91+
va="center",
92+
alpha=0.9,
93+
# bbox=dict(facecolor="blue", edgecolor="none", boxstyle="round,pad=0.4",
94+
# alpha=0.6) # Transparent background for S
95+
)
96+
97+
# Annotate the end location
98+
plt.text(
99+
self.end_loc.x,
100+
self.end_loc.y,
101+
"E", # Label for End
102+
color="white",
103+
fontsize=16,
104+
fontweight="bold",
105+
ha="center",
106+
va="center",
107+
)
108+
60109
plt.show()

0 commit comments

Comments
 (0)