From 3568412f8f230774d0d11d7ed1c897424f95d3ef Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 11 Nov 2021 21:37:34 +0100 Subject: Rewritten from scratch. Welocme nissy 2.0! --- old/2020-unknown-date/cube_backup.c | 527 ++++++++++++++++++++++++++++++++++++ old/2020-unknown-date/cubeutils.c | 100 +++++++ old/2020-unknown-date/cubeutils.h | 18 ++ old/2020-unknown-date/moves.c | 57 ++++ old/2020-unknown-date/moves.h | 9 + old/2020-unknown-date/pieces.c | 208 ++++++++++++++ old/2020-unknown-date/pieces.h | 59 ++++ 7 files changed, 978 insertions(+) create mode 100644 old/2020-unknown-date/cube_backup.c create mode 100644 old/2020-unknown-date/cubeutils.c create mode 100644 old/2020-unknown-date/cubeutils.h create mode 100644 old/2020-unknown-date/moves.c create mode 100644 old/2020-unknown-date/moves.h create mode 100644 old/2020-unknown-date/pieces.c create mode 100644 old/2020-unknown-date/pieces.h (limited to 'old/2020-unknown-date') diff --git a/old/2020-unknown-date/cube_backup.c b/old/2020-unknown-date/cube_backup.c new file mode 100644 index 0000000..e049edd --- /dev/null +++ b/old/2020-unknown-date/cube_backup.c @@ -0,0 +1,527 @@ +#include +#include +#include "cube.h" + +/* The next few functions are used to convert from the Cube structure + * representation to actual arrays of pieces. */ +void cube_to_ep_array(Cube cube, int ep[12]); +void cube_to_eofb_array(Cube cube, int eo[12]); +void cube_to_eorl_array(Cube cube, int eo[12]); +void cube_to_eoud_array(Cube cube, int eo[12]); +void cube_to_cp_array(Cube cube, int cp[8]); +void cube_to_coud_array(Cube cube, int co[8]); +void cube_to_cofb_array(Cube cube, int co[8]); +void cube_to_corl_array(Cube cube, int co[8]); +void cube_to_centerpos_array(Cube cube, int centerpos[6]); +Cube ep_array_to_cube(int ep[12]); +Cube eofb_array_to_cube(int eo[12]); +Cube eorl_array_to_cube(int eo[12]); +Cube eoud_array_to_cube(int eo[12]); +Cube cp_array_to_cube(int cp[8]); +Cube coud_array_to_cube(int co[8]); +Cube cofb_array_to_cube(int co[8]); +Cube corl_array_to_cube(int co[8]); +Cube centerpos_array_to_cube(int centerpos[6]); +Cube move_array(Cube cube, void (cube_to_arr)(Cube, int *), + Cube (*arr_to_cube)(int *), + int *perm, int *orient, int n, int m); + + +/* Transition tables */ +int epose_ttable[NMOVES][factorial12/factorial8]; +int eposs_ttable[NMOVES][factorial12/factorial8]; +int eposm_ttable[NMOVES][factorial12/factorial8]; +int eofb_ttable[NMOVES][pow2to11]; +int eorl_ttable[NMOVES][pow2to11]; +int eoud_ttable[NMOVES][pow2to11]; +int cp_ttable[NMOVES][factorial8]; +int coud_ttable[NMOVES][pow3to7]; +int cofb_ttable[NMOVES][pow3to7]; +int corl_ttable[NMOVES][pow3to7]; +int centerpos_ttable[NMOVES][factorial6]; + +char edge_string[12][5] = { + "UF", "UL", "UB", "UR", "DF", "DL", "DB", "DR", "FR", "FL", "BL", "BR" +}; +char corner_string[8][5] = { "UFR", "UFL", "UBL", "UBR", "DFR", "DFL", "DBL", "DBR" }; +char center_string[6][5] = { "U", "D", "R", "L", "F", "B" }; +char move_string[NMOVES][5] = { + "-", + "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'", + "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'", + "Uw", "Uw2", "Uw\'", "Dw", "Dw2", "Dw\'", "Rw", "Rw2", "Rw\'", + "Lw", "Lw2", "Lw\'", "Fw", "Fw2", "Fw\'", "Bw", "Bw2", "Bw\'", + "M", "M2", "M\'", "S", "S2", "S\'", "E", "E2", "E\'", + "x", "x2", "x\'", "y", "y2", "y\'", "z", "z2", "z\'", +}; + +int epe_solved[] = {FR, FL, BL, BR}; +int eps_solved[] = {UL, UR, DL, DR}; +int epm_solved[] = {UF, UB, DF, DB}; + +/**************************/ +/* Internal use functions */ +/**************************/ + +int cube_to_ep_array(Cube cube, int ep[12]) { + int epe[4], eps[4], epm[4]; + index_to_perm(cube.epose % factorial(4), 4, epe); + index_to_perm(cube.eposs % factorial(4), 4, eps); + index_to_perm(cube.eposm % factorial(4), 4, epm); + + int epose[12], eposs[12], eposm[12]; + index_to_subset(cube.epose / factorial(4), 12, 4, epose); + index_to_subset(cube.eposs / factorial(4), 12, 4, eposs); + index_to_subset(cube.eposm / factorial(4), 12, 4, eposm); + for (int i = 0; i < 4; i++) { + swap(&eposs[eps_solved[i]], &eposs[i+8]); + swap(&eposm[epm_solved[i]], &eposm[i+8]); + } + + for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) { + if (epose[i]) ep[i] = epe_solved[epe[ie++]]; + if (eposs[i]) ep[i] = eps_solved[eps[is++]]; + if (eposm[i]) ep[i] = epm_solved[epm[im++]]; + } +} + +void cube_to_eofb_array(Cube cube, int eo[12]) { + int_to_sum_zero_array(cube.eofb, 2, 12, eo); +} + +void cube_to_eorl_array(Cube cube, int eo[12]) { + int_to_sum_zero_array(cube.eorl, 2, 12, eo); +} + +void cube_to_eoud_array(Cube cube, int eo[12]) { + int_to_sum_zero_array(cube.eoud, 2, 12, eo); +} + +void cube_to_cp_array(Cube cube, int cp[8]) { + index_to_perm(cube.cp, 8, cp); +} + +void cube_to_coud_array(Cube cube, int co[8]) { + int_to_sum_zero_array(cube.coud, 3, 8, co); +} + +void cube_to_cofb_array(Cube cube, int co[8]) { + int_to_sum_zero_array(cube.cofb, 3, 8, co); +} + +void cube_to_corl_array(Cube cube, int co[8]) { + int_to_sum_zero_array(cube.corl, 3, 8, co); +} + +void cube_to_centerpos_array(Cube cube, int centerpos[6]) { + index_to_perm(cube.centerpos, 6, centerpos); +} + +Cube ep_array_to_cube(int ep[12]) { + int epe[4], eps[4], epm[4]; + int epose[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int eposs[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int eposm[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) { + for (int j = 0; j < 4; j++) { + if (ep[i] == epe_solved[j]) { epe[ie++] = j; epose[i] = 1; } + if (ep[i] == eps_solved[j]) { eps[is++] = j; eposs[i] = 1; } + if (ep[i] == epm_solved[j]) { epm[im++] = j; eposm[i] = 1; } + } + } + for (int i = 0; i < 4; i++) { + swap(&eposs[eps_solved[i]], &eposs[i+8]); + swap(&eposm[epm_solved[i]], &eposm[i+8]); + } + return { .epose = factorial(4) * subset_to_index(epose, 12, 4) + + perm_to_index(epe, 4), + .eposs = factorial(4) * subset_to_index(eposs, 12, 4) + + perm_to_index(eps, 4), + .eposm = factorial(4) * subset_to_index(eposm, 12, 4) + + perm_to_index(epm, 4) }; +} + +Cube eofb_array_to_cube(int eo[12]) { + return { .eofb = digit_array_to_int(eo, 11, 2) }; +} + +Cube eorl_array_to_cube(int eo[12]) { + return { .eorl = digit_array_to_int(eo, 11, 2) }; +} + +Cube eoud_array_to_cube(int eo[12]) { + return { .eoud = digit_array_to_int(eo, 11, 2) }; +} + +Cube cp_array_to_cube(int cp[8]) { + return { .cp = perm_to_index(cp, 8) }; +} + +Cube coud_array_to_cube(int co[8]) { + return { .coud = digit_array_to_int(co, 7, 3) }; +} + +Cube cofb_array_to_cube(int co[8]) { + return { .cofb = digit_array_to_int(co, 7, 3) }; +} + +Cube corl_array_to_cube(int co[8]) { + return { .corl = digit_array_to_int(co, 7, 3) }; +} + +Cube centerpos_array_to_cube(int centerpos[6]) { + return { .centerpos = perm_to_index(centerpos, 6) }; +} + +Cube move_array(Cube cube, void (*cube_to_arr)(Cube, int *), + void (*arr_to_cube)(int *), + int *perm, int *orient, int n, int m) { + int arr[n]; + cube_to_arr(cube, arr); + apply_permutation(perm, arr, n); + sum_arrays_mod(arr, orient, n, m); + return arr_to_cube(arr); +} + +/***********************/ +/* Interface functions */ +/***********************/ + +Move inverse(Move m) { + if (m == NULLMOVE) + return m; + int mod = (m-1)%3; + Move base = m - mod; + return base + 2 - mod; +} + +void copy_alg(NissMove *src, NissMove *dest) { + for (int i = 0; src[i].m != NULLMOVE; i++) + dest[i] = src[i]; +} + +bool commute(Move m1, Move m2) { + return equal(apply_move(m2, apply_move(m1, {0})), + apply_move(m1, apply_move(m2, {0}))); +} + +bool equal(Cube c1, Cube c2) { + return c1.eofb == c2.eofb && c1.epose == c2.epose && + c1.eposs == c2.eposs && c1.eposm == c2.eposm && + c1.coud == c2.coud && c1.cp == c2.cp && + c1.centerpos == c2.centerpos; +} + +bool solvable(Cube cube) { + /* Since we memorize orientation truncating the last digit, we only need to + * check that the permutations have the correct sign. */ + /* TODO: add check that every integer is in range */ + int ep[12], cp[12], c[6]; + /* TODO: change to use cube-specific functions */ + cube_to_ep_array(cube, ep); + cube_to_cp_array(cube, 8, cp); + cube_to_centerpos_array(cube, 6, c); + return (perm_sign(ep, 12) ^ perm_sign(c, 6)) == perm_sign(cp, 8); +} + +bool is_solved(Cube cube) { + return (!cube.eofb && !cube.coud && !cube.cp && + !cube.epose && !cube.eposs && !cube.eposm && !cube.centerpos); +} + +char *to_string(Cube cube) { + int eo[12], co[8], ep[12], cp[8], cenpos[6]; + cube_to_eofb_array(cube, eo); + cube_to_coud_array(cube, co); + cube_to_ep_array(cube, ep); + cube_to_cp_array(cube, cp); + cube_to_centerpos_array(cube, cenpos); + + static char ret[1000]; + + for (int i = 0; i < 12; i++) { + strcat(ret, " "); + strcat(ret, edge_string[ep[i]]); + strcat(ret, " "); + } + strcat(ret, "\n"); + for (int i = 0; i < 12; i++) { + strcat(ret, " "); + char num[2] = { [0] = eo[i] + '0', [1] = 0 }; + strcat(ret, num); + strcat(ret, " "); + } + strcat(ret, "\n"); + for (int i = 0; i < 8; i++) { + strcat(ret, corner_string[cp[i]]); + strcat(ret, " "); + } + strcat(ret, "\n"); + for (int i = 0; i < 8; i++) { + strcat(ret, " "); + char num[2] = { [0] = co[i] + '0', [1] = 0 }; + strcat(ret, num); + strcat(ret, " "); + } + strcat(ret, "\n"); + for (int i = 0; i < 6; i++) { + strcat(ret, " "); + strcat(ret, center_string[cenpos[i]]); + strcat(ret, " "); + } + strcat(ret, "\n"); + + return ret; +} + +void init_ttables() { + FILE *ttf; + + if ((ttf = fopen("ttables", "rb")) != NULL) { + for (int m = 0; m < NMOVES; m++) { + fread(epose_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fread(eposs_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fread(eposm_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fread(eofb_ttable[m], sizeof(int), pow2to11, ttf); + fread(eorl_ttable[m], sizeof(int), pow2to11, ttf); + fread(eoud_ttable[m], sizeof(int), pow2to11, ttf); + fread(cp_ttable[m], sizeof(int), factorial8, ttf); + fread(coud_ttable[m], sizeof(int), pow3to7, ttf); + fread(corl_ttable[m], sizeof(int), pow3to7, ttf); + fread(cofb_ttable[m], sizeof(int), pow3to7, ttf); + fread(centerpos_ttable[m], sizeof(int), factorial6, ttf); + } + fclose(ttf); + } else { + ttf = fopen("ttables", "wb"); + int empty[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; + /* For each type of pieces only the effects of U, x and y are described */ + int edge_cycle[NMOVES][12] = { + [U] = {UR, UF, UL, UB, DF, DL, DB, DR, FR, FL, BL, BR}, + [X] = {DF, FL, UF, FR, DB, BL, UB, BR, DR, DL, UL, UR}, + [Y] = {UR, UF, UL, UB, DR, DF, DL, DB, BR, FR, FL, BL}, + }; + int eofb_flipped[NMOVES][12] = { + [X] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 }, + [Y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 }, + }; + int eorl_flipped[NMOVES][12] = { + [X] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + [Y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 }, + }; + int eoud_flipped[NMOVES][12] = { + [U] = { [UF] = 1, [UL] = 1, [UB] = 1, [UR] = 1 }, + [X] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 }, + [Y] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + }; + int corner_cycle[NMOVES][8] = { + [U] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR}, + [X] = {DFR, DFL, UFL, UFR, DBR, DBL, UBL, UBR}, + [Y] = {UBR, UFR, UFL, UBL, DBR, DFR, DFL, DBL}, + }; + int coud_flipped[NMOVES][8] = { + [X] = {[UFR]=2,[UBR]=1,[DBR]=2,[DFR]=1,[UFL]=1,[UBL]=2,[DBL]=1,[DFL]=2}, + }; + int corl_flipped[NMOVES][8] = { + [U] = { [UFR] = 1, [UBR] = 2, [UBL] = 1, [UFL] = 2 }, + [Y] = {[UFR]=1,[UBR]=2,[UBL]=1,[UFL]=2,[DFR]=2,[DBR]=1,[DBL]=2,[DFL]=1}, + }; + int cofb_flipped[NMOVES][8] = { + [U] = { [UFR] = 2, [UBR] = 1, [UBL] = 2, [UFL] = 1 }, + [X] = {[UFR]=1,[UBR]=2,[DFR]=2,[DBR]=1,[UBL]=2,[UFL]=1,[DBL]=1,[DFL]=2}, + [Y] = {[UFR]=2,[UBR]=1,[UBL]=2,[UFL]=1,[DFR]=1,[DBR]=2,[DBL]=1,[DFL]=2}, + }; + int center_cycle[NMOVES][6] = { + [X] = {F_center, B_center, R_center, L_center, D_center, U_center}, + [Y] = {U_center, D_center, B_center, F_center, R_center, L_center}, + }; + + /* Each move is reduced to a combination of U, x and y using this table */ + Move equiv_moves[NMOVES][13] = { + [U] = { U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [U2] = { U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [U3] = { U, U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [D] = { X, X, U, X, X, 0, 0, 0, 0, 0, 0, 0, 0 }, + [D2] = { X, X, U, U, X, X, 0, 0, 0, 0, 0, 0, 0 }, + [D3] = { X, X, U, U, U, X, X, 0, 0, 0, 0, 0, 0 }, + [R] = { Y, X, U, X, X, X, Y, Y, Y, 0, 0, 0, 0 }, + [R2] = { Y, X, U, U, X, X, X, Y, Y, Y, 0, 0, 0 }, + [R3] = { Y, X, U, U, U, X, X, X, Y, Y, Y, 0, 0 }, + [L] = { Y, Y, Y, X, U, X, X, X, Y, 0, 0, 0, 0 }, + [L2] = { Y, Y, Y, X, U, U, X, X, X, Y, 0, 0, 0 }, + [L3] = { Y, Y, Y, X, U, U, U, X, X, X, Y, 0, 0 }, + [F] = { X, U, X, X, X, 0, 0, 0, 0, 0, 0, 0, 0 }, + [F2] = { X, U, U, X, X, X, 0, 0, 0, 0, 0, 0, 0 }, + [F3] = { X, U, U, U, X, X, X, 0, 0, 0, 0, 0, 0 }, + [B] = { X, X, X, U, X, 0, 0, 0, 0, 0, 0, 0, 0 }, + [B2] = { X, X, X, U, U, X, 0, 0, 0, 0, 0, 0, 0 }, + [B3] = { X, X, X, U, U, U, X, 0, 0, 0, 0, 0, 0 }, + + [Uw] = { X, X, U, X, X, Y, 0, 0, 0, 0, 0, 0, 0 }, + [Uw2] = { X, X, U, U, X, X, Y, Y, 0, 0, 0, 0, 0 }, + [Uw3] = { X, X, U, U, U, X, X, Y, Y, Y, 0, 0, 0 }, + [Dw] = { U, Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Dw2] = { U, U, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Dw3] = { U, U, U, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Rw] = { Y, Y, Y, X, U, X, X, X, Y, X, 0, 0, 0 }, + [Rw2] = { Y, Y, Y, X, U, U, X, X, X, Y, X, X, 0 }, + [Rw3] = { Y, Y, Y, X, U, U, U, Y, X, X, X, Y, 0 }, + [Lw] = { Y, X, U, X, X, X, Y, Y, Y, X, X, X, 0 }, + [Lw2] = { Y, X, U, U, X, X, X, Y, Y, Y, X, X, 0 }, + [Lw3] = { Y, X, U, U, U, X, X, X, Y, Y, Y, X, 0 }, + [Fw] = { X, X, X, U, Y, Y, Y, X, 0, 0, 0, 0, 0 }, + [Fw2] = { X, X, X, U, U, Y, Y, X, 0, 0, 0, 0, 0 }, + [Fw3] = { X, X, X, U, U, U, Y, X, 0, 0, 0, 0, 0 }, + [Bw] = { X, U, Y, Y, Y, X, X, X, 0, 0, 0, 0, 0 }, + [Bw2] = { X, U, U, Y, Y, X, X, X, 0, 0, 0, 0, 0 }, + [Bw3] = { X, U, U, U, Y, X, X, X, 0, 0, 0, 0, 0 }, + + [M] = { Y, X, U, X, X, U, U, U, Y, X, Y, Y, Y }, + [M2] = { Y, X, U, U, X, X, U, U, X, X, X, Y, 0 }, + [M3] = { Y, X, U, U, U, X, X, U, Y, X, X, X, Y }, + [S] = { X, U, U, U, X, X, U, Y, Y, Y, X, 0, 0 }, + [S2] = { X, U, U, X, X, U, U, Y, Y, X, 0, 0, 0 }, + [S3] = { X, U, X, X, U, U, U, Y, X, 0, 0, 0, 0 }, + [E] = { U, X, X, U, U, U, X, X, Y, Y, Y, 0, 0 }, + [E2] = { U, U, X, X, U, U, X, X, Y, Y, 0, 0, 0 }, + [E3] = { U, U, U, X, X, U, X, X, Y, 0, 0, 0, 0 }, + + [X] = { X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [X2] = { X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [X3] = { X, X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Y] = { Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Y2] = { Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Y3] = { Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Z] = { Y, Y, Y, X, Y, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Z2] = { Y, Y, X, X, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + [Z3] = { Y, X, Y, Y, Y, 0, 0, 0, 0, 0, 0, 0, 0 }, + }; + + /* Generate all move cycles and flips */ + for (int i = 0; i < NMOVES; i++) { + if (i == U || i == X || i == Y) + continue; + + Cube cube = {0}; + + cube_to_ep_array(&cube, edge_cycle[i]); + cube_to_eofb_array(&cube, eofb_flipped[i]); + cube_to_eorl_array(&cube, eorl_flipped[i]); + cube_to_eoud_array(&cube, eoud_flipped[i]); + cube_to_cp_array(&cube, corner_cycle[i]); + cube_to_coud_array(&cube, coud_flipped[i]); + cube_to_cofb_array(&cube, cofb_flipped[i]); + cube_to_corl_array(&cube, corl_flipped[i]); + cube_to_centerpos_array(&cube, center_cycle[i]); + + for (int j = 0; equiv_moves[i][j]; j++) { + int m = equiv_moves[i][j]; + + apply_permutation(edge_cycle[m], edge_cycle[i], 12); + apply_permutation(edge_cycle[m], eofb_flipped[i], 12); + apply_permutation(edge_cycle[m], eorl_flipped[i], 12); + apply_permutation(edge_cycle[m], eoud_flipped[i], 12); + + sum_arrays_mod(eofb_flipped[i], eofb_flipped[m], 12, 2); + sum_arrays_mod(eorl_flipped[i], eorl_flipped[m], 12, 2); + sum_arrays_mod(eoud_flipped[i], eoud_flipped[m], 12, 2); + + apply_permutation(corner_cycle[m], corner_cycle[i], 8); + apply_permutation(corner_cycle[m], coud_flipped[i], 8); + apply_permutation(corner_cycle[m], cofb_flipped[i], 8); + apply_permutation(corner_cycle[m], corl_flipped[i], 8); + + sum_arrays_mod(coud_flipped[i], coud_flipped[m], 8, 3); + sum_arrays_mod(corl_flipped[i], corl_flipped[m], 8, 3); + sum_arrays_mod(cofb_flipped[i], cofb_flipped[m], 8, 3); + + apply_permutation(center_cycle[m], center_cycle[i], 6); + } + } + + /* Initialize transition tables */ + for (int m = 0; m < NMOVES; m++) { + for (int i = 0; i < factorial12/factorial8; i++) { + Cube cube = { .epose = i }; + move_array(&cube, cube_to_ep_array, ep_array_to_cube, + edge_cycle[m], empty, 12, 1); + epose_ttable[m][i] = cube.epose; + cube.eposs = i; + move_array(&cube, cube_to_ep_array, ep_array_to_cube, + edge_cycle[m], empty, 12, 1); + eposs_ttable[m][i] = cube.eposs; + cube.eposm = i; + move_array(&cube, cube_to_ep_array, ep_array_to_cube, + edge_cycle[m], empty, 12, 1); + eposm_ttable[m][i] = cube.eposm; + } + for (int i = 0; i < pow2to11; i++ ) { + Cube cube = { .eofb = i, .eorl = i, .eoud = i }; + move_array(&cube, cube_to_eofb_array, eofb_array_to_cube, + edge_cycle[m], eofb_flipped[m], 12, 2); + move_array(&cube, cube_to_eorl_array, eorl_array_to_cube, + edge_cycle[m], eorl_flipped[m], 12, 2); + move_array(&cube, cube_to_eoud_array, eoud_array_to_cube, + edge_cycle[m], eoud_flipped[m], 12, 2); + eofb_ttable[m][i] = cube.eofb; + eorl_ttable[m][i] = cube.eorl; + eoud_ttable[m][i] = cube.eoud; + } + for (int i = 0; i < factorial8; i++) { + /* TODO: Maybe do this by hand to optimize? */ + Cube cube = { .cp = i }; + move_array(&cube, cube_to_cp_array, ep_array_to_cube, + corner_cycle[m], empty, 8, 1); + cp_ttable[m][i] = cube.cp; + } + for (int i = 0; i < pow3to7; i++) { + Cube cube = { .coud = i, .corl = i, .cofb = i }; + move_array(&cube, cube_to_coud_array, coud_array_to_cube, + corner_cycle[m], coud_flipped[m], 8, 3); + move_array(&cube, cube_to_corl_array, corl_array_to_cube, + corner_cycle[m], corl_flipped[m], 8, 3); + move_array(&cube, cube_to_cofb_array, cofb_array_to_cube, + corner_cycle[m], cofb_flipped[m], 8, 3); + coud_ttable[m][i] = cube.coud; + corl_ttable[m][i] = cube.corl; + cofb_ttable[m][i] = cube.cofb; + } + for (int i = 0; i < factorial6; i++) { + Cube cube = { .centerpos = i }; + move_array(&cube, cube_to_centerpos_array, centerpos_array_to_cube, + center_cycle[m], empty, 6, 1); + centerpos_ttable[m][i] = cube.centerpos; + } + fwrite(epose_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fwrite(eposs_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fwrite(eposm_ttable[m], sizeof(int), factorial12/factorial8, ttf); + fwrite(eofb_ttable[m], sizeof(int), pow2to11, ttf); + fwrite(eorl_ttable[m], sizeof(int), pow2to11, ttf); + fwrite(eoud_ttable[m], sizeof(int), pow2to11, ttf); + fwrite(cp_ttable[m], sizeof(int), factorial8, ttf); + fwrite(coud_ttable[m], sizeof(int), pow3to7, ttf); + fwrite(corl_ttable[m], sizeof(int), pow3to7, ttf); + fwrite(cofb_ttable[m], sizeof(int), pow3to7, ttf); + fwrite(centerpos_ttable[m], sizeof(int), factorial6, ttf); + } + fclose(ttf); + } +} + +Cube apply_move(Move m, Cube cube) { + Cube moved = cube; + + moved.eofb = eofb_ttable[m][cube.eofb]; + moved.eorl = eorl_ttable[m][cube.eorl]; + moved.eoud = eoud_ttable[m][cube.eoud]; + moved.coud = coud_ttable[m][cube.coud]; + moved.cofb = cofb_ttable[m][cube.cofb]; + moved.corl = corl_ttable[m][cube.corl]; + moved.epose = epose_ttable[m][cube.epose]; + moved.eposs = eposs_ttable[m][cube.eposs]; + moved.eposm = eposm_ttable[m][cube.eposm]; + moved.cp = cp_ttable[m][cube.cp]; + moved.centerpos = centerpos_ttable[m][cube.centerpos]; + + return moved; +} diff --git a/old/2020-unknown-date/cubeutils.c b/old/2020-unknown-date/cubeutils.c new file mode 100644 index 0000000..4f0a060 --- /dev/null +++ b/old/2020-unknown-date/cubeutils.c @@ -0,0 +1,100 @@ +#include +#include "utils.h" +#include "pieces.h" +#include "cubeutils.h" + +int epe_solved[] = {FR, FL, BL, BR}; +int eps_solved[] = {UL, UR, DL, DR}; +int epm_solved[] = {UF, UB, DF, DB}; + +void cube_to_ep_array(Cube *cube, int ep[12]) { + int epe[4], eps[4], epm[4]; + index_to_perm(cube->epose % factorial(4), 4, epe); + index_to_perm(cube->eposs % factorial(4), 4, eps); + index_to_perm(cube->eposm % factorial(4), 4, epm); + + int epose[12], eposs[12], eposm[12]; + index_to_subset(cube->epose / factorial(4), 12, 4, epose); + index_to_subset(cube->eposs / factorial(4), 12, 4, eposs); + index_to_subset(cube->eposm / factorial(4), 12, 4, eposm); + for (int i = 0; i < 4; i++) { + swap(&eposs[eps_solved[i]], &eposs[i+8]); + swap(&eposm[epm_solved[i]], &eposm[i+8]); + } + + for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) { + if (epose[i]) ep[i] = epe_solved[epe[ie++]]; + if (eposs[i]) ep[i] = eps_solved[eps[is++]]; + if (eposm[i]) ep[i] = epm_solved[epm[im++]]; + } +} + +void ep_array_to_epos(int ep[12], Cube *cube) { + int epe[4], eps[4], epm[4]; + int epose[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int eposs[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int eposm[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + for (int i = 0, ie = 0, is = 0, im = 0; i < 12; i++) { + for (int j = 0; j < 4; j++) { + if (ep[i] == epe_solved[j]) { epe[ie++] = j; epose[i] = 1; } + if (ep[i] == eps_solved[j]) { eps[is++] = j; eposs[i] = 1; } + if (ep[i] == epm_solved[j]) { epm[im++] = j; eposm[i] = 1; } + } + } + for (int i = 0; i < 4; i++) { + swap(&eposs[eps_solved[i]], &eposs[i+8]); + swap(&eposm[epm_solved[i]], &eposm[i+8]); + } + cube->epose = factorial(4) * subset_to_index(epose, 12, 4) + + perm_to_index(epe, 4); + cube->eposs = factorial(4) * subset_to_index(eposs, 12, 4) + + perm_to_index(eps, 4); + cube->eposm = factorial(4) * subset_to_index(eposm, 12, 4) + + perm_to_index(epm, 4); +} + +bool solvable(Cube *cube) { + /* Since we memorize orientation truncating the last digit, we only need to + * check that the permutations have the correct sign. */ + /* TODO: add check that every integer is in range */ + int ep[12], cp[12], c[6]; + cube_to_ep_array(cube, ep); + index_to_perm(cube->cp, 8, cp); + index_to_perm(cube->centerpos, 6, c); + return (perm_sign(ep, 12) ^ perm_sign(c, 6)) == perm_sign(cp, 8); +} + +Cube *solved_cube() { + static Cube cube = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + return &cube; +} + +bool solved(Cube *cube) { + return (cube->eofb == 0 && cube->coud == 0 && cube->cp == 0 && + cube->epose == 0 && cube->eposs == 0 && cube->eposm == 0 && + cube->centerpos == 0); +} + +char *to_string(Cube *cube) { + int eo[12], co[8], ep[12], cp[8], cenpos[6]; + cube_to_eofb_array(cube->eofb, eo); + cube_to_coud_array(cube->coud, co); + cube_to_ep_array(cube, ep); + cube_to_cp_array(cube->cp, cp); + cube_to_centerpos_array(cube->centerpos, cenpos); + + char *ret[1000]; + + for (int i = 0; i < 12; i++) sprintf(ret, " %s ", edge_string[ep[i]]); + sprintf(ret, "\n"); + for (int i = 0; i < 12; i++) sprintf(ret, " %d ", eo[i]); + sprintf(ret, "\n"); + for (int i = 0; i < 8; i++) sprintf(ret, "%s ", corner_string[cp[i]]); + sprintf(ret, "\n"); + for (int i = 0; i < 8; i++) sprintf(ret, " %d ", co[i]); + sprintf(ret, "\n"); + for (int i = 0; i < 6; i++) sprintf(ret, " %s ", center_string[cenpos[i]]); + sprintf(ret, "\n"); + + return ret; +} diff --git a/old/2020-unknown-date/cubeutils.h b/old/2020-unknown-date/cubeutils.h new file mode 100644 index 0000000..b24291c --- /dev/null +++ b/old/2020-unknown-date/cubeutils.h @@ -0,0 +1,18 @@ +/* Cube-specific utility functions */ + +#ifndef CUBEUTILS_H +#define CUBEUTILS_H + +#include +#include "pieces.h" + +void cube_to_ep_array(Cube *cube, int ep[12]); +void ep_array_to_epos(int ep[12], Cube *cube); + +Cube *solved_cube(); +bool solvable(Cube *cube); +bool solved(Cube *cube); + +void print(Cube *cube); + +#endif diff --git a/old/2020-unknown-date/moves.c b/old/2020-unknown-date/moves.c new file mode 100644 index 0000000..de293ed --- /dev/null +++ b/old/2020-unknown-date/moves.c @@ -0,0 +1,57 @@ +#include +#include "pieces.h" +#include "moves.h" +#include "utils.h" + +/* Transition tables */ +int eofb_ttable[pow2to11][NULLMOVE]; +int eorl_ttable[pow2to11][NULLMOVE]; +int eoud_ttable[pow2to11][NULLMOVE]; +int coud_ttable[pow3to7][NULLMOVE]; +int cofb_ttable[pow3to7][NULLMOVE]; +int corl_ttable[pow3to7][NULLMOVE]; +int epose_ttable[factorial12/factorial8][NULLMOVE]; +int eposs_ttable[factorial12/factorial8][NULLMOVE]; +int eposm_ttable[factorial12/factorial8][NULLMOVE]; +int cp_ttable[factorial8][NULLMOVE]; +int centerpos_ttable[factorial6][NULLMOVE]; + +void apply_move_ep(Move m, int a[12]) { + int aux[12]; + intarrcopy(a, aux, 12); + for (int i = 0; i < 12; i++) + a[i] = aux[edge_cycle[m][i]]; +} + +void apply_move_cp(Move m, int a[8]) { + int aux[8]; + intarrcopy(a, aux, 8); + for (int i = 0; i < 8; i++) + a[i] = aux[corner_cycle[m][i]]; +} + +void apply_move_centerpos(Move m, int a[6]) { + int aux[6]; + intarrcopy(a, aux, 6); + for (int i = 0; i < 6; i++) + a[i] = aux[center_cycle[m][i]]; +} + +void init_ttables() { + /* TODO */ +} + +void apply_move(Move m, Cube *cube) { + cube->eofb = eofb_ttable[cube->eofb][m]; + cube->eorl = eorl_ttable[cube->eorl][m]; + cube->eoud = eoud_ttable[cube->eoud][m]; + cube->coud = coud_ttable[cube->coud][m]; + cube->cofb = cofb_ttable[cube->cofb][m]; + cube->corl = corl_ttable[cube->corl][m]; + cube->epose = epose_ttable[cube->epose][m]; + cube->eposs = eposs_ttable[cube->eposs][m]; + cube->eposm = eposm_ttable[cube->eposm][m]; + cube->cp = cp_ttable[cube->cp][m]; + cube->centerpos = centerpos_ttable[cube->centerpos][m]; +} + diff --git a/old/2020-unknown-date/moves.h b/old/2020-unknown-date/moves.h new file mode 100644 index 0000000..605f335 --- /dev/null +++ b/old/2020-unknown-date/moves.h @@ -0,0 +1,9 @@ +/* Moves and transition tables */ + +#ifndef MOVES_H +#define MOVES_H + +void apply_move(Move m, Cube *cube); +void init_ttables(); + +#endif diff --git a/old/2020-unknown-date/pieces.c b/old/2020-unknown-date/pieces.c new file mode 100644 index 0000000..d782c89 --- /dev/null +++ b/old/2020-unknown-date/pieces.c @@ -0,0 +1,208 @@ +#include "pieces.h" + +char edge_string[12][5] = { + "UF", "UL", "UB", "UR", "DF", "DL", "DB", "DR", "FR", "FL", "BL", "BR" +}; + +char corner_string[8][5] = { + "UFR", "UFL", "UBL", "UBR", "DFR", "DFL", "DBL", "DBR" +}; + +char center_string[6][5] = { "U", "D", "R", "L", "F", "B" }; + +char move_string[NULLMOVE+1][5] = { + "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'", + "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'", + "Uw", "Uw2", "Uw\'", "Dw", "Dw2", "Dw\'", "Rw", "Rw2", "Rw\'", + "Lw", "Lw2", "Lw\'", "Fw", "Fw2", "Fw\'", "Bw", "Bw2", "Bw\'", + "M", "M2", "M\'", "S", "S2", "S\'", "E", "E2", "E\'", + "x", "x2", "x\'", "y", "y2", "y\'", "z", "z2", "z\'", + "-" +}; + +int edge_cycle[NULLMOVE+1][12] = { + [U] = {UR, UF, UL, UB, DF, DL, DB, DR, FR, FL, BL, BR}, + [U2] = {UB, UR, UF, UL, DF, DL, DB, DR, FR, FL, BL, BR}, + [U3] = {UL, UB, UR, UF, DF, DL, DB, DR, FR, FL, BL, BR}, + [D] = {UF, UL, UB, UR, DL, DB, DR, DF, FR, FL, BL, BR}, + [D2] = {UF, UL, UB, UR, DB, DR, DF, DL, FR, FL, BL, BR}, + [D3] = {UF, UL, UB, UR, DR, DF, DL, DB, FR, FL, BL, BR}, + [R] = {UF, UL, UB, FR, DF, DL, DB, BR, DR, FL, BL, UR}, + [R2] = {UF, UL, UB, DR, DF, DL, DB, UR, BR, FL, BL, FR}, + [R3] = {UF, UL, UB, BR, DF, DL, DB, FR, UR, FL, BL, DR}, + [L] = {UF, BL, UB, UR, DF, FL, DB, DR, FR, UL, DL, BR}, + [L2] = {UF, DL, UB, UR, DF, UL, DB, DR, FR, BL, FL, BR}, + [L3] = {UF, FL, UB, UR, DF, BL, DB, DR, FR, DL, UL, BR}, + [F] = {FL, UL, UB, UR, FR, DL, DB, DR, UF, DF, BL, BR}, + [F2] = {DF, UL, UB, UR, UF, DL, DB, DR, FL, FR, BL, BR}, + [F3] = {FR, UL, UB, UR, FL, DL, DB, DR, DF, UF, BL, BR}, + [B] = {UF, UL, BR, UR, DF, DL, BL, DR, FR, FL, UB, DB}, + [B2] = {UF, UL, DB, UR, DF, DL, UB, DR, FR, FL, BR, BL}, + [B3] = {UF, UL, BL, UR, DF, DL, BR, DR, FR, FL, DB, UB}, + + [Uw] = {UR, UF, UL, UB, DF, DL, DB, DR, BR, FR, FL, BL}, + [Uw2] = {UB, UR, UF, UL, DF, DL, DB, DR, BL, BR, FR, FL}, + [Uw3] = {UL, UB, UR, UF, DF, DL, DB, DR, FL, BL, BR, FR}, + [Dw] = {UF, UL, UB, UR, DL, DB, DR, DF, FL, BL, BR, FR}, + [Dw2] = {UF, UL, UB, UR, DB, DR, DF, DL, BL, BR, FR, FL}, + [Dw3] = {UF, UL, UB, UR, DR, DF, DL, DB, BR, FR, FL, BL}, + [Rw] = {DF, UL, UF, FR, DB, DL, UB, BR, DR, FL, BL, UR}, + [Rw2] = {DB, UL, DF, DR, UB, DL, UF, UR, BR, FL, BL, FR}, + [Rw3] = {UB, UL, DB, BR, UF, DL, DF, FR, UR, FL, BL, DR}, + [Lw] = {UB, BL, DB, UR, UF, FL, DF, DR, FR, UL, DL, BR}, + [Lw2] = {DB, DL, DF, UR, UB, UL, UF, DR, FR, BL, FL, BR}, + [Lw3] = {DF, FL, UF, UR, DB, BL, UB, DR, FR, DL, UL, BR}, + [Fw] = {FL, DL, UB, UL, FR, DR, DB, UR, UF, DF, BL, BR}, + [Fw2] = {DF, DR, UB, DL, UF, UR, DB, UL, FL, FR, BL, BR}, + [Fw3] = {FR, UR, UB, DR, FL, UL, DB, DL, DF, UF, BL, BR}, + [Bw] = {UF, UR, BR, DR, DF, UL, BL, DL, FR, FL, UB, DB}, + [Bw2] = {UF, DR, DB, DL, DF, UR, UB, UL, FR, FL, BR, BL}, + [Bw3] = {UF, DL, BL, UL, DF, DR, BR, UR, FR, FL, DB, UB}, + + [M] = {UB, UL, DB, UR, UF, DL, DF, DR, FR, FL, BL, BR}, + [M2] = {DB, UL, DF, UR, UB, DL, UF, DR, FR, FL, BL, BR}, + [M3] = {DF, UL, UF, UR, DB, DL, UB, DR, FR, FL, BL, BR}, + [S] = {UF, DL, UB, UL, DF, DR, DB, UR, FR, FL, BL, BR}, + [S2] = {UF, DR, UB, DL, DF, UR, DB, UL, FR, FL, BL, BR}, + [S3] = {UF, UR, UB, DR, DF, UL, DB, DL, FR, FL, BL, BR}, + [E] = {UF, UL, UB, UR, DF, DL, DB, DR, FL, BL, BR, FR}, + [E2] = {UF, UL, UB, UR, DF, DL, DB, DR, BL, BR, FR, FL}, + [E3] = {UF, UL, UB, UR, DF, DL, DB, DR, BR, FR, FL, BL}, + + [X] = {DF, FL, UF, FR, DB, BL, UB, BR, DR, DL, UL, UR}, + [X2] = {DB, DL, DF, DR, UB, UL, UF, UR, BR, BL, FL, FR}, + [X3] = {UB, BL, DB, BR, UF, FL, DF, FR, UR, UL, DL, DR}, + [Y] = {UR, UF, UL, UB, DR, DF, DL, DB, BR, FR, FL, BL}, + [Y2] = {UB, UR, UF, UL, DB, DR, DF, DL, BL, BR, FR, FL}, + [Y3] = {UL, UB, UR, UF, DL, DB, DR, DF, FL, BL, BR, FR}, + [Z] = {FL, DL, BL, UL, FR, DR, BR, UR, UF, DF, DB, UB}, + [Z2] = {DF, DR, DB, DL, UF, UR, UB, UL, FL, FR, BR, BL}, + [Z3] = {FR, UR, BR, DR, FL, UL, BL, DL, DF, UF, UB, DB}, + + [NULLMOVE] = {UF, UL, UB, UR, DF, DL, DB, DR, FR, FL, BL, BR}, +}; + +int corner_cycle[NULLMOVE+1][8] = { + [U] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR}, + [U2] = {UBL, UBR, UFR, UFL, DFR, DFL, DBL, DBR}, + [U3] = {UFL, UBL, UBR, UFR, DFR, DFL, DBL, DBR}, + [D] = {UFR, UFL, UBL, UBR, DFL, DBL, DBR, DFR}, + [D2] = {UFR, UFL, UBL, UBR, DBL, DBR, DFR, DFL}, + [D3] = {UFR, UFL, UBL, UBR, DBR, DFR, DFL, DBL}, + [R] = {DFR, UFL, UBL, UFR, DBR, DFL, DBL, UBR}, + [R2] = {DBR, UFL, UBL, DFR, UBR, DFL, DBL, UFR}, + [R3] = {UBR, UFL, UBL, DBR, UFR, DFL, DBL, DFR}, + [L] = {UFR, UBL, DBL, UBR, DFR, UFL, DFL, DBR}, + [L2] = {UFR, DBL, DFL, UBR, DFR, UBL, UFL, DBR}, + [L3] = {UFR, DFL, UFL, UBR, DFR, DBL, UBL, DBR}, + [F] = {UFL, DFL, UBL, UBR, UFR, DFR, DBL, DBR}, + [F2] = {DFL, DFR, UBL, UBR, UFL, UFR, DBL, DBR}, + [F3] = {DFR, UFR, UBL, UBR, DFL, UFL, DBL, DBR}, + [B] = {UFR, UFL, UBR, DBR, DFR, DFL, UBL, DBL}, + [B2] = {UFR, UFL, DBR, DBL, DFR, DFL, UBR, UBL}, + [B3] = {UFR, UFL, DBL, UBL, DFR, DFL, DBR, UBR}, + + [Uw] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR}, + [Uw2] = {UBL, UBR, UFR, UFL, DFR, DFL, DBL, DBR}, + [Uw3] = {UFL, UBL, UBR, UFR, DFR, DFL, DBL, DBR}, + [Dw] = {UFR, UFL, UBL, UBR, DFL, DBL, DBR, DFR}, + [Dw2] = {UFR, UFL, UBL, UBR, DBL, DBR, DFR, DFL}, + [Dw3] = {UFR, UFL, UBL, UBR, DBR, DFR, DFL, DBL}, + [Rw] = {DFR, UFL, UBL, UFR, DBR, DFL, DBL, UBR}, + [Rw2] = {DBR, UFL, UBL, DFR, UBR, DFL, DBL, UFR}, + [Rw3] = {UBR, UFL, UBL, DBR, UFR, DFL, DBL, DFR}, + [Lw] = {UFR, UBL, DBL, UBR, DFR, UFL, DFL, DBR}, + [Lw2] = {UFR, DBL, DFL, UBR, DFR, UBL, UFL, DBR}, + [Lw3] = {UFR, DFL, UFL, UBR, DFR, DBL, UBL, DBR}, + [Fw] = {UFL, DFL, UBL, UBR, UFR, DFR, DBL, DBR}, + [Fw2] = {DFL, DFR, UBL, UBR, UFL, UFR, DBL, DBR}, + [Fw3] = {DFR, UFR, UBL, UBR, DFL, UFL, DBL, DBR}, + [Bw] = {UFR, UFL, UBR, DBR, DFR, DFL, UBL, DBL}, + [Bw2] = {UFR, UFL, DBR, DBL, DFR, DFL, UBR, UBL}, + [Bw3] = {UFR, UFL, DBL, UBL, DFR, DFL, DBR, UBR}, + + [M] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [M2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [M3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [S] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [S2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [S3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [E] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [E2] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + [E3] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, + + [X] = {DFR, DFL, UFL, UFR, DBR, DBL, UBL, UBR}, + [X2] = {DBR, DBL, DFL, DFR, UBR, UBL, UFL, UFR}, + [X3] = {UBR, UBL, DBL, DBR, UFR, UFL, DFL, DFR}, + [Y] = {UBR, UFR, UFL, UBL, DBR, DFR, DFL, DBL}, + [Y2] = {UBL, UBR, UFR, UFL, DBL, DBR, DFR, DFL}, + [Y3] = {UFL, UBL, UBR, UFR, DFL, DBL, DBR, DFR}, + [Z] = {UFL, DFL, DBL, UBL, UFR, DFR, DBR, UBR}, + [Z2] = {DFL, DFR, DBR, DBL, UFL, UFR, UBR, UBL}, + [Z3] = {DFR, UFR, UBR, DBR, DFL, UFL, UBL, DBL}, + + [NULLMOVE] = {UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR}, +}; + +int center_cycle[NULLMOVE+1][6] = { + [U] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [U2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [U3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [D] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [D2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [D3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [R] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [R2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [R3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [L] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [L2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [L3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [F] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [F2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [F3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [B] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [B2] = {U_center, D_center, R_center, L_center, F_center, B_center}, + [B3] = {U_center, D_center, R_center, L_center, F_center, B_center}, + + [Uw] = {U_center, D_center, B_center, F_center, R_center, L_center}, + [Uw2] = {U_center, D_center, L_center, R_center, B_center, F_center}, + [Uw3] = {U_center, D_center, F_center, B_center, L_center, R_center}, + [Dw] = {U_center, D_center, F_center, B_center, L_center, R_center}, + [Dw2] = {U_center, D_center, L_center, R_center, B_center, F_center}, + [Dw3] = {U_center, D_center, B_center, F_center, R_center, L_center}, + [Rw] = {F_center, B_center, R_center, L_center, D_center, U_center}, + [Rw2] = {D_center, U_center, R_center, L_center, B_center, F_center}, + [Rw3] = {B_center, F_center, R_center, L_center, U_center, D_center}, + [Lw] = {B_center, F_center, R_center, L_center, U_center, D_center}, + [Lw2] = {D_center, U_center, R_center, L_center, B_center, F_center}, + [Lw3] = {F_center, B_center, R_center, L_center, D_center, U_center}, + [Fw] = {L_center, R_center, U_center, D_center, F_center, B_center}, + [Fw2] = {D_center, U_center, L_center, R_center, F_center, B_center}, + [Fw3] = {R_center, L_center, D_center, U_center, F_center, B_center}, + [Bw] = {R_center, L_center, D_center, U_center, F_center, B_center}, + [Bw2] = {D_center, U_center, L_center, R_center, F_center, B_center}, + [Bw3] = {L_center, R_center, U_center, D_center, F_center, B_center}, + + [X] = {F_center, B_center, R_center, L_center, D_center, U_center}, + [X2] = {D_center, U_center, R_center, L_center, B_center, F_center}, + [X3] = {B_center, F_center, R_center, L_center, U_center, D_center}, + [Y] = {U_center, D_center, B_center, F_center, R_center, L_center}, + [Y2] = {U_center, D_center, L_center, R_center, B_center, F_center}, + [Y3] = {U_center, D_center, F_center, B_center, L_center, R_center}, + [Z] = {L_center, R_center, U_center, D_center, F_center, B_center}, + [Z2] = {D_center, U_center, L_center, R_center, F_center, B_center}, + [Z3] = {R_center, L_center, D_center, U_center, F_center, B_center}, + + [M] = {B_center, F_center, R_center, L_center, U_center, D_center}, + [M2] = {D_center, U_center, R_center, L_center, B_center, F_center}, + [M3] = {F_center, B_center, R_center, L_center, D_center, U_center}, + [E] = {U_center, D_center, F_center, B_center, L_center, R_center}, + [E2] = {U_center, D_center, L_center, R_center, B_center, F_center}, + [E3] = {U_center, D_center, B_center, F_center, R_center, L_center}, + [S] = {L_center, R_center, U_center, D_center, F_center, B_center}, + [S2] = {D_center, U_center, L_center, R_center, F_center, B_center}, + [S3] = {R_center, L_center, D_center, U_center, F_center, B_center}, + + [NULLMOVE] = {U_center, D_center, R_center, L_center, F_center, B_center}, +}; + diff --git a/old/2020-unknown-date/pieces.h b/old/2020-unknown-date/pieces.h new file mode 100644 index 0000000..dbdd740 --- /dev/null +++ b/old/2020-unknown-date/pieces.h @@ -0,0 +1,59 @@ +/* Moves and other things */ + +#ifndef PIECES_H +#define PIECES_H + +typedef enum { + U, U2, U3, D, D2, D3, R, R2, R3, L, L2, L3, F, F2, F3, B, B2, B3, + Uw, Uw2, Uw3, Dw, Dw2, Dw3, Rw, Rw2, Rw3, + Lw, Lw2, Lw3, Fw, Fw2, Fw3, Bw, Bw2, Bw3, + M, M2, M3, S, S2, S3, E, E2, E3, + X, X2, X3, Y, Y2, Y3, Z, Z2, Z3, + NULLMOVE +} Move; +typedef enum { + U_center, D_center, R_center, L_center, F_center, B_center +} Center; +typedef enum { UF, UL, UB, UR, DF, DL, DB, DR, FR, FL, BL, BR } Edge; +typedef enum { UFR, UFL, UBL, UBR, DFR, DFL, DBL, DBR } Corner; + +/* Arrays for strings of pieces and moves */ +extern char edge_string[12][5]; +extern char corner_string[8][5]; +extern char center_string[6][5]; +extern char move_string[NULLMOVE+1][5]; + +/* Three big arrays that determine the movement of edges, corners and + * centers for some of the basic moves. Yes, one can be much more elegant and + * write much fewer lines. But then things get less elegant somewhere else. */ +extern int edge_cycle[NULLMOVE+1][12]; +extern int corner_cycle[NULLMOVE+1][8]; +extern int center_cycle[NULLMOVE+1][6]; + +/* Representation of the cube */ +typedef struct { + /* Edge orientation */ + int eofb; + int eorl; + int eoud; + + /* Corner orientation */ + int coud; + int cofb; + int corl; + + /* Position of M/E/S slice edges */ + /* TODO: keep in mind that the 4! positions with edges in correct slice + * must be the first 4! indeces */ + int epose; + int eposs; + int eposm; + + /* Permutation of corners */ + int cp; + + /* Position of centers */ + int centerpos; +} Cube; + +#endif -- cgit v1.3