diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-25 17:20:30 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-25 17:20:30 +0100 |
| commit | 06c3b9610b7694db34ee91312d8f3aa2196d7d62 (patch) | |
| tree | 8fe16806bdf9729de8f125ce12100ad58b431a2a /src/moves.c | |
| parent | 1485cc87c248e1f56367774ebd4819a97116abcc (diff) | |
| download | nissy-06c3b9610b7694db34ee91312d8f3aa2196d7d62.tar.gz nissy-06c3b9610b7694db34ee91312d8f3aa2196d7d62.zip | |
Added cleanup command
Diffstat (limited to '')
| -rw-r--r-- | src/moves.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/moves.c b/src/moves.c index 9547de9..7c33db4 100644 --- a/src/moves.c +++ b/src/moves.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | /* Local functions ***********************************************************/ | 3 | /* Local functions ***********************************************************/ |
| 4 | 4 | ||
| 5 | static Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f); | 5 | static Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f); |
| 6 | static void cleanup_aux(Alg *alg, Alg *ret, bool inv); | ||
| 6 | static bool read_mtables_file(); | 7 | static bool read_mtables_file(); |
| 7 | static bool write_mtables_file(); | 8 | static bool write_mtables_file(); |
| 8 | 9 | ||
| @@ -221,6 +222,125 @@ apply_move(Move m, Cube cube) | |||
| 221 | }; | 222 | }; |
| 222 | } | 223 | } |
| 223 | 224 | ||
| 225 | Alg * | ||
| 226 | cleanup(Alg *alg) | ||
| 227 | { | ||
| 228 | int i, j, k, b[2], n, L; | ||
| 229 | Move bb, m; | ||
| 230 | Alg *ret; | ||
| 231 | |||
| 232 | ret = new_alg(""); | ||
| 233 | cleanup_aux(alg, ret, false); | ||
| 234 | cleanup_aux(alg, ret, true); | ||
| 235 | |||
| 236 | do { | ||
| 237 | for (i = 0, j = 0, n = 0; i < ret->len; i = j) { | ||
| 238 | if (ret->move[i] > B3) { | ||
| 239 | ret->move[n] = ret->move[i]; | ||
| 240 | ret->inv[n] = ret->inv[i]; | ||
| 241 | n++; | ||
| 242 | j++; | ||
| 243 | continue; | ||
| 244 | } | ||
| 245 | |||
| 246 | bb = 1 + ((base_move(ret->move[i]) - 1)/6)*6; | ||
| 247 | while (j < ret->len && | ||
| 248 | ret->move[j] <= B3 && | ||
| 249 | ret->inv[j] == ret->inv[i] && | ||
| 250 | 1 + ((base_move(ret->move[j]) - 1)/6)*6 == bb) | ||
| 251 | j++; | ||
| 252 | |||
| 253 | for (k = i, b[0] = 0, b[1] = 0; k < j; k++) { | ||
| 254 | m = ret->move[k]; | ||
| 255 | if (base_move(m) == bb) | ||
| 256 | b[0] = (b[0]+1+m-base_move(m)) % 4; | ||
| 257 | else | ||
| 258 | b[1] = (b[1]+1+m-base_move(m)) % 4; | ||
| 259 | } | ||
| 260 | |||
| 261 | for (k = 0; k < 2; k++) { | ||
| 262 | if (b[k] != 0) { | ||
| 263 | ret->move[n] = bb + b[k] - 1 + 3*k; | ||
| 264 | ret->inv[n] = ret->inv[i]; | ||
| 265 | n++; | ||
| 266 | } | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | L = ret->len; | ||
| 271 | ret->len = n; | ||
| 272 | } while (L != n); | ||
| 273 | |||
| 274 | return ret; | ||
| 275 | } | ||
| 276 | |||
| 277 | static void | ||
| 278 | cleanup_aux(Alg *alg, Alg *ret, bool inv) | ||
| 279 | { | ||
| 280 | int i, j; | ||
| 281 | Cube c, d; | ||
| 282 | Move m, mm; | ||
| 283 | Alg *equiv_alg; | ||
| 284 | |||
| 285 | c = (Cube){0}; | ||
| 286 | for (i = 0; i < alg->len; i++) { | ||
| 287 | if (alg->inv[i] != inv) | ||
| 288 | continue; | ||
| 289 | |||
| 290 | equiv_alg = new_alg(equiv_alg_string[alg->move[i]]); | ||
| 291 | |||
| 292 | for (j = 0; j < equiv_alg->len; j++) { | ||
| 293 | m = equiv_alg->move[j]; | ||
| 294 | if (m == U) { | ||
| 295 | mm = 3*what_center_at(c, U_center) + 1; | ||
| 296 | append_move(ret, mm, inv); | ||
| 297 | } else { | ||
| 298 | c = apply_move(m, c); | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | free_alg(equiv_alg); | ||
| 303 | } | ||
| 304 | |||
| 305 | m = NULLMOVE; | ||
| 306 | switch (what_center_at(c, F_center)) { | ||
| 307 | case U_center: | ||
| 308 | m = x3; | ||
| 309 | break; | ||
| 310 | case D_center: | ||
| 311 | m = x; | ||
| 312 | break; | ||
| 313 | case R_center: | ||
| 314 | m = y; | ||
| 315 | break; | ||
| 316 | case L_center: | ||
| 317 | m = y3; | ||
| 318 | break; | ||
| 319 | case B_center: | ||
| 320 | if (what_center_at(c, U_center) == U_center) | ||
| 321 | m = y2; | ||
| 322 | else | ||
| 323 | m = x2; | ||
| 324 | break; | ||
| 325 | default: | ||
| 326 | break; | ||
| 327 | } | ||
| 328 | d = apply_move(m, (Cube){0}); | ||
| 329 | if (m != NULLMOVE) | ||
| 330 | append_move(ret, m, inv); | ||
| 331 | |||
| 332 | m = NULLMOVE; | ||
| 333 | if (what_center_at(c, U_center) == what_center_at(d, D_center)) { | ||
| 334 | m = z2; | ||
| 335 | } else if (what_center_at(c, U_center) == what_center_at(d, R_center)) { | ||
| 336 | m = z3; | ||
| 337 | } else if (what_center_at(c, U_center) == what_center_at(d, L_center)) { | ||
| 338 | m = z; | ||
| 339 | } | ||
| 340 | if (m != NULLMOVE) | ||
| 341 | append_move(ret, m, inv); | ||
| 342 | } | ||
| 343 | |||
| 224 | static bool | 344 | static bool |
| 225 | read_mtables_file() | 345 | read_mtables_file() |
| 226 | { | 346 | { |
