Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97d2229

Browse files
committed
update plot method for NPuzzleState
1 parent 46b39c7 commit 97d2229

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

‎Search/npuzzle.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /