@@ -21,6 +21,8 @@ def __init__(self, _map: str):
21
21
super ().__init__ (grid_array )
22
22
23
23
point_to_state = {}
24
+ start = end = Point (0 , 0 )
25
+
24
26
for y , row in enumerate (self .rows ):
25
27
for x , value in enumerate (row ):
26
28
p = Point (x , y )
@@ -29,10 +31,15 @@ def __init__(self, _map: str):
29
31
elif value == '.' :
30
32
point_to_state [p ] = State .PATH
31
33
elif value == 'S' :
34
+ start = p
32
35
point_to_state [p ] = State .START
33
36
elif value == 'E' :
37
+ end = p
34
38
point_to_state [p ] = State .END
39
+
35
40
self .point_to_state = point_to_state
41
+ self .current_loc = self .start_loc = start
42
+ self .end_loc = end
36
43
37
44
def visualize (self ):
38
45
"""Visualizes the maze using Matplotlib."""
@@ -55,6 +62,48 @@ def visualize(self):
55
62
56
63
# Plot the maze
57
64
plt .figure (figsize = (8 , 8 ))
58
- plt .imshow (colored_maze , interpolation = "nearest" )
65
+ plt .imshow (colored_maze , interpolation = "nearest" , cmap = "viridis" )
59
66
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
+
60
109
plt .show ()
0 commit comments