nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit 17e5a9e1e2b241c67956651f87f40236467fe7d8
parent 9c209afd81e4c51e4fc2717c0eeff4a5d116bcb0
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Wed, 23 Apr 2025 21:34:06 +0200

Added tests for inverse move

Diffstat:
Msrc/core/moves.h | 36++++++++++++++++++++++++++++++------
Atest/033_inverse_move/00_U.in | 1+
Atest/033_inverse_move/00_U.out | 1+
Atest/033_inverse_move/01_U2.in | 1+
Atest/033_inverse_move/01_U2.out | 1+
Atest/033_inverse_move/02_U3.in | 1+
Atest/033_inverse_move/02_U3.out | 1+
Atest/033_inverse_move/03_F.in | 1+
Atest/033_inverse_move/03_F.out | 1+
Atest/033_inverse_move/04_Uw.in | 1+
Atest/033_inverse_move/04_Uw.out | 1+
Atest/033_inverse_move/05_Rw2.in | 1+
Atest/033_inverse_move/05_Rw2.out | 1+
Atest/033_inverse_move/06_Bw3.in | 1+
Atest/033_inverse_move/06_Bw3.out | 1+
Atest/033_inverse_move/07_M.in | 1+
Atest/033_inverse_move/07_M.out | 1+
Atest/033_inverse_move/08_S2.in | 1+
Atest/033_inverse_move/08_S2.out | 1+
Atest/033_inverse_move/09_S3.in | 1+
Atest/033_inverse_move/09_S3.out | 1+
Atest/033_inverse_move/10_x3.in | 1+
Atest/033_inverse_move/10_x3.out | 1+
Atest/033_inverse_move/11_z2.in | 1+
Atest/033_inverse_move/11_z2.out | 1+
Atest/033_inverse_move/inverse_move_tests.c | 20++++++++++++++++++++
26 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/src/core/moves.h b/src/core/moves.h @@ -33,11 +33,28 @@ STATIC oriented_cube_t applymoves(oriented_cube_t, const char *); RET_ERROR, ARG_ACTION) \ const char *VAR_B; \ uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ + bool VAR_IN_PARENTHESES = false; \ for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ while (*VAR_B == ' ' || *VAR_B == '\t' || *VAR_B == '\n') \ VAR_B++; \ if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ break; \ + if (*VAR_B == '(') { \ + if (VAR_IN_PARENTHESES) { \ + LOG("Nested parentheses in move sequence\n"); \ + return RET_ERROR; \ + } \ + VAR_IN_PARENTHESES = true; \ + continue; \ + } \ + if (*VAR_B == ')') { \ + if (!VAR_IN_PARENTHESES) { \ + LOG("Mismatched ')' in move sequence\n"); \ + return RET_ERROR; \ + } \ + VAR_IN_PARENTHESES = false; \ + continue; \ + } \ if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ LOG("Unknown move: %c\n", *VAR_B); \ return RET_ERROR; \ @@ -103,6 +120,7 @@ readmodifier(char c) STATIC int64_t readmoves(const char *buf, size_t n, uint8_t ret[n]) { +// TODO: modify to accept NISS uint8_t m; uint64_t c; @@ -170,6 +188,8 @@ writemoves_error: STATIC_INLINE bool allowednextmove(uint8_t m1, uint8_t m2) { +// TODO: adjust allowedmask +// TODO: movemask is now 64 bits return allowedmask[movebase(m1)] & (UINT32_C(1) << m2); } @@ -194,9 +214,6 @@ movebase(uint8_t move) STATIC_INLINE uint8_t moveaxis(uint8_t move) { - if (move > MOVE_B3) - return UINT8_ERROR; - return move / 6; } @@ -209,6 +226,8 @@ isbase(uint8_t move) STATIC_INLINE bool parallel(uint8_t m1, uint8_t m2) { +// TODO add unit tests +//TODO fix the logic (maybe use moveaxis(movefollow)), then remove comment return moveaxis(m1) == moveaxis(m2); } @@ -303,7 +322,7 @@ move(cube_t c, uint8_t m) case MOVE_B3: return MOVE(B3, c); default: - LOG("move error: unknown move %" PRIu8 "\n", m); + LOG("move error: %" PRIu8 " is not a basic move\n", m); return ZERO_CUBE; } } @@ -313,10 +332,14 @@ transform_move(uint8_t m, uint8_t t) { uint8_t a, base, modifier; - a = moveaxis(m); - if (a == UINT8_ERROR) + if (m > MOVE_B3) { + LOG("transform_move: attempting to transform %s, but " + "transofrmations are only supported for basic moves\n", + movestr[m]); return UINT8_ERROR; + } + a = moveaxis(m); base = trans_move_table[t][a]; if (movebase(m) != 2 * a) base = moveopposite(base); @@ -405,6 +428,7 @@ inverse_move(uint8_t m) STATIC void sortparallel_moves(size_t n, uint8_t moves[n]) { +// TODO: fix for wide moves... uint8_t i; if (n < 2) diff --git a/test/033_inverse_move/00_U.in 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 @@ -0,0 +1 @@ +U' diff --git a/test/033_inverse_move/01_U2.in 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 @@ -0,0 +1 @@ +U2 diff --git a/test/033_inverse_move/02_U3.in 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 @@ -0,0 +1 @@ +U diff --git a/test/033_inverse_move/03_F.in 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 @@ -0,0 +1 @@ +F' diff --git a/test/033_inverse_move/04_Uw.in 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 @@ -0,0 +1 @@ +Uw' diff --git a/test/033_inverse_move/05_Rw2.in 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 @@ -0,0 +1 @@ +Rw2 diff --git a/test/033_inverse_move/06_Bw3.in 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 @@ -0,0 +1 @@ +Bw diff --git a/test/033_inverse_move/07_M.in 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 @@ -0,0 +1 @@ +M' diff --git a/test/033_inverse_move/08_S2.in 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 @@ -0,0 +1 @@ +S2 diff --git a/test/033_inverse_move/09_S3.in 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 @@ -0,0 +1 @@ +S diff --git a/test/033_inverse_move/10_x3.in 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 @@ -0,0 +1 @@ +x diff --git a/test/033_inverse_move/11_z2.in 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 @@ -0,0 +1 @@ +z2 diff --git a/test/033_inverse_move/inverse_move_tests.c b/test/033_inverse_move/inverse_move_tests.c @@ -0,0 +1,20 @@ +#include "../test.h" + +extern char *movestr[]; + +int64_t readmoves(const char *, size_t n, uint8_t [n]); +uint8_t inverse_move(uint8_t); + +void run(void) { + uint8_t moves[2]; + + char moves_string[STRLENMAX]; + + fgets(moves_string, STRLENMAX, stdin); + if (readmoves(moves_string, 2, moves) != 1) { + printf("Test error: cannot read moves\n"); + return; + } + + printf("%s\n", movestr[inverse_move(moves[0])]); +}