aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/stats.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/h48/stats.h')
-rw-r--r--src/solvers/h48/stats.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/solvers/h48/stats.h b/src/solvers/h48/stats.h
new file mode 100644
index 0000000..6e78ab5
--- /dev/null
+++ b/src/solvers/h48/stats.h
@@ -0,0 +1,100 @@
1/*
2The h48stats solver computes how many moves it takes to solve to
3each of the 12 h48 coordinates, one for each value of h from 0 to 11.
4The solutions array is filled with the length of the solutions. The
5solutions array is therefore not a printable string.
6*/
7
8typedef struct {
9 cube_t cube;
10 int8_t nmoves;
11 int8_t depth;
12 uint8_t moves[MAXLEN];
13 uint32_t *cocsepdata;
14 uint8_t *h48data;
15 char *s;
16} dfsarg_solveh48stats_t;
17
18STATIC int64_t solve_h48stats_dfs(dfsarg_solveh48stats_t *);
19STATIC int64_t solve_h48stats(cube_t, int8_t, const void *, char [static 12]);
20
21STATIC int64_t
22solve_h48stats_dfs(dfsarg_solveh48stats_t *arg)
23{
24 const int64_t limit = 11;
25
26 int8_t bound, u;
27 uint8_t m;
28 uint32_t d;
29 int64_t coord, h;
30 dfsarg_solveh48stats_t nextarg;
31
32 /* Check cocsep lower bound (corners only) */
33 bound = get_h48_cdata(arg->cube, arg->cocsepdata, &d);
34 if (bound + arg->nmoves > arg->depth)
35 return 0;
36
37 /* Check h48 lower bound for h=0 (esep, but no eo) */
38 coord = coord_h48_edges(arg->cube, COCLASS(d), TTREP(d), 0);
39 bound = get_h48_bound(arg->cube, d, 0, 4, arg->h48data);
40 if (bound + arg->nmoves > arg->depth)
41 return 0;
42
43 /* Update all other values, if solved */
44 coord = coord_h48_edges(arg->cube, COCLASS(d), TTREP(d), 11);
45 for (h = 0; h <= limit; h++) {
46 u = coord >> (11-h) == 0 && arg->s[h] == 99;
47 arg->s[h] = u * arg->nmoves + (1-u) * arg->s[h];
48 }
49
50 if (arg->s[limit] != 99)
51 return 0;
52
53 nextarg = *arg;
54 nextarg.nmoves = arg->nmoves + 1;
55 for (m = 0; m < 18; m++) {
56 nextarg.moves[arg->nmoves] = m;
57 if (!allowednextmove(nextarg.moves, nextarg.nmoves)) {
58 /* If a move is not allowed, neither are its 180
59 * and 270 degree variations */
60 m += 2;
61 continue;
62 }
63 nextarg.cube = move(arg->cube, m);
64 solve_h48stats_dfs(&nextarg);
65 }
66
67 return 0;
68}
69
70STATIC int64_t
71solve_h48stats(
72 cube_t cube,
73 int8_t maxmoves,
74 const void *data,
75 char solutions[static 12]
76)
77{
78 int i;
79 dfsarg_solveh48stats_t arg;
80
81 arg = (dfsarg_solveh48stats_t) {
82 .cube = cube,
83 .cocsepdata = get_cocsepdata_ptr(data),
84 .h48data = get_h48data_ptr(data),
85 .s = solutions
86 };
87
88 for (i = 0; i < 12; i++)
89 solutions[i] = (char)99;
90
91 for (arg.depth = 0;
92 arg.depth <= maxmoves && solutions[11] == 99;
93 arg.depth++)
94 {
95 arg.nmoves = 0;
96 solve_h48stats_dfs(&arg);
97 }
98
99 return 0;
100}

Generated with cgit - Back to sebastiano.tronto.net