-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wall.py
63 lines (47 loc) · 1.95 KB
/
Wall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
class Wall:
def __init__(self, initial_state):
self.state = initial_state
self.goal = initial_state[1, 1]
def peek_left_col(self, col):
return 9 - (np.count_nonzero(self.state[:, 1] == self.goal)
+ np.count_nonzero(self.state[:, 2] == self.goal)
+ np.count_nonzero(col == self.goal))
def peek_right_col(self, col):
return 9 - (np.count_nonzero(self.state[:, 0] == self.goal)
+ np.count_nonzero(self.state[:, 1] == self.goal)
+ np.count_nonzero(col == self.goal))
def peek_upper_row(self, row):
return 9 - (np.count_nonzero(self.state[1, :] == self.goal)
+ np.count_nonzero(self.state[2, :] == self.goal)
+ np.count_nonzero(row == self.goal))
def peek_lower_row(self, row):
return 9 - (np.count_nonzero(self.state[0, :] == self.goal)
+ np.count_nonzero(self.state[1, :] == self.goal)
+ np.count_nonzero(row == self.goal))
def swap_upper_row(self, row):
previous = self.get_upper_row()
self.state[0, :] = row
return previous
def swap_lower_row(self, row):
previous = self.get_lower_row()
self.state[2, :] = row
return previous
def swap_left_column(self, column):
previous = self.get_left_column()
self.state[:, 0] = column
return previous
def swap_right_column(self, column):
previous = self.get_right_column()
self.state[:, 2] = column
return previous
def get_upper_row(self):
return self.state[0, :].copy()
def get_lower_row(self):
return self.state[2, :].copy()
def get_left_column(self):
return self.state[:, 0].copy()
def get_right_column(self):
return self.state[:, 2].copy()
def missing_blocks(self):
return 9 - np.count_nonzero(self.state == self.goal)