Revision ad6f6f03
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/objects/TwistyDiamond.java | ||
|---|---|---|
| 38 | 38 |
import org.distorted.library.type.Static1D; |
| 39 | 39 |
import org.distorted.library.type.Static3D; |
| 40 | 40 |
import org.distorted.library.type.Static4D; |
| 41 |
import org.distorted.main.RubikSurfaceView; |
|
| 41 | 42 |
|
| 42 | 43 |
import java.util.Random; |
| 43 | 44 |
|
| ... | ... | |
| 589 | 590 |
return 0; |
| 590 | 591 |
} |
| 591 | 592 |
|
| 593 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 594 |
|
|
| 595 |
int mulQuat(int q1, int q2) |
|
| 596 |
{
|
|
| 597 |
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]); |
|
| 598 |
|
|
| 599 |
float rX = result.get0(); |
|
| 600 |
float rY = result.get1(); |
|
| 601 |
float rZ = result.get2(); |
|
| 602 |
float rW = result.get3(); |
|
| 603 |
|
|
| 604 |
final float MAX_ERROR = 0.1f; |
|
| 605 |
float dX,dY,dZ,dW; |
|
| 606 |
|
|
| 607 |
for(int i=0; i<QUATS.length; i++) |
|
| 608 |
{
|
|
| 609 |
dX = QUATS[i].get0() - rX; |
|
| 610 |
dY = QUATS[i].get1() - rY; |
|
| 611 |
dZ = QUATS[i].get2() - rZ; |
|
| 612 |
dW = QUATS[i].get3() - rW; |
|
| 613 |
|
|
| 614 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
| 615 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
| 616 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
| 617 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
| 618 |
|
|
| 619 |
dX = QUATS[i].get0() + rX; |
|
| 620 |
dY = QUATS[i].get1() + rY; |
|
| 621 |
dZ = QUATS[i].get2() + rZ; |
|
| 622 |
dW = QUATS[i].get3() + rW; |
|
| 623 |
|
|
| 624 |
if( dX<MAX_ERROR && dX>-MAX_ERROR && |
|
| 625 |
dY<MAX_ERROR && dY>-MAX_ERROR && |
|
| 626 |
dZ<MAX_ERROR && dZ>-MAX_ERROR && |
|
| 627 |
dW<MAX_ERROR && dW>-MAX_ERROR ) return i; |
|
| 628 |
} |
|
| 629 |
|
|
| 630 |
return -1; |
|
| 631 |
} |
|
| 632 |
|
|
| 592 | 633 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 593 | 634 |
// The Diamond is solved if and only if: |
| 594 | 635 |
// |
| 595 |
// ?? |
|
| 636 |
// 1) all 5 octahedrons are rotated with the same quat |
|
| 637 |
// 2) the 8 tetrahedrons are rotated with the quat and, optionally, the can also be rotated |
|
| 638 |
// by multitudes of 120 degrees along the face they are the center of. |
|
| 639 |
// |
|
| 640 |
// so: |
|
| 641 |
// 1) cubits 6,12: can also be QUAT 6,10 |
|
| 642 |
// 2) cubits 7,13: can also be QUAT 4,8 |
|
| 643 |
// 3) cubits 8,10: can also be QUAT 7,11 |
|
| 644 |
// 4) cubits 9,11: can also be QUAT 5,9 |
|
| 596 | 645 |
|
| 597 | 646 |
public boolean isSolved() |
| 598 | 647 |
{
|
| 599 | 648 |
int q = CUBITS[0].mQuatIndex; |
| 600 | 649 |
|
| 601 |
return ( CUBITS[ 1].mQuatIndex == q && |
|
| 602 |
CUBITS[ 2].mQuatIndex == q && |
|
| 603 |
CUBITS[ 3].mQuatIndex == q && |
|
| 604 |
CUBITS[ 4].mQuatIndex == q && |
|
| 605 |
CUBITS[ 5].mQuatIndex == q && |
|
| 606 |
CUBITS[ 6].mQuatIndex == q && |
|
| 607 |
CUBITS[ 7].mQuatIndex == q && |
|
| 608 |
CUBITS[ 8].mQuatIndex == q && |
|
| 609 |
CUBITS[ 9].mQuatIndex == q && |
|
| 610 |
CUBITS[10].mQuatIndex == q && |
|
| 611 |
CUBITS[11].mQuatIndex == q && |
|
| 612 |
CUBITS[12].mQuatIndex == q && |
|
| 613 |
CUBITS[13].mQuatIndex == q ); |
|
| 650 |
if ( CUBITS[ 1].mQuatIndex == q && |
|
| 651 |
CUBITS[ 2].mQuatIndex == q && |
|
| 652 |
CUBITS[ 3].mQuatIndex == q && |
|
| 653 |
CUBITS[ 4].mQuatIndex == q && |
|
| 654 |
CUBITS[ 5].mQuatIndex == q ) |
|
| 655 |
{
|
|
| 656 |
int q1 = mulQuat(q,5); |
|
| 657 |
int q2 = mulQuat(q,9); |
|
| 658 |
|
|
| 659 |
if( CUBITS[ 9].mQuatIndex != q && CUBITS[ 9].mQuatIndex != q1 && CUBITS[ 9].mQuatIndex != q2 ) return false; |
|
| 660 |
if( CUBITS[11].mQuatIndex != q && CUBITS[11].mQuatIndex != q1 && CUBITS[11].mQuatIndex != q2 ) return false; |
|
| 661 |
|
|
| 662 |
q1 = mulQuat(q,4); |
|
| 663 |
q2 = mulQuat(q,8); |
|
| 664 |
|
|
| 665 |
if( CUBITS[ 7].mQuatIndex != q && CUBITS[ 7].mQuatIndex != q1 && CUBITS[ 7].mQuatIndex != q2 ) return false; |
|
| 666 |
if( CUBITS[13].mQuatIndex != q && CUBITS[13].mQuatIndex != q1 && CUBITS[13].mQuatIndex != q2 ) return false; |
|
| 667 |
|
|
| 668 |
q1 = mulQuat(q,6); |
|
| 669 |
q2 = mulQuat(q,10); |
|
| 670 |
|
|
| 671 |
if( CUBITS[ 6].mQuatIndex != q && CUBITS[ 6].mQuatIndex != q1 && CUBITS[ 6].mQuatIndex != q2 ) return false; |
|
| 672 |
if( CUBITS[12].mQuatIndex != q && CUBITS[12].mQuatIndex != q1 && CUBITS[12].mQuatIndex != q2 ) return false; |
|
| 673 |
|
|
| 674 |
q1 = mulQuat(q,7); |
|
| 675 |
q2 = mulQuat(q,11); |
|
| 676 |
|
|
| 677 |
if( CUBITS[ 8].mQuatIndex != q && CUBITS[ 8].mQuatIndex != q1 && CUBITS[ 8].mQuatIndex != q2 ) return false; |
|
| 678 |
if( CUBITS[10].mQuatIndex != q && CUBITS[10].mQuatIndex != q1 && CUBITS[10].mQuatIndex != q2 ) return false; |
|
| 679 |
|
|
| 680 |
return true; |
|
| 681 |
} |
|
| 682 |
|
|
| 683 |
return false; |
|
| 614 | 684 |
} |
| 615 | 685 |
|
| 616 | 686 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fix Diamond's isSolved()