aboutsummaryrefslogtreecommitdiff
path: root/src/core/moves.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-03 21:52:16 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-03 21:52:16 +0200
commitc9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (patch)
treef4f569fcbd4d6704fb5dd44892911ce808f03332 /src/core/moves.h
parentff4bde84872ec0b93f0f097f5a56bd5e7cbb0311 (diff)
downloadnissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.tar.gz
nissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.zip
Moved stuff around
Diffstat (limited to 'src/core/moves.h')
-rw-r--r--src/core/moves.h88
1 files changed, 43 insertions, 45 deletions
diff --git a/src/core/moves.h b/src/core/moves.h
index 8f9c8f5..71ef470 100644
--- a/src/core/moves.h
+++ b/src/core/moves.h
@@ -1,13 +1,7 @@
1/* probably these can be placed in constants file */ 1#define _move(M, c) compose(c, _move_cube_ ## M)
2#define NORMAL 0x00 2#define _premove(M, c) compose(_move_cube_ ## M, c)
3#define INVERSE 0x01
4#define INVERSEBRANCH 0x03
5#define NORMALBRANCH 0x02
6#define ALLMOVES 0x3FFFF
7#define NOHALFTURNS 0x2DB6D
8 3
9_static_inline bool allowednextmove(uint8_t *, uint8_t); 4_static_inline bool allowednextmove(uint8_t *, uint8_t);
10_static uint32_t allowednextmoveH48(uint8_t *, uint8_t, uint32_t);
11 5
12_static_inline uint8_t inverse_trans(uint8_t); 6_static_inline uint8_t inverse_trans(uint8_t);
13_static_inline uint8_t movebase(uint8_t); 7_static_inline uint8_t movebase(uint8_t);
@@ -17,7 +11,10 @@ _static_inline uint32_t disable_moves(uint32_t, uint8_t);
17_static cube_t move(cube_t, uint8_t); 11_static cube_t move(cube_t, uint8_t);
18_static cube_t premove(cube_t, uint8_t); 12_static cube_t premove(cube_t, uint8_t);
19_static uint8_t inverse_move(uint8_t); 13_static uint8_t inverse_move(uint8_t);
20_static uint8_t* invertpremoves(uint8_t *, uint8_t); 14_static void invertmoves(uint8_t *, uint8_t, uint8_t *);
15
16_static cube_t applymoves(cube_t, const char *);
17_static cube_t frommoves(const char *);
21 18
22_static bool 19_static bool
23allowednextmove(uint8_t *moves, uint8_t n) 20allowednextmove(uint8_t *moves, uint8_t n)
@@ -50,34 +47,6 @@ disable_moves(uint32_t current_result, uint8_t base_index)
50 return current_result & ~(7 << base_index); 47 return current_result & ~(7 << base_index);
51} 48}
52 49
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
81_static_inline uint8_t 50_static_inline uint8_t
82inverse_trans(uint8_t t) 51inverse_trans(uint8_t t)
83{ 52{
@@ -194,17 +163,46 @@ inverse_move(uint8_t m)
194 return m - 2 * (m % 3) + 2; 163 return m - 2 * (m % 3) + 2;
195} 164}
196 165
197_static uint8_t* 166_static void
198invertpremoves(uint8_t *moves, uint8_t nmoves) 167invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret)
199{ 168{
200 uint8_t i; 169 uint8_t i;
201 uint8_t *ret = malloc(nmoves * sizeof(uint8_t));
202 170
203 for (i = 0; i < nmoves; i++) 171 for (i = 0; i < nmoves; i++)
204 ret[i] = inverse_move(moves[i]); 172 ret[i] = inverse_move(moves[nmoves - i - 1]);
173}
205 174
206 // invert elements in the array 175_static cube_t
207 for (i = 0; i < nmoves / 2; i++) 176applymoves(cube_t cube, const char *buf)
208 _swap(ret[i], ret[nmoves - i - 1]); 177{
209 return ret; 178 uint8_t r, m;
179 const char *b;
180
181 DBG_ASSERT(isconsistent(cube), zero,
182 "move error: inconsistent cube\n");
183
184 for (b = buf; *b != '\0'; b++) {
185 while (*b == ' ' || *b == '\t' || *b == '\n')
186 b++;
187 if (*b == '\0')
188 goto applymoves_finish;
189 if ((r = readmove(*b)) == _error)
190 goto applymoves_error;
191 if ((m = readmodifier(*(b+1))) != 0)
192 b++;
193 cube = move(cube, r + m);
194 }
195
196applymoves_finish:
197 return cube;
198
199applymoves_error:
200 LOG("applymoves error\n");
201 return zero;
202}
203
204_static cube_t
205frommoves(const char *buf)
206{
207 return applymoves(solved, buf);
210} 208}

Generated with cgit - Back to sebastiano.tronto.net