diff options
34 files changed, 124 insertions, 12 deletions
| @@ -30,30 +30,54 @@ for benchmarks. | |||
| 30 | 30 | ||
| 31 | ## TODO: | 31 | ## TODO: |
| 32 | 32 | ||
| 33 | ### Documentation and interface | 33 | ### Coordinates |
| 34 | |||
| 35 | * inline some documentation as comments in cube.h or cube.c | ||
| 36 | * README.md (maybe convert to txt?) becomes the reference documentation | ||
| 37 | 34 | ||
| 38 | ### More features | 35 | * [done] eo |
| 36 | * co | ||
| 37 | * ep | ||
| 38 | * epsep | ||
| 39 | * cp | ||
| 40 | * cpsep | ||
| 41 | * cphtr | ||
| 39 | 42 | ||
| 40 | * move() that takes a string (alg) as input | 43 | What about symcoord? |
| 41 | * coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym | ||
| 42 | 44 | ||
| 43 | ### Solving | 45 | ### Solving |
| 44 | 46 | ||
| 45 | * Fixed depth | 47 | All solving functions take a cube and some parameters as input. |
| 46 | * pruning tables (1 bit per entry + fallback) | 48 | |
| 47 | * Takes as parameters the amount of memory to use and a FILE for the tables | 49 | * Depth [uint, <= 20]: all solvers work at fixed depth. The caller |
| 48 | * Use multi-move (up to 4/5 moves at once) | 50 | implementation can implement an A* search. |
| 51 | * Full [bool]: if false, stop at first solution found, otherwise | ||
| 52 | find all solutions at that depth. | ||
| 53 | * Table [uint8_t *]: table with all the necessare pre-computed info. | ||
| 54 | The table can be generated with a companion function, but reading | ||
| 55 | from and writing to file is delegated to the caller implementation. | ||
| 56 | |||
| 57 | Implement the following solvers: | ||
| 58 | * Slow: basic solver without any table. | ||
| 59 | * H48: one-bit-per-entry table + fallback, 48 symmetries and so on. | ||
| 60 | See planner. | ||
| 61 | * nxopt31: mostly for comparison. | ||
| 62 | * other nxopt solvers: make generic and take the type as parameter. | ||
| 63 | * Step solver: take a coordinate function and a moveset as a parameter. | ||
| 49 | 64 | ||
| 50 | ### cube.h changes | 65 | ### cube.h changes |
| 51 | 66 | ||
| 52 | * Consider removing zerocube() from the api | 67 | * Consider removing zerocube() from the api |
| 53 | * prefix public functions with nissy_ or something similar | 68 | * prefix public functions with nissy_ or something similar |
| 69 | * move() that takes a string (alg) as input | ||
| 70 | |||
| 71 | ### Documentation and interface | ||
| 54 | 72 | ||
| 55 | ### Future optimizations | 73 | * inline some documentation as comments in source code |
| 74 | * README.md (maybe convert to txt?) becomes the reference documentation | ||
| 75 | |||
| 76 | ### Optimizations | ||
| 56 | 77 | ||
| 78 | * Trans: don't do full compose, for some trans composing perm is enough. | ||
| 79 | Split out sumco() as a separate function and refactor, optimize. | ||
| 80 | * Use multi-move (up to 4/5 moves at once) | ||
| 57 | * CO is the worst part of moving, transforming and inverting. Try basing | 81 | * CO is the worst part of moving, transforming and inverting. Try basing |
| 58 | everything on representing the cube without CO and apply it only at the | 82 | everything on representing the cube without CO and apply it only at the |
| 59 | end to check that it is actually solved. | 83 | end to check that it is actually solved. |
| @@ -2104,6 +2104,19 @@ _compose(cube_t c1, cube_t c2) | |||
| 2104 | return ret; | 2104 | return ret; |
| 2105 | } | 2105 | } |
| 2106 | 2106 | ||
| 2107 | static inline int16_t | ||
| 2108 | _coord_eo(cube_t c) | ||
| 2109 | { | ||
| 2110 | cube_t eo, shifted; | ||
| 2111 | int mask; | ||
| 2112 | |||
| 2113 | eo = _mm256_and_si256(c, _eo_avx2); | ||
| 2114 | shifted = _mm256_slli_epi32(eo, 3); | ||
| 2115 | mask = _mm256_movemask_epi8(shifted); | ||
| 2116 | |||
| 2117 | return (int16_t)(mask >> 17); | ||
| 2118 | } | ||
| 2119 | |||
| 2107 | 2120 | ||
| 2108 | /****************************************************************************** | 2121 | /****************************************************************************** |
| 2109 | Section: portable fast methods | 2122 | Section: portable fast methods |
| @@ -3420,6 +3433,19 @@ _compose(cube_t c1, cube_t c2) | |||
| 3420 | return ret; | 3433 | return ret; |
| 3421 | } | 3434 | } |
| 3422 | 3435 | ||
| 3436 | static inline int16_t | ||
| 3437 | _coord_eo(cube_t c) | ||
| 3438 | { | ||
| 3439 | int i, p; | ||
| 3440 | int16_t ret; | ||
| 3441 | |||
| 3442 | ret = 0; | ||
| 3443 | for (i = 1, p = 1; i < 12; i++, p *= 2) | ||
| 3444 | ret += p * (c.e[i] >> 4); | ||
| 3445 | |||
| 3446 | return ret; | ||
| 3447 | } | ||
| 3448 | |||
| 3423 | 3449 | ||
| 3424 | #endif | 3450 | #endif |
| 3425 | 3451 | ||
| @@ -3696,3 +3722,9 @@ transform(cube_t c, trans_t t) | |||
| 3696 | return zerocube(); | 3722 | return zerocube(); |
| 3697 | } | 3723 | } |
| 3698 | } | 3724 | } |
| 3725 | |||
| 3726 | int16_t | ||
| 3727 | coord_eo(cube_t c) | ||
| 3728 | { | ||
| 3729 | return _coord_eo(c); | ||
| 3730 | } | ||
| @@ -31,3 +31,5 @@ cube_t move(cube_t, move_t); | |||
| 31 | cube_t inverse(cube_t); | 31 | cube_t inverse(cube_t); |
| 32 | cube_t compose(cube_t, cube_t); | 32 | cube_t compose(cube_t, cube_t); |
| 33 | cube_t transform(cube_t, trans_t); | 33 | cube_t transform(cube_t, trans_t); |
| 34 | |||
| 35 | int16_t coord_eo(cube_t); | ||
diff --git a/test/061_coord_eo/00_solved.in b/test/061_coord_eo/00_solved.in new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/061_coord_eo/00_solved.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | |||
diff --git a/test/061_coord_eo/00_solved.out b/test/061_coord_eo/00_solved.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/00_solved.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/01_U.in b/test/061_coord_eo/01_U.in new file mode 100644 index 0000000..b5b36ad --- /dev/null +++ b/test/061_coord_eo/01_U.in | |||
| @@ -0,0 +1 @@ | |||
| UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0 | |||
diff --git a/test/061_coord_eo/01_U.out b/test/061_coord_eo/01_U.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/01_U.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/02_U2.in b/test/061_coord_eo/02_U2.in new file mode 100644 index 0000000..316ad57 --- /dev/null +++ b/test/061_coord_eo/02_U2.in | |||
| @@ -0,0 +1 @@ | |||
| UB0 UF0 DB0 DF0 UL0 UR0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UBR0 UFL0 DFR0 DBL0 | |||
diff --git a/test/061_coord_eo/02_U2.out b/test/061_coord_eo/02_U2.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/02_U2.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/03_U3.in b/test/061_coord_eo/03_U3.in new file mode 100644 index 0000000..7721ab5 --- /dev/null +++ b/test/061_coord_eo/03_U3.in | |||
| @@ -0,0 +1 @@ | |||
| UL0 UR0 DB0 DF0 UF0 UB0 DL0 DR0 FR0 FL0 BL0 BR0 UFL0 UBR0 DFL0 DBR0 UBL0 UFR0 DFR0 DBL0 | |||
diff --git a/test/061_coord_eo/03_U3.out b/test/061_coord_eo/03_U3.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/03_U3.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/04_D.in b/test/061_coord_eo/04_D.in new file mode 100644 index 0000000..cf4f816 --- /dev/null +++ b/test/061_coord_eo/04_D.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DR0 DL0 UR0 UL0 DB0 DF0 FR0 FL0 BL0 BR0 UFR0 UBL0 DBL0 DFR0 UFL0 UBR0 DFL0 DBR0 | |||
diff --git a/test/061_coord_eo/04_D.out b/test/061_coord_eo/04_D.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/04_D.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/07_R.in b/test/061_coord_eo/07_R.in new file mode 100644 index 0000000..8c8fcb3 --- /dev/null +++ b/test/061_coord_eo/07_R.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 FR0 UL0 DL0 BR0 DR0 FL0 BL0 UR0 DFR2 UBL0 DFL0 UBR2 UFL0 UFR1 DBR1 DBL0 | |||
diff --git a/test/061_coord_eo/07_R.out b/test/061_coord_eo/07_R.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/07_R.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/08_R2.in b/test/061_coord_eo/08_R2.in new file mode 100644 index 0000000..90765e2 --- /dev/null +++ b/test/061_coord_eo/08_R2.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 DR0 UL0 DL0 UR0 BR0 FL0 BL0 FR0 DBR0 UBL0 DFL0 UFR0 UFL0 DFR0 UBR0 DBL0 | |||
diff --git a/test/061_coord_eo/08_R2.out b/test/061_coord_eo/08_R2.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/08_R2.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/10_L.in b/test/061_coord_eo/10_L.in new file mode 100644 index 0000000..0b0565c --- /dev/null +++ b/test/061_coord_eo/10_L.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 UB0 DB0 DF0 UR0 BL0 FL0 DR0 FR0 UL0 DL0 BR0 UFR0 DBL2 UFL2 DBR0 UBL1 UBR0 DFR0 DFL1 | |||
diff --git a/test/061_coord_eo/10_L.out b/test/061_coord_eo/10_L.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/10_L.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/13_F.in b/test/061_coord_eo/13_F.in new file mode 100644 index 0000000..e805af8 --- /dev/null +++ b/test/061_coord_eo/13_F.in | |||
| @@ -0,0 +1 @@ | |||
| FL1 UB0 DB0 FR1 UR0 UL0 DL0 DR0 UF1 DF1 BL0 BR0 UFL1 UBL0 DFR1 DBR0 DFL2 UBR0 UFR2 DBL0 | |||
diff --git a/test/061_coord_eo/13_F.out b/test/061_coord_eo/13_F.out new file mode 100644 index 0000000..2c60641 --- /dev/null +++ b/test/061_coord_eo/13_F.out | |||
| @@ -0,0 +1 @@ | |||
| 388 | |||
diff --git a/test/061_coord_eo/14_F2.in b/test/061_coord_eo/14_F2.in new file mode 100644 index 0000000..8aa701f --- /dev/null +++ b/test/061_coord_eo/14_F2.in | |||
| @@ -0,0 +1 @@ | |||
| DF0 UB0 DB0 UF0 UR0 UL0 DL0 DR0 FL0 FR0 BL0 BR0 DFL0 UBL0 UFR0 DBR0 DFR0 UBR0 UFL0 DBL0 | |||
diff --git a/test/061_coord_eo/14_F2.out b/test/061_coord_eo/14_F2.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/14_F2.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/15_F3.in b/test/061_coord_eo/15_F3.in new file mode 100644 index 0000000..40f1260 --- /dev/null +++ b/test/061_coord_eo/15_F3.in | |||
| @@ -0,0 +1 @@ | |||
| FR1 UB0 DB0 FL1 UR0 UL0 DL0 DR0 DF1 UF1 BL0 BR0 DFR1 UBL0 UFL1 DBR0 UFR2 UBR0 DFL2 DBL0 | |||
diff --git a/test/061_coord_eo/15_F3.out b/test/061_coord_eo/15_F3.out new file mode 100644 index 0000000..2c60641 --- /dev/null +++ b/test/061_coord_eo/15_F3.out | |||
| @@ -0,0 +1 @@ | |||
| 388 | |||
diff --git a/test/061_coord_eo/16_B.in b/test/061_coord_eo/16_B.in new file mode 100644 index 0000000..f7fb13c --- /dev/null +++ b/test/061_coord_eo/16_B.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 BR1 BL1 DF0 UR0 UL0 DL0 DR0 FR0 FL0 UB1 DB1 UFR0 UBR1 DFL0 DBL1 UFL0 DBR2 DFR0 UBL2 | |||
diff --git a/test/061_coord_eo/16_B.out b/test/061_coord_eo/16_B.out new file mode 100644 index 0000000..1fd9918 --- /dev/null +++ b/test/061_coord_eo/16_B.out | |||
| @@ -0,0 +1 @@ | |||
| 1539 | |||
diff --git a/test/061_coord_eo/17_B2.in b/test/061_coord_eo/17_B2.in new file mode 100644 index 0000000..9b33e35 --- /dev/null +++ b/test/061_coord_eo/17_B2.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 DB0 UB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BR0 BL0 UFR0 DBR0 DFL0 UBL0 UFL0 DBL0 DFR0 UBR0 | |||
diff --git a/test/061_coord_eo/17_B2.out b/test/061_coord_eo/17_B2.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/061_coord_eo/17_B2.out | |||
| @@ -0,0 +1 @@ | |||
| 0 | |||
diff --git a/test/061_coord_eo/18_B3.in b/test/061_coord_eo/18_B3.in new file mode 100644 index 0000000..1367517 --- /dev/null +++ b/test/061_coord_eo/18_B3.in | |||
| @@ -0,0 +1 @@ | |||
| UF0 BL1 BR1 DF0 UR0 UL0 DL0 DR0 FR0 FL0 DB1 UB1 UFR0 DBL1 DFL0 UBR1 UFL0 UBL2 DFR0 DBR2 | |||
diff --git a/test/061_coord_eo/18_B3.out b/test/061_coord_eo/18_B3.out new file mode 100644 index 0000000..1fd9918 --- /dev/null +++ b/test/061_coord_eo/18_B3.out | |||
| @@ -0,0 +1 @@ | |||
| 1539 | |||
diff --git a/test/061_coord_eo/20_scrambled.in b/test/061_coord_eo/20_scrambled.in new file mode 100644 index 0000000..274d30b --- /dev/null +++ b/test/061_coord_eo/20_scrambled.in | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | UL0 BL0 BR1 DL0 FR0 DF0 DB1 DR1 UB0 FL0 UF0 UR1 DFL0 UFR1 DBR1 UBR2 DBL2 DFR0 UFL1 UBL2 | ||
| 2 | |||
| 3 | // Scramble: U R D' L D' F L2 D L F B D2 B' L2 F U2 L2 D2 R2 L2 B' | ||
diff --git a/test/061_coord_eo/20_scrambled.out b/test/061_coord_eo/20_scrambled.out new file mode 100644 index 0000000..aa309cc --- /dev/null +++ b/test/061_coord_eo/20_scrambled.out | |||
| @@ -0,0 +1 @@ | |||
| 1122 | |||
diff --git a/test/061_coord_eo/coord_eo_tests.c b/test/061_coord_eo/coord_eo_tests.c new file mode 100644 index 0000000..3aed352 --- /dev/null +++ b/test/061_coord_eo/coord_eo_tests.c | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <inttypes.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | #include "../../cube.h" | ||
| 6 | |||
| 7 | #define STRLENMAX 10000 | ||
| 8 | |||
| 9 | int main() { | ||
| 10 | char str[STRLENMAX]; | ||
| 11 | cube_t cube; | ||
| 12 | int16_t result; | ||
| 13 | |||
| 14 | fgets(str, STRLENMAX, stdin); | ||
| 15 | cube = readcube(H48, str); | ||
| 16 | |||
| 17 | result = coord_eo(cube); | ||
| 18 | |||
| 19 | printf("%" PRId16 "\n", result); | ||
| 20 | |||
| 21 | return 0; | ||
| 22 | } | ||
