diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 15:36:02 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 15:36:02 +0100 |
| commit | 48cd8b6b1779f34ba0507cb697492de83c4e9da8 (patch) | |
| tree | c3a208fa64c3d37f328984acfb980b3f88e94060 | |
| parent | de0352a2926b0708400a9629c1da813455a6f442 (diff) | |
| download | nissy-48cd8b6b1779f34ba0507cb697492de83c4e9da8.tar.gz nissy-48cd8b6b1779f34ba0507cb697492de83c4e9da8.zip | |
Moved random_cube() from cube.c to commands.c and fixed a bug in corners only and edges
only scrambles. Added fmc scrambles (with R'U'F). Updated manpage for scramble and cleanup.
| -rw-r--r-- | TODO.md | 3 | ||||
| -rw-r--r-- | doc/nissy.1 | 16 | ||||
| -rw-r--r-- | src/commands.c | 71 | ||||
| -rw-r--r-- | src/commands.h | 2 | ||||
| -rw-r--r-- | src/cube.c | 28 | ||||
| -rw-r--r-- | src/cube.h | 7 | ||||
| -rw-r--r-- | src/cubetypes.h | 2 |
7 files changed, 81 insertions, 48 deletions
| @@ -6,7 +6,6 @@ It's more of a personal reminder than anything else. | |||
| 6 | ## For version 2.1 | 6 | ## For version 2.1 |
| 7 | ### Scrambles | 7 | ### Scrambles |
| 8 | * dr and htr scrambles | 8 | * dr and htr scrambles |
| 9 | * rufify | ||
| 10 | ### Memory management | 9 | ### Memory management |
| 11 | * Free large tables from memory before exit (this is not strictly necessary, | 10 | * Free large tables from memory before exit (this is not strictly necessary, |
| 12 | but can help with WSL bugs) | 11 | but can help with WSL bugs) |
| @@ -37,7 +36,6 @@ including e.g. solutions that were not shown because -c) | |||
| 37 | 36 | ||
| 38 | ### Improvements to currently implemented commands | 37 | ### Improvements to currently implemented commands |
| 39 | * solve should re-orient first if needed and not just give up if centers are off | 38 | * solve should re-orient first if needed and not just give up if centers are off |
| 40 | * more scramble types (dr, htr, fmc(rufify)...) | ||
| 41 | * solve should try up to a small bound without loading the large pruning table | 39 | * solve should try up to a small bound without loading the large pruning table |
| 42 | * silent batch mode without >>> | 40 | * silent batch mode without >>> |
| 43 | 41 | ||
| @@ -88,6 +86,7 @@ including e.g. solutions that were not shown because -c) | |||
| 88 | 86 | ||
| 89 | ### Cleanup | 87 | ### Cleanup |
| 90 | * Remove khuge from everywhere | 88 | * Remove khuge from everywhere |
| 89 | * Arrays (commands, steps...): end with NULL and remove size constant | ||
| 91 | * sort again functions alphabetically in their files | 90 | * sort again functions alphabetically in their files |
| 92 | * more stuff to load at start (or when suitable command is called) rather | 91 | * more stuff to load at start (or when suitable command is called) rather |
| 93 | than when called directly, to avoid nasty problems with threading | 92 | than when called directly, to avoid nasty problems with threading |
diff --git a/doc/nissy.1 b/doc/nissy.1 index 4a07c29..25c6ef2 100644 --- a/doc/nissy.1 +++ b/doc/nissy.1 | |||
| @@ -43,6 +43,13 @@ are the following: | |||
| 43 | . | 43 | . |
| 44 | .Bl -tag -width Ds | 44 | .Bl -tag -width Ds |
| 45 | . | 45 | . |
| 46 | .It Nm cleanup Ar scramble | ||
| 47 | Rewrites the given scramble using only the 18 base (HTM) moves and at most two | ||
| 48 | rotations at the end. If | ||
| 49 | Ar scramble | ||
| 50 | uses NISS, all moves done on normal scramble are written first, followed by | ||
| 51 | all moves done on inverse. | ||
| 52 | . | ||
| 46 | .It Nm commands | 53 | .It Nm commands |
| 47 | List all available commands. | 54 | List all available commands. |
| 48 | . | 55 | . |
| @@ -83,15 +90,18 @@ scrambles. | |||
| 83 | .Ar type | 90 | .Ar type |
| 84 | can be specified to be one of the following: | 91 | can be specified to be one of the following: |
| 85 | .Bl -tag -width Ds | 92 | .Bl -tag -width Ds |
| 86 | .It Ar eo | ||
| 87 | Scramble with solved EO on F/B axis. | ||
| 88 | .It Ar corners | 93 | .It Ar corners |
| 89 | Scramble with solved edges (only cornes are scrambled). | 94 | Scramble with solved edges (only cornes are scrambled). |
| 90 | .It Ar edges | 95 | .It Ar edges |
| 91 | Scramble with solved corners (only edges are scrambled). | 96 | Scramble with solved corners (only edges are scrambled). |
| 97 | .It Ar eo | ||
| 98 | Scramble with solved EO on F/B axis. | ||
| 99 | .It Ar fmc | ||
| 100 | Scramble the full cube and the resulting scramble starts and ends with | ||
| 101 | the moves R\(aq U\(aq F. | ||
| 92 | .El | 102 | .El |
| 93 | . | 103 | . |
| 94 | .It Nm solve Ar step Oo Ar options Oc Ar scramble. | 104 | .It Nm solve Ar step Oo Ar options Oc Ar scramble |
| 95 | Solve the given | 105 | Solve the given |
| 96 | .Ar step | 106 | .Ar step |
| 97 | on the given | 107 | on the given |
diff --git a/src/commands.c b/src/commands.c index 8666278..b397878 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -166,6 +166,10 @@ Command *commands[NCOMMANDS] = { | |||
| 166 | &version_cmd, | 166 | &version_cmd, |
| 167 | }; | 167 | }; |
| 168 | 168 | ||
| 169 | /* Other constants ***********************************************************/ | ||
| 170 | |||
| 171 | char *scrtypes[20] = { "eo", "corners", "edges", "fmc", NULL }; | ||
| 172 | |||
| 169 | /* Arg parsing functions implementation **************************************/ | 173 | /* Arg parsing functions implementation **************************************/ |
| 170 | 174 | ||
| 171 | CommandArgs * | 175 | CommandArgs * |
| @@ -277,7 +281,6 @@ scramble_parse_args(int c, char **v) | |||
| 277 | 281 | ||
| 278 | a->success = true; | 282 | a->success = true; |
| 279 | a->n = 1; | 283 | a->n = 1; |
| 280 | a->scrt = -1; | ||
| 281 | 284 | ||
| 282 | for (i = 0; i < c; i++) { | 285 | for (i = 0; i < c; i++) { |
| 283 | if (!strcmp(v[i], "-n") && i+1 < c) { | 286 | if (!strcmp(v[i], "-n") && i+1 < c) { |
| @@ -396,8 +399,8 @@ static void | |||
| 396 | scramble_exec(CommandArgs *args) | 399 | scramble_exec(CommandArgs *args) |
| 397 | { | 400 | { |
| 398 | Cube cube; | 401 | Cube cube; |
| 399 | Alg *scr; | 402 | Alg *scr, *ruf, *aux; |
| 400 | int i; | 403 | int i, j, eo, ep, co, cp, a[12]; |
| 401 | 404 | ||
| 402 | init_all_movesets(); | 405 | init_all_movesets(); |
| 403 | init_symcoord(); | 406 | init_symcoord(); |
| @@ -405,8 +408,56 @@ scramble_exec(CommandArgs *args) | |||
| 405 | srand(time(NULL)); | 408 | srand(time(NULL)); |
| 406 | 409 | ||
| 407 | for (i = 0; i < args->n; i++) { | 410 | for (i = 0; i < args->n; i++) { |
| 408 | cube = random_cube(args->scrt); | 411 | eo = rand() % POW2TO11; |
| 412 | ep = rand() % FACTORIAL12; | ||
| 413 | co = rand() % POW3TO7; | ||
| 414 | cp = rand() % FACTORIAL8; | ||
| 415 | |||
| 416 | if (!strcmp(args->scrtype, "eo")) { | ||
| 417 | eo = 0; | ||
| 418 | } else if (!strcmp(args->scrtype, "corners")) { | ||
| 419 | eo = 0; | ||
| 420 | ep = 0; | ||
| 421 | index_to_perm(cp, 8, a); | ||
| 422 | if (perm_sign(a, 8) == 1) { | ||
| 423 | swap(&a[0], &a[1]); | ||
| 424 | cp = perm_to_index(a, 8); | ||
| 425 | } | ||
| 426 | } else if (!strcmp(args->scrtype, "edges")) { | ||
| 427 | co = 0; | ||
| 428 | cp = 0; | ||
| 429 | index_to_perm(ep, 12, a); | ||
| 430 | if (perm_sign(a, 12) == 1) { | ||
| 431 | swap(&a[0], &a[1]); | ||
| 432 | ep = perm_to_index(a, 12); | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | cube = fourval_to_cube(eo, ep, co, cp); | ||
| 409 | scr = solve_2phase(cube, 1); | 437 | scr = solve_2phase(cube, 1); |
| 438 | |||
| 439 | if (!strcmp(args->scrtype, "fmc")) { | ||
| 440 | aux = new_alg(""); | ||
| 441 | copy_alg(scr, aux); | ||
| 442 | /* Trick to rufify for free: rotate the scramble * | ||
| 443 | * so that it does not start with F or end with R */ | ||
| 444 | for (j = 0; j < NROTATIONS; j++) { | ||
| 445 | if (base_move(scr->move[0]) != F && | ||
| 446 | base_move(scr->move[0]) != B && | ||
| 447 | base_move(scr->move[scr->len-1]) != R && | ||
| 448 | base_move(scr->move[scr->len-1]) != L) | ||
| 449 | break; | ||
| 450 | copy_alg(aux, scr); | ||
| 451 | transform_alg(j, scr); | ||
| 452 | } | ||
| 453 | copy_alg(scr, aux); | ||
| 454 | ruf = new_alg("R' U' F"); | ||
| 455 | copy_alg(ruf, scr); | ||
| 456 | compose_alg(scr, aux); | ||
| 457 | compose_alg(scr, ruf); | ||
| 458 | free_alg(aux); | ||
| 459 | free_alg(ruf); | ||
| 460 | } | ||
| 410 | print_alg(scr, false); | 461 | print_alg(scr, false); |
| 411 | free_alg(scr); | 462 | free_alg(scr); |
| 412 | } | 463 | } |
| @@ -576,12 +627,14 @@ read_scrtype(CommandArgs *args, char *str) | |||
| 576 | { | 627 | { |
| 577 | int i; | 628 | int i; |
| 578 | 629 | ||
| 579 | args->scrt = -1; | 630 | for (i = 0; scrtypes[i] != NULL; i++) { |
| 580 | for (i = 0; i < NSCRTYPES; i++) | 631 | if (!strcmp(scrtypes[i], str)) { |
| 581 | if (!strcmp(scrtypes[i], str)) | 632 | strcpy(args->scrtype, scrtypes[i]); |
| 582 | args->scrt = i; | 633 | return true; |
| 634 | } | ||
| 635 | } | ||
| 583 | 636 | ||
| 584 | return args->scrt != -1; | 637 | return false; |
| 585 | } | 638 | } |
| 586 | 639 | ||
| 587 | static bool | 640 | static bool |
diff --git a/src/commands.h b/src/commands.h index 7773827..bac71f1 100644 --- a/src/commands.h +++ b/src/commands.h | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | #ifndef COMMANDS_H | 1 | #ifndef COMMANDS_H |
| 2 | #define COMMANDS_H | 2 | #define COMMANDS_H |
| 3 | 3 | ||
| 4 | #include <time.h> | ||
| 5 | |||
| 4 | #include "solve.h" | 6 | #include "solve.h" |
| 5 | #include "steps.h" | 7 | #include "steps.h" |
| 6 | 8 | ||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | static void fix_eorleoud(CubeArray *arr); | 5 | static void fix_eorleoud(CubeArray *arr); |
| 6 | static void fix_cofbcorl(CubeArray *arr); | 6 | static void fix_cofbcorl(CubeArray *arr); |
| 7 | static Cube fourval_to_cube(int eofb, int ep, int coud, int cp); | ||
| 8 | static void init_inverse(); | 7 | static void init_inverse(); |
| 9 | static bool read_invtables_file(); | 8 | static bool read_invtables_file(); |
| 10 | static bool write_invtables_file(); | 9 | static bool write_invtables_file(); |
| @@ -18,8 +17,6 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8]; | |||
| 18 | static uint16_t cp_invtable[FACTORIAL8]; | 17 | static uint16_t cp_invtable[FACTORIAL8]; |
| 19 | static uint16_t cpos_invtable[FACTORIAL6]; | 18 | static uint16_t cpos_invtable[FACTORIAL6]; |
| 20 | 19 | ||
| 21 | char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" }; | ||
| 22 | |||
| 23 | /* Functions implementation **************************************************/ | 20 | /* Functions implementation **************************************************/ |
| 24 | 21 | ||
| 25 | int | 22 | int |
| @@ -187,7 +184,7 @@ fix_cofbcorl(CubeArray *arr) | |||
| 187 | } | 184 | } |
| 188 | } | 185 | } |
| 189 | 186 | ||
| 190 | static Cube | 187 | Cube |
| 191 | fourval_to_cube(int eofb, int ep, int coud, int cp) | 188 | fourval_to_cube(int eofb, int ep, int coud, int cp) |
| 192 | { | 189 | { |
| 193 | CubeArray *arr; | 190 | CubeArray *arr; |
| @@ -544,29 +541,6 @@ print_cube(Cube cube) | |||
| 544 | printf("\n"); | 541 | printf("\n"); |
| 545 | } | 542 | } |
| 546 | 543 | ||
| 547 | Cube | ||
| 548 | random_cube(int scrt) | ||
| 549 | { | ||
| 550 | int ep, cp, eo, co; | ||
| 551 | |||
| 552 | ep = rand() % FACTORIAL12; | ||
| 553 | cp = rand() % FACTORIAL8; | ||
| 554 | eo = rand() % POW2TO11; | ||
| 555 | co = rand() % POW3TO7; | ||
| 556 | |||
| 557 | if (scrt == 0) { /* EO */ | ||
| 558 | eo = 0; | ||
| 559 | } else if (scrt == 1) { /* corners */ | ||
| 560 | eo = 0; | ||
| 561 | ep = 0; | ||
| 562 | } else if (scrt == 2) { /* edges */ | ||
| 563 | co = 0; | ||
| 564 | cp = 0; | ||
| 565 | } | ||
| 566 | |||
| 567 | return fourval_to_cube(eo, ep, co, cp); | ||
| 568 | } | ||
| 569 | |||
| 570 | Center | 544 | Center |
| 571 | what_center_at(Cube cube, Center c) | 545 | what_center_at(Cube cube, Center c) |
| 572 | { | 546 | { |
| @@ -2,16 +2,11 @@ | |||
| 2 | #define CUBE_H | 2 | #define CUBE_H |
| 3 | 3 | ||
| 4 | #include <stdio.h> | 4 | #include <stdio.h> |
| 5 | #include <time.h> | ||
| 6 | 5 | ||
| 7 | #include "env.h" | 6 | #include "env.h" |
| 8 | #include "pf.h" | 7 | #include "pf.h" |
| 9 | #include "utils.h" | 8 | #include "utils.h" |
| 10 | 9 | ||
| 11 | #define NSCRTYPES 3 | ||
| 12 | |||
| 13 | extern char *scrtypes[NSCRTYPES]; | ||
| 14 | |||
| 15 | Cube admissible_ep(Cube cube, PieceFilter f); | 10 | Cube admissible_ep(Cube cube, PieceFilter f); |
| 16 | int array_ep_to_epos(int *ep, int *eps_solved); | 11 | int array_ep_to_epos(int *ep, int *eps_solved); |
| 17 | Cube arrays_to_cube(CubeArray *arr, PieceFilter f); | 12 | Cube arrays_to_cube(CubeArray *arr, PieceFilter f); |
| @@ -28,11 +23,11 @@ bool is_solved_center(Cube cube, Center c); | |||
| 28 | bool is_solved_corner(Cube cube, Corner c); | 23 | bool is_solved_corner(Cube cube, Corner c); |
| 29 | bool is_solved_edge(Cube cube, Edge e); | 24 | bool is_solved_edge(Cube cube, Edge e); |
| 30 | void epos_to_partial_ep(int epos, int *ep, int *ss); | 25 | void epos_to_partial_ep(int epos, int *ep, int *ss); |
| 26 | Cube fourval_to_cube(int eofb, int ep, int coud, int cp); | ||
| 31 | void free_cubearray(CubeArray *arr, PieceFilter f); | 27 | void free_cubearray(CubeArray *arr, PieceFilter f); |
| 32 | Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf); | 28 | Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf); |
| 33 | CubeArray * new_cubearray(Cube cube, PieceFilter f); | 29 | CubeArray * new_cubearray(Cube cube, PieceFilter f); |
| 34 | void print_cube(Cube cube); | 30 | void print_cube(Cube cube); |
| 35 | Cube random_cube(int scrt); | ||
| 36 | Center what_center_at(Cube cube, Center c); | 31 | Center what_center_at(Cube cube, Center c); |
| 37 | Corner what_corner_at(Cube cube, Corner c); | 32 | Corner what_corner_at(Cube cube, Corner c); |
| 38 | Edge what_edge_at(Cube cube, Edge e); | 33 | Edge what_edge_at(Cube cube, Edge e); |
diff --git a/src/cubetypes.h b/src/cubetypes.h index 8ba1341..14e490a 100644 --- a/src/cubetypes.h +++ b/src/cubetypes.h | |||
| @@ -157,7 +157,7 @@ commandargs | |||
| 157 | Step * step; | 157 | Step * step; |
| 158 | Command * command; /* For help */ | 158 | Command * command; /* For help */ |
| 159 | int n; | 159 | int n; |
| 160 | int scrt; | 160 | char scrtype[20]; |
| 161 | bool scrstdin; | 161 | bool scrstdin; |
| 162 | bool header; | 162 | bool header; |
| 163 | }; | 163 | }; |
