aboutsummaryrefslogtreecommitdiff
path: root/src/core/moves.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-03-22 06:43:11 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-03-22 18:45:47 +0100
commitce3f1cc0ef9f46d70ab5387b1458e9098b40711d (patch)
tree4949745670b829f2211381bf14b8440dcc6ca7b1 /src/core/moves.h
parent0550a16c1cce868bbc3f3b5ad59f80e35cf2a6cd (diff)
downloadnissy-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.h29
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
4STATIC_INLINE bool allowednextmove(uint8_t *, uint8_t); 4STATIC_INLINE bool allowednextmove(size_t n, const uint8_t [n]);
5STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t); 5STATIC_INLINE uint32_t allowednextmove_mask(size_t n, const uint8_t [n]);
6 6
7STATIC_INLINE uint8_t movebase(uint8_t); 7STATIC_INLINE uint8_t movebase(uint8_t);
8STATIC_INLINE uint8_t moveaxis(uint8_t); 8STATIC_INLINE uint8_t moveaxis(uint8_t);
@@ -13,9 +13,9 @@ STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t);
13STATIC cube_t move(cube_t, uint8_t); 13STATIC cube_t move(cube_t, uint8_t);
14STATIC cube_t premove(cube_t, uint8_t); 14STATIC cube_t premove(cube_t, uint8_t);
15STATIC uint8_t inverse_move(uint8_t); 15STATIC uint8_t inverse_move(uint8_t);
16STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); 16STATIC void invertmoves(size_t n, const uint8_t [n], uint8_t [n]);
17STATIC void sortparallel(uint8_t *, uint8_t); 17STATIC void sortparallel(size_t n, uint8_t [n]);
18STATIC bool are_lastmoves_singlecw(int n, uint8_t [n]); 18STATIC bool are_lastmoves_singlecw(size_t n, uint8_t [n]);
19 19
20STATIC int readmoves(const char *, int, uint8_t *); 20STATIC int readmoves(const char *, int, uint8_t *);
21STATIC cube_t applymoves(cube_t, const char *); 21STATIC cube_t applymoves(cube_t, const char *);
@@ -40,14 +40,13 @@ STATIC cube_t applymoves(cube_t, const char *);
40 } 40 }
41 41
42STATIC bool 42STATIC bool
43allowednextmove(uint8_t *moves, uint8_t n) 43allowednextmove(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
49STATIC uint32_t 48STATIC uint32_t
50allowednextmove_mask(uint8_t *moves, uint8_t n) 49allowednextmove_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)
79STATIC_INLINE uint32_t 78STATIC_INLINE uint32_t
80disable_moves(uint32_t current_result, uint8_t base_index) 79disable_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
85STATIC_INLINE uint8_t 84STATIC_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")
238STATIC void 237STATIC void
239invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) 238invertmoves(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
248STATIC void 247STATIC void
249sortparallel(uint8_t *moves, uint8_t n) 248sortparallel(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
259STATIC bool 258STATIC bool
260are_lastmoves_singlecw(int n, uint8_t moves[n]) 259are_lastmoves_singlecw(size_t n, uint8_t moves[n])
261{ 260{
262 bool two; 261 bool two;
263 262

Generated with cgit - Back to sebastiano.tronto.net