commit 57e86ed085d6018ca2b02cf2d3e253247a869b80
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Jun 10 15:07:28 2021 +0200

    Square-2: correct detecting the solved state.

diff --git a/src/main/java/org/distorted/objects/TwistySquare.java b/src/main/java/org/distorted/objects/TwistySquare.java
index 4c41128e..768da686 100644
--- a/src/main/java/org/distorted/objects/TwistySquare.java
+++ b/src/main/java/org/distorted/objects/TwistySquare.java
@@ -289,20 +289,6 @@ abstract class TwistySquare extends TwistyObject
     return BASIC_ANGLE;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public boolean isSolved()
-    {
-    int index = CUBITS[0].mQuatIndex;
-
-    for(int i=1; i<NUM_CUBITS; i++)
-      {
-      if( CUBITS[i].mQuatIndex != index ) return false;
-      }
-
-    return true;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // only needed for solvers - there are no Square solvers ATM)
 
diff --git a/src/main/java/org/distorted/objects/TwistySquare1.java b/src/main/java/org/distorted/objects/TwistySquare1.java
index 29271dfc..db385698 100644
--- a/src/main/java/org/distorted/objects/TwistySquare1.java
+++ b/src/main/java/org/distorted/objects/TwistySquare1.java
@@ -515,6 +515,20 @@ class TwistySquare1 extends TwistySquare
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public boolean isSolved()
+    {
+    int index = CUBITS[0].mQuatIndex;
+
+    for(int i=1; i<NUM_CUBITS; i++)
+      {
+      if( CUBITS[i].mQuatIndex != index ) return false;
+      }
+
+    return true;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int getObjectName(int numLayers)
diff --git a/src/main/java/org/distorted/objects/TwistySquare2.java b/src/main/java/org/distorted/objects/TwistySquare2.java
index 694a8a9a..c309777e 100644
--- a/src/main/java/org/distorted/objects/TwistySquare2.java
+++ b/src/main/java/org/distorted/objects/TwistySquare2.java
@@ -327,6 +327,43 @@ 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.
+
+  public boolean isSolved()
+    {
+    int index = CUBITS[0].mQuatIndex;
+
+    if( CUBITS[1].mQuatIndex!=index ) return false;
+
+    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 != index && CUBITS[i].mQuatIndex != indexZ ) return false;
+      }
+    for(int i=3; i<18; i+=2)
+      {
+      if( CUBITS[i].mQuatIndex != index && CUBITS[i].mQuatIndex != indexX ) return false;
+      }
+    for(int i=18; i<NUM_CUBITS; i+=2)
+      {
+      if( CUBITS[i].mQuatIndex != index && CUBITS[i].mQuatIndex != indexX ) return false;
+      }
+    for(int i=19; i<NUM_CUBITS; i+=2)
+      {
+      if( CUBITS[i].mQuatIndex != index && CUBITS[i].mQuatIndex != indexZ ) return false;
+      }
+
+    return true;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int getObjectName(int numLayers)
