diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cube.c | 2 | ||||
| -rw-r--r-- | src/cube.h | 79 | ||||
| -rw-r--r-- | src/cube_generic.h | 7 | ||||
| -rw-r--r-- | src/cube_public.h | 83 | ||||
| -rw-r--r-- | src/solve_generic.h | 19 |
5 files changed, 148 insertions, 42 deletions
| @@ -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" | ||
| @@ -1,32 +1,65 @@ | |||
| 1 | /* TODO: change cube to const char [static 22], or const char * */ | 1 | /* |
| 2 | /* TODO: return error code */ | 2 | All 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 */ | 3 | in case of error. See (TODO: documentation) for details. |
| 4 | /* TODO: document in a separate file, possibly leave here 1-line comments */ | 4 | */ |
| 5 | 5 | ||
| 6 | cube_t compose(cube_t cube, cube_t perm); | 6 | int nissy_compose( |
| 7 | cube_t inverse(cube_t cube); | 7 | const char cube[static 22], |
| 8 | cube_t solvedcube(void); | 8 | const char permutation[static 22], |
| 9 | cube_t applymoves(cube_t, const char *); | 9 | char result[static 22] |
| 10 | cube_t applytrans(cube_t, const char *); | 10 | ); |
| 11 | cube_t readcube(const char *format, const char *buf); | 11 | |
| 12 | void writecube(const char *format, cube_t cube, char *buf); | 12 | int nissy_inverse( |
| 13 | int64_t solve( | 13 | const char cube[static 22], |
| 14 | cube_t cube, | 14 | char result[static 22] |
| 15 | ); | ||
| 16 | |||
| 17 | int nissy_applyoves( | ||
| 18 | const char cube[static 22], | ||
| 19 | const char *moves, | ||
| 20 | char result[static 22] | ||
| 21 | ); | ||
| 22 | |||
| 23 | int nissy_applytrans( | ||
| 24 | const char cube[static 22], | ||
| 25 | const char *transformation, | ||
| 26 | char result[static 22] | ||
| 27 | ); | ||
| 28 | |||
| 29 | int nissy_frommoves( | ||
| 30 | const char *moves, | ||
| 31 | char result[static 22] | ||
| 32 | ); | ||
| 33 | |||
| 34 | int nissy_readcube( | ||
| 35 | const char *format, | ||
| 36 | const char *cube_string, | ||
| 37 | char result[static 22] | ||
| 38 | ); | ||
| 39 | |||
| 40 | int nissy_writecube( | ||
| 41 | const char *format, | ||
| 42 | const char cube[static 22], | ||
| 43 | char *result | ||
| 44 | ); | ||
| 45 | |||
| 46 | int nissy_gendata( | ||
| 47 | const char *solver, | ||
| 48 | const char *options, | ||
| 49 | void *generated_data, | ||
| 50 | int64_t *generated_bytes | ||
| 51 | ); | ||
| 52 | |||
| 53 | int 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 | ); | ||
| 25 | void 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 | ); |
| 32 | int64_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 |
| 169 | frommoves(const char *buf) | ||
| 170 | { | ||
| 171 | return applymoves(solved, buf); | ||
| 172 | } | ||
| 173 | |||
| 174 | _static cube_t | ||
| 168 | applytrans(cube_t cube, const char *buf) | 175 | applytrans(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 @@ | |||
| 1 | int check(cube_t, char [static 22]); | ||
| 2 | |||
| 3 | int | ||
| 4 | check(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 | |||
| 14 | int | ||
| 15 | nissy_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 | |||
| 31 | int | ||
| 32 | nissy_inverse( | ||
| 33 | const char cube[static 22], | ||
| 34 | char result[static 22] | ||
| 35 | ); | ||
| 36 | |||
| 37 | int nissy_applymoves( | ||
| 38 | const char cube[static 22], | ||
| 39 | const char *moves, | ||
| 40 | char result[static 22] | ||
| 41 | ); | ||
| 42 | |||
| 43 | int nissy_applytrans( | ||
| 44 | const char cube[static 22], | ||
| 45 | const char *transformation, | ||
| 46 | char result[static 22] | ||
| 47 | ); | ||
| 48 | |||
| 49 | int nissy_frommoves( | ||
| 50 | const char *moves, | ||
| 51 | char result[static 22] | ||
| 52 | ); | ||
| 53 | |||
| 54 | int nissy_readcube( | ||
| 55 | const char *format, | ||
| 56 | const char *cube_string, | ||
| 57 | char result[static 22] | ||
| 58 | ); | ||
| 59 | |||
| 60 | int nissy_writecube( | ||
| 61 | const char *format, | ||
| 62 | const char cube[static 22], | ||
| 63 | char *result | ||
| 64 | ); | ||
| 65 | |||
| 66 | int64_t nissy_gendata( | ||
| 67 | const char *solver, | ||
| 68 | const char *options, | ||
| 69 | void *data | ||
| 70 | ); | ||
| 71 | |||
| 72 | int64_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 | ||
| 60 | void | ||
| 61 | multisolve( | ||
| 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 |
| 80 | solve_generic_appendsolution(dfsarg_generic_t *arg) | 61 | solve_generic_appendsolution(dfsarg_generic_t *arg) |
| 81 | { | 62 | { |
