aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-06-10 22:22:03 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-06-10 22:22:03 +0200
commitd9f40f59c9f14bef7f87c11da7494f7dcf1457b4 (patch)
treed8d63db63a9558b0befbd0ec6c267dd13be20dfa /src
parent832ad3dcf3818e57c53304ea9b09a943e785a16b (diff)
downloadnissy-core-d9f40f59c9f14bef7f87c11da7494f7dcf1457b4.tar.gz
nissy-core-d9f40f59c9f14bef7f87c11da7494f7dcf1457b4.zip
Started cube.h refactor
Diffstat (limited to 'src')
-rw-r--r--src/cube.c2
-rw-r--r--src/cube.h79
-rw-r--r--src/cube_generic.h7
-rw-r--r--src/cube_public.h83
-rw-r--r--src/solve_generic.h19
5 files changed, 148 insertions, 42 deletions
diff --git a/src/cube.c b/src/cube.c
index fce0683..97f7844 100644
--- a/src/cube.c
+++ b/src/cube.c
@@ -47,3 +47,5 @@
47#include "moves.h" 47#include "moves.h"
48#include "solve_h48.h" 48#include "solve_h48.h"
49#include "solve_generic.h" 49#include "solve_generic.h"
50
51#include "cube_public.h"
diff --git a/src/cube.h b/src/cube.h
index d30c1d4..b5f4211 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -1,32 +1,65 @@
1/* TODO: change cube to const char [static 22], or const char * */ 1/*
2/* TODO: return error code */ 2All the functions below return 0 in case of success and a positive number
3/* TODO: implement all of this, or move the implementation to cube_public.h */ 3in case of error. See (TODO: documentation) for details.
4/* TODO: document in a separate file, possibly leave here 1-line comments */ 4*/
5 5
6cube_t compose(cube_t cube, cube_t perm); 6int nissy_compose(
7cube_t inverse(cube_t cube); 7 const char cube[static 22],
8cube_t solvedcube(void); 8 const char permutation[static 22],
9cube_t applymoves(cube_t, const char *); 9 char result[static 22]
10cube_t applytrans(cube_t, const char *); 10);
11cube_t readcube(const char *format, const char *buf); 11
12void writecube(const char *format, cube_t cube, char *buf); 12int nissy_inverse(
13int64_t solve( 13 const char cube[static 22],
14 cube_t cube, 14 char result[static 22]
15);
16
17int nissy_applyoves(
18 const char cube[static 22],
19 const char *moves,
20 char result[static 22]
21);
22
23int nissy_applytrans(
24 const char cube[static 22],
25 const char *transformation,
26 char result[static 22]
27);
28
29int nissy_frommoves(
30 const char *moves,
31 char result[static 22]
32);
33
34int nissy_readcube(
35 const char *format,
36 const char *cube_string,
37 char result[static 22]
38);
39
40int nissy_writecube(
41 const char *format,
42 const char cube[static 22],
43 char *result
44);
45
46int nissy_gendata(
47 const char *solver,
48 const char *options,
49 void *generated_data,
50 int64_t *generated_bytes
51);
52
53int nissy_solve(
54 const char cube[static 22],
15 const char *solver, 55 const char *solver,
16 const char *options, 56 const char *options,
17 const char *nisstype, 57 const char *nisstype,
18 int8_t minmoves, 58 int8_t minmoves,
19 int8_t maxmoves, 59 int8_t maxmoves,
20 int64_t maxsols, 60 int64_t maxsolutions,
21 int8_t optimal, 61 int8_t optimal,
22 const void *data,
23 char *solutions
24);
25void multisolve(
26 int n,
27 cube_t *cube,
28 const char *solver,
29 const void *data, 62 const void *data,
30 char *sols 63 char *solutions,
64 int *n_solutions
31); 65);
32int64_t gendata(const char *solver, const char *options, void *data);
diff --git a/src/cube_generic.h b/src/cube_generic.h
index 6b675ee..7ff9992 100644
--- a/src/cube_generic.h
+++ b/src/cube_generic.h
@@ -8,6 +8,7 @@ _static bool issolved(cube_t);
8_static bool iserror(cube_t); 8_static bool iserror(cube_t);
9_static cube_t applymoves(cube_t, const char *); 9_static cube_t applymoves(cube_t, const char *);
10_static cube_t applytrans(cube_t, const char *); 10_static cube_t applytrans(cube_t, const char *);
11_static cube_t frommoves(const char *);
11 12
12_static int permsign(uint8_t *, int); 13_static int permsign(uint8_t *, int);
13_static cube_t move(cube_t, uint8_t); 14_static cube_t move(cube_t, uint8_t);
@@ -165,6 +166,12 @@ applymoves_error:
165} 166}
166 167
167_static cube_t 168_static cube_t
169frommoves(const char *buf)
170{
171 return applymoves(solved, buf);
172}
173
174_static cube_t
168applytrans(cube_t cube, const char *buf) 175applytrans(cube_t cube, const char *buf)
169{ 176{
170 uint8_t t; 177 uint8_t t;
diff --git a/src/cube_public.h b/src/cube_public.h
new file mode 100644
index 0000000..7f7b81c
--- /dev/null
+++ b/src/cube_public.h
@@ -0,0 +1,83 @@
1int check(cube_t, char [static 22]);
2
3int
4check(cube_t cube, char result[static 22])
5{
6 if (!isconsistent(cube)) {
7 writecube("B32", zero, result);
8 return 2;
9 }
10
11 return issolvable(cube) ? 0 : 1;
12}
13
14int
15nissy_compose(
16 const char cube[static 22],
17 const char permutation[static 22],
18 char result[static 22]
19)
20{
21 cube_t c, p, res;
22
23 c = readcube("B32", cube);
24 p = readcube("B32", permutation);
25
26 res = compose(c, p);
27
28 return check(res, result);
29}
30
31int
32nissy_inverse(
33 const char cube[static 22],
34 char result[static 22]
35);
36
37int nissy_applymoves(
38 const char cube[static 22],
39 const char *moves,
40 char result[static 22]
41);
42
43int nissy_applytrans(
44 const char cube[static 22],
45 const char *transformation,
46 char result[static 22]
47);
48
49int nissy_frommoves(
50 const char *moves,
51 char result[static 22]
52);
53
54int nissy_readcube(
55 const char *format,
56 const char *cube_string,
57 char result[static 22]
58);
59
60int nissy_writecube(
61 const char *format,
62 const char cube[static 22],
63 char *result
64);
65
66int64_t nissy_gendata(
67 const char *solver,
68 const char *options,
69 void *data
70);
71
72int64_t nissy_solve(
73 const char cube[static 22],
74 const char *solver,
75 const char *options,
76 const char *nisstype,
77 int8_t minmoves,
78 int8_t maxmoves,
79 int64_t maxsolutions,
80 int8_t optimal,
81 const void *data,
82 char *solutions
83);
diff --git a/src/solve_generic.h b/src/solve_generic.h
index b5d1e2d..c80f3ef 100644
--- a/src/solve_generic.h
+++ b/src/solve_generic.h
@@ -57,25 +57,6 @@ solve(
57 return -1; 57 return -1;
58} 58}
59 59
60void
61multisolve(
62 int n,
63 cube_t *cube,
64 const char *solver,
65 const void *data,
66 char *sols
67)
68{
69 char *s;
70 int i;
71
72 s = sols;
73 for (i = 0; i < n; i++) {
74 solve(cube[i], solver, "", "normal", 0, -1, 1, 0, NULL, s);
75 while (s++);
76 }
77}
78
79_static void 60_static void
80solve_generic_appendsolution(dfsarg_generic_t *arg) 61solve_generic_appendsolution(dfsarg_generic_t *arg)
81{ 62{

Generated with cgit - Back to sebastiano.tronto.net