aboutsummaryrefslogtreecommitdiff
path: root/src/cube.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cube.c')
-rw-r--r--src/cube.c95
1 files changed, 81 insertions, 14 deletions
diff --git a/src/cube.c b/src/cube.c
index b9653ce..3a6234d 100644
--- a/src/cube.c
+++ b/src/cube.c
@@ -2,6 +2,9 @@
2 2
3/* Local functions ***********************************************************/ 3/* Local functions ***********************************************************/
4 4
5static void fix_eorleoud(CubeArray *arr);
6static void fix_cofbcorl(CubeArray *arr);
7static Cube fourval_to_cube(int eofb, int ep, int coud, int cp);
5static void init_inverse(); 8static void init_inverse();
6static bool read_invtables_file(); 9static bool read_invtables_file();
7static bool write_invtables_file(); 10static bool write_invtables_file();
@@ -15,6 +18,8 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8];
15static uint16_t cp_invtable[FACTORIAL8]; 18static uint16_t cp_invtable[FACTORIAL8];
16static uint16_t cpos_invtable[FACTORIAL6]; 19static uint16_t cpos_invtable[FACTORIAL6];
17 20
21char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" };
22
18/* Functions implementation **************************************************/ 23/* Functions implementation **************************************************/
19 24
20int 25int
@@ -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
147static void
148fix_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
169static void
170fix_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
190static Cube
191fourval_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
142void 212void
143free_cubearray(CubeArray *arr, PieceFilter f) 213free_cubearray(CubeArray *arr, PieceFilter f)
144{ 214{
@@ -475,10 +545,8 @@ print_cube(Cube cube)
475} 545}
476 546
477Cube 547Cube
478random_cube() 548random_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
503Center 570Center

Generated with cgit - Back to sebastiano.tronto.net