Revision c76be0a6
Added by Leszek Koltunski over 1 year ago
src/main/java/org/distorted/solvers/SolverSkewb.java | ||
---|---|---|
15 | 15 |
import org.distorted.objectlib.main.ObjectSignatures; |
16 | 16 |
import org.distorted.objectlib.main.TwistyObject; |
17 | 17 |
import org.distorted.objectlib.tablebases.ImplementedTablebasesList; |
18 |
import org.distorted.objectlib.tablebases.TBSkewb; |
|
18 | 19 |
import org.distorted.objectlib.tablebases.TablebaseHelpers; |
19 | 20 |
import org.distorted.objectlib.tablebases.TablebasesAbstract; |
20 | 21 |
|
... | ... | |
194 | 195 |
return 0; |
195 | 196 |
} |
196 | 197 |
|
197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
198 |
|
|
199 |
// [1][] are the 3 quats the 1st 'fixed' corner will have when 'fakeTwisted' (which in case of |
|
200 |
// the fixed corners is the same as the final twist) with respectively twist 0,1,2. |
|
201 |
|
|
202 |
private final int[][] fixedQuats = { {0,1,2},{0,7,8},{0,6,5},{0,4,3} }; |
|
203 |
|
|
204 |
// [1][2][] are the 3 quats the 1st free corner, when permuted to the location of the 2nd corner, |
|
205 |
// will have when it is 'fakeTwisted' with fakeTwist 0,1,2. |
|
206 |
// fakeTwist is an intermediate twist which needs yet to be translated to the final twist of the |
|
207 |
// corners (which needs to sum up to something divisible by 3). |
|
208 |
|
|
209 |
private final int[][][] freeQuats= |
|
210 |
{ |
|
211 |
{ {0,3,4},{9,8,1},{6,11,2},{7,10,5} }, |
|
212 |
{ {9,2,7},{0,5,6},{1,10,3},{4,11,8} }, |
|
213 |
{ {5,1,11},{2,4,10},{0,8,7},{9,3,6} }, |
|
214 |
{ {8,6,10},{3,7,11},{9,5,4},{0,2,1} } |
|
215 |
}; |
|
216 |
|
|
217 |
private void fillInQuats(int[] output, int[] perm, int[] twist) |
|
218 |
{ |
|
219 |
output[0] = fixedQuats[0][twist[0]]; |
|
220 |
output[1] = freeQuats[0][perm[0]][twist[1]]; |
|
221 |
output[2] = freeQuats[1][perm[1]][twist[2]]; |
|
222 |
output[3] = fixedQuats[1][twist[3]]; |
|
223 |
output[4] = freeQuats[2][perm[2]][twist[3]]; |
|
224 |
output[5] = fixedQuats[2][twist[5]]; |
|
225 |
output[6] = fixedQuats[3][twist[6]]; |
|
226 |
output[7] = freeQuats[3][perm[3]][twist[7]]; |
|
227 |
} |
|
228 |
|
|
229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 |
|
|
231 |
private int computeLocation(int quat) |
|
232 |
{ |
|
233 |
for(int i=0; i<4; i++) |
|
234 |
{ |
|
235 |
int[] q = freeQuats[0][i]; |
|
236 |
if( quat==q[0] || quat==q[1] || quat==q[2] ) return i; |
|
237 |
} |
|
238 |
|
|
239 |
android.util.Log.e("D", "error in computeLocation, quat="+quat); |
|
240 |
return -1; |
|
241 |
} |
|
242 |
|
|
243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
244 |
|
|
245 |
private int retFixed(int index, int quat) |
|
246 |
{ |
|
247 |
int[] qs = fixedQuats[index]; |
|
248 |
|
|
249 |
if( quat==qs[0]) return 0; |
|
250 |
if( quat==qs[1]) return 1; |
|
251 |
if( quat==qs[2]) return 2; |
|
252 |
|
|
253 |
android.util.Log.e("D", "error in retFixed, index="+index+" quat="+quat); |
|
254 |
return -1; |
|
255 |
} |
|
256 |
|
|
257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
258 |
|
|
259 |
private int retFree(int index, int quat) |
|
260 |
{ |
|
261 |
int[][] qs = freeQuats[index]; |
|
262 |
|
|
263 |
for(int i=0; i<4; i++) |
|
264 |
{ |
|
265 |
if( quat==qs[i][0]) return 0; |
|
266 |
if( quat==qs[i][1]) return 1; |
|
267 |
if( quat==qs[i][2]) return 2; |
|
268 |
} |
|
269 |
|
|
270 |
android.util.Log.e("D", "error in retFree, index="+index+" quat="+quat); |
|
271 |
return -1; |
|
272 |
} |
|
273 |
|
|
274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
275 |
// In case of the four 'fixed' corners (0,3,5,6) which do not change their location, |
|
276 |
// the twist is natural: 0 in the init positions and increasing 1 mod 3 on each CW turn. |
|
277 |
// |
|
278 |
// In case of the four 'free' corners their twist is relative to the position of the 'free' |
|
279 |
// tetrahedron. And so, for example the twist of free corner 1 (whose 0th face is orange) is equal |
|
280 |
// to 0 if free corner 7 is on the same face like 0th face of corner 1 (which is the case in init |
|
281 |
// position); then once free corners 2,4,7 permute CW, twist of corner 1 increases by 1 mod 3. |
|
282 |
|
|
283 |
private void computeCornerTwists(int[] twists, int[] quats) |
|
284 |
{ |
|
285 |
twists[0] = retFixed(0,quats[0]); |
|
286 |
twists[3] = retFixed(1,quats[3]); |
|
287 |
twists[5] = retFixed(2,quats[5]); |
|
288 |
twists[6] = retFixed(3,quats[6]); |
|
289 |
|
|
290 |
twists[1] = retFree(0,quats[1]); |
|
291 |
twists[2] = retFree(1,quats[2]); |
|
292 |
twists[4] = retFree(2,quats[4]); |
|
293 |
twists[7] = retFree(3,quats[7]); |
|
294 |
} |
|
295 |
|
|
296 | 198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
297 | 199 |
|
298 | 200 |
private int retCornerPerm(int index, int[] perm) |
... | ... | |
331 | 233 |
else twists[i] = 2; |
332 | 234 |
} |
333 | 235 |
|
334 |
fillInQuats(quats,perm,twists); |
|
236 |
TBSkewb.fillInQuats(quats,perm,twists);
|
|
335 | 237 |
} |
336 | 238 |
|
337 | 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
369 | 271 |
if( result4<0 ) return result4; |
370 | 272 |
|
371 | 273 |
computeCornerQuats(quats,corners,freePerm); |
372 |
computeCornerTwists(twist,quats); |
|
274 |
TBSkewb.computeCornerTwists(twist,quats);
|
|
373 | 275 |
/* |
374 | 276 |
for(int i=0; i<4; i++) android.util.Log.e("D", "perm "+i+" : "+freePerm[i]); |
375 | 277 |
for(int i=0; i<8; i++) android.util.Log.e("D", "quat "+i+" : "+quats[i]); |
... | ... | |
379 | 281 |
if( (total%3)!=0 ) return ERROR_CORNER_TWISTED; |
380 | 282 |
int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6]))))); |
381 | 283 |
|
382 |
int locationOfFree0 = computeLocation(quats[1]); |
|
284 |
int locationOfFree0 = TBSkewb.computeLocation(quats[1]);
|
|
383 | 285 |
|
384 | 286 |
return center_perm_num+ 360*(totalTwist + 2187*locationOfFree0); |
385 | 287 |
} |
... | ... | |
500 | 402 |
|
501 | 403 |
if( mSolver!=null ) |
502 | 404 |
{ |
503 |
mSolver.createTablebase(-1);
|
|
504 |
mSolver.pack(); |
|
405 |
mSolver.createTablebase(2);
|
|
406 |
// mSolver.pack();
|
|
505 | 407 |
} |
506 | 408 |
} |
507 | 409 |
|
Also available in: Unified diff
Progess with Skewb solver.