commit 121e4a398b962c31f7fb1d45d9fa9fd6dfe7d656
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Apr 23 16:03:03 2021 +0200

    Fix solved state detection of the Dino4

diff --git a/src/main/java/org/distorted/objects/TwistyDino.java b/src/main/java/org/distorted/objects/TwistyDino.java
index 5a4c2eb9..eb64f545 100644
--- a/src/main/java/org/distorted/objects/TwistyDino.java
+++ b/src/main/java/org/distorted/objects/TwistyDino.java
@@ -71,7 +71,7 @@ public abstract class TwistyDino extends TwistyObject
          };
 
   // centers of the 12 edges. Must be in the same order like QUATs above.
-  private static final float[][] CENTERS = new float[][]
+  static final float[][] CENTERS = new float[][]
          {
              { 0.0f, 1.5f, 1.5f },
              { 1.5f, 0.0f, 1.5f },
diff --git a/src/main/java/org/distorted/objects/TwistyDino4.java b/src/main/java/org/distorted/objects/TwistyDino4.java
index 38e3975d..6f64d2ff 100644
--- a/src/main/java/org/distorted/objects/TwistyDino4.java
+++ b/src/main/java/org/distorted/objects/TwistyDino4.java
@@ -26,6 +26,7 @@ import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
 import org.distorted.library.type.Static4D;
 import org.distorted.main.R;
+import org.distorted.main.RubikSurfaceView;
 
 import java.util.Random;
 
@@ -33,9 +34,51 @@ import java.util.Random;
 
 public class TwistyDino4 extends TwistyDino
 {
-  private static final int[] mFaceMap = {4,4, 2,2, 2,2, 4,4,
-                                         0,0, 2,2, 1,1, 4,4,
-                                         0,0, 0,0, 1,1, 1,1 };
+  private static final int[] mFaceMap = { 4, 2, 2, 4, 0, 2, 1, 4, 0, 0, 1, 1 };
+  private static final int[][] mScramble;
+
+  static
+    {
+    int numQuats = QUATS.length;
+    int numCenters = CENTERS.length;
+
+    mScramble = new int[numQuats][numCenters];
+
+    for(int q=0; q<numQuats; q++)
+      for(int c=0; c<numCenters; c++) mScramble[q][c] = computeScramble(q,c);
+    }
+
+  private final int[] mColors = new int[CENTERS.length];
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static int computeScramble(int quatNum, int centerNum)
+    {
+    float MAXDIFF = 0.01f;
+    float[] center= CENTERS[centerNum];
+    Static4D sc = new Static4D(center[0], center[1], center[2], 1.0f);
+    Static4D result = RubikSurfaceView.rotateVectorByQuat(sc,QUATS[quatNum]);
+    int numCenters = CENTERS.length;
+
+    float x = result.get0();
+    float y = result.get1();
+    float z = result.get2();
+
+    for(int c=0; c<numCenters; c++)
+      {
+      float[] cent = CENTERS[c];
+
+      float qx = cent[0] - x;
+      float qy = cent[1] - y;
+      float qz = cent[2] - z;
+
+      if( qx>-MAXDIFF && qx<MAXDIFF &&
+          qy>-MAXDIFF && qy<MAXDIFF &&
+          qz>-MAXDIFF && qz<MAXDIFF  ) return c;
+      }
+
+    return -1;
+    }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -49,12 +92,7 @@ public class TwistyDino4 extends TwistyDino
 
   int getFaceColor(int cubit, int cubitface, int size)
     {
-    switch(cubitface)
-      {
-      case 0 : return mFaceMap[2*cubit];
-      case 1 : return mFaceMap[2*cubit+1];
-      default: return NUM_FACES;
-      }
+    return (cubitface==0 || cubitface==1) ? mFaceMap[cubit] : NUM_TEXTURES;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -88,81 +126,31 @@ public class TwistyDino4 extends TwistyDino
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// Dino4 is solved if and only if the four groups of three same-colored cubits are each 'together'
-// (actually we need to check only 3 first groups - if those are correct, the fourth one also needs
-// to be correct).
-//
-// White group : (X,Y,Z) = 10,11,6
-// Red group   : (X,Y,Z) = 0,3,7
-// Blue group  : (X,Y,Z) = 2,1,5
-// Yellow group: (X,Y,Z) = 8,9,4
-//
-// A group of 3 cubits is 'together' if and only if they are all rotated with one quat - but we cannot
-// forget that the whole Dino can be mirrored! (so then qY = qX*Q2 and qZ = qX*Q8 )
-//
-// X cubits: 0, 2, 8, 10
-// Y cubits: 1, 3, 9, 11
-// Z cubits: 4, 5, 6, 7
+// Dino4 is solved if and only if groups of cubits
+// (0,3,7), (1,2,5), (4,8,9), (6,10,11)
+// or
+// (0,1,4), (2,3,6), (5,9,10), (7,8,11)
+// are all the same color.
 
   public boolean isSolved()
     {
-android.util.Log.e("D",
-
-CUBITS[ 0].mQuatIndex+" "+
-CUBITS[ 1].mQuatIndex+" "+
-CUBITS[ 2].mQuatIndex+" "+
-CUBITS[ 3].mQuatIndex+" "+
-CUBITS[ 4].mQuatIndex+" "+
-CUBITS[ 5].mQuatIndex+" "+
-CUBITS[ 6].mQuatIndex+" "+
-CUBITS[ 7].mQuatIndex+" "+
-CUBITS[ 8].mQuatIndex+" "+
-CUBITS[ 9].mQuatIndex+" "+
-CUBITS[10].mQuatIndex+" "+
-CUBITS[11].mQuatIndex
-
-);
-
-    int redX = CUBITS[0].mQuatIndex;
-    int bluX = CUBITS[2].mQuatIndex;
-    int yelX = CUBITS[8].mQuatIndex;
-
-    if (CUBITS[3].mQuatIndex == redX && CUBITS[7].mQuatIndex == redX &&
-        CUBITS[1].mQuatIndex == bluX && CUBITS[5].mQuatIndex == bluX &&
-        CUBITS[9].mQuatIndex == yelX && CUBITS[4].mQuatIndex == yelX  ) return true;
-
-    if (CUBITS[3].mQuatIndex != mulQuat(redX,2))
-      {
-      android.util.Log.e("D", "FALSE 1");
-      return false;
-      }
-    if (CUBITS[7].mQuatIndex != mulQuat(redX,8))
-      {
-      android.util.Log.e("D", "FALSE 2");
-      return false;
-      }
-    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2))
-      {
-      android.util.Log.e("D", "FALSE 3");
-      return false;
-      }
-    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8))
-      {
-      android.util.Log.e("D", "FALSE 4");
-      return false;
-      }
-    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2))
-      {
-      android.util.Log.e("D", "FALSE 5");
-      return false;
-      }
-    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8))
+    int numCenters = CENTERS.length;
+
+    for(int c=0; c<numCenters; c++)
       {
-      android.util.Log.e("D", "FALSE 6");
-      return false;
+      int index = mScramble[CUBITS[c].mQuatIndex][c];
+      mColors[c] = mFaceMap[index];
       }
 
-    return true;
+    if( mColors[0]==mColors[3] && mColors[0]==mColors[7] &&
+        mColors[1]==mColors[2] && mColors[1]==mColors[5] &&
+        mColors[4]==mColors[8] && mColors[4]==mColors[9]  ) return true;
+
+    if( mColors[0]==mColors[1] && mColors[0]==mColors[4] &&
+        mColors[2]==mColors[3] && mColors[2]==mColors[6] &&
+        mColors[5]==mColors[9] && mColors[5]==mColors[10] ) return true;
+
+    return false;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
