aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/coord.c105
1 files changed, 54 insertions, 51 deletions
diff --git a/src/coord.c b/src/coord.c
index 5439d60..25c8538 100644
--- a/src/coord.c
+++ b/src/coord.c
@@ -36,6 +36,8 @@ static void init_cphtr_right_cosets_color(int i, int c);
36static void init_cpud_separate(void); 36static void init_cpud_separate(void);
37static void init_cornershtrfin(void); 37static void init_cornershtrfin(void);
38static void init_htr_eposs(void); 38static void init_htr_eposs(void);
39static void init_move_epud(void);
40static void init_move_cphtr(void);
39 41
40 42
41/* All sorts of useful costants and tables **********************************/ 43/* All sorts of useful costants and tables **********************************/
@@ -49,6 +51,8 @@ static int cornershtrfin_ind[FACTORIAL8];
49int cornershtrfin_ant[24*24/6]; 51int cornershtrfin_ant[24*24/6];
50static int htr_eposs_ind[BINOM12ON4]; 52static int htr_eposs_ind[BINOM12ON4];
51static int htr_eposs_ant[BINOM8ON4]; 53static int htr_eposs_ant[BINOM8ON4];
54static int move_cphtr_aux[NMOVES][BINOM8ON4*6];
55static int move_epud_aux[NMOVES][FACTORIAL8];
52 56
53/* Coordinates and their implementation **************************************/ 57/* Coordinates and their implementation **************************************/
54 58
@@ -286,47 +290,12 @@ move_eofbepos(Move m, uint64_t ind)
286static uint64_t 290static uint64_t
287move_epud(Move m, uint64_t ind) 291move_epud(Move m, uint64_t ind)
288{ 292{
289 /* TODO: save to file? */
290 static bool initialized = false;
291 static int a[12] = { [8] = 8, [9] = 9, [10] = 10, [11] = 11 };
292 static int shortlist[NMOVES] = { 293 static int shortlist[NMOVES] = {
293 [U] = 0, [U2] = 1, [U3] = 2, [D] = 3, [D2] = 4, [D3] = 5, 294 [U] = 0, [U2] = 1, [U3] = 2, [D] = 3, [D2] = 4, [D3] = 5,
294 [R2] = 6, [L2] = 7, [F2] = 8, [B2] = 9 295 [R2] = 6, [L2] = 7, [F2] = 8, [B2] = 9
295 }; 296 };
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 }
308
309 if (!initialized) {
310 auxarr = malloc(sizeof(CubeArray));
311 auxarr->ep = a;
312 for (ui = 0; ui < coord_epud.max; ui++) {
313 index_to_perm(ui, 8, a);
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 }
323 }
324 free(auxarr);
325 297
326 initialized = true; 298 return move_epud_aux[shortlist[m]][ind];
327 }
328
329 return aux[shortlist[m]][ind];
330} 299}
331 300
332static uint64_t 301static uint64_t
@@ -355,21 +324,7 @@ move_cp(Move m, uint64_t ind)
355static uint64_t 324static uint64_t
356move_cphtr(Move m, uint64_t ind) 325move_cphtr(Move m, uint64_t ind)
357{ 326{
358 static bool initialized = false; 327 return move_cphtr_aux[m][ind];
359 static uint64_t aux[NMOVES][BINOM8ON4*6];
360 uint64_t ui;
361 Move j;
362
363 if (!initialized) {
364 for (ui = 0; ui < BINOM8ON4*6; ui++)
365 for (j = U; j < NMOVES; j++)
366 aux[j][ui] = cphtr_right_cosets[
367 cp_mtable[j][cphtr_right_rep[ui]]];
368
369 initialized = true;
370 }
371
372 return aux[m][ind];
373} 328}
374 329
375static uint64_t 330static uint64_t
@@ -594,6 +549,51 @@ init_htr_eposs(void)
594 } 549 }
595} 550}
596 551
552static void
553init_move_epud(void)
554{
555 /* TODO: save to file? */
556 static int a[12] = { [8] = 8, [9] = 9, [10] = 10, [11] = 11 };
557 static int shortlist[NMOVES] = {
558 [U] = 0, [U2] = 1, [U3] = 2, [D] = 3, [D2] = 4, [D3] = 5,
559 [R2] = 6, [L2] = 7, [F2] = 8, [B2] = 9
560 };
561 uint64_t ui;
562 int j;
563 Move mj;
564 Cube c;
565 CubeArray *arr, *auxarr;
566
567 auxarr = malloc(sizeof(CubeArray));
568 auxarr->ep = a;
569 for (ui = 0; ui < coord_epud.max; ui++) {
570 index_to_perm(ui, 8, a);
571 c = arrays_to_cube(auxarr, pf_ep);
572 for (j = 0; moveset_drud.sorted_moves[j] != NULLMOVE;
573 j++) {
574 mj = moveset_drud.sorted_moves[j];
575 arr = new_cubearray(apply_move(mj, c), pf_ep);
576 move_epud_aux[shortlist[mj]][ui] =
577 perm_to_index(arr->ep, 8);
578 free_cubearray(arr, pf_ep);
579 }
580 }
581 free(auxarr);
582}
583
584static void
585init_move_cphtr(void)
586{
587 uint64_t ui;
588 Move j;
589
590 for (ui = 0; ui < BINOM8ON4*6; ui++)
591 for (j = U; j < NMOVES; j++)
592 move_cphtr_aux[j][ui] = cphtr_right_cosets[
593 cp_mtable[j][cphtr_right_rep[ui]]];
594}
595
596
597void 597void
598init_coord(void) 598init_coord(void)
599{ 599{
@@ -608,5 +608,8 @@ init_coord(void)
608 init_cornershtrfin(); 608 init_cornershtrfin();
609 init_htr_eposs(); 609 init_htr_eposs();
610 init_cpud_separate(); 610 init_cpud_separate();
611
612 init_move_epud();
613 init_move_cphtr();
611} 614}
612 615

Generated with cgit - Back to sebastiano.tronto.net