aboutsummaryrefslogtreecommitdiff
path: root/old/2021-06-17-cachedata/steps.c
diff options
context:
space:
mode:
Diffstat (limited to 'old/2021-06-17-cachedata/steps.c')
-rw-r--r--old/2021-06-17-cachedata/steps.c327
1 files changed, 327 insertions, 0 deletions
diff --git a/old/2021-06-17-cachedata/steps.c b/old/2021-06-17-cachedata/steps.c
new file mode 100644
index 0000000..f1001e6
--- /dev/null
+++ b/old/2021-06-17-cachedata/steps.c
@@ -0,0 +1,327 @@
1#include "steps.h"
2
3/* Check functions ***********************************************************/
4
5static int check_nothing(Cube cube);
6static int check_eofb_HTM(Cube cube);
7static int check_coud_HTM(Cube cube);
8static int check_coud_URF(Cube cube);
9static int check_corners_HTM(Cube cube);
10static int check_corners_URF(Cube cube);
11static int check_edges_HTM(Cube cube);
12static int check_drud_HTM(Cube cube);
13static int check_optimal_HTM(Cube cube);
14
15
16/* Index functions ***********************************************************/
17
18static uint64_t index_eofb(Cube cube);
19static uint64_t index_coud(Cube cube);
20static uint64_t index_corners(Cube cube);
21static uint64_t index_ep(Cube cube);
22static uint64_t index_drud(Cube cube);
23
24
25/* Steps *********************************************************************/
26
27Step
28eofb_HTM = {
29 .check = check_eofb_HTM,
30 .ready = check_nothing,
31 .moveset = moveset_HTM
32};
33
34Step
35coud_HTM = {
36 .check = check_coud_HTM,
37 .ready = check_nothing,
38 .moveset = moveset_HTM
39};
40
41Step
42coud_URF = {
43 .check = check_coud_URF,
44 .ready = check_nothing,
45 .moveset = moveset_URF
46};
47
48Step
49corners_HTM = {
50 .check = check_corners_HTM,
51 .ready = check_nothing,
52 .moveset = moveset_HTM
53};
54
55Step
56corners_URF = {
57 .check = check_corners_URF,
58 .ready = check_nothing,
59 .moveset = moveset_URF
60};
61
62Step
63edges_HTM = {
64 .check = check_edges_HTM,
65 .ready = check_nothing,
66 .moveset = moveset_HTM
67};
68
69Step
70drud_HTM = {
71 .check = check_drud_HTM,
72 .ready = check_nothing,
73 .moveset = moveset_HTM
74};
75
76Step
77optimal_HTM = {
78 .check = check_optimal_HTM,
79 .ready = check_nothing,
80 .moveset = moveset_HTM,
81 .cd = &cd_optimal_HTM_6
82};
83
84
85/* Cache solutions ***********************************************************/
86
87CacheData
88cd_optimal_HTM_6 = {
89 .filename = "cd_optimal_HTM_6",
90 .maxind0 = POW3TO7 * FACTORIAL8,
91 .len = 6,
92 .nind = 3,
93 .index = { index_corners, index_eofb, index_ep },
94 .moveset = moveset_HTM
95};
96
97
98/* Pruning tables ************************************************************/
99
100PruneData
101pd_eofb_HTM = {
102 .filename = "ptable_eofb_HTM",
103 .size = POW2TO11,
104 .index = index_eofb,
105 .moveset = moveset_HTM
106};
107
108PruneData
109pd_coud_HTM = {
110 .filename = "ptable_coud_HTM",
111 .size = POW3TO7,
112 .index = index_coud,
113 .moveset = moveset_HTM
114};
115
116PruneData
117pd_corners_HTM = {
118 .filename = "ptable_corners_HTM",
119 .size = POW3TO7 * FACTORIAL8,
120 .index = index_corners,
121 .moveset = moveset_HTM
122};
123
124PruneData
125pd_ep_HTM = {
126 .filename = "ptable_ep_HTM",
127 .size = FACTORIAL12,
128 .index = index_ep,
129 .moveset = moveset_HTM
130};
131
132PruneData
133pd_drud_HTM = {
134 .filename = "ptable_drud_HTM",
135 .size = POW2TO11 * POW3TO7 * BINOM12ON4,
136 .index = index_drud,
137 .moveset = moveset_HTM
138};
139
140
141/* Check functions implementation ********************************************/
142
143static int
144check_nothing(Cube cube)
145{
146 /* At least we check that it is admissible */
147 return is_admissible(cube);
148}
149
150static int
151check_eofb_HTM(Cube cube)
152{
153 if (!pd_eofb_HTM.generated)
154 generate_ptable(&pd_eofb_HTM);
155
156 return PTABLEVAL(pd_eofb_HTM.ptable, cube.eofb);
157}
158
159static int
160check_coud_HTM(Cube cube)
161{
162 if (!pd_coud_HTM.generated)
163 generate_ptable(&pd_coud_HTM);
164
165 return PTABLEVAL(pd_coud_HTM.ptable, cube.coud);
166}
167
168static int
169check_coud_URF(Cube cube)
170{
171 /* TODO: I can improve this by checking first the orientation of
172 * the corner in DBL and use that as a reference */
173
174 int ud = check_coud_HTM(cube);
175 int rl = check_coud_HTM(apply_move(z, cube));
176 int fb = check_coud_HTM(apply_move(x, cube));
177
178 return MIN(ud, MIN(rl, fb));
179}
180
181static int
182check_corners_HTM(Cube cube)
183{
184 if (!pd_corners_HTM.generated)
185 generate_ptable(&pd_corners_HTM);
186
187 return PTABLEVAL(pd_corners_HTM.ptable, index_corners(cube));
188}
189
190static int
191check_corners_URF(Cube cube)
192{
193 /* TODO: I can improve this by checking first the corner in DBL
194 * and use that as a reference */
195
196 int ret = 15;
197 Trans i;
198
199 for (i = 0; i < NROTATIONS; i++)
200 ret = MIN(ret,check_corners_HTM(apply_alg(trans_alg(i),cube)));
201
202 return ret;
203}
204
205static int
206check_edges_HTM(Cube cube)
207{
208 int ret = 0;
209
210 if (!pd_ep_HTM.generated)
211 generate_ptable(&pd_ep_HTM);
212
213 ret = MAX(ret, PTABLEVAL(pd_ep_HTM.ptable, index_ep(cube)));
214 ret = MAX(ret, check_eofb_HTM(cube));
215 ret = MAX(ret, check_eofb_HTM(apply_trans(ur, cube)));
216 ret = MAX(ret, check_eofb_HTM(apply_trans(fd, cube)));
217
218 return ret;
219}
220
221static int
222check_drud_HTM(Cube cube)
223{
224 if (!pd_drud_HTM.generated)
225 generate_ptable(&pd_drud_HTM);
226
227 return PTABLEVAL(pd_drud_HTM.ptable, index_drud(cube));
228}
229
230static int
231check_optimal_HTM(Cube cube)
232{
233 int dr1, dr2, dr3, drmax, cor; /*ep;*/
234
235 if (!pd_drud_HTM.generated)
236 generate_ptable(&pd_drud_HTM);
237 if (!pd_corners_HTM.generated)
238 generate_ptable(&pd_corners_HTM);
239 /*
240 *if (!pd_ep_HTM.generated)
241 * generate_ptable(&pd_ep_HTM);
242 */
243
244 dr1 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(cube));
245 dr2 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(apply_trans(rf, cube)));
246 dr3 = PTABLEVAL(pd_drud_HTM.ptable, index_drud(apply_trans(fd, cube)));
247
248 drmax = MAX(dr1, MAX(dr2, dr3));
249 if (dr1 == dr2 && dr2 == dr3 && dr1 != 0)
250 drmax++;
251
252 cor = PTABLEVAL(pd_corners_HTM.ptable, index_corners(cube));
253 /* ep = PTABLEVAL(pd_ep_HTM.ptable, index_ep(cube)); */
254
255 /*return MAX(drmax, MAX(ep, cor));*/
256 if (drmax == 0 && cor == 0)
257 return is_solved(cube, false) ? 0 : 1;
258 return MAX(drmax, cor);
259}
260
261
262/* Index functions implementation ********************************************/
263
264static uint64_t
265index_eofb(Cube cube)
266{
267 return cube.eofb;
268}
269
270static uint64_t
271index_coud(Cube cube)
272{
273 return cube.coud;
274}
275
276static uint64_t
277index_corners(Cube cube)
278{
279 return cube.coud * FACTORIAL8 + cube.cp;
280}
281
282static uint64_t
283index_ep(Cube cube)
284{
285 uint64_t a, b, c;
286
287 a = cube.eposs;
288 b = (cube.epose % FACTORIAL4) + epos_dependent_cube(cube)*FACTORIAL4;
289 c = cube.eposm % FACTORIAL4;
290
291 b *= FACTORIAL4 * BINOM12ON4;
292 c *= FACTORIAL4 * BINOM12ON4 * FACTORIAL4 * BINOM8ON4;
293
294 return a + b + c;
295}
296
297static uint64_t
298index_drud(Cube cube)
299{
300 uint64_t a, b, c;
301
302 a = cube.eofb;
303 b = cube.coud;
304 c = cube.epose / FACTORIAL4;
305
306 b *= POW2TO11;
307 c *= POW2TO11 * POW3TO7;
308
309 return a + b + c;
310}
311
312/* Movesets ******************************************************************/
313
314bool
315moveset_HTM(Move m)
316{
317 return m >= U && m <= B3;
318}
319
320bool
321moveset_URF(Move m)
322{
323 Move b = base_move(m);
324
325 return b == U || b == R || b == F;
326}
327

Generated with cgit - Back to sebastiano.tronto.net