commit e42a9e87ac14a91792b55548678d24727a7a2166
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Sep 1 22:24:15 2021 +0200

    Fix the Square-2 isSolved()  (it was wrong even before!)

diff --git a/src/main/java/org/distorted/objects/TwistyObject.java b/src/main/java/org/distorted/objects/TwistyObject.java
index c74bda85..b8e230da 100644
--- a/src/main/java/org/distorted/objects/TwistyObject.java
+++ b/src/main/java/org/distorted/objects/TwistyObject.java
@@ -454,6 +454,7 @@ public abstract class TwistyObject extends DistortedNode
     if( mSolvedFunctionIndex==0 ) return isSolved0();
     if( mSolvedFunctionIndex==1 ) return isSolved1();
     if( mSolvedFunctionIndex==2 ) return isSolved2();
+    if( mSolvedFunctionIndex==3 ) return isSolved3();
 
     return false;
     }
@@ -588,7 +589,44 @@ public abstract class TwistyObject extends DistortedNode
       }
 
     return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Square-2 is solved iff
+// a) all of its cubits are rotated with the same quat
+// b) its two 'middle' cubits are rotated with the same quat, the 6 'front' and 6 'back'
+// edges and corners with this quat multiplied by QUATS[18] (i.e. those are upside down)
+// and all the 12 left and right edges and corners also with the same quat multiplied by
+// QUATS[12] - i.e. also upside down.
+
+  public boolean isSolved3()
+    {
+    int index = CUBITS[0].mQuatIndex;
+
+    if( CUBITS[1].mQuatIndex!=index ) return false;
+
+    boolean solved = true;
+
+    for(int i=2; i<NUM_CUBITS; i++)
+      {
+      if( CUBITS[i].mQuatIndex!=index )
+        {
+        solved = false;
+        break;
+        }
+      }
 
+    if( solved ) return true;
+
+    int indexX = mulQuat(index,12);  // QUATS[12] = 180deg (1,0,0)
+    int indexZ = mulQuat(index,18);  // QUATS[18] = 180deg (0,0,1)
+
+    for(int i= 2; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
+    for(int i= 3; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
+    for(int i=18; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
+    for(int i=19; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
+
+    return true;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/TwistySquare.java b/src/main/java/org/distorted/objects/TwistySquare.java
index 9910095a..957c98ab 100644
--- a/src/main/java/org/distorted/objects/TwistySquare.java
+++ b/src/main/java/org/distorted/objects/TwistySquare.java
@@ -220,13 +220,6 @@ abstract class TwistySquare extends TwistyObject
     return FACE_COLORS[face];
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  int getSolvedFunctionIndex()
-    {
-    return 0;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 
diff --git a/src/main/java/org/distorted/objects/TwistySquare1.java b/src/main/java/org/distorted/objects/TwistySquare1.java
index f58f8532..675d6751 100644
--- a/src/main/java/org/distorted/objects/TwistySquare1.java
+++ b/src/main/java/org/distorted/objects/TwistySquare1.java
@@ -260,6 +260,13 @@ class TwistySquare1 extends TwistySquare
     return CENTERS;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getSolvedFunctionIndex()
+    {
+    return 0;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int getNumStickerTypes(int numLayers)
diff --git a/src/main/java/org/distorted/objects/TwistySquare2.java b/src/main/java/org/distorted/objects/TwistySquare2.java
index f16fd775..f4025bf1 100644
--- a/src/main/java/org/distorted/objects/TwistySquare2.java
+++ b/src/main/java/org/distorted/objects/TwistySquare2.java
@@ -182,29 +182,9 @@ class TwistySquare2 extends TwistySquare
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// Square-2 is solved iff
-// a) all of its cubits are rotated with the same quat
-// b) its two 'middle' cubits are rotated with the same quat, the 6 'front' and 6 'back'
-// edges and corners with this quat multiplied by QUATS[18] (i.e. those are upside down)
-// and all the 12 left and right edges and corners also with the same quat multiplied by
-// QUATS[12] - i.e. also upside down.
-
-  private static final int[] S18 = new int[] {18};
-  private static final int[] S12 = new int[] {12};
 
   int[] getSolvedQuats(int cubit, int numLayers)
     {
-    switch(cubit)
-      {
-      case  0: case  1: return null;
-      case  2: case  4: case  6: case  8:
-      case 10: case 12: case 14: case 16:
-      case 19: case 21: case 23: case 25: return S18;
-      case  3: case  5: case  7: case  9:
-      case 11: case 13: case 15: case 17:
-      case 18: case 20: case 22: case 24: return S12;
-      }
-
     return null;
     }
 
@@ -281,6 +261,13 @@ class TwistySquare2 extends TwistySquare
     return CENTERS;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getSolvedFunctionIndex()
+    {
+    return 3;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int getNumStickerTypes(int numLayers)
