aboutsummaryrefslogtreecommitdiff
path: root/src/core/moves.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/moves.h')
-rw-r--r--src/core/moves.h54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index e3a9bc1..7d4972e 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -2,8 +2,8 @@
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(uint8_t *, uint8_t);
5STATIC_INLINE uint32_t allowednextmove_mask(uint8_t *, uint8_t);
5 6
6STATIC_INLINE uint8_t inverse_trans(uint8_t);
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);
9STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t); 9STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t);
@@ -38,26 +38,38 @@ STATIC cube_t applymoves(cube_t, const char *);
38STATIC bool 38STATIC bool
39allowednextmove(uint8_t *moves, uint8_t n) 39allowednextmove(uint8_t *moves, uint8_t n)
40{ 40{
41 uint8_t base[3], axis[3]; 41 return n == 0 ? true :
42 allowednextmove_mask(moves, n-1) & (1 << moves[n-1]);
43}
44
45STATIC uint32_t
46allowednextmove_mask(uint8_t *moves, uint8_t n)
47{
48 uint32_t result;
49 uint8_t base1, base2, axis1, axis2;
50
51 result = MM_ALLMOVES;
42 52
43 if (n < 2) 53 if (n == 0)
44 return true; 54 return result;
45 55
46 base[0] = movebase(moves[n-1]); 56 base1 = movebase(moves[n-1]);
47 axis[0] = moveaxis(moves[n-1]); 57 axis1 = moveaxis(moves[n-1]);
48 base[1] = movebase(moves[n-2]); 58 result = disable_moves(result, base1 * 3);
49 axis[1] = moveaxis(moves[n-2]);
50 59
51 if (base[0] == base[1] || (axis[0] == axis[1] && base[0] < base[1])) 60 if (base1 % 2)
52 return false; 61 result = disable_moves(result, (base1 - 1) * 3);
53 62
54 if (n == 2) 63 if (n == 1)
55 return true; 64 return result;
56 65
57 base[2] = movebase(moves[n-3]); 66 base2 = movebase(moves[n-2]);
58 axis[2] = moveaxis(moves[n-3]); 67 axis2 = moveaxis(moves[n-2]);
59 68
60 return axis[1] != axis[2] || base[0] != base[2]; 69 if(axis1 == axis2)
70 result = disable_moves(result, base2 * 3);
71
72 return result;
61} 73}
62 74
63STATIC_INLINE uint32_t 75STATIC_INLINE uint32_t
@@ -67,12 +79,6 @@ disable_moves(uint32_t current_result, uint8_t base_index)
67} 79}
68 80
69STATIC_INLINE uint8_t 81STATIC_INLINE uint8_t
70inverse_trans(uint8_t t)
71{
72 return inverse_trans_table[t];
73}
74
75STATIC_INLINE uint8_t
76movebase(uint8_t move) 82movebase(uint8_t move)
77{ 83{
78 return move / 3; 84 return move / 3;
@@ -84,6 +90,12 @@ moveaxis(uint8_t move)
84 return move / 6; 90 return move / 6;
85} 91}
86 92
93STATIC_INLINE uint8_t
94moveopposite(uint8_t move)
95{
96 return movebase(move) == 2 * moveaxis(move) ? move + 3 : move - 3;
97}
98
87STATIC cube_t 99STATIC cube_t
88move(cube_t c, uint8_t m) 100move(cube_t c, uint8_t m)
89{ 101{

Generated with cgit - Back to sebastiano.tronto.net