aboutsummaryrefslogtreecommitdiff
path: root/src/coord.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coord.c')
-rw-r--r--src/coord.c560
1 files changed, 241 insertions, 319 deletions
diff --git a/src/coord.c b/src/coord.c
index 3bbda22..abfa1b9 100644
--- a/src/coord.c
+++ b/src/coord.c
@@ -1,20 +1,5 @@
1#include "coord.h" 1#include "coord.h"
2 2
3static Cube antindex_eofb(uint64_t ind);
4static Cube antindex_eofbepos(uint64_t ind);
5static Cube antindex_epud(uint64_t ind);
6static Cube antindex_coud(uint64_t ind);
7static Cube antindex_corners(uint64_t ind);
8static Cube antindex_cp(uint64_t ind);
9static Cube antindex_cphtr(uint64_t);
10static Cube antindex_cornershtr(uint64_t ind);
11static Cube antindex_cornershtrfin(uint64_t ind);
12static Cube antindex_drud(uint64_t ind);
13static Cube antindex_drud_eofb(uint64_t ind);
14static Cube antindex_htr_drud(uint64_t ind);
15static Cube antindex_htrfin(uint64_t ind);
16static Cube antindex_cpud_separate(uint64_t ind);
17
18static uint64_t index_eofb(Cube cube); 3static uint64_t index_eofb(Cube cube);
19static uint64_t index_eofbepos(Cube cube); 4static uint64_t index_eofbepos(Cube cube);
20static uint64_t index_epud(Cube cube); 5static uint64_t index_epud(Cube cube);
@@ -30,10 +15,27 @@ static uint64_t index_htr_drud(Cube cube);
30static uint64_t index_htrfin(Cube cube); 15static uint64_t index_htrfin(Cube cube);
31static uint64_t index_cpud_separate(Cube cube); 16static uint64_t index_cpud_separate(Cube cube);
32 17
18static uint64_t move_eofb(Move m, uint64_t ind);
19static uint64_t move_eofbepos(Move m, uint64_t ind);
20static uint64_t move_epud(Move m, uint64_t ind);
21static uint64_t move_coud(Move m, uint64_t ind);
22static uint64_t move_corners(Move m, uint64_t ind);
23static uint64_t move_cp(Move m, uint64_t ind);
24static uint64_t move_cphtr(Move m, uint64_t ind);
25static uint64_t move_cornershtr(Move m, uint64_t ind);
26static uint64_t move_cornershtrfin(Move m, uint64_t ind);
27static uint64_t move_drud(Move m, uint64_t ind);
28static uint64_t move_drud_eofb(Move m, uint64_t ind);
29static uint64_t move_htr_drud(Move m, uint64_t ind);
30static uint64_t move_htrfin(Move m, uint64_t ind);
31static uint64_t move_cpud_separate(Move m, uint64_t ind);
32
33static void init_cphtr_cosets(); 33static void init_cphtr_cosets();
34static void init_cphtr_left_cosets_bfs(int i, int c); 34static void init_cphtr_left_cosets_bfs(int i, int c);
35static void init_cphtr_right_cosets_color(int i, int c); 35static void init_cphtr_right_cosets_color(int i, int c);
36static void init_cpud_separate();
36static void init_cornershtrfin(); 37static void init_cornershtrfin();
38static void init_htr_eposs();
37 39
38 40
39/* All sorts of useful costants and tables **********************************/ 41/* All sorts of useful costants and tables **********************************/
@@ -41,497 +43,408 @@ static void init_cornershtrfin();
41static int cphtr_left_cosets[FACTORIAL8]; 43static int cphtr_left_cosets[FACTORIAL8];
42static int cphtr_right_cosets[FACTORIAL8]; 44static int cphtr_right_cosets[FACTORIAL8];
43static int cphtr_right_rep[BINOM8ON4*6]; 45static int cphtr_right_rep[BINOM8ON4*6];
46int cpud_separate_ind[FACTORIAL8];
47int cpud_separate_ant[BINOM8ON4];
44static int cornershtrfin_ind[FACTORIAL8]; 48static int cornershtrfin_ind[FACTORIAL8];
45static int cornershtrfin_ant[24*24/6]; 49int cornershtrfin_ant[24*24/6];
50static int htr_eposs_ind[BINOM12ON4];
51static int htr_eposs_ant[BINOM8ON4];
46 52
47/* Coordinates and their implementation **************************************/ 53/* Coordinates and their implementation **************************************/
48 54
49Coordinate 55Coordinate
50coord_eofb = { 56coord_eofb = {
51 .index = index_eofb, 57 .index = index_eofb,
52 .cube = antindex_eofb,
53 .max = POW2TO11, 58 .max = POW2TO11,
59 .move = move_eofb,
54}; 60};
55 61
56Coordinate 62Coordinate
57coord_eofbepos = { 63coord_eofbepos = {
58 .index = index_eofbepos, 64 .index = index_eofbepos,
59 .cube = antindex_eofbepos,
60 .max = POW2TO11 * BINOM12ON4, 65 .max = POW2TO11 * BINOM12ON4,
66 .move = move_eofbepos,
61}; 67};
62 68
63Coordinate 69Coordinate
64coord_coud = { 70coord_coud = {
65 .index = index_coud, 71 .index = index_coud,
66 .cube = antindex_coud,
67 .max = POW3TO7, 72 .max = POW3TO7,
73 .move = move_coud,
68}; 74};
69 75
70Coordinate 76Coordinate
71coord_corners = { 77coord_corners = {
72 .index = index_corners, 78 .index = index_corners,
73 .cube = antindex_corners,
74 .max = POW3TO7 * FACTORIAL8, 79 .max = POW3TO7 * FACTORIAL8,
80 .move = move_corners,
75}; 81};
76 82
77Coordinate 83Coordinate
78coord_cp = { 84coord_cp = {
79 .index = index_cp, 85 .index = index_cp,
80 .cube = antindex_cp,
81 .max = FACTORIAL8, 86 .max = FACTORIAL8,
87 .move = move_cp,
82}; 88};
83 89
84Coordinate 90Coordinate
85coord_cphtr = { 91coord_cphtr = {
86 .index = index_cphtr, 92 .index = index_cphtr,
87 .cube = antindex_cphtr,
88 .max = BINOM8ON4 * 6, 93 .max = BINOM8ON4 * 6,
94 .move = move_cphtr,
89}; 95};
90 96
91Coordinate 97Coordinate
92coord_cornershtr = { 98coord_cornershtr = {
93 .index = index_cornershtr, 99 .index = index_cornershtr,
94 .cube = antindex_cornershtr,
95 .max = POW3TO7 * BINOM8ON4 * 6, 100 .max = POW3TO7 * BINOM8ON4 * 6,
101 .move = move_cornershtr,
96}; 102};
97 103
98Coordinate 104Coordinate
99coord_cornershtrfin = { 105coord_cornershtrfin = {
100 .index = index_cornershtrfin, 106 .index = index_cornershtrfin,
101 .cube = antindex_cornershtrfin,
102 .max = 24*24/6, 107 .max = 24*24/6,
108 .move = move_cornershtrfin,
103}; 109};
104 110
105Coordinate 111Coordinate
106coord_epud = { 112coord_epud = {
107 .index = index_epud, 113 .index = index_epud,
108 .cube = antindex_epud,
109 .max = FACTORIAL8, 114 .max = FACTORIAL8,
115 .move = move_epud,
110}; 116};
111 117
112Coordinate 118Coordinate
113coord_drud = { 119coord_drud = {
114 .index = index_drud, 120 .index = index_drud,
115 .cube = antindex_drud,
116 .max = POW2TO11 * POW3TO7 * BINOM12ON4, 121 .max = POW2TO11 * POW3TO7 * BINOM12ON4,
122 .move = move_drud,
117}; 123};
118 124
119Coordinate 125Coordinate
120coord_htr_drud = { 126coord_htr_drud = {
121 .index = index_htr_drud, 127 .index = index_htr_drud,
122 .cube = antindex_htr_drud,
123 .max = BINOM8ON4 * 6 * BINOM8ON4, 128 .max = BINOM8ON4 * 6 * BINOM8ON4,
129 .move = move_htr_drud,
124}; 130};
125 131
126Coordinate 132Coordinate
127coord_htrfin = { 133coord_htrfin = {
128 .index = index_htrfin, 134 .index = index_htrfin,
129 .cube = antindex_htrfin,
130 .max = 24 * 24 * 24 *24 * 24 / 6, /* should be /12 but it's ok */ 135 .max = 24 * 24 * 24 *24 * 24 / 6, /* should be /12 but it's ok */
136 .move = move_htrfin,
131}; 137};
132 138
133Coordinate 139Coordinate
134coord_drud_eofb = { 140coord_drud_eofb = {
135 .index = index_drud_eofb, 141 .index = index_drud_eofb,
136 .cube = antindex_drud_eofb,
137 .max = POW3TO7 * BINOM12ON4, 142 .max = POW3TO7 * BINOM12ON4,
143 .move = move_drud_eofb,
138}; 144};
139 145
140Coordinate 146Coordinate
141coord_cpud_separate = { 147coord_cpud_separate = {
142 .index = index_cpud_separate, 148 .index = index_cpud_separate,
143 .cube = antindex_cpud_separate,
144 .max = BINOM8ON4, 149 .max = BINOM8ON4,
150 .move = move_cpud_separate,
145}; 151};
146 152
147/* Antindexers ***************************************************************/ 153/* Indexers ******************************************************************/
148 154
149static Cube 155static uint64_t
150antindex_eofb(uint64_t ind) 156index_eofb(Cube cube)
151{ 157{
152 /* The returned cube is consistent */ 158 return cube.eofb;
153 Cube ret = {0};
154
155 ret.eofb = ind;
156 ret.eorl = ind;
157 ret.eoud = ind;
158
159 return ret;
160} 159}
161 160
162static Cube 161static uint64_t
163antindex_eofbepos(uint64_t ind) 162index_eofbepos(Cube cube)
164{ 163{
165 /* The returned cube is NOT consistent: eoud can be wrong */ 164 return (cube.epose / FACTORIAL4) * POW2TO11 + cube.eofb;
166 Cube ret = {0}; 165}
167
168 /* We need eorl for sym16 coordinate */
169 static int initialized = false;
170 static uint64_t eorl_a[POW2TO11][BINOM12ON4];
171 static int eo_aux[12], ep_aux[12];
172 unsigned int i, j, k;
173
174 if (!initialized) {
175 for (i = 0; i < POW2TO11; i++) {
176 for (j = 0; j < BINOM12ON4; j++) {
177 int_to_sum_zero_array(i, 2, 12, eo_aux);
178 index_to_subset(j, 12, 4, ep_aux);
179 for (k = 0; k < 12; k++)
180 if ((ep_aux[k] && k < FR) ||
181 (!ep_aux[k] && k >= FR))
182 eo_aux[k] = 1 - eo_aux[k];
183 eorl_a[i][j] = digit_array_to_int(eo_aux,11,2);
184 }
185 }
186 166
187 initialized = true; 167static uint64_t
188 } 168index_epud(Cube cube)
169{
170 uint64_t ret;
171 CubeArray *arr = new_cubearray(cube, pf_ep);
189 172
190 ret.eofb = ind % POW2TO11; 173 ret = perm_to_index(arr->ep, 8);
191 ret.epose = (ind / POW2TO11) * 24; 174 free_cubearray(arr, pf_ep);
192 ret.eorl = eorl_a[ret.eofb][ret.epose/24];
193 175
194 return ret; 176 return ret;
195} 177}
196 178
197static Cube 179static uint64_t
198antindex_epud(uint64_t ind) 180index_coud(Cube cube)
199{ 181{
200 /* The returned cube is consistent */ 182 return cube.coud;
201 static bool initialized = false;
202 static Cube epud_aux[FACTORIAL8];
203 int a[12];
204 uint64_t ui;
205 CubeArray arr;
206
207 if (!initialized) {
208 a[FR] = FR;
209 a[FL] = FL;
210 a[BL] = BL;
211 a[BR] = BR;
212 for (ui = 0; ui < FACTORIAL8; ui++) {
213 index_to_perm(ui, 8, a);
214 arr.ep = a;
215 epud_aux[ui] = arrays_to_cube(&arr, pf_ep);
216 }
217
218 initialized = true;
219 }
220
221 return epud_aux[ind];
222} 183}
223 184
224static Cube 185static uint64_t
225antindex_coud(uint64_t ind) 186index_corners(Cube cube)
226{ 187{
227 /* The returned cube is consistent */ 188 return cube.coud * FACTORIAL8 + cube.cp;
228 Cube ret = {0};
229
230 ret.coud = ind;
231 ret.corl = ind;
232 ret.cofb = ind;
233
234 return ret;
235} 189}
236 190
237static Cube 191static uint64_t
238antindex_corners(uint64_t ind) 192index_cp(Cube cube)
239{ 193{
240 /* The returned cube is NOT consistent: corl and cofb can be wrong */ 194 return cube.cp;
241 /* TODO: remember to make this consistent if I use this for symcoord */
242 Cube ret = {0};
243
244 ret.coud = ind / FACTORIAL8;
245 ret.cp = ind % FACTORIAL8;
246
247 return ret;
248} 195}
249 196
250static Cube 197static uint64_t
251antindex_cp(uint64_t ind) 198index_cphtr(Cube cube)
252{ 199{
253 /* The returned cube is NOT consistent: co can be wrong in all axes */ 200 return cphtr_right_cosets[cube.cp];
254 Cube ret = {0}; 201}
255 202
256 ret.cp = ind; 203static uint64_t
204index_cornershtr(Cube cube)
205{
206 return cube.coud * BINOM8ON4 * 6 + index_cphtr(cube);
207}
257 208
258 return ret; 209static uint64_t
210index_cornershtrfin(Cube cube)
211{
212 return cornershtrfin_ind[cube.cp];
259} 213}
260 214
261static Cube 215static uint64_t
262antindex_cphtr(uint64_t ind) 216index_drud(Cube cube)
263{ 217{
264 /* The returned cube is NOT consistent: co can be wrong in all axes */ 218 uint64_t a, b, c;
265 Cube ret = {0};
266 219
267 ret.cp = cphtr_right_rep[ind]; 220 a = cube.eofb;
221 b = cube.coud;
222 c = cube.epose / FACTORIAL4;
268 223
269 return ret; 224 b *= POW2TO11;
225 c *= POW2TO11 * POW3TO7;
226
227 return a + b + c;
270} 228}
271 229
272static Cube 230static uint64_t
273antindex_cornershtr(uint64_t ind) 231index_drud_eofb(Cube cube)
274{ 232{
275 /* The returned cube is NOT consistent: corl and cofb can be wrong */ 233 return index_drud(cube) / POW2TO11;
276 Cube ret = antindex_cphtr(ind % (BINOM8ON4 * 6));
277
278 ret.coud = ind / (BINOM8ON4 * 6);
279
280 return ret;
281} 234}
282 235
283static Cube 236static uint64_t
284antindex_cornershtrfin(uint64_t ind) 237index_htr_drud(Cube cube)
285{ 238{
286 /* The returned cube is consistent */ 239 uint64_t a, b;
287 Cube ret = {0};
288 240
289 ret.cp = cornershtrfin_ant[ind]; 241 a = index_cphtr(cube);
242 b = htr_eposs_ind[cube.eposs/24];
290 243
291 return ret; 244 return a * BINOM8ON4 + b;
292} 245}
293 246
294static Cube 247static uint64_t
295antindex_drud(uint64_t ind) 248index_htrfin(Cube cube)
296{ 249{
297 /* The returned cube is NOT consistent in the same way as eofbepos */ 250 uint64_t epe, eps, epm, cp, ep;
298 /* (see above). It works with sym16 coordinates */
299 uint64_t epos, eofb;
300 Cube ret = {0};
301
302 eofb = ind % POW2TO11;
303 epos = ind / (POW2TO11 * POW3TO7);
304 ret = antindex_eofbepos(eofb + POW2TO11 * epos);
305 251
306 ret.coud = (ind / POW2TO11) % POW3TO7; 252 epe = cube.epose % 24;
307 ret.corl = ret.coud; 253 eps = cube.eposs % 24;
308 ret.cofb = ret.coud; 254 epm = cube.eposm % 24;
255 ep = (epe * 24 + eps) *24 + epm;
256 cp = index_cornershtrfin(cube);
309 257
310 return ret; 258 return cp * 24 * 24 * 24 + ep;
311} 259}
312 260
313static Cube 261static uint64_t
314antindex_drud_eofb(uint64_t ind) 262index_cpud_separate(Cube cube)
315{ 263{
316 /* The returned cube is NOT consistent (see antindex_drud) */ 264 return cpud_separate_ind[cube.cp];
317 return antindex_drud(ind * POW2TO11);
318} 265}
319 266
320static Cube 267/* Coordinate movers *********************************************************/
321antindex_htr_drud(uint64_t ind)
322{
323 /* The returned cube is NOT consistent: corl and cofb can be wrong */
324 /* (see cphtr) and eposm can be wrong too (not epose because dr). */
325 Cube ret = {0};
326 static bool initialized = false;
327 static int aux[BINOM8ON4], ep[12], ep2[12];
328 static int eps_solved[4] = {UL, UR, DL, DR};
329 unsigned int i, j, k;
330 268
331 if (!initialized) { 269static uint64_t
332 for (i = 0; i < BINOM8ON4; i++) { 270move_eofb(Move m, uint64_t ind)
333 for (j = 0; j < 12; j++) 271{
334 ep[j] = ep2[j] = 0; 272 return eofb_mtable[m][ind];
335 index_to_subset(i, 8, 4, ep);
336 for (j = 0, k = 0; j < 8; j++)
337 ep2[j] = ep[j/2+4*(j%2)] ? eps_solved[k++] : 0;
338 aux[i] = array_ep_to_epos(ep2, eps_solved);
339 }
340
341 initialized = true;
342 }
343
344 ret = antindex_cphtr(ind / BINOM8ON4);
345 ret.epose = 0;
346 ret.eposs = aux[ind % BINOM8ON4];
347
348 return ret;
349} 273}
350 274
351static Cube 275static uint64_t
352antindex_htrfin(uint64_t ind) 276move_eofbepos(Move m, uint64_t ind)
353{ 277{
354 /* The returned cube is consistent */ 278 uint64_t a, b;
355 Cube ret = {0};
356
357 ret = antindex_cornershtrfin(ind/(24*24*24));
358 279
359 ret.eposm = ind % 24; 280 a = epose_mtable[m][(ind / POW2TO11)*24];
360 ind /= 24; 281 b = eofb_mtable[m][ind % POW2TO11];
361 ret.eposs = ind % 24;
362 ind /= 24;
363 ret.epose = ind % 24;
364 282
365 return ret; 283 return a/24 + b;
366} 284}
367 285
368static Cube 286static uint64_t
369antindex_cpud_separate(uint64_t ind) 287move_epud(Move m, uint64_t ind)
370{ 288{
371 /* Not consistent because of side corner orientations and cp */ 289 /* TODO: save to file? */
372 unsigned int ui;
373 int i, co[8], cp[8];
374 Corner u, d;
375
376 static Cube aux[BINOM8ON4];
377 static bool initialized = false; 290 static bool initialized = false;
291 static int a[12] = { [8] = 8, [9] = 9, [10] = 10, [11] = 11 };
292 static int shortlist[NMOVES] = {
293 [U] = 0, [U2] = 1, [U3] = 2, [D] = 3, [D2] = 4, [D3] = 5,
294 [R2] = 6, [L2] = 7, [F2] = 8, [B2] = 9
295 };
296 static uint64_t aux[10][FACTORIAL8];
297 uint64_t ui;
298 int j;
299 Move mj;
300 Cube c;
301 CubeArray *arr, *auxarr;
302
303 if (!moveset_drud.allowed(m)) {
304 fprintf(stderr, "Move not allowed for epud\n"
305 "This is a bug, please report\n");
306 return coord_epud.max;
307 }
378 308
379 if (!initialized) { 309 if (!initialized) {
380 for (ui = 0; ui < BINOM8ON4; ui++) { 310 auxarr = malloc(sizeof(CubeArray));
381 index_to_subset(ui, 8, 4, co); 311 auxarr->ep = a;
382 for (i = 0, u = UFR, d = DFR; i < 8; i++) 312 for (ui = 0; ui < coord_epud.max; ui++) {
383 cp[i] = co[i] ? d++ : u++; 313 index_to_perm(ui, 8, a);
384 aux[ui] = (Cube){.cp = perm_to_index(cp, 8)}; 314 c = arrays_to_cube(auxarr, pf_ep);
315 for (j = 0; moveset_drud.sorted_moves[j] != NULLMOVE;
316 j++) {
317 mj = moveset_drud.sorted_moves[j];
318 arr = new_cubearray(apply_move(mj, c), pf_ep);
319 aux[shortlist[mj]][ui] =
320 perm_to_index(arr->ep, 8);
321 free_cubearray(arr, pf_ep);
322 }
385 } 323 }
324 free(auxarr);
386 325
387 initialized = true; 326 initialized = true;
388 } 327 }
389 328
390 return aux[ind]; 329 return aux[shortlist[m]][ind];
391}
392
393/* Indexers ******************************************************************/
394
395static uint64_t
396index_eofb(Cube cube)
397{
398 return cube.eofb;
399} 330}
400 331
401static uint64_t 332static uint64_t
402index_eofbepos(Cube cube) 333move_coud(Move m, uint64_t ind)
403{ 334{
404 return (cube.epose / FACTORIAL4) * POW2TO11 + cube.eofb; 335 return coud_mtable[m][ind];
405} 336}
406 337
407static uint64_t 338static uint64_t
408index_epud(Cube cube) 339move_corners(Move m, uint64_t ind)
409{ 340{
410 uint64_t ret; 341 uint64_t a, b;
411 CubeArray *arr = new_cubearray(cube, pf_ep);
412 342
413 ret = perm_to_index(arr->ep, 8); 343 a = coud_mtable[m][ind / FACTORIAL8];
414 free_cubearray(arr, pf_ep); 344 b = cp_mtable[m][ind % FACTORIAL8];
415 345
416 return ret; 346 return a * FACTORIAL8 + b;
417} 347}
418 348
419static uint64_t 349static uint64_t
420index_coud(Cube cube) 350move_cp(Move m, uint64_t ind)
421{ 351{
422 return cube.coud; 352 return cp_mtable[m][ind];
423} 353}
424 354
425static uint64_t 355static uint64_t
426index_corners(Cube cube) 356move_cphtr(Move m, uint64_t ind)
427{ 357{
428 return cube.coud * FACTORIAL8 + cube.cp; 358 static bool initialized = false;
429} 359 static uint64_t aux[NMOVES][BINOM8ON4*6];
360 uint64_t ui;
361 Move j;
430 362
431static uint64_t 363 if (!initialized) {
432index_cp(Cube cube) 364 for (ui = 0; ui < BINOM8ON4*6; ui++)
433{ 365 for (j = U; j < NMOVES; j++)
434 return cube.cp; 366 aux[j][ui] =
435} 367 cp_mtable[j][cphtr_right_rep[ind]];
436 368
437static uint64_t 369 initialized = true;
438index_cphtr(Cube cube) 370 }
439{ 371
440 return cphtr_right_cosets[cube.cp]; 372 return aux[m][ind];
441} 373}
442 374
443static uint64_t 375static uint64_t
444index_cornershtr(Cube cube) 376move_cornershtr(Move m, uint64_t ind)
445{ 377{
446 return cube.coud * BINOM8ON4 * 6 + index_cphtr(cube); 378 uint64_t a, b;
379
380 a = coud_mtable[m][ind/(BINOM8ON4 * 6)];
381 b = move_cphtr(m, ind % (BINOM8ON4 * 6));
382
383 return a * BINOM8ON4 * 6 + b;
447} 384}
448 385
449static uint64_t 386static uint64_t
450index_cornershtrfin(Cube cube) 387move_cornershtrfin(Move m, uint64_t ind)
451{ 388{
452 return cornershtrfin_ind[cube.cp]; 389 int a;
390
391 a = cp_mtable[m][cornershtrfin_ant[ind]];
392
393 return cornershtrfin_ind[a];
453} 394}
454 395
455static uint64_t 396static uint64_t
456index_drud(Cube cube) 397move_drud(Move m, uint64_t ind)
457{ 398{
458 uint64_t a, b, c; 399 uint64_t a, b, c;
459 400
460 a = cube.eofb; 401 a = eofb_mtable[m][ind % POW2TO11];
461 b = cube.coud; 402 b = coud_mtable[m][(ind / POW2TO11) % POW3TO7];
462 c = cube.epose / FACTORIAL4; 403 c = epose_mtable[m][ind / (POW2TO11 * POW3TO7)];
463
464 b *= POW2TO11;
465 c *= POW2TO11 * POW3TO7;
466 404
467 return a + b + c; 405 return a + (b + c * POW3TO7) * POW2TO11;
468} 406}
469 407
470static uint64_t 408static uint64_t
471index_drud_eofb(Cube cube) 409move_drud_eofb(Move m, uint64_t ind)
472{ 410{
473 return index_drud(cube) / POW2TO11; 411 uint64_t a, b;
412
413 a = coud_mtable[m][ind % POW3TO7];
414 b = epose_mtable[m][ind / POW3TO7];
415
416 return a + b * POW3TO7;
474} 417}
475 418
476static uint64_t 419static uint64_t
477index_htr_drud(Cube cube) 420move_htr_drud(Move m, uint64_t ind)
478{ 421{
479 static bool initialized = false; 422 uint64_t a, b;
480 static int aux[BINOM12ON4], ep[12], ep2[12];
481 static int eps_solved[4] = {UL, UR, DL, DR};
482 unsigned int i, j;
483 423
484 if (!initialized) { 424 a = move_cphtr(m, ind/BINOM8ON4);
485 for (i = 0; i < BINOM12ON4; i++) { 425 b = eposs_mtable[m][htr_eposs_ant[ind%BINOM8ON4]];
486 for (j = 0; j < 12; j++)
487 ep[j] = ep2[j] = 0;
488 epos_to_partial_ep(i*24, ep, eps_solved);
489 for (j = 0; j < 8; j++)
490 ep2[j/2 + 4*(j%2)] = ep[j] ? 1 : 0;
491 aux[i] = subset_to_index(ep2, 8, 4);
492 }
493 426
494 initialized = true; 427 return a*BINOM8ON4 + htr_eposs_ind[b/24];
495 }
496
497 return index_cphtr(cube) * BINOM8ON4 + aux[cube.eposs/24];
498} 428}
499 429
500static uint64_t 430static uint64_t
501index_htrfin(Cube cube) 431move_htrfin(Move m, uint64_t ind)
502{ 432{
503 uint64_t epe, eps, epm, cp, ep; 433 uint64_t a, b, bm, bs, be;
504 434
505 epe = cube.epose % 24; 435 a = move_cornershtrfin(m, ind % (24*24*24));
506 eps = cube.eposs % 24; 436 bm = eposm_mtable[m][ind%24] % 24;
507 epm = cube.eposm % 24; 437 bs = eposs_mtable[m][(ind/24)%24] % 24;
508 ep = (epe * 24 + eps) *24 + epm; 438 be = epose_mtable[m][ind/(24*24)] % 24;
509 cp = index_cornershtrfin(cube); 439 b = (be * 24 + bs) * 24 + bm;
510 440
511 return cp * 24 * 24 * 24 + ep; 441 return a * (24*24*24) + b;
512} 442}
513 443
514static uint64_t 444static uint64_t
515index_cpud_separate(Cube cube) 445move_cpud_separate(Move m, uint64_t ind)
516{ 446{
517 unsigned int ui; 447 return cpud_separate_ind[cp_mtable[m][cpud_separate_ant[ind]]];
518 int i, co[8];
519
520 static int aux[FACTORIAL8];
521 static bool initialized = false;
522
523 if (!initialized) {
524 for (ui = 0; ui < FACTORIAL8; ui++) {
525 for (i = 0; i < 8; i++)
526 co[i] = what_corner_at((Cube){.cp=ui},i)>UBR ?
527 1 : 0;
528 aux[ui] = subset_to_index(co, 8, 4);
529 }
530
531 initialized = true;
532 }
533
534 return aux[cube.cp];
535} 448}
536 449
537/* Init functions implementation *********************************************/ 450/* Init functions implementation *********************************************/
@@ -618,6 +531,20 @@ init_cphtr_right_cosets_color(int i, int d)
618} 531}
619 532
620static void 533static void
534init_cpud_separate()
535{
536 unsigned int ui;
537 int i, co[8];
538
539 for (ui = 0; ui < FACTORIAL8; ui++) {
540 for (i = 0; i < 8; i++)
541 co[i] = what_corner_at((Cube){.cp=ui},i)>UBR ? 1 : 0;
542 cpud_separate_ind[ui] = subset_to_index(co, 8, 4);
543 cpud_separate_ant[cpud_separate_ind[ui]] = ui;
544 }
545}
546
547static void
621init_cornershtrfin() 548init_cornershtrfin()
622{ 549{
623 unsigned int i, j; 550 unsigned int i, j;
@@ -649,28 +576,21 @@ init_cornershtrfin()
649} 576}
650 577
651void 578void
652test_coord(Coordinate *coord) 579init_htr_eposs()
653{ 580{
654 bool passed; 581 int ep[12], ep2[12];
655 uint64_t ui, failcount; 582 int eps_solved[4] = {UL, UR, DL, DR};
656 583 unsigned int i, j;
657 if (!(passed = (coord->index((Cube){0}) == 0))) {
658 printf("Failed: coordinate of solved cube is "
659 "%" PRIu64 "\n", coord->index((Cube){0}));
660 }
661 584
662 printf("Testing %" PRIu64 " coordinates\n", coord->max); 585 for (i = 0; i < BINOM12ON4; i++) {
663 for (failcount = 0, ui = 0; ui < coord->max; ui++) { 586 for (j = 0; j < 12; j++)
664 if (!(passed = (coord->index(coord->cube(ui)) == ui))) { 587 ep[j] = ep2[j] = 0;
665 printf("Failed at %" PRIu64 "\n", ui); 588 epos_to_partial_ep(i*24, ep, eps_solved);
666 failcount++; 589 for (j = 0; j < 8; j++)
667 } 590 ep2[j/2 + 4*(j%2)] = ep[j] ? 1 : 0;
591 htr_eposs_ind[i] = subset_to_index(ep2, 8, 4);
592 htr_eposs_ant[htr_eposs_ind[i]] = i*24;
668 } 593 }
669
670 if (passed)
671 printf("Ok\n");
672 else
673 printf("Test failed in %" PRIu64 " cases\n", failcount);
674} 594}
675 595
676void 596void
@@ -685,5 +605,7 @@ init_coord()
685 605
686 init_cphtr_cosets(); 606 init_cphtr_cosets();
687 init_cornershtrfin(); 607 init_cornershtrfin();
608 init_htr_eposs();
609 init_cpud_separate();
688} 610}
689 611

Generated with cgit - Back to sebastiano.tronto.net