aboutsummaryrefslogtreecommitdiff
path: root/src/cube_generic.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-04 17:09:55 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-04 17:09:55 +0200
commit518d98ad5f9eec0cf4124375bdbb84d1296b3f3f (patch)
tree467b2b0387f23a0b379cf428c6883937ec18c134 /src/cube_generic.h
parent425eee24421bf0a19c7e0199d2e3ecba3318c8f4 (diff)
downloadnissy-core-518d98ad5f9eec0cf4124375bdbb84d1296b3f3f.tar.gz
nissy-core-518d98ad5f9eec0cf4124375bdbb84d1296b3f3f.zip
(almost) added getcube
Diffstat (limited to 'src/cube_generic.h')
-rw-r--r--src/cube_generic.h59
1 files changed, 45 insertions, 14 deletions
diff --git a/src/cube_generic.h b/src/cube_generic.h
index 7095c3a..c40844d 100644
--- a/src/cube_generic.h
+++ b/src/cube_generic.h
@@ -1,6 +1,7 @@
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 cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]);
4_static cube_t solvedcube(void); 5_static cube_t solvedcube(void);
5_static bool isconsistent(cube_t); 6_static bool isconsistent(cube_t);
6_static bool issolvable(cube_t); 7_static bool issolvable(cube_t);
@@ -9,14 +10,24 @@ _static bool iserror(cube_t);
9_static cube_t applymoves(cube_t, const char *); 10_static cube_t applymoves(cube_t, const char *);
10_static cube_t applytrans(cube_t, const char *); 11_static cube_t applytrans(cube_t, const char *);
11_static cube_t frommoves(const char *); 12_static cube_t frommoves(const char *);
13_static void getcube_fix(int64_t *, int64_t *, int64_t *, int64_t *);
14_static cube_t getcube(int64_t, int64_t, int64_t, int64_t);
12 15
13_static int permsign(uint8_t *, int);
14_static cube_t move(cube_t, uint8_t); 16_static cube_t move(cube_t, uint8_t);
15_static cube_t transform_edges(cube_t, uint8_t); 17_static cube_t transform_edges(cube_t, uint8_t);
16_static cube_t transform_corners(cube_t, uint8_t); 18_static cube_t transform_corners(cube_t, uint8_t);
17_static cube_t transform(cube_t, uint8_t); 19_static cube_t transform(cube_t, uint8_t);
18 20
19_static cube_t 21_static cube_t
22cubefromarray(uint8_t c[static 8], uint8_t e[static 12])
23{
24 return static_cube(
25 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7],
26 e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7],
27 e[8], e[9], e[10], e[11]);
28}
29
30_static cube_t
20solvedcube(void) 31solvedcube(void)
21{ 32{
22 return solved; 33 return solved;
@@ -171,6 +182,39 @@ frommoves(const char *buf)
171 return applymoves(solved, buf); 182 return applymoves(solved, buf);
172} 183}
173 184
185_static void
186getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co)
187{
188 uint8_t e[12], c[8], aux;
189
190 *ep %= _12f;
191 *eo %= _2p11;
192 *cp %= _8f;
193 *cp %= _3p7;
194
195 indextoperm(*ep, 12, e);
196 indextoperm(*cp, 8, c);
197 if (permsign(e, 12) != permsign(c, 8)) {
198 aux = c[0];
199 c[0] = c[1];
200 c[1] = aux;
201 *cp = permtoindex(c, 8);
202 }
203}
204
205_static cube_t
206getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co)
207{
208 uint8_t e[12], c[8];
209
210 indextoperm(ep, 12, e);
211 indextoperm(cp, 8, c);
212
213 /* TODO: orientation */
214
215 return cubefromarray(c, e);
216}
217
174_static cube_t 218_static cube_t
175applytrans(cube_t cube, const char *buf) 219applytrans(cube_t cube, const char *buf)
176{ 220{
@@ -184,19 +228,6 @@ applytrans(cube_t cube, const char *buf)
184 return transform(cube, t); 228 return transform(cube, t);
185} 229}
186 230
187_static int
188permsign(uint8_t *a, int n)
189{
190 int i, j;
191 uint8_t ret = 0;
192
193 for (i = 0; i < n; i++)
194 for (j = i+1; j < n; j++)
195 ret += a[i] > a[j] ? 1 : 0;
196
197 return ret % 2;
198}
199
200_static cube_t 231_static cube_t
201move(cube_t c, uint8_t m) 232move(cube_t c, uint8_t m)
202{ 233{

Generated with cgit - Back to sebastiano.tronto.net