From 05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 23 Jun 2024 12:09:37 +0200 Subject: Cleanup --- src/cube.h | 14 +------- src/cube_public.h | 91 ++++++++++++++++++++++++++++++++++--------------- src/solve_generic.h | 98 ----------------------------------------------------- 3 files changed, 64 insertions(+), 139 deletions(-) (limited to 'src') diff --git a/src/cube.h b/src/cube.h index 30016fd..b5eb615 100644 --- a/src/cube.h +++ b/src/cube.h @@ -34,19 +34,7 @@ int64_t nissy_frommoves( char result[static 22] ); -int64_t nissy_readcube( - const char *format, - const char *cube_string, - char result[static 22] -); - -int64_t nissy_writecube( - const char *format, - const char cube[static 22], - char *result -); - -int64_t nissy_convertcube( +int64_t nissy_convert( const char *format_in, const char *format_out, const char *cube_string, diff --git a/src/cube_public.h b/src/cube_public.h index 69809d7..ea1d28d 100644 --- a/src/cube_public.h +++ b/src/cube_public.h @@ -88,20 +88,6 @@ nissy_frommoves( return write_result(res, result); } -int64_t -nissy_readcube( - const char *format, - const char *cube_string, - char result[static 22] -) -{ - cube_t res; - - res = readcube(format, cube_string); - - return write_result(res, result); -} - int64_t nissy_convertcube( const char *format_in, @@ -118,16 +104,6 @@ nissy_convertcube( return isconsistent(c) ? 0 : 2; } -int64_t -nissy_writecube( - const char *format, - const char cube[static 22], - char *result -) -{ - return nissy_convertcube("B32", format, cube, result); -} - int64_t nissy_datasize( const char *solver, @@ -145,8 +121,22 @@ nissy_gendata( void *data ) { - /* TODO: move gendata here? */ - return gendata(solver, options, data); + int64_t ret; + uint8_t maxdepth, h, i, j; + + if (!strcmp(solver, "H48")) { + /* options are in the form "h;maxdepth" */ + for (i = 0; options[i] != ';'; i++) ; + for (j = i; options[j]; j++) ; + h = atoi(options); + maxdepth = atoi(&options[i+1]); + ret = gendata_h48(data, h, maxdepth); + } else { + LOG("gendata: implemented only for H48 solver\n"); + ret = -1; + } + + return ret; } int64_t @@ -163,8 +153,53 @@ nissy_solve( char *solutions ) { - /* TODO: move solve_generic here? */ - return -1; + cube_t c; + int64_t ret; + + c = readcube_B32(cube); + + if (!issolvable(c)) { + LOG("solve: cube is not solvable\n"); + return -1; + } + + if (minmoves < 0) { + LOG("solve: 'minmoves' is negative, setting it to 0\n"); + minmoves = 0; + } + + if (maxmoves < 0) { + LOG("solve: 'maxmoves' is negative, setting it to 20\n"); + maxmoves = 20; + } + + if (maxsolutions < 0) { + LOG("solve: 'maxsols' is negative, stopping\n"); + return -1; + } + + if (maxsolutions == 0) { + LOG("solve: 'maxsols' is 0, returning no solution\n"); + return 0; + } + + if (solutions == NULL) { + LOG("solve: return parameter 'solutions' is NULL, stopping\n"); + return -1; + } + + if (!strcmp(solver, "h48")) { + LOG("h48 solver not implemented yet\n"); + ret = -1; + } else if (!strcmp(solver, "simple")) { + ret = solve_simple( + c, minmoves, maxmoves, maxsolutions, optimal, solutions); + } else { + LOG("solve: unknown solver '%s'\n", solver); + ret = -1; + } + + return ret; } void diff --git a/src/solve_generic.h b/src/solve_generic.h index 6a1dcf3..d1d1469 100644 --- a/src/solve_generic.h +++ b/src/solve_generic.h @@ -16,47 +16,6 @@ _static int64_t solve_generic(cube_t, const char *, int8_t, int8_t, int64_t, _static uint8_t estimate_simple(cube_t); _static int64_t solve_simple(cube_t, int8_t, int8_t, int64_t, int8_t, char *); -int64_t -solve( - cube_t cube, - const char *solver, - const char *options, - const char *nisstype, - int8_t minmoves, - int8_t maxmoves, - int64_t maxsols, - int8_t optimal, - const void *data, - char *solutions -) -{ - DBG_WARN(!strcmp(options, ""), - "solve: 'options' not implemented yet, ignoring\n"); - - DBG_WARN(!strcmp(nisstype, ""), - "solve: NISS not implemented yet, ignoring 'nisstype'\n"); - - DBG_WARN(data == NULL, - "solve: 'data' not implemented yet, ignoring\n"); - - if (!strcmp(solver, "optimal") || !strcmp(solver, "simple")) { - return solve_simple( - cube, - minmoves, - maxmoves, - maxsols, - optimal, - solutions - ); - } else { - LOG("solve: unknown solver '%s'\n", solver); - return -1; - } - - LOG("solve: error\n"); - return -1; -} - _static void solve_generic_appendsolution(dfsarg_generic_t *arg) { @@ -125,11 +84,6 @@ solve_generic( dfsarg_generic_t arg; int64_t ret, tmp, first; - if (!issolvable(cube)) { - LOG("solve: cube is not solvable\n"); - return -1; - } - if (issolved(cube)) { LOG("solve: cube is already solved\n"); sols[0] = '\n'; @@ -137,34 +91,6 @@ solve_generic( return 1; } - DBG_WARN(!strcmp(nisstype, ""), - "solve: NISS not implemented yet, 'nisstype' ignored\n"); - - if (minmoves < 0) { - LOG("solve: 'minmoves' is negative, setting to 0\n"); - minmoves = 0; - } - - if (maxmoves < 0) { - LOG("solve: invalid 'maxmoves', setting to 20\n"); - maxmoves = 20; - } - - if (maxsols < 0) { - LOG("solve: 'maxsols' is negative\n"); - return -1; - } - - if (maxsols == 0) { - LOG("solve: 'maxsols' is 0\n"); - return 0; - } - - if (sols == NULL) { - LOG("solve: return parameter 'sols' is NULL\n"); - return -1; - } - if (estimate == NULL) { LOG("solve: 'estimate' is NULL\n"); return -1; @@ -230,27 +156,3 @@ solve_simple( &estimate_simple ); } - -int64_t -gendata(const char *solver, const char *options, void *data) -{ - int64_t ret; - uint8_t maxdepth, h, i, j; - - if (!strcmp(solver, "H48")) { - /* - TODO: write a generic parser for options - for now it accepts "h;maxdepth" - */ - for (i = 0; options[i] != ';'; i++) ; - for (j = i; options[j]; j++) ; - h = atoi(options); - maxdepth = atoi(&options[i+1]); - ret = gendata_h48(data, h, maxdepth); - } else { - LOG("gendata: implemented only for H48 solver\n"); - ret = -1; - } - - return ret; -} -- cgit v1.3