diff options
Diffstat (limited to 'src/nissy.h')
| -rw-r--r-- | src/nissy.h | 99 |
1 files changed, 64 insertions, 35 deletions
diff --git a/src/nissy.h b/src/nissy.h index e037e3b..d4c2760 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -98,7 +98,7 @@ Apply the given sequence of moves on the given cube. | |||
| 98 | 98 | ||
| 99 | Parameters: | 99 | Parameters: |
| 100 | cube - The cube to move, in B32 format. | 100 | cube - The cube to move, in B32 format. |
| 101 | moves - The moves to apply to the cube. | 101 | moves - The moves to apply to the cube. Must be a NULL-terminated string. |
| 102 | result - The return parameter for the resulting cube, in B32 format. | 102 | result - The return parameter for the resulting cube, in B32 format. |
| 103 | 103 | ||
| 104 | Return values: | 104 | Return values: |
| @@ -108,6 +108,7 @@ Return values: | |||
| 108 | or due to an unknown internal error. | 108 | or due to an unknown internal error. |
| 109 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. | 109 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. |
| 110 | NISSY_ERROR_INVALID_MOVES - The given moves are invalid. | 110 | NISSY_ERROR_INVALID_MOVES - The given moves are invalid. |
| 111 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. | ||
| 111 | */ | 112 | */ |
| 112 | int64_t nissy_applymoves( | 113 | int64_t nissy_applymoves( |
| 113 | const char cube[static 22], | 114 | const char cube[static 22], |
| @@ -132,7 +133,7 @@ Return values: | |||
| 132 | */ | 133 | */ |
| 133 | int64_t nissy_applytrans( | 134 | int64_t nissy_applytrans( |
| 134 | const char cube[static 22], | 135 | const char cube[static 22], |
| 135 | const char *transformation, | 136 | const char transformation[static 12], |
| 136 | char result[static 22] | 137 | char result[static 22] |
| 137 | ); | 138 | ); |
| 138 | 139 | ||
| @@ -140,7 +141,8 @@ int64_t nissy_applytrans( | |||
| 140 | Apply the given moves to the solved cube. | 141 | Apply the given moves to the solved cube. |
| 141 | 142 | ||
| 142 | Parameters: | 143 | Parameters: |
| 143 | moves - The moves to be applied to the solved cube. | 144 | moves - The moves to be applied to the solved cube. Must be a |
| 145 | NULL-terminated string. | ||
| 144 | result - Return parameter for the resulting cube, in B32 format. | 146 | result - Return parameter for the resulting cube, in B32 format. |
| 145 | 147 | ||
| 146 | Return values: | 148 | Return values: |
| @@ -148,6 +150,7 @@ Return values: | |||
| 148 | NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is | 150 | NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is |
| 149 | probably due to an unknown internal error. | 151 | probably due to an unknown internal error. |
| 150 | NISSY_ERROR_INVALID_MOVES - The given moves are invalid. | 152 | NISSY_ERROR_INVALID_MOVES - The given moves are invalid. |
| 153 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. | ||
| 151 | */ | 154 | */ |
| 152 | int64_t nissy_frommoves( | 155 | int64_t nissy_frommoves( |
| 153 | const char *moves, | 156 | const char *moves, |
| @@ -158,23 +161,26 @@ int64_t nissy_frommoves( | |||
| 158 | Convert the given cube between the two given formats. | 161 | Convert the given cube between the two given formats. |
| 159 | 162 | ||
| 160 | Parameters: | 163 | Parameters: |
| 161 | format_in - The input format. | 164 | format_in - The input format. |
| 162 | format_out - The output format. | 165 | format_out - The output format. |
| 163 | string - The cube, in format_in format. | 166 | cube_string - The cube, in format_in format. |
| 164 | result - Return parameter for the cube in format_out format. Must be | 167 | retult_size - The allocated size of the result array. |
| 165 | large enough to contains the cube in this format. | 168 | result - Return parameter for the cube in format_out format. |
| 166 | 169 | ||
| 167 | Return values: | 170 | Return values: |
| 168 | NISSY_OK - The conversion was performed succesfully. | 171 | NISSY_OK - The conversion was performed succesfully. |
| 169 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. | 172 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. |
| 170 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. | 173 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. |
| 171 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 174 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 175 | NISSY_ERROR_NULL_POINTER - At least one of 'format_in', 'format_out' or | ||
| 176 | 'cube_string' arguments is NULL. | ||
| 172 | */ | 177 | */ |
| 173 | int64_t nissy_convert( | 178 | int64_t nissy_convert( |
| 174 | const char *format_in, | 179 | const char *format_in, |
| 175 | const char *format_out, | 180 | const char *format_out, |
| 176 | const char *cube, | 181 | const char *cube_string, |
| 177 | char *result | 182 | uint64_t result_size, |
| 183 | char result[result_size] | ||
| 178 | ); | 184 | ); |
| 179 | 185 | ||
| 180 | /* | 186 | /* |
| @@ -214,6 +220,7 @@ Parameters: | |||
| 214 | 220 | ||
| 215 | Return values: | 221 | Return values: |
| 216 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. | 222 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. |
| 223 | NISSY_ERROR_NULL_POINTER - The 'solver' argument is null. | ||
| 217 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 224 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 218 | Any value >= 0 - The size of the data, in bytes. | 225 | Any value >= 0 - The size of the data, in bytes. |
| 219 | */ | 226 | */ |
| @@ -225,55 +232,75 @@ int64_t nissy_datasize( | |||
| 225 | Compute the data for the given solver and store it in generated_data. | 232 | Compute the data for the given solver and store it in generated_data. |
| 226 | 233 | ||
| 227 | Parameters: | 234 | Parameters: |
| 228 | solver - The name of the solver. | 235 | solver - The name of the solver. |
| 229 | data - The return parameter for the generated data. Must be large enoguh | 236 | data_size - The size of the data buffer. It is advised to use nissy_datasize |
| 230 | to contain the whole data. It is advised to use nissy_datasize to | 237 | to check how much memory is needed. |
| 231 | check how much memory is needed. | 238 | data - The return parameter for the generated data. |
| 232 | 239 | ||
| 233 | Return values: | 240 | Return values: |
| 234 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. | 241 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. |
| 242 | NISSY_ERROR_NULL_POINTER - The 'solver' argument is null. | ||
| 235 | NISSY_ERROR_UNKNOWN - An error occurred while generating the data. | 243 | NISSY_ERROR_UNKNOWN - An error occurred while generating the data. |
| 236 | Any value >= 0 - The size of the data, in bytes. | 244 | Any value >= 0 - The size of the data, in bytes. |
| 237 | */ | 245 | */ |
| 238 | int64_t nissy_gendata( | 246 | int64_t nissy_gendata( |
| 239 | const char *solver, | 247 | const char *solver, |
| 240 | void *data | 248 | uint64_t data_size, |
| 249 | char data[data_size] | ||
| 241 | ); | 250 | ); |
| 242 | 251 | ||
| 243 | /* | 252 | /* |
| 244 | Print information on a data table via the provided callback writer. | 253 | Print information on a data table via the provided callback writer. |
| 245 | 254 | ||
| 246 | Parameters: | 255 | Parameters: |
| 247 | data - The data | 256 | data_size - The size of the data buffer. |
| 248 | write - A callback writer with the same signature as printf(3). | 257 | data - The data to be read. |
| 258 | write - A callback writer with the same signature as printf(3). | ||
| 249 | 259 | ||
| 250 | Return values: | 260 | Return values: |
| 251 | NISSY_OK - The data is correct. | 261 | NISSY_OK - The data is correct. |
| 252 | NISSY_ERROR_DATA - The data contains errors. | 262 | NISSY_ERROR_DATA - The data contains errors. |
| 253 | */ | 263 | */ |
| 254 | int64_t nissy_datainfo( | 264 | int64_t nissy_datainfo( |
| 255 | const void *data, | 265 | uint64_t data_size, |
| 266 | const char data[data_size], | ||
| 256 | void (*write)(const char *, ...) | 267 | void (*write)(const char *, ...) |
| 257 | ); | 268 | ); |
| 258 | 269 | ||
| 259 | /* | 270 | /* |
| 271 | Check that the data is a valid data table for a solver. | ||
| 272 | |||
| 273 | Parameters: | ||
| 274 | data_size - The size of the data buffer. | ||
| 275 | data - The data for the solver. Can be computed with gendata. | ||
| 276 | |||
| 277 | Return values: | ||
| 278 | NISSY_OK - The data is valid. | ||
| 279 | NISSY_ERROR_DATA - The data is invalid. | ||
| 280 | */ | ||
| 281 | int64_t nissy_checkdata( | ||
| 282 | uint64_t data_size, | ||
| 283 | const char data[data_size] | ||
| 284 | ); | ||
| 285 | |||
| 286 | /* | ||
| 260 | Solve the given cube using the given solver and options. | 287 | Solve the given cube using the given solver and options. |
| 261 | 288 | ||
| 262 | Parameters: | 289 | Parameters: |
| 263 | cube - The cube to solver, in B32 format. | 290 | cube - The cube to solver, in B32 format. |
| 264 | solver - The name of the solver. | 291 | solver - The name of the solver. |
| 265 | nissflag - The flags for NISS (linear, inverse, mixed, or combinations). | 292 | nissflag - The flags for NISS (linear, inverse, mixed, or combinations). |
| 266 | minmoves - The minimum number of moves for a solution. | 293 | minmoves - The minimum number of moves for a solution. |
| 267 | maxmoves - The maximum number of moves for a solution. | 294 | maxmoves - The maximum number of moves for a solution. |
| 268 | maxsolutions - The maximum number of solutions. | 295 | maxsols - The maximum number of solutions. |
| 269 | optimal - If set to a non-negative value, the maximum number of moves | 296 | optimal - If set to a non-negative value, the maximum number of moves |
| 270 | above the optimal solution length. | 297 | above the optimal solution length. |
| 271 | data - The data for the solver. Can be computed with gendata. | 298 | data_size - The size of the data buffer. |
| 272 | solutions - The return parameter for the solutions. Must be large enough | 299 | data - The data for the solver. Can be computed with gendata. |
| 273 | to store all found solutions. The solutions are separated by | 300 | sols_size - The size of the solutions buffer. |
| 274 | a '\n' (newline) and a '\0' (NULL character) terminates the | 301 | sols - The return parameter for the solutions. The solutions are |
| 275 | list. | 302 | separated by a '\n' (newline) and a '\0' (NULL character) |
| 276 | TODO: replace with callback writer. | 303 | terminates the list. |
| 277 | 304 | ||
| 278 | Return values: | 305 | Return values: |
| 279 | NISSY_OK - Cube solved succesfully. | 306 | NISSY_OK - Cube solved succesfully. |
| @@ -281,8 +308,8 @@ Return values: | |||
| 281 | NISSY_ERROR_UNSOLVABLE_CUBE - The given cube is valid, but not solvable with | 308 | NISSY_ERROR_UNSOLVABLE_CUBE - The given cube is valid, but not solvable with |
| 282 | the given solver. | 309 | the given solver. |
| 283 | NISSY_ERROR_OPTIONS - One or more of the given options are invalid. | 310 | NISSY_ERROR_OPTIONS - One or more of the given options are invalid. |
| 284 | NISSY_ERROR_NULL_POINTER - One of the provided pointers is null. | ||
| 285 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. | 311 | NISSY_ERROR_INVALID_SOLVER - The given solver is not known. |
| 312 | NISSY_ERROR_NULL_POINTER - The 'solver' argument is null. | ||
| 286 | Any value >= 0 - The number of solutions found. | 313 | Any value >= 0 - The number of solutions found. |
| 287 | */ | 314 | */ |
| 288 | int64_t nissy_solve( | 315 | int64_t nissy_solve( |
| @@ -293,8 +320,10 @@ int64_t nissy_solve( | |||
| 293 | int8_t maxmoves, | 320 | int8_t maxmoves, |
| 294 | int64_t maxsolutions, | 321 | int64_t maxsolutions, |
| 295 | int8_t optimal, | 322 | int8_t optimal, |
| 296 | const void *data, | 323 | uint64_t data_size, |
| 297 | char *solutions | 324 | const char data[data_size], |
| 325 | uint64_t sols_size, | ||
| 326 | char sols[sols_size] | ||
| 298 | ); | 327 | ); |
| 299 | 328 | ||
| 300 | /* | 329 | /* |
