aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-26 22:42:37 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-12-26 22:42:37 +0100
commit8cec37cb3e490b06639f2e05df8b947a9333d5d2 (patch)
treedcb1039625ae9f7afca90a0348891d29497edd17
parent975e3eafbae15b93a1a4f160dd781d359a6c717b (diff)
downloadnissy-8cec37cb3e490b06639f2e05df8b947a9333d5d2.tar.gz
nissy-8cec37cb3e490b06639f2e05df8b947a9333d5d2.zip
Added scramble command
-rw-r--r--Makefile2
-rw-r--r--TODO.md5
-rw-r--r--doc/nissy.121
-rwxr-xr-xnissybin318160 -> 0 bytes
-rw-r--r--nissy-2.0beta10.tar.gzbin0 -> 63768 bytes
-rw-r--r--nissy-2.0beta9.tar.gzbin60944 -> 0 bytes
-rwxr-xr-xnissy.exebin786001 -> 788520 bytes
-rw-r--r--src/commands.c107
-rw-r--r--src/cube.c95
-rw-r--r--src/cube.h6
-rw-r--r--src/cubetypes.h2
-rw-r--r--src/solve.c2
12 files changed, 204 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index ea3835c..ebe10a1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1# See LICENSE file for copyright and license details. 1# See LICENSE file for copyright and license details.
2 2
3VERSION = 2.0beta9 3VERSION = 2.0beta10
4 4
5PREFIX = /usr/local 5PREFIX = /usr/local
6MANPREFIX = ${PREFIX}/share/man 6MANPREFIX = ${PREFIX}/share/man
diff --git a/TODO.md b/TODO.md
index eb8d487..bff0521 100644
--- a/TODO.md
+++ b/TODO.md
@@ -10,7 +10,6 @@ It's more of a personal reminder than anything else.
10### Commands that are available in nissy 1.0, but not in this version (yet): 10### Commands that are available in nissy 1.0, but not in this version (yet):
11* drcorners (solve corners after dr) 11* drcorners (solve corners after dr)
12* search and improve non-optimal subsequences 12* search and improve non-optimal subsequences
13* **scramble [dr, corners only, edges only, htr, fmc(RUF)...]**
14* save and edit algs as "variables" 13* save and edit algs as "variables"
15 (or just use a "logging system" to keep info about previously run commands, 14 (or just use a "logging system" to keep info about previously run commands,
16including e.g. solutions that were not shown because -c) 15including e.g. solutions that were not shown because -c)
@@ -21,7 +20,8 @@ including e.g. solutions that were not shown because -c)
21* Other common steps (LSE, ...) 20* Other common steps (LSE, ...)
22 21
23### Improvements to currently implemented commands 22### Improvements to currently implemented commands
24* **solve should re-orient first if needed and not just give up if centers are off** 23* solve should re-orient first if needed and not just give up if centers are off
24* more scramble types (dr, htr, fmc(rufify)...)
25* solve should try up to a small bound without loading the large pruning table 25* solve should try up to a small bound without loading the large pruning table
26 26
27### New features 27### New features
@@ -29,7 +29,6 @@ including e.g. solutions that were not shown because -c)
29* configurability: add an `alias` command, run config file at startup 29* configurability: add an `alias` command, run config file at startup
30* configure max ram to be used (via config file and/or command line option) 30* configure max ram to be used (via config file and/or command line option)
31* transform alg, rufify etc... 31* transform alg, rufify etc...
32* more scramble stuff (scramble FMC with rufify...)
33* command notation to list available moves 32* command notation to list available moves
34* make multi-step solve much more general and create command 33* make multi-step solve much more general and create command
35 34
diff --git a/doc/nissy.1 b/doc/nissy.1
index 643674a..c725c0a 100644
--- a/doc/nissy.1
+++ b/doc/nissy.1
@@ -71,7 +71,26 @@ Display a text-only description of the cube obtained after applying
71.It Nm quit 71.It Nm quit
72Quit nissy. 72Quit nissy.
73. 73.
74.It Nm solve Ar step Oo Ar options Oc Ar scramble 74.It Nm scramble Oo Fl n Ar N Oc Oo Ar type Oc
75Print a randomly-generated (random position) scramble
76.
77If
78.Ar N
79is given, it produces
80.Ar N
81scrambles.
82.Ar type
83can be specified to be one of the following:
84.Bl -tag -width Ds
85.It Ar eo
86Scramble with solved EO on F/B axis.
87.It Ar corners
88Scramble with solved edges (only cornes are scrambled).
89.It Ar edges
90Scramble with solved corners (only edges are scrambled).
91.El
92.
93.It Nm solve Ar step Oo Ar options Oc Ar scramble.
75Solve the given 94Solve the given
76.Ar step 95.Ar step
77on the given 96on the given
diff --git a/nissy b/nissy
deleted file mode 100755
index c697a48..0000000
--- a/nissy
+++ /dev/null
Binary files differ
diff --git a/nissy-2.0beta10.tar.gz b/nissy-2.0beta10.tar.gz
new file mode 100644
index 0000000..b3b9766
--- /dev/null
+++ b/nissy-2.0beta10.tar.gz
Binary files differ
diff --git a/nissy-2.0beta9.tar.gz b/nissy-2.0beta9.tar.gz
deleted file mode 100644
index 17b905f..0000000
--- a/nissy-2.0beta9.tar.gz
+++ /dev/null
Binary files differ
diff --git a/nissy.exe b/nissy.exe
index 9dff82b..6020557 100755
--- a/nissy.exe
+++ b/nissy.exe
Binary files differ
diff --git a/src/commands.c b/src/commands.c
index 02af19f..fc63e7c 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -8,12 +8,14 @@ CommandArgs * print_parse_args(int c, char **v);
8CommandArgs * parse_only_scramble(int c, char **v); 8CommandArgs * parse_only_scramble(int c, char **v);
9CommandArgs * parse_no_arg(int c, char **v); 9CommandArgs * parse_no_arg(int c, char **v);
10CommandArgs * solve_parse_args(int c, char **v); 10CommandArgs * solve_parse_args(int c, char **v);
11CommandArgs * scramble_parse_args(int c, char **v);
11 12
12/* Exec functions ************************************************************/ 13/* Exec functions ************************************************************/
13 14
14static void gen_exec(CommandArgs *args); 15static void gen_exec(CommandArgs *args);
15static void invert_exec(CommandArgs *args); 16static void invert_exec(CommandArgs *args);
16static void solve_exec(CommandArgs *args); 17static void solve_exec(CommandArgs *args);
18static void scramble_exec(CommandArgs *args);
17static void steps_exec(CommandArgs *args); 19static void steps_exec(CommandArgs *args);
18static void commands_exec(CommandArgs *args); 20static void commands_exec(CommandArgs *args);
19static void print_exec(CommandArgs *args); 21static void print_exec(CommandArgs *args);
@@ -26,6 +28,7 @@ static void version_exec(CommandArgs *args);
26/* Local functions ***********************************************************/ 28/* Local functions ***********************************************************/
27 29
28static bool read_step(CommandArgs *args, char *str); 30static bool read_step(CommandArgs *args, char *str);
31static bool read_scrtype(CommandArgs *args, char *str);
29static bool read_scramble(int c, char **v, CommandArgs *args); 32static bool read_scramble(int c, char **v, CommandArgs *args);
30 33
31/* Commands ******************************************************************/ 34/* Commands ******************************************************************/
@@ -40,6 +43,15 @@ solve_cmd = {
40}; 43};
41 44
42Command 45Command
46scramble_cmd = {
47 .name = "scramble",
48 .usage = "scramble [TYPE] [-n N]",
49 .description = "Get a random-position scramble",
50 .parse_args = scramble_parse_args,
51 .exec = scramble_exec,
52};
53
54Command
43gen_cmd = { 55gen_cmd = {
44 .name = "gen", 56 .name = "gen",
45 .usage = "gen [-t N]", 57 .usage = "gen [-t N]",
@@ -137,6 +149,7 @@ Command *commands[NCOMMANDS] = {
137 &print_cmd, 149 &print_cmd,
138 &quit_cmd, 150 &quit_cmd,
139 &solve_cmd, 151 &solve_cmd,
152 &scramble_cmd,
140 &steps_cmd, 153 &steps_cmd,
141 &twophase_cmd, 154 &twophase_cmd,
142 &unniss_cmd, 155 &unniss_cmd,
@@ -243,6 +256,37 @@ solve_parse_args(int c, char **v)
243} 256}
244 257
245CommandArgs * 258CommandArgs *
259scramble_parse_args(int c, char **v)
260{
261 int i;
262 long val;
263
264 CommandArgs *a = new_args();
265
266 a->success = true;
267 a->n = 1;
268 a->scrt = -1;
269
270 for (i = 0; i < c; i++) {
271 if (!strcmp(v[i], "-n") && i+1 < c) {
272 val = strtol(v[++i], NULL, 10);
273 if (val < 1 || val > 1000000) {
274 fprintf(stderr,
275 "Invalid number of scrambles.\n");
276 a->success = false;
277 return a;
278 }
279 a->n = val;
280 } else if (!read_scrtype(a, v[i])) {
281 a->success = false;
282 return a;
283 }
284 }
285
286 return a;
287}
288
289CommandArgs *
246gen_parse_args(int c, char **v) 290gen_parse_args(int c, char **v)
247{ 291{
248 int val; 292 int val;
@@ -342,6 +386,26 @@ solve_exec(CommandArgs *args)
342} 386}
343 387
344static void 388static void
389scramble_exec(CommandArgs *args)
390{
391 Cube cube;
392 Alg *scr;
393 int i;
394
395 init_movesets();
396 init_symcoord();
397
398 srand(time(NULL));
399
400 for (i = 0; i < args->n; i++) {
401 cube = random_cube(args->scrt);
402 scr = solve_2phase(cube, 1);
403 print_alg(scr, false);
404 free_alg(scr);
405 }
406}
407
408static void
345gen_exec(CommandArgs *args) 409gen_exec(CommandArgs *args)
346{ 410{
347 int i; 411 int i;
@@ -454,21 +518,6 @@ version_exec(CommandArgs *args)
454/* Local functions implementation ********************************************/ 518/* Local functions implementation ********************************************/
455 519
456static bool 520static bool
457read_step(CommandArgs *args, char *str)
458{
459 int i;
460
461 for (i = 0; i < NSTEPS; i++) {
462 if (steps[i] != NULL && !strcmp(steps[i]->shortname, str)) {
463 args->step = steps[i];
464 return true;
465 }
466 }
467
468 return false;
469}
470
471static bool
472read_scramble(int c, char **v, CommandArgs *args) 521read_scramble(int c, char **v, CommandArgs *args)
473{ 522{
474 int i, k, n; 523 int i, k, n;
@@ -510,6 +559,34 @@ read_scramble(int c, char **v, CommandArgs *args)
510 return args->scramble->len > 0; 559 return args->scramble->len > 0;
511} 560}
512 561
562static bool
563read_scrtype(CommandArgs *args, char *str)
564{
565 int i;
566
567 args->scrt = -1;
568 for (i = 0; i < NSCRTYPES; i++)
569 if (!strcmp(scrtypes[i], str))
570 args->scrt = i;
571
572 return args->scrt != -1;
573}
574
575static bool
576read_step(CommandArgs *args, char *str)
577{
578 int i;
579
580 for (i = 0; i < NSTEPS; i++) {
581 if (steps[i] != NULL && !strcmp(steps[i]->shortname, str)) {
582 args->step = steps[i];
583 return true;
584 }
585 }
586
587 return false;
588}
589
513/* Public functions implementation *******************************************/ 590/* Public functions implementation *******************************************/
514 591
515void 592void
diff --git a/src/cube.c b/src/cube.c
index b9653ce..3a6234d 100644
--- a/src/cube.c
+++ b/src/cube.c
@@ -2,6 +2,9 @@
2 2
3/* Local functions ***********************************************************/ 3/* Local functions ***********************************************************/
4 4
5static void fix_eorleoud(CubeArray *arr);
6static void fix_cofbcorl(CubeArray *arr);
7static Cube fourval_to_cube(int eofb, int ep, int coud, int cp);
5static void init_inverse(); 8static void init_inverse();
6static bool read_invtables_file(); 9static bool read_invtables_file();
7static bool write_invtables_file(); 10static bool write_invtables_file();
@@ -15,6 +18,8 @@ static uint16_t co_invtable[POW3TO7][FACTORIAL8];
15static uint16_t cp_invtable[FACTORIAL8]; 18static uint16_t cp_invtable[FACTORIAL8];
16static uint16_t cpos_invtable[FACTORIAL6]; 19static uint16_t cpos_invtable[FACTORIAL6];
17 20
21char *scrtypes[NSCRTYPES] = { "eo", "corners", "edges" };
22
18/* Functions implementation **************************************************/ 23/* Functions implementation **************************************************/
19 24
20int 25int
@@ -139,6 +144,71 @@ epos_to_partial_ep(int epos, int *ep, int *ss)
139 ep[i] = ss[eps[is++]]; 144 ep[i] = ss[eps[is++]];
140} 145}
141 146
147static void
148fix_eorleoud(CubeArray *arr)
149{
150 int i;
151
152 for (i = 0; i < 12; i++) {
153 if ((edge_slice(i) == 0 && edge_slice(arr->ep[i]) != 0) ||
154 (edge_slice(i) != 0 && edge_slice(arr->ep[i]) == 0)) {
155 arr->eorl[i] = 1 - arr->eofb[i];
156 } else {
157 arr->eorl[i] = arr->eofb[i];
158 }
159
160 if ((edge_slice(i) == 2 && edge_slice(arr->ep[i]) != 2) ||
161 (edge_slice(i) != 2 && edge_slice(arr->ep[i]) == 2)) {
162 arr->eoud[i] = 1 - arr->eofb[i];
163 } else {
164 arr->eoud[i] = arr->eofb[i];
165 }
166 }
167}
168
169static void
170fix_cofbcorl(CubeArray *arr)
171{
172 int i;
173
174 for (i = 0; i < 8; i++) {
175 if (i % 2 == arr->cp[i] % 2) {
176 arr->cofb[i] = arr->coud[i];
177 arr->corl[i] = arr->coud[i];
178 } else {
179 if (arr->cp[i] % 2 == 0) {
180 arr->cofb[i] = (arr->coud[i]+1)%3;
181 arr->corl[i] = (arr->coud[i]+2)%3;
182 } else {
183 arr->cofb[i] = (arr->coud[i]+2)%3;
184 arr->corl[i] = (arr->coud[i]+1)%3;
185 }
186 }
187 }
188}
189
190static Cube
191fourval_to_cube(int eofb, int ep, int coud, int cp)
192{
193 CubeArray *arr;
194
195 arr = new_cubearray((Cube){0}, pf_all);
196
197 index_to_perm(ep, 12, arr->ep);
198 index_to_perm(cp, 8, arr->cp);
199 int_to_sum_zero_array(eofb, 2, 12, arr->eofb);
200 int_to_sum_zero_array(coud, 3, 8, arr->coud);
201
202 /* fix parity */
203 if (perm_sign(arr->ep, 12) != perm_sign(arr->cp, 8))
204 swap(&(arr->ep[0]), &(arr->ep[1]));
205
206 fix_eorleoud(arr);
207 fix_cofbcorl(arr);
208
209 return arrays_to_cube(arr, pf_all);
210}
211
142void 212void
143free_cubearray(CubeArray *arr, PieceFilter f) 213free_cubearray(CubeArray *arr, PieceFilter f)
144{ 214{
@@ -475,10 +545,8 @@ print_cube(Cube cube)
475} 545}
476 546
477Cube 547Cube
478random_cube() 548random_cube(int scrt)
479{ 549{
480 CubeArray *arr = new_cubearray((Cube){0}, pf_4val);
481 Cube ret;
482 int ep, cp, eo, co; 550 int ep, cp, eo, co;
483 551
484 ep = rand() % FACTORIAL12; 552 ep = rand() % FACTORIAL12;
@@ -486,18 +554,17 @@ random_cube()
486 eo = rand() % POW2TO11; 554 eo = rand() % POW2TO11;
487 co = rand() % POW3TO7; 555 co = rand() % POW3TO7;
488 556
489 index_to_perm(ep, 12, arr->ep); 557 if (scrt == 0) { /* EO */
490 index_to_perm(cp, 8, arr->cp); 558 eo = 0;
491 int_to_sum_zero_array(eo, 2, 12, arr->eofb); 559 } else if (scrt == 1) { /* corners */
492 int_to_sum_zero_array(co, 3, 8, arr->coud); 560 eo = 0;
493 561 ep = 0;
494 if (perm_sign(arr->ep, 12) != perm_sign(arr->cp, 8)) 562 } else if (scrt == 2) { /* edges */
495 swap(&(arr->ep[0]), &(arr->ep[1])); 563 co = 0;
496 564 cp = 0;
497 ret = arrays_to_cube(arr, pf_4val); 565 }
498 free_cubearray(arr, pf_4val);
499 566
500 return ret; 567 return fourval_to_cube(eo, ep, co, cp);
501} 568}
502 569
503Center 570Center
diff --git a/src/cube.h b/src/cube.h
index 71e3cc5..82f6d10 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -8,6 +8,10 @@
8#include "pf.h" 8#include "pf.h"
9#include "utils.h" 9#include "utils.h"
10 10
11#define NSCRTYPES 3
12
13extern char *scrtypes[NSCRTYPES];
14
11Cube admissible_ep(Cube cube, PieceFilter f); 15Cube admissible_ep(Cube cube, PieceFilter f);
12int array_ep_to_epos(int *ep, int *eps_solved); 16int array_ep_to_epos(int *ep, int *eps_solved);
13Cube arrays_to_cube(CubeArray *arr, PieceFilter f); 17Cube arrays_to_cube(CubeArray *arr, PieceFilter f);
@@ -28,7 +32,7 @@ void free_cubearray(CubeArray *arr, PieceFilter f);
28Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf); 32Cube move_via_arrays(CubeArray *arr, Cube c, PieceFilter pf);
29CubeArray * new_cubearray(Cube cube, PieceFilter f); 33CubeArray * new_cubearray(Cube cube, PieceFilter f);
30void print_cube(Cube cube); 34void print_cube(Cube cube);
31Cube random_cube(); 35Cube random_cube(int scrt);
32Center what_center_at(Cube cube, Center c); 36Center what_center_at(Cube cube, Center c);
33Corner what_corner_at(Cube cube, Corner c); 37Corner what_corner_at(Cube cube, Corner c);
34Edge what_edge_at(Cube cube, Edge e); 38Edge what_edge_at(Cube cube, Edge e);
diff --git a/src/cubetypes.h b/src/cubetypes.h
index b002e8b..20e028b 100644
--- a/src/cubetypes.h
+++ b/src/cubetypes.h
@@ -156,6 +156,8 @@ commandargs
156 SolveOptions * opts; 156 SolveOptions * opts;
157 Step * step; 157 Step * step;
158 Command * command; /* For help */ 158 Command * command; /* For help */
159 int n;
160 int scrt;
159}; 161};
160 162
161struct 163struct
diff --git a/src/solve.c b/src/solve.c
index cfb2bd3..0bd1de7 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -452,7 +452,7 @@ solve_2phase(Cube cube, int nthreads)
452 452
453 opts1.min_moves = 0; 453 opts1.min_moves = 0;
454 opts1.max_moves = 13; 454 opts1.max_moves = 13;
455 opts1.max_solutions = 100; 455 opts1.max_solutions = 20;
456 opts1.nthreads = nthreads; 456 opts1.nthreads = nthreads;
457 opts1.optimal = 3; 457 opts1.optimal = 3;
458 opts1.can_niss = false; 458 opts1.can_niss = false;

Generated with cgit - Back to sebastiano.tronto.net