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 f2907e471b3caddc5844bc6994e1cbd249019747
parent 25c16cc4350a659ede2a2503c4c5be36264e853d
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon, 26 Aug 2024 15:35:09 +0200

Fixed bug in run solve

Diffstat:
Mshell.c | 6+++---
Msrc/nissy.c | 12++++++++++--
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/shell.c b/shell.c @@ -183,21 +183,21 @@ struct { ), COMMAND( "datasize", - "datasize" _flag_solver " SOLVER " _flag_options " OPTIONS", + "datasize " _flag_solver " SOLVER " _flag_options " OPTIONS", "Return the size in bytes of the data table used by " "SOLVER when called with the given OPTIONS.", datasize_exec ), COMMAND( "gendata", - "gendata" _flag_solver " SOLVER " _flag_options " OPTIONS", + "gendata " _flag_solver " SOLVER " _flag_options " OPTIONS", "Generate the data table used by " "SOLVER when called with the given OPTIONS.", gendata_exec ), COMMAND( "solve", - "solve" _flag_solver " SOLVER " _flag_options " OPTIONS " + "solve " _flag_solver " SOLVER " _flag_options " OPTIONS " "[" _flag_minmoves " n] [" _flag_maxmoves " N] " _flag_cube " CUBE", "Solve the given CUBE using SOLVER with the given OPTIONS, " diff --git a/src/nissy.c b/src/nissy.c @@ -26,23 +26,31 @@ struct { _static int parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) { + bool h_valid, k_valid, maxdepth_valid; int i; /* TODO temporarily, options are in the form "h;k;maxdepth" */ if (h != NULL) *h = atoi(buf); + h_valid = h == NULL || *h <= 11; + for (i = 0; buf[i] != ';'; i++) if (buf[i] == 0) goto parse_h48_options_error; + if (k != NULL) *k = atoi(&buf[i+1]); + k_valid = k == NULL || (*k == 2 || *k == 4); + for (i = i+1; buf[i] != ';'; i++) if (buf[i] == 0) goto parse_h48_options_error; + if (maxdepth != NULL) *maxdepth = atoi(&buf[i+1]); + maxdepth_valid = maxdepth == NULL || *maxdepth <= 20; - return (*h <= 11 && (*k == 2 || *k == 4) && *maxdepth <= 20) ? 0 : 1; + return h_valid && k_valid && maxdepth_valid ? 0 : 1; parse_h48_options_error: *h = 0; @@ -202,7 +210,7 @@ nissy_gendata( if (!strcmp(solver, "h48")) { p = parse_h48_options(options, &arg.h, &arg.k, &arg.maxdepth); if (p != 0) { - LOG("gendata: ould not parse options\n"); + LOG("gendata: could not parse options\n"); ret = -1; } else { ret = gendata_h48(&arg);