diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-22 06:43:11 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-22 18:45:47 +0100 |
| commit | ce3f1cc0ef9f46d70ab5387b1458e9098b40711d (patch) | |
| tree | 4949745670b829f2211381bf14b8440dcc6ca7b1 /src/core/moves.h | |
| parent | 0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd (diff) | |
| download | nissy-core-ce3f1cc0ef9f46d70ab5387b1458e9098b40711d.tar.gz nissy-core-ce3f1cc0ef9f46d70ab5387b1458e9098b40711d.zip | |
Some safety with move arrays, small refactor appendchar
Diffstat (limited to 'src/core/moves.h')
| -rw-r--r-- | src/core/moves.h | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index a45bc05..820406b 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -1,8 +1,8 @@ | |||
| 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(uint8_t *, uint8_t); | 4 | STATIC_INLINE bool allowednextmove(size_t n, const uint8_t [n]); |
| 5 | STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t); | 5 | STATIC_INLINE uint32_t allowednextmove_mask(size_t n, const uint8_t [n]); |
| 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); |
| @@ -13,9 +13,9 @@ STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); | |||
| 13 | STATIC cube_t move(cube_t, uint8_t); | 13 | STATIC cube_t move(cube_t, uint8_t); |
| 14 | STATIC cube_t premove(cube_t, uint8_t); | 14 | STATIC cube_t premove(cube_t, uint8_t); |
| 15 | STATIC uint8_t inverse_move(uint8_t); | 15 | STATIC uint8_t inverse_move(uint8_t); |
| 16 | STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); | 16 | STATIC void invertmoves(size_t n, const uint8_t [n], uint8_t [n]); |
| 17 | STATIC void sortparallel(uint8_t *, uint8_t); | 17 | STATIC void sortparallel(size_t n, uint8_t [n]); |
| 18 | STATIC bool are_lastmoves_singlecw(int n, uint8_t [n]); | 18 | STATIC bool are_lastmoves_singlecw(size_t n, uint8_t [n]); |
| 19 | 19 | ||
| 20 | STATIC int readmoves(const char *, int, uint8_t *); | 20 | STATIC int readmoves(const char *, int, uint8_t *); |
| 21 | STATIC cube_t applymoves(cube_t, const char *); | 21 | STATIC cube_t applymoves(cube_t, const char *); |
| @@ -40,14 +40,13 @@ STATIC cube_t applymoves(cube_t, const char *); | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | STATIC bool | 42 | STATIC bool |
| 43 | allowednextmove(uint8_t *moves, uint8_t n) | 43 | allowednextmove(size_t n, const uint8_t moves[n]) |
| 44 | { | 44 | { |
| 45 | return n == 0 ? true : | 45 | return n == 0 || allowednextmove_mask(n-1, moves) & (1 << moves[n-1]); |
| 46 | allowednextmove_mask(moves, n-1) & (1 << moves[n-1]); | ||
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | STATIC uint32_t | 48 | STATIC uint32_t |
| 50 | allowednextmove_mask(uint8_t *moves, uint8_t n) | 49 | allowednextmove_mask(size_t n, const uint8_t moves[n]) |
| 51 | { | 50 | { |
| 52 | uint32_t result; | 51 | uint32_t result; |
| 53 | uint8_t base1, base2, axis1, axis2; | 52 | uint8_t base1, base2, axis1, axis2; |
| @@ -79,7 +78,7 @@ allowednextmove_mask(uint8_t *moves, uint8_t n) | |||
| 79 | STATIC_INLINE uint32_t | 78 | STATIC_INLINE uint32_t |
| 80 | disable_moves(uint32_t current_result, uint8_t base_index) | 79 | disable_moves(uint32_t current_result, uint8_t base_index) |
| 81 | { | 80 | { |
| 82 | return current_result & ~(7 << base_index); | 81 | return current_result & ~MM_SIDE(base_index); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | STATIC_INLINE uint8_t | 84 | STATIC_INLINE uint8_t |
| @@ -236,17 +235,17 @@ TODO check if the issue is resolved | |||
| 236 | #pragma GCC push_options | 235 | #pragma GCC push_options |
| 237 | #pragma GCC optimize ("O2") | 236 | #pragma GCC optimize ("O2") |
| 238 | STATIC void | 237 | STATIC void |
| 239 | invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) | 238 | invertmoves(size_t n, const uint8_t moves[n], uint8_t ret[n]) |
| 240 | { | 239 | { |
| 241 | uint8_t i; | 240 | uint8_t i; |
| 242 | 241 | ||
| 243 | for (i = 0; i < nmoves; i++) | 242 | for (i = 0; i < n; i++) |
| 244 | ret[i] = inverse_move(moves[nmoves - i - 1]); | 243 | ret[i] = inverse_move(moves[n - i - 1]); |
| 245 | } | 244 | } |
| 246 | #pragma GCC pop_options | 245 | #pragma GCC pop_options |
| 247 | 246 | ||
| 248 | STATIC void | 247 | STATIC void |
| 249 | sortparallel(uint8_t *moves, uint8_t n) | 248 | sortparallel(size_t n, uint8_t moves[n]) |
| 250 | { | 249 | { |
| 251 | uint8_t i; | 250 | uint8_t i; |
| 252 | 251 | ||
| @@ -257,7 +256,7 @@ sortparallel(uint8_t *moves, uint8_t n) | |||
| 257 | } | 256 | } |
| 258 | 257 | ||
| 259 | STATIC bool | 258 | STATIC bool |
| 260 | are_lastmoves_singlecw(int n, uint8_t moves[n]) | 259 | are_lastmoves_singlecw(size_t n, uint8_t moves[n]) |
| 261 | { | 260 | { |
| 262 | bool two; | 261 | bool two; |
| 263 | 262 | ||
