diff options
Diffstat (limited to 'old/2021-06-17-cachedata/steps.c')
| -rw-r--r-- | old/2021-06-17-cachedata/steps.c | 327 |
1 files changed, 0 insertions, 327 deletions
diff --git a/old/2021-06-17-cachedata/steps.c b/old/2021-06-17-cachedata/steps.c deleted file mode 100644 index f1001e6..0000000 --- a/old/2021-06-17-cachedata/steps.c +++ /dev/null | |||
| @@ -1,327 +0,0 @@ | |||
| 1 | #include "steps.h" | ||
| 2 | |||
| 3 | /* Check functions ***********************************************************/ | ||
| 4 | |||
| 5 | static int check_nothing(Cube cube); | ||
| 6 | static int check_eofb_HTM(Cube cube); | ||
| 7 | static int check_coud_HTM(Cube cube); | ||
| 8 | static int check_coud_URF(Cube cube); | ||
| 9 | static int check_corners_HTM(Cube cube); | ||
| 10 | static int check_corners_URF(Cube cube); | ||
| 11 | static int check_edges_HTM(Cube cube); | ||
| 12 | static int check_drud_HTM(Cube cube); | ||
| 13 | static int check_optimal_HTM(Cube cube); | ||
| 14 | |||
| 15 | |||
| 16 | /* Index functions ***********************************************************/ | ||
| 17 | |||
| 18 | static uint64_t index_eofb(Cube cube); | ||
| 19 | static uint64_t index_coud(Cube cube); | ||
| 20 | static uint64_t index_corners(Cube cube); | ||
| 21 | static uint64_t index_ep(Cube cube); | ||
| 22 | static uint64_t index_drud(Cube cube); | ||
| 23 | |||
| 24 | |||
| 25 | /* Steps *********************************************************************/ | ||
| 26 | |||
| 27 | Step | ||
| 28 | eofb_HTM = { | ||
| 29 | .check = check_eofb_HTM, | ||
| 30 | .ready = check_nothing, | ||
| 31 | .moveset = moveset_HTM | ||
| 32 | }; | ||
| 33 | |||
| 34 | Step | ||
| 35 | coud_HTM = { | ||
| 36 | .check = check_coud_HTM, | ||
| 37 | .ready = check_nothing, | ||
| 38 | .moveset = moveset_HTM | ||
| 39 | }; | ||
| 40 | |||
| 41 | Step | ||
| 42 | coud_URF = { | ||
| 43 | .check = check_coud_URF, | ||
| 44 | .ready = check_nothing, | ||
| 45 | .moveset = moveset_URF | ||
| 46 | }; | ||
| 47 | |||
| 48 | Step | ||
| 49 | corners_HTM = { | ||
| 50 | .check = check_corners_HTM, | ||
| 51 | .ready = check_nothing, | ||
| 52 | .moveset = moveset_HTM | ||
| 53 | }; | ||
| 54 | |||
| 55 | Step | ||
| 56 | corners_URF = { | ||
| 57 | .check = check_corners_URF, | ||
| 58 | .ready = check_nothing, | ||
| 59 | .moveset = moveset_URF | ||
| 60 | }; | ||
| 61 | |||
| 62 | Step | ||
| 63 | edges_HTM = { | ||
| 64 | .check = check_edges_HTM, | ||
| 65 | .ready = check_nothing, | ||
| 66 | .moveset = moveset_HTM | ||
| 67 | }; | ||
| 68 | |||
| 69 | Step | ||
| 70 | drud_HTM = { | ||
| 71 | .check = check_drud_HTM, | ||
| 72 | .ready = check_nothing, | ||
| 73 | .moveset = moveset_HTM | ||
| 74 | }; | ||
| 75 | |||
| 76 | Step | ||
| 77 | optimal_HTM = { | ||
| 78 | .check = check_optimal_HTM, | ||
| 79 | .ready = check_nothing, | ||
| 80 | .moveset = moveset_HTM, | ||
| 81 | .cd = &cd_optimal_HTM_6 | ||
| 82 | }; | ||
| 83 | |||
| 84 | |||
| 85 | /* Cache solutions ***********************************************************/ | ||
| 86 | |||
| 87 | CacheData | ||
| 88 | cd_optimal_HTM_6 = { | ||
| 89 | .filename = "cd_optimal_HTM_6", | ||
| 90 | .maxind0 = POW3TO7 * FACTORIAL8, | ||
| 91 | .len = 6, | ||
| 92 | .nind = 3, | ||
| 93 | .index = { index_corners, index_eofb, index_ep }, | ||
| 94 | .moveset = moveset_HTM | ||
| 95 | }; | ||
| 96 | |||
| 97 | |||
| 98 | /* Pruning tables ************************************************************/ | ||
| 99 | |||
| 100 | PruneData | ||
| 101 | pd_eofb_HTM = { | ||
| 102 | .filename = "ptable_eofb_HTM", | ||
| 103 | .size = POW2TO11, | ||
| 104 | .index = index_eofb, | ||
| 105 | .moveset = moveset_HTM | ||
| 106 | }; | ||
| 107 | |||
| 108 | PruneData | ||
| 109 | pd_coud_HTM = { | ||
| 110 | .filename = "ptable_coud_HTM", | ||
| 111 | .size = POW3TO7, | ||
| 112 | .index = index_coud, | ||
| 113 | .moveset = moveset_HTM | ||
| 114 | }; | ||
| 115 | |||
| 116 | PruneData | ||
| 117 | pd_corners_HTM = { | ||
| 118 | .filename = "ptable_corners_HTM", | ||
| 119 | .size = POW3TO7 * FACTORIAL8, | ||
| 120 | .index = index_corners, | ||
| 121 | .moveset = moveset_HTM | ||
| 122 | }; | ||
| 123 | |||
| 124 | PruneData | ||
| 125 | pd_ep_HTM = { | ||
| 126 | .filename = "ptable_ep_HTM", | ||
| 127 | .size = FACTORIAL12, | ||
| 128 | .index = index_ep, | ||
| 129 | .moveset = moveset_HTM | ||
| 130 | }; | ||
| 131 | |||
| 132 | PruneData | ||
| 133 | pd_drud_HTM = { | ||
| 134 | .filename = "ptable_drud_HTM", | ||
| 135 | .size = POW2TO11 * POW3TO7 * BINOM12ON4, | ||
| 136 | .index = index_drud, | ||
| 137 | .moveset = moveset_HTM | ||
| 138 | }; | ||
| 139 | |||
| 140 | |||
| 141 | /* Check functions implementation ********************************************/ | ||
| 142 | |||
| 143 | static int | ||
| 144 | check_nothing(Cube cube) | ||
| 145 | { | ||
| 146 | /* At least we check that it is admissible */ | ||
| 147 | return is_admissible(cube); | ||
| 148 | } | ||
| 149 | |||
| 150 | static int | ||
| 151 | check_eofb_HTM(Cube cube) | ||
| 152 | { | ||
| 153 | if (!pd_eofb_HTM.generated) | ||
| 154 | generate_ptable(&pd_eofb_HTM); | ||
| 155 | |||
| 156 | return PTABLEVAL(pd_eofb_HTM.ptable, cube.eofb); | ||
| 157 | } | ||
| 158 | |||
| 159 | static int | ||
| 160 | check_coud_HTM(Cube cube) | ||
| 161 | { | ||
| 162 | if (!pd_coud_HTM.generated) | ||
| 163 | generate_ptable(&pd_coud_HTM); | ||
| 164 | |||
| 165 | return PTABLEVAL(pd_coud_HTM.ptable, cube.coud); | ||
| 166 | } | ||
| 167 | |||
| 168 | static int | ||
| 169 | check_coud_URF(Cube cube) | ||
| 170 | { | ||
| 171 | /* TODO: I can improve this by checking first the orientation of | ||
| 172 | * the corner in DBL and use that as a reference */ | ||
| 173 | |||
| 174 | int ud = check_coud_HTM(cube); | ||
| 175 | int rl = check_coud_HTM(apply_move(z, cube)); | ||
| 176 | int fb = check_coud_HTM(apply_move(x, cube)); | ||
| 177 | |||
| 178 | return MIN(ud, MIN(rl, fb)); | ||
| 179 | } | ||
| 180 | |||
| 181 | static int | ||
| 182 | check_corners_HTM(Cube cube) | ||
| 183 | { | ||
| 184 | if (!pd_corners_HTM.generated) | ||
| 185 | generate_ptable(&pd_corners_HTM); | ||
| 186 | |||
| 187 | return PTABLEVAL(pd_corners_HTM.ptable, index_corners(cube)); | ||
| 188 | } | ||
| 189 | |||
| 190 | static int | ||
| 191 | check_corners_URF(Cube cube) | ||
| 192 | { | ||
| 193 | /* TODO: I can improve this by checking first the corner in DBL | ||
| 194 | * and use that as a reference */ | ||
| 195 | |||
| 196 | int ret = 15; | ||
| 197 | Trans i; | ||
| 198 | |||
| 199 | for (i = 0; i < NROTATIONS; i++) | ||
| 200 | ret = MIN(ret,check_corners_HTM(apply_alg(trans_alg(i),cube))); | ||
| 201 | |||
| 202 | return ret; | ||
| 203 | } | ||
| 204 | |||
| 205 | static int | ||
| 206 | check_edges_HTM(Cube cube) | ||
| 207 | { | ||
| 208 | int ret = 0; | ||
| 209 | |||
| 210 | if (!pd_ep_HTM.generated) | ||
| 211 | generate_ptable(&pd_ep_HTM); | ||
| 212 | |||
| 213 | ret = MAX(ret, PTABLEVAL(pd_ep_HTM.ptable, index_ep(cube))); | ||
| 214 | ret = MAX(ret, check_eofb_HTM(cube)); | ||
| 215 | ret = MAX(ret, check_eofb_HTM(apply_trans(ur, cube))); | ||
| 216 | ret = MAX(ret, check_eofb_HTM(apply_trans(fd, cube))); | ||
| 217 | |||
| 218 | return ret; | ||
| 219 | } | ||
| 220 | |||
| 221 | static int | ||
| 222 | check_drud_HTM(Cube cube) | ||
| 223 | { | ||
| 224 | if (!pd_drud_HTM.generated) | ||
| 225 | generate_ptable(&pd_drud_HTM); | ||
| 226 | |||
| 227 | return PTABLEVAL(pd_drud_HTM.ptable, index_drud(cube)); | ||
| 228 | } | ||
| 229 | |||
| 230 | static int | ||
| 231 | check_optimal_HTM(Cube cube) | ||
| 232 | { | ||
| 233 | int dr1, dr2, dr3, drmax, cor; /*ep;*/ | ||
| 234 | |||
| 235 | if (!pd_drud_HTM.generated) | ||
| 236 | generate_ptable(&pd_drud_HTM); | ||
| 237 | if (!pd_corners_HTM.generated) | ||
| 238 | generate_ptable(&pd_corners_HTM); | ||
| 239 | /* | ||
| 240 | *if (!pd_ep_HTM.generated) | ||
| 241 | * generate_ptable(&pd_ep_HTM); | ||
| 242 | */ | ||
| 243 | |||
| 244 | dr1 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(cube)); | ||
| 245 | dr2 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(apply_trans(rf, cube))); | ||
| 246 | dr3 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(apply_trans(fd, cube))); | ||
| 247 | |||
| 248 | drmax = MAX(dr1, MAX(dr2, dr3)); | ||
| 249 | if (dr1 == dr2 && dr2 == dr3 && dr1 != 0) | ||
| 250 | drmax++; | ||
| 251 | |||
| 252 | cor = PTABLEVAL(pd_corners_HTM.ptable, index_corners(cube)); | ||
| 253 | /* ep = PTABLEVAL(pd_ep_HTM.ptable, index_ep(cube)); */ | ||
| 254 | |||
| 255 | /*return MAX(drmax, MAX(ep, cor));*/ | ||
| 256 | if (drmax == 0 && cor == 0) | ||
| 257 | return is_solved(cube, false) ? 0 : 1; | ||
| 258 | return MAX(drmax, cor); | ||
| 259 | } | ||
| 260 | |||
| 261 | |||
| 262 | /* Index functions implementation ********************************************/ | ||
| 263 | |||
| 264 | static uint64_t | ||
| 265 | index_eofb(Cube cube) | ||
| 266 | { | ||
| 267 | return cube.eofb; | ||
| 268 | } | ||
| 269 | |||
| 270 | static uint64_t | ||
| 271 | index_coud(Cube cube) | ||
| 272 | { | ||
| 273 | return cube.coud; | ||
| 274 | } | ||
| 275 | |||
| 276 | static uint64_t | ||
| 277 | index_corners(Cube cube) | ||
| 278 | { | ||
| 279 | return cube.coud * FACTORIAL8 + cube.cp; | ||
| 280 | } | ||
| 281 | |||
| 282 | static uint64_t | ||
| 283 | index_ep(Cube cube) | ||
| 284 | { | ||
| 285 | uint64_t a, b, c; | ||
| 286 | |||
| 287 | a = cube.eposs; | ||
| 288 | b = (cube.epose % FACTORIAL4) + epos_dependent_cube(cube)*FACTORIAL4; | ||
| 289 | c = cube.eposm % FACTORIAL4; | ||
| 290 | |||
| 291 | b *= FACTORIAL4 * BINOM12ON4; | ||
| 292 | c *= FACTORIAL4 * BINOM12ON4 * FACTORIAL4 * BINOM8ON4; | ||
| 293 | |||
| 294 | return a + b + c; | ||
| 295 | } | ||
| 296 | |||
| 297 | static uint64_t | ||
| 298 | index_drud(Cube cube) | ||
| 299 | { | ||
| 300 | uint64_t a, b, c; | ||
| 301 | |||
| 302 | a = cube.eofb; | ||
| 303 | b = cube.coud; | ||
| 304 | c = cube.epose / FACTORIAL4; | ||
| 305 | |||
| 306 | b *= POW2TO11; | ||
| 307 | c *= POW2TO11 * POW3TO7; | ||
| 308 | |||
| 309 | return a + b + c; | ||
| 310 | } | ||
| 311 | |||
| 312 | /* Movesets ******************************************************************/ | ||
| 313 | |||
| 314 | bool | ||
| 315 | moveset_HTM(Move m) | ||
| 316 | { | ||
| 317 | return m >= U && m <= B3; | ||
| 318 | } | ||
| 319 | |||
| 320 | bool | ||
| 321 | moveset_URF(Move m) | ||
| 322 | { | ||
| 323 | Move b = base_move(m); | ||
| 324 | |||
| 325 | return b == U || b == R || b == F; | ||
| 326 | } | ||
| 327 | |||
