nissy-nx

A Rubik's cube optimal solver
git clone https://git.tronto.net/nissy-nx
Download | Log | Files | Refs | README | LICENSE

commit 1ac26de8dcb76323a5f96eab200a027236cb55d0
parent 4da48094d65b4269be7a4d7d2dc9c7d72f2e6869
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Fri, 28 Oct 2022 08:01:01 +0200

Quick push warning message

Diffstat:
MREADME.md | 7+++++++
MTODO.md | 6+++++-
Msrc/cubetypes.h | 1+
Msrc/fst.c | 1+
Mtests/test_fst.c | 161++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
5 files changed, 137 insertions(+), 39 deletions(-)

diff --git a/README.md b/README.md @@ -1,3 +1,10 @@ +# WARNING + +I am currently rewriting some important parts of the code +and the git version is not working. +You can download the last stable version from the +[download page](https://nissy.tronto.net/download). + # Nissy A Rubik's cube solver and FMC assistant. diff --git a/TODO.md b/TODO.md @@ -9,7 +9,11 @@ It's more of a personal reminder than anything else. of the files includes + doing more stuff. A static "initiliazed" variable is probably needed too. ### testing! -* test fst and other things... +* test fst: implement fst_consistent +* test fst: init_fst is necessary before testing move and inverse +* separate "commands" for testing different parts (e.g. ./test coord) +* test coordinate (needed anyway to test fst) +* other tests (start from bottom: utils.c) * move test_coord to the testing folder ### Solving standard coordinates * add Void * extradata to DfsArg and a custom move function diff --git a/src/cubetypes.h b/src/cubetypes.h @@ -103,6 +103,7 @@ typedef struct threaddatagenpt ThreadDataGenpt; typedef struct transgroup TransGroup; typedef bool (*Checker) (Cube *); +typedef bool (*CubeTester) (Cube *, Alg *); typedef bool (*DfsMover) (DfsArg *); typedef void (*DfsExtraCopier) (void *, void *); typedef bool (*Validator) (Alg *); diff --git a/src/fst.c b/src/fst.c @@ -43,6 +43,7 @@ cube_to_fst(Cube *cube) ret.fr_eofb = coord_eofb.i[0]->index(&c); ret.fr_eposepe = coord_eposepe.i[0]->index(&c); ret.fr_coud = coord_coud.i[0]->index(&c); + copy_cube(cube, &c); apply_trans(rd, &c); ret.rd_eofb = coord_eofb.i[0]->index(&c); ret.rd_eposepe = coord_eposepe.i[0]->index(&c); diff --git a/tests/test_fst.c b/tests/test_fst.c @@ -1,24 +1,62 @@ #include "inc.h" #include "../src/fst.h" -static bool test_cube_to_fst_to_cube(Cube *c); +static bool cube_to_fst_to_cube(Cube *c, Alg *a); +static bool fst_consistent(Cube *c, Alg *a); +static bool fst_move_test(Cube *c, Alg *a); +static bool fst_inverse_test(Cube *c, Alg *a); +static bool try_str(CubeTester f, char *algstr, char *msg); +static bool try_all_str(CubeTester f, char *msg); -static bool test_cube_to_fst_to_cube_solved(); -static bool test_cube_to_fst_to_cube_unsolved(); +static bool test_fst_consistent_algs(); +static bool test_cube_to_fst_to_cube_algs(); +static bool test_fst_move_algs(); +static bool test_fst_inverse_algs(); static Tester test[] = { - test_cube_to_fst_to_cube_solved, - test_cube_to_fst_to_cube_unsolved, + test_fst_consistent_algs, + test_cube_to_fst_to_cube_algs, + test_fst_move_algs, + test_fst_inverse_algs, NULL }; static char *name[] = { - "Cube to FST to cube (solved)", - "Cube to FST to cube (unsolved)", + "Consistency of FST (converted from cube)", + "Cube to FST to cube", + "FST move", + "FST inverse", }; +static char *algs[] = { + "", + "U", "U2", "U'", "D", "D2", "D'", "R", "R2", "R'", + "L", "L2", "L'", "F", "F2", "F'", "B", "B2", "B'", + "U2 R2 U2 R2 U2", + "U2 F2 R2 B2 U2 D2 F2 L2 B2", + "RUR'URU2R'", + "L2 D R U2 B2 L", + "R'U'F", + "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2", + "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2", + "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B", + NULL, +}; + +static bool +fst_consistent(Cube *c, Alg *a) +{ + FstCube fst; + + fst = cube_to_fst(c); + + /* TODO: check consistency of fr_* and rd_* with uf_* */ + + return true; +} + static bool -test_cube_to_fst_to_cube(Cube *c) +cube_to_fst_to_cube(Cube *c, Alg *a) { Cube d; FstCube fst; @@ -40,46 +78,93 @@ test_cube_to_fst_to_cube(Cube *c) } static bool -test_cube_to_fst_to_cube_solved() +fst_move_test(Cube *c, Alg *a) +{ + int i; + Cube d; + FstCube fst; + + fst = cube_to_fst(c); + + for (i = 0; i < a->len; i++) { + if (a->inv[i] || a->move[i] > B3) { + printf("Cannot apply the following alg to FST: "); + print_alg(a, false); + return false; + } + fst = fst_move(a->move[i], fst); + } + + fst_to_cube(fst, &d); + + return equal(c, &d); +} + +static bool +fst_inverse_test(Cube *c, Alg *a) +{ + Cube d; + + fst_to_cube(fst_inverse(cube_to_fst(c)), &d); + invert_cube(c); + + return equal(c, &d); +} + +static bool +try_str(CubeTester f, char *algstr, char *msg) { + bool b; + Alg *a; Cube c; + a = new_alg(algstr); make_solved(&c); - return test_cube_to_fst_to_cube(&c); + apply_alg(a, &c); + + if (!(b = f(&c, a))) + printf("%s with alg %s\n", msg, algstr); + + free_alg(a); + + return b; } static bool -test_cube_to_fst_to_cube_unsolved() +try_all_str(CubeTester f, char *msg) { bool b; int i; - Alg *a; - Cube c; - char *algs[] = { - "U2 R2 U2 R2 U2", - "U2 F2 R2 B2 U2 D2 F2 L2 B2", - "RUR'URU2R'", - "L2 D R U2 B2 L", - "R'U'F", - "F2 U' R2 D' B2 D2 R2 D2 R2 U' F L' U' R B F2 R B' D2", - "D L2 F2 R2 D R2 U L2 U' B2 D L' F2 U2 B' L D' U' R' B2 F2", - "F' L2 F' D' R F2 L U L' D2 R2 F2 D2 R2 B' L2 B2 U2 F D2 B", - NULL, - }; - - for (i = 0; algs[i] != NULL; i++) { - make_solved(&c); - a = new_alg(algs[i]); - apply_alg(a, &c); - b = test_cube_to_fst_to_cube(&c); - free_alg(a); - if (!b) { - printf("Cube to FST to cube failed with alg %s\n", - algs[i]); - return false; - } - } - return true; + + b = true; + for (i = 0; algs[i] != NULL; i++) + b = b && try_str(f, algs[i], msg); + + return b; +} + +static bool +test_cube_to_fst_to_cube_algs() +{ + return try_all_str(cube_to_fst_to_cube, "Cube to FST to cube failed"); +} + +static bool +test_fst_consistent_algs() +{ + return try_all_str(fst_consistent, "FST from cube not consistent"); +} + +static bool +test_fst_move_algs() +{ + return try_all_str(fst_move_test, "FST move incorrect"); +} + +static bool +test_fst_inverse_algs() +{ + return try_all_str(fst_inverse_test, "FST test incorrect"); } void test_fst_all() {