diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-19 17:16:41 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-19 17:16:41 +0100 |
| commit | 0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd (patch) | |
| tree | 3051a8267f1050e172d5e799ef0c20fb608d9a74 /src | |
| parent | ab95e3801f6659aa6b25ebd9a69b2e23dded130e (diff) | |
| download | nissy-core-0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd.tar.gz nissy-core-0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd.zip | |
Filter solutions for coordinate solver and fix ordering
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/moves.h | 28 | ||||
| -rw-r--r-- | src/solvers/coord/eo.h | 1 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 8 | ||||
| -rw-r--r-- | src/solvers/coord/types_macros.h | 1 |
4 files changed, 35 insertions, 3 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index 3a1158b..a45bc05 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -6,6 +6,8 @@ STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t); | |||
| 6 | 6 | ||
| 7 | STATIC_INLINE uint8_t movebase(uint8_t); | 7 | STATIC_INLINE uint8_t movebase(uint8_t); |
| 8 | STATIC_INLINE uint8_t moveaxis(uint8_t); | 8 | STATIC_INLINE uint8_t moveaxis(uint8_t); |
| 9 | STATIC_INLINE bool isbase(uint8_t); | ||
| 10 | STATIC_INLINE bool parallel(uint8_t, uint8_t); | ||
| 9 | STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); | 11 | STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); |
| 10 | 12 | ||
| 11 | STATIC cube_t move(cube_t, uint8_t); | 13 | STATIC cube_t move(cube_t, uint8_t); |
| @@ -13,6 +15,7 @@ STATIC cube_t premove(cube_t, uint8_t); | |||
| 13 | STATIC uint8_t inverse_move(uint8_t); | 15 | STATIC uint8_t inverse_move(uint8_t); |
| 14 | STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); | 16 | STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); |
| 15 | STATIC void sortparallel(uint8_t *, uint8_t); | 17 | STATIC void sortparallel(uint8_t *, uint8_t); |
| 18 | STATIC bool are_lastmoves_singlecw(int n, uint8_t [n]); | ||
| 16 | 19 | ||
| 17 | STATIC int readmoves(const char *, int, uint8_t *); | 20 | STATIC int readmoves(const char *, int, uint8_t *); |
| 18 | STATIC cube_t applymoves(cube_t, const char *); | 21 | STATIC cube_t applymoves(cube_t, const char *); |
| @@ -91,6 +94,18 @@ moveaxis(uint8_t move) | |||
| 91 | return move / 6; | 94 | return move / 6; |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 97 | STATIC_INLINE bool | ||
| 98 | isbase(uint8_t move) | ||
| 99 | { | ||
| 100 | return move == 3 * movebase(move); | ||
| 101 | } | ||
| 102 | |||
| 103 | STATIC_INLINE bool | ||
| 104 | parallel(uint8_t m1, uint8_t m2) | ||
| 105 | { | ||
| 106 | return moveaxis(m1) == moveaxis(m2); | ||
| 107 | } | ||
| 108 | |||
| 94 | STATIC_INLINE uint8_t | 109 | STATIC_INLINE uint8_t |
| 95 | moveopposite(uint8_t move) | 110 | moveopposite(uint8_t move) |
| 96 | { | 111 | { |
| @@ -241,6 +256,19 @@ sortparallel(uint8_t *moves, uint8_t n) | |||
| 241 | SWAP(moves[i], moves[i+1]); | 256 | SWAP(moves[i], moves[i+1]); |
| 242 | } | 257 | } |
| 243 | 258 | ||
| 259 | STATIC bool | ||
| 260 | are_lastmoves_singlecw(int n, uint8_t moves[n]) | ||
| 261 | { | ||
| 262 | bool two; | ||
| 263 | |||
| 264 | if (n == 0) | ||
| 265 | return true; | ||
| 266 | |||
| 267 | two = n > 1 && parallel(moves[n-1], moves[n-2]); | ||
| 268 | |||
| 269 | return isbase(moves[n-1]) && (!two || isbase(moves[n-2])); | ||
| 270 | } | ||
| 271 | |||
| 244 | STATIC int | 272 | STATIC int |
| 245 | readmoves(const char *buf, int max, uint8_t *ret) | 273 | readmoves(const char *buf, int max, uint8_t *ret) |
| 246 | { | 274 | { |
diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h index 449397f..46a6f70 100644 --- a/src/solvers/coord/eo.h +++ b/src/solvers/coord/eo.h | |||
| @@ -15,6 +15,7 @@ STATIC coord_t coordinate_eo = { | |||
| 15 | [AXIS_RL] = TRANS_URr, | 15 | [AXIS_RL] = TRANS_URr, |
| 16 | [AXIS_FB] = TRANS_UFr, | 16 | [AXIS_FB] = TRANS_UFr, |
| 17 | }, | 17 | }, |
| 18 | .is_admissible = &are_lastmoves_singlecw, | ||
| 18 | }; | 19 | }; |
| 19 | 20 | ||
| 20 | STATIC uint64_t | 21 | STATIC uint64_t |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index 73ae9b1..6903d1e 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -35,15 +35,17 @@ solve_coord_appendsolution(dfsarg_solve_coord_t *arg) | |||
| 35 | char *m; | 35 | char *m; |
| 36 | 36 | ||
| 37 | if (*arg->nsols >= arg->maxsolutions || | 37 | if (*arg->nsols >= arg->maxsolutions || |
| 38 | arg->nmoves > *arg->shortest_sol + arg->optimal) | 38 | arg->nmoves > *arg->shortest_sol + arg->optimal || |
| 39 | (arg->coord->is_admissible != NULL && | ||
| 40 | !arg->coord->is_admissible(arg->nmoves, arg->moves))) | ||
| 39 | return 0; | 41 | return 0; |
| 40 | 42 | ||
| 41 | sortparallel(arg->moves, arg->nmoves); | ||
| 42 | |||
| 43 | t = inverse_trans(arg->trans); | 43 | t = inverse_trans(arg->trans); |
| 44 | for (i = 0; i < arg->nmoves; i++) | 44 | for (i = 0; i < arg->nmoves; i++) |
| 45 | tmoves[i] = transform_move(arg->moves[i], t); | 45 | tmoves[i] = transform_move(arg->moves[i], t); |
| 46 | 46 | ||
| 47 | sortparallel(tmoves, arg->nmoves); | ||
| 48 | |||
| 47 | l = arg->solutions_size - *arg->solutions_used; | 49 | l = arg->solutions_size - *arg->solutions_used; |
| 48 | m = *arg->solutions + *arg->solutions_used; | 50 | m = *arg->solutions + *arg->solutions_used; |
| 49 | strl = writemoves(tmoves, arg->nmoves, l, m); | 51 | strl = writemoves(tmoves, arg->nmoves, l, m); |
diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index 84085ad..2309efc 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h | |||
| @@ -11,4 +11,5 @@ typedef struct { | |||
| 11 | uint32_t moves_mask; | 11 | uint32_t moves_mask; |
| 12 | uint64_t trans_mask; | 12 | uint64_t trans_mask; |
| 13 | uint8_t axistrans[3]; | 13 | uint8_t axistrans[3]; |
| 14 | bool (*is_admissible)(int n, uint8_t [n]); | ||
| 14 | } coord_t; | 15 | } coord_t; |
