diff options
Diffstat (limited to '')
| -rw-r--r-- | src/coord.c | 86 |
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); | |||
| 13 | static Cube antindex_drud_eofb(uint64_t ind); | 13 | static Cube antindex_drud_eofb(uint64_t ind); |
| 14 | static Cube antindex_htr_drud(uint64_t ind); | 14 | static Cube antindex_htr_drud(uint64_t ind); |
| 15 | static Cube antindex_htrfin(uint64_t ind); | 15 | static Cube antindex_htrfin(uint64_t ind); |
| 16 | static Cube antindex_cpud_separate(uint64_t ind); | ||
| 16 | 17 | ||
| 17 | static uint64_t index_eofb(Cube cube); | 18 | static uint64_t index_eofb(Cube cube); |
| 18 | static uint64_t index_eofbepos(Cube cube); | 19 | static uint64_t index_eofbepos(Cube cube); |
| @@ -27,6 +28,7 @@ static uint64_t index_drud(Cube cube); | |||
| 27 | static uint64_t index_drud_eofb(Cube cube); | 28 | static uint64_t index_drud_eofb(Cube cube); |
| 28 | static uint64_t index_htr_drud(Cube cube); | 29 | static uint64_t index_htr_drud(Cube cube); |
| 29 | static uint64_t index_htrfin(Cube cube); | 30 | static uint64_t index_htrfin(Cube cube); |
| 31 | static uint64_t index_cpud_separate(Cube cube); | ||
| 30 | 32 | ||
| 31 | static void init_cphtr_cosets(); | 33 | static void init_cphtr_cosets(); |
| 32 | static void init_cphtr_left_cosets_bfs(int i, int c); | 34 | static 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 | ||
| 140 | Coordinate | ||
| 141 | coord_cpud_separate = { | ||
| 142 | .index = index_cpud_separate, | ||
| 143 | .cube = antindex_cpud_separate, | ||
| 144 | .max = BINOM8ON4, | ||
| 145 | }; | ||
| 146 | |||
| 138 | /* Antindexers ***************************************************************/ | 147 | /* Antindexers ***************************************************************/ |
| 139 | 148 | ||
| 140 | static Cube | 149 | static Cube |
| @@ -356,6 +365,31 @@ antindex_htrfin(uint64_t ind) | |||
| 356 | return ret; | 365 | return ret; |
| 357 | } | 366 | } |
| 358 | 367 | ||
| 368 | static Cube | ||
| 369 | antindex_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 | ||
| 361 | static uint64_t | 395 | static 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 | ||
| 514 | static uint64_t | ||
| 515 | index_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 | ||
| 594 | void | 651 | void |
| 652 | test_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 | |||
| 676 | void | ||
| 595 | init_coord() | 677 | init_coord() |
| 596 | { | 678 | { |
| 597 | static bool initialized = false; | 679 | static bool initialized = false; |
