diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-11 07:48:58 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-11 07:48:58 +0200 |
| commit | c89c5a1832354d656757c5aff49018d0313838e0 (patch) | |
| tree | c01d1cedfcdf850f2df66a209a7e4c04c247293f | |
| parent | 2ec81876eb59bb3e7c544774aa222988c1f574c4 (diff) | |
| download | nissy-core-c89c5a1832354d656757c5aff49018d0313838e0.tar.gz nissy-core-c89c5a1832354d656757c5aff49018d0313838e0.zip | |
Cleaned up cube.h
| -rw-r--r-- | TODO.txt | 6 | ||||
| -rw-r--r-- | src/cube.h | 18 | ||||
| -rw-r--r-- | src/cube_public.h | 111 | ||||
| -rw-r--r-- | src/io_cube.h | 4 |
4 files changed, 110 insertions, 29 deletions
| @@ -1,8 +1,7 @@ | |||
| 1 | Refactoring: remove cube_fast_t and add b32 format | 1 | Refactoring: remove cube_fast_t and add b32 format |
| 2 | - see TODO comments in cube.h | ||
| 3 | - fix utility code in utils/*.c | 2 | - fix utility code in utils/*.c |
| 4 | replace h48_to_lst with convert.c | 3 | replace h48_to_lst with convert.c (use convert from cube.h) |
| 5 | fix invert.c | 4 | fix invert.c (use inverse from cube.h) |
| 6 | fix utils/*.sh scripts to use the new convert | 5 | fix utils/*.sh scripts to use the new convert |
| 7 | convert all utils/cubes/*.txt files in b32 format | 6 | convert all utils/cubes/*.txt files in b32 format |
| 8 | - switch to b32 by default | 7 | - switch to b32 by default |
| @@ -20,6 +19,7 @@ Solver | |||
| 20 | - write a solver (how many tricks? some, but not all are needed) | 19 | - write a solver (how many tricks? some, but not all are needed) |
| 21 | 20 | ||
| 22 | More utilities for tables (in cube.h) | 21 | More utilities for tables (in cube.h) |
| 22 | - cleanup solve and gendata in cube.h and cube_public.h | ||
| 23 | - for tables, a "dryrun" function that only tells you the size needed | 23 | - for tables, a "dryrun" function that only tells you the size needed |
| 24 | - check hash of generated data | 24 | - check hash of generated data |
| 25 | 25 | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | All the functions below return 0 in case of success and a positive number | 2 | All the functions below return 0 in case of success and a positive |
| 3 | in case of error. See (TODO: documentation) for details. | 3 | number in case of error, unless otherwise specified. See (TODO: |
| 4 | documentation) for details. | ||
| 4 | */ | 5 | */ |
| 5 | 6 | ||
| 6 | int nissy_compose( | 7 | int nissy_compose( |
| @@ -43,13 +44,21 @@ int nissy_writecube( | |||
| 43 | char *result | 44 | char *result |
| 44 | ); | 45 | ); |
| 45 | 46 | ||
| 46 | int nissy_gendata( | 47 | int nissy_convertcube( |
| 48 | const char *format_in, | ||
| 49 | const char *format_out, | ||
| 50 | const char *cube_string, | ||
| 51 | char *result | ||
| 52 | ); | ||
| 53 | |||
| 54 | /* Returns the number of bytes written, or -1 in case of error */ | ||
| 55 | int64_t nissy_gendata( | ||
| 47 | const char *solver, | 56 | const char *solver, |
| 48 | const char *options, | 57 | const char *options, |
| 49 | void *generated_data, | 58 | void *generated_data, |
| 50 | int64_t *generated_bytes | ||
| 51 | ); | 59 | ); |
| 52 | 60 | ||
| 61 | /* Returns the number of solutions found, or -1 in case of error */ | ||
| 53 | int nissy_solve( | 62 | int nissy_solve( |
| 54 | const char cube[static 22], | 63 | const char cube[static 22], |
| 55 | const char *solver, | 64 | const char *solver, |
| @@ -61,5 +70,4 @@ int nissy_solve( | |||
| 61 | int8_t optimal, | 70 | int8_t optimal, |
| 62 | const void *data, | 71 | const void *data, |
| 63 | char *solutions, | 72 | char *solutions, |
| 64 | int *n_solutions | ||
| 65 | ); | 73 | ); |
diff --git a/src/cube_public.h b/src/cube_public.h index ade8778..1b0cc14 100644 --- a/src/cube_public.h +++ b/src/cube_public.h | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | int check_error(cube_t, char [static 22]); | 1 | int write_result(cube_t, char [static 22]); |
| 2 | 2 | ||
| 3 | int | 3 | int |
| 4 | check_error(cube_t cube, char result[static 22]) | 4 | write_result(cube_t cube, char result[static 22]) |
| 5 | { | 5 | { |
| 6 | if (!isconsistent(cube)) { | 6 | if (!isconsistent(cube)) { |
| 7 | writecube("B32", zero, result); | 7 | writecube("B32", zero, result); |
| 8 | return 2; | 8 | return 2; |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | writecube("B32", cube, result); | ||
| 12 | |||
| 11 | return issolvable(cube) ? 0 : 1; | 13 | return issolvable(cube) ? 0 : 1; |
| 12 | } | 14 | } |
| 13 | 15 | ||
| @@ -22,54 +24,121 @@ nissy_compose( | |||
| 22 | 24 | ||
| 23 | c = readcube("B32", cube); | 25 | c = readcube("B32", cube); |
| 24 | p = readcube("B32", permutation); | 26 | p = readcube("B32", permutation); |
| 25 | |||
| 26 | res = compose(c, p); | 27 | res = compose(c, p); |
| 27 | 28 | ||
| 28 | return check_error(res, result); | 29 | return write_result(res, result); |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | int | 32 | int |
| 32 | nissy_inverse( | 33 | nissy_inverse( |
| 33 | const char cube[static 22], | 34 | const char cube[static 22], |
| 34 | char result[static 22] | 35 | char result[static 22] |
| 35 | ); | 36 | ) |
| 37 | { | ||
| 38 | cube_t c, res; | ||
| 39 | |||
| 40 | c = readcube("B32", cube); | ||
| 41 | res = inverse(c); | ||
| 42 | |||
| 43 | return write_result(res, result); | ||
| 44 | } | ||
| 36 | 45 | ||
| 37 | int nissy_applymoves( | 46 | int |
| 47 | nissy_applymoves( | ||
| 38 | const char cube[static 22], | 48 | const char cube[static 22], |
| 39 | const char *moves, | 49 | const char *moves, |
| 40 | char result[static 22] | 50 | char result[static 22] |
| 41 | ); | 51 | ) |
| 52 | { | ||
| 53 | cube_t c, res; | ||
| 42 | 54 | ||
| 43 | int nissy_applytrans( | 55 | c = readcube("B32", cube); |
| 56 | res = applymoves(c, moves); | ||
| 57 | |||
| 58 | return write_result(res, result); | ||
| 59 | } | ||
| 60 | |||
| 61 | int | ||
| 62 | nissy_applytrans( | ||
| 44 | const char cube[static 22], | 63 | const char cube[static 22], |
| 45 | const char *transformation, | 64 | const char *transformation, |
| 46 | char result[static 22] | 65 | char result[static 22] |
| 47 | ); | 66 | ) |
| 67 | { | ||
| 68 | cube_t c, res; | ||
| 48 | 69 | ||
| 49 | int nissy_frommoves( | 70 | c = readcube("B32", cube); |
| 71 | res = applytrans(c, transformation); | ||
| 72 | |||
| 73 | return write_result(res, result); | ||
| 74 | } | ||
| 75 | |||
| 76 | int | ||
| 77 | nissy_frommoves( | ||
| 50 | const char *moves, | 78 | const char *moves, |
| 51 | char result[static 22] | 79 | char result[static 22] |
| 52 | ); | 80 | ) |
| 81 | { | ||
| 82 | cube_t res; | ||
| 83 | |||
| 84 | res = applymoves(solved, moves); | ||
| 53 | 85 | ||
| 54 | int nissy_readcube( | 86 | return write_result(res, result); |
| 87 | } | ||
| 88 | |||
| 89 | int | ||
| 90 | nissy_readcube( | ||
| 55 | const char *format, | 91 | const char *format, |
| 56 | const char *cube_string, | 92 | const char *cube_string, |
| 57 | char result[static 22] | 93 | char result[static 22] |
| 58 | ); | 94 | ) |
| 95 | { | ||
| 96 | cube_t res; | ||
| 97 | |||
| 98 | res = readcube(format, cube_string); | ||
| 99 | |||
| 100 | return write_result(res, result); | ||
| 101 | } | ||
| 102 | |||
| 103 | int | ||
| 104 | nissy_convertcube( | ||
| 105 | const char *format_in, | ||
| 106 | const char *format_out, | ||
| 107 | const char *cube_string, | ||
| 108 | char *result | ||
| 109 | ) | ||
| 110 | { | ||
| 111 | cube_t c; | ||
| 59 | 112 | ||
| 60 | int nissy_writecube( | 113 | c = readcube(format_in, cube_string); |
| 114 | writecube(format_out, c, result); | ||
| 115 | |||
| 116 | return isconsistent(c) ? 0 : 2; | ||
| 117 | } | ||
| 118 | |||
| 119 | int | ||
| 120 | nissy_writecube( | ||
| 61 | const char *format, | 121 | const char *format, |
| 62 | const char cube[static 22], | 122 | const char cube[static 22], |
| 63 | char *result | 123 | char *result |
| 64 | ); | 124 | ) |
| 125 | { | ||
| 126 | return nissy_convertcube("B32", format, cube, result); | ||
| 127 | } | ||
| 65 | 128 | ||
| 66 | int64_t nissy_gendata( | 129 | int64_t |
| 130 | nissy_gendata( | ||
| 67 | const char *solver, | 131 | const char *solver, |
| 68 | const char *options, | 132 | const char *options, |
| 69 | void *data | 133 | void *data |
| 70 | ); | 134 | ) |
| 135 | { | ||
| 136 | /* TODO: move gendata here? */ | ||
| 137 | return gendata(solver, options, data); | ||
| 138 | } | ||
| 71 | 139 | ||
| 72 | int64_t nissy_solve( | 140 | int64_t |
| 141 | nissy_solve( | ||
| 73 | const char cube[static 22], | 142 | const char cube[static 22], |
| 74 | const char *solver, | 143 | const char *solver, |
| 75 | const char *options, | 144 | const char *options, |
| @@ -80,4 +149,8 @@ int64_t nissy_solve( | |||
| 80 | int8_t optimal, | 149 | int8_t optimal, |
| 81 | const void *data, | 150 | const void *data, |
| 82 | char *solutions | 151 | char *solutions |
| 83 | ); | 152 | ) |
| 153 | { | ||
| 154 | /* TODO: move solve_generic here? */ | ||
| 155 | return -1; | ||
| 156 | } | ||
diff --git a/src/io_cube.h b/src/io_cube.h index 430d3ac..3e7880e 100644 --- a/src/io_cube.h +++ b/src/io_cube.h | |||
| @@ -60,7 +60,7 @@ writecube(const char *format, cube_t cube, char *buf) | |||
| 60 | size_t len; | 60 | size_t len; |
| 61 | 61 | ||
| 62 | if (!isconsistent(cube)) { | 62 | if (!isconsistent(cube)) { |
| 63 | errormsg = "ERROR: cannot write inconsistent cube"; | 63 | errormsg = "ERROR: inconsistent"; |
| 64 | goto writecube_error; | 64 | goto writecube_error; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| @@ -73,7 +73,7 @@ writecube(const char *format, cube_t cube, char *buf) | |||
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | errormsg = "ERROR: cannot write cube in the given format"; | 76 | errormsg = "ERROR: format"; |
| 77 | 77 | ||
| 78 | writecube_error: | 78 | writecube_error: |
| 79 | DBG_LOG("writecube error, see stdout for details\n"); | 79 | DBG_LOG("writecube error, see stdout for details\n"); |
