Revision 1eafa9c6
Added by Leszek Koltunski almost 2 years ago
| src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java | ||
|---|---|---|
| 44 | 44 |
}; |
| 45 | 45 |
|
| 46 | 46 |
private int[][] mSurfaceTable; |
| 47 |
private int[][] mFaceColorTable; |
|
| 47 |
private int[][] mTmpFaceColorTable;
|
|
| 48 | 48 |
private int[][] mCubitFaceToSurfaceMap; |
| 49 |
private int[][] mCubitFaceColor; |
|
| 49 |
private int[][] mCubitFaceToPuzzleFaceMap; |
|
| 50 |
private int[] mPuzzleFaceColor; |
|
| 50 | 51 |
|
| 51 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 | 53 |
// remember about the double cover or unit quaternions! |
| ... | ... | |
| 324 | 325 |
int numVariants = mParent.getNumCubitVariants(numLayers); |
| 325 | 326 |
ObjectShape[] shapes = new ObjectShape[numVariants]; |
| 326 | 327 |
mCubitFaceToSurfaceMap = new int[numCubits][]; |
| 327 |
mCubitFaceColor = new int[numCubits][];
|
|
| 328 |
mCubitFaceToPuzzleFaceMap = new int[numCubits][];
|
|
| 328 | 329 |
|
| 329 | 330 |
for(int v=0; v<numVariants; v++) shapes[v] = mParent.getObjectShape(v); |
| 330 | 331 |
|
| ... | ... | |
| 335 | 336 |
int variant = mParent.getCubitVariant(c,numLayers); |
| 336 | 337 |
ObjectShape s = shapes[variant]; |
| 337 | 338 |
int numFaces = s.getNumFaces(); |
| 338 |
mCubitFaceColor[c] = new int[numFaces];
|
|
| 339 |
mCubitFaceToPuzzleFaceMap[c] = new int[numFaces];
|
|
| 339 | 340 |
mCubitFaceToSurfaceMap[c] = new int[numFaces]; |
| 340 | 341 |
for(int f=0; f<numFaces; f++) mCubitFaceToSurfaceMap[c][f] = -1; |
| 341 | 342 |
|
| ... | ... | |
| 358 | 359 |
|
| 359 | 360 |
for(int f=0; f<numFaces; f++) |
| 360 | 361 |
{
|
| 361 |
mCubitFaceColor[c][f] = mParent.getCubitFaceColor(c,f);
|
|
| 362 |
mCubitFaceToPuzzleFaceMap[c][f] = mParent.getCubitFaceColor(c,f);
|
|
| 362 | 363 |
|
| 363 |
if( !mParent.faceIsOuter(c,f) ) continue;
|
|
| 364 |
//android.util.Log.e("D", "cubit "+c+" face "+f+" puzzle face: "+ mCubitFaceToPuzzleFaceMap[c][f]);
|
|
| 364 | 365 |
|
| 365 |
//android.util.Log.e("D", "cubit "+c+" face "+f);
|
|
| 366 |
if( !mParent.faceIsOuter(c,f) ) continue;
|
|
| 366 | 367 |
|
| 367 | 368 |
float[] surface = new float[4]; |
| 368 | 369 |
float[] rotPoint = new float[4]; |
| ... | ... | |
| 400 | 401 |
{
|
| 401 | 402 |
float[] ts = multiplySurface(surface, mObjectQuats[q]); |
| 402 | 403 |
int ind = adjoinNewSurface(tmpSurfaces,ts); |
| 403 |
/* |
|
| 404 |
if( ind==6 || ind==5 ) |
|
| 405 |
{
|
|
| 406 |
android.util.Log.e("D","SURFACE "+ind+": "+ts[0]+" "+ts[1]+" "+ts[2]+" "+ts[3] );
|
|
| 407 |
} |
|
| 408 |
*/ |
|
| 409 | 404 |
indices[q] = ind; |
| 410 | 405 |
} |
| 411 | 406 |
|
| ... | ... | |
| 572 | 567 |
private int surfaceColor(int filled, int surface) |
| 573 | 568 |
{
|
| 574 | 569 |
for(int s=0; s<filled; s++) |
| 575 |
if( mFaceColorTable[s][0] == surface ) return mFaceColorTable[s][1];
|
|
| 570 |
if( mTmpFaceColorTable[s][0] == surface ) return mTmpFaceColorTable[s][1];
|
|
| 576 | 571 |
|
| 577 |
return -1;
|
|
| 572 |
return 0;
|
|
| 578 | 573 |
} |
| 579 | 574 |
|
| 580 | 575 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 582 | 577 |
private boolean isSolved2(TwistyObjectCubit[] cubits) |
| 583 | 578 |
{
|
| 584 | 579 |
int filled = 0; |
| 585 |
int max = mFaceColorTable.length; |
|
| 580 |
int max = mTmpFaceColorTable.length;
|
|
| 586 | 581 |
|
| 587 | 582 |
for(int c=0; c<mNumCubits; c++) |
| 588 | 583 |
{
|
| ... | ... | |
| 595 | 590 |
|
| 596 | 591 |
if( initSurface>=0 ) |
| 597 | 592 |
{
|
| 598 |
int currSurface = mSurfaceTable[initSurface][quat]; |
|
| 599 |
int currColor = mCubitFaceColor[c][f]; |
|
| 600 |
int prevColor = surfaceColor(filled,currSurface); |
|
| 593 |
int puzzleFace = mCubitFaceToPuzzleFaceMap[c][f]; |
|
| 594 |
int currSurface= mSurfaceTable[initSurface][quat]; |
|
| 595 |
int currColor = puzzleFace>=0 ? mPuzzleFaceColor[puzzleFace] : 0; |
|
| 596 |
int prevColor = surfaceColor(filled,currSurface); |
|
| 601 | 597 |
|
| 602 |
if( prevColor<0 ) |
|
| 598 |
//android.util.Log.e("D", "cubit "+c+" face "+f+" puzzleFace: "+puzzleFace+" currColor: "+currColor+" prevColor: "+prevColor);
|
|
| 599 |
|
|
| 600 |
if( prevColor==0 ) |
|
| 603 | 601 |
{
|
| 604 |
if( filled>=max ) return false; |
|
| 605 |
mFaceColorTable[filled][0] = currSurface; |
|
| 606 |
mFaceColorTable[filled][1] = currColor; |
|
| 602 |
if( filled>=max ) |
|
| 603 |
{
|
|
| 604 |
//android.util.Log.e("D", "false1");
|
|
| 605 |
return false; |
|
| 606 |
} |
|
| 607 |
mTmpFaceColorTable[filled][0] = currSurface; |
|
| 608 |
mTmpFaceColorTable[filled][1] = currColor; |
|
| 607 | 609 |
prevColor = currColor; |
| 608 | 610 |
filled++; |
| 609 | 611 |
} |
| 610 | 612 |
|
| 611 |
if( prevColor!=currColor ) return false; |
|
| 613 |
if( prevColor!=currColor ) |
|
| 614 |
{
|
|
| 615 |
//android.util.Log.e("D", "false2");
|
|
| 616 |
return false; |
|
| 617 |
} |
|
| 612 | 618 |
} |
| 613 | 619 |
} |
| 614 | 620 |
} |
| 615 | 621 |
|
| 622 |
// android.util.Log.e("D", "true");
|
|
| 616 | 623 |
return true; |
| 617 | 624 |
} |
| 618 | 625 |
|
| ... | ... | |
| 697 | 704 |
if( mFunctionIndex==2 ) |
| 698 | 705 |
{
|
| 699 | 706 |
computeSurfaceTable(); |
| 700 |
int numFaces = parent.getNumFaces(); |
|
| 701 |
mFaceColorTable = new int[numFaces][2]; |
|
| 707 |
int numFaces = parent.getNumPuzzleFaces();
|
|
| 708 |
mTmpFaceColorTable = new int[numFaces][2];
|
|
| 702 | 709 |
} |
| 703 | 710 |
} |
| 704 | 711 |
|
| 712 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 713 |
|
|
| 714 |
void setPuzzleFaceColor(int[] color) |
|
| 715 |
{
|
|
| 716 |
mPuzzleFaceColor = color; |
|
| 717 |
} |
|
| 718 |
|
|
| 705 | 719 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 706 | 720 |
|
| 707 | 721 |
boolean isSolved(TwistyObjectCubit[] cubits) |
Also available in: Unified diff
Fix the detection of the solved state.