commit 05bdcfef13ef2bdd05df6af13a74ec3cd7fcd22f
parent 71c0188306377940ae172dceb58f2bd5f4fcdb4f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sun, 23 Jun 2024 12:09:37 +0200
Cleanup
Diffstat:
9 files changed, 73 insertions(+), 221 deletions(-)
diff --git a/TODO.txt b/TODO.txt
@@ -1,26 +1,22 @@
-Shell and nissy_run
- x done shell.c, but it is ugly (as expected)
- - move stuff from solve_generic to cube_public
- - make shell a bit nicer?
-
-Fixes
- - tables/tables.c: fix, use new nissy_gendata and nissy_datasize
-
Solver
+ - write a solver (how many tricks? some, but not all are needed)
- benchmark for solve
table generation, where to keep tables? in benchmark folder or in tables/?
- - write a solver (how many tricks? some, but not all are needed)
+ - remove solve_simple and maybe the whole solve_generic
-More utilities for tables (in cube.h)
- - cleanup solve and gendata in cube.h and cube_public.h
- - check hash of generated data
+Cleanup cube_public and interface
+ - remove options, use only solver name
+ cleanup also benchmark
+ - write a generic parse + dispatch to solver
+ (maybe use helper function from solve_h48 for parsing hXkY)
Goal: find out which k value is best
- temporarily call current table and solver "k4" instead of h48
- write table generation and solver for k2 and k1
- benchmark for different sizes!
-Read / write: replace by convertcube only?
+Improvements
+ - check hash of generated data
## H48 optimal solver (some has already been implemented)
diff --git 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
@@ -89,20 +89,6 @@ nissy_frommoves(
}
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,
const char *format_out,
@@ -119,16 +105,6 @@ nissy_convertcube(
}
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,
const char *options
@@ -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
@@ -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;
-}
diff --git a/test/090_solve_simple/01_U_U3.in b/test/090_solve_simple/01_U_U3.in
@@ -1,8 +0,0 @@
-UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0
-simple
-
-normal
-0
-3
-3
--1
diff --git a/test/090_solve_simple/01_U_U3.out b/test/090_solve_simple/01_U_U3.out
@@ -1 +0,0 @@
-U'
diff --git a/test/090_solve_simple/02_MUMU_alloptimal.in b/test/090_solve_simple/02_MUMU_alloptimal.in
@@ -1,8 +0,0 @@
-UB0 DF0 DB0 UF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
-simple
-
-normal
-0
--1
-10
-0
diff --git a/test/090_solve_simple/02_MUMU_alloptimal.out b/test/090_solve_simple/02_MUMU_alloptimal.out
@@ -1,4 +0,0 @@
-U2 R' L F2 R L'
-R U2 R' L F2 L'
-R L' U2 R' L F2
-L' U2 R' L F2 R
diff --git a/test/090_solve_simple/solve_simple_tests.c b/test/090_solve_simple/solve_simple_tests.c
@@ -1,48 +0,0 @@
-#include "../test.h"
-
-int64_t solve(cube_t, char *, char *, char *, int8_t, int8_t, int64_t, int8_t,
- void *, char *);
-
-void run(void) {
- char cubestr[STRLENMAX], solverstr[STRLENMAX], optionsstr[STRLENMAX];
- char nisstypestr[STRLENMAX], minmovesstr[STRLENMAX];
- char maxmovesstr[STRLENMAX], maxsolsstr[STRLENMAX];
- char optimalstr[STRLENMAX], solutionsstr[STRLENMAX];
- cube_t cube;
- int64_t maxsols;
- int8_t minmoves, maxmoves, optimal;
-
- fgets(cubestr, STRLENMAX, stdin);
- fgets(solverstr, STRLENMAX, stdin);
- fgets(optionsstr, STRLENMAX, stdin);
- fgets(nisstypestr, STRLENMAX, stdin);
- fgets(minmovesstr, STRLENMAX, stdin);
- fgets(maxmovesstr, STRLENMAX, stdin);
- fgets(maxsolsstr, STRLENMAX, stdin);
- fgets(optimalstr, STRLENMAX, stdin);
-
- solverstr[strcspn(solverstr, "\n")] = 0;
- optionsstr[strcspn(optionsstr, "\n")] = 0;
- nisstypestr[strcspn(nisstypestr, "\n")] = 0;
-
- cube = readcube("H48", cubestr);
- minmoves = atoi(minmovesstr);
- maxmoves = atoi(maxmovesstr);
- maxsols = atoi(maxsolsstr);
- optimal = atoi(optimalstr);
-
- solve(
- cube,
- solverstr,
- optionsstr,
- nisstypestr,
- minmoves,
- maxmoves,
- maxsols,
- optimal,
- NULL,
- solutionsstr
- );
-
- printf("%s", solutionsstr);
-}