aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-01 09:33:26 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-01 09:33:26 +0200
commitb0053277e385bee23336d1fe6b69a12f49f9172f (patch)
tree531e44cd6f8e807c991d0a46692140667939fbe3 /src/core
parentb6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690 (diff)
downloadnissy-core-b0053277e385bee23336d1fe6b69a12f49f9172f.tar.gz
nissy-core-b0053277e385bee23336d1fe6b69a12f49f9172f.zip
simplified allowedmoves logic
Diffstat (limited to 'src/core')
-rw-r--r--src/core/moves.h52
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
4STATIC_INLINE bool allowednextmove(size_t n, const uint8_t [n]); 4STATIC_INLINE bool allowednextmove(uint8_t, uint8_t);
5STATIC_INLINE uint32_t allowednextmove_mask(size_t n, const uint8_t [n]);
6STATIC bool allowedmoves(size_t n, const uint8_t [n]); 5STATIC bool allowedmoves(size_t n, const uint8_t [n]);
7 6
8STATIC_INLINE uint8_t movebase(uint8_t); 7STATIC_INLINE uint8_t movebase(uint8_t);
9STATIC_INLINE uint8_t moveaxis(uint8_t); 8STATIC_INLINE uint8_t moveaxis(uint8_t);
10STATIC_INLINE bool isbase(uint8_t); 9STATIC_INLINE bool isbase(uint8_t);
11STATIC_INLINE bool parallel(uint8_t, uint8_t); 10STATIC_INLINE bool parallel(uint8_t, uint8_t);
12STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t);
13 11
14STATIC cube_t move(cube_t, uint8_t); 12STATIC cube_t move(cube_t, uint8_t);
15STATIC cube_t premove(cube_t, uint8_t); 13STATIC 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
41STATIC bool 39STATIC_INLINE bool
42allowednextmove(size_t n, const uint8_t moves[n]) 40allowednextmove(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
47STATIC uint32_t
48allowednextmove_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
77STATIC bool 45STATIC bool
78allowedmoves(size_t n, const uint8_t moves[n]) 46allowedmoves(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
89STATIC_INLINE uint32_t
90disable_moves(uint32_t current_result, uint8_t base_index)
91{
92 return current_result & ~MM_SIDE(base_index);
93}
94
95STATIC_INLINE uint8_t 57STATIC_INLINE uint8_t
96movebase(uint8_t move) 58movebase(uint8_t move)
97{ 59{

Generated with cgit - Back to sebastiano.tronto.net