diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-30 17:52:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-30 17:52:55 +0200 |
| commit | ff4bde84872ec0b93f0f097f5a56bd5e7cbb0311 (patch) | |
| tree | 2c5faddf404ebd92bd1b1039dd0c8a779de4fc58 /src/solvers/h48 | |
| parent | eb20084ec94e9043e55a98717128a4ba1e6215cb (diff) | |
| parent | 4abb800c4b4f3a509c07821ade8d34e3699bdf10 (diff) | |
| download | nissy-core-ff4bde84872ec0b93f0f097f5a56bd5e7cbb0311.tar.gz nissy-core-ff4bde84872ec0b93f0f097f5a56bd5e7cbb0311.zip | |
Merge pull request #2 from enricotenuti/master
nissbranch ver1
Diffstat (limited to 'src/solvers/h48')
| -rw-r--r-- | src/solvers/h48/solve.h | 75 |
1 files changed, 52 insertions, 23 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 0843792..bbe59e5 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -11,6 +11,9 @@ typedef struct { | |||
| 11 | uint32_t *cocsepdata; | 11 | uint32_t *cocsepdata; |
| 12 | uint32_t *h48data; | 12 | uint32_t *h48data; |
| 13 | char **nextsol; | 13 | char **nextsol; |
| 14 | uint8_t nissbranch; | ||
| 15 | int8_t npremoves; | ||
| 16 | uint8_t premoves[MAXLEN]; | ||
| 14 | } dfsarg_solveh48_t; | 17 | } dfsarg_solveh48_t; |
| 15 | 18 | ||
| 16 | typedef struct { | 19 | typedef struct { |
| @@ -26,8 +29,7 @@ typedef struct { | |||
| 26 | _static void solve_h48_appendsolution(dfsarg_solveh48_t *); | 29 | _static void solve_h48_appendsolution(dfsarg_solveh48_t *); |
| 27 | _static_inline bool solve_h48_stop(dfsarg_solveh48_t *); | 30 | _static_inline bool solve_h48_stop(dfsarg_solveh48_t *); |
| 28 | _static int64_t solve_h48_dfs(dfsarg_solveh48_t *); | 31 | _static int64_t solve_h48_dfs(dfsarg_solveh48_t *); |
| 29 | _static int64_t solve_h48( | 32 | _static int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); |
| 30 | cube_t, int8_t, int8_t, int8_t, uint8_t, uint8_t, const void *, char *); | ||
| 31 | 33 | ||
| 32 | _static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); | 34 | _static int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *); |
| 33 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); | 35 | _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]); |
| @@ -36,10 +38,22 @@ _static void | |||
| 36 | solve_h48_appendsolution(dfsarg_solveh48_t *arg) | 38 | solve_h48_appendsolution(dfsarg_solveh48_t *arg) |
| 37 | { | 39 | { |
| 38 | int strl; | 40 | int strl; |
| 41 | char *solution = *arg->nextsol; | ||
| 39 | 42 | ||
| 40 | strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); | 43 | strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); |
| 41 | LOG("Solution found: %s\n", *arg->nextsol); | 44 | *arg->nextsol += strl; |
| 42 | *arg->nextsol += strl; | 45 | |
| 46 | if (arg->npremoves) { | ||
| 47 | **arg->nextsol = ' '; | ||
| 48 | (*arg->nextsol)++; | ||
| 49 | |||
| 50 | uint8_t* invertedpremoves = invertpremoves(arg->premoves, arg->npremoves); | ||
| 51 | strl = writemoves(invertedpremoves, arg->npremoves, *arg->nextsol); | ||
| 52 | free(invertedpremoves); | ||
| 53 | *arg->nextsol += strl; | ||
| 54 | } | ||
| 55 | LOG("Solution found: %s\n", solution); | ||
| 56 | |||
| 43 | **arg->nextsol = '\n'; | 57 | **arg->nextsol = '\n'; |
| 44 | (*arg->nextsol)++; | 58 | (*arg->nextsol)++; |
| 45 | (*arg->nsols)++; | 59 | (*arg->nsols)++; |
| @@ -51,24 +65,27 @@ solve_h48_stop(dfsarg_solveh48_t *arg) | |||
| 51 | uint32_t data, data_inv; | 65 | uint32_t data, data_inv; |
| 52 | int8_t bound; | 66 | int8_t bound; |
| 53 | 67 | ||
| 68 | arg->nissbranch = NORMAL; | ||
| 54 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); | 69 | bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); |
| 55 | if (bound + arg->nmoves > arg->depth) | 70 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 56 | return true; | 71 | return true; |
| 57 | 72 | ||
| 58 | bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); | 73 | bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); |
| 59 | if (bound + arg->nmoves > arg->depth) | 74 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 60 | return true; | 75 | return true; |
| 61 | 76 | ||
| 62 | /* | ||
| 63 | bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); | 77 | bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); |
| 64 | LOG("Using pval %" PRId8 "\n", bound); | 78 | // LOG("Using pval %" PRId8 "\n", bound); |
| 65 | if (bound + arg->nmoves > arg->depth) | 79 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 66 | return true; | 80 | return true; |
| 81 | if (bound + arg->nmoves + arg->npremoves == arg->depth) | ||
| 82 | arg->nissbranch = INVERSEBRANCH; | ||
| 67 | 83 | ||
| 68 | bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); | 84 | bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); |
| 69 | if (bound + arg->nmoves > arg->depth) | 85 | if (bound + arg->nmoves + arg->npremoves > arg->depth) |
| 70 | return true; | 86 | return true; |
| 71 | */ | 87 | if (bound + arg->nmoves + arg->npremoves == arg->depth) |
| 88 | arg->nissbranch = NORMALBRANCH; | ||
| 72 | 89 | ||
| 73 | return false; | 90 | return false; |
| 74 | } | 91 | } |
| @@ -87,7 +104,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 87 | return 0; | 104 | return 0; |
| 88 | 105 | ||
| 89 | if (issolved(arg->cube)) { | 106 | if (issolved(arg->cube)) { |
| 90 | if (arg->nmoves != arg->depth) | 107 | if (arg->nmoves + arg->npremoves != arg->depth) |
| 91 | return 0; | 108 | return 0; |
| 92 | solve_h48_appendsolution(arg); | 109 | solve_h48_appendsolution(arg); |
| 93 | return 1; | 110 | return 1; |
| @@ -95,19 +112,30 @@ solve_h48_dfs(dfsarg_solveh48_t *arg) | |||
| 95 | 112 | ||
| 96 | /* TODO: avoid copy, change arg and undo changes after recursion */ | 113 | /* TODO: avoid copy, change arg and undo changes after recursion */ |
| 97 | nextarg = *arg; | 114 | nextarg = *arg; |
| 98 | nextarg.nmoves = arg->nmoves + 1; | ||
| 99 | ret = 0; | 115 | ret = 0; |
| 100 | for (m = 0; m < 18; m++) { | 116 | uint32_t allowed; |
| 101 | nextarg.moves[arg->nmoves] = m; | 117 | if(arg->nissbranch & INVERSE) { |
| 102 | if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { | 118 | allowed = allowednextmoveH48(arg->premoves, arg->npremoves, arg->nissbranch); |
| 103 | /* If a move is not allowed, neither are its 180 | 119 | for (m = 0; m < 18; m++) { |
| 104 | * and 270 degree variations */ | 120 | if(allowed & (1 << m)) { |
| 105 | m += 2; | 121 | nextarg.npremoves = arg->npremoves + 1; |
| 106 | continue; | 122 | nextarg.premoves[arg->npremoves] = m; |
| 123 | nextarg.inverse = move(arg->inverse, m); | ||
| 124 | nextarg.cube = premove(arg->cube, m); | ||
| 125 | ret += solve_h48_dfs(&nextarg); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } else { | ||
| 129 | allowed = allowednextmoveH48(arg->moves, arg->nmoves, arg->nissbranch); | ||
| 130 | for (m = 0; m < 18; m++) { | ||
| 131 | if (allowed & (1 << m)) { | ||
| 132 | nextarg.nmoves = arg->nmoves + 1; | ||
| 133 | nextarg.moves[arg->nmoves] = m; | ||
| 134 | nextarg.cube = move(arg->cube, m); | ||
| 135 | nextarg.inverse = premove(arg->inverse, m); | ||
| 136 | ret += solve_h48_dfs(&nextarg); | ||
| 137 | } | ||
| 107 | } | 138 | } |
| 108 | nextarg.cube = move(arg->cube, m); | ||
| 109 | nextarg.inverse = inverse(nextarg.cube); /* TODO: use premove */ | ||
| 110 | ret += solve_h48_dfs(&nextarg); | ||
| 111 | } | 139 | } |
| 112 | 140 | ||
| 113 | return ret; | 141 | return ret; |
| @@ -148,6 +176,7 @@ solve_h48( | |||
| 148 | LOG("Found %" PRId64 " solutions, searching at depth %" | 176 | LOG("Found %" PRId64 " solutions, searching at depth %" |
| 149 | PRId8 "\n", nsols, arg.depth); | 177 | PRId8 "\n", nsols, arg.depth); |
| 150 | arg.nmoves = 0; | 178 | arg.nmoves = 0; |
| 179 | arg.npremoves = 0; | ||
| 151 | solve_h48_dfs(&arg); | 180 | solve_h48_dfs(&arg); |
| 152 | } | 181 | } |
| 153 | 182 | ||
