diff options
Diffstat (limited to 'old')
| -rw-r--r-- | old/maybe-useful-coord.c | 181 | ||||
| -rw-r--r-- | old/maybe-useful-steps.c | 1111 | ||||
| -rw-r--r-- | old/solve_old.c | 447 | ||||
| -rw-r--r-- | old/solve_old.h | 9 |
4 files changed, 0 insertions, 1748 deletions
diff --git a/old/maybe-useful-coord.c b/old/maybe-useful-coord.c deleted file mode 100644 index 9ab2971..0000000 --- a/old/maybe-useful-coord.c +++ /dev/null | |||
| @@ -1,181 +0,0 @@ | |||
| 1 | int | ||
| 2 | array_ep_to_epos(int *ep, int *ss) | ||
| 3 | { | ||
| 4 | int epos[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
| 5 | int eps[4]; | ||
| 6 | int i, j, is; | ||
| 7 | |||
| 8 | for (i = 0, is = 0; i < 12; i++) { | ||
| 9 | for (j = 0; j < 4; j++) { | ||
| 10 | if (ep[i] == ss[j]) { | ||
| 11 | eps[is++] = j; | ||
| 12 | epos[i] = 1; | ||
| 13 | } | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | for (i = 0; i < 4; i++) | ||
| 18 | swap(&epos[ss[i]], &epos[i+8]); | ||
| 19 | |||
| 20 | return 24 * subset_to_index(epos, 12, 4) + perm_to_index(eps, 4); | ||
| 21 | } | ||
| 22 | |||
| 23 | void | ||
| 24 | epos_to_compatible_ep(int epos, int *ep, int *ss) | ||
| 25 | { | ||
| 26 | int i, j, k, other[8]; | ||
| 27 | bool flag; | ||
| 28 | |||
| 29 | for (i = 0; i < 12; i++) | ||
| 30 | ep[i] = -1; | ||
| 31 | |||
| 32 | epos_to_partial_ep(epos, ep, ss); | ||
| 33 | |||
| 34 | for (i = 0, j = 0; i < 12; i++) { | ||
| 35 | flag = false; | ||
| 36 | for (k = 0; k < 4; k++) | ||
| 37 | flag = flag || (i == ss[k]); | ||
| 38 | if (!flag) | ||
| 39 | other[j++] = i; | ||
| 40 | } | ||
| 41 | |||
| 42 | for (i = 0, j = 0; i < 12; i++) | ||
| 43 | if (ep[i] == -1) | ||
| 44 | ep[i] = other[j++]; | ||
| 45 | } | ||
| 46 | |||
| 47 | void | ||
| 48 | epos_to_partial_ep(int epos, int *ep, int *ss) | ||
| 49 | { | ||
| 50 | int i, is, eposs[12], eps[4]; | ||
| 51 | |||
| 52 | index_to_perm(epos % FACTORIAL4, 4, eps); | ||
| 53 | index_to_subset(epos / FACTORIAL4, 12, 4, eposs); | ||
| 54 | |||
| 55 | for (i = 0; i < 4; i++) | ||
| 56 | swap(&eposs[ss[i]], &eposs[i+8]); | ||
| 57 | |||
| 58 | for (i = 0, is = 0; i < 12; i++) | ||
| 59 | if (eposs[i]) | ||
| 60 | ep[i] = ss[eps[is++]]; | ||
| 61 | } | ||
| 62 | |||
| 63 | void | ||
| 64 | fix_eorleoud(CubeArray *arr) | ||
| 65 | { | ||
| 66 | int i; | ||
| 67 | |||
| 68 | for (i = 0; i < 12; i++) { | ||
| 69 | if ((edge_slice(i) == 0 && edge_slice(arr->ep[i]) != 0) || | ||
| 70 | (edge_slice(i) != 0 && edge_slice(arr->ep[i]) == 0)) { | ||
| 71 | arr->eorl[i] = 1 - arr->eofb[i]; | ||
| 72 | } else { | ||
| 73 | arr->eorl[i] = arr->eofb[i]; | ||
| 74 | } | ||
| 75 | |||
| 76 | if ((edge_slice(i) == 2 && edge_slice(arr->ep[i]) != 2) || | ||
| 77 | (edge_slice(i) != 2 && edge_slice(arr->ep[i]) == 2)) { | ||
| 78 | arr->eoud[i] = 1 - arr->eofb[i]; | ||
| 79 | } else { | ||
| 80 | arr->eoud[i] = arr->eofb[i]; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | void | ||
| 86 | fix_cofbcorl(CubeArray *arr) | ||
| 87 | { | ||
| 88 | int i; | ||
| 89 | |||
| 90 | for (i = 0; i < 8; i++) { | ||
| 91 | if (i % 2 == arr->cp[i] % 2) { | ||
| 92 | arr->cofb[i] = arr->coud[i]; | ||
| 93 | arr->corl[i] = arr->coud[i]; | ||
| 94 | } else { | ||
| 95 | if (arr->cp[i] % 2 == 0) { | ||
| 96 | arr->cofb[i] = (arr->coud[i]+1)%3; | ||
| 97 | arr->corl[i] = (arr->coud[i]+2)%3; | ||
| 98 | } else { | ||
| 99 | arr->cofb[i] = (arr->coud[i]+2)%3; | ||
| 100 | arr->corl[i] = (arr->coud[i]+1)%3; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | Cube | ||
| 107 | admissible_ep(Cube cube, PieceFilter f) | ||
| 108 | { | ||
| 109 | CubeArray *arr = new_cubearray(cube, f); | ||
| 110 | Cube ret; | ||
| 111 | bool used[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
| 112 | int i, j; | ||
| 113 | |||
| 114 | for (i = 0; i < 12; i++) | ||
| 115 | if (arr->ep[i] != -1) | ||
| 116 | used[arr->ep[i]] = true; | ||
| 117 | |||
| 118 | for (i = 0, j = 0; i < 12; i++) { | ||
| 119 | for ( ; j < 11 && used[j]; j++); | ||
| 120 | if (arr->ep[i] == -1) | ||
| 121 | arr->ep[i] = j++; | ||
| 122 | } | ||
| 123 | |||
| 124 | ret = arrays_to_cube(arr, pf_ep); | ||
| 125 | free_cubearray(arr, f); | ||
| 126 | |||
| 127 | return ret; | ||
| 128 | } | ||
| 129 | |||
| 130 | int | ||
| 131 | edge_slice(Edge e) { | ||
| 132 | if (e < 0 || e > 11) | ||
| 133 | return -1; | ||
| 134 | |||
| 135 | if (e == FR || e == FL || e == BL || e == BR) | ||
| 136 | return 0; | ||
| 137 | if (e == UR || e == UL || e == DR || e == DL) | ||
| 138 | return 1; | ||
| 139 | |||
| 140 | return 2; | ||
| 141 | } | ||
| 142 | |||
| 143 | int | ||
| 144 | piece_orientation(Cube cube, int piece, char *orientation) | ||
| 145 | { | ||
| 146 | int arr[12], n, b, x; | ||
| 147 | |||
| 148 | if (!strcmp(orientation, "eofb")) { | ||
| 149 | x = cube.eofb; | ||
| 150 | n = 12; | ||
| 151 | b = 2; | ||
| 152 | } else if (!strcmp(orientation, "eorl")) { | ||
| 153 | x = cube.eorl; | ||
| 154 | n = 12; | ||
| 155 | b = 2; | ||
| 156 | } else if (!strcmp(orientation, "eoud")) { | ||
| 157 | x = cube.eoud; | ||
| 158 | n = 12; | ||
| 159 | b = 2; | ||
| 160 | } else if (!strcmp(orientation, "coud")) { | ||
| 161 | x = cube.coud; | ||
| 162 | n = 8; | ||
| 163 | b = 3; | ||
| 164 | } else if (!strcmp(orientation, "corl")) { | ||
| 165 | x = cube.corl; | ||
| 166 | n = 8; | ||
| 167 | b = 3; | ||
| 168 | } else if (!strcmp(orientation, "cofb")) { | ||
| 169 | x = cube.cofb; | ||
| 170 | n = 8; | ||
| 171 | b = 3; | ||
| 172 | } else { | ||
| 173 | return -1; | ||
| 174 | } | ||
| 175 | |||
| 176 | int_to_sum_zero_array(x, b, n, arr); | ||
| 177 | if (piece < n) | ||
| 178 | return arr[piece]; | ||
| 179 | |||
| 180 | return -1; | ||
| 181 | } | ||
diff --git a/old/maybe-useful-steps.c b/old/maybe-useful-steps.c deleted file mode 100644 index 2a20dd9..0000000 --- a/old/maybe-useful-steps.c +++ /dev/null | |||
| @@ -1,1111 +0,0 @@ | |||
| 1 | #include "steps.h" | ||
| 2 | |||
| 3 | #define UPDATECHECKSTOP(a, b, c) if ((a=(MAX((a),(b))))>(c)) return (a); | ||
| 4 | |||
| 5 | static int estimate_stepalt(StepAlt *a, uint64_t *ind); | ||
| 6 | |||
| 7 | /* Checkers and validators ***************************************************/ | ||
| 8 | |||
| 9 | /* TODO: these should be with Cube *cube (and all need to change) */ | ||
| 10 | /* Maybe move them to cube.c */ | ||
| 11 | static bool check_centers(Cube cube); | ||
| 12 | static bool check_coud_HTM(Cube cube); | ||
| 13 | static bool check_coud_URF(Cube cube); | ||
| 14 | static bool check_corners_HTM(Cube cube); | ||
| 15 | static bool check_corners_URF(Cube cube); | ||
| 16 | static bool check_cornershtr(Cube cube); | ||
| 17 | static bool check_eofb(Cube cube); | ||
| 18 | static bool check_drud(Cube cube); | ||
| 19 | static bool check_htr(Cube cube); | ||
| 20 | |||
| 21 | static bool always_valid(Alg *alg); | ||
| 22 | static bool validate_singlecw_ending(Alg *alg); | ||
| 23 | |||
| 24 | /* Messages for when cube is not ready ***************************************/ | ||
| 25 | |||
| 26 | static char check_centers_msg[100] = "cube must be oriented (centers solved)"; | ||
| 27 | static char check_eo_msg[100] = "EO must be solved on given axis"; | ||
| 28 | static char check_dr_msg[100] = "DR must be solved on given axis"; | ||
| 29 | static char check_htr_msg[100] = "HTR must be solved"; | ||
| 30 | static char check_drany_msg[100] = "DR must be solved on at least one axis"; | ||
| 31 | |||
| 32 | /* Steps *********************************************************************/ | ||
| 33 | |||
| 34 | /* Optimal solvers *******************/ | ||
| 35 | |||
| 36 | Step | ||
| 37 | optimal_HTM = { | ||
| 38 | .shortname = "optimal", | ||
| 39 | .name = "Optimal solve (in HTM)", | ||
| 40 | |||
| 41 | .final = true, | ||
| 42 | .is_done = is_solved, | ||
| 43 | .estimate = estimate_nxopt31_HTM, | ||
| 44 | .ready = check_centers, | ||
| 45 | .ready_msg = check_centers_msg, | ||
| 46 | .is_valid = always_valid, | ||
| 47 | .moveset = &moveset_HTM, | ||
| 48 | |||
| 49 | .pre_trans = uf, | ||
| 50 | |||
| 51 | .tables = {&pd_nxopt31_HTM, &pd_corners_HTM}, | ||
| 52 | .ntables = 2, | ||
| 53 | }; | ||
| 54 | |||
| 55 | Step | ||
| 56 | optimal_light_HTM = { | ||
| 57 | .shortname = "light", | ||
| 58 | .name = "Optimal solve (in HTM), small table (500Mb RAM total)", | ||
| 59 | |||
| 60 | .final = true, | ||
| 61 | .is_done = is_solved, | ||
| 62 | .estimate = estimate_light_HTM, | ||
| 63 | .ready = check_centers, | ||
| 64 | .ready_msg = check_centers_msg, | ||
| 65 | .is_valid = always_valid, | ||
| 66 | .moveset = &moveset_HTM, | ||
| 67 | |||
| 68 | .pre_trans = uf, | ||
| 69 | |||
| 70 | .tables = {&pd_drud_sym16_HTM, &pd_corners_HTM}, | ||
| 71 | .ntables = 2, | ||
| 72 | }; | ||
| 73 | |||
| 74 | /* Optimal after EO ******************/ | ||
| 75 | |||
| 76 | Step | ||
| 77 | eofin_eo = { | ||
| 78 | .shortname = "eofin", | ||
| 79 | .name = "Optimal solve after EO without breaking EO (detected)", | ||
| 80 | |||
| 81 | .final = true, | ||
| 82 | .is_done = is_solved, | ||
| 83 | .estimate = estimate_nxopt31_HTM, | ||
| 84 | .ready = check_eofb, | ||
| 85 | .ready_msg = check_eo_msg, | ||
| 86 | .is_valid = always_valid, | ||
| 87 | .moveset = &moveset_eofb, | ||
| 88 | |||
| 89 | .detect = detect_pretrans_eofb, | ||
| 90 | |||
| 91 | .tables = {&pd_nxopt31_HTM, &pd_corners_HTM}, | ||
| 92 | .ntables = 2, | ||
| 93 | }; | ||
| 94 | |||
| 95 | Step | ||
| 96 | eofbfin_eofb = { | ||
| 97 | .shortname = "eofbfin", | ||
| 98 | .name = "Optimal after EO on F/B without breaking EO", | ||
| 99 | |||
| 100 | .final = true, | ||
| 101 | .is_done = is_solved, | ||
| 102 | .estimate = estimate_nxopt31_HTM, | ||
| 103 | .ready = check_eofb, | ||
| 104 | .ready_msg = check_eo_msg, | ||
| 105 | .is_valid = always_valid, | ||
| 106 | .moveset = &moveset_eofb, | ||
| 107 | |||
| 108 | .pre_trans = uf, | ||
| 109 | |||
| 110 | .tables = {&pd_nxopt31_HTM, &pd_corners_HTM}, | ||
| 111 | .ntables = 2, | ||
| 112 | }; | ||
| 113 | |||
| 114 | Step | ||
| 115 | eorlfin_eorl = { | ||
| 116 | .shortname = "eorlfin", | ||
| 117 | .name = "Optimal after EO on R/L without breaking EO", | ||
| 118 | |||
| 119 | .final = true, | ||
| 120 | .is_done = is_solved, | ||
| 121 | .estimate = estimate_nxopt31_HTM, | ||
| 122 | .ready = check_eofb, | ||
| 123 | .ready_msg = check_eo_msg, | ||
| 124 | .is_valid = always_valid, | ||
| 125 | .moveset = &moveset_eofb, | ||
| 126 | |||
| 127 | .pre_trans = ur, | ||
| 128 | |||
| 129 | .tables = {&pd_nxopt31_HTM, &pd_corners_HTM}, | ||
| 130 | .ntables = 2, | ||
| 131 | }; | ||
| 132 | |||
| 133 | Step | ||
| 134 | eoudfin_eoud = { | ||
| 135 | .shortname = "eoudfin", | ||
| 136 | .name = "Optimal after EO on U/D without breaking EO", | ||
| 137 | |||
| 138 | .final = true, | ||
| 139 | .is_done = is_solved, | ||
| 140 | .estimate = estimate_nxopt31_HTM, | ||
| 141 | .ready = check_eofb, | ||
| 142 | .ready_msg = check_eo_msg, | ||
| 143 | .is_valid = always_valid, | ||
| 144 | .moveset = &moveset_eofb, | ||
| 145 | |||
| 146 | .pre_trans = fd, | ||
| 147 | |||
| 148 | .tables = {&pd_nxopt31_HTM, &pd_corners_HTM}, | ||
| 149 | .ntables = 2, | ||
| 150 | }; | ||
| 151 | |||
| 152 | /* EO steps **************************/ | ||
| 153 | Step | ||
| 154 | eoany_HTM = { | ||
| 155 | .shortname = "eo", | ||
| 156 | .name = "EO on any axis", | ||
| 157 | |||
| 158 | .final = false, | ||
| 159 | .is_done = check_eofb, | ||
| 160 | .estimate = estimate_eofb_HTM, | ||
| 161 | .ready = check_centers, | ||
| 162 | .ready_msg = check_centers_msg, | ||
| 163 | .is_valid = validate_singlecw_ending, | ||
| 164 | .moveset = &moveset_HTM, | ||
| 165 | |||
| 166 | .detect = detect_pretrans_void_3axis, | ||
| 167 | |||
| 168 | .tables = {&pd_eofb_HTM}, | ||
| 169 | .ntables = 1, | ||
| 170 | }; | ||
| 171 | |||
| 172 | Step | ||
| 173 | eofb_HTM = { | ||
| 174 | .shortname = "eofb", | ||
| 175 | .name = "EO on F/B", | ||
| 176 | |||
| 177 | .final = false, | ||
| 178 | .is_done = check_eofb, | ||
| 179 | .estimate = estimate_eofb_HTM, | ||
| 180 | .ready = check_centers, | ||
| 181 | .ready_msg = check_centers_msg, | ||
| 182 | .is_valid = validate_singlecw_ending, | ||
| 183 | .moveset = &moveset_HTM, | ||
| 184 | |||
| 185 | .pre_trans = uf, | ||
| 186 | |||
| 187 | .tables = {&pd_eofb_HTM}, | ||
| 188 | .ntables = 1, | ||
| 189 | }; | ||
| 190 | |||
| 191 | Step | ||
| 192 | eorl_HTM = { | ||
| 193 | .shortname = "eorl", | ||
| 194 | .name = "EO on R/L", | ||
| 195 | |||
| 196 | .final = false, | ||
| 197 | .is_done = check_eofb, | ||
| 198 | .estimate = estimate_eofb_HTM, | ||
| 199 | .ready = check_centers, | ||
| 200 | .ready_msg = check_centers_msg, | ||
| 201 | .is_valid = validate_singlecw_ending, | ||
| 202 | .moveset = &moveset_HTM, | ||
| 203 | |||
| 204 | .pre_trans = ur, | ||
| 205 | |||
| 206 | .tables = {&pd_eofb_HTM}, | ||
| 207 | .ntables = 1, | ||
| 208 | }; | ||
| 209 | |||
| 210 | Step | ||
| 211 | eoud_HTM = { | ||
| 212 | .shortname = "eoud", | ||
| 213 | .name = "EO on U/D", | ||
| 214 | |||
| 215 | .final = false, | ||
| 216 | .is_done = check_eofb, | ||
| 217 | .estimate = estimate_eofb_HTM, | ||
| 218 | .ready = check_centers, | ||
| 219 | .ready_msg = check_centers_msg, | ||
| 220 | .is_valid = validate_singlecw_ending, | ||
| 221 | .moveset = &moveset_HTM, | ||
| 222 | |||
| 223 | .pre_trans = fd, | ||
| 224 | |||
| 225 | .tables = {&pd_eofb_HTM}, | ||
| 226 | .ntables = 1, | ||
| 227 | }; | ||
| 228 | |||
| 229 | /* CO steps **************************/ | ||
| 230 | Step | ||
| 231 | coany_HTM = { | ||
| 232 | .shortname = "co", | ||
| 233 | .name = "CO on any axis", | ||
| 234 | |||
| 235 | .final = false, | ||
| 236 | .is_done = check_coud_HTM, | ||
| 237 | .estimate = estimate_coud_HTM, | ||
| 238 | .ready = NULL, | ||
| 239 | .is_valid = validate_singlecw_ending, | ||
| 240 | .moveset = &moveset_HTM, | ||
| 241 | |||
| 242 | .detect = detect_pretrans_void_3axis, | ||
| 243 | |||
| 244 | .tables = {&pd_coud_HTM}, | ||
| 245 | .ntables = 1, | ||
| 246 | }; | ||
| 247 | |||
| 248 | Step | ||
| 249 | coud_HTM = { | ||
| 250 | .shortname = "coud", | ||
| 251 | .name = "CO on U/D", | ||
| 252 | |||
| 253 | .final = false, | ||
| 254 | .is_done = check_coud_HTM, | ||
| 255 | .estimate = estimate_coud_HTM, | ||
| 256 | .ready = NULL, | ||
| 257 | .is_valid = validate_singlecw_ending, | ||
| 258 | .moveset = &moveset_HTM, | ||
| 259 | |||
| 260 | .pre_trans = uf, | ||
| 261 | |||
| 262 | .tables = {&pd_coud_HTM}, | ||
| 263 | .ntables = 1, | ||
| 264 | }; | ||
| 265 | |||
| 266 | Step | ||
| 267 | corl_HTM = { | ||
| 268 | .shortname = "corl", | ||
| 269 | .name = "CO on R/L", | ||
| 270 | |||
| 271 | .final = false, | ||
| 272 | .is_done = check_coud_HTM, | ||
| 273 | .estimate = estimate_coud_HTM, | ||
| 274 | .ready = NULL, | ||
| 275 | .is_valid = validate_singlecw_ending, | ||
| 276 | .moveset = &moveset_HTM, | ||
| 277 | |||
| 278 | .pre_trans = rf, | ||
| 279 | |||
| 280 | .tables = {&pd_coud_HTM}, | ||
| 281 | .ntables = 1, | ||
| 282 | }; | ||
| 283 | |||
| 284 | Step | ||
| 285 | cofb_HTM = { | ||
| 286 | .shortname = "cofb", | ||
| 287 | .name = "CO on F/B", | ||
| 288 | |||
| 289 | .final = false, | ||
| 290 | .is_done = check_coud_HTM, | ||
| 291 | .estimate = estimate_coud_HTM, | ||
| 292 | .ready = NULL, | ||
| 293 | .is_valid = validate_singlecw_ending, | ||
| 294 | .moveset = &moveset_HTM, | ||
| 295 | |||
| 296 | .pre_trans = fd, | ||
| 297 | |||
| 298 | .tables = {&pd_coud_HTM}, | ||
| 299 | .ntables = 1, | ||
| 300 | }; | ||
| 301 | |||
| 302 | Step | ||
| 303 | coany_URF = { | ||
| 304 | .shortname = "co-URF", | ||
| 305 | .name = "CO any axis (URF moveset)", | ||
| 306 | |||
| 307 | .final = false, | ||
| 308 | .is_done = check_coud_URF, | ||
| 309 | .estimate = estimate_coud_URF, | ||
| 310 | .ready = NULL, | ||
| 311 | .is_valid = validate_singlecw_ending, | ||
| 312 | .moveset = &moveset_URF, | ||
| 313 | |||
| 314 | .detect = detect_pretrans_void_3axis, | ||
| 315 | |||
| 316 | .tables = {&pd_coud_HTM}, | ||
| 317 | .ntables = 1, | ||
| 318 | }; | ||
| 319 | |||
| 320 | Step | ||
| 321 | coud_URF = { | ||
| 322 | .shortname = "coud-URF", | ||
| 323 | .name = "CO on U/D (URF moveset)", | ||
| 324 | |||
| 325 | .final = false, | ||
| 326 | .is_done = check_coud_URF, | ||
| 327 | .estimate = estimate_coud_URF, | ||
| 328 | .ready = NULL, | ||
| 329 | .is_valid = validate_singlecw_ending, | ||
| 330 | .moveset = &moveset_URF, | ||
| 331 | |||
| 332 | .pre_trans = uf, | ||
| 333 | |||
| 334 | .tables = {&pd_coud_HTM}, | ||
| 335 | .ntables = 1, | ||
| 336 | }; | ||
| 337 | |||
| 338 | Step | ||
| 339 | corl_URF = { | ||
| 340 | .shortname = "corl-URF", | ||
| 341 | .name = "CO on R/L (URF moveset)", | ||
| 342 | |||
| 343 | .final = false, | ||
| 344 | .is_done = check_coud_URF, | ||
| 345 | .estimate = estimate_coud_URF, | ||
| 346 | .ready = NULL, | ||
| 347 | .is_valid = validate_singlecw_ending, | ||
| 348 | .moveset = &moveset_URF, | ||
| 349 | |||
| 350 | .pre_trans = rf, | ||
| 351 | |||
| 352 | .tables = {&pd_coud_HTM}, | ||
| 353 | .ntables = 1, | ||
| 354 | }; | ||
| 355 | |||
| 356 | Step | ||
| 357 | cofb_URF = { | ||
| 358 | .shortname = "cofb-URF", | ||
| 359 | .name = "CO on F/B (URF moveset)", | ||
| 360 | |||
| 361 | .final = false, | ||
| 362 | .is_done = check_coud_URF, | ||
| 363 | .estimate = estimate_coud_URF, | ||
| 364 | .ready = NULL, | ||
| 365 | .is_valid = validate_singlecw_ending, | ||
| 366 | .moveset = &moveset_URF, | ||
| 367 | |||
| 368 | .pre_trans = fd, | ||
| 369 | |||
| 370 | .tables = {&pd_coud_HTM}, | ||
| 371 | .ntables = 1, | ||
| 372 | }; | ||
| 373 | |||
| 374 | /* Misc corner steps *****************/ | ||
| 375 | Step | ||
| 376 | cornershtr_HTM = { | ||
| 377 | .shortname = "chtr", | ||
| 378 | .name = "Solve corners to HTR state", | ||
| 379 | |||
| 380 | .final = false, | ||
| 381 | .is_done = check_cornershtr, | ||
| 382 | .estimate = estimate_cornershtr_HTM, | ||
| 383 | .ready = NULL, | ||
| 384 | .is_valid = validate_singlecw_ending, | ||
| 385 | .moveset = &moveset_HTM, | ||
| 386 | |||
| 387 | .pre_trans = uf, | ||
| 388 | |||
| 389 | .tables = {&pd_cornershtr_HTM}, | ||
| 390 | .ntables = 1, | ||
| 391 | }; | ||
| 392 | |||
| 393 | Step | ||
| 394 | cornershtr_URF = { | ||
| 395 | .shortname = "chtr-URF", | ||
| 396 | .name = "Solve corners to HTR state (URF moveset)", | ||
| 397 | |||
| 398 | .final = false, | ||
| 399 | .is_done = check_cornershtr, | ||
| 400 | .estimate = estimate_cornershtr_URF, | ||
| 401 | .ready = NULL, | ||
| 402 | .is_valid = validate_singlecw_ending, | ||
| 403 | .moveset = &moveset_URF, | ||
| 404 | |||
| 405 | .pre_trans = uf, | ||
| 406 | |||
| 407 | .tables = {&pd_cornershtr_HTM}, | ||
| 408 | .ntables = 1, | ||
| 409 | }; | ||
| 410 | |||
| 411 | Step | ||
| 412 | corners_HTM = { | ||
| 413 | .shortname = "corners", | ||
| 414 | .name = "Solve corners", | ||
| 415 | |||
| 416 | .final = true, | ||
| 417 | .is_done = check_corners_HTM, | ||
| 418 | .estimate = estimate_corners_HTM, | ||
| 419 | .ready = NULL, | ||
| 420 | .is_valid = always_valid, | ||
| 421 | .moveset = &moveset_HTM, | ||
| 422 | |||
| 423 | .pre_trans = uf, | ||
| 424 | |||
| 425 | .tables = {&pd_corners_HTM}, | ||
| 426 | .ntables = 1, | ||
| 427 | }; | ||
| 428 | |||
| 429 | Step | ||
| 430 | corners_URF = { | ||
| 431 | .shortname = "corners-URF", | ||
| 432 | .name = "Solve corners (URF moveset)", | ||
| 433 | |||
| 434 | .final = true, /* TODO: check if this works with reorient */ | ||
| 435 | .is_done = check_corners_URF, | ||
| 436 | .estimate = estimate_corners_URF, | ||
| 437 | .ready = NULL, | ||
| 438 | .is_valid = always_valid, | ||
| 439 | .moveset = &moveset_URF, | ||
| 440 | |||
| 441 | .pre_trans = uf, | ||
| 442 | |||
| 443 | .tables = {&pd_corners_HTM}, | ||
| 444 | .ntables = 1, | ||
| 445 | }; | ||
| 446 | |||
| 447 | /* DR steps **************************/ | ||
| 448 | Step | ||
| 449 | drany_HTM = { | ||
| 450 | .shortname = "dr", | ||
| 451 | .name = "DR on any axis", | ||
| 452 | |||
| 453 | .final = false, | ||
| 454 | .is_done = check_drud, | ||
| 455 | .estimate = estimate_drud_HTM, | ||
| 456 | .ready = check_centers, | ||
| 457 | .ready_msg = check_centers_msg, | ||
| 458 | .is_valid = validate_singlecw_ending, | ||
| 459 | .moveset = &moveset_HTM, | ||
| 460 | |||
| 461 | .detect = detect_pretrans_void_3axis, | ||
| 462 | |||
| 463 | .tables = {&pd_drud_sym16_HTM}, | ||
| 464 | .ntables = 1, | ||
| 465 | }; | ||
| 466 | |||
| 467 | Step | ||
| 468 | drud_HTM = { | ||
| 469 | .shortname = "drud", | ||
| 470 | .name = "DR on U/D", | ||
| 471 | |||
| 472 | .final = false, | ||
| 473 | .is_done = check_drud, | ||
| 474 | .estimate = estimate_drud_HTM, | ||
| 475 | .ready = check_centers, | ||
| 476 | .ready_msg = check_centers_msg, | ||
| 477 | .is_valid = validate_singlecw_ending, | ||
| 478 | .moveset = &moveset_HTM, | ||
| 479 | |||
| 480 | .pre_trans = uf, | ||
| 481 | |||
| 482 | .tables = {&pd_drud_sym16_HTM}, | ||
| 483 | .ntables = 1, | ||
| 484 | }; | ||
| 485 | |||
| 486 | Step | ||
| 487 | drrl_HTM = { | ||
| 488 | .shortname = "drrl", | ||
| 489 | .name = "DR on R/L", | ||
| 490 | |||
| 491 | .final = false, | ||
| 492 | .is_done = check_drud, | ||
| 493 | .estimate = estimate_drud_HTM, | ||
| 494 | .ready = check_centers, | ||
| 495 | .ready_msg = check_centers_msg, | ||
| 496 | .is_valid = validate_singlecw_ending, | ||
| 497 | .moveset = &moveset_HTM, | ||
| 498 | |||
| 499 | .pre_trans = rf, | ||
| 500 | |||
| 501 | .tables = {&pd_drud_sym16_HTM}, | ||
| 502 | .ntables = 1, | ||
| 503 | }; | ||
| 504 | |||
| 505 | Step | ||
| 506 | drfb_HTM = { | ||
| 507 | .shortname = "drfb", | ||
| 508 | .name = "DR on F/B", | ||
| 509 | |||
| 510 | .final = false, | ||
| 511 | .is_done = check_drud, | ||
| 512 | .estimate = estimate_drud_HTM, | ||
| 513 | .ready = check_centers, | ||
| 514 | .ready_msg = check_centers_msg, | ||
| 515 | .is_valid = validate_singlecw_ending, | ||
| 516 | .moveset = &moveset_HTM, | ||
| 517 | |||
| 518 | .pre_trans = fd, | ||
| 519 | |||
| 520 | .tables = {&pd_drud_sym16_HTM}, | ||
| 521 | .ntables = 1, | ||
| 522 | }; | ||
| 523 | |||
| 524 | /* DR from EO */ | ||
| 525 | Step | ||
| 526 | dr_eo = { | ||
| 527 | .shortname = "dr-eo", | ||
| 528 | .name = "DR without breaking EO (automatically detected)", | ||
| 529 | |||
| 530 | .final = false, | ||
| 531 | .is_done = check_drud, | ||
| 532 | .estimate = estimate_dr_eofb, | ||
| 533 | .ready = check_eofb, | ||
| 534 | .ready_msg = check_eo_msg, | ||
| 535 | .is_valid = validate_singlecw_ending, | ||
| 536 | .moveset = &moveset_eofb, | ||
| 537 | |||
| 538 | .detect = detect_pretrans_eofb, | ||
| 539 | |||
| 540 | .tables = {&pd_drud_eofb}, | ||
| 541 | .ntables = 1, | ||
| 542 | }; | ||
| 543 | |||
| 544 | Step | ||
| 545 | dr_eofb = { | ||
| 546 | .shortname = "dr-eofb", | ||
| 547 | .name = "DR on U/D or R/L without breaking EO on F/B", | ||
| 548 | |||
| 549 | .final = false, | ||
| 550 | .is_done = check_drud, | ||
| 551 | .estimate = estimate_dr_eofb, | ||
| 552 | .ready = check_eofb, | ||
| 553 | .ready_msg = check_eo_msg, | ||
| 554 | .is_valid = validate_singlecw_ending, | ||
| 555 | .moveset = &moveset_eofb, | ||
| 556 | |||
| 557 | .pre_trans = uf, | ||
| 558 | |||
| 559 | .tables = {&pd_drud_eofb}, | ||
| 560 | .ntables = 1, | ||
| 561 | }; | ||
| 562 | |||
| 563 | Step | ||
| 564 | dr_eorl = { | ||
| 565 | .shortname = "dr-eorl", | ||
| 566 | .name = "DR on U/D or F/B without breaking EO on R/L", | ||
| 567 | |||
| 568 | .final = false, | ||
| 569 | .is_done = check_drud, | ||
| 570 | .estimate = estimate_dr_eofb, | ||
| 571 | .ready = check_eofb, | ||
| 572 | .ready_msg = check_eo_msg, | ||
| 573 | .is_valid = validate_singlecw_ending, | ||
| 574 | .moveset = &moveset_eofb, | ||
| 575 | |||
| 576 | .pre_trans = ur, | ||
| 577 | |||
| 578 | .tables = {&pd_drud_eofb}, | ||
| 579 | .ntables = 1, | ||
| 580 | }; | ||
| 581 | |||
| 582 | Step | ||
| 583 | dr_eoud = { | ||
| 584 | .shortname = "dr-eoud", | ||
| 585 | .name = "DR on R/L or F/B without breaking EO on U/D", | ||
| 586 | |||
| 587 | .final = false, | ||
| 588 | .is_done = check_drud, | ||
| 589 | .estimate = estimate_dr_eofb, | ||
| 590 | .ready = check_eofb, | ||
| 591 | .ready_msg = check_eo_msg, | ||
| 592 | .is_valid = validate_singlecw_ending, | ||
| 593 | .moveset = &moveset_eofb, | ||
| 594 | |||
| 595 | .pre_trans = fd, | ||
| 596 | |||
| 597 | .tables = {&pd_drud_eofb}, | ||
| 598 | .ntables = 1, | ||
| 599 | }; | ||
| 600 | |||
| 601 | Step | ||
| 602 | drud_eofb = { | ||
| 603 | .shortname = "drud-eofb", | ||
| 604 | .name = "DR on U/D without breaking EO on F/B", | ||
| 605 | |||
| 606 | .final = false, | ||
| 607 | .is_done = check_drud, | ||
| 608 | .estimate = estimate_drud_eofb, | ||
| 609 | .ready = check_eofb, | ||
| 610 | .ready_msg = check_eo_msg, | ||
| 611 | .is_valid = validate_singlecw_ending, | ||
| 612 | .moveset = &moveset_eofb, | ||
| 613 | |||
| 614 | .pre_trans = uf, | ||
| 615 | |||
| 616 | .tables = {&pd_drud_eofb}, | ||
| 617 | .ntables = 1, | ||
| 618 | }; | ||
| 619 | |||
| 620 | Step | ||
| 621 | drrl_eofb = { | ||
| 622 | .shortname = "drrl-eofb", | ||
| 623 | .name = "DR on R/L without breaking EO on F/B", | ||
| 624 | |||
| 625 | .final = false, | ||
| 626 | .is_done = check_drud, | ||
| 627 | .estimate = estimate_drud_eofb, | ||
| 628 | .ready = check_eofb, | ||
| 629 | .ready_msg = check_eo_msg, | ||
| 630 | .is_valid = validate_singlecw_ending, | ||
| 631 | .moveset = &moveset_eofb, | ||
| 632 | |||
| 633 | .pre_trans = rf, | ||
| 634 | |||
| 635 | .tables = {&pd_drud_eofb}, | ||
| 636 | .ntables = 1, | ||
| 637 | }; | ||
| 638 | |||
| 639 | Step | ||
| 640 | drud_eorl = { | ||
| 641 | .shortname = "drud-eorl", | ||
| 642 | .name = "DR on U/D without breaking EO on R/L", | ||
| 643 | |||
| 644 | .final = false, | ||
| 645 | .is_done = check_drud, | ||
| 646 | .estimate = estimate_drud_eofb, | ||
| 647 | .ready = check_eofb, | ||
| 648 | .ready_msg = check_eo_msg, | ||
| 649 | .is_valid = validate_singlecw_ending, | ||
| 650 | .moveset = &moveset_eofb, | ||
| 651 | |||
| 652 | .pre_trans = ur, | ||
| 653 | |||
| 654 | .tables = {&pd_drud_eofb}, | ||
| 655 | .ntables = 1, | ||
| 656 | }; | ||
| 657 | |||
| 658 | Step | ||
| 659 | drfb_eorl = { | ||
| 660 | .shortname = "drfb-eorl", | ||
| 661 | .name = "DR on F/B without breaking EO on R/L", | ||
| 662 | |||
| 663 | .final = false, | ||
| 664 | .is_done = check_drud, | ||
| 665 | .estimate = estimate_drud_eofb, | ||
| 666 | .ready = check_eofb, | ||
| 667 | .ready_msg = check_eo_msg, | ||
| 668 | .is_valid = validate_singlecw_ending, | ||
| 669 | .moveset = &moveset_eofb, | ||
| 670 | |||
| 671 | .pre_trans = fr, | ||
| 672 | |||
| 673 | .tables = {&pd_drud_eofb}, | ||
| 674 | .ntables = 1, | ||
| 675 | }; | ||
| 676 | |||
| 677 | Step | ||
| 678 | drfb_eoud = { | ||
| 679 | .shortname = "drfb-eoud", | ||
| 680 | .name = "DR on F/B without breaking EO on U/D", | ||
| 681 | |||
| 682 | .final = false, | ||
| 683 | .is_done = check_drud, | ||
| 684 | .estimate = estimate_drud_eofb, | ||
| 685 | .ready = check_eofb, | ||
| 686 | .ready_msg = check_eo_msg, | ||
| 687 | .is_valid = validate_singlecw_ending, | ||
| 688 | .moveset = &moveset_eofb, | ||
| 689 | |||
| 690 | .pre_trans = fd, | ||
| 691 | |||
| 692 | .tables = {&pd_drud_eofb}, | ||
| 693 | .ntables = 1, | ||
| 694 | }; | ||
| 695 | |||
| 696 | Step | ||
| 697 | drrl_eoud = { | ||
| 698 | .shortname = "drrl-eoud", | ||
| 699 | .name = "DR on R/L without breaking EO on U/D", | ||
| 700 | |||
| 701 | .final = false, | ||
| 702 | .is_done = check_drud, | ||
| 703 | .estimate = estimate_drud_eofb, | ||
| 704 | .ready = check_eofb, | ||
| 705 | .ready_msg = check_eo_msg, | ||
| 706 | .is_valid = validate_singlecw_ending, | ||
| 707 | .moveset = &moveset_eofb, | ||
| 708 | |||
| 709 | .pre_trans = rd, | ||
| 710 | |||
| 711 | .tables = {&pd_drud_eofb}, | ||
| 712 | .ntables = 1, | ||
| 713 | }; | ||
| 714 | |||
| 715 | /* DR finish steps */ | ||
| 716 | Step | ||
| 717 | dranyfin_DR = { | ||
| 718 | .shortname = "drfin", | ||
| 719 | .name = "DR finish on any axis without breaking DR", | ||
| 720 | |||
| 721 | .final = true, | ||
| 722 | .is_done = is_solved, | ||
| 723 | .estimate = estimate_drudfin_drud, | ||
| 724 | .ready = check_drud, | ||
| 725 | .ready_msg = check_drany_msg, | ||
| 726 | .is_valid = always_valid, | ||
| 727 | .moveset = &moveset_drud, | ||
| 728 | |||
| 729 | .detect = detect_pretrans_drud, | ||
| 730 | |||
| 731 | .tables = {&pd_drudfin_noE_sym16_drud}, | ||
| 732 | .ntables = 1, | ||
| 733 | }; | ||
| 734 | |||
| 735 | Step | ||
| 736 | drudfin_drud = { | ||
| 737 | .shortname = "drudfin", | ||
| 738 | .name = "DR finish on U/D without breaking DR", | ||
| 739 | |||
| 740 | .final = true, | ||
| 741 | .is_done = is_solved, | ||
| 742 | .estimate = estimate_drudfin_drud, | ||
| 743 | .ready = check_drud, | ||
| 744 | .ready_msg = check_dr_msg, | ||
| 745 | .is_valid = always_valid, | ||
| 746 | .moveset = &moveset_drud, | ||
| 747 | |||
| 748 | .pre_trans = uf, | ||
| 749 | |||
| 750 | .tables = {&pd_drudfin_noE_sym16_drud}, | ||
| 751 | .ntables = 1, | ||
| 752 | }; | ||
| 753 | |||
| 754 | Step | ||
| 755 | drrlfin_drrl = { | ||
| 756 | .shortname = "drrlfin", | ||
| 757 | .name = "DR finish on R/L without breaking DR", | ||
| 758 | |||
| 759 | .final = true, | ||
| 760 | .is_done = is_solved, | ||
| 761 | .estimate = estimate_drudfin_drud, | ||
| 762 | .ready = check_drud, | ||
| 763 | .ready_msg = check_dr_msg, | ||
| 764 | .is_valid = always_valid, | ||
| 765 | .moveset = &moveset_drud, | ||
| 766 | |||
| 767 | .pre_trans = rf, | ||
| 768 | |||
| 769 | .tables = {&pd_drudfin_noE_sym16_drud}, | ||
| 770 | .ntables = 1, | ||
| 771 | }; | ||
| 772 | |||
| 773 | Step | ||
| 774 | drfbfin_drfb = { | ||
| 775 | .shortname = "drfbfin", | ||
| 776 | .name = "DR finish on F/B without breaking DR", | ||
| 777 | |||
| 778 | .final = true, | ||
| 779 | .is_done = is_solved, | ||
| 780 | .estimate = estimate_drudfin_drud, | ||
| 781 | .ready = check_drud, | ||
| 782 | .ready_msg = check_dr_msg, | ||
| 783 | .is_valid = always_valid, | ||
| 784 | .moveset = &moveset_drud, | ||
| 785 | |||
| 786 | .pre_trans = fd, | ||
| 787 | |||
| 788 | .tables = {&pd_drudfin_noE_sym16_drud}, | ||
| 789 | .ntables = 1, | ||
| 790 | }; | ||
| 791 | |||
| 792 | /* HTR from DR */ | ||
| 793 | Step | ||
| 794 | htr_any = { | ||
| 795 | .shortname = "htr", | ||
| 796 | .name = "HTR from DR", | ||
| 797 | |||
| 798 | .final = false, | ||
| 799 | .is_done = check_htr, | ||
| 800 | .estimate = estimate_htr_drud, | ||
| 801 | .ready = check_drud, | ||
| 802 | .ready_msg = check_drany_msg, | ||
| 803 | .is_valid = validate_singlecw_ending, | ||
| 804 | .moveset = &moveset_drud, | ||
| 805 | |||
| 806 | .detect = detect_pretrans_drud, | ||
| 807 | |||
| 808 | .tables = {&pd_htr_drud}, | ||
| 809 | .ntables = 1, | ||
| 810 | }; | ||
| 811 | |||
| 812 | Step | ||
| 813 | htr_drud = { | ||
| 814 | .shortname = "htr-drud", | ||
| 815 | .name = "HTR from DR on U/D", | ||
| 816 | |||
| 817 | .final = false, | ||
| 818 | .is_done = check_htr, | ||
| 819 | .estimate = estimate_htr_drud, | ||
| 820 | .ready = check_drud, | ||
| 821 | .ready_msg = check_dr_msg, | ||
| 822 | .is_valid = validate_singlecw_ending, | ||
| 823 | .moveset = &moveset_drud, | ||
| 824 | |||
| 825 | .pre_trans = uf, | ||
| 826 | |||
| 827 | .tables = {&pd_htr_drud}, | ||
| 828 | .ntables = 1, | ||
| 829 | }; | ||
| 830 | |||
| 831 | Step | ||
| 832 | htr_drrl = { | ||
| 833 | .shortname = "htr-drrl", | ||
| 834 | .name = "HTR from DR on R/L", | ||
| 835 | |||
| 836 | .final = false, | ||
| 837 | .is_done = check_htr, | ||
| 838 | .estimate = estimate_htr_drud, | ||
| 839 | .ready = check_drud, | ||
| 840 | .ready_msg = check_dr_msg, | ||
| 841 | .is_valid = validate_singlecw_ending, | ||
| 842 | .moveset = &moveset_drud, | ||
| 843 | |||
| 844 | .pre_trans = rf, | ||
| 845 | |||
| 846 | .tables = {&pd_htr_drud}, | ||
| 847 | .ntables = 1, | ||
| 848 | }; | ||
| 849 | |||
| 850 | Step | ||
| 851 | htr_drfb = { | ||
| 852 | .shortname = "htr-drfb", | ||
| 853 | .name = "HTR from DR on F/B", | ||
| 854 | |||
| 855 | .final = false, | ||
| 856 | .is_done = check_htr, | ||
| 857 | .estimate = estimate_htr_drud, | ||
| 858 | .ready = check_drud, | ||
| 859 | .ready_msg = check_dr_msg, | ||
| 860 | .is_valid = validate_singlecw_ending, | ||
| 861 | .moveset = &moveset_drud, | ||
| 862 | |||
| 863 | .pre_trans = fd, | ||
| 864 | |||
| 865 | .tables = {&pd_htr_drud}, | ||
| 866 | .ntables = 1, | ||
| 867 | }; | ||
| 868 | |||
| 869 | /* HTR finish */ | ||
| 870 | Step | ||
| 871 | htrfin_htr = { | ||
| 872 | .shortname = "htrfin", | ||
| 873 | .name = "HTR finish without breaking HTR", | ||
| 874 | |||
| 875 | .final = true, | ||
| 876 | .is_done = is_solved, | ||
| 877 | .estimate = estimate_htrfin_htr, | ||
| 878 | .ready = check_htr, | ||
| 879 | .ready_msg = check_htr_msg, | ||
| 880 | .is_valid = always_valid, | ||
| 881 | .moveset = &moveset_htr, | ||
| 882 | |||
| 883 | .pre_trans = uf, | ||
| 884 | |||
| 885 | .tables = {&pd_htrfin_htr}, | ||
| 886 | .ntables = 1, | ||
| 887 | }; | ||
| 888 | |||
| 889 | Step *steps[] = { | ||
| 890 | &optimal_HTM, /* first is default */ | ||
| 891 | &optimal_light_HTM, | ||
| 892 | |||
| 893 | &eofin_eo, | ||
| 894 | &eofbfin_eofb, | ||
| 895 | &eorlfin_eorl, | ||
| 896 | &eoudfin_eoud, | ||
| 897 | |||
| 898 | &eoany_HTM, | ||
| 899 | &eofb_HTM, | ||
| 900 | &eorl_HTM, | ||
| 901 | &eoud_HTM, | ||
| 902 | |||
| 903 | &coany_HTM, | ||
| 904 | &coud_HTM, | ||
| 905 | &corl_HTM, | ||
| 906 | &cofb_HTM, | ||
| 907 | |||
| 908 | &coany_URF, | ||
| 909 | &coud_URF, | ||
| 910 | &corl_URF, | ||
| 911 | &cofb_URF, | ||
| 912 | |||
| 913 | &drany_HTM, | ||
| 914 | &drud_HTM, | ||
| 915 | &drrl_HTM, | ||
| 916 | &drfb_HTM, | ||
| 917 | |||
| 918 | &dr_eo, | ||
| 919 | &dr_eofb, | ||
| 920 | &dr_eorl, | ||
| 921 | &dr_eoud, | ||
| 922 | &drud_eofb, | ||
| 923 | &drrl_eofb, | ||
| 924 | &drud_eorl, | ||
| 925 | &drfb_eorl, | ||
| 926 | &drfb_eoud, | ||
| 927 | &drrl_eoud, | ||
| 928 | |||
| 929 | &dranyfin_DR, | ||
| 930 | &drudfin_drud, | ||
| 931 | &drrlfin_drrl, | ||
| 932 | &drfbfin_drfb, | ||
| 933 | |||
| 934 | &htr_any, | ||
| 935 | &htr_drud, | ||
| 936 | &htr_drrl, | ||
| 937 | &htr_drfb, | ||
| 938 | |||
| 939 | &htrfin_htr, | ||
| 940 | |||
| 941 | &cornershtr_HTM, | ||
| 942 | &cornershtr_URF, | ||
| 943 | &corners_HTM, | ||
| 944 | &corners_URF, | ||
| 945 | |||
| 946 | NULL | ||
| 947 | }; | ||
| 948 | |||
| 949 | /* Checkers and validators ***************************************************/ | ||
| 950 | |||
| 951 | static bool | ||
| 952 | check_centers(Cube cube) | ||
| 953 | { | ||
| 954 | return cube.cpos == 0; | ||
| 955 | } | ||
| 956 | |||
| 957 | static bool | ||
| 958 | check_coud_HTM(Cube cube) | ||
| 959 | { | ||
| 960 | return cube.coud == 0; | ||
| 961 | } | ||
| 962 | |||
| 963 | static bool | ||
| 964 | check_coud_URF(Cube cube) | ||
| 965 | { | ||
| 966 | Cube c2, c3; | ||
| 967 | |||
| 968 | c2 = apply_move(z, cube); | ||
| 969 | c3 = apply_move(x, cube); | ||
| 970 | |||
| 971 | return cube.coud == 0 || c2.coud == 0 || c3.coud == 0; | ||
| 972 | } | ||
| 973 | |||
| 974 | static bool | ||
| 975 | check_corners_URF(Cube cube) | ||
| 976 | { | ||
| 977 | Cube c; | ||
| 978 | Trans i; | ||
| 979 | |||
| 980 | for (i = 0; i < NROTATIONS; i++) { | ||
| 981 | c = apply_alg(rotation_alg(i), cube); | ||
| 982 | if (c.cp && c.coud) | ||
| 983 | return true; | ||
| 984 | } | ||
| 985 | |||
| 986 | return false; | ||
| 987 | } | ||
| 988 | |||
| 989 | static bool | ||
| 990 | check_corners_HTM(Cube cube) | ||
| 991 | { | ||
| 992 | return cube.cp == 0 && cube.coud == 0; | ||
| 993 | } | ||
| 994 | |||
| 995 | static bool | ||
| 996 | check_cornershtr(Cube cube) | ||
| 997 | { | ||
| 998 | return coord_cornershtr.index(cube) == 0; | ||
| 999 | } | ||
| 1000 | |||
| 1001 | static bool | ||
| 1002 | check_eofb(Cube cube) | ||
| 1003 | { | ||
| 1004 | return cube.eofb == 0; | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | static bool | ||
| 1008 | check_drud(Cube cube) | ||
| 1009 | { | ||
| 1010 | return cube.eofb == 0 && cube.eorl == 0 && cube.coud == 0; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | static bool | ||
| 1014 | check_htr(Cube cube) | ||
| 1015 | { | ||
| 1016 | return check_drud(cube) && coord_htr_drud.index(cube) == 0; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | static bool | ||
| 1020 | always_valid(Alg *alg) | ||
| 1021 | { | ||
| 1022 | return true; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | static bool | ||
| 1026 | validate_singlecw_ending(Alg *alg) | ||
| 1027 | { | ||
| 1028 | int i; | ||
| 1029 | bool nor, inv; | ||
| 1030 | Move l2 = NULLMOVE, l1 = NULLMOVE, l2i = NULLMOVE, l1i = NULLMOVE; | ||
| 1031 | |||
| 1032 | for (i = 0; i < alg->len; i++) { | ||
| 1033 | if (alg->inv[i]) { | ||
| 1034 | l2i = l1i; | ||
| 1035 | l1i = alg->move[i]; | ||
| 1036 | } else { | ||
| 1037 | l2 = l1; | ||
| 1038 | l1 = alg->move[i]; | ||
| 1039 | } | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | nor = l1 ==base_move(l1) && (!commute(l1, l2) ||l2 ==base_move(l2)); | ||
| 1043 | inv = l1i==base_move(l1i) && (!commute(l1i,l2i)||l2i==base_move(l2i)); | ||
| 1044 | |||
| 1045 | return nor && inv; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | /* Public functions **********************************************************/ | ||
| 1049 | |||
| 1050 | void | ||
| 1051 | compute_ind(StepAlt *a, Cube *cube, uint64_t *ind) | ||
| 1052 | { | ||
| 1053 | |||
| 1054 | } | ||
| 1055 | |||
| 1056 | int | ||
| 1057 | estimate_stepalt(StepAlt *a, uint64_t *ind) | ||
| 1058 | { | ||
| 1059 | int i, ret, est[a->n_coord]; | ||
| 1060 | |||
| 1061 | for (i = 0; i < a->n_coord; i++) { | ||
| 1062 | est[i] = ptableval(a->pd[i], ind[i]); | ||
| 1063 | if (est[i] == 0 && a->compact_pd[i]) | ||
| 1064 | est[i] = ptableval(a->fallback_pd, ind[i] / a->fbmod); | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | for (i = 0; i < a->n_dbtrick; i++) | ||
| 1068 | if (est[a->dbtrick[i][0]] == est[a->dbtrick[i][1]] && | ||
| 1069 | est[a->dbtrick[i][0]] == est[a->dbtrick[i][2]]) | ||
| 1070 | est[a->dbtrick[i][0]] += 1; | ||
| 1071 | |||
| 1072 | for (i = 0, ret = -1; i < a->n_coord; i++) | ||
| 1073 | ret = max(ret, est[i]); | ||
| 1074 | |||
| 1075 | return ret; | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | void | ||
| 1079 | prepare_step(Step *step, SolveOptions *opts) | ||
| 1080 | { | ||
| 1081 | int i, j; | ||
| 1082 | PDGenData pdg; | ||
| 1083 | StepAlt *a; | ||
| 1084 | |||
| 1085 | init_moveset(step->moveset); | ||
| 1086 | pdg.moveset = step->moveset; | ||
| 1087 | |||
| 1088 | for (i = 0; step->alt[i] != NULL; i++) { | ||
| 1089 | a = step->alt[i]; | ||
| 1090 | for (j = 0; j < a->n_coord; j++) { | ||
| 1091 | gen_coord(a->coord[j]); | ||
| 1092 | |||
| 1093 | pdg.coord = a->coord[j]; | ||
| 1094 | pdg.compact = a->compact[j]; | ||
| 1095 | pdg.pd = NULL; | ||
| 1096 | |||
| 1097 | a->pd[j] = genptable(&pdg, opts->nthreads); | ||
| 1098 | |||
| 1099 | if (a->compact_pd[j]) { | ||
| 1100 | gen_coord(a->fallback_coord[j]); | ||
| 1101 | |||
| 1102 | pdg.coord = a->fallback_coord[j]; | ||
| 1103 | pdg.compact = false; | ||
| 1104 | pdg.pd = NULL; | ||
| 1105 | |||
| 1106 | a->fallback_pd[j] = | ||
| 1107 | step->genptable(&pdg, opts->nthreads); | ||
| 1108 | } | ||
| 1109 | } | ||
| 1110 | } | ||
| 1111 | } | ||
diff --git a/old/solve_old.c b/old/solve_old.c deleted file mode 100644 index 8662c9e..0000000 --- a/old/solve_old.c +++ /dev/null | |||
| @@ -1,447 +0,0 @@ | |||
| 1 | #define SOLVE_C | ||
| 2 | |||
| 3 | #include "solve.h" | ||
| 4 | |||
| 5 | /* Local functions ***********************************************************/ | ||
| 6 | |||
| 7 | static void copy_dfsarg(DfsArg *src, DfsArg *dst); | ||
| 8 | static void dfs(DfsArg *arg); | ||
| 9 | static void dfs_add_sol(DfsArg *arg); | ||
| 10 | static void dfs_niss(DfsArg *arg); | ||
| 11 | static bool dfs_move_checkstop(DfsArg *arg); | ||
| 12 | static void * instance_thread(void *arg); | ||
| 13 | static void multidfs(DfsArg *arg); | ||
| 14 | static bool niss_makes_sense(DfsArg *arg); | ||
| 15 | static bool solvestop(int d, int op, SolveOptions *opts, AlgList *sols); | ||
| 16 | |||
| 17 | /* Local functions ***********************************************************/ | ||
| 18 | |||
| 19 | static void | ||
| 20 | copy_dfsarg(DfsArg *src, DfsArg *dst) | ||
| 21 | { | ||
| 22 | int i; | ||
| 23 | |||
| 24 | dst->cube = src->cube; | ||
| 25 | dst->t = src->t; | ||
| 26 | dst->s = src->s; | ||
| 27 | dst->opts = src->opts; | ||
| 28 | dst->d = src->d; | ||
| 29 | dst->bound = src->bound; /* In theory not needed */ | ||
| 30 | dst->niss = src->niss; | ||
| 31 | dst->sols = src->sols; | ||
| 32 | dst->sols_mutex = src->sols_mutex; | ||
| 33 | dst->current_alg = src->current_alg; | ||
| 34 | |||
| 35 | for (i = 0; i < src->s->n_coord; i++) { | ||
| 36 | dst->ind[i].val = src->ind[i].val; | ||
| 37 | dst->ind[i].t = src->ind[i].t; | ||
| 38 | } | ||
| 39 | |||
| 40 | src->s->copy_extra(src, dst); | ||
| 41 | } | ||
| 42 | |||
| 43 | static void | ||
| 44 | dfs(DfsArg *arg) | ||
| 45 | { | ||
| 46 | int i; | ||
| 47 | Move m, l0, l1; | ||
| 48 | DfsArg newarg; | ||
| 49 | |||
| 50 | if (dfs_move_checkstop(arg)) | ||
| 51 | return; | ||
| 52 | |||
| 53 | if (arg->bound == 0) { | ||
| 54 | if (arg->current_alg->len == arg->d) | ||
| 55 | dfs_add_sol(arg); | ||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | for (i = 0; arg->s->moveset->sorted_moves[i] != NULLMOVE; i++) { | ||
| 60 | m = arg->s->moveset->sorted_moves[i]; | ||
| 61 | if (arg->s->moveset->can_append(arg->current_alg, m, arg->niss) | ||
| 62 | && compare_last(arg->current_alg, m, arg->niss) >= 0) { | ||
| 63 | copy_dfsarg(arg, &newarg); | ||
| 64 | append_move(arg->current_alg, m, newarg.niss); | ||
| 65 | dfs(&newarg); | ||
| 66 | remove_last_move(arg->current_alg); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | if (niss_makes_sense(arg)) | ||
| 71 | dfs_niss(arg); | ||
| 72 | } | ||
| 73 | |||
| 74 | static void | ||
| 75 | dfs_add_sol(DfsArg *arg) | ||
| 76 | { | ||
| 77 | bool valid, accepted, nisscanc; | ||
| 78 | |||
| 79 | valid = arg->s->is_valid==NULL || arg->s->is_valid(arg->current_alg); | ||
| 80 | accepted = valid || arg->opts->all; | ||
| 81 | nisscanc = arg->s->final && | ||
| 82 | arg->s->moveset->cancel_niss(arg->current_alg); | ||
| 83 | |||
| 84 | if (accepted && !nisscanc) { | ||
| 85 | pthread_mutex_lock(arg->sols_mutex); | ||
| 86 | |||
| 87 | if (arg->sols->len < arg->opts->max_solutions) { | ||
| 88 | append_alg(arg->sols, arg->current_alg); | ||
| 89 | transform_alg( | ||
| 90 | inverse_trans(arg->t), arg->sols->last->alg); | ||
| 91 | if (arg->opts->verbose) | ||
| 92 | print_alg(arg->sols->last->alg, false); | ||
| 93 | } | ||
| 94 | |||
| 95 | pthread_mutex_unlock(arg->sols_mutex); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | static void | ||
| 100 | dfs_niss(DfsArg *arg) | ||
| 101 | { | ||
| 102 | DfsArg newarg; | ||
| 103 | Alg *inv; | ||
| 104 | Cube *c; | ||
| 105 | |||
| 106 | copy_dfsarg(arg, &newarg); | ||
| 107 | |||
| 108 | /* Invert current alg and scramble */ | ||
| 109 | newarg.cube = malloc(sizeof(Cube)); | ||
| 110 | inv = inverse_alg(arg->current_alg); | ||
| 111 | c = malloc(sizeof(Cube)); | ||
| 112 | make_solved(newarg.cube); | ||
| 113 | apply_alg(inv, newarg.cube); | ||
| 114 | copy_cube(arg->cube, c); | ||
| 115 | invert_cube(c); | ||
| 116 | compose(c, newarg.cube); | ||
| 117 | |||
| 118 | /* New indexes */ | ||
| 119 | compute_ind(newarg.s, newarg.cube, newarg.ind); | ||
| 120 | |||
| 121 | newarg.niss = !(arg->niss); | ||
| 122 | |||
| 123 | dfs(&newarg); | ||
| 124 | |||
| 125 | free_alg(inv); | ||
| 126 | free(c); | ||
| 127 | free(newarg.cube); | ||
| 128 | } | ||
| 129 | |||
| 130 | static bool | ||
| 131 | dfs_move_checkstop(DfsArg *arg) | ||
| 132 | { | ||
| 133 | int i, goal, nsols; | ||
| 134 | Move mm; | ||
| 135 | Trans tt = uf; /* Avoid uninitialized warning */ | ||
| 136 | |||
| 137 | /* Moving and computing bound */ | ||
| 138 | arg->bound = 0; | ||
| 139 | goal = arg->d - arg->current_alg->len; | ||
| 140 | for (i = 0; i < arg->s->n_coord; i++) { | ||
| 141 | if (arg->last[0] != NULLMOVE) { | ||
| 142 | mm = transform_move(arg->ind[i].t, arg->last[0]); | ||
| 143 | arg->ind[i].val = move_coord(arg->s->coord[i], | ||
| 144 | mm, arg->ind[i].val, &tt); | ||
| 145 | arg->ind[i].t = transform_trans(tt, arg->ind[i].t); | ||
| 146 | } | ||
| 147 | |||
| 148 | arg->bound = | ||
| 149 | MAX(arg->bound, ptableval(arg->s->pd[i], arg->ind[i].val)); | ||
| 150 | if (arg->opts->can_niss && !arg->niss) | ||
| 151 | arg->bound = MIN(1, arg->bound); | ||
| 152 | |||
| 153 | if (arg->bound > goal) | ||
| 154 | return true; | ||
| 155 | } | ||
| 156 | |||
| 157 | pthread_mutex_lock(arg->sols_mutex); | ||
| 158 | nsols = arg->sols->len; | ||
| 159 | pthread_mutex_unlock(arg->sols_mutex); | ||
| 160 | |||
| 161 | return nsols >= arg->opts->max_solutions; | ||
| 162 | } | ||
| 163 | |||
| 164 | static void * | ||
| 165 | instance_thread(void *arg) | ||
| 166 | { | ||
| 167 | bool b, inv; | ||
| 168 | Cube c; | ||
| 169 | Move m; | ||
| 170 | ThreadDataSolve *td; | ||
| 171 | AlgListNode *node; | ||
| 172 | DfsArg darg; | ||
| 173 | |||
| 174 | td = (ThreadDataSolve *)arg; | ||
| 175 | |||
| 176 | while (1) { | ||
| 177 | b = false; | ||
| 178 | |||
| 179 | pthread_mutex_lock(td->start_mutex); | ||
| 180 | if ((node = *(td->node)) == NULL) | ||
| 181 | b = true; | ||
| 182 | else | ||
| 183 | *(td->node) = (*(td->node))->next; | ||
| 184 | pthread_mutex_unlock(td->start_mutex); | ||
| 185 | |||
| 186 | if (b) | ||
| 187 | break; | ||
| 188 | |||
| 189 | inv = node->alg->inv[0]; | ||
| 190 | m = node->alg->move[0]; | ||
| 191 | |||
| 192 | copy_cube(td->arg.cube, &c); | ||
| 193 | if (inv) | ||
| 194 | invert_cube(&c); | ||
| 195 | |||
| 196 | copy_dfsarg(&td->arg, &darg); | ||
| 197 | compute_ind(td->arg.s, &c, darg.ind); | ||
| 198 | darg.cube = &c; | ||
| 199 | |||
| 200 | darg.niss = inv; | ||
| 201 | darg.current_alg = new_alg(""); | ||
| 202 | append_move(darg.current_alg, m, inv); | ||
| 203 | |||
| 204 | dfs(&darg); | ||
| 205 | |||
| 206 | free_alg(darg.current_alg); | ||
| 207 | } | ||
| 208 | |||
| 209 | return NULL; | ||
| 210 | } | ||
| 211 | |||
| 212 | static void | ||
| 213 | multidfs(DfsArg *arg) | ||
| 214 | { | ||
| 215 | int i; | ||
| 216 | Cube local_cube; | ||
| 217 | Alg *alg; | ||
| 218 | AlgList *start; | ||
| 219 | AlgListNode **node; | ||
| 220 | pthread_t t[arg->opts->nthreads]; | ||
| 221 | ThreadDataSolve td[arg->opts->nthreads]; | ||
| 222 | pthread_mutex_t *start_mutex, *sols_mutex; | ||
| 223 | |||
| 224 | node = malloc(sizeof(AlgListNode *)); | ||
| 225 | start_mutex = malloc(sizeof(pthread_mutex_t)); | ||
| 226 | sols_mutex = malloc(sizeof(pthread_mutex_t)); | ||
| 227 | |||
| 228 | start = new_alglist(); | ||
| 229 | pthread_mutex_init(start_mutex, NULL); | ||
| 230 | pthread_mutex_init(sols_mutex, NULL); | ||
| 231 | |||
| 232 | for (i = 0; arg->s->moveset->sorted_moves[i] != NULLMOVE; i++) { | ||
| 233 | alg = new_alg(""); | ||
| 234 | append_move(alg, arg->s->moveset->sorted_moves[i], false); | ||
| 235 | append_alg(start, alg); | ||
| 236 | if (arg->opts->can_niss && !arg->s->final) { | ||
| 237 | alg->inv[0] = true; | ||
| 238 | append_alg(start, alg); | ||
| 239 | } | ||
| 240 | free_alg(alg); | ||
| 241 | } | ||
| 242 | *node = start->first; | ||
| 243 | |||
| 244 | copy_cube(arg->cube, &local_cube); | ||
| 245 | |||
| 246 | for (i = 0; i < arg->opts->nthreads; i++) { | ||
| 247 | copy_dfsarg(arg, &(td[i].arg)); | ||
| 248 | td[i].arg.cube = &local_cube; | ||
| 249 | td[i].arg.sols_mutex = sols_mutex; | ||
| 250 | |||
| 251 | td[i].thid = i; | ||
| 252 | td[i].start = start; | ||
| 253 | td[i].node = node; | ||
| 254 | td[i].start_mutex = start_mutex; | ||
| 255 | |||
| 256 | pthread_create(&t[i], NULL, instance_thread, &td[i]); | ||
| 257 | } | ||
| 258 | |||
| 259 | for (i = 0; i < arg->opts->nthreads; i++) | ||
| 260 | pthread_join(t[i], NULL); | ||
| 261 | |||
| 262 | free_alglist(start); | ||
| 263 | free(node); | ||
| 264 | free(start_mutex); | ||
| 265 | free(sols_mutex); | ||
| 266 | } | ||
| 267 | |||
| 268 | static bool | ||
| 269 | niss_makes_sense(DfsArg *arg) | ||
| 270 | { | ||
| 271 | Move m, mm; | ||
| 272 | uint64_t u; | ||
| 273 | int i; | ||
| 274 | |||
| 275 | if (arg->s->final || arg->niss || !arg->opts->can_niss) | ||
| 276 | return false; | ||
| 277 | |||
| 278 | if (arg->current_alg->len_normal == 0) | ||
| 279 | return true; | ||
| 280 | |||
| 281 | m = inverse_move(arg->last[0]); | ||
| 282 | for (i = 0; i < arg->s->n_coord; i++) { | ||
| 283 | mm = transform_move(arg->ind[i].t, m); | ||
| 284 | u = move_coord(arg->s->coord[i], mm, 0, NULL); | ||
| 285 | if (ptableval(arg->s->pd[i], u) > 0) | ||
| 286 | return true; | ||
| 287 | } | ||
| 288 | |||
| 289 | return false; | ||
| 290 | } | ||
| 291 | |||
| 292 | static bool | ||
| 293 | solvestop(int d, int op, SolveOptions *opts, AlgList *sols) | ||
| 294 | { | ||
| 295 | bool opt_done, max_moves_exceeded, max_sols_exceeded; | ||
| 296 | |||
| 297 | opt_done = opts->optimal != -1 && op != -1 && d > opts->optimal + op; | ||
| 298 | max_moves_exceeded = d > opts->max_moves; | ||
| 299 | max_sols_exceeded = sols->len >= opts->max_solutions; | ||
| 300 | |||
| 301 | return opt_done || max_moves_exceeded || max_sols_exceeded; | ||
| 302 | } | ||
| 303 | |||
| 304 | /* Public functions **********************************************************/ | ||
| 305 | |||
| 306 | AlgList * | ||
| 307 | solve(Cube *cube, ChoiceStep *cs, SolveOptions *opts) | ||
| 308 | { | ||
| 309 | int i, j, d, op, est; | ||
| 310 | bool ready[99], one_ready, zerosol; | ||
| 311 | Movable ind[99][10]; | ||
| 312 | AlgList *s; | ||
| 313 | Cube *c[99]; | ||
| 314 | DfsArg arg[99]; | ||
| 315 | |||
| 316 | prepare_cs(cs, opts); | ||
| 317 | s = new_alglist(); | ||
| 318 | |||
| 319 | for (i = 0, one_ready = false; cs->step[i] != NULL; i++) { | ||
| 320 | c[i] = malloc(sizeof(Cube)); | ||
| 321 | copy_cube(cube, c[i]); | ||
| 322 | apply_trans(cs->t[i], c[i]); | ||
| 323 | |||
| 324 | arg[i].cube = c[i]; | ||
| 325 | arg[i].t = cs->t[i]; | ||
| 326 | arg[i].s = cs->step[i]; | ||
| 327 | arg[i].opts = opts; | ||
| 328 | arg[i].sols = s; | ||
| 329 | |||
| 330 | if ((ready[i] = cs->step[i]->ready(c[i]))) { | ||
| 331 | one_ready = true; | ||
| 332 | /* Only for local use for 0 moves solutions */ | ||
| 333 | compute_ind(cs->step[i], c[i], ind[i]); | ||
| 334 | } | ||
| 335 | } | ||
| 336 | if (!one_ready) { | ||
| 337 | fprintf(stderr, "Cube not ready for solving step: "); | ||
| 338 | fprintf(stderr, "%s\n", cs->ready_msg); | ||
| 339 | return s; | ||
| 340 | } | ||
| 341 | |||
| 342 | /* If the empty moves sequence is a solution for one of the | ||
| 343 | * alternatives, all longer solutions will be discarded, so we may | ||
| 344 | * just set its ready[] value to false. If the solution is accepted | ||
| 345 | * we append it and start searching from d = 1. */ | ||
| 346 | for (i = 0, zerosol = false; cs->step[i] != NULL; i++) { | ||
| 347 | if (ready[i]) { | ||
| 348 | est = 0; | ||
| 349 | for (j = 0; j < cs->step[i]->n_coord; j++) | ||
| 350 | est = MAX(est, ptableval(cs->step[i]->pd[j], | ||
| 351 | ind[i][j].val)); | ||
| 352 | if (est == 0) { | ||
| 353 | ready[i] = false; | ||
| 354 | zerosol = true; | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } | ||
| 358 | if (zerosol && opts->min_moves == 0) { | ||
| 359 | append_alg(s, new_alg("")); | ||
| 360 | opts->min_moves = 1; | ||
| 361 | if (opts->verbose) | ||
| 362 | printf("Step is already solved" | ||
| 363 | "(empty alg is a solution)\n"); | ||
| 364 | } | ||
| 365 | |||
| 366 | for (d = opts->min_moves, op = -1; !solvestop(d, op, opts, s); d++) { | ||
| 367 | if (opts->verbose) | ||
| 368 | fprintf(stderr, "Searching depth %d\n", d); | ||
| 369 | |||
| 370 | for (i=0; cs->step[i]!=NULL && !solvestop(d,op,opts,s); i++) { | ||
| 371 | if (!ready[i]) | ||
| 372 | continue; | ||
| 373 | |||
| 374 | arg[i].d = d; | ||
| 375 | multidfs(&arg[i]); | ||
| 376 | |||
| 377 | if (s->len > 0 && op == -1) | ||
| 378 | op = d; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | for (i = 0; cs->step[i] != NULL; i++) | ||
| 383 | free(c[i]); | ||
| 384 | |||
| 385 | return s; | ||
| 386 | } | ||
| 387 | |||
| 388 | /* TODO: make more general! */ | ||
| 389 | Alg * | ||
| 390 | solve_2phase(Cube *cube, int nthreads) | ||
| 391 | { | ||
| 392 | int bestlen, newb; | ||
| 393 | Alg *bestalg, *ret; | ||
| 394 | AlgList *sols1, *sols2; | ||
| 395 | AlgListNode *i; | ||
| 396 | Cube c; | ||
| 397 | SolveOptions opts1, opts2; | ||
| 398 | |||
| 399 | opts1.min_moves = 0; | ||
| 400 | opts1.max_moves = 13; | ||
| 401 | opts1.max_solutions = 20; | ||
| 402 | opts1.nthreads = nthreads; | ||
| 403 | opts1.optimal = 3; | ||
| 404 | opts1.can_niss = false; | ||
| 405 | opts1.verbose = false; | ||
| 406 | opts1.all = true; | ||
| 407 | |||
| 408 | opts2.min_moves = 0; | ||
| 409 | opts2.max_moves = 19; | ||
| 410 | opts2.max_solutions = 1; | ||
| 411 | opts2.nthreads = nthreads; | ||
| 412 | opts2.can_niss = false; | ||
| 413 | opts2.verbose = false; | ||
| 414 | |||
| 415 | /* We skip step1 if it is solved on U/D */ | ||
| 416 | if (check_drud(cube)) { | ||
| 417 | sols1 = new_alglist(); | ||
| 418 | append_alg(sols1, new_alg("")); | ||
| 419 | } else { | ||
| 420 | sols1 = solve(cube, &drud_HTM, &opts1); | ||
| 421 | } | ||
| 422 | bestalg = new_alg(""); | ||
| 423 | bestlen = 999; | ||
| 424 | for (i = sols1->first; i != NULL; i = i->next) { | ||
| 425 | copy_cube(cube, &c); | ||
| 426 | apply_alg(i->alg, &c); | ||
| 427 | sols2 = solve(&c, &dranyfin_DR, &opts2); | ||
| 428 | |||
| 429 | if (sols2->len > 0) { | ||
| 430 | newb = i->alg->len + sols2->first->alg->len; | ||
| 431 | if (newb < bestlen) { | ||
| 432 | bestlen = newb; | ||
| 433 | copy_alg(i->alg, bestalg); | ||
| 434 | compose_alg(bestalg, sols2->first->alg); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | |||
| 438 | free_alglist(sols2); | ||
| 439 | } | ||
| 440 | |||
| 441 | free_alglist(sols1); | ||
| 442 | |||
| 443 | ret = cleanup(bestalg); | ||
| 444 | free_alg(bestalg); | ||
| 445 | |||
| 446 | return ret; | ||
| 447 | } | ||
diff --git a/old/solve_old.h b/old/solve_old.h deleted file mode 100644 index 010389e..0000000 --- a/old/solve_old.h +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | #ifndef SOLVE_H | ||
| 2 | #define SOLVE_H | ||
| 3 | |||
| 4 | #include "movesets.h" | ||
| 5 | |||
| 6 | AlgList * solve(Cube *cube, ChoiceStep *cs, SolveOptions *opts); | ||
| 7 | Alg * solve_2phase(Cube *cube, int nthreads); | ||
| 8 | |||
| 9 | #endif | ||
