aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-15 16:55:01 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-15 17:21:49 +0100
commit99b746a01c11e061c4bd42cf096d27be9507ae21 (patch)
treea373a1930a987d5146b8a66abc993ce8a3c4644b
parentde70dc746f16607e2110f2c6acee8ed8ba2507f8 (diff)
downloadnissy-core-99b746a01c11e061c4bd42cf096d27be9507ae21.tar.gz
nissy-core-99b746a01c11e061c4bd42cf096d27be9507ae21.zip
Fix rare bug, but one more bug to go
-rw-r--r--src/core/moves.h12
-rw-r--r--src/solvers/h48/solve.h8
2 files changed, 16 insertions, 4 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index 037944b..3a1158b 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -12,6 +12,7 @@ STATIC cube_t move(cube_t, uint8_t);
12STATIC cube_t premove(cube_t, uint8_t); 12STATIC cube_t premove(cube_t, uint8_t);
13STATIC uint8_t inverse_move(uint8_t); 13STATIC uint8_t inverse_move(uint8_t);
14STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); 14STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *);
15STATIC void sortparallel(uint8_t *, uint8_t);
15 16
16STATIC int readmoves(const char *, int, uint8_t *); 17STATIC int readmoves(const char *, int, uint8_t *);
17STATIC cube_t applymoves(cube_t, const char *); 18STATIC cube_t applymoves(cube_t, const char *);
@@ -229,6 +230,17 @@ invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret)
229} 230}
230#pragma GCC pop_options 231#pragma GCC pop_options
231 232
233STATIC void
234sortparallel(uint8_t *moves, uint8_t n)
235{
236 uint8_t i;
237
238 for (i = 0; i < n-1; i++)
239 if (moveaxis(moves[i]) == moveaxis(moves[i+1]) &&
240 movebase(moves[i]) == movebase(moves[i+1]) + 1)
241 SWAP(moves[i], moves[i+1]);
242}
243
232STATIC int 244STATIC int
233readmoves(const char *buf, int max, uint8_t *ret) 245readmoves(const char *buf, int max, uint8_t *ret)
234{ 246{
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index c415370..9f0cb78 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -78,6 +78,9 @@ solve_h48_appendsolution(dfsarg_solve_h48_t *arg)
78 78
79 invertmoves(arg->premoves, arg->npremoves, arg->moves + arg->nmoves); 79 invertmoves(arg->premoves, arg->npremoves, arg->moves + arg->nmoves);
80 80
81 /* Sort parallel moves for consistency */
82 sortparallel(arg->moves, arg->nmoves + arg->npremoves);
83
81 /* Do not append the solution in case premoves cancel with normal */ 84 /* Do not append the solution in case premoves cancel with normal */
82 if (arg->npremoves > 0 && !allowednextmove(arg->moves, arg->nmoves+1)) 85 if (arg->npremoves > 0 && !allowednextmove(arg->moves, arg->nmoves+1))
83 return 0; 86 return 0;
@@ -106,10 +109,7 @@ solve_h48_appendallsym(dfsarg_solve_h48_t *arg)
106 all[j][i] = transform_move(arg->moves[i], t); 109 all[j][i] = transform_move(arg->moves[i], t);
107 110
108 /* Sort parallel moves for consistency */ 111 /* Sort parallel moves for consistency */
109 for (i = 0; i < n - 1; i++) 112 sortparallel(all[j], n);
110 if (moveaxis(all[j][i]) == moveaxis(all[j][i+1]) &&
111 movebase(all[j][i]) == movebase(all[j][i+1]) + 1)
112 SWAP(all[j][i], all[j][i+1]);
113 113
114 /* Check for duplicate solutions */ 114 /* Check for duplicate solutions */
115 for (k = 0; k < j; k++) { 115 for (k = 0; k < j; k++) {

Generated with cgit - Back to sebastiano.tronto.net