-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransftoWCA.py
223 lines (165 loc) · 9.08 KB
/
transftoWCA.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
# this module can convert Rubiksskewb algs to WCA notation, given that the algs use the moves
# specified down below
# the two algs as in SkewbSkills itself to swap three or four stickers cyclically
# each permutation is split up into transpositions of pairs
def threeswap(listname, i, j, k):
# cycles three elements i,j,k of a given list by performing two transpositions
listname[j], listname[k] = listname[k], listname[j]
listname[i], listname[j] = listname[j], listname[i]
def fourswap(listname, i, j, k, l):
# same as threeswap, but cycles four elements i,j,k,l, which needs three transpositions
listname[k], listname[l] = listname[l], listname[k]
listname[j], listname[k] = listname[k], listname[j]
listname[i], listname[j] = listname[j], listname[i]
# the main function to perform the transposition to WCA scrambles which needs the previous ones
# so it must follow them
def transftoWCA(scr):
# define list carrying all stickers of the skewb and the color that is placed there initially
# note that for this subprogram of SkewbSkills, we only need the centers and can therefore
# use arbitrary letters for all other facelets
# might be improved in the future so that there are only 6 elements in the list
# but right know it does not matter (we only have to do it once and never again, in principle)
stickercol = ["o", "a", "a", "a", "a", "g", "a", "a", "a", "a", "y", "a", "a", "a", "a",
"w", "a", "a", "a", "a", "r", "a", "a", "a", "a", "b", "a", "a", "a", "a"]
# define a string carrying the WCA notation scramble
finalscr = ""
# split the scramble sequence into distinct moves (default split character space)
scrsplit = scr.split()
# store all the cycled centers (as in: all permutations of three centers) in one list
allcycles = []
# go through all elements (moves) and find out what centers they permute
for i in scrsplit:
# ensure we can compare the current with previous list
previous = stickercol.copy()
# for each move, store the permuted centers
thecycledcolors = []
# use a lighter version of the code in MainWindow.py, so just permute centers as they are
# sufficient to describe the notation (abbreviations for moves) or in other words the
# centers implicate unambiguous move sequence
if i == "x":
fourswap(stickercol, 15, 25, 10, 5)
elif i == "x'":
fourswap(stickercol, 5, 10, 25, 15)
elif i == "x2":
fourswap(stickercol, 5, 10, 25, 15)
fourswap(stickercol, 5, 10, 25, 15)
elif i == "y":
fourswap(stickercol, 25, 20, 5, 0)
elif i == "y'":
fourswap(stickercol, 0, 5, 20, 25)
elif i == "y2":
fourswap(stickercol, 0, 5, 20, 25)
fourswap(stickercol, 0, 5, 20, 25)
elif i == "z":
fourswap(stickercol, 15, 20, 10, 0)
elif i == "z'":
fourswap(stickercol, 0, 10, 20, 15)
elif i == "z2":
fourswap(stickercol, 0, 10, 20, 15)
fourswap(stickercol, 0, 10, 20, 15)
elif i == "r" or i == "r'2":
threeswap(stickercol, 10, 20, 25)
elif i == "r'" or i == "r2":
threeswap(stickercol, 25, 20, 10)
elif i == "R" or i == "R'2":
threeswap(stickercol, 15, 25, 20)
elif i == "R'" or i == "R2":
threeswap(stickercol, 20, 25, 15)
elif i == "l" or i == "L" or i == "l'2" or i == "L'2":
threeswap(stickercol, 0, 5, 10)
elif i == "l'" or i == "L'" or i == "l2" or i == "L2":
threeswap(stickercol, 10, 5, 0)
elif i == "f" or i == "f'2":
threeswap(stickercol, 5, 20, 10)
elif i == "f'" or i == "f2":
threeswap(stickercol, 10, 20, 5)
elif i == "B" or i == "U" or i == "B'2" or i == "U'2":
threeswap(stickercol, 0, 25, 15)
elif i == "B'" or i == "U'" or i == "B2" or i == "U2":
threeswap(stickercol, 15, 25, 0)
elif i == "b" or i == "b'2":
threeswap(stickercol, 0, 10, 25)
else:
threeswap(stickercol, 25, 10, 0)
# "read the previous" "compare with current" only if i = real move (no rotations)
if i not in ("x", "x'", "x2", "y", "y'", "y2", "z", "z'", "z2"):
# check all centers (if they changed or not)
for j in (0, 5, 10, 15, 20, 25):
if previous[j] == stickercol[j]:
continue
else:
# store the previous and the current color
thecycledcolors.append([previous[j], stickercol[j]])
# after all centers have been checked, store the list of the three varied centers
# in one bigger list
allcycles.append(thecycledcolors)
# whole process is repeated for all moves in the Rubiksskewb notation scramble sequence
# print("The cycles made by the non-WCA scramble, containing previous and current color: ", allcycles)
# find out the WCA moves that permute the exact same 3-tuples of centers
# store the corresponding permuted INDICES for each move; find out, beginning
# with the initial state, which INDICES need to be permuted with each move
# for that: transform the cycle of colors to a cycle of indices (knowing where the three cycled
# colors were in the previous and the current stickercol list is necessary, and then you go
# back to their indices)
# go through all the cycled centers
# move them either directly (rather: their indices) with WCA moves
# or move the opposite indices with WCA moves
# find the indices on the WCA skewb, starting with the initial = solved state
stickercolWCA = ["o", "a", "a", "a", "a", "g", "a", "a", "a", "a", "y", "a", "a", "a", "a",
"w", "a", "a", "a", "a", "r", "a", "a", "a", "a", "b", "a", "a", "a", "a"]
# go through all real moves changing three centers
for o in range(len(allcycles)):
# find out the indices of the three premuted colors on the WCA-scrambled cube
# for this I take the two colors of the first entry (one transposition) and find the
# third one by checking if the remaining entrys are already covered by the variables
# "first" and "second" or not -> then I use the third and last color that is affected
# by the move
first = stickercolWCA.index(allcycles[o][0][1])
second = stickercolWCA.index(allcycles[o][0][0])
if (stickercolWCA.index(allcycles[o][1][0]) == first) \
or (stickercolWCA.index(allcycles[o][1][0]) == second):
third = stickercolWCA.index(allcycles[o][2][0])
else:
third = stickercolWCA.index(allcycles[o][1][0])
# just for convenience and to check what's going on, I print the three indices as a tuple
#print(first, second, third)
# find out which WCA move corresponds to the permuted centers (or if this is not possible,
# I check if the permuted centers are opposite to the normally affected centers by
# standard WCA moves)
# in either case, print the corresponding WCA move and swap the corresponding centers
# to proceed with the next real move
if ((first, second, third) in ((20,25,10),(25,10,20),(10,20,25),
(0,15,5),(15,5,0),(5,0,15))):
finalscr += "R "
threeswap(stickercolWCA, 10, 20, 25)
elif ((first, second, third) in ((10,25,20),(20,10,25),(25,20,10),
(5,15,0),(0,5,15),(15,0,5))):
finalscr += "R' "
threeswap(stickercolWCA, 25, 20, 10)
elif ((first, second, third) in ((0,5,10),(5,10,0),(10,0,5),
(15,25,20),(25,20,15),(20,15,25))):
finalscr += "L "
threeswap(stickercolWCA, 0, 5, 10)
elif (first, second, third) in ((10,5,0),(0,10,5),(5,0,10),
(20,25,15),(15,20,25),(25,15,20)):
finalscr += "L' "
threeswap(stickercolWCA, 10, 5, 0)
elif (first, second, third) in ((15,0,25),(0,25,15),(25,15,0),
(5,20,10),(20,10,5),(10,5,20)):
finalscr += "U "
threeswap(stickercolWCA, 0, 25, 15)
elif (first, second, third) in ((25,0,15),(15,25,0),(0,15,25),
(10,20,5),(5,10,20),(20,5,10)):
finalscr += "U' "
threeswap(stickercolWCA, 15, 25, 0)
elif (first, second, third) in ((25,0,10),(0,10,25),(10,25,0),
(15,20,5),(20,5,15),(5,15,20)):
finalscr += "B "
threeswap(stickercolWCA, 0, 10, 25)
elif (first, second, third) in ((10,0,25),(25,10,0),(0,25,10),
(5,20,15),(15,5,20),(20,15,5)):
finalscr += "B' "
threeswap(stickercolWCA, 25, 10, 0)
return(finalscr)
# call the function by putting in a Rubiksskewb scramble sequence as a string
#print(transftoWCA("r R' r' B' r R r' B"))