h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit 7dbd34574f629cacf3b89292d2a06ad0ae612f26
parent ee129a671620de49a5477b1e84bfcd110c522831
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 13 Oct 2024 15:37:02 +0200

Removed nissy_explainerror and moved datainfo to tools

Diffstat:
Msrc/nissy.c | 144-------------------------------------------------------------------------------
Msrc/nissy.h | 142+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mtools/nissy_extra.h | 1+
3 files changed, 90 insertions(+), 197 deletions(-)

diff --git a/src/nissy.c b/src/nissy.c @@ -571,149 +571,5 @@ nissy_setlogger( ) { nissy_log = log; - - if (log == NULL) - return NISSY_WARNING_NULL_CALLBACK; - return NISSY_OK; } - -int64_t -nissy_explainerror( - int64_t error_code, - void (*write)(const char *, ...) -) -{ - if (write == NULL) - return NISSY_WARNING_NULL_CALLBACK; - - switch (error_code) { - case NISSY_OK: - write( - "The value %" PRId64 " denotes a success.\n" - "If returned by solve, it means that no solutions has " - "been found.\n", NISSY_OK - ); - return NISSY_OK; - case NISSY_WARNING_UNSOLVABLE: - write( - "The value %" PRId64 " is a warning. It means that the " - "operation was completed succesfully, but the resulting " - "cube is in an unsolvable state. This could be intended, " - "for example if the user has provided an unsolvable cube " - "as input.\n", NISSY_WARNING_UNSOLVABLE - ); - return NISSY_OK; - case NISSY_WARNING_NULL_CALLBACK: - write( - "The value %" PRId64 " is a warning. It means that the " - "provided pointer to a writer function is NULL.\n" - "If returned by nissy_setlogger, it means that any future " - "log messages will not be printed.\n", - NISSY_WARNING_NULL_CALLBACK - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_CUBE: - write( - "The value %" PRId64 " means that the provided cube is " - "invalid. It could be written in an unknown format, or " - "in a format different from what specified, or simply " - "ill-formed.\n", NISSY_ERROR_INVALID_CUBE - ); - return NISSY_OK; - case NISSY_ERROR_UNSOLVABLE_CUBE: - write( - "The value %" PRId64 " means that the provided cube is " - "in an unsolvable state.\n", NISSY_ERROR_INVALID_CUBE - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_MOVES: - write( - "The value %" PRId64 " means that the given moves are " - "invalid.\n", NISSY_ERROR_INVALID_MOVES - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_TRANS: - write( - "The value %" PRId64 " means that the given transformation " - "is invalid.\n", NISSY_ERROR_INVALID_TRANS - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_FORMAT: - write( - "The value %" PRId64 " means that the given format is not " - "known.\n", NISSY_ERROR_INVALID_FORMAT - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_SOLVER: - write( - "The value %" PRId64 " means that the given solver is not " - "known.\n", NISSY_ERROR_INVALID_SOLVER - ); - return NISSY_OK; - case NISSY_ERROR_NULL_POINTER: - write( - "The value %" PRId64 " means that one of the provided " - "pointer arguments is NULL. For example, it may be " - "returned by solve when called with a solver that " - "requires some pre-computed data, but the provided data " - "is NULL.\n", NISSY_ERROR_NULL_POINTER - ); - return NISSY_OK; - case NISSY_ERROR_BUFFER_SIZE: - write( - "The value %" PRId64 " means that one of the buffers " - "provided is too small. For example, it could be too " - "small to hold the result or too small to hold the data " - "generated by gendata.\n", NISSY_ERROR_BUFFER_SIZE - ); - return NISSY_OK; - case NISSY_ERROR_DATA: - write( - "The value %" PRId64 " means that the provided data is " - "invalid. For example, it may be returned by solve when " - "called with incompatible solver and data arguments.\n", - NISSY_ERROR_DATA - ); - return NISSY_OK; - case NISSY_ERROR_OPTIONS: - write( - "The value %" PRId64 " means that one or more of the " - "given options are invalid. For example, it may be " - "returned by solve when called with a negative maximum " - "number of solutions.\n", NISSY_ERROR_OPTIONS - ); - return NISSY_OK; - case NISSY_ERROR_INVALID_CODE: - write( - "The value %" PRId64 " means that the given error code " - "is not known. It may be returned by explainerror.\n", - NISSY_ERROR_INVALID_CODE - ); - return NISSY_OK; - case NISSY_ERROR_UNKNOWN: - write( - "The value %" PRId64 " denotes an unexpected error. It " - "probably means that there some bug in this library.\n" - "If you can, report any error of this kind to " - "sebastiano@tronto.net. Thanks!\n", NISSY_ERROR_UNKNOWN - ); - return NISSY_OK; - default: - break; - } - - if (error_code > 0) { - write( - "A positive return values does not denote an error\n" - "If returned by gendata or datasize, it denotes the size " - "of the data, in bytes\n" - "If returned by solve, it denotes the number of solutions " - "found.\n" - ); - return NISSY_OK; - } else { - write("Unknown error code %" PRId64 "\n", error_code); - return NISSY_ERROR_INVALID_CODE; - } -} diff --git a/src/nissy.h b/src/nissy.h @@ -9,8 +9,8 @@ If you include this file, you should also use the following includes: #include <string.h> All the functions return 0 or a positive integer in case of success and -a negative integer in case of error, unless otherwise specified. -You can see the list of error codes below, or use nissy_explainerror(). +a negative integer in case of error, unless otherwise specified. See at +the bottom of this file for the list of error codes and their meaning. All cube arguments are in B32 formats, unless otherwise specified. Other available formats are H48 and SRC. See README.md for more info on @@ -24,23 +24,6 @@ A transformation must be given in the format for example 'rotation UF' or 'mirrored BL'. */ -/* Error codes */ -#define NISSY_OK INT64_C(0) -#define NISSY_WARNING_UNSOLVABLE INT64_C(-1) -#define NISSY_WARNING_NULL_CALLBACK INT64_C(-2) -#define NISSY_ERROR_INVALID_CUBE INT64_C(-10) -#define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11) -#define NISSY_ERROR_INVALID_MOVES INT64_C(-20) -#define NISSY_ERROR_INVALID_TRANS INT64_C(-30) -#define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) -#define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) -#define NISSY_ERROR_NULL_POINTER INT64_C(-60) -#define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) -#define NISSY_ERROR_DATA INT64_C(-70) -#define NISSY_ERROR_OPTIONS INT64_C(-80) -#define NISSY_ERROR_INVALID_CODE INT64_C(-90) -#define NISSY_ERROR_UNKNOWN INT64_C(-999) - /* Some constants for size for I/O buffers */ #define NISSY_SIZE_B32 UINT64_C(22) #define NISSY_SIZE_H48 UINT64_C(88) @@ -257,24 +240,6 @@ int64_t nissy_gendata( ); /* -Print information on a data table via the provided callback writer. - -Parameters: - data_size - The size of the data buffer. - data - The data to be read. - write - A callback writer with the same signature as printf(3). - -Return values: - NISSY_OK - The data is correct. - NISSY_ERROR_DATA - The data contains errors. -*/ -int64_t nissy_datainfo( - uint64_t data_size, - const char data[data_size], - void (*write)(const char *, ...) -); - -/* Check that the data is a valid data table for a solver. Parameters: @@ -340,28 +305,99 @@ Parameters: write - A callback writer with the same signature as printf(3). Return values: - NISSY_OK - Logger set succesfully. - NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL. + NISSY_OK - Logger set succesfully. No warning or error is goind to be given + if the logger is NULL or invalid. */ int64_t nissy_setlogger( void (*logger_function)(const char *, ...) ); + +/* Error codes */ + /* -Print an explanation of the given error code via the provided callback writer. +The value NISSY_OK denotes a success. If returned by solve, it means +that no solution has been found. +*/ +#define NISSY_OK INT64_C(0) -Parameters: - error_code - The error code to be explained. It can be any value returned - by a function in this library, not necessarily an error. - write - A callback writer with the same signature as printf(3). - Must be non-NULL. +/* +The value NISSY_WARNING_UNSOLVABLE is a warning. It means that the +operation was completed succesfully, but the resulting cube is in an +unsolvable state. This could be intended, for example if the user has +provided an unsolvable cube as input. +*/ +#define NISSY_WARNING_UNSOLVABLE INT64_C(-1) -Return values: - NISSY_OK - The error code is known. - NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL. - NISSY_ERROR_INVALID_CODE - The error code is unknown. +/* +The value NISSY_ERROR_INVALID_CUBE means that the provided cube is +invalid. It could be written in an unknown format, or in a format +different from what specified, or simply ill-formed. */ -int64_t nissy_explainerror( - int64_t error_code, - void (*write)(const char *, ...) -); +#define NISSY_ERROR_INVALID_CUBE INT64_C(-10) + +/* +The value NISSY_ERROR_UNSOLVABLE_CUBE means that the provided cube is +in an unsolvable state. +*/ +#define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11) + +/* +The value NISSY_ERROR_INVALID_MOVES means that the given moves are +invalid. +*/ +#define NISSY_ERROR_INVALID_MOVES INT64_C(-20) + +/* +The value NISSY_ERROR_INVALID_TRANS means that the given transformation +is invalid. +*/ +#define NISSY_ERROR_INVALID_TRANS INT64_C(-30) + +/* +The value NISSY_ERROR_INVALID_FORMAT means that the given format is +not known. +*/ +#define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) + +/* +The value NISSY_ERROR_INVALID_SOLVER means that the given solver is +not known. +*/ +#define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) + +/* +The value NISSY_ERROR_NULL_POINTER means that one of the provided pointer +arguments is NULL. For example, it may be returned by solve when called +with a solver that requires some pre-computed data, but the provided +data is NULL. +*/ +#define NISSY_ERROR_NULL_POINTER INT64_C(-60) + +/* +The value NISSY_ERROR_BUFFER_SIZE means that one of the buffers provided +is too small. For example, it could be too small to hold the result or +too small to hold the data generated by gendata. +*/ +#define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) + +/* +The value NISSY_ERROR_DATA means that the provided data is invalid. For +example, it may be returned by solve when called with incompatible solver +and data arguments. +*/ +#define NISSY_ERROR_DATA INT64_C(-70) + +/* +The value NISSY_ERROR_OPTIONS means that one or more of the given options +are invalid. For example, it may be returned by solve when called with +a negative maximum number of solutions. +*/ +#define NISSY_ERROR_OPTIONS INT64_C(-80) + +/* +The value NISSY_ERROR_UNKNOWN denotes an unexpected error. It probably +means that there some bug in this library. If you can, report any error +of this kind to sebastiano@tronto.net. Thanks! +*/ +#define NISSY_ERROR_UNKNOWN INT64_C(-999) diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h @@ -10,4 +10,5 @@ for testing purposes only. size_t gendata_h48_derive(uint8_t, const void *, void *); int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); +int64_t nissy_datainfo(uint64_t, const char *, void (*)(const char *, ...)); int64_t nissy_derivedata(const char *, const void *, void *);