diff options
Diffstat (limited to '')
| -rw-r--r-- | src/cube.c | 95 |
1 files changed, 81 insertions, 14 deletions
| @@ -2,6 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | /* Local functions ***********************************************************/ | 3 | /* Local functions ***********************************************************/ |
| 4 | 4 | ||
| 5 | static void fix_eorleoud(CubeArray *arr); | ||
| 6 | static void fix_cofbcorl(CubeArray *arr); | ||
| 7 | static Cube fourval_to_cube(int eofb, int ep, int coud, int cp); | ||
| 5 | static void init_inverse(); | 8 | static void init_inverse(); |
| 6 | static bool read_invtables_file(); | 9 | static bool read_invtables_file(); |
| 7 | static bool write_invtables_file(); | 10 | static bool write_invtables_file(); |
| @@ -15,6 +18,8 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8]; | |||
| 15 | static uint16_t cp_invtable[FACTORIAL8]; | 18 | static uint16_t cp_invtable[FACTORIAL8]; |
| 16 | static uint16_t cpos_invtable[FACTORIAL6]; | 19 | static uint16_t cpos_invtable[FACTORIAL6]; |
| 17 | 20 | ||
| 21 | char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" }; | ||
| 22 | |||
| 18 | /* Functions implementation **************************************************/ | 23 | /* Functions implementation **************************************************/ |
| 19 | 24 | ||
| 20 | int | 25 | int |
| @@ -139,6 +144,71 @@ epos_to_partial_ep(int epos, int *ep, int *ss) | |||
| 139 | ep[i] = ss[eps[is++]]; | 144 | ep[i] = ss[eps[is++]]; |
| 140 | } | 145 | } |
| 141 | 146 | ||
| 147 | static void | ||
| 148 | fix_eorleoud(CubeArray *arr) | ||
| 149 | { | ||
| 150 | int i; | ||
| 151 | |||
| 152 | for (i = 0; i < 12; i++) { | ||
| 153 | if ((edge_slice(i) == 0 && edge_slice(arr->ep[i]) != 0) || | ||
| 154 | (edge_slice(i) != 0 && edge_slice(arr->ep[i]) == 0)) { | ||
| 155 | arr->eorl[i] = 1 - arr->eofb[i]; | ||
| 156 | } else { | ||
| 157 | arr->eorl[i] = arr->eofb[i]; | ||
| 158 | } | ||
| 159 | |||
| 160 | if ((edge_slice(i) == 2 && edge_slice(arr->ep[i]) != 2) || | ||
| 161 | (edge_slice(i) != 2 && edge_slice(arr->ep[i]) == 2)) { | ||
| 162 | arr->eoud[i] = 1 - arr->eofb[i]; | ||
| 163 | } else { | ||
| 164 | arr->eoud[i] = arr->eofb[i]; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | static void | ||
| 170 | fix_cofbcorl(CubeArray *arr) | ||
| 171 | { | ||
| 172 | int i; | ||
| 173 | |||
| 174 | for (i = 0; i < 8; i++) { | ||
| 175 | if (i % 2 == arr->cp[i] % 2) { | ||
| 176 | arr->cofb[i] = arr->coud[i]; | ||
| 177 | arr->corl[i] = arr->coud[i]; | ||
| 178 | } else { | ||
| 179 | if (arr->cp[i] % 2 == 0) { | ||
| 180 | arr->cofb[i] = (arr->coud[i]+1)%3; | ||
| 181 | arr->corl[i] = (arr->coud[i]+2)%3; | ||
| 182 | } else { | ||
| 183 | arr->cofb[i] = (arr->coud[i]+2)%3; | ||
| 184 | arr->corl[i] = (arr->coud[i]+1)%3; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | static Cube | ||
| 191 | fourval_to_cube(int eofb, int ep, int coud, int cp) | ||
| 192 | { | ||
| 193 | CubeArray *arr; | ||
| 194 | |||
| 195 | arr = new_cubearray((Cube){0}, pf_all); | ||
| 196 | |||
| 197 | index_to_perm(ep, 12, arr->ep); | ||
| 198 | index_to_perm(cp, 8, arr->cp); | ||
| 199 | int_to_sum_zero_array(eofb, 2, 12, arr->eofb); | ||
| 200 | int_to_sum_zero_array(coud, 3, 8, arr->coud); | ||
| 201 | |||
| 202 | /* fix parity */ | ||
| 203 | if (perm_sign(arr->ep, 12) != perm_sign(arr->cp, 8)) | ||
| 204 | swap(&(arr->ep[0]), &(arr->ep[1])); | ||
| 205 | |||
| 206 | fix_eorleoud(arr); | ||
| 207 | fix_cofbcorl(arr); | ||
| 208 | |||
| 209 | return arrays_to_cube(arr, pf_all); | ||
| 210 | } | ||
| 211 | |||
| 142 | void | 212 | void |
| 143 | free_cubearray(CubeArray *arr, PieceFilter f) | 213 | free_cubearray(CubeArray *arr, PieceFilter f) |
| 144 | { | 214 | { |
| @@ -475,10 +545,8 @@ print_cube(Cube cube) | |||
| 475 | } | 545 | } |
| 476 | 546 | ||
| 477 | Cube | 547 | Cube |
| 478 | random_cube() | 548 | random_cube(int scrt) |
| 479 | { | 549 | { |
| 480 | CubeArray *arr = new_cubearray((Cube){0}, pf_4val); | ||
| 481 | Cube ret; | ||
| 482 | int ep, cp, eo, co; | 550 | int ep, cp, eo, co; |
| 483 | 551 | ||
| 484 | ep = rand() % FACTORIAL12; | 552 | ep = rand() % FACTORIAL12; |
| @@ -486,18 +554,17 @@ random_cube() | |||
| 486 | eo = rand() % POW2TO11; | 554 | eo = rand() % POW2TO11; |
| 487 | co = rand() % POW3TO7; | 555 | co = rand() % POW3TO7; |
| 488 | 556 | ||
| 489 | index_to_perm(ep, 12, arr->ep); | 557 | if (scrt == 0) { /* EO */ |
| 490 | index_to_perm(cp, 8, arr->cp); | 558 | eo = 0; |
| 491 | int_to_sum_zero_array(eo, 2, 12, arr->eofb); | 559 | } else if (scrt == 1) { /* corners */ |
| 492 | int_to_sum_zero_array(co, 3, 8, arr->coud); | 560 | eo = 0; |
| 493 | 561 | ep = 0; | |
| 494 | if (perm_sign(arr->ep, 12) != perm_sign(arr->cp, 8)) | 562 | } else if (scrt == 2) { /* edges */ |
| 495 | swap(&(arr->ep[0]), &(arr->ep[1])); | 563 | co = 0; |
| 496 | 564 | cp = 0; | |
| 497 | ret = arrays_to_cube(arr, pf_4val); | 565 | } |
| 498 | free_cubearray(arr, pf_4val); | ||
| 499 | 566 | ||
| 500 | return ret; | 567 | return fourval_to_cube(eo, ep, co, cp); |
| 501 | } | 568 | } |
| 502 | 569 | ||
| 503 | Center | 570 | Center |
