diff options
Diffstat (limited to '')
26 files changed, 74 insertions, 6 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index 0d97172..dc580be 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -33,11 +33,28 @@ STATIC oriented_cube_t applymoves(oriented_cube_t, const char *); | |||
| 33 | RET_ERROR, ARG_ACTION) \ | 33 | RET_ERROR, ARG_ACTION) \ |
| 34 | const char *VAR_B; \ | 34 | const char *VAR_B; \ |
| 35 | uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ | 35 | uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ |
| 36 | bool VAR_IN_PARENTHESES = false; \ | ||
| 36 | for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ | 37 | for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ |
| 37 | while (*VAR_B == ' ' || *VAR_B == '\t' || *VAR_B == '\n') \ | 38 | while (*VAR_B == ' ' || *VAR_B == '\t' || *VAR_B == '\n') \ |
| 38 | VAR_B++; \ | 39 | VAR_B++; \ |
| 39 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ | 40 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ |
| 40 | break; \ | 41 | break; \ |
| 42 | if (*VAR_B == '(') { \ | ||
| 43 | if (VAR_IN_PARENTHESES) { \ | ||
| 44 | LOG("Nested parentheses in move sequence\n"); \ | ||
| 45 | return RET_ERROR; \ | ||
| 46 | } \ | ||
| 47 | VAR_IN_PARENTHESES = true; \ | ||
| 48 | continue; \ | ||
| 49 | } \ | ||
| 50 | if (*VAR_B == ')') { \ | ||
| 51 | if (!VAR_IN_PARENTHESES) { \ | ||
| 52 | LOG("Mismatched ')' in move sequence\n"); \ | ||
| 53 | return RET_ERROR; \ | ||
| 54 | } \ | ||
| 55 | VAR_IN_PARENTHESES = false; \ | ||
| 56 | continue; \ | ||
| 57 | } \ | ||
| 41 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ | 58 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ |
| 42 | LOG("Unknown move: %c\n", *VAR_B); \ | 59 | LOG("Unknown move: %c\n", *VAR_B); \ |
| 43 | return RET_ERROR; \ | 60 | return RET_ERROR; \ |
| @@ -103,6 +120,7 @@ readmodifier(char c) | |||
| 103 | STATIC int64_t | 120 | STATIC int64_t |
| 104 | readmoves(const char *buf, size_t n, uint8_t ret[n]) | 121 | readmoves(const char *buf, size_t n, uint8_t ret[n]) |
| 105 | { | 122 | { |
| 123 | // TODO: modify to accept NISS | ||
| 106 | uint8_t m; | 124 | uint8_t m; |
| 107 | uint64_t c; | 125 | uint64_t c; |
| 108 | 126 | ||
| @@ -170,6 +188,8 @@ writemoves_error: | |||
| 170 | STATIC_INLINE bool | 188 | STATIC_INLINE bool |
| 171 | allowednextmove(uint8_t m1, uint8_t m2) | 189 | allowednextmove(uint8_t m1, uint8_t m2) |
| 172 | { | 190 | { |
| 191 | // TODO: adjust allowedmask | ||
| 192 | // TODO: movemask is now 64 bits | ||
| 173 | return allowedmask[movebase(m1)] & (UINT32_C(1) << m2); | 193 | return allowedmask[movebase(m1)] & (UINT32_C(1) << m2); |
| 174 | } | 194 | } |
| 175 | 195 | ||
| @@ -194,9 +214,6 @@ movebase(uint8_t move) | |||
| 194 | STATIC_INLINE uint8_t | 214 | STATIC_INLINE uint8_t |
| 195 | moveaxis(uint8_t move) | 215 | moveaxis(uint8_t move) |
| 196 | { | 216 | { |
| 197 | if (move > MOVE_B3) | ||
| 198 | return UINT8_ERROR; | ||
| 199 | |||
| 200 | return move / 6; | 217 | return move / 6; |
| 201 | } | 218 | } |
| 202 | 219 | ||
| @@ -209,6 +226,8 @@ isbase(uint8_t move) | |||
| 209 | STATIC_INLINE bool | 226 | STATIC_INLINE bool |
| 210 | parallel(uint8_t m1, uint8_t m2) | 227 | parallel(uint8_t m1, uint8_t m2) |
| 211 | { | 228 | { |
| 229 | // TODO add unit tests | ||
| 230 | //TODO fix the logic (maybe use moveaxis(movefollow)), then remove comment | ||
| 212 | return moveaxis(m1) == moveaxis(m2); | 231 | return moveaxis(m1) == moveaxis(m2); |
| 213 | } | 232 | } |
| 214 | 233 | ||
| @@ -303,7 +322,7 @@ move(cube_t c, uint8_t m) | |||
| 303 | case MOVE_B3: | 322 | case MOVE_B3: |
| 304 | return MOVE(B3, c); | 323 | return MOVE(B3, c); |
| 305 | default: | 324 | default: |
| 306 | LOG("move error: unknown move %" PRIu8 "\n", m); | 325 | LOG("move error: %" PRIu8 " is not a basic move\n", m); |
| 307 | return ZERO_CUBE; | 326 | return ZERO_CUBE; |
| 308 | } | 327 | } |
| 309 | } | 328 | } |
| @@ -313,10 +332,14 @@ transform_move(uint8_t m, uint8_t t) | |||
| 313 | { | 332 | { |
| 314 | uint8_t a, base, modifier; | 333 | uint8_t a, base, modifier; |
| 315 | 334 | ||
| 316 | a = moveaxis(m); | 335 | if (m > MOVE_B3) { |
| 317 | if (a == UINT8_ERROR) | 336 | LOG("transform_move: attempting to transform %s, but " |
| 337 | "transofrmations are only supported for basic moves\n", | ||
| 338 | movestr[m]); | ||
| 318 | return UINT8_ERROR; | 339 | return UINT8_ERROR; |
| 340 | } | ||
| 319 | 341 | ||
| 342 | a = moveaxis(m); | ||
| 320 | base = trans_move_table[t][a]; | 343 | base = trans_move_table[t][a]; |
| 321 | if (movebase(m) != 2 * a) | 344 | if (movebase(m) != 2 * a) |
| 322 | base = moveopposite(base); | 345 | base = moveopposite(base); |
| @@ -405,6 +428,7 @@ inverse_move(uint8_t m) | |||
| 405 | STATIC void | 428 | STATIC void |
| 406 | sortparallel_moves(size_t n, uint8_t moves[n]) | 429 | sortparallel_moves(size_t n, uint8_t moves[n]) |
| 407 | { | 430 | { |
| 431 | // TODO: fix for wide moves... | ||
| 408 | uint8_t i; | 432 | uint8_t i; |
| 409 | 433 | ||
| 410 | if (n < 2) | 434 | if (n < 2) |
diff --git a/test/033_inverse_move/00_U.in b/test/033_inverse_move/00_U.in new file mode 100644 index 0000000..765140b --- /dev/null +++ b/test/033_inverse_move/00_U.in | |||
| @@ -0,0 +1 @@ | |||
| U | |||
diff --git a/test/033_inverse_move/00_U.out b/test/033_inverse_move/00_U.out new file mode 100644 index 0000000..ca934b4 --- /dev/null +++ b/test/033_inverse_move/00_U.out | |||
| @@ -0,0 +1 @@ | |||
| U' | |||
diff --git a/test/033_inverse_move/01_U2.in b/test/033_inverse_move/01_U2.in new file mode 100644 index 0000000..cd9971a --- /dev/null +++ b/test/033_inverse_move/01_U2.in | |||
| @@ -0,0 +1 @@ | |||
| U2 | |||
diff --git a/test/033_inverse_move/01_U2.out b/test/033_inverse_move/01_U2.out new file mode 100644 index 0000000..cd9971a --- /dev/null +++ b/test/033_inverse_move/01_U2.out | |||
| @@ -0,0 +1 @@ | |||
| U2 | |||
diff --git a/test/033_inverse_move/02_U3.in b/test/033_inverse_move/02_U3.in new file mode 100644 index 0000000..ca934b4 --- /dev/null +++ b/test/033_inverse_move/02_U3.in | |||
| @@ -0,0 +1 @@ | |||
| U' | |||
diff --git a/test/033_inverse_move/02_U3.out b/test/033_inverse_move/02_U3.out new file mode 100644 index 0000000..765140b --- /dev/null +++ b/test/033_inverse_move/02_U3.out | |||
| @@ -0,0 +1 @@ | |||
| U | |||
diff --git a/test/033_inverse_move/03_F.in b/test/033_inverse_move/03_F.in new file mode 100644 index 0000000..cf84443 --- /dev/null +++ b/test/033_inverse_move/03_F.in | |||
| @@ -0,0 +1 @@ | |||
| F | |||
diff --git a/test/033_inverse_move/03_F.out b/test/033_inverse_move/03_F.out new file mode 100644 index 0000000..6ab6e07 --- /dev/null +++ b/test/033_inverse_move/03_F.out | |||
| @@ -0,0 +1 @@ | |||
| F' | |||
diff --git a/test/033_inverse_move/04_Uw.in b/test/033_inverse_move/04_Uw.in new file mode 100644 index 0000000..9a3dc81 --- /dev/null +++ b/test/033_inverse_move/04_Uw.in | |||
| @@ -0,0 +1 @@ | |||
| Uw | |||
diff --git a/test/033_inverse_move/04_Uw.out b/test/033_inverse_move/04_Uw.out new file mode 100644 index 0000000..be58449 --- /dev/null +++ b/test/033_inverse_move/04_Uw.out | |||
| @@ -0,0 +1 @@ | |||
| Uw' | |||
diff --git a/test/033_inverse_move/05_Rw2.in b/test/033_inverse_move/05_Rw2.in new file mode 100644 index 0000000..e922aff --- /dev/null +++ b/test/033_inverse_move/05_Rw2.in | |||
| @@ -0,0 +1 @@ | |||
| Rw2 | |||
diff --git a/test/033_inverse_move/05_Rw2.out b/test/033_inverse_move/05_Rw2.out new file mode 100644 index 0000000..e922aff --- /dev/null +++ b/test/033_inverse_move/05_Rw2.out | |||
| @@ -0,0 +1 @@ | |||
| Rw2 | |||
diff --git a/test/033_inverse_move/06_Bw3.in b/test/033_inverse_move/06_Bw3.in new file mode 100644 index 0000000..0223066 --- /dev/null +++ b/test/033_inverse_move/06_Bw3.in | |||
| @@ -0,0 +1 @@ | |||
| Bw' | |||
diff --git a/test/033_inverse_move/06_Bw3.out b/test/033_inverse_move/06_Bw3.out new file mode 100644 index 0000000..51de48f --- /dev/null +++ b/test/033_inverse_move/06_Bw3.out | |||
| @@ -0,0 +1 @@ | |||
| Bw | |||
diff --git a/test/033_inverse_move/07_M.in b/test/033_inverse_move/07_M.in new file mode 100644 index 0000000..ab77689 --- /dev/null +++ b/test/033_inverse_move/07_M.in | |||
| @@ -0,0 +1 @@ | |||
| M | |||
diff --git a/test/033_inverse_move/07_M.out b/test/033_inverse_move/07_M.out new file mode 100644 index 0000000..f753133 --- /dev/null +++ b/test/033_inverse_move/07_M.out | |||
| @@ -0,0 +1 @@ | |||
| M' | |||
diff --git a/test/033_inverse_move/08_S2.in b/test/033_inverse_move/08_S2.in new file mode 100644 index 0000000..778c8ff --- /dev/null +++ b/test/033_inverse_move/08_S2.in | |||
| @@ -0,0 +1 @@ | |||
| S2 | |||
diff --git a/test/033_inverse_move/08_S2.out b/test/033_inverse_move/08_S2.out new file mode 100644 index 0000000..778c8ff --- /dev/null +++ b/test/033_inverse_move/08_S2.out | |||
| @@ -0,0 +1 @@ | |||
| S2 | |||
diff --git a/test/033_inverse_move/09_S3.in b/test/033_inverse_move/09_S3.in new file mode 100644 index 0000000..878cb3c --- /dev/null +++ b/test/033_inverse_move/09_S3.in | |||
| @@ -0,0 +1 @@ | |||
| S3 | |||
diff --git a/test/033_inverse_move/09_S3.out b/test/033_inverse_move/09_S3.out new file mode 100644 index 0000000..3762249 --- /dev/null +++ b/test/033_inverse_move/09_S3.out | |||
| @@ -0,0 +1 @@ | |||
| S | |||
diff --git a/test/033_inverse_move/10_x3.in b/test/033_inverse_move/10_x3.in new file mode 100644 index 0000000..4989755 --- /dev/null +++ b/test/033_inverse_move/10_x3.in | |||
| @@ -0,0 +1 @@ | |||
| x' | |||
diff --git a/test/033_inverse_move/10_x3.out b/test/033_inverse_move/10_x3.out new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/test/033_inverse_move/10_x3.out | |||
| @@ -0,0 +1 @@ | |||
| x | |||
diff --git a/test/033_inverse_move/11_z2.in b/test/033_inverse_move/11_z2.in new file mode 100644 index 0000000..67d0c15 --- /dev/null +++ b/test/033_inverse_move/11_z2.in | |||
| @@ -0,0 +1 @@ | |||
| z2 | |||
diff --git a/test/033_inverse_move/11_z2.out b/test/033_inverse_move/11_z2.out new file mode 100644 index 0000000..67d0c15 --- /dev/null +++ b/test/033_inverse_move/11_z2.out | |||
| @@ -0,0 +1 @@ | |||
| z2 | |||
diff --git a/test/033_inverse_move/inverse_move_tests.c b/test/033_inverse_move/inverse_move_tests.c new file mode 100644 index 0000000..dc9845c --- /dev/null +++ b/test/033_inverse_move/inverse_move_tests.c | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | extern char *movestr[]; | ||
| 4 | |||
| 5 | int64_t readmoves(const char *, size_t n, uint8_t [n]); | ||
| 6 | uint8_t inverse_move(uint8_t); | ||
| 7 | |||
| 8 | void run(void) { | ||
| 9 | uint8_t moves[2]; | ||
| 10 | |||
| 11 | char moves_string[STRLENMAX]; | ||
| 12 | |||
| 13 | fgets(moves_string, STRLENMAX, stdin); | ||
| 14 | if (readmoves(moves_string, 2, moves) != 1) { | ||
| 15 | printf("Test error: cannot read moves\n"); | ||
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 | printf("%s\n", movestr[inverse_move(moves[0])]); | ||
| 20 | } | ||
