Revision 202b167e
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/solvers/SolverPyraminx.java | ||
|---|---|---|
| 42 | 42 |
|
| 43 | 43 |
private static final int ERROR_CORNERS_CANNOT = -15; |
| 44 | 44 |
private static final int ERROR_VERTICES_CANNOT = -16; |
| 45 |
private static final int ERROR_CORNER_TWISTED = -17; |
|
| 46 |
private static final int ERROR_EDGE_TWISTED = -18; |
|
| 47 |
private static final int ERROR_C_V_DONT_MATCH = -19; |
|
| 48 |
private static final int ERROR_TWO_EDGES = -20; |
|
| 49 |
|
|
| 50 |
private static final int[][] edgeColors = new int[][] |
|
| 51 |
{
|
|
| 52 |
{3,2},{1,3},{0,3},{2,1},{2,0},{1,0} // order of those pairs determines edge twist
|
|
| 53 |
}; |
|
| 45 |
private static final int ERROR_EDGE_TWISTED = -17; |
|
| 46 |
private static final int ERROR_C_V_DONT_MATCH = -18; |
|
| 47 |
private static final int ERROR_TWO_EDGES = -19; |
|
| 54 | 48 |
|
| 55 | 49 |
private TablebasesAbstract mSolver; |
| 56 | 50 |
private int[] mCornerTwist; |
| ... | ... | |
| 127 | 121 |
|
| 128 | 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 129 | 123 |
|
| 130 |
private int checkAllEdgesPresent(int[][] edges) |
|
| 124 |
private int checkAllEdgesPresent(int[][] edges, int[][] edgeColors)
|
|
| 131 | 125 |
{
|
| 132 | 126 |
boolean[] present = new boolean[6]; |
| 133 | 127 |
for(int i=0; i<6; i++) present[i] = false; |
| ... | ... | |
| 234 | 228 |
|
| 235 | 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 236 | 230 |
|
| 237 |
private int[] computeEdgeQuats(int[][] edges) |
|
| 231 |
private int[] computeEdgeQuats(int[][] edges, int[][] edgeColors)
|
|
| 238 | 232 |
{
|
| 239 | 233 |
int[] quats = new int[6]; |
| 240 | 234 |
|
| ... | ... | |
| 320 | 314 |
edges[5][1] = object.getCubitFaceStickerIndex(12,0); // G |
| 321 | 315 |
} |
| 322 | 316 |
|
| 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 318 |
|
|
| 319 |
private int[][] computeEdgeColors(int[] faceColor) |
|
| 320 |
{
|
|
| 321 |
// The first pair being (2,3) means 'the first edge's first face is on the tetrahedron |
|
| 322 |
// face which oppeses corner number 2, and its second face on tetra face which opposes |
|
| 323 |
// corner number 3' |
|
| 324 |
// Order of those pairs determines edge twist. |
|
| 325 |
|
|
| 326 |
final int[][] edgeColorIndices = new int[][] { {2,3},{0,2},{1,2},{3,0},{3,1},{0,1} };
|
|
| 327 |
int[][] ret = new int[6][2]; |
|
| 328 |
|
|
| 329 |
for(int i=0; i<6; i++) |
|
| 330 |
{
|
|
| 331 |
ret[i][0] = faceColor[edgeColorIndices[i][0]]; |
|
| 332 |
ret[i][1] = faceColor[edgeColorIndices[i][1]]; |
|
| 333 |
} |
|
| 334 |
|
|
| 335 |
return ret; |
|
| 336 |
} |
|
| 337 |
|
|
| 323 | 338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 324 | 339 |
|
| 325 | 340 |
public int tablebaseIndex(TwistyObject object) |
| ... | ... | |
| 332 | 347 |
|
| 333 | 348 |
getCorners(object,corners); |
| 334 | 349 |
getVertices(object,vertices); |
| 335 |
getEdges(object,edges); |
|
| 336 | 350 |
|
| 337 | 351 |
int result1 = checkAllCornersPresent(corners); |
| 338 | 352 |
if( result1<0 ) return result1; |
| ... | ... | |
| 340 | 354 |
int result2 = checkAllVerticesPresent(vertices); |
| 341 | 355 |
if( result2<0 ) return result2; |
| 342 | 356 |
|
| 343 |
int result3 = checkAllEdgesPresent(edges); |
|
| 344 |
if( result3<0 ) return result3; |
|
| 345 |
|
|
| 346 | 357 |
int[] faces1 = computeFaceColors(corners); |
| 347 | 358 |
int[] faces2 = computeFaceColors(vertices); |
| 348 | 359 |
|
| 349 |
int result4 = checkAgreement(faces1,faces2); |
|
| 360 |
int result3 = checkAgreement(faces1,faces2); |
|
| 361 |
if( result3<0 ) return result3; |
|
| 362 |
|
|
| 363 |
int[][] edgeColors = computeEdgeColors(faces1); |
|
| 364 |
|
|
| 365 |
getEdges(object,edges); |
|
| 366 |
int result4 = checkAllEdgesPresent(edges,edgeColors); |
|
| 350 | 367 |
if( result4<0 ) return result4; |
| 351 | 368 |
|
| 352 | 369 |
for(int i=0; i<4; i++) |
| ... | ... | |
| 361 | 378 |
if( vertex_twist[i]<0 ) return ERROR_VERTICES_CANNOT; |
| 362 | 379 |
} |
| 363 | 380 |
|
| 364 |
int[] quats = computeEdgeQuats(edges); |
|
| 381 |
int[] quats = computeEdgeQuats(edges,edgeColors);
|
|
| 365 | 382 |
int[] permutation = new int[6]; |
| 366 | 383 |
TablebasesPyraminx.getEdgePermutation(permutation,quats,0); |
| 367 | 384 |
boolean even = TablebaseHelpers.permutationIsEven(permutation); |
| ... | ... | |
| 488 | 505 |
case ERROR_EDGE_YB_MISSING : return edgeError(res,2,1); |
| 489 | 506 |
case ERROR_EDGE_GB_MISSING : return edgeError(res,2,0); |
| 490 | 507 |
case ERROR_EDGE_GY_MISSING : return edgeError(res,1,0); |
| 491 |
case ERROR_CORNER_TWISTED : return res.getString(R.string.solver_generic_corner_twist); |
|
| 492 | 508 |
case ERROR_EDGE_TWISTED : return res.getString(R.string.solver_generic_edge_twist); |
| 493 | 509 |
case ERROR_CORNERS_CANNOT : return res.getString(R.string.solver_generic_corners_cannot); |
| 494 | 510 |
case ERROR_VERTICES_CANNOT : return res.getString(R.string.solver_generic_vertices_cannot); |
| ... | ... | |
| 548 | 564 |
int len1 = (moves1==null ? 0:moves1.length); |
| 549 | 565 |
int len2 = (moves2==null ? 0:moves2.length); |
| 550 | 566 |
|
| 551 |
int[][] moves = new int[len1+len2][]; |
|
| 552 |
|
|
| 553 |
android.util.Log.e("D", "len1="+len1+" len2="+len2);
|
|
| 567 |
int[][] moves = new int[len1+len2][3]; |
|
| 554 | 568 |
|
| 555 | 569 |
if( len1>0 ) System.arraycopy(moves1, 0, moves, 0, len1); |
| 556 | 570 |
if( len2>0 ) System.arraycopy(moves2, 0, moves, len1, len2); |
Also available in: Unified diff
Pyraminx solver: bugfix.