-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.py
219 lines (187 loc) · 7.14 KB
/
checks.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""
Rubix Cube Solver - Cube State Checking Algorithms
v0.11 (alpha)
History available at github.com/OliverMatthews/rubiksCube/
Oli Matthews 2019
"""
# Checks whether the 'green cross' step has been completed correctly. Takes one
# side matrix as input.
def greenCross(side):
# Returns false if any of the green cross pieces are out of position.
if side[0][1] != "G":
return False
elif side[1][0] != "G":
return False
elif side[1][2] != "G":
return False
elif side[2][1] != "G":
return False
elif side[1][1] != "G":
return False
# Returns true otherwise.
else:
return True
# Checks whether the 'green side' step has been completed correctly. Takes one
# side matrix as input.
def greenSide(side):
# Cycles through every entry in the matrix and returns false if any are not
# green.
for i in range(len(side)):
for j in range(len(side)):
if side[i][j] != "G":
return False
# Returns true otherwise.
return True
# Checks whether the edge pieces adjacent the green side match the centre
# colour for their side. Takes 4 side matrices as inputs - these should be the
# matrices of the sides adjacent to the green side.
def alignedCenters(side2, side3, side4, side5):
# Returns false if the adjacent white edge is not in the correct position.
if side2[2][1] != "W":
return False
# Returns false if the adjacent red edge is not in the correct position.
elif side3[2][1] != "R":
return False
# Returns false if the adjacent yellow edge is not in the correct position.
elif side4[2][1] != "Y":
return False
# Returns false if the adjacent orange edge is not in the correct position.
elif side5[2][1] != "O":
return False
# Returns true otherwise.
else:
return True
# Checks whether the corner pieces adjacent the green side match the centre
# colour for their side. Takes 4 side matrices as inputs - these should be
# the matrices of the sides adjacent to the green side.
def alignedCorners(side2, side3, side4, side5):
# Returns false if the green/white/orange corner is incorrectly placed.
if side2[2][0] != "W" or side5[2][2] != "O":
return False
# Returns false if the green/red/white corner is incorrectly placed.
elif side3[2][0] != "R" or side2[2][2] != "W":
return False
# Returns false if the green/yellow/red corner is incorrectly placed.
elif side4[2][0] != "Y" or side3[2][2] != "R":
return False
# Returns false if the green/orange/yellow corner is incorrectly placed.
elif side5[2][0] != "O" or side4[2][2] != "Y":
return False
# Returns true otherwise.
else:
return True
# Checks whether the two rows closest the green side on the white, red, yellow
# and orange sides are solved correctly. Takes 4 side matrices as input - these
# should be the matrices of the sides adjacent to the green side.
def firstTwoRows(side2, side3, side4, side5):
# Returns false if any of the white pieces in the two rows closest to the
# green side are incorrectly placed.
for i in range(len(side2)-1):
for j in range(len(side2)):
if side2[i+1][j] != "W":
return False
# Returns false if any of the red pieces in the two rows closest to the
# green side are incorrectly placed.
for i in range(len(side3)-1):
for j in range(len(side3)):
if side3[i+1][j] != "R":
return False
# Returns false if any of the yellow pieces in the two rows closest to the
# green side are incorrectly placed.
for i in range(len(side4)-1):
for j in range(len(side4)):
if side4[i+1][j] != "Y":
return False
# Returns false if any of the orange pieces in the two rows closest to the
# green side are incorrectly placed.
for i in range(len(side5)-1):
for j in range(len(side5)):
if side5[i+1][j] != "O":
return False
# Returns true otherwise.
return True
# Checks whether the 'blue cross' step has been completed correctly. Takes one
# side matrix as input.
def blueCross(side):
# Returns false if any of the blue cross pieces are out of position.
if side[0][1] != "B":
return False
elif side[1][0] != "B":
return False
elif side[1][2] != "B":
return False
elif side[2][1] != "B":
return False
elif side[1][1] != "B":
return False
# Returns true otherwise.
else:
return True
# Checks whether the 'blue side' step has been completed correctly. Takes one
# side matrix as input.
def blueSide(side):
# Cycles through every entry in the matrix and returns false if any are not
# blue.
for i in range(len(side)):
for j in range(len(side)):
if side[i][j] != "B":
return False
# Returns true otherwise.
return True
# Checks whether the top layer corners are in the correct positions.
# Takes 4 side matrices as input - these should be the matrices of the sides
# adjacent to the green side.
def topLayerCorners(side2, side3, side4, side5):
# Returns false if any of the top layer corners are out of position.
if side2[0][0] != "W" or side5[0][2] != "O":
return False
elif side3[0][0] != "R" or side2[0][2] != "W":
return False
elif side4[0][0] != "Y" or side3[0][2] != "R":
return False
elif side5[0][0] != "O" or side4[0][2] != "Y":
return False
# Returns true otherwise.
else:
return True
# Checks whether the entire cube is completed. Takes all 6 side matrices as
# input.
def wholeCube(side1, side2, side3, side4, side5, side6):
# Cycles through every entry in side 1 and returns false if any are not
# green.
for i in range(len(side1)):
for j in range(len(side1)):
if side1[i][j] != "G":
return False
# Cycles through every entry in side 2 and returns false if any are not
# white.
for i in range(len(side2)):
for j in range(len(side2)):
if side2[i][j] != "W":
return False
# Cycles through every entry in side 3 and returns false if any are not
# red.
for i in range(len(side3)):
for j in range(len(side3)):
if side3[i][j] != "R":
return False
# Cycles through every entry in side 4 and returns false if any are not
# yellow.
for i in range(len(side4)):
for j in range(len(side4)):
if side4[i][j] != "Y":
return False
# Cycles through every entry in side 5 and returns false if any are not
# orange.
for i in range(len(side5)):
for j in range(len(side5)):
if side5[i][j] != "O":
return False
# Cycles through every entry in side 6 and returns false if any are not
# blue.
for i in range(len(side6)):
for j in range(len(side6)):
if side6[i][j] != "B":
return False
# Returns true otherwise.
return True