aboutsummaryrefslogtreecommitdiff
path: root/src
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
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 'src')
-rw-r--r--src/commands.c71
-rw-r--r--src/commands.h2
-rw-r--r--src/cube.c28
-rw-r--r--src/cube.h7
-rw-r--r--src/cubetypes.h2
5 files changed, 67 insertions, 43 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
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
diff --git a/src/cube.c b/src/cube.c
index 3a6234d..803fefd 100644
--- a/src/cube.c
+++ b/src/cube.c
@@ -4,7 +4,6 @@
4 4
5static void fix_eorleoud(CubeArray *arr); 5static void fix_eorleoud(CubeArray *arr);
6static void fix_cofbcorl(CubeArray *arr); 6static void fix_cofbcorl(CubeArray *arr);
7static Cube fourval_to_cube(int eofb, int ep, int coud, int cp);
8static void init_inverse(); 7static void init_inverse();
9static bool read_invtables_file(); 8static bool read_invtables_file();
10static bool write_invtables_file(); 9static bool write_invtables_file();
@@ -18,8 +17,6 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8];
18static uint16_t cp_invtable[FACTORIAL8]; 17static uint16_t cp_invtable[FACTORIAL8];
19static uint16_t cpos_invtable[FACTORIAL6]; 18static uint16_t cpos_invtable[FACTORIAL6];
20 19
21char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" };
22
23/* Functions implementation **************************************************/ 20/* Functions implementation **************************************************/
24 21
25int 22int
@@ -187,7 +184,7 @@ fix_cofbcorl(CubeArray *arr)
187 } 184 }
188} 185}
189 186
190static Cube 187Cube
191fourval_to_cube(int eofb, int ep, int coud, int cp) 188fourval_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
547Cube
548random_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
570Center 544Center
571what_center_at(Cube cube, Center c) 545what_center_at(Cube cube, Center c)
572{ 546{
diff --git a/src/cube.h b/src/cube.h
index 82f6d10..8e04839 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -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
13extern char *scrtypes[NSCRTYPES];
14
15Cube admissible_ep(Cube cube, PieceFilter f); 10Cube admissible_ep(Cube cube, PieceFilter f);
16int array_ep_to_epos(int *ep, int *eps_solved); 11int array_ep_to_epos(int *ep, int *eps_solved);
17Cube arrays_to_cube(CubeArray *arr, PieceFilter f); 12Cube arrays_to_cube(CubeArray *arr, PieceFilter f);
@@ -28,11 +23,11 @@ bool is_solved_center(Cube cube, Center c);
28bool is_solved_corner(Cube cube, Corner c); 23bool is_solved_corner(Cube cube, Corner c);
29bool is_solved_edge(Cube cube, Edge e); 24bool is_solved_edge(Cube cube, Edge e);
30void epos_to_partial_ep(int epos, int *ep, int *ss); 25void epos_to_partial_ep(int epos, int *ep, int *ss);
26Cube fourval_to_cube(int eofb, int ep, int coud, int cp);
31void free_cubearray(CubeArray *arr, PieceFilter f); 27void free_cubearray(CubeArray *arr, PieceFilter f);
32Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf); 28Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf);
33CubeArray * new_cubearray(Cube cube, PieceFilter f); 29CubeArray * new_cubearray(Cube cube, PieceFilter f);
34void print_cube(Cube cube); 30void print_cube(Cube cube);
35Cube random_cube(int scrt);
36Center what_center_at(Cube cube, Center c); 31Center what_center_at(Cube cube, Center c);
37Corner what_corner_at(Cube cube, Corner c); 32Corner what_corner_at(Cube cube, Corner c);
38Edge what_edge_at(Cube cube, Edge e); 33Edge 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};

Generated with cgit - Back to sebastiano.tronto.net