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 3cb66440de97a787a974eed87a5fd876b46cef92
parent 2c109db35b3b30b27e71e7811776edec1af1208e
Author: enricotenuti <tenutz_27@outlook.it>
Date:   Thu, 26 Sep 2024 10:48:27 +0200

Fixed solutions vector, added constants

Diffstat:
Msrc/solvers/h48/solve.h | 3++-
Msrc/solvers/h48/thread.h | 21++++++++++++---------
Mtools/200_solve_small/solve_small.c | 2++
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -199,6 +199,7 @@ solve_h48( arg.npremoves = 0; solve_h48_dfs(&arg); } - + **arg.nextsol = '\0'; + (*arg.nextsol)++; return nsols; } diff --git a/src/solvers/h48/thread.h b/src/solvers/h48/thread.h @@ -4,7 +4,8 @@ #include <stdio.h> #include <stdlib.h> -#define MAX_QUEUE_SIZE 500 +#define MAX_QUEUE_SIZE 244 +#define BFS_DEPTH 2 typedef struct { dfsarg_solveh48_t *tasks[MAX_QUEUE_SIZE]; @@ -31,7 +32,7 @@ STATIC void solve_h48_appendsolution_thread(dfsarg_solveh48_t *arg, task_queue_t *tq) { pthread_mutex_lock(&tq->mutex); - int strl; + int strl = 0; uint8_t invertedpremoves[MAXLEN]; char *solution = *arg->nextsol; @@ -168,7 +169,7 @@ solve_h48_bfs(dfsarg_solveh48_t *arg_zero, task_queue_t *tq) nextarg.cube = move(arg.cube, m); nextarg.inverse = premove(arg.inverse, m); - if (nextarg.nmoves == 2){ + if (nextarg.nmoves == BFS_DEPTH){ dfsarg_solveh48_t *task = malloc(sizeof(dfsarg_solveh48_t)); *task = nextarg; submit_task(tq, task); @@ -179,11 +180,11 @@ solve_h48_bfs(dfsarg_solveh48_t *arg_zero, task_queue_t *tq) } } if (nodes_at_current_depth == 0){ - depth++; nodes_at_current_depth = nodes_at_next_depth; nodes_at_next_depth = 0; + LOG("Found %" PRId64 " solutions, searching at depth %" PRId8 "\n", *nextarg.nsols, depth++); } - if (depth == 2) return 0; + if (depth == BFS_DEPTH) return 0; } return 1; } @@ -248,7 +249,7 @@ solve_h48_parent( { int64_t nsols = 0; int p_depth = 0; - dfsarg_solveh48_t bfs_arg; + dfsarg_solveh48_t arg; tableinfo_t info; pthread_t threads[THREADS]; @@ -258,7 +259,7 @@ solve_h48_parent( return 0; } - bfs_arg = (dfsarg_solveh48_t){ + arg = (dfsarg_solveh48_t){ .cube = cube, .inverse = inverse(cube), .nsols = &nsols, @@ -271,7 +272,7 @@ solve_h48_parent( task_queue_t q; init_queue(&q); - if (solve_h48_bfs(&bfs_arg, &q)) + if (solve_h48_bfs(&arg, &q)) return nsols; task_queue_t nq; @@ -282,7 +283,7 @@ solve_h48_parent( } nsols = 0; - for (p_depth = minmoves > 2 ? minmoves : 2; + for (p_depth = minmoves > BFS_DEPTH ? minmoves : BFS_DEPTH; p_depth <= maxmoves && nsols < maxsolutions; p_depth++) { @@ -301,5 +302,7 @@ solve_h48_parent( for (int i = 0; i < THREADS; i++){ pthread_join(threads[i], NULL); } + **arg.nextsol = '\0'; + (*arg.nextsol)++; return nsols; } diff --git a/tools/200_solve_small/solve_small.c b/tools/200_solve_small/solve_small.c @@ -10,6 +10,8 @@ char *buf; char *scrambles[] = { "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ "RLUD RLUD RLUD", /* 12 optimal */ + "R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F", /* FMC2019 A1 - 16 optimal */ + // "R' U' F D R F2 D L F D2 F2 L' U R' L2 D' R2 F2 R2 D L2 U2 R' U' F", /* FMC2024 A1 - 19 optimal */ NULL };