aboutsummaryrefslogtreecommitdiff
path: root/src/commands.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2022-02-27 15:36:02 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2022-02-27 15:36:02 +0100
commit48cd8b6b1779f34ba0507cb697492de83c4e9da8 (patch)
treec3a208fa64c3d37f328984acfb980b3f88e94060 /src/commands.c
parentde0352a2926b0708400a9629c1da813455a6f442 (diff)
downloadnissy-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.
Diffstat (limited to '')
-rw-r--r--src/commands.c71
1 files changed, 62 insertions, 9 deletions
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
171char *scrtypes[20] = { "eo", "corners", "edges", "fmc", NULL };
172
169/* Arg parsing functions implementation **************************************/ 173/* Arg parsing functions implementation **************************************/
170 174
171CommandArgs * 175CommandArgs *
@@ -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
396scramble_exec(CommandArgs *args) 399scramble_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
587static bool 640static bool

Generated with cgit - Back to sebastiano.tronto.net