aboutsummaryrefslogtreecommitdiff
path: root/src/solvers
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-03 21:52:16 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-03 21:52:16 +0200
commitc9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (patch)
treef4f569fcbd4d6704fb5dd44892911ce808f03332 /src/solvers
parentff4bde84872ec0b93f0f097f5a56bd5e7cbb0311 (diff)
downloadnissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.tar.gz
nissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.zip
Moved stuff around
Diffstat (limited to '')
-rw-r--r--src/solvers/h48/solve.h46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index bbe59e5..3878498 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -26,6 +26,8 @@ typedef struct {
26 char *s; 26 char *s;
27} dfsarg_solveh48stats_t; 27} dfsarg_solveh48stats_t;
28 28
29_static uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint32_t);
30
29_static void solve_h48_appendsolution(dfsarg_solveh48_t *); 31_static void solve_h48_appendsolution(dfsarg_solveh48_t *);
30_static_inline bool solve_h48_stop(dfsarg_solveh48_t *); 32_static_inline bool solve_h48_stop(dfsarg_solveh48_t *);
31_static int64_t solve_h48_dfs(dfsarg_solveh48_t *); 33_static int64_t solve_h48_dfs(dfsarg_solveh48_t *);
@@ -34,10 +36,39 @@ _static int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, cons
34_static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); 36_static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *);
35_static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); 37_static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]);
36 38
39_static uint32_t
40allowednextmove_h48(uint8_t *moves, uint8_t n, uint32_t h48branch)
41{
42 uint32_t result = _mm_allmoves;
43 if (h48branch & _mm_normalbranch)
44 result &= _mm_nohalfturns;
45 if (n < 1)
46 return result;
47
48 uint8_t base1 = movebase(moves[n-1]);
49 uint8_t axis1 = moveaxis(moves[n-1]);
50
51 result = disable_moves(result, base1 * 3);
52 if (base1 % 2)
53 result = disable_moves(result, (base1 - 1) * 3);
54
55 if (n == 1)
56 return result;
57
58 uint8_t base2 = movebase(moves[n-2]);
59 uint8_t axis2 = moveaxis(moves[n-2]);
60
61 if(axis1 == axis2)
62 result = disable_moves(result, base2 * 3);
63
64 return result;
65}
66
37_static void 67_static void
38solve_h48_appendsolution(dfsarg_solveh48_t *arg) 68solve_h48_appendsolution(dfsarg_solveh48_t *arg)
39{ 69{
40 int strl; 70 int strl;
71 uint8_t invertedpremoves[MAXLEN];
41 char *solution = *arg->nextsol; 72 char *solution = *arg->nextsol;
42 73
43 strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); 74 strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol);
@@ -47,9 +78,8 @@ solve_h48_appendsolution(dfsarg_solveh48_t *arg)
47 **arg->nextsol = ' '; 78 **arg->nextsol = ' ';
48 (*arg->nextsol)++; 79 (*arg->nextsol)++;
49 80
50 uint8_t* invertedpremoves = invertpremoves(arg->premoves, arg->npremoves); 81 invertmoves(arg->premoves, arg->npremoves, invertedpremoves);
51 strl = writemoves(invertedpremoves, arg->npremoves, *arg->nextsol); 82 strl = writemoves(invertedpremoves, arg->npremoves, *arg->nextsol);
52 free(invertedpremoves);
53 *arg->nextsol += strl; 83 *arg->nextsol += strl;
54 } 84 }
55 LOG("Solution found: %s\n", solution); 85 LOG("Solution found: %s\n", solution);
@@ -65,7 +95,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
65 uint32_t data, data_inv; 95 uint32_t data, data_inv;
66 int8_t bound; 96 int8_t bound;
67 97
68 arg->nissbranch = NORMAL; 98 arg->nissbranch = _mm_normal;
69 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); 99 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data);
70 if (bound + arg->nmoves + arg->npremoves > arg->depth) 100 if (bound + arg->nmoves + arg->npremoves > arg->depth)
71 return true; 101 return true;
@@ -79,13 +109,13 @@ solve_h48_stop(dfsarg_solveh48_t *arg)
79 if (bound + arg->nmoves + arg->npremoves > arg->depth) 109 if (bound + arg->nmoves + arg->npremoves > arg->depth)
80 return true; 110 return true;
81 if (bound + arg->nmoves + arg->npremoves == arg->depth) 111 if (bound + arg->nmoves + arg->npremoves == arg->depth)
82 arg->nissbranch = INVERSEBRANCH; 112 arg->nissbranch = _mm_inversebranch;
83 113
84 bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); 114 bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data);
85 if (bound + arg->nmoves + arg->npremoves > arg->depth) 115 if (bound + arg->nmoves + arg->npremoves > arg->depth)
86 return true; 116 return true;
87 if (bound + arg->nmoves + arg->npremoves == arg->depth) 117 if (bound + arg->nmoves + arg->npremoves == arg->depth)
88 arg->nissbranch = NORMALBRANCH; 118 arg->nissbranch = _mm_normalbranch;
89 119
90 return false; 120 return false;
91} 121}
@@ -114,8 +144,8 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
114 nextarg = *arg; 144 nextarg = *arg;
115 ret = 0; 145 ret = 0;
116 uint32_t allowed; 146 uint32_t allowed;
117 if(arg->nissbranch & INVERSE) { 147 if(arg->nissbranch & _mm_inverse) {
118 allowed = allowednextmoveH48(arg->premoves, arg->npremoves, arg->nissbranch); 148 allowed = allowednextmove_h48(arg->premoves, arg->npremoves, arg->nissbranch);
119 for (m = 0; m < 18; m++) { 149 for (m = 0; m < 18; m++) {
120 if(allowed & (1 << m)) { 150 if(allowed & (1 << m)) {
121 nextarg.npremoves = arg->npremoves + 1; 151 nextarg.npremoves = arg->npremoves + 1;
@@ -126,7 +156,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
126 } 156 }
127 } 157 }
128 } else { 158 } else {
129 allowed = allowednextmoveH48(arg->moves, arg->nmoves, arg->nissbranch); 159 allowed = allowednextmove_h48(arg->moves, arg->nmoves, arg->nissbranch);
130 for (m = 0; m < 18; m++) { 160 for (m = 0; m < 18; m++) {
131 if (allowed & (1 << m)) { 161 if (allowed & (1 << m)) {
132 nextarg.nmoves = arg->nmoves + 1; 162 nextarg.nmoves = arg->nmoves + 1;

Generated with cgit - Back to sebastiano.tronto.net