diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 19:49:48 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 19:49:48 +0200 |
| commit | 5e291466fbbc45aed74f67a1b2e555d1f0c44d8f (patch) | |
| tree | ebe96c88599d55ee1b986412f1d0456f55f950a9 /src/nissy.h | |
| parent | d4fadc24ee1993104bac7fd854ed6ca83f60ee66 (diff) | |
| download | nissy-core-5e291466fbbc45aed74f67a1b2e555d1f0c44d8f.tar.gz nissy-core-5e291466fbbc45aed74f67a1b2e555d1f0c44d8f.zip | |
Improved error messages and add some comments in nissy.h
Diffstat (limited to '')
| -rw-r--r-- | src/nissy.h | 120 |
1 files changed, 91 insertions, 29 deletions
diff --git a/src/nissy.h b/src/nissy.h index 1fc1776..c78fb50 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -1,10 +1,17 @@ | |||
| 1 | /* | 1 | /* |
| 2 | If you include this file, you should also include the following: | 2 | This is libnissy (temporarily also known as h48), a Rubik's cube library. |
| 3 | 3 | ||
| 4 | inttypes, stdarg, stdbool, string | 4 | If you include this file, you should also use the following includes: |
| 5 | 5 | ||
| 6 | All the functions below return 0 in case of success and a positive | 6 | #include <inttypes> |
| 7 | number in case of error, unless otherwise specified. | 7 | #include <stdarg> |
| 8 | #include <stdbool> | ||
| 9 | #include <string> | ||
| 10 | |||
| 11 | All the functions below return 0 in case of success and a positive number | ||
| 12 | in case of error, unless otherwise specified. Errors are checked in code | ||
| 13 | order: for example if error code 1 is returned then it could that also | ||
| 14 | an error with code 2 or higher occurred. | ||
| 8 | 15 | ||
| 9 | Arguments of type char [static 22] denote a cube in B32 format. | 16 | Arguments of type char [static 22] denote a cube in B32 format. |
| 10 | Other available formats are H48 and SRC. See README.md for more info on | 17 | Other available formats are H48 and SRC. See README.md for more info on |
| @@ -18,40 +25,85 @@ A transformation must be given in the format | |||
| 18 | for example 'rotation UF' or 'mirrored BL'. | 25 | for example 'rotation UF' or 'mirrored BL'. |
| 19 | */ | 26 | */ |
| 20 | 27 | ||
| 21 | /* Apply the secod argument as a permutation on the first argument */ | 28 | /* |
| 29 | Apply the secod argument as a permutation on the first argument. | ||
| 30 | |||
| 31 | Return values: | ||
| 32 | 0 Valid result | ||
| 33 | 1 The given cube is invalid | ||
| 34 | 2 The given permutation is invalid | ||
| 35 | 9 The resulting cube is not solvable | ||
| 36 | */ | ||
| 22 | int64_t nissy_compose( | 37 | int64_t nissy_compose( |
| 23 | const char cube[static 22], | 38 | const char cube[static 22], |
| 24 | const char permutation[static 22], | 39 | const char permutation[static 22], |
| 25 | char result[static 22] | 40 | char result[static 22] |
| 26 | ); | 41 | ); |
| 27 | 42 | ||
| 28 | /* Compute the inverse of the given cube */ | 43 | /* |
| 44 | Compute the inverse of the given cube. | ||
| 45 | |||
| 46 | Return values: | ||
| 47 | 0 Valid result | ||
| 48 | 1 The given cube is invalid | ||
| 49 | 9 The resulting cube is not solvable | ||
| 50 | */ | ||
| 29 | int64_t nissy_inverse( | 51 | int64_t nissy_inverse( |
| 30 | const char cube[static 22], | 52 | const char cube[static 22], |
| 31 | char result[static 22] | 53 | char result[static 22] |
| 32 | ); | 54 | ); |
| 33 | 55 | ||
| 34 | /* Apply the given sequence of moves on the given cube */ | 56 | /* |
| 57 | Apply the given sequence of moves on the given cube. | ||
| 58 | |||
| 59 | Return values: | ||
| 60 | 0 Valid result | ||
| 61 | 1 The given cube is invalid | ||
| 62 | 8 The given moves are invalid | ||
| 63 | 9 The resulting cube is not solvable | ||
| 64 | */ | ||
| 35 | int64_t nissy_applymoves( | 65 | int64_t nissy_applymoves( |
| 36 | const char cube[static 22], | 66 | const char cube[static 22], |
| 37 | const char *moves, | 67 | const char *moves, |
| 38 | char result[static 22] | 68 | char result[static 22] |
| 39 | ); | 69 | ); |
| 40 | 70 | ||
| 41 | /* Apply the single given transformation to the given cube */ | 71 | /* |
| 72 | Apply the single given transformation to the given cube. | ||
| 73 | |||
| 74 | Return values: | ||
| 75 | 0 Valid result | ||
| 76 | 1 The given cube is invalid | ||
| 77 | 8 The given transformation is invalid | ||
| 78 | 9 The resulting cube is not solvable | ||
| 79 | */ | ||
| 42 | int64_t nissy_applytrans( | 80 | int64_t nissy_applytrans( |
| 43 | const char cube[static 22], | 81 | const char cube[static 22], |
| 44 | const char *transformation, | 82 | const char *transformation, |
| 45 | char result[static 22] | 83 | char result[static 22] |
| 46 | ); | 84 | ); |
| 47 | 85 | ||
| 48 | /* Return the cube obtained by applying the given moves to the solved cube */ | 86 | /* |
| 87 | Apply the given moves to the solved cube. | ||
| 88 | |||
| 89 | Return values: | ||
| 90 | 0 Valid result | ||
| 91 | 1 The given moves are invalid | ||
| 92 | */ | ||
| 49 | int64_t nissy_frommoves( | 93 | int64_t nissy_frommoves( |
| 50 | const char *moves, | 94 | const char *moves, |
| 51 | char result[static 22] | 95 | char result[static 22] |
| 52 | ); | 96 | ); |
| 53 | 97 | ||
| 54 | /* Convert the given cube between the two given formats */ | 98 | /* |
| 99 | Convert the given cube between the two given formats. | ||
| 100 | |||
| 101 | Return values: | ||
| 102 | 0 Valid result | ||
| 103 | 1 The given cube or format_in is invalid | ||
| 104 | 2 The resulting cube or format_out is invalid | ||
| 105 | 3 The resulting cube is inconsistent | ||
| 106 | */ | ||
| 55 | int64_t nissy_convert( | 107 | int64_t nissy_convert( |
| 56 | const char *format_in, | 108 | const char *format_in, |
| 57 | const char *format_out, | 109 | const char *format_out, |
| @@ -70,40 +122,48 @@ int64_t nissy_getcube( | |||
| 70 | ); | 122 | ); |
| 71 | 123 | ||
| 72 | /* | 124 | /* |
| 73 | Returns the size of the data generated by nissy_gendata, when called with | 125 | Compute the size of the data generated by nissy_gendata, when called with |
| 74 | the same parameters, or -1 in case of error. The returned value can be | 126 | the same parameters, or -1 in case of error. |
| 75 | slightly larger than the actual table size. | 127 | |
| 128 | Return values: | ||
| 129 | -1 Error | ||
| 130 | >=0 The size of the table, in bytes | ||
| 76 | */ | 131 | */ |
| 77 | int64_t nissy_datasize( | 132 | int64_t nissy_datasize( |
| 78 | const char *solver | 133 | const char *solver |
| 79 | ); | 134 | ); |
| 80 | 135 | ||
| 81 | /* Returns the number of bytes written, or -1 in case of error */ | 136 | /* |
| 137 | Compute the data for the given solver and store it in generated_data. | ||
| 138 | |||
| 139 | Return values: | ||
| 140 | -1 Error | ||
| 141 | >=0 The size of the table, in bytes | ||
| 142 | */ | ||
| 82 | int64_t nissy_gendata( | 143 | int64_t nissy_gendata( |
| 83 | const char *solver, | 144 | const char *solver, |
| 84 | void *generated_data | 145 | void *generated_data |
| 85 | ); | 146 | ); |
| 86 | 147 | ||
| 87 | /* Temporarily added to test h48 intermediate tables */ | 148 | /* |
| 88 | int64_t nissy_derivedata( | 149 | Print information on a data table via the provided callback writer. |
| 89 | const char *options, | ||
| 90 | const void *fulltable, | ||
| 91 | void *generated_data | ||
| 92 | ); | ||
| 93 | |||
| 94 | /* Returns 0 on positive check, 1 on error */ | ||
| 95 | int64_t nissy_checkdata( | ||
| 96 | const char *solver, | ||
| 97 | const void *data | ||
| 98 | ); | ||
| 99 | 150 | ||
| 100 | /* Print information on a data table via the provided callback writer */ | 151 | Return values: |
| 152 | 0 No error | ||
| 153 | 1 The given data could not be read correctly | ||
| 154 | */ | ||
| 101 | int64_t nissy_datainfo( | 155 | int64_t nissy_datainfo( |
| 102 | const void *table, | 156 | const void *table, |
| 103 | void (*write)(const char *, ...) | 157 | void (*write)(const char *, ...) |
| 104 | ); | 158 | ); |
| 105 | 159 | ||
| 106 | /* Returns the number of solutions found, or -1 in case of error */ | 160 | /* |
| 161 | Solve the given cube using the given solver and options | ||
| 162 | |||
| 163 | Return values: | ||
| 164 | -1 Error | ||
| 165 | >=0 The number of solutions found | ||
| 166 | */ | ||
| 107 | int64_t nissy_solve( | 167 | int64_t nissy_solve( |
| 108 | const char cube[static 22], | 168 | const char cube[static 22], |
| 109 | const char *solver, | 169 | const char *solver, |
| @@ -116,5 +176,7 @@ int64_t nissy_solve( | |||
| 116 | char *solutions | 176 | char *solutions |
| 117 | ); | 177 | ); |
| 118 | 178 | ||
| 119 | /* Set a global logger function used by this library. */ | 179 | /* |
| 180 | Set a global logger function used by this library. | ||
| 181 | */ | ||
| 120 | void nissy_setlogger(void (*logger_function)(const char *, ...)); | 182 | void nissy_setlogger(void (*logger_function)(const char *, ...)); |
