@@ -56,28 +56,24 @@ def is_goal(self, goal_state):
5656
5757 def plot (self , ax = None , title = None , fs = 20 ):
5858 if ax is None :
59- fig , ax = plt .subplots (1 )
59+ _ , ax = plt .subplots (1 )
6060
61- size = 10
6261 gs = self .grid_size
6362
6463 # draw border
65- border = plt .Rectangle ((0 , 0 ), gs * size , gs * size , ec = 'k' , fc = 'w' , lw = 3 )
64+ border = plt .Rectangle ((0 , 0 ), gs , gs , ec = 'k' , fc = 'w' , lw = 3 )
6665 ax .add_patch (border )
6766
6867 # draw tiles
6968 for i , tile in enumerate (self .tiles ):
7069 if tile == 0 : continue
7170 col = self .grid_size - 1 - i // self .grid_size
7271 row = i % self .grid_size
73- cell = plt .Rectangle ((row * size , col * size ), size , size , fc = 'darkslateblue' , ec = 'k' , lw = 3 , alpha = 0.4 )
72+ cell = plt .Rectangle ((row , col ), 1 , 1 , fc = 'darkslateblue' , ec = 'k' , lw = 3 , alpha = 0.4 )
7473 ax .add_patch (cell )
75- tileSq = plt .Rectangle ((row * size + int (size * 0.1 ), col * size + int (size * 0.1 )),
76- int (size * 0.8 ), int (size * 0.8 ), fc = 'darkslateblue' , ec = 'k' , lw = 1 , alpha = 0.8 )
74+ tileSq = plt .Rectangle ((row + 0.15 , col + 0.15 ), 0.7 , 0.7 , fc = 'darkslateblue' , ec = 'k' , lw = 1 , alpha = 0.8 )
7775 ax .add_patch (tileSq )
78-
79- ax .text (row * size + size // 2 , col * size + size // 2 , "%d" % tile , color = 'w' ,
80- fontsize = fs , verticalalignment = 'center' , horizontalalignment = 'center' )
76+ ax .text (row + 0.5 , col + 0.5 , f"{ tile } " , color = 'w' , fontsize = fs , va = 'center' , ha = 'center' )
8177
8278 ax .axis ('square' )
8379 ax .axis ('off' )
0 commit comments