diff options
Diffstat (limited to '')
| -rw-r--r-- | old/2021-06-30-reached/steps.c | 307 |
1 files changed, 307 insertions, 0 deletions
diff --git a/old/2021-06-30-reached/steps.c b/old/2021-06-30-reached/steps.c new file mode 100644 index 0000000..bc833cb --- /dev/null +++ b/old/2021-06-30-reached/steps.c | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | #include "steps.h" | ||
| 2 | |||
| 3 | /* Standard checkers (return lower bound) ************************************/ | ||
| 4 | |||
| 5 | static int estimate_eofb_HTM(CubeTarget ct); | ||
| 6 | static int estimate_coud_HTM(CubeTarget ct); | ||
| 7 | static int estimate_coud_URF(CubeTarget ct); | ||
| 8 | static int estimate_corners_HTM(CubeTarget ct); | ||
| 9 | static int estimate_cornershtr_HTM(CubeTarget ct); | ||
| 10 | static int estimate_corners_URF(CubeTarget ct); | ||
| 11 | static int estimate_cornershtr_URF(CubeTarget ct); | ||
| 12 | static int estimate_drud_HTM(CubeTarget ct); | ||
| 13 | static int estimate_optimal_HTM(CubeTarget ct); | ||
| 14 | |||
| 15 | /* Steps *********************************************************************/ | ||
| 16 | |||
| 17 | Step | ||
| 18 | eofb_HTM = { | ||
| 19 | .estimate = estimate_eofb_HTM, | ||
| 20 | .ready = check_centers, | ||
| 21 | .moveset = moveset_HTM | ||
| 22 | }; | ||
| 23 | |||
| 24 | Step | ||
| 25 | coud_HTM = { | ||
| 26 | .estimate = estimate_coud_HTM, | ||
| 27 | .ready = check_centers, | ||
| 28 | .moveset = moveset_HTM | ||
| 29 | }; | ||
| 30 | |||
| 31 | Step | ||
| 32 | coud_URF = { | ||
| 33 | .estimate = estimate_coud_URF, | ||
| 34 | .ready = check_nothing, | ||
| 35 | .moveset = moveset_URF | ||
| 36 | }; | ||
| 37 | |||
| 38 | Step | ||
| 39 | corners_HTM = { | ||
| 40 | .estimate = estimate_corners_HTM, | ||
| 41 | .ready = check_centers, | ||
| 42 | .moveset = moveset_HTM | ||
| 43 | }; | ||
| 44 | |||
| 45 | Step | ||
| 46 | cornershtr_HTM = { | ||
| 47 | .estimate = estimate_cornershtr_HTM, | ||
| 48 | .ready = check_centers, | ||
| 49 | .moveset = moveset_HTM | ||
| 50 | }; | ||
| 51 | |||
| 52 | Step | ||
| 53 | cornershtr_URF = { | ||
| 54 | .estimate = estimate_cornershtr_URF, | ||
| 55 | .ready = check_nothing, | ||
| 56 | .moveset = moveset_URF | ||
| 57 | }; | ||
| 58 | |||
| 59 | Step | ||
| 60 | corners_URF = { | ||
| 61 | .estimate = estimate_corners_URF, | ||
| 62 | .ready = check_nothing, | ||
| 63 | .moveset = moveset_URF | ||
| 64 | }; | ||
| 65 | |||
| 66 | Step | ||
| 67 | drud_HTM = { | ||
| 68 | .estimate = estimate_drud_HTM, | ||
| 69 | .ready = check_centers, | ||
| 70 | .moveset = moveset_HTM | ||
| 71 | }; | ||
| 72 | |||
| 73 | Step | ||
| 74 | optimal_HTM = { | ||
| 75 | .estimate = estimate_optimal_HTM, | ||
| 76 | .ready = check_centers, | ||
| 77 | .moveset = moveset_HTM | ||
| 78 | }; | ||
| 79 | |||
| 80 | |||
| 81 | /* Pruning tables ************************************************************/ | ||
| 82 | |||
| 83 | PruneData | ||
| 84 | pd_eofb_HTM = { | ||
| 85 | .filename = "ptable_eofb_HTM", | ||
| 86 | .coord = &coord_eofb, | ||
| 87 | .moveset = moveset_HTM | ||
| 88 | }; | ||
| 89 | |||
| 90 | PruneData | ||
| 91 | pd_coud_HTM = { | ||
| 92 | .filename = "ptable_coud_HTM", | ||
| 93 | .coord = &coord_coud, | ||
| 94 | .moveset = moveset_HTM | ||
| 95 | }; | ||
| 96 | |||
| 97 | PruneData | ||
| 98 | pd_cornershtr_HTM = { | ||
| 99 | .filename = "ptable_cornershtr_withcosets_HTM", | ||
| 100 | .coord = &coord_cornershtr, | ||
| 101 | .moveset = moveset_HTM | ||
| 102 | }; | ||
| 103 | |||
| 104 | PruneData | ||
| 105 | pd_corners_HTM = { | ||
| 106 | .filename = "ptable_corners_HTM", | ||
| 107 | .coord = &coord_corners, | ||
| 108 | .moveset = moveset_HTM | ||
| 109 | }; | ||
| 110 | |||
| 111 | PruneData | ||
| 112 | pd_drud_HTM = { | ||
| 113 | .filename = "ptable_drud_HTM", | ||
| 114 | .coord = &coord_drud, | ||
| 115 | .moveset = moveset_HTM | ||
| 116 | }; | ||
| 117 | |||
| 118 | PruneData | ||
| 119 | pd_drud_sym16_HTM = { | ||
| 120 | .filename = "pd_drud_sym16_HTM", | ||
| 121 | .coord = &coord_drud_sym16, | ||
| 122 | .moveset = moveset_HTM, | ||
| 123 | }; | ||
| 124 | |||
| 125 | PruneData | ||
| 126 | pd_khuge_HTM = { | ||
| 127 | .filename = "pd_khuge_HTM", | ||
| 128 | .coord = &coord_khuge, | ||
| 129 | .moveset = moveset_HTM | ||
| 130 | }; | ||
| 131 | |||
| 132 | |||
| 133 | /* Standard checkers (return lower bound) ************************************/ | ||
| 134 | |||
| 135 | static int | ||
| 136 | estimate_eofb_HTM(CubeTarget ct) | ||
| 137 | { | ||
| 138 | if (!pd_eofb_HTM.generated) | ||
| 139 | genptable(&pd_eofb_HTM); | ||
| 140 | |||
| 141 | return ptableval(&pd_eofb_HTM, ct.cube); | ||
| 142 | } | ||
| 143 | |||
| 144 | static int | ||
| 145 | estimate_coud_HTM(CubeTarget ct) | ||
| 146 | { | ||
| 147 | if (!pd_coud_HTM.generated) | ||
| 148 | genptable(&pd_coud_HTM); | ||
| 149 | |||
| 150 | return ptableval(&pd_coud_HTM, ct.cube); | ||
| 151 | } | ||
| 152 | |||
| 153 | static int | ||
| 154 | estimate_coud_URF(CubeTarget ct) | ||
| 155 | { | ||
| 156 | /* TODO: I can improve this by checking first the orientation of | ||
| 157 | * the corner in DBL and use that as a reference */ | ||
| 158 | |||
| 159 | CubeTarget ct2 = {.cube = apply_move(z, ct.cube), .target = ct.target}; | ||
| 160 | CubeTarget ct3 = {.cube = apply_move(x, ct.cube), .target = ct.target}; | ||
| 161 | |||
| 162 | int ud = estimate_coud_HTM(ct); | ||
| 163 | int rl = estimate_coud_HTM(ct2); | ||
| 164 | int fb = estimate_coud_HTM(ct3); | ||
| 165 | |||
| 166 | return MIN(ud, MIN(rl, fb)); | ||
| 167 | } | ||
| 168 | |||
| 169 | static int | ||
| 170 | estimate_corners_HTM(CubeTarget ct) | ||
| 171 | { | ||
| 172 | if (!pd_corners_HTM.generated) | ||
| 173 | genptable(&pd_corners_HTM); | ||
| 174 | |||
| 175 | return ptableval(&pd_corners_HTM, ct.cube); | ||
| 176 | } | ||
| 177 | |||
| 178 | static int | ||
| 179 | estimate_cornershtr_HTM(CubeTarget ct) | ||
| 180 | { | ||
| 181 | if (!pd_cornershtr_HTM.generated) | ||
| 182 | genptable(&pd_cornershtr_HTM); | ||
| 183 | |||
| 184 | return ptableval(&pd_cornershtr_HTM, ct.cube); | ||
| 185 | } | ||
| 186 | |||
| 187 | static int | ||
| 188 | estimate_cornershtr_URF(CubeTarget ct) | ||
| 189 | { | ||
| 190 | /* TODO: I can improve this by checking first the corner in DBL | ||
| 191 | * and use that as a reference */ | ||
| 192 | |||
| 193 | int c, ret = 15; | ||
| 194 | Trans i; | ||
| 195 | |||
| 196 | for (i = 0; i < NROTATIONS; i++) { | ||
| 197 | ct.cube = apply_alg(rotation_alg(i), ct.cube); | ||
| 198 | c = estimate_cornershtr_HTM(ct); | ||
| 199 | ret = MIN(ret, c); | ||
| 200 | } | ||
| 201 | |||
| 202 | return ret; | ||
| 203 | } | ||
| 204 | |||
| 205 | static int | ||
| 206 | estimate_corners_URF(CubeTarget ct) | ||
| 207 | { | ||
| 208 | /* TODO: I can improve this by checking first the corner in DBL | ||
| 209 | * and use that as a reference */ | ||
| 210 | |||
| 211 | int c, ret = 15; | ||
| 212 | Trans i; | ||
| 213 | |||
| 214 | for (i = 0; i < NROTATIONS; i++) { | ||
| 215 | ct.cube = apply_alg(rotation_alg(i), ct.cube); | ||
| 216 | c = estimate_corners_HTM(ct); | ||
| 217 | ret = MIN(ret, c); | ||
| 218 | } | ||
| 219 | |||
| 220 | return ret; | ||
| 221 | } | ||
| 222 | |||
| 223 | static int | ||
| 224 | estimate_drud_HTM(CubeTarget ct) | ||
| 225 | { | ||
| 226 | /* | ||
| 227 | if (!pd_drud_HTM.generated) | ||
| 228 | genptable(&pd_drud_HTM); | ||
| 229 | |||
| 230 | return ptableval(&pd_drud_HTM, ct.cube); | ||
| 231 | */ | ||
| 232 | |||
| 233 | if (!pd_drud_sym16_HTM.generated) | ||
| 234 | genptable(&pd_drud_sym16_HTM); | ||
| 235 | |||
| 236 | return ptableval(&pd_drud_sym16_HTM, ct.cube); | ||
| 237 | } | ||
| 238 | |||
| 239 | /* TODO: if lucky, remove this */ | ||
| 240 | /* | ||
| 241 | static int | ||
| 242 | estimate_optimal_HTM(CubeTarget ct) | ||
| 243 | { | ||
| 244 | static Trans t1 = { .rot = rf, .mirror = false }; | ||
| 245 | static Trans t2 = { .rot = bd, .mirror = false }; | ||
| 246 | int dr1, dr2, dr3, cor, ret; | ||
| 247 | Cube cube = ct.cube; | ||
| 248 | |||
| 249 | dr1 = estimate_drud_HTM(ct); | ||
| 250 | cor = estimate_corners_HTM(ct); | ||
| 251 | ret = MAX(dr1, cor); | ||
| 252 | |||
| 253 | if (ret > ct.target) | ||
| 254 | return ret; | ||
| 255 | |||
| 256 | ct.cube = apply_trans(t1, cube); | ||
| 257 | dr2 = estimate_drud_HTM(ct); | ||
| 258 | ret = MAX(ret, dr2); | ||
| 259 | |||
| 260 | if (ret > ct.target) | ||
| 261 | return ret; | ||
| 262 | |||
| 263 | ct.cube = apply_trans(t2, cube); | ||
| 264 | dr3 = estimate_drud_HTM(ct); | ||
| 265 | |||
| 266 | if (dr1 == dr2 && dr2 == dr3 && dr1 != 0) | ||
| 267 | dr3++; | ||
| 268 | |||
| 269 | ret = MAX(ret, dr3); | ||
| 270 | |||
| 271 | if (ret == 0) | ||
| 272 | return check_ep(cube) ? 0 : 6; | ||
| 273 | |||
| 274 | return ret; | ||
| 275 | } | ||
| 276 | */ | ||
| 277 | |||
| 278 | static int | ||
| 279 | estimate_optimal_HTM(CubeTarget ct) | ||
| 280 | { | ||
| 281 | static Trans t2 = rf, t3 = bd; | ||
| 282 | |||
| 283 | int dr1, dr2, dr3, cor, ret; | ||
| 284 | Cube cube = ct.cube; | ||
| 285 | |||
| 286 | if (!pd_khuge_HTM.generated) | ||
| 287 | genptable(&pd_khuge_HTM); | ||
| 288 | |||
| 289 | dr1 = ptableval(&pd_khuge_HTM, cube); | ||
| 290 | cor = estimate_corners_HTM(ct); | ||
| 291 | ret = MAX(dr1, cor); | ||
| 292 | |||
| 293 | if (ret > ct.target) | ||
| 294 | return ret; | ||
| 295 | |||
| 296 | cube = apply_trans(t2, ct.cube); | ||
| 297 | dr2 = ptableval(&pd_khuge_HTM, cube); | ||
| 298 | ret = MAX(ret, dr2); | ||
| 299 | |||
| 300 | if (ret > ct.target) | ||
| 301 | return ret; | ||
| 302 | |||
| 303 | cube = apply_trans(t3, ct.cube); | ||
| 304 | dr3 = ptableval(&pd_khuge_HTM, cube); | ||
| 305 | |||
| 306 | return MAX(ret, dr3); | ||
| 307 | } | ||
