-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotations.go
247 lines (214 loc) · 11 KB
/
rotations.go
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package main
func replaceBits(src int32, sLoc int, dest int32, dLoc int) int32 {
return (dest & (-int32(0b1111<<dLoc) - 1)) | ((src >> sLoc) & 0b1111 << dLoc)
}
func rotSide0(cube *[6]int32, way int) {
sides := [4]int{3, 2, 4, 1}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 12, cube[sides[0]], 4)
cube[sides[1]] = replaceBits(cube[sides[2]], 20, cube[sides[1]], 12)
cube[sides[2]] = replaceBits(cube[sides[3]], 28, cube[sides[2]], 20)
cube[sides[3]] = replaceBits(mem, 4, cube[sides[3]], 28)
cube[sides[0]] = replaceBits(cube[sides[1]], 16, cube[sides[0]], 8)
cube[sides[1]] = replaceBits(cube[sides[2]], 24, cube[sides[1]], 16)
cube[sides[2]] = replaceBits(cube[sides[3]], 0, cube[sides[2]], 24)
cube[sides[3]] = replaceBits(mem, 8, cube[sides[3]], 0)
cube[sides[0]] = replaceBits(cube[sides[1]], 20, cube[sides[0]], 12)
cube[sides[1]] = replaceBits(cube[sides[2]], 28, cube[sides[1]], 20)
cube[sides[2]] = replaceBits(cube[sides[3]], 4, cube[sides[2]], 28)
cube[sides[3]] = replaceBits(mem, 12, cube[sides[3]], 4)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 28, cube[sides[0]], 4)
cube[sides[3]] = replaceBits(cube[sides[2]], 20, cube[sides[3]], 28)
cube[sides[2]] = replaceBits(cube[sides[1]], 12, cube[sides[2]], 20)
cube[sides[1]] = replaceBits(mem, 4, cube[sides[1]], 12)
cube[sides[0]] = replaceBits(cube[sides[3]], 0, cube[sides[0]], 8)
cube[sides[3]] = replaceBits(cube[sides[2]], 24, cube[sides[3]], 0)
cube[sides[2]] = replaceBits(cube[sides[1]], 16, cube[sides[2]], 24)
cube[sides[1]] = replaceBits(mem, 8, cube[sides[1]], 16)
cube[sides[0]] = replaceBits(cube[sides[3]], 4, cube[sides[0]], 12)
cube[sides[3]] = replaceBits(cube[sides[2]], 28, cube[sides[3]], 4)
cube[sides[2]] = replaceBits(cube[sides[1]], 20, cube[sides[2]], 28)
cube[sides[1]] = replaceBits(mem, 12, cube[sides[1]], 20)
}
}
func rotSide1(cube *[6]int32, way int) {
sides := [4]int{3, 0, 4, 5}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 12, cube[sides[0]], 12)
cube[sides[1]] = replaceBits(cube[sides[2]], 12, cube[sides[1]], 12)
cube[sides[2]] = replaceBits(cube[sides[3]], 12, cube[sides[2]], 12)
cube[sides[3]] = replaceBits(mem, 12, cube[sides[3]], 12)
cube[sides[0]] = replaceBits(cube[sides[1]], 16, cube[sides[0]], 16)
cube[sides[1]] = replaceBits(cube[sides[2]], 16, cube[sides[1]], 16)
cube[sides[2]] = replaceBits(cube[sides[3]], 16, cube[sides[2]], 16)
cube[sides[3]] = replaceBits(mem, 16, cube[sides[3]], 16)
cube[sides[0]] = replaceBits(cube[sides[1]], 20, cube[sides[0]], 20)
cube[sides[1]] = replaceBits(cube[sides[2]], 20, cube[sides[1]], 20)
cube[sides[2]] = replaceBits(cube[sides[3]], 20, cube[sides[2]], 20)
cube[sides[3]] = replaceBits(mem, 20, cube[sides[3]], 20)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 12, cube[sides[0]], 12)
cube[sides[3]] = replaceBits(cube[sides[2]], 12, cube[sides[3]], 12)
cube[sides[2]] = replaceBits(cube[sides[1]], 12, cube[sides[2]], 12)
cube[sides[1]] = replaceBits(mem, 12, cube[sides[1]], 12)
cube[sides[0]] = replaceBits(cube[sides[3]], 16, cube[sides[0]], 16)
cube[sides[3]] = replaceBits(cube[sides[2]], 16, cube[sides[3]], 16)
cube[sides[2]] = replaceBits(cube[sides[1]], 16, cube[sides[2]], 16)
cube[sides[1]] = replaceBits(mem, 16, cube[sides[1]], 16)
cube[sides[0]] = replaceBits(cube[sides[3]], 20, cube[sides[0]], 20)
cube[sides[3]] = replaceBits(cube[sides[2]], 20, cube[sides[3]], 20)
cube[sides[2]] = replaceBits(cube[sides[1]], 20, cube[sides[2]], 20)
cube[sides[1]] = replaceBits(mem, 20, cube[sides[1]], 20)
}
}
func rotSide2(cube *[6]int32, way int) {
sides := [4]int{3, 5, 4, 0}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 4, cube[sides[0]], 4)
cube[sides[1]] = replaceBits(cube[sides[2]], 4, cube[sides[1]], 4)
cube[sides[2]] = replaceBits(cube[sides[3]], 4, cube[sides[2]], 4)
cube[sides[3]] = replaceBits(mem, 4, cube[sides[3]], 4)
cube[sides[0]] = replaceBits(cube[sides[1]], 0, cube[sides[0]], 0)
cube[sides[1]] = replaceBits(cube[sides[2]], 0, cube[sides[1]], 0)
cube[sides[2]] = replaceBits(cube[sides[3]], 0, cube[sides[2]], 0)
cube[sides[3]] = replaceBits(mem, 0, cube[sides[3]], 0)
cube[sides[0]] = replaceBits(cube[sides[1]], 28, cube[sides[0]], 28)
cube[sides[1]] = replaceBits(cube[sides[2]], 28, cube[sides[1]], 28)
cube[sides[2]] = replaceBits(cube[sides[3]], 28, cube[sides[2]], 28)
cube[sides[3]] = replaceBits(mem, 28, cube[sides[3]], 28)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 4, cube[sides[0]], 4)
cube[sides[3]] = replaceBits(cube[sides[2]], 4, cube[sides[3]], 4)
cube[sides[2]] = replaceBits(cube[sides[1]], 4, cube[sides[2]], 4)
cube[sides[1]] = replaceBits(mem, 4, cube[sides[1]], 4)
cube[sides[0]] = replaceBits(cube[sides[3]], 0, cube[sides[0]], 0)
cube[sides[3]] = replaceBits(cube[sides[2]], 0, cube[sides[3]], 0)
cube[sides[2]] = replaceBits(cube[sides[1]], 0, cube[sides[2]], 0)
cube[sides[1]] = replaceBits(mem, 0, cube[sides[1]], 0)
cube[sides[0]] = replaceBits(cube[sides[3]], 28, cube[sides[0]], 28)
cube[sides[3]] = replaceBits(cube[sides[2]], 28, cube[sides[3]], 28)
cube[sides[2]] = replaceBits(cube[sides[1]], 28, cube[sides[2]], 28)
cube[sides[1]] = replaceBits(mem, 28, cube[sides[1]], 28)
}
}
func rotSide3(cube *[6]int32, way int) {
sides := [4]int{5, 2, 0, 1}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 20, cube[sides[0]], 4)
cube[sides[1]] = replaceBits(cube[sides[2]], 20, cube[sides[1]], 20)
cube[sides[2]] = replaceBits(cube[sides[3]], 20, cube[sides[2]], 20)
cube[sides[3]] = replaceBits(mem, 4, cube[sides[3]], 20)
cube[sides[0]] = replaceBits(cube[sides[1]], 24, cube[sides[0]], 8)
cube[sides[1]] = replaceBits(cube[sides[2]], 24, cube[sides[1]], 24)
cube[sides[2]] = replaceBits(cube[sides[3]], 24, cube[sides[2]], 24)
cube[sides[3]] = replaceBits(mem, 8, cube[sides[3]], 24)
cube[sides[0]] = replaceBits(cube[sides[1]], 28, cube[sides[0]], 12)
cube[sides[1]] = replaceBits(cube[sides[2]], 28, cube[sides[1]], 28)
cube[sides[2]] = replaceBits(cube[sides[3]], 28, cube[sides[2]], 28)
cube[sides[3]] = replaceBits(mem, 12, cube[sides[3]], 28)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 20, cube[sides[0]], 4)
cube[sides[3]] = replaceBits(cube[sides[2]], 20, cube[sides[3]], 20)
cube[sides[2]] = replaceBits(cube[sides[1]], 20, cube[sides[2]], 20)
cube[sides[1]] = replaceBits(mem, 4, cube[sides[1]], 20)
cube[sides[0]] = replaceBits(cube[sides[3]], 24, cube[sides[0]], 8)
cube[sides[3]] = replaceBits(cube[sides[2]], 24, cube[sides[3]], 24)
cube[sides[2]] = replaceBits(cube[sides[1]], 24, cube[sides[2]], 24)
cube[sides[1]] = replaceBits(mem, 8, cube[sides[1]], 24)
cube[sides[0]] = replaceBits(cube[sides[3]], 28, cube[sides[0]], 12)
cube[sides[3]] = replaceBits(cube[sides[2]], 28, cube[sides[3]], 28)
cube[sides[2]] = replaceBits(cube[sides[1]], 28, cube[sides[2]], 28)
cube[sides[1]] = replaceBits(mem, 12, cube[sides[1]], 28)
}
}
func rotSide4(cube *[6]int32, way int) {
sides := [4]int{0, 2, 5, 1}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 4, cube[sides[0]], 4)
cube[sides[1]] = replaceBits(cube[sides[2]], 20, cube[sides[1]], 4)
cube[sides[2]] = replaceBits(cube[sides[3]], 4, cube[sides[2]], 20)
cube[sides[3]] = replaceBits(mem, 4, cube[sides[3]], 4)
cube[sides[0]] = replaceBits(cube[sides[1]], 8, cube[sides[0]], 8)
cube[sides[1]] = replaceBits(cube[sides[2]], 24, cube[sides[1]], 8)
cube[sides[2]] = replaceBits(cube[sides[3]], 8, cube[sides[2]], 24)
cube[sides[3]] = replaceBits(mem, 8, cube[sides[3]], 8)
cube[sides[0]] = replaceBits(cube[sides[1]], 12, cube[sides[0]], 12)
cube[sides[1]] = replaceBits(cube[sides[2]], 28, cube[sides[1]], 12)
cube[sides[2]] = replaceBits(cube[sides[3]], 12, cube[sides[2]], 28)
cube[sides[3]] = replaceBits(mem, 12, cube[sides[3]], 12)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 4, cube[sides[0]], 4)
cube[sides[3]] = replaceBits(cube[sides[2]], 20, cube[sides[3]], 4)
cube[sides[2]] = replaceBits(cube[sides[1]], 4, cube[sides[2]], 20)
cube[sides[1]] = replaceBits(mem, 4, cube[sides[1]], 4)
cube[sides[0]] = replaceBits(cube[sides[3]], 8, cube[sides[0]], 8)
cube[sides[3]] = replaceBits(cube[sides[2]], 24, cube[sides[3]], 8)
cube[sides[2]] = replaceBits(cube[sides[1]], 8, cube[sides[2]], 24)
cube[sides[1]] = replaceBits(mem, 8, cube[sides[1]], 8)
cube[sides[0]] = replaceBits(cube[sides[3]], 12, cube[sides[0]], 12)
cube[sides[3]] = replaceBits(cube[sides[2]], 28, cube[sides[3]], 12)
cube[sides[2]] = replaceBits(cube[sides[1]], 12, cube[sides[2]], 28)
cube[sides[1]] = replaceBits(mem, 12, cube[sides[1]], 12)
}
}
func rotSide5(cube *[6]int32, way int) {
sides := [4]int{4, 2, 3, 1}
mem := cube[sides[0]]
if way == 0 {
cube[sides[0]] = replaceBits(cube[sides[1]], 28, cube[sides[0]], 4)
cube[sides[1]] = replaceBits(cube[sides[2]], 20, cube[sides[1]], 28)
cube[sides[2]] = replaceBits(cube[sides[3]], 12, cube[sides[2]], 20)
cube[sides[3]] = replaceBits(mem, 4, cube[sides[3]], 12)
cube[sides[0]] = replaceBits(cube[sides[1]], 0, cube[sides[0]], 8)
cube[sides[1]] = replaceBits(cube[sides[2]], 24, cube[sides[1]], 0)
cube[sides[2]] = replaceBits(cube[sides[3]], 16, cube[sides[2]], 24)
cube[sides[3]] = replaceBits(mem, 8, cube[sides[3]], 16)
cube[sides[0]] = replaceBits(cube[sides[1]], 4, cube[sides[0]], 12)
cube[sides[1]] = replaceBits(cube[sides[2]], 28, cube[sides[1]], 4)
cube[sides[2]] = replaceBits(cube[sides[3]], 20, cube[sides[2]], 28)
cube[sides[3]] = replaceBits(mem, 12, cube[sides[3]], 20)
} else {
cube[sides[0]] = replaceBits(cube[sides[3]], 12, cube[sides[0]], 4)
cube[sides[3]] = replaceBits(cube[sides[2]], 20, cube[sides[3]], 12)
cube[sides[2]] = replaceBits(cube[sides[1]], 28, cube[sides[2]], 20)
cube[sides[1]] = replaceBits(mem, 4, cube[sides[1]], 28)
cube[sides[0]] = replaceBits(cube[sides[3]], 16, cube[sides[0]], 8)
cube[sides[3]] = replaceBits(cube[sides[2]], 24, cube[sides[3]], 16)
cube[sides[2]] = replaceBits(cube[sides[1]], 0, cube[sides[2]], 24)
cube[sides[1]] = replaceBits(mem, 8, cube[sides[1]], 0)
cube[sides[0]] = replaceBits(cube[sides[3]], 20, cube[sides[0]], 12)
cube[sides[3]] = replaceBits(cube[sides[2]], 28, cube[sides[3]], 20)
cube[sides[2]] = replaceBits(cube[sides[1]], 4, cube[sides[2]], 28)
cube[sides[1]] = replaceBits(mem, 12, cube[sides[1]], 4)
}
}
func rotSides(cube *[6]int32, face, way int) {
if face == 0 {
rotSide0(cube, way)
} else if face == 1 {
rotSide1(cube, way)
} else if face == 2 {
rotSide2(cube, way)
} else if face == 3 {
rotSide3(cube, way)
} else if face == 4 {
rotSide4(cube, way)
} else if face == 5 {
rotSide5(cube, way)
}
}
func rotate(face, way int, cube [6]int32) [6]int32 {
if way == 0 {
cube[face] = (cube[face] >> 8) | (cube[face] << (32 - 8))
} else {
cube[face] = (cube[face] << 8) | (cube[face] >> (32 - 8))
}
rotSides(&cube, face, way)
return cube
}