diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-23 12:09:37 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-06-23 12:09:37 +0200 |
| commit | 05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f (patch) | |
| tree | 1d5512f3e31dd86414d386713a82336db5edf0f5 /src/cube_public.h | |
| parent | 71c0188306377940ae172dceb58f2bd5f4fcdb4f (diff) | |
| download | nissy-core-05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f.tar.gz nissy-core-05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f.zip | |
Cleanup
Diffstat (limited to '')
| -rw-r--r-- | src/cube_public.h | 91 |
1 files changed, 63 insertions, 28 deletions
diff --git a/src/cube_public.h b/src/cube_public.h index 69809d7..ea1d28d 100644 --- a/src/cube_public.h +++ b/src/cube_public.h | |||
| @@ -89,20 +89,6 @@ nissy_frommoves( | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | int64_t | 91 | int64_t |
| 92 | nissy_readcube( | ||
| 93 | const char *format, | ||
| 94 | const char *cube_string, | ||
| 95 | char result[static 22] | ||
| 96 | ) | ||
| 97 | { | ||
| 98 | cube_t res; | ||
| 99 | |||
| 100 | res = readcube(format, cube_string); | ||
| 101 | |||
| 102 | return write_result(res, result); | ||
| 103 | } | ||
| 104 | |||
| 105 | int64_t | ||
| 106 | nissy_convertcube( | 92 | nissy_convertcube( |
| 107 | const char *format_in, | 93 | const char *format_in, |
| 108 | const char *format_out, | 94 | const char *format_out, |
| @@ -119,16 +105,6 @@ nissy_convertcube( | |||
| 119 | } | 105 | } |
| 120 | 106 | ||
| 121 | int64_t | 107 | int64_t |
| 122 | nissy_writecube( | ||
| 123 | const char *format, | ||
| 124 | const char cube[static 22], | ||
| 125 | char *result | ||
| 126 | ) | ||
| 127 | { | ||
| 128 | return nissy_convertcube("B32", format, cube, result); | ||
| 129 | } | ||
| 130 | |||
| 131 | int64_t | ||
| 132 | nissy_datasize( | 108 | nissy_datasize( |
| 133 | const char *solver, | 109 | const char *solver, |
| 134 | const char *options | 110 | const char *options |
| @@ -145,8 +121,22 @@ nissy_gendata( | |||
| 145 | void *data | 121 | void *data |
| 146 | ) | 122 | ) |
| 147 | { | 123 | { |
| 148 | /* TODO: move gendata here? */ | 124 | int64_t ret; |
| 149 | return gendata(solver, options, data); | 125 | uint8_t maxdepth, h, i, j; |
| 126 | |||
| 127 | if (!strcmp(solver, "H48")) { | ||
| 128 | /* options are in the form "h;maxdepth" */ | ||
| 129 | for (i = 0; options[i] != ';'; i++) ; | ||
| 130 | for (j = i; options[j]; j++) ; | ||
| 131 | h = atoi(options); | ||
| 132 | maxdepth = atoi(&options[i+1]); | ||
| 133 | ret = gendata_h48(data, h, maxdepth); | ||
| 134 | } else { | ||
| 135 | LOG("gendata: implemented only for H48 solver\n"); | ||
| 136 | ret = -1; | ||
| 137 | } | ||
| 138 | |||
| 139 | return ret; | ||
| 150 | } | 140 | } |
| 151 | 141 | ||
| 152 | int64_t | 142 | int64_t |
| @@ -163,8 +153,53 @@ nissy_solve( | |||
| 163 | char *solutions | 153 | char *solutions |
| 164 | ) | 154 | ) |
| 165 | { | 155 | { |
| 166 | /* TODO: move solve_generic here? */ | 156 | cube_t c; |
| 167 | return -1; | 157 | int64_t ret; |
| 158 | |||
| 159 | c = readcube_B32(cube); | ||
| 160 | |||
| 161 | if (!issolvable(c)) { | ||
| 162 | LOG("solve: cube is not solvable\n"); | ||
| 163 | return -1; | ||
| 164 | } | ||
| 165 | |||
| 166 | if (minmoves < 0) { | ||
| 167 | LOG("solve: 'minmoves' is negative, setting it to 0\n"); | ||
| 168 | minmoves = 0; | ||
| 169 | } | ||
| 170 | |||
| 171 | if (maxmoves < 0) { | ||
| 172 | LOG("solve: 'maxmoves' is negative, setting it to 20\n"); | ||
| 173 | maxmoves = 20; | ||
| 174 | } | ||
| 175 | |||
| 176 | if (maxsolutions < 0) { | ||
| 177 | LOG("solve: 'maxsols' is negative, stopping\n"); | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | |||
| 181 | if (maxsolutions == 0) { | ||
| 182 | LOG("solve: 'maxsols' is 0, returning no solution\n"); | ||
| 183 | return 0; | ||
| 184 | } | ||
| 185 | |||
| 186 | if (solutions == NULL) { | ||
| 187 | LOG("solve: return parameter 'solutions' is NULL, stopping\n"); | ||
| 188 | return -1; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (!strcmp(solver, "h48")) { | ||
| 192 | LOG("h48 solver not implemented yet\n"); | ||
| 193 | ret = -1; | ||
| 194 | } else if (!strcmp(solver, "simple")) { | ||
| 195 | ret = solve_simple( | ||
| 196 | c, minmoves, maxmoves, maxsolutions, optimal, solutions); | ||
| 197 | } else { | ||
| 198 | LOG("solve: unknown solver '%s'\n", solver); | ||
| 199 | ret = -1; | ||
| 200 | } | ||
| 201 | |||
| 202 | return ret; | ||
| 168 | } | 203 | } |
| 169 | 204 | ||
| 170 | void | 205 | void |
