aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2022-01-15 19:16:34 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2022-01-15 19:16:34 +0100
commit719080e6a88c4e17ba33a8dfec817e2d89ee666e (patch)
tree8ef78a30f2f86fdc70093327d6cf75c47895f539
parent298e9e11eda1db26fabced2e4ff14ce51c15a862 (diff)
downloadnissy-719080e6a88c4e17ba33a8dfec817e2d89ee666e.tar.gz
nissy-719080e6a88c4e17ba33a8dfec817e2d89ee666e.zip
Added one adhoc test (cornerhtr from CO)
-rw-r--r--adhoc/README3
-rwxr-xr-xadhoc/compile.sh15
-rw-r--r--adhoc/cornersdrhtr.c128
-rwxr-xr-xadhoc/runbin0 -> 322392 bytes
-rw-r--r--doc/nissy.12
-rwxr-xr-xnissybin0 -> 322488 bytes
-rw-r--r--src/alg.c40
-rw-r--r--src/alg.h3
-rw-r--r--src/commands.c8
9 files changed, 175 insertions, 24 deletions
diff --git a/adhoc/README b/adhoc/README
new file mode 100644
index 0000000..8f72c6e
--- /dev/null
+++ b/adhoc/README
@@ -0,0 +1,3 @@
1This folder contains some ad-hoc code that is not included in the main nissy
2program. You probably don't need it, but it may be worth looking into if you
3are trying to extend nissy by writing your own steps or other functions.
diff --git a/adhoc/compile.sh b/adhoc/compile.sh
new file mode 100755
index 0000000..aa541c7
--- /dev/null
+++ b/adhoc/compile.sh
@@ -0,0 +1,15 @@
1#/!bin/sh
2
3mkdir build
4cd build
5cp -R ../../src ./
6rm src/shell.c
7cp ../$1 src/
8cp ../../Makefile ./
9make
10cp nissy ../run
11rm src/*
12rmdir src
13rm *
14cd ..
15rmdir build
diff --git a/adhoc/cornersdrhtr.c b/adhoc/cornersdrhtr.c
new file mode 100644
index 0000000..2a5a6e6
--- /dev/null
+++ b/adhoc/cornersdrhtr.c
@@ -0,0 +1,128 @@
1#include "commands.h"
2
3/* Some of the following functions are new, some are copied from steps.c */
4bool
5allowed(Move m)
6{
7 return base_move(m) == U || m == R2 || m == F2;
8}
9
10bool
11allowed_next(Move l2, Move l1, Move m)
12{
13 return base_move(m) != base_move(l1);
14}
15
16bool
17check_cornershtr(Cube c)
18{
19 return coord_cornershtr.index(c) == 0;
20}
21
22bool
23check_coud_and_dbl(Cube c)
24{
25 return c.coud == 0 && what_corner_at(c, DBL) == DBL;
26}
27
28static int
29estimate_cornershtr_HTM(DfsArg *arg)
30{
31 return ptableval(&pd_cornershtr_HTM, arg->cube);
32}
33
34static bool
35validate_singlecw_ending(Alg *alg)
36{
37 int i;
38 bool nor, inv;
39 Move l2 = NULLMOVE, l1 = NULLMOVE, l2i = NULLMOVE, l1i = NULLMOVE;
40
41 for (i = 0; i < alg->len; i++) {
42 if (alg->inv[i]) {
43 l2i = l1i;
44 l1i = alg->move[i];
45 } else {
46 l2 = l1;
47 l1 = alg->move[i];
48 }
49 }
50
51 nor = l1 ==base_move(l1) && (!commute(l1, l2) ||l2 ==base_move(l2));
52 inv = l1i==base_move(l1i) && (!commute(l1i,l2i)||l2i==base_move(l2i));
53
54 return nor && inv;
55}
56
57int
58main()
59{
60 Moveset moveset_UR2F2 = {
61 .allowed = allowed,
62 .allowed_next = allowed_next,
63 };
64
65 init_moveset(&moveset_UR2F2);
66
67 /*
68 * This step is the same as cornershtr_HTM in steps.c, except for
69 * the ready() function (which is not relevant anyway, it is there
70 * more for testing than anything else) and the moveset.
71 */
72 Step step = {
73 .final = false,
74 .is_done = check_cornershtr,
75 .estimate = estimate_cornershtr_HTM,
76 .ready = check_coud_and_dbl,
77 .is_valid = validate_singlecw_ending,
78 .moveset = &moveset_UR2F2,
79
80 .pre_trans = uf,
81
82 .tables = {&pd_cornershtr_HTM},
83 .ntables = 1,
84 };
85
86 SolveOptions opts = {
87 .min_moves = 0,
88 .max_moves = 20,
89 .max_solutions = 1,
90 .nthreads = 4,
91 .optimal = 0,
92 .can_niss = false,
93 .verbose = false,
94 .all = false,
95 .print_number = false,
96 .count_only = false
97 };
98
99 init_symcoord();
100
101 bool cphtr_state_done[BINOM8ON4*6];
102 for (unsigned long int i = 0; i < BINOM8ON4*6; i++)
103 cphtr_state_done[i] = false;
104
105 for (unsigned long int i = 0; i < FACTORIAL8; i++) {
106 AlgList *sols;
107 Cube c = {0};
108 c.cp = i; /* inconsistent state because of side CO */
109
110 if (what_corner_at(c, DBL) != DBL ||
111 cphtr_state_done[coord_cphtr.index(c)])
112 continue;
113
114 fprintf(stderr, "Doing cp %ld (cphtr state %ld)\n",
115 i, coord_cphtr.index(c));
116
117 cphtr_state_done[coord_cphtr.index(c)] = true;
118 /* Comment next two lines to get non-reduced list */
119 Cube mirror = apply_trans(ur_mirror, c);
120 cphtr_state_done[coord_cphtr.index(mirror)] = true;
121
122 sols = solve(c, &step, &opts);
123 printf("%.2d\t", sols->first->alg->len);
124 print_alglist(sols, opts.print_number);
125 }
126
127 return 0;
128}
diff --git a/adhoc/run b/adhoc/run
new file mode 100755
index 0000000..27541c2
--- /dev/null
+++ b/adhoc/run
Binary files differ
diff --git a/doc/nissy.1 b/doc/nissy.1
index 089b189..948316d 100644
--- a/doc/nissy.1
+++ b/doc/nissy.1
@@ -152,7 +152,7 @@ Only find solutions that require at most
152moves more than the optimal solution. If 152moves more than the optimal solution. If
153.Ar N 153.Ar N
154is 0, this is equivalent to 154is 0, this is equivalent to
155.It Fl o 155.Fl o
156. 156.
157.It Fl p 157.It Fl p
158Plain style: do not print the number of moves. 158Plain style: do not print the number of moves.
diff --git a/nissy b/nissy
new file mode 100755
index 0000000..06e7708
--- /dev/null
+++ b/nissy
Binary files differ
diff --git a/src/alg.c b/src/alg.c
index 4c732a3..27af676 100644
--- a/src/alg.c
+++ b/src/alg.c
@@ -474,32 +474,36 @@ unniss(Alg *alg)
474} 474}
475 475
476void 476void
477init_movesets() 477init_moveset(Moveset *ms)
478{ 478{
479 int i, j; 479 int j;
480 uint64_t l, one; 480 uint64_t l, one;
481 Move m, l2, l1; 481 Move m, l2, l1;
482 Moveset *ms;
483 482
484 one = 1; 483 one = 1;
485 484
486 for (i = 0; i < nmoveset; i++) { 485 for (j = 0, m = U; m < NMOVES; m++)
487 ms = all_ms[i]; 486 if (ms->allowed(m))
487 ms->sorted_moves[j++] = m;
488 ms->sorted_moves[j] = NULLMOVE;
488 489
489 for (j = 0, m = U; m < NMOVES; m++) 490 for (l1 = 0; l1 < NMOVES; l1++) {
490 if (ms->allowed(m)) 491 for (l2 = 0; l2 < NMOVES; l2++) {
491 ms->sorted_moves[j++] = m; 492 ms->mask[l2][l1] = 0;
492 ms->sorted_moves[j] = NULLMOVE; 493 for (l=0; ms->sorted_moves[l]!=NULLMOVE; l++) {
493 494 m = ms->sorted_moves[l];
494 for (l1 = 0; l1 < NMOVES; l1++) { 495 if (ms->allowed_next(l2, l1, m))
495 for (l2 = 0; l2 < NMOVES; l2++) { 496 ms->mask[l2][l1] |= (one<<m);
496 ms->mask[l2][l1] = 0;
497 for (l=0; ms->sorted_moves[l]!=NULLMOVE; l++) {
498 m = ms->sorted_moves[l];
499 if (ms->allowed_next(l2, l1, m))
500 ms->mask[l2][l1] |= (one<<m);
501 }
502 } 497 }
503 } 498 }
504 } 499 }
505} 500}
501
502void
503init_all_movesets()
504{
505 int i;
506
507 for (i = 0; i < nmoveset; i++)
508 init_moveset(all_ms[i]);
509}
diff --git a/src/alg.h b/src/alg.h
index ea95a9c..d32c8bf 100644
--- a/src/alg.h
+++ b/src/alg.h
@@ -35,7 +35,8 @@ void print_alglist(AlgList *al, bool l);
35void swapmove(Move *m1, Move *m2); 35void swapmove(Move *m1, Move *m2);
36void unniss(Alg *alg); 36void unniss(Alg *alg);
37 37
38void init_movesets(); 38void init_moveset(Moveset *ms);
39void init_all_movesets();
39 40
40#endif 41#endif
41 42
diff --git a/src/commands.c b/src/commands.c
index 9ecc9c7..740736c 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -367,7 +367,7 @@ solve_exec(CommandArgs *args)
367 Cube c; 367 Cube c;
368 AlgList *sols; 368 AlgList *sols;
369 369
370 init_movesets(); 370 init_all_movesets();
371 init_symcoord(); 371 init_symcoord();
372 372
373 c = apply_alg(args->scramble, (Cube){0}); 373 c = apply_alg(args->scramble, (Cube){0});
@@ -388,7 +388,7 @@ scramble_exec(CommandArgs *args)
388 Alg *scr; 388 Alg *scr;
389 int i; 389 int i;
390 390
391 init_movesets(); 391 init_all_movesets();
392 init_symcoord(); 392 init_symcoord();
393 393
394 srand(time(NULL)); 394 srand(time(NULL));
@@ -407,7 +407,7 @@ gen_exec(CommandArgs *args)
407 int i; 407 int i;
408 408
409 fprintf(stderr, "Generating coordinates...\n"); 409 fprintf(stderr, "Generating coordinates...\n");
410 init_movesets(); 410 init_all_movesets();
411 init_symcoord(); 411 init_symcoord();
412 412
413 fprintf(stderr, "Generating pruning tables...\n"); 413 fprintf(stderr, "Generating pruning tables...\n");
@@ -460,7 +460,7 @@ twophase_exec(CommandArgs *args)
460 Cube c; 460 Cube c;
461 Alg *sol; 461 Alg *sol;
462 462
463 init_movesets(); 463 init_all_movesets();
464 init_symcoord(); 464 init_symcoord();
465 465
466 c = apply_alg(args->scramble, (Cube){0}); 466 c = apply_alg(args->scramble, (Cube){0});

Generated with cgit - Back to sebastiano.tronto.net