aboutsummaryrefslogtreecommitdiff
path: root/old/2020-unknown-date/cube_backup.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 22:05:00 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 22:05:00 +0100
commit4fb67201414169a2687f41c4056b2e284b4938cb (patch)
treea68246e3e21435229541f83f485ab41cfb2ba08a /old/2020-unknown-date/cube_backup.c
parent3568412f8f230774d0d11d7ed1c897424f95d3ef (diff)
downloadnissy-4fb67201414169a2687f41c4056b2e284b4938cb.tar.gz
nissy-4fb67201414169a2687f41c4056b2e284b4938cb.zip
Removed old files
Diffstat (limited to 'old/2020-unknown-date/cube_backup.c')
-rw-r--r--old/2020-unknown-date/cube_backup.c527
1 files changed, 0 insertions, 527 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}

Generated with cgit - Back to sebastiano.tronto.net