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 6008855b28763f297f4379dfcdc23eacb303ee45
parent ce987d566b8322d0e341a2c9baf0608d1609943b
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 15 Dec 2024 11:14:42 +0100

Added tool to check for correctnes of H48 solver. TODO: add more scrambles.

Diffstat:
Mtools/400_solvetest/solve_test.c | 22++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/400_solvetest/solve_test.c b/tools/400_solvetest/solve_test.c @@ -14,8 +14,17 @@ char *buf; scramblesol_t s[] = { [0] = { .scramble = "R' D R U R' D' R U'", - .solutions = "U R' D R U' R' D' R\n" - "B' D2 B U' B' D2 B U\n", + .solutions = + "U R' D R U' R' D' R\n" + "B' D2 B U' B' D2 B U\n" +}, +[1] = { + .scramble = "R' L U2 R L' B2", + .solutions = + "B2 R' L U2 R L'\n" + "R L' B2 R' L U2\n" + "R B2 R' L U2 L'\n" + "L' B2 R' L U2 R\n" }, { .scramble = "", /* End-of-list signal */ @@ -26,7 +35,7 @@ bool check_one(char *actual, char *expected) { unsigned i; size_t l_actual, l_expected; - l_actual = strlen(actual); + for (l_actual = 0; actual[l_actual] != '\n'; l_actual++) ; l_expected = strlen(expected); if (l_actual > l_expected) return false; @@ -42,15 +51,16 @@ bool check_all(char *actual, char *expected) { unsigned i, found, n_expected; size_t l_actual; - if (strlen(actual) != strlen(expected)) + l_actual = strlen(actual); + if (l_actual != strlen(expected)) return false; for (i = 0, n_expected = 0; expected[i]; i++) n_expected += expected[i] == '\n'; - l_actual = strlen(actual); for (i = 0, found = 0; i < l_actual; i++) - found += check_one(&actual[i], expected); + if (i == 0 || actual[i-1] == '\n') + found += check_one(&actual[i], expected); return found == n_expected; }