aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-23 21:34:06 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-23 21:34:06 +0200
commit17e5a9e1e2b241c67956651f87f40236467fe7d8 (patch)
tree00e9eb137f6b3be8e1d287f25b0ad24d6658a2b3 /src
parent9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0 (diff)
downloadnissy-core-17e5a9e1e2b241c67956651f87f40236467fe7d8.tar.gz
nissy-core-17e5a9e1e2b241c67956651f87f40236467fe7d8.zip
Added tests for inverse move
Diffstat (limited to 'src')
-rw-r--r--src/core/moves.h36
1 files changed, 30 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)
103STATIC int64_t 120STATIC int64_t
104readmoves(const char *buf, size_t n, uint8_t ret[n]) 121readmoves(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:
170STATIC_INLINE bool 188STATIC_INLINE bool
171allowednextmove(uint8_t m1, uint8_t m2) 189allowednextmove(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)
194STATIC_INLINE uint8_t 214STATIC_INLINE uint8_t
195moveaxis(uint8_t move) 215moveaxis(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)
209STATIC_INLINE bool 226STATIC_INLINE bool
210parallel(uint8_t m1, uint8_t m2) 227parallel(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)
405STATIC void 428STATIC void
406sortparallel_moves(size_t n, uint8_t moves[n]) 429sortparallel_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)

Generated with cgit - Back to sebastiano.tronto.net