@@ -56,28 +56,24 @@ def is_goal(self, goal_state):
56
56
57
57
def plot (self , ax = None , title = None , fs = 20 ):
58
58
if ax is None :
59
- fig , ax = plt .subplots (1 )
59
+ _ , ax = plt .subplots (1 )
60
60
61
- size = 10
62
61
gs = self .grid_size
63
62
64
63
# 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 )
66
65
ax .add_patch (border )
67
66
68
67
# draw tiles
69
68
for i , tile in enumerate (self .tiles ):
70
69
if tile == 0 : continue
71
70
col = self .grid_size - 1 - i // self .grid_size
72
71
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 )
74
73
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 )
77
75
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' )
81
77
82
78
ax .axis ('square' )
83
79
ax .axis ('off' )
0 commit comments