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 d9f40f59c9f14bef7f87c11da7494f7dcf1457b4
parent 832ad3dcf3818e57c53304ea9b09a943e785a16b
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Mon, 10 Jun 2024 22:22:03 +0200

Started cube.h refactor

Diffstat:
Msrc/cube.c | 2++
Msrc/cube.h | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Msrc/cube_generic.h | 7+++++++
Asrc/cube_public.h | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/solve_generic.h | 19-------------------
5 files changed, 149 insertions(+), 43 deletions(-)

diff --git a/src/cube.c b/src/cube.c @@ -47,3 +47,5 @@ #include "moves.h" #include "solve_h48.h" #include "solve_generic.h" + +#include "cube_public.h" diff --git a/src/cube.h b/src/cube.h @@ -1,32 +1,65 @@ -/* TODO: change cube to const char [static 22], or const char * */ -/* TODO: return error code */ -/* TODO: implement all of this, or move the implementation to cube_public.h */ -/* TODO: document in a separate file, possibly leave here 1-line comments */ - -cube_t compose(cube_t cube, cube_t perm); -cube_t inverse(cube_t cube); -cube_t solvedcube(void); -cube_t applymoves(cube_t, const char *); -cube_t applytrans(cube_t, const char *); -cube_t readcube(const char *format, const char *buf); -void writecube(const char *format, cube_t cube, char *buf); -int64_t solve( - cube_t cube, +/* +All the functions below return 0 in case of success and a positive number +in case of error. See (TODO: documentation) for details. +*/ + +int nissy_compose( + const char cube[static 22], + const char permutation[static 22], + char result[static 22] +); + +int nissy_inverse( + const char cube[static 22], + char result[static 22] +); + +int nissy_applyoves( + const char cube[static 22], + const char *moves, + char result[static 22] +); + +int nissy_applytrans( + const char cube[static 22], + const char *transformation, + char result[static 22] +); + +int nissy_frommoves( + const char *moves, + char result[static 22] +); + +int nissy_readcube( + const char *format, + const char *cube_string, + char result[static 22] +); + +int nissy_writecube( + const char *format, + const char cube[static 22], + char *result +); + +int nissy_gendata( + const char *solver, + const char *options, + void *generated_data, + int64_t *generated_bytes +); + +int nissy_solve( + const char cube[static 22], const char *solver, const char *options, const char *nisstype, int8_t minmoves, int8_t maxmoves, - int64_t maxsols, + int64_t maxsolutions, int8_t optimal, - const void *data, - char *solutions -); -void multisolve( - int n, - cube_t *cube, - const char *solver, const void *data, - char *sols + char *solutions, + int *n_solutions ); -int64_t gendata(const char *solver, const char *options, void *data); diff --git a/src/cube_generic.h b/src/cube_generic.h @@ -8,6 +8,7 @@ _static bool issolved(cube_t); _static bool iserror(cube_t); _static cube_t applymoves(cube_t, const char *); _static cube_t applytrans(cube_t, const char *); +_static cube_t frommoves(const char *); _static int permsign(uint8_t *, int); _static cube_t move(cube_t, uint8_t); @@ -165,6 +166,12 @@ applymoves_error: } _static cube_t +frommoves(const char *buf) +{ + return applymoves(solved, buf); +} + +_static cube_t applytrans(cube_t cube, const char *buf) { uint8_t t; diff --git a/src/cube_public.h b/src/cube_public.h @@ -0,0 +1,83 @@ +int check(cube_t, char [static 22]); + +int +check(cube_t cube, char result[static 22]) +{ + if (!isconsistent(cube)) { + writecube("B32", zero, result); + return 2; + } + + return issolvable(cube) ? 0 : 1; +} + +int +nissy_compose( + const char cube[static 22], + const char permutation[static 22], + char result[static 22] +) +{ + cube_t c, p, res; + + c = readcube("B32", cube); + p = readcube("B32", permutation); + + res = compose(c, p); + + return check(res, result); +} + +int +nissy_inverse( + const char cube[static 22], + char result[static 22] +); + +int nissy_applymoves( + const char cube[static 22], + const char *moves, + char result[static 22] +); + +int nissy_applytrans( + const char cube[static 22], + const char *transformation, + char result[static 22] +); + +int nissy_frommoves( + const char *moves, + char result[static 22] +); + +int nissy_readcube( + const char *format, + const char *cube_string, + char result[static 22] +); + +int nissy_writecube( + const char *format, + const char cube[static 22], + char *result +); + +int64_t nissy_gendata( + const char *solver, + const char *options, + void *data +); + +int64_t nissy_solve( + const char cube[static 22], + const char *solver, + const char *options, + const char *nisstype, + int8_t minmoves, + int8_t maxmoves, + int64_t maxsolutions, + int8_t optimal, + const void *data, + char *solutions +); diff --git a/src/solve_generic.h b/src/solve_generic.h @@ -57,25 +57,6 @@ solve( return -1; } -void -multisolve( - int n, - cube_t *cube, - const char *solver, - const void *data, - char *sols -) -{ - char *s; - int i; - - s = sols; - for (i = 0; i < n; i++) { - solve(cube[i], solver, "", "normal", 0, -1, 1, 0, NULL, s); - while (s++); - } -} - _static void solve_generic_appendsolution(dfsarg_generic_t *arg) {