diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-11-11 21:37:34 +0100 |
| commit | 3568412f8f230774d0d11d7ed1c897424f95d3ef (patch) | |
| tree | 77223792d8c925a9b1fc32b3f4341e943b5f8209 /old/2021-06-23-realizing-bad-tables/steps.c | |
| parent | 67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff) | |
| download | nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip | |
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to '')
| -rw-r--r-- | old/2021-06-23-realizing-bad-tables/steps.c | 486 |
1 files changed, 486 insertions, 0 deletions
diff --git a/old/2021-06-23-realizing-bad-tables/steps.c b/old/2021-06-23-realizing-bad-tables/steps.c new file mode 100644 index 0000000..2b029b8 --- /dev/null +++ b/old/2021-06-23-realizing-bad-tables/steps.c | |||
| @@ -0,0 +1,486 @@ | |||
| 1 | #include "steps.h" | ||
| 2 | |||
| 3 | /* Check functions ***********************************************************/ | ||
| 4 | |||
| 5 | static int check_nothing(Cube cube, int target); | ||
| 6 | static int check_centers(Cube cube, int target); | ||
| 7 | static int check_eofb_HTM(Cube cube, int target); | ||
| 8 | static int check_coud_HTM(Cube cube, int target); | ||
| 9 | static int check_coud_URF(Cube cube, int target); | ||
| 10 | static int check_corners_HTM(Cube cube, int target); | ||
| 11 | static int check_cornershtr_HTM(Cube cube, int target); | ||
| 12 | static int check_corners_URF(Cube cube, int target); | ||
| 13 | static int check_cornershtr_URF(Cube cube, int target); | ||
| 14 | static int check_ep_HTM(Cube cube, int target); | ||
| 15 | static int check_edges_HTM(Cube cube, int target); | ||
| 16 | static int check_drud_HTM(Cube cube, int target); | ||
| 17 | static int check_optimal_HTM(Cube cube, int target); | ||
| 18 | static int check_corners6eo_HTM(Cube cube, int target); | ||
| 19 | static int check_tripleeo_HTM(Cube cube, int target); | ||
| 20 | |||
| 21 | |||
| 22 | /* Index functions ***********************************************************/ | ||
| 23 | |||
| 24 | static uint64_t index_eofb(Cube cube); | ||
| 25 | static uint64_t index_coud(Cube cube); | ||
| 26 | static uint64_t index_corners(Cube cube); | ||
| 27 | static uint64_t index_cornershtr(Cube cube); | ||
| 28 | static uint64_t index_ep(Cube cube); | ||
| 29 | static uint64_t index_drud(Cube cube); | ||
| 30 | static uint64_t index_corners6eo(Cube cube); | ||
| 31 | static uint64_t index_tripleeo(Cube cube); | ||
| 32 | |||
| 33 | |||
| 34 | /* Steps *********************************************************************/ | ||
| 35 | |||
| 36 | Step | ||
| 37 | eofb_HTM = { | ||
| 38 | .check = check_eofb_HTM, | ||
| 39 | .ready = check_centers, | ||
| 40 | .moveset = moveset_HTM | ||
| 41 | }; | ||
| 42 | |||
| 43 | Step | ||
| 44 | coud_HTM = { | ||
| 45 | .check = check_coud_HTM, | ||
| 46 | .ready = check_centers, | ||
| 47 | .moveset = moveset_HTM | ||
| 48 | }; | ||
| 49 | |||
| 50 | Step | ||
| 51 | coud_URF = { | ||
| 52 | .check = check_coud_URF, | ||
| 53 | .ready = check_nothing, | ||
| 54 | .moveset = moveset_URF | ||
| 55 | }; | ||
| 56 | |||
| 57 | Step | ||
| 58 | corners_HTM = { | ||
| 59 | .check = check_corners_HTM, | ||
| 60 | .ready = check_centers, | ||
| 61 | .moveset = moveset_HTM | ||
| 62 | }; | ||
| 63 | |||
| 64 | Step | ||
| 65 | cornershtr_HTM = { | ||
| 66 | .check = check_cornershtr_HTM, | ||
| 67 | .ready = check_centers, | ||
| 68 | .moveset = moveset_HTM | ||
| 69 | }; | ||
| 70 | |||
| 71 | Step | ||
| 72 | cornershtr_URF = { | ||
| 73 | .check = check_cornershtr_URF, | ||
| 74 | .ready = check_nothing, | ||
| 75 | .moveset = moveset_URF | ||
| 76 | }; | ||
| 77 | |||
| 78 | Step | ||
| 79 | corners_URF = { | ||
| 80 | .check = check_corners_URF, | ||
| 81 | .ready = check_nothing, | ||
| 82 | .moveset = moveset_URF | ||
| 83 | }; | ||
| 84 | |||
| 85 | Step | ||
| 86 | edges_HTM = { | ||
| 87 | .check = check_edges_HTM, | ||
| 88 | .ready = check_centers, | ||
| 89 | .moveset = moveset_HTM | ||
| 90 | }; | ||
| 91 | |||
| 92 | Step | ||
| 93 | drud_HTM = { | ||
| 94 | .check = check_drud_HTM, | ||
| 95 | .ready = check_centers, | ||
| 96 | .moveset = moveset_HTM | ||
| 97 | }; | ||
| 98 | |||
| 99 | Step | ||
| 100 | optimal_HTM = { | ||
| 101 | .check = check_optimal_HTM, | ||
| 102 | .ready = check_centers, | ||
| 103 | .moveset = moveset_HTM | ||
| 104 | }; | ||
| 105 | |||
| 106 | Step | ||
| 107 | tripleeo_HTM = { | ||
| 108 | .check = check_tripleeo_HTM, | ||
| 109 | .ready = check_centers, | ||
| 110 | .moveset = moveset_HTM | ||
| 111 | }; | ||
| 112 | |||
| 113 | |||
| 114 | /* Blocks ********************************************************************/ | ||
| 115 | |||
| 116 | Block | ||
| 117 | block_223dl = { | ||
| 118 | .edge = { [DF] = 1, [DL] = 1, [DB] = 1, [FL] = 1, [BL] = 1 }, | ||
| 119 | .corner = { [DFL] = 1, [DBL] = 1 }, | ||
| 120 | .center = { [D_center] = 1, [L_center] = 1 } | ||
| 121 | }; | ||
| 122 | |||
| 123 | |||
| 124 | /* Pruning tables ************************************************************/ | ||
| 125 | |||
| 126 | PruneData | ||
| 127 | pd_eofb_HTM = { | ||
| 128 | .filename = "ptable_eofb_HTM", | ||
| 129 | .size = POW2TO11, | ||
| 130 | .index = index_eofb, | ||
| 131 | .moveset = moveset_HTM | ||
| 132 | }; | ||
| 133 | |||
| 134 | PruneData | ||
| 135 | pd_coud_HTM = { | ||
| 136 | .filename = "ptable_coud_HTM", | ||
| 137 | .size = POW3TO7, | ||
| 138 | .index = index_coud, | ||
| 139 | .moveset = moveset_HTM | ||
| 140 | }; | ||
| 141 | |||
| 142 | PruneData | ||
| 143 | pd_cornershtr_HTM = { | ||
| 144 | .filename = "ptable_cornershtr_HTM", | ||
| 145 | .size = POW3TO7 * BINOM8ON4 * 6, /*TODO: check */ | ||
| 146 | .index = index_cornershtr, | ||
| 147 | .moveset = moveset_HTM | ||
| 148 | }; | ||
| 149 | |||
| 150 | PruneData | ||
| 151 | pd_corners_HTM = { | ||
| 152 | .filename = "ptable_corners_HTM", | ||
| 153 | .size = POW3TO7 * FACTORIAL8, | ||
| 154 | .index = index_corners, | ||
| 155 | .moveset = moveset_HTM | ||
| 156 | }; | ||
| 157 | |||
| 158 | PruneData | ||
| 159 | pd_ep_HTM = { | ||
| 160 | .filename = "ptable_ep_HTM", | ||
| 161 | .size = FACTORIAL12, | ||
| 162 | .index = index_ep, | ||
| 163 | .moveset = moveset_HTM | ||
| 164 | }; | ||
| 165 | |||
| 166 | PruneData | ||
| 167 | pd_drud_HTM = { | ||
| 168 | .filename = "ptable_drud_HTM", | ||
| 169 | .size = POW2TO11 * POW3TO7 * BINOM12ON4, | ||
| 170 | .index = index_drud, | ||
| 171 | .moveset = moveset_HTM | ||
| 172 | }; | ||
| 173 | |||
| 174 | PruneData | ||
| 175 | pd_corners6eo_HTM = { | ||
| 176 | .filename = "ptable_corners6eo_HTM", | ||
| 177 | .size = POW2TO6 * POW3TO7 * FACTORIAL8, | ||
| 178 | .index = index_corners6eo, | ||
| 179 | .moveset = moveset_HTM | ||
| 180 | }; | ||
| 181 | |||
| 182 | PruneData | ||
| 183 | pd_tripleeo_HTM = { | ||
| 184 | .filename = "ptable_tripleeo_HTM", | ||
| 185 | .size = BINOM12ON4 * BINOM8ON4 * POW2TO11, | ||
| 186 | .index = index_tripleeo, | ||
| 187 | .moveset = moveset_HTM | ||
| 188 | }; | ||
| 189 | |||
| 190 | |||
| 191 | /* Alg sets ******************************************************************/ | ||
| 192 | |||
| 193 | /* TODO: remove this (I am only keeping it as an example for future algesets) | ||
| 194 | AlgSet | ||
| 195 | as_ephtr_HTM = { | ||
| 196 | .filename = "algset_ephtr_HTM", | ||
| 197 | .size = FACTORIAL4 * FACTORIAL4 * FACTORIAL4, | ||
| 198 | .index = index_ephtr, | ||
| 199 | .antindex = index_to_cube_ephtr, | ||
| 200 | .step = (Step) { | ||
| 201 | .check = check_optimal_HTM, | ||
| 202 | .ready = check_htr_solved_corners_HTM, | ||
| 203 | .moveset = moveset_HTM | ||
| 204 | }, | ||
| 205 | .opts = (SolveOptions) { | ||
| 206 | .min_moves = 0, | ||
| 207 | .max_moves = 20, | ||
| 208 | .max_solutions = 1, | ||
| 209 | .optimal_only = true, | ||
| 210 | .can_niss = false, | ||
| 211 | .feedback = true, | ||
| 212 | .pre_trans = uf | ||
| 213 | } | ||
| 214 | }; | ||
| 215 | */ | ||
| 216 | |||
| 217 | |||
| 218 | /* Check functions implementation ********************************************/ | ||
| 219 | |||
| 220 | static int | ||
| 221 | check_nothing(Cube cube, int target) | ||
| 222 | { | ||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | |||
| 226 | static int | ||
| 227 | check_centers(Cube cube, int target) | ||
| 228 | { | ||
| 229 | return (cube.cpos == 0) ? 0 : 1; | ||
| 230 | } | ||
| 231 | |||
| 232 | static int | ||
| 233 | check_eofb_HTM(Cube cube, int target) | ||
| 234 | { | ||
| 235 | if (!pd_eofb_HTM.generated) | ||
| 236 | genptable(&pd_eofb_HTM); | ||
| 237 | |||
| 238 | return ptableval(&pd_eofb_HTM, cube.eofb); | ||
| 239 | } | ||
| 240 | |||
| 241 | static int | ||
| 242 | check_coud_HTM(Cube cube, int target) | ||
| 243 | { | ||
| 244 | if (!pd_coud_HTM.generated) | ||
| 245 | genptable(&pd_coud_HTM); | ||
| 246 | |||
| 247 | return ptableval(&pd_coud_HTM, cube.coud); | ||
| 248 | } | ||
| 249 | |||
| 250 | static int | ||
| 251 | check_coud_URF(Cube cube, int target) | ||
| 252 | { | ||
| 253 | /* TODO: I can improve this by checking first the orientation of | ||
| 254 | * the corner in DBL and use that as a reference */ | ||
| 255 | |||
| 256 | int ud = check_coud_HTM(cube, target); | ||
| 257 | int rl = check_coud_HTM(apply_move(z, cube), target); | ||
| 258 | int fb = check_coud_HTM(apply_move(x, cube), target); | ||
| 259 | |||
| 260 | return MIN(ud, MIN(rl, fb)); | ||
| 261 | } | ||
| 262 | |||
| 263 | static int | ||
| 264 | check_corners_HTM(Cube cube, int target) | ||
| 265 | { | ||
| 266 | if (!pd_corners_HTM.generated) | ||
| 267 | genptable(&pd_corners_HTM); | ||
| 268 | |||
| 269 | return ptableval(&pd_corners_HTM, index_corners(cube)); | ||
| 270 | } | ||
| 271 | |||
| 272 | static int | ||
| 273 | check_cornershtr_HTM(Cube cube, int target) | ||
| 274 | { | ||
| 275 | if (!pd_cornershtr_HTM.generated) | ||
| 276 | genptable(&pd_cornershtr_HTM); | ||
| 277 | |||
| 278 | return ptableval(&pd_cornershtr_HTM, index_cornershtr(cube)); | ||
| 279 | } | ||
| 280 | |||
| 281 | static int | ||
| 282 | check_cornershtr_URF(Cube cube, int target) | ||
| 283 | { | ||
| 284 | /* TODO: I can improve this by checking first the corner in DBL | ||
| 285 | * and use that as a reference */ | ||
| 286 | |||
| 287 | int c, ret = 15; | ||
| 288 | Trans i; | ||
| 289 | |||
| 290 | for (i = 0; i < NROTATIONS; i++) { | ||
| 291 | c = check_cornershtr_HTM(apply_alg(trans_alg(i),cube), target); | ||
| 292 | ret = MIN(ret, c); | ||
| 293 | } | ||
| 294 | |||
| 295 | return ret; | ||
| 296 | } | ||
| 297 | |||
| 298 | static int | ||
| 299 | check_corners_URF(Cube cube, int target) | ||
| 300 | { | ||
| 301 | /* TODO: I can improve this by checking first the corner in DBL | ||
| 302 | * and use that as a reference */ | ||
| 303 | |||
| 304 | int ret = 15; | ||
| 305 | Trans i; | ||
| 306 | |||
| 307 | for (i = 0; i < NROTATIONS; i++) | ||
| 308 | ret = MIN(ret, check_corners_HTM( | ||
| 309 | apply_alg(trans_alg(i), cube), target)); | ||
| 310 | |||
| 311 | return ret; | ||
| 312 | } | ||
| 313 | |||
| 314 | static int | ||
| 315 | check_ep_HTM(Cube cube, int target) | ||
| 316 | { | ||
| 317 | if (!pd_ep_HTM.generated) | ||
| 318 | genptable(&pd_ep_HTM); | ||
| 319 | |||
| 320 | return ptableval(&pd_ep_HTM, index_ep(cube)); | ||
| 321 | } | ||
| 322 | |||
| 323 | static int | ||
| 324 | check_edges_HTM(Cube cube, int target) | ||
| 325 | { | ||
| 326 | return MAX(check_ep_HTM(cube, target), | ||
| 327 | check_tripleeo_HTM(cube, target)); | ||
| 328 | } | ||
| 329 | |||
| 330 | static int | ||
| 331 | check_drud_HTM(Cube cube, int target) | ||
| 332 | { | ||
| 333 | if (!pd_drud_HTM.generated) | ||
| 334 | genptable(&pd_drud_HTM); | ||
| 335 | |||
| 336 | return ptableval(&pd_drud_HTM, index_drud(cube)); | ||
| 337 | } | ||
| 338 | |||
| 339 | static int | ||
| 340 | check_optimal_HTM(Cube cube, int target) | ||
| 341 | { | ||
| 342 | int dr1, dr2, dr3, cor, ret; | ||
| 343 | Cube cube2, cube3; | ||
| 344 | |||
| 345 | dr1 = check_drud_HTM(cube, target); | ||
| 346 | /*cor = check_corners6eo_HTM(cube, target);*/ | ||
| 347 | cor = check_corners_HTM(cube, target); | ||
| 348 | ret = MAX(dr1, cor); | ||
| 349 | |||
| 350 | if (ret > target) | ||
| 351 | return ret; | ||
| 352 | |||
| 353 | cube2 = apply_trans(rf, cube); | ||
| 354 | dr2 = check_drud_HTM(cube2, target); | ||
| 355 | /*cor = check_corners6eo_HTM(cube2, target); | ||
| 356 | ret = MAX(ret, MAX(dr2, cor));*/ | ||
| 357 | ret = MAX(ret, dr2); | ||
| 358 | |||
| 359 | if (ret > target) | ||
| 360 | return ret; | ||
| 361 | |||
| 362 | cube3 = apply_trans(bd, cube); | ||
| 363 | dr3 = check_drud_HTM(cube3, target); | ||
| 364 | /*cor = check_corners6eo_HTM(cube3, target);*/ | ||
| 365 | |||
| 366 | if (dr1 == dr2 && dr2 == dr3 && dr1 != 0) | ||
| 367 | dr3++; | ||
| 368 | |||
| 369 | /*ret = MAX(ret, MAX(dr3, cor));*/ | ||
| 370 | ret = MAX(ret, dr3); | ||
| 371 | |||
| 372 | if (ret == 0) | ||
| 373 | return (!cube.epose && !cube.eposs && !cube.eposm) ? 0 : 6; | ||
| 374 | |||
| 375 | return ret; | ||
| 376 | } | ||
| 377 | |||
| 378 | static int | ||
| 379 | check_corners6eo_HTM(Cube cube, int target) | ||
| 380 | { | ||
| 381 | if (!pd_corners6eo_HTM.generated) | ||
| 382 | genptable(&pd_corners6eo_HTM); | ||
| 383 | |||
| 384 | return ptableval(&pd_corners6eo_HTM, index_corners6eo(cube)); | ||
| 385 | } | ||
| 386 | |||
| 387 | static int | ||
| 388 | check_tripleeo_HTM(Cube cube, int target) | ||
| 389 | { | ||
| 390 | if (!pd_tripleeo_HTM.generated) | ||
| 391 | genptable(&pd_tripleeo_HTM); | ||
| 392 | |||
| 393 | return ptableval(&pd_tripleeo_HTM, index_tripleeo(cube)); | ||
| 394 | } | ||
| 395 | |||
| 396 | |||
| 397 | /* Index functions implementation ********************************************/ | ||
| 398 | |||
| 399 | static uint64_t | ||
| 400 | index_eofb(Cube cube) | ||
| 401 | { | ||
| 402 | return cube.eofb; | ||
| 403 | } | ||
| 404 | |||
| 405 | static uint64_t | ||
| 406 | index_coud(Cube cube) | ||
| 407 | { | ||
| 408 | return cube.coud; | ||
| 409 | } | ||
| 410 | |||
| 411 | static uint64_t | ||
| 412 | index_cornershtr(Cube cube) | ||
| 413 | { | ||
| 414 | return cube.coud * BINOM8ON4 * 6 + cphtr(cube); | ||
| 415 | } | ||
| 416 | |||
| 417 | static uint64_t | ||
| 418 | index_corners(Cube cube) | ||
| 419 | { | ||
| 420 | return cube.coud * FACTORIAL8 + cube.cp; | ||
| 421 | } | ||
| 422 | |||
| 423 | static uint64_t | ||
| 424 | index_ep(Cube cube) | ||
| 425 | { | ||
| 426 | uint64_t a, b, c; | ||
| 427 | |||
| 428 | a = cube.epose; | ||
| 429 | b = (cube.eposs % FACTORIAL4) + epos_dependent(cube)*FACTORIAL4; | ||
| 430 | c = cube.eposm % FACTORIAL4; | ||
| 431 | |||
| 432 | b *= FACTORIAL4 * BINOM12ON4; | ||
| 433 | c *= FACTORIAL4 * BINOM12ON4 * FACTORIAL4 * BINOM8ON4; | ||
| 434 | |||
| 435 | return a + b + c; | ||
| 436 | } | ||
| 437 | |||
| 438 | static uint64_t | ||
| 439 | index_drud(Cube cube) | ||
| 440 | { | ||
| 441 | uint64_t a, b, c; | ||
| 442 | |||
| 443 | a = cube.eofb; | ||
| 444 | b = cube.coud; | ||
| 445 | c = cube.epose / FACTORIAL4; | ||
| 446 | |||
| 447 | b *= POW2TO11; | ||
| 448 | c *= POW2TO11 * POW3TO7; | ||
| 449 | |||
| 450 | return a + b + c; | ||
| 451 | } | ||
| 452 | |||
| 453 | static uint64_t | ||
| 454 | index_corners6eo(Cube cube) | ||
| 455 | { | ||
| 456 | return (cube.coud*FACTORIAL8 + cube.cp)*POW2TO6 + (cube.eofb%POW2TO6); | ||
| 457 | } | ||
| 458 | |||
| 459 | static uint64_t | ||
| 460 | index_tripleeo(Cube cube) | ||
| 461 | { | ||
| 462 | uint64_t ee, es; | ||
| 463 | |||
| 464 | ee = cube.epose / FACTORIAL4; | ||
| 465 | es = epos_dependent(cube); | ||
| 466 | |||
| 467 | return (ee * BINOM8ON4 + es) * POW2TO11 + cube.eofb; | ||
| 468 | } | ||
| 469 | |||
| 470 | |||
| 471 | /* Movesets ******************************************************************/ | ||
| 472 | |||
| 473 | bool | ||
| 474 | moveset_HTM(Move m) | ||
| 475 | { | ||
| 476 | return m >= U && m <= B3; | ||
| 477 | } | ||
| 478 | |||
| 479 | bool | ||
| 480 | moveset_URF(Move m) | ||
| 481 | { | ||
| 482 | Move b = base_move(m); | ||
| 483 | |||
| 484 | return b == U || b == R || b == F; | ||
| 485 | } | ||
| 486 | |||
