-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube_input_verifier.py
executable file
·112 lines (97 loc) · 3.48 KB
/
cube_input_verifier.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from notation import mycube
class cube_input_verifier():
def __init__(self,input):
self.front = input['f']
self.back = input['b']
self.left = input['l']
self.right = input['r']
self.up = input['u']
self.down = input['d']
self.faces = [self.front,self.back,self.up,self.down,self.right,self.left]
self.colors = ['b','g','r','o','w','y']
self.edge_map = []
self.corner_map = []
for i in range(0,6):
self.edge_map.append([False,False,False,False,False,False])
self.corner_map.append([False,False,False,False,False,False])
self.cube = mycube(input)
def full_verify(self):
if self.color_verifier() and self.number_of_colors_verifier() and self.cubies_verifier():
return True
else:
return False
def color_verifier(self):
for face in self.faces:
for i in range(0,9):
if face[i] not in self.colors:
return False
return True
def number_of_colors_verifier(self):
color_count = {'b':0,'g':0,'r':0,'o':0,'w':0,'y':0}
for face in self.faces:
for i in range(0,9):
color_count[face[i]]+=1
for color in color_count:
if color_count[color] != 9:
return False
return True
def cubies_verifier(self):
if self.corners_verifier() and self.edges_verifier():
return True
else:
return False
def corners_verifier(self):
color_to_index_mapping = {'b':0,'g':1,'r':2,'o':3,'w':4,'y':5}
index_to_color_mapping = {0:'b',1:'g',2:'r',3:'o',4:'w',5:'y'}
mismatching_colors = {'b':'g','g':'b','r':'o','o':'r','w':'y','y':'w'}
for i in range(1,9):
colors = self.extract_color(self.cube.get_corner(i))
index_i = color_to_index_mapping[colors[0]]
index_j = color_to_index_mapping[colors[1]]
index_k = color_to_index_mapping[colors[2]]
self.corner_map[index_i][index_j] = True
self.corner_map[index_j][index_i] = True
self.corner_map[index_i][index_k] = True
self.corner_map[index_k][index_i] = True
self.corner_map[index_j][index_k] = True
self.corner_map[index_k][index_j] = True
for i in range(0,6):
current_color = index_to_color_mapping[i]
mismatch_color = mismatching_colors[current_color]
mismatch_color_index = color_to_index_mapping[mismatch_color]
for j in range(0,6):
if i == j and self.corner_map[i][j] == True:
return False
elif j == mismatch_color_index and self.corner_map[i][j] == True:
return False
elif j != mismatch_color_index and j!=i and self.corner_map[i][j] == False:
return False
return True
def edges_verifier(self):
color_to_index_mapping = {'b':0,'g':1,'r':2,'o':3,'w':4,'y':5}
index_to_color_mapping = {0:'b',1:'g',2:'r',3:'o',4:'w',5:'y'}
mismatching_colors = {'b':'g','g':'b','r':'o','o':'r','w':'y','y':'w'}
for i in range(1,13):
colors = self.extract_color(self.cube.get_edge(i))
index_i = color_to_index_mapping[colors[0]]
index_j = color_to_index_mapping[colors[1]]
self.edge_map[index_i][index_j] = True
self.edge_map[index_j][index_i] = True
for i in range(0,6):
current_color = index_to_color_mapping[i]
mismatch_color = mismatching_colors[current_color]
mismatch_color_index = color_to_index_mapping[mismatch_color]
for j in range(0,6):
if i == j and self.edge_map[i][j] == True:
return False
elif j == mismatch_color_index and self.edge_map[i][j] == True:
return False
elif j != mismatch_color_index and j!=i and self.edge_map[i][j] == False:
return False
return True
def extract_color(self,cubie):
ans = []
for i in range(0,3):
if cubie[i] != -1:
ans.append(cubie[i])
return ans