aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--TODO.md3
-rw-r--r--doc/nissy.116
-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
7 files changed, 81 insertions, 48 deletions
diff --git a/TODO.md b/TODO.md
index 4eaa051..c97c5dc 100644
--- a/TODO.md
+++ b/TODO.md
@@ -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
47Rewrites the given scramble using only the 18 base (HTM) moves and at most two
48rotations at the end. If
49Ar scramble
50uses NISS, all moves done on normal scramble are written first, followed by
51all moves done on inverse.
52.
46.It Nm commands 53.It Nm commands
47List all available commands. 54List all available commands.
48. 55.
@@ -83,15 +90,18 @@ scrambles.
83.Ar type 90.Ar type
84can be specified to be one of the following: 91can be specified to be one of the following:
85.Bl -tag -width Ds 92.Bl -tag -width Ds
86.It Ar eo
87Scramble with solved EO on F/B axis.
88.It Ar corners 93.It Ar corners
89Scramble with solved edges (only cornes are scrambled). 94Scramble with solved edges (only cornes are scrambled).
90.It Ar edges 95.It Ar edges
91Scramble with solved corners (only edges are scrambled). 96Scramble with solved corners (only edges are scrambled).
97.It Ar eo
98Scramble with solved EO on F/B axis.
99.It Ar fmc
100Scramble the full cube and the resulting scramble starts and ends with
101the 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
95Solve the given 105Solve the given
96.Ar step 106.Ar step
97on the given 107on 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
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