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.h122
1 files changed, 61 insertions, 61 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index 71ef470..45cd804 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -1,22 +1,22 @@
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); 4STATIC_INLINE bool allowednextmove(uint8_t *, uint8_t);
5 5
6_static_inline uint8_t inverse_trans(uint8_t); 6STATIC_INLINE uint8_t inverse_trans(uint8_t);
7_static_inline uint8_t movebase(uint8_t); 7STATIC_INLINE uint8_t movebase(uint8_t);
8_static_inline uint8_t moveaxis(uint8_t); 8STATIC_INLINE uint8_t moveaxis(uint8_t);
9_static_inline uint32_t disable_moves(uint32_t, uint8_t); 9STATIC_INLINE uint32_t disable_moves(uint32_t, uint8_t);
10 10
11_static cube_t move(cube_t, uint8_t); 11STATIC cube_t move(cube_t, uint8_t);
12_static cube_t premove(cube_t, uint8_t); 12STATIC cube_t premove(cube_t, uint8_t);
13_static uint8_t inverse_move(uint8_t); 13STATIC uint8_t inverse_move(uint8_t);
14_static void invertmoves(uint8_t *, uint8_t, uint8_t *); 14STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *);
15 15
16_static cube_t applymoves(cube_t, const char *); 16STATIC cube_t applymoves(cube_t, const char *);
17_static cube_t frommoves(const char *); 17STATIC cube_t frommoves(const char *);
18 18
19_static bool 19STATIC bool
20allowednextmove(uint8_t *moves, uint8_t n) 20allowednextmove(uint8_t *moves, uint8_t n)
21{ 21{
22 uint8_t base[3], axis[3]; 22 uint8_t base[3], axis[3];
@@ -41,69 +41,69 @@ allowednextmove(uint8_t *moves, uint8_t n)
41 return axis[1] != axis[2] || base[0] != base[2]; 41 return axis[1] != axis[2] || base[0] != base[2];
42} 42}
43 43
44_static_inline uint32_t 44STATIC_INLINE uint32_t
45disable_moves(uint32_t current_result, uint8_t base_index) 45disable_moves(uint32_t current_result, uint8_t base_index)
46{ 46{
47 return current_result & ~(7 << base_index); 47 return current_result & ~(7 << base_index);
48} 48}
49 49
50_static_inline uint8_t 50STATIC_INLINE uint8_t
51inverse_trans(uint8_t t) 51inverse_trans(uint8_t t)
52{ 52{
53 return inverse_trans_table[t]; 53 return inverse_trans_table[t];
54} 54}
55 55
56_static_inline uint8_t 56STATIC_INLINE uint8_t
57movebase(uint8_t move) 57movebase(uint8_t move)
58{ 58{
59 return move / 3; 59 return move / 3;
60} 60}
61 61
62_static_inline uint8_t 62STATIC_INLINE uint8_t
63moveaxis(uint8_t move) 63moveaxis(uint8_t move)
64{ 64{
65 return move / 6; 65 return move / 6;
66} 66}
67 67
68_static cube_t 68STATIC cube_t
69move(cube_t c, uint8_t m) 69move(cube_t c, uint8_t m)
70{ 70{
71 switch (m) { 71 switch (m) {
72 case _move_U: 72 case MOVE_U:
73 return _move(U, c); 73 return _move(U, c);
74 case _move_U2: 74 case MOVE_U2:
75 return _move(U2, c); 75 return _move(U2, c);
76 case _move_U3: 76 case MOVE_U3:
77 return _move(U3, c); 77 return _move(U3, c);
78 case _move_D: 78 case MOVE_D:
79 return _move(D, c); 79 return _move(D, c);
80 case _move_D2: 80 case MOVE_D2:
81 return _move(D2, c); 81 return _move(D2, c);
82 case _move_D3: 82 case MOVE_D3:
83 return _move(D3, c); 83 return _move(D3, c);
84 case _move_R: 84 case MOVE_R:
85 return _move(R, c); 85 return _move(R, c);
86 case _move_R2: 86 case MOVE_R2:
87 return _move(R2, c); 87 return _move(R2, c);
88 case _move_R3: 88 case MOVE_R3:
89 return _move(R3, c); 89 return _move(R3, c);
90 case _move_L: 90 case MOVE_L:
91 return _move(L, c); 91 return _move(L, c);
92 case _move_L2: 92 case MOVE_L2:
93 return _move(L2, c); 93 return _move(L2, c);
94 case _move_L3: 94 case MOVE_L3:
95 return _move(L3, c); 95 return _move(L3, c);
96 case _move_F: 96 case MOVE_F:
97 return _move(F, c); 97 return _move(F, c);
98 case _move_F2: 98 case MOVE_F2:
99 return _move(F2, c); 99 return _move(F2, c);
100 case _move_F3: 100 case MOVE_F3:
101 return _move(F3, c); 101 return _move(F3, c);
102 case _move_B: 102 case MOVE_B:
103 return _move(B, c); 103 return _move(B, c);
104 case _move_B2: 104 case MOVE_B2:
105 return _move(B2, c); 105 return _move(B2, c);
106 case _move_B3: 106 case MOVE_B3:
107 return _move(B3, c); 107 return _move(B3, c);
108 default: 108 default:
109 LOG("move error, unknown move\n"); 109 LOG("move error, unknown move\n");
@@ -111,45 +111,45 @@ move(cube_t c, uint8_t m)
111 } 111 }
112} 112}
113 113
114_static cube_t 114STATIC cube_t
115premove(cube_t c, uint8_t m) 115premove(cube_t c, uint8_t m)
116{ 116{
117 switch (m) { 117 switch (m) {
118 case _move_U: 118 case MOVE_U:
119 return _premove(U3, c); 119 return _premove(U3, c);
120 case _move_U2: 120 case MOVE_U2:
121 return _premove(U2, c); 121 return _premove(U2, c);
122 case _move_U3: 122 case MOVE_U3:
123 return _premove(U, c); 123 return _premove(U, c);
124 case _move_D: 124 case MOVE_D:
125 return _premove(D3, c); 125 return _premove(D3, c);
126 case _move_D2: 126 case MOVE_D2:
127 return _premove(D2, c); 127 return _premove(D2, c);
128 case _move_D3: 128 case MOVE_D3:
129 return _premove(D, c); 129 return _premove(D, c);
130 case _move_R: 130 case MOVE_R:
131 return _premove(R3, c); 131 return _premove(R3, c);
132 case _move_R2: 132 case MOVE_R2:
133 return _premove(R2, c); 133 return _premove(R2, c);
134 case _move_R3: 134 case MOVE_R3:
135 return _premove(R, c); 135 return _premove(R, c);
136 case _move_L: 136 case MOVE_L:
137 return _premove(L3, c); 137 return _premove(L3, c);
138 case _move_L2: 138 case MOVE_L2:
139 return _premove(L2, c); 139 return _premove(L2, c);
140 case _move_L3: 140 case MOVE_L3:
141 return _premove(L, c); 141 return _premove(L, c);
142 case _move_F: 142 case MOVE_F:
143 return _premove(F3, c); 143 return _premove(F3, c);
144 case _move_F2: 144 case MOVE_F2:
145 return _premove(F2, c); 145 return _premove(F2, c);
146 case _move_F3: 146 case MOVE_F3:
147 return _premove(F, c); 147 return _premove(F, c);
148 case _move_B: 148 case MOVE_B:
149 return _premove(B3, c); 149 return _premove(B3, c);
150 case _move_B2: 150 case MOVE_B2:
151 return _premove(B2, c); 151 return _premove(B2, c);
152 case _move_B3: 152 case MOVE_B3:
153 return _premove(B, c); 153 return _premove(B, c);
154 default: 154 default:
155 LOG("move error, unknown move\n"); 155 LOG("move error, unknown move\n");
@@ -157,13 +157,13 @@ premove(cube_t c, uint8_t m)
157 } 157 }
158} 158}
159 159
160_static uint8_t 160STATIC uint8_t
161inverse_move(uint8_t m) 161inverse_move(uint8_t m)
162{ 162{
163 return m - 2 * (m % 3) + 2; 163 return m - 2 * (m % 3) + 2;
164} 164}
165 165
166_static void 166STATIC void
167invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) 167invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret)
168{ 168{
169 uint8_t i; 169 uint8_t i;
@@ -172,7 +172,7 @@ invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret)
172 ret[i] = inverse_move(moves[nmoves - i - 1]); 172 ret[i] = inverse_move(moves[nmoves - i - 1]);
173} 173}
174 174
175_static cube_t 175STATIC cube_t
176applymoves(cube_t cube, const char *buf) 176applymoves(cube_t cube, const char *buf)
177{ 177{
178 uint8_t r, m; 178 uint8_t r, m;
@@ -186,7 +186,7 @@ applymoves(cube_t cube, const char *buf)
186 b++; 186 b++;
187 if (*b == '\0') 187 if (*b == '\0')
188 goto applymoves_finish; 188 goto applymoves_finish;
189 if ((r = readmove(*b)) == _error) 189 if ((r = readmove(*b)) == UINT8_ERROR)
190 goto applymoves_error; 190 goto applymoves_error;
191 if ((m = readmodifier(*(b+1))) != 0) 191 if ((m = readmodifier(*(b+1))) != 0)
192 b++; 192 b++;
@@ -201,7 +201,7 @@ applymoves_error:
201 return zero; 201 return zero;
202} 202}
203 203
204_static cube_t 204STATIC cube_t
205frommoves(const char *buf) 205frommoves(const char *buf)
206{ 206{
207 return applymoves(solved, buf); 207 return applymoves(solved, buf);

Generated with cgit - Back to sebastiano.tronto.net