diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/constants.h | 4 | ||||
| -rw-r--r-- | src/cube.h | 5 | ||||
| -rw-r--r-- | src/cube_array.c | 75 | ||||
| -rw-r--r-- | test/05_transform/00_solved_UFr.in | 2 | ||||
| -rw-r--r-- | test/05_transform/00_solved_UFr.out | 1 | ||||
| -rw-r--r-- | test/05_transform/01_solved_BLm.in | 2 | ||||
| -rw-r--r-- | test/05_transform/01_solved_BLm.out | 1 | ||||
| -rw-r--r-- | test/05_transform/transform_tests.c | 38 | ||||
| -rw-r--r-- | utils/TRANSFORMATIONS.txt | 6 | ||||
| -rwxr-xr-x | utils/mirror.sh | 2 | ||||
| -rw-r--r-- | utils/transform_moves.txt | 95 |
12 files changed, 232 insertions, 2 deletions
| @@ -4,7 +4,8 @@ Work in progress. | |||
| 4 | 4 | ||
| 5 | TODO: | 5 | TODO: |
| 6 | 6 | ||
| 7 | * test SRC: scrambled cube, rename directory in io_SRC_write | 7 | * write script to generate tests for trans (see utils/transform_moves.txt) |
| 8 | * add tests for transformation | ||
| 8 | * implement transformations (use write to SRC to make life easier) | 9 | * implement transformations (use write to SRC to make life easier) |
| 9 | * setup benchmarks | 10 | * setup benchmarks |
| 10 | * coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym | 11 | * coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym |
diff --git a/src/constants.h b/src/constants.h index 54152bc..9e0a7a7 100644 --- a/src/constants.h +++ b/src/constants.h | |||
| @@ -69,3 +69,7 @@ | |||
| 69 | #define BRm 45 | 69 | #define BRm 45 |
| 70 | #define BDm 46 | 70 | #define BDm 46 |
| 71 | #define BLm 47 | 71 | #define BLm 47 |
| 72 | |||
| 73 | /* Errors */ | ||
| 74 | #define errormove 99U | ||
| 75 | #define errortrans 99U | ||
| @@ -21,7 +21,12 @@ bool iserror(cube_t); | |||
| 21 | int readmoves(char *, move_t *); | 21 | int readmoves(char *, move_t *); |
| 22 | void writemoves(move_t *, int, char *); | 22 | void writemoves(move_t *, int, char *); |
| 23 | 23 | ||
| 24 | trans_t readtrans(char *); | ||
| 25 | void writetrans(trans_t, char *); | ||
| 26 | |||
| 24 | cube_t move(cube_t, move_t); | 27 | cube_t move(cube_t, move_t); |
| 25 | cube_t inverse(cube_t); | 28 | cube_t inverse(cube_t); |
| 26 | cube_t compose(cube_t, cube_t); | 29 | cube_t compose(cube_t, cube_t); |
| 30 | |||
| 31 | /* See utils/TRANSFORMATIONS.txt for how transformations are applied */ | ||
| 27 | cube_t transform(cube_t, trans_t); | 32 | cube_t transform(cube_t, trans_t); |
diff --git a/src/cube_array.c b/src/cube_array.c index 1d2da86..cbf59e4 100644 --- a/src/cube_array.c +++ b/src/cube_array.c | |||
| @@ -120,6 +120,57 @@ static char *movestr[] = { | |||
| 120 | [B3] = "B'", | 120 | [B3] = "B'", |
| 121 | }; | 121 | }; |
| 122 | 122 | ||
| 123 | static char *transstr[] = { | ||
| 124 | [UFr] = "rotation UF", | ||
| 125 | [UFm] = "mirrored UF", | ||
| 126 | [ULr] = "rotation UL", | ||
| 127 | [ULm] = "mirrored UL", | ||
| 128 | [UBr] = "rotation UB", | ||
| 129 | [UBm] = "mirrored UB", | ||
| 130 | [URr] = "rotation UR", | ||
| 131 | [URm] = "mirrored UR", | ||
| 132 | [DFr] = "rotation DF", | ||
| 133 | [DFm] = "mirrored DF", | ||
| 134 | [DLr] = "rotation DL", | ||
| 135 | [DLm] = "mirrored DL", | ||
| 136 | [DBr] = "rotation DB", | ||
| 137 | [DBm] = "mirrored DB", | ||
| 138 | [DRr] = "rotation DR", | ||
| 139 | [DRm] = "mirrored DR", | ||
| 140 | [RUr] = "rotation RU", | ||
| 141 | [RUm] = "mirrored RU", | ||
| 142 | [RFr] = "rotation RF", | ||
| 143 | [RFm] = "mirrored RF", | ||
| 144 | [RDr] = "rotation RD", | ||
| 145 | [RDm] = "mirrored RD", | ||
| 146 | [RBr] = "rotation RB", | ||
| 147 | [RBm] = "mirrored RB", | ||
| 148 | [LUr] = "rotation LU", | ||
| 149 | [LUm] = "mirrored LU", | ||
| 150 | [LFr] = "rotation LF", | ||
| 151 | [LFm] = "mirrored LF", | ||
| 152 | [LDr] = "rotation LD", | ||
| 153 | [LDm] = "mirrored LD", | ||
| 154 | [LBr] = "rotation LB", | ||
| 155 | [LBm] = "mirrored LB", | ||
| 156 | [FUr] = "rotation FU", | ||
| 157 | [FUm] = "mirrored FU", | ||
| 158 | [FRr] = "rotation FR", | ||
| 159 | [FRm] = "mirrored FR", | ||
| 160 | [FDr] = "rotation FD", | ||
| 161 | [FDm] = "mirrored FD", | ||
| 162 | [FLr] = "rotation FL", | ||
| 163 | [FLm] = "mirrored FL", | ||
| 164 | [BUr] = "rotation BU", | ||
| 165 | [BUm] = "mirrored BU", | ||
| 166 | [BRr] = "rotation BR", | ||
| 167 | [BRm] = "mirrored BR", | ||
| 168 | [BDr] = "rotation BD", | ||
| 169 | [BDm] = "mirrored BD", | ||
| 170 | [BLr] = "rotation BL", | ||
| 171 | [BLm] = "mirrored BL", | ||
| 172 | }; | ||
| 173 | |||
| 123 | cube_t solvedcube = { | 174 | cube_t solvedcube = { |
| 124 | .c = { | 175 | .c = { |
| 125 | [_c_ufr] = _c_ufr, | 176 | [_c_ufr] = _c_ufr, |
| @@ -452,6 +503,21 @@ readmoves_error: | |||
| 452 | return -1; | 503 | return -1; |
| 453 | } | 504 | } |
| 454 | 505 | ||
| 506 | trans_t | ||
| 507 | readtrans(char *buf) | ||
| 508 | { | ||
| 509 | uint8_t t; | ||
| 510 | |||
| 511 | for (t = 0; t < 48; t++) | ||
| 512 | if (!strncmp(buf, transstr[t], 11)) | ||
| 513 | return t; | ||
| 514 | |||
| 515 | #ifdef DEBUG | ||
| 516 | fprintf(stderr, "readtrans error\n"); | ||
| 517 | #endif | ||
| 518 | return errortrans; | ||
| 519 | } | ||
| 520 | |||
| 455 | void | 521 | void |
| 456 | writemoves(move_t *m, int n, char *buf) | 522 | writemoves(move_t *m, int n, char *buf) |
| 457 | { | 523 | { |
| @@ -469,6 +535,15 @@ writemoves(move_t *m, int n, char *buf) | |||
| 469 | *b = '\0'; | 535 | *b = '\0'; |
| 470 | } | 536 | } |
| 471 | 537 | ||
| 538 | void | ||
| 539 | writetrans(trans_t t, char *buf) | ||
| 540 | { | ||
| 541 | if (t >= 48) | ||
| 542 | memcpy(buf, "error trans", 11); | ||
| 543 | else | ||
| 544 | memcpy(buf, transstr[t], 11); | ||
| 545 | buf[11] = '\0'; | ||
| 546 | } | ||
| 472 | 547 | ||
| 473 | static int | 548 | static int |
| 474 | permsign(uint8_t *a, int n) | 549 | permsign(uint8_t *a, int n) |
diff --git a/test/05_transform/00_solved_UFr.in b/test/05_transform/00_solved_UFr.in new file mode 100644 index 0000000..aa89e85 --- /dev/null +++ b/test/05_transform/00_solved_UFr.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | rotation UF | ||
| 2 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
diff --git a/test/05_transform/00_solved_UFr.out b/test/05_transform/00_solved_UFr.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/05_transform/00_solved_UFr.out | |||
| @@ -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/05_transform/01_solved_BLm.in b/test/05_transform/01_solved_BLm.in new file mode 100644 index 0000000..43aadb8 --- /dev/null +++ b/test/05_transform/01_solved_BLm.in | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | mirrored BL | ||
| 2 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
diff --git a/test/05_transform/01_solved_BLm.out b/test/05_transform/01_solved_BLm.out new file mode 100644 index 0000000..dff224d --- /dev/null +++ b/test/05_transform/01_solved_BLm.out | |||
| @@ -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/05_transform/transform_tests.c b/test/05_transform/transform_tests.c new file mode 100644 index 0000000..c648662 --- /dev/null +++ b/test/05_transform/transform_tests.c | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | #include "../../src/cube.h" | ||
| 6 | #include "../../src/constants.h" | ||
| 7 | |||
| 8 | #define STRLENMAX 10000 | ||
| 9 | |||
| 10 | int main() { | ||
| 11 | char str[STRLENMAX]; | ||
| 12 | trans_t t; | ||
| 13 | cube_t cube; | ||
| 14 | |||
| 15 | fgets(str, STRLENMAX, stdin); | ||
| 16 | t = readtrans(str); | ||
| 17 | |||
| 18 | if (t == errortrans) { | ||
| 19 | printf("Error reading trans\n"); | ||
| 20 | return 1; | ||
| 21 | } | ||
| 22 | |||
| 23 | fgets(str, STRLENMAX, stdin); | ||
| 24 | cube = readcube(H48, str); | ||
| 25 | |||
| 26 | cube = transform(cube, t); | ||
| 27 | |||
| 28 | if (iserror(cube)) { | ||
| 29 | printf("Error transforming cube\n"); | ||
| 30 | } else if (!issolvable(cube)) { | ||
| 31 | printf("Transformed cube is not solvable\n"); | ||
| 32 | } else { | ||
| 33 | writecube(H48, cube, str); | ||
| 34 | printf("%s\n", str); | ||
| 35 | } | ||
| 36 | |||
| 37 | return 0; | ||
| 38 | } | ||
diff --git a/utils/TRANSFORMATIONS.txt b/utils/TRANSFORMATIONS.txt index 6ff6946..58446e8 100644 --- a/utils/TRANSFORMATIONS.txt +++ b/utils/TRANSFORMATIONS.txt | |||
| @@ -8,6 +8,12 @@ the rotation that brings the F face on top and the D face on front. | |||
| 8 | A composed rotation + mirror is obtained by applying the corresponding | 8 | A composed rotation + mirror is obtained by applying the corresponding |
| 9 | rotation to the solved cube mirrored along the M plane. | 9 | rotation to the solved cube mirrored along the M plane. |
| 10 | 10 | ||
| 11 | For example, to apply the transformation RBm (mirrored RB) to a cube C: | ||
| 12 | 1a. Apply a mirror along the M plane to the solved cube | ||
| 13 | 1b. Rotate the mirrored cube with z' y2 | ||
| 14 | 3. Apply the cube C to the transformed solved cube | ||
| 15 | 4. Apply the transformations of step 1a and 1b in reverse | ||
| 16 | |||
| 11 | The orientation of pieces after a rotation ignores the new position | 17 | The orientation of pieces after a rotation ignores the new position |
| 12 | of centers. A rotated cube can technically be inconsistent, because | 18 | of centers. A rotated cube can technically be inconsistent, because |
| 13 | the parity of the edge permutation has to be adjusted considering the | 19 | the parity of the edge permutation has to be adjusted considering the |
diff --git a/utils/mirror.sh b/utils/mirror.sh index 57b02d1..41a434f 100755 --- a/utils/mirror.sh +++ b/utils/mirror.sh | |||
| @@ -1,3 +1,3 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | sed 's/R/l/g ; s/L/R/g ; s/l/L/g' | 3 | tr 'LR' 'RL' |
diff --git a/utils/transform_moves.txt b/utils/transform_moves.txt new file mode 100644 index 0000000..469008b --- /dev/null +++ b/utils/transform_moves.txt | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | UFr U U | ||
| 2 | UFr R R | ||
| 3 | UFr F F | ||
| 4 | |||
| 5 | ULr U U | ||
| 6 | ULr R F | ||
| 7 | ULr F L | ||
| 8 | |||
| 9 | UBr U U | ||
| 10 | UBr R L | ||
| 11 | UBr F B | ||
| 12 | |||
| 13 | URr U U | ||
| 14 | URr R B | ||
| 15 | URr F R | ||
| 16 | |||
| 17 | DFr U D | ||
| 18 | DFr R L | ||
| 19 | DFr F F | ||
| 20 | |||
| 21 | DLr U D | ||
| 22 | DLr R B | ||
| 23 | DLr F L | ||
| 24 | |||
| 25 | DBr U D | ||
| 26 | DBr R R | ||
| 27 | DBr F B | ||
| 28 | |||
| 29 | DRr U D | ||
| 30 | DRr R F | ||
| 31 | DRr F R | ||
| 32 | |||
| 33 | RUr U R | ||
| 34 | RUr R F | ||
| 35 | RUr F U | ||
| 36 | |||
| 37 | RFr U R | ||
| 38 | RFr R D | ||
| 39 | RFr F F | ||
| 40 | |||
| 41 | RDr U R | ||
| 42 | RDr R B | ||
| 43 | RDr F D | ||
| 44 | |||
| 45 | RBr U R | ||
| 46 | RBr R U | ||
| 47 | RBr F B | ||
| 48 | |||
| 49 | LUr U L | ||
| 50 | LUr R B | ||
| 51 | LUr F U | ||
| 52 | |||
| 53 | LFr U L | ||
| 54 | LFr R U | ||
| 55 | LFr F F | ||
| 56 | |||
| 57 | LDr U L | ||
| 58 | LDr R F | ||
| 59 | LDr F D | ||
| 60 | |||
| 61 | LBr U L | ||
| 62 | LBr R D | ||
| 63 | LBr F B | ||
| 64 | |||
| 65 | FUr U F | ||
| 66 | FUr R L | ||
| 67 | FUr F U | ||
| 68 | |||
| 69 | FRr U F | ||
| 70 | FRr R U | ||
| 71 | FRr F R | ||
| 72 | |||
| 73 | FDr U F | ||
| 74 | FDr R R | ||
| 75 | FDr F D | ||
| 76 | |||
| 77 | FLr U F | ||
| 78 | FLr R D | ||
| 79 | FLr F L | ||
| 80 | |||
| 81 | BUr U B | ||
| 82 | BUr R R | ||
| 83 | BUr F U | ||
| 84 | |||
| 85 | BRr U B | ||
| 86 | BRr R D | ||
| 87 | BRr F R | ||
| 88 | |||
| 89 | BDr U B | ||
| 90 | BDr R L | ||
| 91 | BDr F D | ||
| 92 | |||
| 93 | BLr U B | ||
| 94 | BLr R U | ||
| 95 | BLr F L | ||
