aboutsummaryrefslogtreecommitdiff
path: root/src/coord.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-16 19:25:58 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-16 19:25:58 +0100
commit2f924f942bd6e7126e8f1d8692e475c95bd9fe82 (patch)
treedd5877c2fd836f43523263e48632946423401093 /src/coord.c
parent4e2b4e603c7e84c7556f489d7d8dab06915b3a9b (diff)
downloadnissy-2f924f942bd6e7126e8f1d8692e475c95bd9fe82.tar.gz
nissy-2f924f942bd6e7126e8f1d8692e475c95bd9fe82.zip
Added a new pruning table (equivalent to nxopt31). I have not tested it yet, it takes a while to generate.
Plus I have done a whole lot of refactoring in random places because I cannot focus on one thing at the time.
Diffstat (limited to 'src/coord.c')
-rw-r--r--src/coord.c86
1 files changed, 84 insertions, 2 deletions
diff --git a/src/coord.c b/src/coord.c
index c9a28c4..3bbda22 100644
--- a/src/coord.c
+++ b/src/coord.c
@@ -13,6 +13,7 @@ static Cube antindex_drud(uint64_t ind);
13static Cube antindex_drud_eofb(uint64_t ind); 13static Cube antindex_drud_eofb(uint64_t ind);
14static Cube antindex_htr_drud(uint64_t ind); 14static Cube antindex_htr_drud(uint64_t ind);
15static Cube antindex_htrfin(uint64_t ind); 15static Cube antindex_htrfin(uint64_t ind);
16static Cube antindex_cpud_separate(uint64_t ind);
16 17
17static uint64_t index_eofb(Cube cube); 18static uint64_t index_eofb(Cube cube);
18static uint64_t index_eofbepos(Cube cube); 19static uint64_t index_eofbepos(Cube cube);
@@ -27,6 +28,7 @@ static uint64_t index_drud(Cube cube);
27static uint64_t index_drud_eofb(Cube cube); 28static uint64_t index_drud_eofb(Cube cube);
28static uint64_t index_htr_drud(Cube cube); 29static uint64_t index_htr_drud(Cube cube);
29static uint64_t index_htrfin(Cube cube); 30static uint64_t index_htrfin(Cube cube);
31static uint64_t index_cpud_separate(Cube cube);
30 32
31static void init_cphtr_cosets(); 33static void init_cphtr_cosets();
32static void init_cphtr_left_cosets_bfs(int i, int c); 34static void init_cphtr_left_cosets_bfs(int i, int c);
@@ -135,6 +137,13 @@ coord_drud_eofb = {
135 .max = POW3TO7 * BINOM12ON4, 137 .max = POW3TO7 * BINOM12ON4,
136}; 138};
137 139
140Coordinate
141coord_cpud_separate = {
142 .index = index_cpud_separate,
143 .cube = antindex_cpud_separate,
144 .max = BINOM8ON4,
145};
146
138/* Antindexers ***************************************************************/ 147/* Antindexers ***************************************************************/
139 148
140static Cube 149static Cube
@@ -356,6 +365,31 @@ antindex_htrfin(uint64_t ind)
356 return ret; 365 return ret;
357} 366}
358 367
368static Cube
369antindex_cpud_separate(uint64_t ind)
370{
371 /* Not consistent because of side corner orientations and cp */
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;
378
379 if (!initialized) {
380 for (ui = 0; ui < BINOM8ON4; ui++) {
381 index_to_subset(ui, 8, 4, co);
382 for (i = 0, u = UFR, d = DFR; i < 8; i++)
383 cp[i] = co[i] ? d++ : u++;
384 aux[ui] = (Cube){.cp = perm_to_index(cp, 8)};
385 }
386
387 initialized = true;
388 }
389
390 return aux[ind];
391}
392
359/* Indexers ******************************************************************/ 393/* Indexers ******************************************************************/
360 394
361static uint64_t 395static uint64_t
@@ -477,6 +511,29 @@ index_htrfin(Cube cube)
477 return cp * 24 * 24 * 24 + ep; 511 return cp * 24 * 24 * 24 + ep;
478} 512}
479 513
514static uint64_t
515index_cpud_separate(Cube cube)
516{
517 unsigned int ui;
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}
536
480/* Init functions implementation *********************************************/ 537/* Init functions implementation *********************************************/
481 538
482/* 539/*
@@ -528,7 +585,7 @@ init_cphtr_left_cosets_bfs(int i, int c)
528 while (n != 0) { 585 while (n != 0) {
529 for (j = 0, n2 = 0; j < n; j++) { 586 for (j = 0, n2 = 0; j < n; j++) {
530 for (k = U2; k < B3; k++) { 587 for (k = U2; k < B3; k++) {
531 if (!moveset_htr(k)) 588 if (!moveset_htr.allowed(k))
532 continue; 589 continue;
533 jj = apply_move(k, (Cube){ .cp = next[j] }).cp; 590 jj = apply_move(k, (Cube){ .cp = next[j] }).cp;
534 591
@@ -578,7 +635,7 @@ init_cornershtrfin()
578 if (cornershtrfin_ind[j] == -1) 635 if (cornershtrfin_ind[j] == -1)
579 continue; 636 continue;
580 for (m = U; m < NMOVES; m++) { 637 for (m = U; m < NMOVES; m++) {
581 if (moveset_htr(m)) { 638 if (moveset_htr.allowed(m)) {
582 c = apply_move(m, (Cube){.cp = j}).cp; 639 c = apply_move(m, (Cube){.cp = j}).cp;
583 if (cornershtrfin_ind[c] == -1) { 640 if (cornershtrfin_ind[c] == -1) {
584 cornershtrfin_ind[c] = n; 641 cornershtrfin_ind[c] = n;
@@ -592,6 +649,31 @@ init_cornershtrfin()
592} 649}
593 650
594void 651void
652test_coord(Coordinate *coord)
653{
654 bool passed;
655 uint64_t ui, failcount;
656
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
662 printf("Testing %" PRIu64 " coordinates\n", coord->max);
663 for (failcount = 0, ui = 0; ui < coord->max; ui++) {
664 if (!(passed = (coord->index(coord->cube(ui)) == ui))) {
665 printf("Failed at %" PRIu64 "\n", ui);
666 failcount++;
667 }
668 }
669
670 if (passed)
671 printf("Ok\n");
672 else
673 printf("Test failed in %" PRIu64 " cases\n", failcount);
674}
675
676void
595init_coord() 677init_coord()
596{ 678{
597 static bool initialized = false; 679 static bool initialized = false;

Generated with cgit - Back to sebastiano.tronto.net