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.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index 7da6405..8f9c8f5 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -1,7 +1,23 @@
1/* probably these can be placed in constants file */
2#define NORMAL 0x00
3#define INVERSE 0x01
4#define INVERSEBRANCH 0x03
5#define NORMALBRANCH 0x02
6#define ALLMOVES 0x3FFFF
7#define NOHALFTURNS 0x2DB6D
8
1_static_inline bool allowednextmove(uint8_t *, uint8_t); 9_static_inline bool allowednextmove(uint8_t *, uint8_t);
10_static uint32_t allowednextmoveH48(uint8_t *, uint8_t, uint32_t);
11
2_static_inline uint8_t inverse_trans(uint8_t); 12_static_inline uint8_t inverse_trans(uint8_t);
3_static_inline uint8_t movebase(uint8_t); 13_static_inline uint8_t movebase(uint8_t);
4_static_inline uint8_t moveaxis(uint8_t); 14_static_inline uint8_t moveaxis(uint8_t);
15_static_inline uint32_t disable_moves(uint32_t, uint8_t);
16
17_static cube_t move(cube_t, uint8_t);
18_static cube_t premove(cube_t, uint8_t);
19_static uint8_t inverse_move(uint8_t);
20_static uint8_t* invertpremoves(uint8_t *, uint8_t);
5 21
6_static bool 22_static bool
7allowednextmove(uint8_t *moves, uint8_t n) 23allowednextmove(uint8_t *moves, uint8_t n)
@@ -28,6 +44,40 @@ allowednextmove(uint8_t *moves, uint8_t n)
28 return axis[1] != axis[2] || base[0] != base[2]; 44 return axis[1] != axis[2] || base[0] != base[2];
29} 45}
30 46
47_static_inline uint32_t
48disable_moves(uint32_t current_result, uint8_t base_index)
49{
50 return current_result & ~(7 << base_index);
51}
52
53_static uint32_t
54allowednextmoveH48(uint8_t *moves, uint8_t n, uint32_t h48branch)
55{
56 uint32_t result = ALLMOVES;
57 if (h48branch & NORMALBRANCH)
58 result &= NOHALFTURNS;
59 if (n < 1)
60 return result;
61
62 uint8_t base1 = movebase(moves[n-1]);
63 uint8_t axis1 = moveaxis(moves[n-1]);
64
65 result = disable_moves(result, base1 * 3);
66 if (base1 % 2)
67 result = disable_moves(result, (base1 - 1) * 3);
68
69 if (n == 1)
70 return result;
71
72 uint8_t base2 = movebase(moves[n-2]);
73 uint8_t axis2 = moveaxis(moves[n-2]);
74
75 if(axis1 == axis2)
76 result = disable_moves(result, base2 * 3);
77
78 return result;
79}
80
31_static_inline uint8_t 81_static_inline uint8_t
32inverse_trans(uint8_t t) 82inverse_trans(uint8_t t)
33{ 83{
@@ -45,3 +95,116 @@ moveaxis(uint8_t move)
45{ 95{
46 return move / 6; 96 return move / 6;
47} 97}
98
99_static cube_t
100move(cube_t c, uint8_t m)
101{
102 switch (m) {
103 case _move_U:
104 return _move(U, c);
105 case _move_U2:
106 return _move(U2, c);
107 case _move_U3:
108 return _move(U3, c);
109 case _move_D:
110 return _move(D, c);
111 case _move_D2:
112 return _move(D2, c);
113 case _move_D3:
114 return _move(D3, c);
115 case _move_R:
116 return _move(R, c);
117 case _move_R2:
118 return _move(R2, c);
119 case _move_R3:
120 return _move(R3, c);
121 case _move_L:
122 return _move(L, c);
123 case _move_L2:
124 return _move(L2, c);
125 case _move_L3:
126 return _move(L3, c);
127 case _move_F:
128 return _move(F, c);
129 case _move_F2:
130 return _move(F2, c);
131 case _move_F3:
132 return _move(F3, c);
133 case _move_B:
134 return _move(B, c);
135 case _move_B2:
136 return _move(B2, c);
137 case _move_B3:
138 return _move(B3, c);
139 default:
140 LOG("move error, unknown move\n");
141 return zero;
142 }
143}
144
145_static cube_t
146premove(cube_t c, uint8_t m)
147{
148 switch (m) {
149 case _move_U:
150 return _premove(U3, c);
151 case _move_U2:
152 return _premove(U2, c);
153 case _move_U3:
154 return _premove(U, c);
155 case _move_D:
156 return _premove(D3, c);
157 case _move_D2:
158 return _premove(D2, c);
159 case _move_D3:
160 return _premove(D, c);
161 case _move_R:
162 return _premove(R3, c);
163 case _move_R2:
164 return _premove(R2, c);
165 case _move_R3:
166 return _premove(R, c);
167 case _move_L:
168 return _premove(L3, c);
169 case _move_L2:
170 return _premove(L2, c);
171 case _move_L3:
172 return _premove(L, c);
173 case _move_F:
174 return _premove(F3, c);
175 case _move_F2:
176 return _premove(F2, c);
177 case _move_F3:
178 return _premove(F, c);
179 case _move_B:
180 return _premove(B3, c);
181 case _move_B2:
182 return _premove(B2, c);
183 case _move_B3:
184 return _premove(B, c);
185 default:
186 LOG("move error, unknown move\n");
187 return zero;
188 }
189}
190
191_static uint8_t
192inverse_move(uint8_t m)
193{
194 return m - 2 * (m % 3) + 2;
195}
196
197_static uint8_t*
198invertpremoves(uint8_t *moves, uint8_t nmoves)
199{
200 uint8_t i;
201 uint8_t *ret = malloc(nmoves * sizeof(uint8_t));
202
203 for (i = 0; i < nmoves; i++)
204 ret[i] = inverse_move(moves[i]);
205
206 // invert elements in the array
207 for (i = 0; i < nmoves / 2; i++)
208 _swap(ret[i], ret[nmoves - i - 1]);
209 return ret;
210}

Generated with cgit - Back to sebastiano.tronto.net