aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenricotenuti <tenutz_27@outlook.it>2024-08-26 17:56:17 +0200
committerenricotenuti <tenutz_27@outlook.it>2024-08-26 17:56:17 +0200
commit81daed66c3415827de7ab6a15c081a8f696f7a95 (patch)
tree9f6a2b7600cbaa6306eb73ef3be6e52fb9084881
parentf2907e471b3caddc5844bc6994e1cbd249019747 (diff)
downloadnissy-core-81daed66c3415827de7ab6a15c081a8f696f7a95.tar.gz
nissy-core-81daed66c3415827de7ab6a15c081a8f696f7a95.zip
premoves and niss
-rw-r--r--.gitignore2
-rw-r--r--src/core/cube.h107
-rw-r--r--src/solvers/h48/solve.h98
3 files changed, 179 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 5fb5b1f..236d875 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,7 @@ run
7tables/* 7tables/*
8test/*/runtest 8test/*/runtest
9test/run 9test/run
10test/run.DSYM 10run.DSYM
11test/last.* 11test/last.*
12tools/results 12tools/results
13.vscode 13.vscode
diff --git a/src/core/cube.h b/src/core/cube.h
index fe36f90..b24fb5c 100644
--- a/src/core/cube.h
+++ b/src/core/cube.h
@@ -285,6 +285,113 @@ move(cube_t c, uint8_t m)
285 } 285 }
286} 286}
287 287
288_static cube_t
289premove(cube_t c, uint8_t m){
290 switch (m) {
291 case _move_U:
292 return _premove(U3, c);
293 case _move_U2:
294 return _premove(U2, c);
295 case _move_U3:
296 return _premove(U, c);
297 case _move_D:
298 return _premove(D3, c);
299 case _move_D2:
300 return _premove(D2, c);
301 case _move_D3:
302 return _premove(D, c);
303 case _move_R:
304 return _premove(R3, c);
305 case _move_R2:
306 return _premove(R2, c);
307 case _move_R3:
308 return _premove(R, c);
309 case _move_L:
310 return _premove(L3, c);
311 case _move_L2:
312 return _premove(L2, c);
313 case _move_L3:
314 return _premove(L, c);
315 case _move_F:
316 return _premove(F3, c);
317 case _move_F2:
318 return _premove(F2, c);
319 case _move_F3:
320 return _premove(F, c);
321 case _move_B:
322 return _premove(B3, c);
323 case _move_B2:
324 return _premove(B2, c);
325 case _move_B3:
326 return _premove(B, c);
327 default:
328 LOG("move error, unknown move\n");
329 return zero;
330 }
331}
332_static uint8_t
333invertmove(uint8_t m)
334{
335 switch (m) {
336 case _move_U:
337 return _move_U3;
338 case _move_U2:
339 return _move_U2;
340 case _move_U3:
341 return _move_U;
342 case _move_D:
343 return _move_D3;
344 case _move_D2:
345 return _move_D2;
346 case _move_D3:
347 return _move_D;
348 case _move_R:
349 return _move_R3;
350 case _move_R2:
351 return _move_R2;
352 case _move_R3:
353 return _move_R;
354 case _move_L:
355 return _move_L3;
356 case _move_L2:
357 return _move_L2;
358 case _move_L3:
359 return _move_L;
360 case _move_F:
361 return _move_F3;
362 case _move_F2:
363 return _move_F2;
364 case _move_F3:
365 return _move_F;
366 case _move_B:
367 return _move_B3;
368 case _move_B2:
369 return _move_B2;
370 case _move_B3:
371 return _move_B;
372 default:
373 LOG("invertmove error, unknown move\n");
374 return _error;
375 }
376}
377
378_static uint8_t*
379invertpremoves(uint8_t *moves, uint8_t nmoves)
380{
381 uint8_t i;
382 uint8_t *ret = malloc(nmoves * sizeof(uint8_t));
383
384 for (i = 0; i < nmoves; i++)
385 ret[i] = invertmove(moves[i]);
386
387 // invert elements in the array
388 for (i = 0; i < nmoves / 2; i++)
389 _swap(ret[i], ret[nmoves - i - 1]);
390 return ret;
391}
392
393
394
288/* 395/*
289TODO transform is now relegated to a separated file because it is too long. 396TODO transform is now relegated to a separated file because it is too long.
290It would be nice to make it shorter without loosing performance. 397It would be nice to make it shorter without loosing performance.
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 0843792..7430228 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -11,6 +11,10 @@ typedef struct {
11 uint32_t *cocsepdata; 11 uint32_t *cocsepdata;
12 uint32_t *h48data; 12 uint32_t *h48data;
13 char **nextsol; 13 char **nextsol;
14 bool niss;
15 int8_t npremoves;
16 uint8_t premoves[MAXLEN];
17 int8_t totmoves;
14} dfsarg_solveh48_t; 18} dfsarg_solveh48_t;
15 19
16typedef struct { 20typedef struct {
@@ -35,41 +39,63 @@ _static int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]);
35_static void 39_static void
36solve_h48_appendsolution(dfsarg_solveh48_t *arg) 40solve_h48_appendsolution(dfsarg_solveh48_t *arg)
37{ 41{
38 int strl; 42 int strl;
43 char *solution = *arg->nextsol;
39 44
40 strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol); 45 strl = writemoves(arg->moves, arg->nmoves, *arg->nextsol);
41 LOG("Solution found: %s\n", *arg->nextsol); 46 *arg->nextsol += strl;
42 *arg->nextsol += strl; 47
43 **arg->nextsol = '\n'; 48 if (arg->npremoves) {
44 (*arg->nextsol)++; 49 **arg->nextsol = ' ';
45 (*arg->nsols)++; 50 (*arg->nextsol)++;
51
52 uint8_t* invertedpremoves = invertpremoves(arg->premoves, arg->npremoves);
53 strl = writemoves(invertedpremoves, arg->npremoves, *arg->nextsol);
54 free(invertedpremoves);
55 *arg->nextsol += strl;
56 }
57 LOG("Solution found: %s\n", solution);
58
59 **arg->nextsol = '\n';
60 (*arg->nextsol)++;
61 (*arg->nsols)++;
46} 62}
47 63
48_static_inline bool 64_static_inline bool
49solve_h48_stop(dfsarg_solveh48_t *arg) 65solve_h48_stop(dfsarg_solveh48_t *arg)
50{ 66{
51 uint32_t data, data_inv; 67 uint32_t data, data_inv;
52 int8_t bound; 68 int8_t bound, newbound;
69 bool niss = false;
53 70
54 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); 71 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &data);
55 if (bound + arg->nmoves > arg->depth) 72 if (bound + arg->totmoves > arg->depth)
56 return true; 73 return true;
57 74
58 bound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv); 75 newbound = get_h48_cdata(arg->inverse, arg->cocsepdata, &data_inv);
59 if (bound + arg->nmoves > arg->depth) 76 if (newbound + arg->totmoves > arg->depth)
60 return true; 77 return true;
78 if (newbound < bound) {
79 bound = newbound;
80 niss = true;
81 }
61 82
62/* 83 newbound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data);
63 bound = get_h48_bound(arg->cube, data, arg->h, arg->k, arg->h48data); 84 // LOG("Using pval %" PRId8 "\n", bound);
64LOG("Using pval %" PRId8 "\n", bound); 85 if (newbound + arg->totmoves > arg->depth)
65 if (bound + arg->nmoves > arg->depth)
66 return true; 86 return true;
67 87 if (newbound < bound) {
68 bound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data); 88 bound = newbound;
69 if (bound + arg->nmoves > arg->depth) 89 niss = false;
90 }
91 newbound = get_h48_bound(arg->inverse, data_inv, arg->h, arg->k, arg->h48data);
92 if (newbound + arg->totmoves > arg->depth)
70 return true; 93 return true;
71*/ 94 if (newbound < bound) {
72 95 bound = newbound;
96 niss = true;
97 }
98 arg->niss = niss;
73 return false; 99 return false;
74} 100}
75 101
@@ -87,7 +113,7 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
87 return 0; 113 return 0;
88 114
89 if (issolved(arg->cube)) { 115 if (issolved(arg->cube)) {
90 if (arg->nmoves != arg->depth) 116 if (arg->totmoves != arg->depth)
91 return 0; 117 return 0;
92 solve_h48_appendsolution(arg); 118 solve_h48_appendsolution(arg);
93 return 1; 119 return 1;
@@ -95,21 +121,39 @@ solve_h48_dfs(dfsarg_solveh48_t *arg)
95 121
96 /* TODO: avoid copy, change arg and undo changes after recursion */ 122 /* TODO: avoid copy, change arg and undo changes after recursion */
97 nextarg = *arg; 123 nextarg = *arg;
98 nextarg.nmoves = arg->nmoves + 1;
99 ret = 0; 124 ret = 0;
100 for (m = 0; m < 18; m++) { 125 nextarg.totmoves = arg->totmoves + 1;
101 nextarg.moves[arg->nmoves] = m; 126 if(arg->niss) {
102 if (!allowednextmove(nextarg.moves, nextarg.nmoves)) { 127 nextarg.npremoves = arg->npremoves + 1;
128 for (m = 0; m < 18; m++) {
129 nextarg.premoves[arg->npremoves] = m;
130 if (!allowednextmove(nextarg.premoves, nextarg.npremoves)) {
103 /* If a move is not allowed, neither are its 180 131 /* If a move is not allowed, neither are its 180
104 * and 270 degree variations */ 132 * and 270 degree variations */
105 m += 2; 133 m += 2;
106 continue; 134 continue;
107 } 135 }
108 nextarg.cube = move(arg->cube, m); 136 nextarg.cube = premove(arg->cube, m);
109 nextarg.inverse = inverse(nextarg.cube); /* TODO: use premove */ 137 nextarg.inverse = move(arg->inverse, m);
110 ret += solve_h48_dfs(&nextarg); 138 ret += solve_h48_dfs(&nextarg);
139 }
140 } else {
141 nextarg.nmoves = arg->nmoves + 1;
142 for (m = 0; m < 18; m++) {
143 nextarg.moves[arg->nmoves] = m;
144 if (!allowednextmove(nextarg.moves, nextarg.nmoves)) {
145 /* If a move is not allowed, neither are its 180
146 * and 270 degree variations */
147 m += 2;
148 continue;
149 }
150 nextarg.cube = move(arg->cube, m);
151 nextarg.inverse = premove(arg->inverse, m);
152 ret += solve_h48_dfs(&nextarg);
153 }
111 } 154 }
112 155
156
113 return ret; 157 return ret;
114} 158}
115 159

Generated with cgit - Back to sebastiano.tronto.net