1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#define STEPS_C
#include "steps.h"
/* TODO: change all checkers to use coordinates! */
bool
check_centers(Cube *cube)
{
int i;
for (i = 0; i < 6; i++)
if (cube->xp[i] != i)
return false;
return true;
}
bool
check_coud_HTM(Cube *cube)
{
int i;
for (i = 0; i < 8; i++)
if (cube->co[i] != 0)
return false;
return true;
}
bool
check_coud_URF(Cube *cube)
{
Cube c2, c3;
copy_cube(cube, &c2);
copy_cube(cube, &c3);
apply_move(z, &c2);
apply_move(x, &c3);
return check_coud_HTM(cube) ||
check_coud_HTM(&c2) ||
check_coud_HTM(&c3);
}
bool
check_cp_HTM(Cube *cube)
{
int i;
for (i = 0; i < 8; i++)
if (cube->cp[i] != i)
return false;
return true;
}
bool
check_corners_HTM(Cube *cube)
{
return check_coud_HTM(cube) && check_cp_HTM(cube);
}
bool
check_corners_URF(Cube *cube)
{
Cube c;
Trans i;
for (i = 0; i < NROTATIONS; i++) {
copy_cube(cube, &c);
apply_alg(rotation_alg(i), &c);
if (check_corners_HTM(&c))
return true;
}
return false;
}
bool
check_cornershtr(Cube *cube)
{
/* TODO (use coord) */
return true;
}
bool
check_eofb(Cube *cube)
{
/* TODO (use coord) */
return true;
}
bool
check_drud(Cube *cube)
{
/* TODO (use coord) */
return true;
}
bool
check_htr(Cube *cube)
{
/* TODO (check_drud(cube) and coord_htr_drud == 0) */
return true;
}
bool
validate_singlecw_ending(Alg *alg)
{
int i;
bool nor, inv;
Move l2 = NULLMOVE, l1 = NULLMOVE, l2i = NULLMOVE, l1i = NULLMOVE;
for (i = 0; i < alg->len; i++) {
if (alg->inv[i]) {
l2i = l1i;
l1i = alg->move[i];
} else {
l2 = l1;
l1 = alg->move[i];
}
}
nor = l1 ==base_move(l1) && (!commute(l1, l2) ||l2 ==base_move(l2));
inv = l1i==base_move(l1i) && (!commute(l1i,l2i)||l2i==base_move(l2i));
return nor && inv;
}
/* Public functions **********************************************************/
void
compute_ind(StepAlt *a, Cube *cube, Movable *ind)
{
int i;
Cube mvd;
Trans t, tt;
for (i = 0; i < a->n_coord; i++) {
t = a->coord_trans[i];
copy_cube(cube, &mvd);
apply_trans(t, &mvd);
ind[i].val = index_coord(a->coord[i], &mvd, &tt);
ind[i].t = transform_trans(tt, t);
}
}
int
estimate_stepalt(StepAlt *a, Movable *ind, int goal)
{
int i, ret, est[a->n_coord];
for (i = 0; i < a->n_coord; i++) {
est[i] = ptableval(a->pd[i], ind[i].val);
if (est[i] == a->pd[i]->base && a->compact_pd[i])
est[i] = ptableval(a->fallback_pd[i],
ind[i].val/a->fbmod[i]);
if (ind[i].val != 0 && est[i] == 0) /* est == 0 iff solved */
est[i] = 1;
/*
TODO: remove this debug code
printf("%d: est=%d | ", i, est[i]);
*/
if (est[i] > goal)
return est[i];
}
for (i = 0; i < a->n_dbtrick; i++)
if (est[a->dbtrick[i][0]] > 0 &&
est[a->dbtrick[i][0]] == est[a->dbtrick[i][1]] &&
est[a->dbtrick[i][0]] == est[a->dbtrick[i][2]])
est[a->dbtrick[i][0]] += 1;
for (i = 0, ret = -1; i < a->n_coord; i++)
ret = MAX(ret, est[i]);
/*
TODO: remove this debug code
printf("Final estimate: %d\n", ret);
*/
return ret;
}
void
prepare_step(Step *step, SolveOptions *opts)
{
int i, j;
PDGenData pdg;
StepAlt *a;
for (i = 0; step->alt[i] != NULL; i++) {
a = step->alt[i];
init_moveset(a->moveset);
pdg.moveset = a->moveset;
for (j = 0; j < a->n_coord; j++) {
gen_coord(a->coord[j]);
pdg.coord = a->coord[j];
pdg.compact = a->compact_pd[j];
pdg.pd = NULL;
a->pd[j] = genptable(&pdg, opts->nthreads);
if (a->compact_pd[j]) {
gen_coord(a->fallback_coord[j]);
pdg.coord = a->fallback_coord[j];
pdg.compact = false;
pdg.pd = NULL;
a->fallback_pd[j] =
genptable(&pdg, opts->nthreads);
}
}
}
}
|