diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-01 09:33:26 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-01 09:33:26 +0200 |
| commit | b0053277e385bee23336d1fe6b69a12f49f9172f (patch) | |
| tree | 531e44cd6f8e807c991d0a46692140667939fbe3 /src/core | |
| parent | b6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690 (diff) | |
| download | nissy-core-b0053277e385bee23336d1fe6b69a12f49f9172f.tar.gz nissy-core-b0053277e385bee23336d1fe6b69a12f49f9172f.zip | |
simplified allowedmoves logic
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/moves.h | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index 11ac34e..1238c7d 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -1,15 +1,13 @@ | |||
| 1 | #define MOVE(M, c) compose(c, MOVE_CUBE_ ## M) | 1 | #define MOVE(M, c) compose(c, MOVE_CUBE_ ## M) |
| 2 | #define PREMOVE(M, c) compose(MOVE_CUBE_ ## M, c) | 2 | #define PREMOVE(M, c) compose(MOVE_CUBE_ ## M, c) |
| 3 | 3 | ||
| 4 | STATIC_INLINE bool allowednextmove(size_t n, const uint8_t [n]); | 4 | STATIC_INLINE bool allowednextmove(uint8_t, uint8_t); |
| 5 | STATIC_INLINE uint32_t allowednextmove_mask(size_t n, const uint8_t [n]); | ||
| 6 | STATIC bool allowedmoves(size_t n, const uint8_t [n]); | 5 | STATIC bool allowedmoves(size_t n, const uint8_t [n]); |
| 7 | 6 | ||
| 8 | STATIC_INLINE uint8_t movebase(uint8_t); | 7 | STATIC_INLINE uint8_t movebase(uint8_t); |
| 9 | STATIC_INLINE uint8_t moveaxis(uint8_t); | 8 | STATIC_INLINE uint8_t moveaxis(uint8_t); |
| 10 | STATIC_INLINE bool isbase(uint8_t); | 9 | STATIC_INLINE bool isbase(uint8_t); |
| 11 | STATIC_INLINE bool parallel(uint8_t, uint8_t); | 10 | STATIC_INLINE bool parallel(uint8_t, uint8_t); |
| 12 | STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); | ||
| 13 | 11 | ||
| 14 | STATIC cube_t move(cube_t, uint8_t); | 12 | STATIC cube_t move(cube_t, uint8_t); |
| 15 | STATIC cube_t premove(cube_t, uint8_t); | 13 | STATIC cube_t premove(cube_t, uint8_t); |
| @@ -38,60 +36,24 @@ STATIC cube_t applymoves(cube_t, const char *); | |||
| 38 | ARG_ACTION \ | 36 | ARG_ACTION \ |
| 39 | } | 37 | } |
| 40 | 38 | ||
| 41 | STATIC bool | 39 | STATIC_INLINE bool |
| 42 | allowednextmove(size_t n, const uint8_t moves[n]) | 40 | allowednextmove(uint8_t m1, uint8_t m2) |
| 43 | { | 41 | { |
| 44 | return n == 0 || allowednextmove_mask(n-1, moves) & (1 << moves[n-1]); | 42 | return allowedmask[movebase(m1)] & (UINT32_C(1) << m2); |
| 45 | } | ||
| 46 | |||
| 47 | STATIC uint32_t | ||
| 48 | allowednextmove_mask(size_t n, const uint8_t moves[n]) | ||
| 49 | { | ||
| 50 | uint32_t result; | ||
| 51 | uint8_t base1, base2, axis1, axis2; | ||
| 52 | |||
| 53 | result = MM_ALLMOVES; | ||
| 54 | |||
| 55 | if (n == 0) | ||
| 56 | return result; | ||
| 57 | |||
| 58 | base1 = movebase(moves[n-1]); | ||
| 59 | axis1 = moveaxis(moves[n-1]); | ||
| 60 | result = disable_moves(result, base1 * 3); | ||
| 61 | |||
| 62 | if (base1 % 2) | ||
| 63 | result = disable_moves(result, (base1 - 1) * 3); | ||
| 64 | |||
| 65 | if (n == 1) | ||
| 66 | return result; | ||
| 67 | |||
| 68 | base2 = movebase(moves[n-2]); | ||
| 69 | axis2 = moveaxis(moves[n-2]); | ||
| 70 | |||
| 71 | if(axis1 == axis2) | ||
| 72 | result = disable_moves(result, base2 * 3); | ||
| 73 | |||
| 74 | return result; | ||
| 75 | } | 43 | } |
| 76 | 44 | ||
| 77 | STATIC bool | 45 | STATIC bool |
| 78 | allowedmoves(size_t n, const uint8_t moves[n]) | 46 | allowedmoves(size_t n, const uint8_t m[n]) |
| 79 | { | 47 | { |
| 80 | uint8_t j; | 48 | uint8_t j; |
| 81 | 49 | ||
| 82 | for (j = 2; j < n; j++) | 50 | for (j = 1; j < n; j++) |
| 83 | if (!allowednextmove(j, moves)) | 51 | if (!allowednextmove(m[j-1], m[j])) |
| 84 | return false; | 52 | return false; |
| 85 | 53 | ||
| 86 | return true; | 54 | return true; |
| 87 | } | 55 | } |
| 88 | 56 | ||
| 89 | STATIC_INLINE uint32_t | ||
| 90 | disable_moves(uint32_t current_result, uint8_t base_index) | ||
| 91 | { | ||
| 92 | return current_result & ~MM_SIDE(base_index); | ||
| 93 | } | ||
| 94 | |||
| 95 | STATIC_INLINE uint8_t | 57 | STATIC_INLINE uint8_t |
| 96 | movebase(uint8_t move) | 58 | movebase(uint8_t move) |
| 97 | { | 59 | { |
