aboutsummaryrefslogtreecommitdiff
path: root/old/2020-unknown-date
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--old/2020-unknown-date/cube_backup.c527
-rw-r--r--old/2020-unknown-date/cubeutils.c100
-rw-r--r--old/2020-unknown-date/cubeutils.h18
-rw-r--r--old/2020-unknown-date/moves.c57
-rw-r--r--old/2020-unknown-date/moves.h9
-rw-r--r--old/2020-unknown-date/pieces.c208
-rw-r--r--old/2020-unknown-date/pieces.h59
7 files changed, 0 insertions, 978 deletions
diff --git a/old/2020-unknown-date/cube_backup.c b/old/2020-unknown-date/cube_backup.c
deleted file mode 100644
index e049edd..0000000
--- a/old/2020-unknown-date/cube_backup.c
+++ /dev/null
@@ -1,527 +0,0 @@
1#include <stdio.h>
2#include <string.h>
3#include "cube.h"
4
5/* The next few functions are used to convert from the Cube structure
6 * representation to actual arrays of pieces. */
7void cube_to_ep_array(Cube cube, int ep[12]);
8void cube_to_eofb_array(Cube cube, int eo[12]);
9void cube_to_eorl_array(Cube cube, int eo[12]);
10void cube_to_eoud_array(Cube cube, int eo[12]);
11void cube_to_cp_array(Cube cube, int cp[8]);
12void cube_to_coud_array(Cube cube, int co[8]);
13void cube_to_cofb_array(Cube cube, int co[8]);
14void cube_to_corl_array(Cube cube, int co[8]);
15void cube_to_centerpos_array(Cube cube, int centerpos[6]);
16Cube ep_array_to_cube(int ep[12]);
17Cube eofb_array_to_cube(int eo[12]);
18Cube eorl_array_to_cube(int eo[12]);
19Cube eoud_array_to_cube(int eo[12]);
20Cube cp_array_to_cube(int cp[8]);
21Cube coud_array_to_cube(int co[8]);
22Cube cofb_array_to_cube(int co[8]);
23Cube corl_array_to_cube(int co[8]);
24Cube centerpos_array_to_cube(int centerpos[6]);
25Cube move_array(Cube cube, void (cube_to_arr)(Cube, int *),
26 Cube (*arr_to_cube)(int *),
27 int *perm, int *orient, int n, int m);
28
29
30/* Transition tables */
31int epose_ttable[NMOVES][factorial12/factorial8];
32int eposs_ttable[NMOVES][factorial12/factorial8];
33int eposm_ttable[NMOVES][factorial12/factorial8];
34int eofb_ttable[NMOVES][pow2to11];
35int eorl_ttable[NMOVES][pow2to11];
36int eoud_ttable[NMOVES][pow2to11];
37int cp_ttable[NMOVES][factorial8];
38int coud_ttable[NMOVES][pow3to7];
39int cofb_ttable[NMOVES][pow3to7];
40int corl_ttable[NMOVES][pow3to7];
41int centerpos_ttable[NMOVES][factorial6];
42
43char edge_string[12][5] = {
44 "UF", "UL", "UB", "UR", "DF", "DL", "DB", "DR", "FR", "FL", "BL", "BR"
45};
46char corner_string[8][5] = { "UFR", "UFL", "UBL", "UBR", "DFR", "DFL", "DBL", "DBR" };
47char center_string[6][5] = { "U", "D", "R", "L", "F", "B" };
48char move_string[NMOVES][5] = {
49 "-",
50 "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'",
51 "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'",
52 "Uw", "Uw2", "Uw\'", "Dw", "Dw2", "Dw\'", "Rw", "Rw2", "Rw\'",
53 "Lw", "Lw2", "Lw\'", "Fw", "Fw2", "Fw\'", "Bw", "Bw2", "Bw\'",
54 "M", "M2", "M\'", "S", "S2", "S\'", "E", "E2", "E\'",
55 "x", "x2", "x\'", "y", "y2", "y\'", "z", "z2", "z\'",
56};
57
58int epe_solved[] = {FR, FL, BL, BR};
59int eps_solved[] = {UL, UR, DL, DR};
60int epm_solved[] = {UF, UB, DF, DB};
61
62/**************************/
63/* Internal use functions */
64/**************************/
65
66int cube_to_ep_array(Cube cube, int ep[12]) {
67 int epe[4], eps[4], epm[4];
68 index_to_perm(cube.epose % factorial(4), 4, epe);
69 index_to_perm(cube.eposs % factorial(4), 4, eps);
70 index_to_perm(cube.eposm % factorial(4), 4, epm);
71
72 int epose[12], eposs[12], eposm[12];
73 index_to_subset(cube.epose / factorial(4), 12, 4, epose);
74 index_to_subset(cube.eposs / factorial(4), 12, 4, eposs);
75 index_to_subset(cube.eposm / factorial(4), 12, 4, eposm);
76 for (int i = 0; i < 4; i++) {
77 swap(&eposs[eps_solved[i]], &eposs[i+8]);
78 swap(&eposm[epm_solved[i]], &eposm[i+8]);
79 }
80
81 for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) {
82 if (epose[i]) ep[i] = epe_solved[epe[ie++]];
83 if (eposs[i]) ep[i] = eps_solved[eps[is++]];
84 if (eposm[i]) ep[i] = epm_solved[epm[im++]];
85 }
86}
87
88void cube_to_eofb_array(Cube cube, int eo[12]) {
89 int_to_sum_zero_array(cube.eofb, 2, 12, eo);
90}
91
92void cube_to_eorl_array(Cube cube, int eo[12]) {
93 int_to_sum_zero_array(cube.eorl, 2, 12, eo);
94}
95
96void cube_to_eoud_array(Cube cube, int eo[12]) {
97 int_to_sum_zero_array(cube.eoud, 2, 12, eo);
98}
99
100void cube_to_cp_array(Cube cube, int cp[8]) {
101 index_to_perm(cube.cp, 8, cp);
102}
103
104void cube_to_coud_array(Cube cube, int co[8]) {
105 int_to_sum_zero_array(cube.coud, 3, 8, co);
106}
107
108void cube_to_cofb_array(Cube cube, int co[8]) {
109 int_to_sum_zero_array(cube.cofb, 3, 8, co);
110}
111
112void cube_to_corl_array(Cube cube, int co[8]) {
113 int_to_sum_zero_array(cube.corl, 3, 8, co);
114}
115
116void cube_to_centerpos_array(Cube cube, int centerpos[6]) {
117 index_to_perm(cube.centerpos, 6, centerpos);
118}
119
120Cube ep_array_to_cube(int ep[12]) {
121 int epe[4], eps[4], epm[4];
122 int epose[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
123 int eposs[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
124 int eposm[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
125 for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) {
126 for (int j = 0; j < 4; j++) {
127 if (ep[i] == epe_solved[j]) { epe[ie++] = j; epose[i] = 1; }
128 if (ep[i] == eps_solved[j]) { eps[is++] = j; eposs[i] = 1; }
129 if (ep[i] == epm_solved[j]) { epm[im++] = j; eposm[i] = 1; }
130 }
131 }
132 for (int i = 0; i < 4; i++) {
133 swap(&eposs[eps_solved[i]], &eposs[i+8]);
134 swap(&eposm[epm_solved[i]], &eposm[i+8]);
135 }
136 return { .epose = factorial(4) * subset_to_index(epose, 12, 4)
137 + perm_to_index(epe, 4),
138 .eposs = factorial(4) * subset_to_index(eposs, 12, 4)
139 + perm_to_index(eps, 4),
140 .eposm = factorial(4) * subset_to_index(eposm, 12, 4)
141 + perm_to_index(epm, 4) };
142}
143
144Cube eofb_array_to_cube(int eo[12]) {
145 return { .eofb = digit_array_to_int(eo, 11, 2) };
146}
147
148Cube eorl_array_to_cube(int eo[12]) {
149 return { .eorl = digit_array_to_int(eo, 11, 2) };
150}
151
152Cube eoud_array_to_cube(int eo[12]) {
153 return { .eoud = digit_array_to_int(eo, 11, 2) };
154}
155
156Cube cp_array_to_cube(int cp[8]) {
157 return { .cp = perm_to_index(cp, 8) };
158}
159
160Cube coud_array_to_cube(int co[8]) {
161 return { .coud = digit_array_to_int(co, 7, 3) };
162}
163
164Cube cofb_array_to_cube(int co[8]) {
165 return { .cofb = digit_array_to_int(co, 7, 3) };
166}
167
168Cube corl_array_to_cube(int co[8]) {
169 return { .corl = digit_array_to_int(co, 7, 3) };
170}
171
172Cube centerpos_array_to_cube(int centerpos[6]) {
173 return { .centerpos = perm_to_index(centerpos, 6) };
174}
175
176Cube move_array(Cube cube, void (*cube_to_arr)(Cube, int *),
177 void (*arr_to_cube)(int *),
178 int *perm, int *orient, int n, int m) {
179 int arr[n];
180 cube_to_arr(cube, arr);
181 apply_permutation(perm, arr, n);
182 sum_arrays_mod(arr, orient, n, m);
183 return arr_to_cube(arr);
184}
185
186/***********************/
187/* Interface functions */
188/***********************/
189
190Move inverse(Move m) {
191 if (m == NULLMOVE)
192 return m;
193 int mod = (m-1)%3;
194 Move base = m - mod;
195 return base + 2 - mod;
196}
197
198void copy_alg(NissMove *src, NissMove *dest) {
199 for (int i = 0; src[i].m != NULLMOVE; i++)
200 dest[i] = src[i];
201}
202
203bool commute(Move m1, Move m2) {
204 return equal(apply_move(m2, apply_move(m1, {0})),
205 apply_move(m1, apply_move(m2, {0})));
206}
207
208bool equal(Cube c1, Cube c2) {
209 return c1.eofb == c2.eofb && c1.epose == c2.epose &&
210 c1.eposs == c2.eposs && c1.eposm == c2.eposm &&
211 c1.coud == c2.coud && c1.cp == c2.cp &&
212 c1.centerpos == c2.centerpos;
213}
214
215bool solvable(Cube cube) {
216 /* Since we memorize orientation truncating the last digit, we only need to
217 * check that the permutations have the correct sign. */
218 /* TODO: add check that every integer is in range */
219 int ep[12], cp[12], c[6];
220 /* TODO: change to use cube-specific functions */
221 cube_to_ep_array(cube, ep);
222 cube_to_cp_array(cube, 8, cp);
223 cube_to_centerpos_array(cube, 6, c);
224 return (perm_sign(ep, 12) ^ perm_sign(c, 6)) == perm_sign(cp, 8);
225}
226
227bool is_solved(Cube cube) {
228 return (!cube.eofb && !cube.coud && !cube.cp &&
229 !cube.epose && !cube.eposs && !cube.eposm && !cube.centerpos);
230}
231
232char *to_string(Cube cube) {
233 int eo[12], co[8], ep[12], cp[8], cenpos[6];
234 cube_to_eofb_array(cube, eo);
235 cube_to_coud_array(cube, co);
236 cube_to_ep_array(cube, ep);
237 cube_to_cp_array(cube, cp);
238 cube_to_centerpos_array(cube, cenpos);
239
240 static char ret[1000];
241
242 for (int i = 0; i < 12; i++) {
243 strcat(ret, " ");
244 strcat(ret, edge_string[ep[i]]);
245 strcat(ret, " ");
246 }
247 strcat(ret, "\n");
248 for (int i = 0; i < 12; i++) {
249 strcat(ret, " ");
250 char num[2] = { [0] = eo[i] + '0', [1] = 0 };
251 strcat(ret, num);
252 strcat(ret, " ");
253 }
254 strcat(ret, "\n");
255 for (int i = 0; i < 8; i++) {
256 strcat(ret, corner_string[cp[i]]);
257 strcat(ret, " ");
258 }
259 strcat(ret, "\n");
260 for (int i = 0; i < 8; i++) {
261 strcat(ret, " ");
262 char num[2] = { [0] = co[i] + '0', [1] = 0 };
263 strcat(ret, num);
264 strcat(ret, " ");
265 }
266 strcat(ret, "\n");
267 for (int i = 0; i < 6; i++) {
268 strcat(ret, " ");
269 strcat(ret, center_string[cenpos[i]]);
270 strcat(ret, " ");
271 }
272 strcat(ret, "\n");
273
274 return ret;
275}
276
277void init_ttables() {
278 FILE *ttf;
279
280 if ((ttf = fopen("ttables", "rb")) != NULL) {
281 for (int m = 0; m < NMOVES; m++) {
282 fread(epose_ttable[m], sizeof(int), factorial12/factorial8, ttf);
283 fread(eposs_ttable[m], sizeof(int), factorial12/factorial8, ttf);
284 fread(eposm_ttable[m], sizeof(int), factorial12/factorial8, ttf);
285 fread(eofb_ttable[m], sizeof(int), pow2to11, ttf);
286 fread(eorl_ttable[m], sizeof(int), pow2to11, ttf);
287 fread(eoud_ttable[m], sizeof(int), pow2to11, ttf);
288 fread(cp_ttable[m], sizeof(int), factorial8, ttf);
289 fread(coud_ttable[m], sizeof(int), pow3to7, ttf);
290 fread(corl_ttable[m], sizeof(int), pow3to7, ttf);
291 fread(cofb_ttable[m], sizeof(int), pow3to7, ttf);
292 fread(centerpos_ttable[m], sizeof(int), factorial6, ttf);
293 }
294 fclose(ttf);
295 } else {
296 ttf = fopen("ttables", "wb");
297 int empty[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
298 /* For each type of pieces only the effects of U, x and y are described */
299 int edge_cycle[NMOVES][12] = {
300 [U] = {UR, UF, UL, UB, DF, DL, DB, DR, FR, FL, BL, BR},
301 [X] = {DF, FL, UF, FR, DB, BL, UB, BR, DR, DL, UL, UR},
302 [Y] = {UR, UF, UL, UB, DR, DF, DL, DB, BR, FR, FL, BL},
303 };
304 int eofb_flipped[NMOVES][12] = {
305 [X] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 },
306 [Y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 },
307 };
308 int eorl_flipped[NMOVES][12] = {
309 [X] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
310 [Y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 },
311 };
312 int eoud_flipped[NMOVES][12] = {
313 [U] = { [UF] = 1, [UL] = 1, [UB] = 1, [UR] = 1 },
314 [X] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 },
315 [Y] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
316 };
317 int corner_cycle[NMOVES][8] = {
318 [U] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR},
319 [X] = {DFR, DFL, UFL, UFR, DBR, DBL, UBL, UBR},
320 [Y] = {UBR, UFR, UFL, UBL, DBR, DFR, DFL, DBL},
321 };
322 int coud_flipped[NMOVES][8] = {
323 [X] = {[UFR]=2,[UBR]=1,[DBR]=2,[DFR]=1,[UFL]=1,[UBL]=2,[DBL]=1,[DFL]=2},
324 };
325 int corl_flipped[NMOVES][8] = {
326 [U] = { [UFR] = 1, [UBR] = 2, [UBL] = 1, [UFL] = 2 },
327 [Y] = {[UFR]=1,[UBR]=2,[UBL]=1,[UFL]=2,[DFR]=2,[DBR]=1,[DBL]=2,[DFL]=1},
328 };
329 int cofb_flipped[NMOVES][8] = {
330 [U] = { [UFR] = 2, [UBR] = 1, [UBL] = 2, [UFL] = 1 },
331 [X] = {[UFR]=1,[UBR]=2,[DFR]=2,[DBR]=1,[UBL]=2,[UFL]=1,[DBL]=1,[DFL]=2},
332 [Y] = {[UFR]=2,[UBR]=1,[UBL]=2,[UFL]=1,[DFR]=1,[DBR]=2,[DBL]=1,[DFL]=2},
333 };
334 int center_cycle[NMOVES][6] = {
335 [X] = {F_center, B_center, R_center, L_center, D_center, U_center},
336 [Y] = {U_center, D_center, B_center, F_center, R_center, L_center},
337 };
338
339 /* Each move is reduced to a combination of U, x and y using this table */
340 Move equiv_moves[NMOVES][13] = {
341 [U] = { U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
342 [U2] = { U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
343 [U3] = { U, U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
344 [D] = { X, X, U, X, X, 0, 0, 0, 0, 0, 0, 0, 0 },
345 [D2] = { X, X, U, U, X, X, 0, 0, 0, 0, 0, 0, 0 },
346 [D3] = { X, X, U, U, U, X, X, 0, 0, 0, 0, 0, 0 },
347 [R] = { Y, X, U, X, X, X, Y, Y, Y, 0, 0, 0, 0 },
348 [R2] = { Y, X, U, U, X, X, X, Y, Y, Y, 0, 0, 0 },
349 [R3] = { Y, X, U, U, U, X, X, X, Y, Y, Y, 0, 0 },
350 [L] = { Y, Y, Y, X, U, X, X, X, Y, 0, 0, 0, 0 },
351 [L2] = { Y, Y, Y, X, U, U, X, X, X, Y, 0, 0, 0 },
352 [L3] = { Y, Y, Y, X, U, U, U, X, X, X, Y, 0, 0 },
353 [F] = { X, U, X, X, X, 0, 0, 0, 0, 0, 0, 0, 0 },
354 [F2] = { X, U, U, X, X, X, 0, 0, 0, 0, 0, 0, 0 },
355 [F3] = { X, U, U, U, X, X, X, 0, 0, 0, 0, 0, 0 },
356 [B] = { X, X, X, U, X, 0, 0, 0, 0, 0, 0, 0, 0 },
357 [B2] = { X, X, X, U, U, X, 0, 0, 0, 0, 0, 0, 0 },
358 [B3] = { X, X, X, U, U, U, X, 0, 0, 0, 0, 0, 0 },
359
360 [Uw] = { X, X, U, X, X, Y, 0, 0, 0, 0, 0, 0, 0 },
361 [Uw2] = { X, X, U, U, X, X, Y, Y, 0, 0, 0, 0, 0 },
362 [Uw3] = { X, X, U, U, U, X, X, Y, Y, Y, 0, 0, 0 },
363 [Dw] = { U, Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
364 [Dw2] = { U, U, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
365 [Dw3] = { U, U, U, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
366 [Rw] = { Y, Y, Y, X, U, X, X, X, Y, X, 0, 0, 0 },
367 [Rw2] = { Y, Y, Y, X, U, U, X, X, X, Y, X, X, 0 },
368 [Rw3] = { Y, Y, Y, X, U, U, U, Y, X, X, X, Y, 0 },
369 [Lw] = { Y, X, U, X, X, X, Y, Y, Y, X, X, X, 0 },
370 [Lw2] = { Y, X, U, U, X, X, X, Y, Y, Y, X, X, 0 },
371 [Lw3] = { Y, X, U, U, U, X, X, X, Y, Y, Y, X, 0 },
372 [Fw] = { X, X, X, U, Y, Y, Y, X, 0, 0, 0, 0, 0 },
373 [Fw2] = { X, X, X, U, U, Y, Y, X, 0, 0, 0, 0, 0 },
374 [Fw3] = { X, X, X, U, U, U, Y, X, 0, 0, 0, 0, 0 },
375 [Bw] = { X, U, Y, Y, Y, X, X, X, 0, 0, 0, 0, 0 },
376 [Bw2] = { X, U, U, Y, Y, X, X, X, 0, 0, 0, 0, 0 },
377 [Bw3] = { X, U, U, U, Y, X, X, X, 0, 0, 0, 0, 0 },
378
379 [M] = { Y, X, U, X, X, U, U, U, Y, X, Y, Y, Y },
380 [M2] = { Y, X, U, U, X, X, U, U, X, X, X, Y, 0 },
381 [M3] = { Y, X, U, U, U, X, X, U, Y, X, X, X, Y },
382 [S] = { X, U, U, U, X, X, U, Y, Y, Y, X, 0, 0 },
383 [S2] = { X, U, U, X, X, U, U, Y, Y, X, 0, 0, 0 },
384 [S3] = { X, U, X, X, U, U, U, Y, X, 0, 0, 0, 0 },
385 [E] = { U, X, X, U, U, U, X, X, Y, Y, Y, 0, 0 },
386 [E2] = { U, U, X, X, U, U, X, X, Y, Y, 0, 0, 0 },
387 [E3] = { U, U, U, X, X, U, X, X, Y, 0, 0, 0, 0 },
388
389 [X] = { X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
390 [X2] = { X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
391 [X3] = { X, X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
392 [Y] = { Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
393 [Y2] = { Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
394 [Y3] = { Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
395 [Z] = { Y, Y, Y, X, Y, 0, 0, 0, 0, 0, 0, 0, 0 },
396 [Z2] = { Y, Y, X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
397 [Z3] = { Y, X, Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0 },
398 };
399
400 /* Generate all move cycles and flips */
401 for (int i = 0; i < NMOVES; i++) {
402 if (i == U || i == X || i == Y)
403 continue;
404
405 Cube cube = {0};
406
407 cube_to_ep_array(&cube, edge_cycle[i]);
408 cube_to_eofb_array(&cube, eofb_flipped[i]);
409 cube_to_eorl_array(&cube, eorl_flipped[i]);
410 cube_to_eoud_array(&cube, eoud_flipped[i]);
411 cube_to_cp_array(&cube, corner_cycle[i]);
412 cube_to_coud_array(&cube, coud_flipped[i]);
413 cube_to_cofb_array(&cube, cofb_flipped[i]);
414 cube_to_corl_array(&cube, corl_flipped[i]);
415 cube_to_centerpos_array(&cube, center_cycle[i]);
416
417 for (int j = 0; equiv_moves[i][j]; j++) {
418 int m = equiv_moves[i][j];
419
420 apply_permutation(edge_cycle[m], edge_cycle[i], 12);
421 apply_permutation(edge_cycle[m], eofb_flipped[i], 12);
422 apply_permutation(edge_cycle[m], eorl_flipped[i], 12);
423 apply_permutation(edge_cycle[m], eoud_flipped[i], 12);
424
425 sum_arrays_mod(eofb_flipped[i], eofb_flipped[m], 12, 2);
426 sum_arrays_mod(eorl_flipped[i], eorl_flipped[m], 12, 2);
427 sum_arrays_mod(eoud_flipped[i], eoud_flipped[m], 12, 2);
428
429 apply_permutation(corner_cycle[m], corner_cycle[i], 8);
430 apply_permutation(corner_cycle[m], coud_flipped[i], 8);
431 apply_permutation(corner_cycle[m], cofb_flipped[i], 8);
432 apply_permutation(corner_cycle[m], corl_flipped[i], 8);
433
434 sum_arrays_mod(coud_flipped[i], coud_flipped[m], 8, 3);
435 sum_arrays_mod(corl_flipped[i], corl_flipped[m], 8, 3);
436 sum_arrays_mod(cofb_flipped[i], cofb_flipped[m], 8, 3);
437
438 apply_permutation(center_cycle[m], center_cycle[i], 6);
439 }
440 }
441
442 /* Initialize transition tables */
443 for (int m = 0; m < NMOVES; m++) {
444 for (int i = 0; i < factorial12/factorial8; i++) {
445 Cube cube = { .epose = i };
446 move_array(&cube, cube_to_ep_array, ep_array_to_cube,
447 edge_cycle[m], empty, 12, 1);
448 epose_ttable[m][i] = cube.epose;
449 cube.eposs = i;
450 move_array(&cube, cube_to_ep_array, ep_array_to_cube,
451 edge_cycle[m], empty, 12, 1);
452 eposs_ttable[m][i] = cube.eposs;
453 cube.eposm = i;
454 move_array(&cube, cube_to_ep_array, ep_array_to_cube,
455 edge_cycle[m], empty, 12, 1);
456 eposm_ttable[m][i] = cube.eposm;
457 }
458 for (int i = 0; i < pow2to11; i++ ) {
459 Cube cube = { .eofb = i, .eorl = i, .eoud = i };
460 move_array(&cube, cube_to_eofb_array, eofb_array_to_cube,
461 edge_cycle[m], eofb_flipped[m], 12, 2);
462 move_array(&cube, cube_to_eorl_array, eorl_array_to_cube,
463 edge_cycle[m], eorl_flipped[m], 12, 2);
464 move_array(&cube, cube_to_eoud_array, eoud_array_to_cube,
465 edge_cycle[m], eoud_flipped[m], 12, 2);
466 eofb_ttable[m][i] = cube.eofb;
467 eorl_ttable[m][i] = cube.eorl;
468 eoud_ttable[m][i] = cube.eoud;
469 }
470 for (int i = 0; i < factorial8; i++) {
471 /* TODO: Maybe do this by hand to optimize? */
472 Cube cube = { .cp = i };
473 move_array(&cube, cube_to_cp_array, ep_array_to_cube,
474 corner_cycle[m], empty, 8, 1);
475 cp_ttable[m][i] = cube.cp;
476 }
477 for (int i = 0; i < pow3to7; i++) {
478 Cube cube = { .coud = i, .corl = i, .cofb = i };
479 move_array(&cube, cube_to_coud_array, coud_array_to_cube,
480 corner_cycle[m], coud_flipped[m], 8, 3);
481 move_array(&cube, cube_to_corl_array, corl_array_to_cube,
482 corner_cycle[m], corl_flipped[m], 8, 3);
483 move_array(&cube, cube_to_cofb_array, cofb_array_to_cube,
484 corner_cycle[m], cofb_flipped[m], 8, 3);
485 coud_ttable[m][i] = cube.coud;
486 corl_ttable[m][i] = cube.corl;
487 cofb_ttable[m][i] = cube.cofb;
488 }
489 for (int i = 0; i < factorial6; i++) {
490 Cube cube = { .centerpos = i };
491 move_array(&cube, cube_to_centerpos_array, centerpos_array_to_cube,
492 center_cycle[m], empty, 6, 1);
493 centerpos_ttable[m][i] = cube.centerpos;
494 }
495 fwrite(epose_ttable[m], sizeof(int), factorial12/factorial8, ttf);
496 fwrite(eposs_ttable[m], sizeof(int), factorial12/factorial8, ttf);
497 fwrite(eposm_ttable[m], sizeof(int), factorial12/factorial8, ttf);
498 fwrite(eofb_ttable[m], sizeof(int), pow2to11, ttf);
499 fwrite(eorl_ttable[m], sizeof(int), pow2to11, ttf);
500 fwrite(eoud_ttable[m], sizeof(int), pow2to11, ttf);
501 fwrite(cp_ttable[m], sizeof(int), factorial8, ttf);
502 fwrite(coud_ttable[m], sizeof(int), pow3to7, ttf);
503 fwrite(corl_ttable[m], sizeof(int), pow3to7, ttf);
504 fwrite(cofb_ttable[m], sizeof(int), pow3to7, ttf);
505 fwrite(centerpos_ttable[m], sizeof(int), factorial6, ttf);
506 }
507 fclose(ttf);
508 }
509}
510
511Cube apply_move(Move m, Cube cube) {
512 Cube moved = cube;
513
514 moved.eofb = eofb_ttable[m][cube.eofb];
515 moved.eorl = eorl_ttable[m][cube.eorl];
516 moved.eoud = eoud_ttable[m][cube.eoud];
517 moved.coud = coud_ttable[m][cube.coud];
518 moved.cofb = cofb_ttable[m][cube.cofb];
519 moved.corl = corl_ttable[m][cube.corl];
520 moved.epose = epose_ttable[m][cube.epose];
521 moved.eposs = eposs_ttable[m][cube.eposs];
522 moved.eposm = eposm_ttable[m][cube.eposm];
523 moved.cp = cp_ttable[m][cube.cp];
524 moved.centerpos = centerpos_ttable[m][cube.centerpos];
525
526 return moved;
527}
diff --git a/old/2020-unknown-date/cubeutils.c b/old/2020-unknown-date/cubeutils.c
deleted file mode 100644
index 4f0a060..0000000
--- a/old/2020-unknown-date/cubeutils.c
+++ /dev/null
@@ -1,100 +0,0 @@
1#include <stdio.h>
2#include "utils.h"
3#include "pieces.h"
4#include "cubeutils.h"
5
6int epe_solved[] = {FR, FL, BL, BR};
7int eps_solved[] = {UL, UR, DL, DR};
8int epm_solved[] = {UF, UB, DF, DB};
9
10void cube_to_ep_array(Cube *cube, int ep[12]) {
11 int epe[4], eps[4], epm[4];
12 index_to_perm(cube->epose % factorial(4), 4, epe);
13 index_to_perm(cube->eposs % factorial(4), 4, eps);
14 index_to_perm(cube->eposm % factorial(4), 4, epm);
15
16 int epose[12], eposs[12], eposm[12];
17 index_to_subset(cube->epose / factorial(4), 12, 4, epose);
18 index_to_subset(cube->eposs / factorial(4), 12, 4, eposs);
19 index_to_subset(cube->eposm / factorial(4), 12, 4, eposm);
20 for (int i = 0; i < 4; i++) {
21 swap(&eposs[eps_solved[i]], &eposs[i+8]);
22 swap(&eposm[epm_solved[i]], &eposm[i+8]);
23 }
24
25 for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) {
26 if (epose[i]) ep[i] = epe_solved[epe[ie++]];
27 if (eposs[i]) ep[i] = eps_solved[eps[is++]];
28 if (eposm[i]) ep[i] = epm_solved[epm[im++]];
29 }
30}
31
32void ep_array_to_epos(int ep[12], Cube *cube) {
33 int epe[4], eps[4], epm[4];
34 int epose[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35 int eposs[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
36 int eposm[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
37 for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) {
38 for (int j = 0; j < 4; j++) {
39 if (ep[i] == epe_solved[j]) { epe[ie++] = j; epose[i] = 1; }
40 if (ep[i] == eps_solved[j]) { eps[is++] = j; eposs[i] = 1; }
41 if (ep[i] == epm_solved[j]) { epm[im++] = j; eposm[i] = 1; }
42 }
43 }
44 for (int i = 0; i < 4; i++) {
45 swap(&eposs[eps_solved[i]], &eposs[i+8]);
46 swap(&eposm[epm_solved[i]], &eposm[i+8]);
47 }
48 cube->epose = factorial(4) * subset_to_index(epose, 12, 4)
49 + perm_to_index(epe, 4);
50 cube->eposs = factorial(4) * subset_to_index(eposs, 12, 4)
51 + perm_to_index(eps, 4);
52 cube->eposm = factorial(4) * subset_to_index(eposm, 12, 4)
53 + perm_to_index(epm, 4);
54}
55
56bool solvable(Cube *cube) {
57 /* Since we memorize orientation truncating the last digit, we only need to
58 * check that the permutations have the correct sign. */
59 /* TODO: add check that every integer is in range */
60 int ep[12], cp[12], c[6];
61 cube_to_ep_array(cube, ep);
62 index_to_perm(cube->cp, 8, cp);
63 index_to_perm(cube->centerpos, 6, c);
64 return (perm_sign(ep, 12) ^ perm_sign(c, 6)) == perm_sign(cp, 8);
65}
66
67Cube *solved_cube() {
68 static Cube cube = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
69 return &cube;
70}
71
72bool solved(Cube *cube) {
73 return (cube->eofb == 0 && cube->coud == 0 && cube->cp == 0 &&
74 cube->epose == 0 && cube->eposs == 0 && cube->eposm == 0 &&
75 cube->centerpos == 0);
76}
77
78char *to_string(Cube *cube) {
79 int eo[12], co[8], ep[12], cp[8], cenpos[6];
80 cube_to_eofb_array(cube->eofb, eo);
81 cube_to_coud_array(cube->coud, co);
82 cube_to_ep_array(cube, ep);
83 cube_to_cp_array(cube->cp, cp);
84 cube_to_centerpos_array(cube->centerpos, cenpos);
85
86 char *ret[1000];
87
88 for (int i = 0; i < 12; i++) sprintf(ret, " %s ", edge_string[ep[i]]);
89 sprintf(ret, "\n");
90 for (int i = 0; i < 12; i++) sprintf(ret, " %d ", eo[i]);
91 sprintf(ret, "\n");
92 for (int i = 0; i < 8; i++) sprintf(ret, "%s ", corner_string[cp[i]]);
93 sprintf(ret, "\n");
94 for (int i = 0; i < 8; i++) sprintf(ret, " %d ", co[i]);
95 sprintf(ret, "\n");
96 for (int i = 0; i < 6; i++) sprintf(ret, " %s ", center_string[cenpos[i]]);
97 sprintf(ret, "\n");
98
99 return ret;
100}
diff --git a/old/2020-unknown-date/cubeutils.h b/old/2020-unknown-date/cubeutils.h
deleted file mode 100644
index b24291c..0000000
--- a/old/2020-unknown-date/cubeutils.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/* Cube-specific utility functions */
2
3#ifndef CUBEUTILS_H
4#define CUBEUTILS_H
5
6#include <stdbool.h>
7#include "pieces.h"
8
9void cube_to_ep_array(Cube *cube, int ep[12]);
10void ep_array_to_epos(int ep[12], Cube *cube);
11
12Cube *solved_cube();
13bool solvable(Cube *cube);
14bool solved(Cube *cube);
15
16void print(Cube *cube);
17
18#endif
diff --git a/old/2020-unknown-date/moves.c b/old/2020-unknown-date/moves.c
deleted file mode 100644
index de293ed..0000000
--- a/old/2020-unknown-date/moves.c
+++ /dev/null
@@ -1,57 +0,0 @@
1#include <stdbool.h>
2#include "pieces.h"
3#include "moves.h"
4#include "utils.h"
5
6/* Transition tables */
7int eofb_ttable[pow2to11][NULLMOVE];
8int eorl_ttable[pow2to11][NULLMOVE];
9int eoud_ttable[pow2to11][NULLMOVE];
10int coud_ttable[pow3to7][NULLMOVE];
11int cofb_ttable[pow3to7][NULLMOVE];
12int corl_ttable[pow3to7][NULLMOVE];
13int epose_ttable[factorial12/factorial8][NULLMOVE];
14int eposs_ttable[factorial12/factorial8][NULLMOVE];
15int eposm_ttable[factorial12/factorial8][NULLMOVE];
16int cp_ttable[factorial8][NULLMOVE];
17int centerpos_ttable[factorial6][NULLMOVE];
18
19void apply_move_ep(Move m, int a[12]) {
20 int aux[12];
21 intarrcopy(a, aux, 12);
22 for (int i = 0; i < 12; i++)
23 a[i] = aux[edge_cycle[m][i]];
24}
25
26void apply_move_cp(Move m, int a[8]) {
27 int aux[8];
28 intarrcopy(a, aux, 8);
29 for (int i = 0; i < 8; i++)
30 a[i] = aux[corner_cycle[m][i]];
31}
32
33void apply_move_centerpos(Move m, int a[6]) {
34 int aux[6];
35 intarrcopy(a, aux, 6);
36 for (int i = 0; i < 6; i++)
37 a[i] = aux[center_cycle[m][i]];
38}
39
40void init_ttables() {
41 /* TODO */
42}
43
44void apply_move(Move m, Cube *cube) {
45 cube->eofb = eofb_ttable[cube->eofb][m];
46 cube->eorl = eorl_ttable[cube->eorl][m];
47 cube->eoud = eoud_ttable[cube->eoud][m];
48 cube->coud = coud_ttable[cube->coud][m];
49 cube->cofb = cofb_ttable[cube->cofb][m];
50 cube->corl = corl_ttable[cube->corl][m];
51 cube->epose = epose_ttable[cube->epose][m];
52 cube->eposs = eposs_ttable[cube->eposs][m];
53 cube->eposm = eposm_ttable[cube->eposm][m];
54 cube->cp = cp_ttable[cube->cp][m];
55 cube->centerpos = centerpos_ttable[cube->centerpos][m];
56}
57
diff --git a/old/2020-unknown-date/moves.h b/old/2020-unknown-date/moves.h
deleted file mode 100644
index 605f335..0000000
--- a/old/2020-unknown-date/moves.h
+++ /dev/null
@@ -1,9 +0,0 @@
1/* Moves and transition tables */
2
3#ifndef MOVES_H
4#define MOVES_H
5
6void apply_move(Move m, Cube *cube);
7void init_ttables();
8
9#endif
diff --git a/old/2020-unknown-date/pieces.c b/old/2020-unknown-date/pieces.c
deleted file mode 100644
index d782c89..0000000
--- a/old/2020-unknown-date/pieces.c
+++ /dev/null
@@ -1,208 +0,0 @@
1#include "pieces.h"
2
3char edge_string[12][5] = {
4 "UF", "UL", "UB", "UR", "DF", "DL", "DB", "DR", "FR", "FL", "BL", "BR"
5};
6
7char corner_string[8][5] = {
8 "UFR", "UFL", "UBL", "UBR", "DFR", "DFL", "DBL", "DBR"
9};
10
11char center_string[6][5] = { "U", "D", "R", "L", "F", "B" };
12
13char move_string[NULLMOVE+1][5] = {
14 "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'",
15 "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'",
16 "Uw", "Uw2", "Uw\'", "Dw", "Dw2", "Dw\'", "Rw", "Rw2", "Rw\'",
17 "Lw", "Lw2", "Lw\'", "Fw", "Fw2", "Fw\'", "Bw", "Bw2", "Bw\'",
18 "M", "M2", "M\'", "S", "S2", "S\'", "E", "E2", "E\'",
19 "x", "x2", "x\'", "y", "y2", "y\'", "z", "z2", "z\'",
20 "-"
21};
22
23int edge_cycle[NULLMOVE+1][12] = {
24 [U] = {UR, UF, UL, UB, DF, DL, DB, DR, FR, FL, BL, BR},
25 [U2] = {UB, UR, UF, UL, DF, DL, DB, DR, FR, FL, BL, BR},
26 [U3] = {UL, UB, UR, UF, DF, DL, DB, DR, FR, FL, BL, BR},
27 [D] = {UF, UL, UB, UR, DL, DB, DR, DF, FR, FL, BL, BR},
28 [D2] = {UF, UL, UB, UR, DB, DR, DF, DL, FR, FL, BL, BR},
29 [D3] = {UF, UL, UB, UR, DR, DF, DL, DB, FR, FL, BL, BR},
30 [R] = {UF, UL, UB, FR, DF, DL, DB, BR, DR, FL, BL, UR},
31 [R2] = {UF, UL, UB, DR, DF, DL, DB, UR, BR, FL, BL, FR},
32 [R3] = {UF, UL, UB, BR, DF, DL, DB, FR, UR, FL, BL, DR},
33 [L] = {UF, BL, UB, UR, DF, FL, DB, DR, FR, UL, DL, BR},
34 [L2] = {UF, DL, UB, UR, DF, UL, DB, DR, FR, BL, FL, BR},
35 [L3] = {UF, FL, UB, UR, DF, BL, DB, DR, FR, DL, UL, BR},
36 [F] = {FL, UL, UB, UR, FR, DL, DB, DR, UF, DF, BL, BR},
37 [F2] = {DF, UL, UB, UR, UF, DL, DB, DR, FL, FR, BL, BR},
38 [F3] = {FR, UL, UB, UR, FL, DL, DB, DR, DF, UF, BL, BR},
39 [B] = {UF, UL, BR, UR, DF, DL, BL, DR, FR, FL, UB, DB},
40 [B2] = {UF, UL, DB, UR, DF, DL, UB, DR, FR, FL, BR, BL},
41 [B3] = {UF, UL, BL, UR, DF, DL, BR, DR, FR, FL, DB, UB},
42
43 [Uw] = {UR, UF, UL, UB, DF, DL, DB, DR, BR, FR, FL, BL},
44 [Uw2] = {UB, UR, UF, UL, DF, DL, DB, DR, BL, BR, FR, FL},
45 [Uw3] = {UL, UB, UR, UF, DF, DL, DB, DR, FL, BL, BR, FR},
46 [Dw] = {UF, UL, UB, UR, DL, DB, DR, DF, FL, BL, BR, FR},
47 [Dw2] = {UF, UL, UB, UR, DB, DR, DF, DL, BL, BR, FR, FL},
48 [Dw3] = {UF, UL, UB, UR, DR, DF, DL, DB, BR, FR, FL, BL},
49 [Rw] = {DF, UL, UF, FR, DB, DL, UB, BR, DR, FL, BL, UR},
50 [Rw2] = {DB, UL, DF, DR, UB, DL, UF, UR, BR, FL, BL, FR},
51 [Rw3] = {UB, UL, DB, BR, UF, DL, DF, FR, UR, FL, BL, DR},
52 [Lw] = {UB, BL, DB, UR, UF, FL, DF, DR, FR, UL, DL, BR},
53 [Lw2] = {DB, DL, DF, UR, UB, UL, UF, DR, FR, BL, FL, BR},
54 [Lw3] = {DF, FL, UF, UR, DB, BL, UB, DR, FR, DL, UL, BR},
55 [Fw] = {FL, DL, UB, UL, FR, DR, DB, UR, UF, DF, BL, BR},
56 [Fw2] = {DF, DR, UB, DL, UF, UR, DB, UL, FL, FR, BL, BR},
57 [Fw3] = {FR, UR, UB, DR, FL, UL, DB, DL, DF, UF, BL, BR},
58 [Bw] = {UF, UR, BR, DR, DF, UL, BL, DL, FR, FL, UB, DB},
59 [Bw2] = {UF, DR, DB, DL, DF, UR, UB, UL, FR, FL, BR, BL},
60 [Bw3] = {UF, DL, BL, UL, DF, DR, BR, UR, FR, FL, DB, UB},
61
62 [M] = {UB, UL, DB, UR, UF, DL, DF, DR, FR, FL, BL, BR},
63 [M2] = {DB, UL, DF, UR, UB, DL, UF, DR, FR, FL, BL, BR},
64 [M3] = {DF, UL, UF, UR, DB, DL, UB, DR, FR, FL, BL, BR},
65 [S] = {UF, DL, UB, UL, DF, DR, DB, UR, FR, FL, BL, BR},
66 [S2] = {UF, DR, UB, DL, DF, UR, DB, UL, FR, FL, BL, BR},
67 [S3] = {UF, UR, UB, DR, DF, UL, DB, DL, FR, FL, BL, BR},
68 [E] = {UF, UL, UB, UR, DF, DL, DB, DR, FL, BL, BR, FR},
69 [E2] = {UF, UL, UB, UR, DF, DL, DB, DR, BL, BR, FR, FL},
70 [E3] = {UF, UL, UB, UR, DF, DL, DB, DR, BR, FR, FL, BL},
71
72 [X] = {DF, FL, UF, FR, DB, BL, UB, BR, DR, DL, UL, UR},
73 [X2] = {DB, DL, DF, DR, UB, UL, UF, UR, BR, BL, FL, FR},
74 [X3] = {UB, BL, DB, BR, UF, FL, DF, FR, UR, UL, DL, DR},
75 [Y] = {UR, UF, UL, UB, DR, DF, DL, DB, BR, FR, FL, BL},
76 [Y2] = {UB, UR, UF, UL, DB, DR, DF, DL, BL, BR, FR, FL},
77 [Y3] = {UL, UB, UR, UF, DL, DB, DR, DF, FL, BL, BR, FR},
78 [Z] = {FL, DL, BL, UL, FR, DR, BR, UR, UF, DF, DB, UB},
79 [Z2] = {DF, DR, DB, DL, UF, UR, UB, UL, FL, FR, BR, BL},
80 [Z3] = {FR, UR, BR, DR, FL, UL, BL, DL, DF, UF, UB, DB},
81
82 [NULLMOVE] = {UF, UL, UB, UR, DF, DL, DB, DR, FR, FL, BL, BR},
83};
84
85int corner_cycle[NULLMOVE+1][8] = {
86 [U] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR},
87 [U2] = {UBL, UBR, UFR, UFL, DFR, DFL, DBL, DBR},
88 [U3] = {UFL, UBL, UBR, UFR, DFR, DFL, DBL, DBR},
89 [D] = {UFR, UFL, UBL, UBR, DFL, DBL, DBR, DFR},
90 [D2] = {UFR, UFL, UBL, UBR, DBL, DBR, DFR, DFL},
91 [D3] = {UFR, UFL, UBL, UBR, DBR, DFR, DFL, DBL},
92 [R] = {DFR, UFL, UBL, UFR, DBR, DFL, DBL, UBR},
93 [R2] = {DBR, UFL, UBL, DFR, UBR, DFL, DBL, UFR},
94 [R3] = {UBR, UFL, UBL, DBR, UFR, DFL, DBL, DFR},
95 [L] = {UFR, UBL, DBL, UBR, DFR, UFL, DFL, DBR},
96 [L2] = {UFR, DBL, DFL, UBR, DFR, UBL, UFL, DBR},
97 [L3] = {UFR, DFL, UFL, UBR, DFR, DBL, UBL, DBR},
98 [F] = {UFL, DFL, UBL, UBR, UFR, DFR, DBL, DBR},
99 [F2] = {DFL, DFR, UBL, UBR, UFL, UFR, DBL, DBR},
100 [F3] = {DFR, UFR, UBL, UBR, DFL, UFL, DBL, DBR},
101 [B] = {UFR, UFL, UBR, DBR, DFR, DFL, UBL, DBL},
102 [B2] = {UFR, UFL, DBR, DBL, DFR, DFL, UBR, UBL},
103 [B3] = {UFR, UFL, DBL, UBL, DFR, DFL, DBR, UBR},
104
105 [Uw] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR},
106 [Uw2] = {UBL, UBR, UFR, UFL, DFR, DFL, DBL, DBR},
107 [Uw3] = {UFL, UBL, UBR, UFR, DFR, DFL, DBL, DBR},
108 [Dw] = {UFR, UFL, UBL, UBR, DFL, DBL, DBR, DFR},
109 [Dw2] = {UFR, UFL, UBL, UBR, DBL, DBR, DFR, DFL},
110 [Dw3] = {UFR, UFL, UBL, UBR, DBR, DFR, DFL, DBL},
111 [Rw] = {DFR, UFL, UBL, UFR, DBR, DFL, DBL, UBR},
112 [Rw2] = {DBR, UFL, UBL, DFR, UBR, DFL, DBL, UFR},
113 [Rw3] = {UBR, UFL, UBL, DBR, UFR, DFL, DBL, DFR},
114 [Lw] = {UFR, UBL, DBL, UBR, DFR, UFL, DFL, DBR},
115 [Lw2] = {UFR, DBL, DFL, UBR, DFR, UBL, UFL, DBR},
116 [Lw3] = {UFR, DFL, UFL, UBR, DFR, DBL, UBL, DBR},
117 [Fw] = {UFL, DFL, UBL, UBR, UFR, DFR, DBL, DBR},
118 [Fw2] = {DFL, DFR, UBL, UBR, UFL, UFR, DBL, DBR},
119 [Fw3] = {DFR, UFR, UBL, UBR, DFL, UFL, DBL, DBR},
120 [Bw] = {UFR, UFL, UBR, DBR, DFR, DFL, UBL, DBL},
121 [Bw2] = {UFR, UFL, DBR, DBL, DFR, DFL, UBR, UBL},
122 [Bw3] = {UFR, UFL, DBL, UBL, DFR, DFL, DBR, UBR},
123
124 [M] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
125 [M2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
126 [M3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
127 [S] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
128 [S2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
129 [S3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
130 [E] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
131 [E2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
132 [E3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
133
134 [X] = {DFR, DFL, UFL, UFR, DBR, DBL, UBL, UBR},
135 [X2] = {DBR, DBL, DFL, DFR, UBR, UBL, UFL, UFR},
136 [X3] = {UBR, UBL, DBL, DBR, UFR, UFL, DFL, DFR},
137 [Y] = {UBR, UFR, UFL, UBL, DBR, DFR, DFL, DBL},
138 [Y2] = {UBL, UBR, UFR, UFL, DBL, DBR, DFR, DFL},
139 [Y3] = {UFL, UBL, UBR, UFR, DFL, DBL, DBR, DFR},
140 [Z] = {UFL, DFL, DBL, UBL, UFR, DFR, DBR, UBR},
141 [Z2] = {DFL, DFR, DBR, DBL, UFL, UFR, UBR, UBL},
142 [Z3] = {DFR, UFR, UBR, DBR, DFL, UFL, UBL, DBL},
143
144 [NULLMOVE] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR},
145};
146
147int center_cycle[NULLMOVE+1][6] = {
148 [U] = {U_center, D_center, R_center, L_center, F_center, B_center},
149 [U2] = {U_center, D_center, R_center, L_center, F_center, B_center},
150 [U3] = {U_center, D_center, R_center, L_center, F_center, B_center},
151 [D] = {U_center, D_center, R_center, L_center, F_center, B_center},
152 [D2] = {U_center, D_center, R_center, L_center, F_center, B_center},
153 [D3] = {U_center, D_center, R_center, L_center, F_center, B_center},
154 [R] = {U_center, D_center, R_center, L_center, F_center, B_center},
155 [R2] = {U_center, D_center, R_center, L_center, F_center, B_center},
156 [R3] = {U_center, D_center, R_center, L_center, F_center, B_center},
157 [L] = {U_center, D_center, R_center, L_center, F_center, B_center},
158 [L2] = {U_center, D_center, R_center, L_center, F_center, B_center},
159 [L3] = {U_center, D_center, R_center, L_center, F_center, B_center},
160 [F] = {U_center, D_center, R_center, L_center, F_center, B_center},
161 [F2] = {U_center, D_center, R_center, L_center, F_center, B_center},
162 [F3] = {U_center, D_center, R_center, L_center, F_center, B_center},
163 [B] = {U_center, D_center, R_center, L_center, F_center, B_center},
164 [B2] = {U_center, D_center, R_center, L_center, F_center, B_center},
165 [B3] = {U_center, D_center, R_center, L_center, F_center, B_center},
166
167 [Uw] = {U_center, D_center, B_center, F_center, R_center, L_center},
168 [Uw2] = {U_center, D_center, L_center, R_center, B_center, F_center},
169 [Uw3] = {U_center, D_center, F_center, B_center, L_center, R_center},
170 [Dw] = {U_center, D_center, F_center, B_center, L_center, R_center},
171 [Dw2] = {U_center, D_center, L_center, R_center, B_center, F_center},
172 [Dw3] = {U_center, D_center, B_center, F_center, R_center, L_center},
173 [Rw] = {F_center, B_center, R_center, L_center, D_center, U_center},
174 [Rw2] = {D_center, U_center, R_center, L_center, B_center, F_center},
175 [Rw3] = {B_center, F_center, R_center, L_center, U_center, D_center},
176 [Lw] = {B_center, F_center, R_center, L_center, U_center, D_center},
177 [Lw2] = {D_center, U_center, R_center, L_center, B_center, F_center},
178 [Lw3] = {F_center, B_center, R_center, L_center, D_center, U_center},
179 [Fw] = {L_center, R_center, U_center, D_center, F_center, B_center},
180 [Fw2] = {D_center, U_center, L_center, R_center, F_center, B_center},
181 [Fw3] = {R_center, L_center, D_center, U_center, F_center, B_center},
182 [Bw] = {R_center, L_center, D_center, U_center, F_center, B_center},
183 [Bw2] = {D_center, U_center, L_center, R_center, F_center, B_center},
184 [Bw3] = {L_center, R_center, U_center, D_center, F_center, B_center},
185
186 [X] = {F_center, B_center, R_center, L_center, D_center, U_center},
187 [X2] = {D_center, U_center, R_center, L_center, B_center, F_center},
188 [X3] = {B_center, F_center, R_center, L_center, U_center, D_center},
189 [Y] = {U_center, D_center, B_center, F_center, R_center, L_center},
190 [Y2] = {U_center, D_center, L_center, R_center, B_center, F_center},
191 [Y3] = {U_center, D_center, F_center, B_center, L_center, R_center},
192 [Z] = {L_center, R_center, U_center, D_center, F_center, B_center},
193 [Z2] = {D_center, U_center, L_center, R_center, F_center, B_center},
194 [Z3] = {R_center, L_center, D_center, U_center, F_center, B_center},
195
196 [M] = {B_center, F_center, R_center, L_center, U_center, D_center},
197 [M2] = {D_center, U_center, R_center, L_center, B_center, F_center},
198 [M3] = {F_center, B_center, R_center, L_center, D_center, U_center},
199 [E] = {U_center, D_center, F_center, B_center, L_center, R_center},
200 [E2] = {U_center, D_center, L_center, R_center, B_center, F_center},
201 [E3] = {U_center, D_center, B_center, F_center, R_center, L_center},
202 [S] = {L_center, R_center, U_center, D_center, F_center, B_center},
203 [S2] = {D_center, U_center, L_center, R_center, F_center, B_center},
204 [S3] = {R_center, L_center, D_center, U_center, F_center, B_center},
205
206 [NULLMOVE] = {U_center, D_center, R_center, L_center, F_center, B_center},
207};
208
diff --git a/old/2020-unknown-date/pieces.h b/old/2020-unknown-date/pieces.h
deleted file mode 100644
index dbdd740..0000000
--- a/old/2020-unknown-date/pieces.h
+++ /dev/null
@@ -1,59 +0,0 @@
1/* Moves and other things */
2
3#ifndef PIECES_H
4#define PIECES_H
5
6typedef enum {
7 U, U2, U3, D, D2, D3, R, R2, R3, L, L2, L3, F, F2, F3, B, B2, B3,
8 Uw, Uw2, Uw3, Dw, Dw2, Dw3, Rw, Rw2, Rw3,
9 Lw, Lw2, Lw3, Fw, Fw2, Fw3, Bw, Bw2, Bw3,
10 M, M2, M3, S, S2, S3, E, E2, E3,
11 X, X2, X3, Y, Y2, Y3, Z, Z2, Z3,
12 NULLMOVE
13} Move;
14typedef enum {
15 U_center, D_center, R_center, L_center, F_center, B_center
16} Center;
17typedef enum { UF, UL, UB, UR, DF, DL, DB, DR, FR, FL, BL, BR } Edge;
18typedef enum { UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR } Corner;
19
20/* Arrays for strings of pieces and moves */
21extern char edge_string[12][5];
22extern char corner_string[8][5];
23extern char center_string[6][5];
24extern char move_string[NULLMOVE+1][5];
25
26/* Three big arrays that determine the movement of edges, corners and
27 * centers for some of the basic moves. Yes, one can be much more elegant and
28 * write much fewer lines. But then things get less elegant somewhere else. */
29extern int edge_cycle[NULLMOVE+1][12];
30extern int corner_cycle[NULLMOVE+1][8];
31extern int center_cycle[NULLMOVE+1][6];
32
33/* Representation of the cube */
34typedef struct {
35 /* Edge orientation */
36 int eofb;
37 int eorl;
38 int eoud;
39
40 /* Corner orientation */
41 int coud;
42 int cofb;
43 int corl;
44
45 /* Position of M/E/S slice edges */
46 /* TODO: keep in mind that the 4! positions with edges in correct slice
47 * must be the first 4! indeces */
48 int epose;
49 int eposs;
50 int eposm;
51
52 /* Permutation of corners */
53 int cp;
54
55 /* Position of centers */
56 int centerpos;
57} Cube;
58
59#endif

Generated with cgit - Back to sebastiano.tronto.net