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
|
STATIC uint64_t coord_coord_generic(
const coord_t [static 1], cube_t, const unsigned char *);
STATIC cube_t coord_cube_generic(
const coord_t [static 1], uint64_t, const unsigned char *);
STATIC bool coord_isnasty_generic(
const coord_t [static 1], uint64_t, const unsigned char *);
STATIC size_t coord_gendata_generic(const coord_t [static 1], unsigned char *);
STATIC bool solution_lastqt_cw(const solution_moves_t [static 1]);
STATIC bool coord_can_switch(const coord_t [static 1], const unsigned char *,
size_t, const uint8_t *);
STATIC bool coord_is_solved(
const coord_t [static 1], uint64_t, const unsigned char *);
STATIC cube_t coordinate_merge_ce(cube_t, cube_t);
STATIC cube_t coordinate_merge_ec(cube_t, cube_t);
STATIC uint64_t
coord_coord_generic(
const coord_t coord[static 1],
cube_t c,
const unsigned char *data
)
{
const uint32_t *data32;
uint32_t d;
cube_t tr;
data32 = (const uint32_t *)(data + INFOSIZE);
d = data32[coord->sym.coord(c)];
tr = transform(c, COORD_TTREP(d));
return COORD_CLASS(d) * coord->sym.max2 + coord->sym.coord2(tr);
}
STATIC cube_t
coord_cube_generic(
const coord_t coord[static 1],
uint64_t i,
const unsigned char *data
)
{
const unsigned char *datanoinfo;
const uint32_t *rep32;
cube_t c;
datanoinfo = data + INFOSIZE;
rep32 = (const uint32_t *)(datanoinfo + 4 * (size_t)coord->sym.max);
c = coord->sym.cube(rep32[i / coord->sym.max2]);
return coord->sym.merge(c, coord->sym.cube2(i % coord->sym.max2));
}
STATIC bool
coord_isnasty_generic(
const coord_t coord[static 1],
uint64_t i,
const unsigned char *data
)
{
const unsigned char *datanoinfo;
const uint32_t *classttrep, *rep32;
uint32_t r;
datanoinfo = data + INFOSIZE;
classttrep = (const uint32_t *)datanoinfo;
rep32 = (const uint32_t *)(datanoinfo + 4 * (size_t)coord->sym.max);
r = rep32[i / coord->sym.max2];
return COORD_ISNASTY(classttrep[r]);
}
STATIC size_t
coord_gendata_generic(
const coord_t coord[static 1],
unsigned char *data
)
{
uint64_t i, j, n, t, nasty;
unsigned char *datanoinfo;
uint32_t *classttrep, *rep;
size_t coord_datasize;
cube_t c;
tableinfo_t info;
coord_datasize = INFOSIZE + 4*(coord->sym.classes + coord->sym.max);
if (data == NULL)
return coord_datasize;
datanoinfo = data + INFOSIZE;
classttrep = (uint32_t *)datanoinfo;
rep = classttrep + coord->sym.max;
memset(data, 0xFF, coord_datasize);
info = (tableinfo_t) {
.solver = "coord data for ",
.type = TABLETYPE_SPECIAL,
.infosize = INFOSIZE,
.fullsize = coord_datasize,
.hash = 0,
.entries = coord->sym.classes + coord->sym.max,
.classes = coord->sym.classes,
.bits = 32,
.base = 0,
.maxvalue = 0,
.next = 0
};
append_name(&info, coord->name);
for (i = 0, n = 0; i < coord->sym.max; i++) {
if (classttrep[i] != 0xFFFFFFFF)
continue;
c = coord->sym.cube(i);
for (t = 1, nasty = 0; t < NTRANS && !nasty; t++) {
if (!((UINT64_C(1) << t) & coord->trans_mask))
continue;
nasty = i == coord->sym.coord(transform(c, t));
}
for (t = 0; t < NTRANS; t++) {
if (!((UINT64_C(1) << t) & coord->trans_mask))
continue;
j = coord->sym.coord(transform(c, t));
classttrep[j] =
(n << COORD_CLASS_SHIFT) |
(nasty << COORD_ISNASTY_SHIFT) |
(inverse_trans(t) << COORD_TTREP_SHIFT);
}
rep[n++] = i;
}
writetableinfo(&info, coord_datasize, data);
DBG_ASSERT(n == coord->sym.classes,
"%s coordinate data: computed %" PRIu64 " classes, "
"expected %" PRIu64 "\n", coord->name, n, coord->sym.classes);
return coord_datasize;
}
STATIC bool
solution_lastqt_cw(const solution_moves_t s[static 1])
{
return are_lastmoves_singlecw(s->nmoves, s->moves) &&
are_lastmoves_singlecw(s->npremoves, s->premoves);
}
STATIC bool
solution_always_valid(const solution_moves_t s[static 1])
{
return true;
}
STATIC bool
coord_can_switch(
const coord_t coord[static 1],
const unsigned char *data,
size_t n,
const uint8_t *moves
)
{
/*
This function checks that the last move (or two moves, if parallel)
have a non-trivial effect on the coordinate of the solved cube. This
works in general for all coordinates that have been used so far, but
in more general cases that have not been considered yet it may fail.
*/
uint64_t i;
DBG_ASSERT(n > 0, "Error: cannot check if coordinate solver "
"can use NISS after 0 moves");
if (!coord->allow_niss)
return false;
i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data);
if (i == 0)
return false;
if (n == 1 || !parallel(moves[n-1], moves[n-2]))
return true;
i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data);
return i != 0;
}
STATIC bool
coord_is_solved(
const coord_t coord[static 1],
uint64_t i,
const unsigned char *data
)
{
return coord->is_solved == NULL ? i == 0 : coord->is_solved(i, data);
}
STATIC cube_t
coordinate_merge_ce(cube_t corners, cube_t edges)
{
cube_t merged;
merged = corners;
copy_edges(&merged, edges);
return merged;
}
STATIC cube_t
coordinate_merge_ec(cube_t edges, cube_t corners)
{
return coordinate_merge_ce(corners, edges);
}
|