aboutsummaryrefslogtreecommitdiff
path: root/old/2021-07-15-almostbeforerefactor/steps.c
diff options
context:
space:
mode:
Diffstat (limited to 'old/2021-07-15-almostbeforerefactor/steps.c')
-rw-r--r--old/2021-07-15-almostbeforerefactor/steps.c284
1 files changed, 284 insertions, 0 deletions
diff --git a/old/2021-07-15-almostbeforerefactor/steps.c b/old/2021-07-15-almostbeforerefactor/steps.c
new file mode 100644
index 0000000..33dc74d
--- /dev/null
+++ b/old/2021-07-15-almostbeforerefactor/steps.c
@@ -0,0 +1,284 @@
1#include "steps.h"
2
3/* Standard checkers (return lower bound) ************************************/
4
5static int estimate_eofb_HTM(CubeTarget ct);
6static int estimate_coud_HTM(CubeTarget ct);
7static int estimate_coud_URF(CubeTarget ct);
8static int estimate_corners_HTM(CubeTarget ct);
9static int estimate_cornershtr_HTM(CubeTarget ct);
10static int estimate_corners_URF(CubeTarget ct);
11static int estimate_cornershtr_URF(CubeTarget ct);
12static int estimate_drud_HTM(CubeTarget ct);
13static int estimate_optimal_HTM(CubeTarget ct);
14
15/* Steps *********************************************************************/
16
17Step
18eofb_HTM = {
19 .estimate = estimate_eofb_HTM,
20 .ready = check_centers,
21 .moveset = moveset_HTM
22};
23
24Step
25coud_HTM = {
26 .estimate = estimate_coud_HTM,
27 .ready = check_centers,
28 .moveset = moveset_HTM
29};
30
31Step
32coud_URF = {
33 .estimate = estimate_coud_URF,
34 .ready = check_nothing,
35 .moveset = moveset_URF
36};
37
38Step
39corners_HTM = {
40 .estimate = estimate_corners_HTM,
41 .ready = check_centers,
42 .moveset = moveset_HTM
43};
44
45Step
46cornershtr_HTM = {
47 .estimate = estimate_cornershtr_HTM,
48 .ready = check_centers,
49 .moveset = moveset_HTM
50};
51
52Step
53cornershtr_URF = {
54 .estimate = estimate_cornershtr_URF,
55 .ready = check_nothing,
56 .moveset = moveset_URF
57};
58
59Step
60corners_URF = {
61 .estimate = estimate_corners_URF,
62 .ready = check_nothing,
63 .moveset = moveset_URF
64};
65
66Step
67drud_HTM = {
68 .estimate = estimate_drud_HTM,
69 .ready = check_centers,
70 .moveset = moveset_HTM
71};
72
73Step
74optimal_HTM = {
75 .estimate = estimate_optimal_HTM,
76 .ready = check_centers,
77 .moveset = moveset_HTM
78};
79
80
81/* Pruning tables ************************************************************/
82
83PruneData
84pd_eofb_HTM = {
85 .filename = "ptable_eofb_HTM",
86 .coord = &coord_eofb,
87 .moveset = moveset_HTM,
88 .ntrans = 1,
89 .trans = trans_group_trivial
90};
91
92PruneData
93pd_coud_HTM = {
94 .filename = "ptable_coud_HTM",
95 .coord = &coord_coud,
96 .moveset = moveset_HTM,
97 .ntrans = 1,
98 .trans = trans_group_trivial
99};
100
101PruneData
102pd_cornershtr_HTM = {
103 .filename = "ptable_cornershtr_withcosets_HTM",
104 .coord = &coord_cornershtr,
105 .moveset = moveset_HTM,
106 .ntrans = 1,
107 .trans = trans_group_trivial
108};
109
110PruneData
111pd_corners_HTM = {
112 .filename = "ptable_corners_HTM",
113 .coord = &coord_corners,
114 .moveset = moveset_HTM,
115 .ntrans = 1,
116 .trans = trans_group_trivial
117};
118
119PruneData
120pd_drud_HTM = {
121 .filename = "ptable_drud_HTM",
122 .coord = &coord_drud,
123 .moveset = moveset_HTM,
124 .ntrans = 1,
125 .trans = trans_group_trivial
126};
127
128PruneData
129pd_drud_sym16_HTM = {
130 .filename = "ptable_drud_sym16_HTM",
131 .coord = &coord_drud_sym16,
132 .moveset = moveset_HTM,
133 .ntrans = 16,
134 .trans = trans_group_udfix
135};
136
137PruneData
138pd_khuge_HTM = {
139 .filename = "ptable_khuge_HTM",
140 .coord = &coord_khuge,
141 .moveset = moveset_HTM,
142 .ntrans = 16,
143 .trans = trans_group_udfix
144};
145
146
147/* Standard checkers (return lower bound) ************************************/
148
149static int
150estimate_eofb_HTM(CubeTarget ct)
151{
152 if (!pd_eofb_HTM.generated)
153 genptable(&pd_eofb_HTM);
154
155 return ptableval(&pd_eofb_HTM, ct.cube);
156}
157
158static int
159estimate_coud_HTM(CubeTarget ct)
160{
161 if (!pd_coud_HTM.generated)
162 genptable(&pd_coud_HTM);
163
164 return ptableval(&pd_coud_HTM, ct.cube);
165}
166
167static int
168estimate_coud_URF(CubeTarget ct)
169{
170 /* TODO: I can improve this by checking first the orientation of
171 * the corner in DBL and use that as a reference */
172
173 CubeTarget ct2 = {.cube = apply_move(z, ct.cube), .target = ct.target};
174 CubeTarget ct3 = {.cube = apply_move(x, ct.cube), .target = ct.target};
175
176 int ud = estimate_coud_HTM(ct);
177 int rl = estimate_coud_HTM(ct2);
178 int fb = estimate_coud_HTM(ct3);
179
180 return MIN(ud, MIN(rl, fb));
181}
182
183static int
184estimate_corners_HTM(CubeTarget ct)
185{
186 if (!pd_corners_HTM.generated)
187 genptable(&pd_corners_HTM);
188
189 return ptableval(&pd_corners_HTM, ct.cube);
190}
191
192static int
193estimate_cornershtr_HTM(CubeTarget ct)
194{
195 if (!pd_cornershtr_HTM.generated)
196 genptable(&pd_cornershtr_HTM);
197
198 return ptableval(&pd_cornershtr_HTM, ct.cube);
199}
200
201static int
202estimate_cornershtr_URF(CubeTarget ct)
203{
204 /* TODO: I can improve this by checking first the corner in DBL
205 * and use that as a reference */
206
207 int c, ret = 15;
208 Trans i;
209
210 for (i = 0; i < NROTATIONS; i++) {
211 ct.cube = apply_alg(rotation_alg(i), ct.cube);
212 c = estimate_cornershtr_HTM(ct);
213 ret = MIN(ret, c);
214 }
215
216 return ret;
217}
218
219static int
220estimate_corners_URF(CubeTarget ct)
221{
222 /* TODO: I can improve this by checking first the corner in DBL
223 * and use that as a reference */
224
225 int c, ret = 15;
226 Trans i;
227
228 for (i = 0; i < NROTATIONS; i++) {
229 ct.cube = apply_alg(rotation_alg(i), ct.cube);
230 c = estimate_corners_HTM(ct);
231 ret = MIN(ret, c);
232 }
233
234 return ret;
235}
236
237static int
238estimate_drud_HTM(CubeTarget ct)
239{
240/*
241 if (!pd_drud_HTM.generated)
242 genptable(&pd_drud_HTM);
243
244 return ptableval(&pd_drud_HTM, ct.cube);
245*/
246
247 if (!pd_drud_sym16_HTM.generated)
248 genptable(&pd_drud_sym16_HTM);
249
250 return ptableval(&pd_drud_sym16_HTM, ct.cube);
251}
252
253static int
254estimate_optimal_HTM(CubeTarget ct)
255{
256 int dr1, dr2, dr3, cor, ret;
257 Cube cube = ct.cube;
258
259 if (!pd_khuge_HTM.generated)
260 genptable(&pd_khuge_HTM);
261
262 dr1 = ptableval(&pd_khuge_HTM, cube);
263 cor = estimate_corners_HTM(ct);
264 ret = MAX(dr1, cor);
265
266 if (ret > ct.target)
267 return ret;
268
269 cube = apply_trans(rf, ct.cube);
270 dr2 = ptableval(&pd_khuge_HTM, cube);
271 ret = MAX(ret, dr2);
272
273 if (ret > ct.target)
274 return ret;
275
276 cube = apply_trans(fd, ct.cube);
277 dr3 = ptableval(&pd_khuge_HTM, cube);
278
279 /* Michiel de Bondt's trick */
280 if (dr1 == dr2 && dr2 == dr3 && dr1 != 0)
281 dr3++;
282
283 return MAX(ret, dr3);
284}

Generated with cgit - Back to sebastiano.tronto.net