diff options
Diffstat (limited to '')
| -rw-r--r-- | shell/shell.c | 23 | ||||
| -rw-r--r-- | src/core/moves.h | 5 | ||||
| -rw-r--r-- | src/nissy.c | 12 | ||||
| -rw-r--r-- | src/nissy.h | 13 |
4 files changed, 50 insertions, 3 deletions
diff --git a/shell/shell.c b/shell/shell.c index 24ae243..42b3ccd 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -67,6 +67,7 @@ static int64_t datasize_exec(args_t *); | |||
| 67 | static int64_t gendata_exec(args_t *); | 67 | static int64_t gendata_exec(args_t *); |
| 68 | static int64_t solve_exec(args_t *); | 68 | static int64_t solve_exec(args_t *); |
| 69 | static int64_t solve_scramble_exec(args_t *); | 69 | static int64_t solve_scramble_exec(args_t *); |
| 70 | static int64_t countmoves_exec(args_t *); | ||
| 70 | static int64_t help_exec(args_t *); | 71 | static int64_t help_exec(args_t *); |
| 71 | 72 | ||
| 72 | static int parse_args(int, char **, args_t *); | 73 | static int parse_args(int, char **, args_t *); |
| @@ -202,13 +203,20 @@ struct { | |||
| 202 | "solve_scramble", | 203 | "solve_scramble", |
| 203 | "solve_scramble " FLAG_SOLVER " SOLVER" | 204 | "solve_scramble " FLAG_SOLVER " SOLVER" |
| 204 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " | 205 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " |
| 205 | FLAG_CUBE " CUBE", | 206 | FLAG_MOVES " MOVES", |
| 206 | "Solve the given SCRAMBLE using SOLVER, " | 207 | "Solve the given SCRAMBLE using SOLVER, " |
| 207 | "using at least n and at most N moves. " | 208 | "using at least n and at most N moves. " |
| 208 | INFO_MOVESFORMAT, | 209 | INFO_MOVESFORMAT, |
| 209 | solve_scramble_exec | 210 | solve_scramble_exec |
| 210 | ), | 211 | ), |
| 211 | COMMAND( | 212 | COMMAND( |
| 213 | "countmoves", | ||
| 214 | "countmoves " FLAG_MOVES " MOVES", | ||
| 215 | "Count the given MOVES in HTM. " | ||
| 216 | INFO_MOVESFORMAT, | ||
| 217 | countmoves_exec | ||
| 218 | ), | ||
| 219 | COMMAND( | ||
| 212 | "help", | 220 | "help", |
| 213 | "help [" FLAG_COMMAND " COMMAND]", | 221 | "help [" FLAG_COMMAND " COMMAND]", |
| 214 | "If no COMMAND is specified, prints some generic information " | 222 | "If no COMMAND is specified, prints some generic information " |
| @@ -488,6 +496,19 @@ solve_scramble_exec(args_t *args) | |||
| 488 | } | 496 | } |
| 489 | 497 | ||
| 490 | static int64_t | 498 | static int64_t |
| 499 | countmoves_exec(args_t *args) | ||
| 500 | { | ||
| 501 | long long count; | ||
| 502 | |||
| 503 | count = nissy_countmoves(args->str_moves); | ||
| 504 | |||
| 505 | if (count >= 0) | ||
| 506 | printf("%lld\n", count); | ||
| 507 | |||
| 508 | return count >= 0 ? 0 : count; | ||
| 509 | } | ||
| 510 | |||
| 511 | static int64_t | ||
| 491 | help_exec(args_t *args) | 512 | help_exec(args_t *args) |
| 492 | { | 513 | { |
| 493 | int i; | 514 | int i; |
diff --git a/src/core/moves.h b/src/core/moves.h index d07bc19..e3a9bc1 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -223,8 +223,9 @@ readmoves(const char *buf, int max, uint8_t *ret) | |||
| 223 | uint8_t m; | 223 | uint8_t m; |
| 224 | int c; | 224 | int c; |
| 225 | 225 | ||
| 226 | FOREACH_READMOVE(buf, m, c, max, -1, | 226 | FOREACH_READMOVE(buf, m, c, max, NISSY_ERROR_INVALID_MOVES, |
| 227 | ret[c] = m; | 227 | if (ret != NULL) |
| 228 | ret[c] = m; | ||
| 228 | ) | 229 | ) |
| 229 | 230 | ||
| 230 | return c; | 231 | return c; |
diff --git a/src/nissy.c b/src/nissy.c index fe2747b..986f27f 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | #include <inttypes.h> | 1 | #include <inttypes.h> |
| 2 | #include <limits.h> | ||
| 2 | #include <pthread.h> | 3 | #include <pthread.h> |
| 3 | #include <stdatomic.h> | 4 | #include <stdatomic.h> |
| 4 | #include <stdarg.h> | 5 | #include <stdarg.h> |
| @@ -521,6 +522,17 @@ nissy_solve( | |||
| 521 | } | 522 | } |
| 522 | 523 | ||
| 523 | long long | 524 | long long |
| 525 | nissy_countmoves( | ||
| 526 | const char *moves | ||
| 527 | ) | ||
| 528 | { | ||
| 529 | if (moves == NULL) | ||
| 530 | return NISSY_ERROR_NULL_POINTER; | ||
| 531 | |||
| 532 | return readmoves(moves, INT_MAX, NULL); | ||
| 533 | } | ||
| 534 | |||
| 535 | long long | ||
| 524 | nissy_setlogger( | 536 | nissy_setlogger( |
| 525 | void (*log)(const char *, ...) | 537 | void (*log)(const char *, ...) |
| 526 | ) | 538 | ) |
diff --git a/src/nissy.h b/src/nissy.h index 8f4f363..7a39927 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -281,6 +281,19 @@ long long nissy_solve( | |||
| 281 | ); | 281 | ); |
| 282 | 282 | ||
| 283 | /* | 283 | /* |
| 284 | Parameters: | ||
| 285 | moves - The moves to be counted. | ||
| 286 | |||
| 287 | Return values: | ||
| 288 | NISSY_ERROR_INVALID_MOVES - The given moves are invalid. | ||
| 289 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. | ||
| 290 | Any value >= 0 - The number of moves. | ||
| 291 | */ | ||
| 292 | long long nissy_countmoves( | ||
| 293 | const char *moves | ||
| 294 | ); | ||
| 295 | |||
| 296 | /* | ||
| 284 | Set a global logger function used by this library. | 297 | Set a global logger function used by this library. |
| 285 | 298 | ||
| 286 | Parameters: | 299 | Parameters: |
