-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScrambleRubixcube1.py
227 lines (180 loc) · 4.63 KB
/
ScrambleRubixcube1.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
220
221
222
223
import numpy as np
from random import randint
xInitial= np.array(
[
['W', 'W', 'W'],
['W', 'W', 'W'],
['W', 'W', 'W'],
['G', 'G', 'G'],
['G', 'G', 'G'],
['G', 'G', 'G'],
['R', 'R', 'R'],
['R', 'R', 'R'],
['R', 'R', 'R'],
['B', 'B', 'B'],
['B', 'B', 'B'],
['B', 'B', 'B'],
['O', 'O', 'O'],
['O', 'O', 'O'],
['O', 'O', 'O'],
['Y', 'Y', 'Y'],
['Y', 'Y', 'Y'],
['Y', 'Y', 'Y']
]
)
def restore_x():
x[0:18,0:3]=xInitial[0:18,0:3]
def FrontCW(): # action 1
x[6:9,0:3]=np.fliplr(x[6:9,0:3].transpose())
temp1=np.array(x[2, 0:3])
temp2=np.array(x [9:12,0])
temp3=np.array(x[15,0:3])
temp4=np.array(x[3:6,2])
x[2, 0:3]=np.fliplr([temp4])[0]
x [9:12,0]=temp1
x[15,0:3]=np.fliplr([temp2])[0]
x[3:6,2]=temp3
def FrontACW(): # action 2
FrontCW()
FrontCW()
FrontCW()
def UpCW(): #action 3
x[0:3,0:3]=np.fliplr(x[0:3,0:3].transpose())
temp1=np.array(x[12, 0:3])
temp2=np.array(x [9,0:3])
temp3=np.array(x[6,0:3])
temp4=np.array(x[3,0:3])
x[12, 0:3]=temp4
x[9,0:3]=temp1
x[6,0:3]=temp2
x[3,0:3]=temp3
def UpACW(): # acion 4
UpCW()
UpCW()
UpCW()
def DownCW():# action 5 Front down clock wise
x[15:18,0:3]=np.fliplr(x[15:18,0:3].transpose())
temp1=np.array(x[8, 0:3])
temp2=np.array(x [11,0:3])
temp3=np.array(x[14,0:3])
temp4=np.array(x[5,0:3])
x[8, 0:3]=temp4
x[11,0:3]=temp1
x[14,0:3]=temp2
x[5,0:3]=temp3
def DownACW(): #action 6
DownCW()
DownCW()
DownCW()
def LeftCW(): #action 7
x[3:6,0:3]=np.fliplr(x[3:6,0:3].transpose())
temp1=np.array(x[0:3, 0])
temp2=np.array(x [6:9,0])
temp3=np.array(x[15:18,0])
temp4=np.array(x[12:15,2])
x[0:3, 0]=np.fliplr([temp4])[0]
x[6:9,0]=temp1
x[15:18,0]=temp2
x[12:15,2]=np.fliplr([temp3])[0]
def LeftACW(): #action 8
LeftCW()
LeftCW()
LeftCW()
def RightCW(): #action 9 Front right clock wise
x[9:12,0:3]=np.fliplr(x[9:12,0:3].transpose())
temp1=np.array(x[0:3, 2])
temp2=np.array(x [12:15,0])
temp3=np.array(x[15:18,2])
temp4=np.array(x[6:9,2])
x[0:3, 2]=temp4
x[12:15,0]=np.fliplr([temp1])[0]
x[15:18,2]=np.fliplr([temp2])[0]
x[6:9,2]=temp3
def RightACW(): # action 10
RightCW()
RightCW()
RightCW()
def BackCW(): # action 11 Front back clock wise
x[12:15,:]=np.fliplr(x[12:15,:].transpose())
temp1=np.array(x[0, 0:3])
temp2=np.array(x[3:6,0])
temp3=np.array(x[17,0:3])
temp4=np.array(x[9:12,2])
x[0, 0:3]=temp4
x[3:6,0]=np.fliplr([temp1])[0]
x[17,0:3]=temp2
x[9:12,2]=np.fliplr([temp3])[0]
def BackACW(): # action 12
BackCW()
BackCW()
BackCW()
def PrintCube():
print(" ",x[0,0:3])
print(" ",x[1,0:3])
print(" ",x[2,0:3])
print(x[3,0:3],x[6,0:3],x[9,0:3],x[12,0:3])
print(x[4,0:3],x[7,0:3],x[10,0:3],x[13,0:3])
print(x[5,0:3],x[8,0:3],x[11,0:3],x[14,0:3])
print(" ",x[15,0:3]," "," "," ")
print(" ",x[16,0:3]," "," "," ")
print(" ",x[17,0:3]," "," "," ")
def make_move(move, reverse ,printCube):
# move number
# reverse if 0 original move if 1 reverse of input move
#printCube 0/1 if 0 dont print else print
if reverse==1:
if move%2==0:
move=move-1
else:
move=move+1
if move==1:
FrontCW()
print("FrontCW")
if move==2:
FrontACW()
print("FrontACW")
if move==3:
UpCW()
print("UpCW")
if move==4:
UpACW()
print("UpACW")
if move==5:
DownCW()
print("DownCW")
if move==6:
DownACW()
print("DownACW")
if move==7:
LeftCW()
print("LeftCW")
if move==8:
LeftACW()
print("LeftACW")
if move==9:
RightCW()
print("RightCW")
if move==10:
RightACW()
print("RightACW")
if move==11:
BackCW()
print("BackCW")
if move==12:
BackACW()
print("BackACW")
if printCube==1:
PrintCube()
##########################################
#intialize Cube x
x=np.array(xInitial)
print("x intialized")
PrintCube()
# pick random moves
total_move=6
my_randoms = [randint(1,12) for x in range(total_move)]
print(my_randoms)
# scramble according to moves
for move in my_randoms:
make_move(move,0,0)
PrintCube()