commit 338e42aab7a8288ad7b2d6f3e59ce67065e016ea
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon May 9 22:17:45 2022 +0200

    Fixes for scrambling locally-produced bandaged cuboid.
    Still does not work completely.

diff --git a/src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java b/src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java
index ff7f3a93..78385e46 100644
--- a/src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java
+++ b/src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java
@@ -206,7 +206,7 @@ public class ObjectSignature
         if( getBit(index)!=0 )
           {
           float[] touch = getCubitTouchOfIndex(index);
-          if( belongsToTheLeft(touch,axis,layer) ) return false;
+          if( belongsLeft(touch,axis,layer) ) return false;
           }
 
     return true;
@@ -223,9 +223,10 @@ public class ObjectSignature
       float[][] cyc = mAllCycles[i];
       float[] p0 = cyc[0];
       float[] p1 = cyc[1];
+      float[] p2 = cyc[2];
 
-      if( (belongsToTheLeft(p0,axis,layer) && belongsToTheLeft(p1,axis,layer)) ||
-          (belongsToTheCent(p0,axis,layer) && belongsToTheCent(p1,axis,layer))  )
+      if( (belongsLeft(p0,axis,layer) && belongsLeft(p1,axis,layer) && belongsLeft(p2,axis,layer)) ||
+          (belongsCent(p0,axis,layer) && belongsCent(p1,axis,layer) && belongsCent(p2,axis,layer))  )
         {
         ret.cycle(turn,cyc);
         }
@@ -234,6 +235,20 @@ public class ObjectSignature
     return ret;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private boolean belongsLeft(float[] point, int axis, int layer)
+    {
+    return 2*point[axis]+mLayer[axis] == 2*layer;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private boolean belongsCent(float[] point, int axis, int layer)
+    {
+    return 2*point[axis]+mLayer[axis] == 2*layer+1;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void cycle(int turn, float[][] cyc)
@@ -456,20 +471,6 @@ public class ObjectSignature
     return -1;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private boolean belongsToTheLeft(float[] point, int axis, int layer)
-    {
-    return 2*point[axis]+mLayer[axis] == 2*layer;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private boolean belongsToTheCent(float[] point, int axis, int layer)
-    {
-    return 2*point[axis]+mLayer[axis] == 2*layer+1;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private int getIndexOfCubitTouch(float x, float y, float z)
diff --git a/src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java b/src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java
index 920f618c..ec48e34e 100644
--- a/src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java
+++ b/src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java
@@ -56,7 +56,6 @@ public class ObjectScrambler
   // type=2 , i.e. locally created bandaged cuboids
   private static ObjectSignature mSignature;
   private ArrayList<ScrambleStateBandagedCuboid> mBandagedStates;
-  private int[] mSize, mTurns;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -73,19 +72,6 @@ public class ObjectScrambler
       mCornerQuat = new int[8];
       mLastRot = LAST_SL;
       }
-    if( mType==2 )
-      {
-      mSize = new int[3];
-      mTurns= new int[3];
-
-      mSize[0] = (mNumLayers[0]>1 ? mNumLayers[0] : 0);
-      mSize[1] = (mNumLayers[1]>1 ? mNumLayers[1] : 0);
-      mSize[2] = (mNumLayers[2]>1 ? mNumLayers[2] : 0);
-
-      mTurns[0] = mNumLayers[1]==mNumLayers[2] ? 3:1;
-      mTurns[1] = mNumLayers[0]==mNumLayers[2] ? 3:1;
-      mTurns[2] = mNumLayers[0]==mNumLayers[1] ? 3:1;
-      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -421,39 +407,6 @@ public class ObjectScrambler
       }
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// TYPE 2
-
-  private void fillOutScramble(int[] scramble, int moveIndex)
-    {
-    for(int axis=0; axis<3; axis++)
-      {
-      int size = mTurns[axis]*mSize[axis];
-
-      if( moveIndex<size )
-        {
-        scramble[0] = axis;
-        scramble[1] = moveIndex/mTurns[axis];
-
-        if( mTurns[axis]==3 )
-          {
-          switch(moveIndex%3)
-            {
-            case 0: scramble[2] = -1; break;
-            case 1: scramble[2] =  2; break;
-            case 2: scramble[2] =  1; break;
-            }
-          }
-        else scramble[2] =  1;
-        return;
-        }
-
-      moveIndex -= size;
-      }
-
-    android.util.Log.e("D", "ERROR in fillOutScramble moveIndex="+moveIndex);
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // TYPE 2
 
@@ -480,7 +433,7 @@ public class ObjectScrambler
       int randMove = rnd.nextInt(numMoves);
       int moveIndex = currState.getNthMove(randMove,indexExcluded);
       mSignature = currState.getMove(moveIndex);
-      fillOutScramble(scramble[curr],moveIndex);
+      currState.fillOutScramble(scramble[curr],moveIndex);
       }
 
     ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
@@ -519,7 +472,7 @@ public class ObjectScrambler
     int randMove = rnd.nextInt(numMoves);
     int moveIndex = currState.getNthMove(randMove,indexExcluded);
     mSignature = currState.getMove(moveIndex);
-    fillOutScramble(scramble[curr],moveIndex);
+    currState.fillOutScramble(scramble[curr],moveIndex);
 
     ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
     mBandagedStates.add(nextState);
diff --git a/src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandagedCuboid.java b/src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandagedCuboid.java
index 69b6c8e1..7fda5557 100644
--- a/src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandagedCuboid.java
+++ b/src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandagedCuboid.java
@@ -35,7 +35,7 @@ public class ScrambleStateBandagedCuboid
 
   private final ObjectSignature[] mMoves;
   private final ObjectSignature mSignature;
-  private final int[] mLayer, mTurns;
+  private final int[] mLayer, mTurns, mSize;
   private final int mNumMoves;
   private final int mStartX, mStartY, mStartZ;
   private final boolean[][] mIsUnblocked;
@@ -46,6 +46,7 @@ public class ScrambleStateBandagedCuboid
     {
     mLayer = new int[3];
     mTurns = new int[3];
+    mSize  = new int[3];
 
     mIsUnblocked = new boolean[3][MAX_SUPPORTED_SIZE];
 
@@ -57,9 +58,13 @@ public class ScrambleStateBandagedCuboid
     mTurns[1] = mLayer[0]==mLayer[2] ? 3:1;
     mTurns[2] = mLayer[0]==mLayer[1] ? 3:1;
 
-    int xMoves = mLayer[0]>1 ? mTurns[0]*mLayer[0] : 0;
-    int yMoves = mLayer[1]>1 ? mTurns[1]*mLayer[1] : 0;
-    int zMoves = mLayer[2]>1 ? mTurns[2]*mLayer[2] : 0;
+    mSize[0] = (mLayer[0]>1 ? mLayer[0] : 0);
+    mSize[1] = (mLayer[1]>1 ? mLayer[1] : 0);
+    mSize[2] = (mLayer[2]>1 ? mLayer[2] : 0);
+
+    int xMoves = mTurns[0]*mSize[0];
+    int yMoves = mTurns[1]*mSize[1];
+    int zMoves = mTurns[2]*mSize[2];
 
     mNumMoves = xMoves + yMoves + zMoves;
 
@@ -210,12 +215,12 @@ printMoves();
       for(int layer=0; layer<mLayer[axis]; layer++)
         {
         mIsUnblocked[axis][layer] = mSignature.isUnblockedFromLeft(axis,layer);
-        android.util.Log.e("D", "unblocked from left: axis="+axis+" layer="+layer+" val="+mIsUnblocked[axis][layer]);
+        //android.util.Log.e("D", "unblocked from left: axis="+axis+" layer="+layer+" val="+mIsUnblocked[axis][layer]);
         }
 
     for(int axis=0; axis<3; axis++)
       if( mLayer[axis]>1 )
-        for(int turn=0; turn<mTurns[axis]; turn++)
+        for(int turn=1; turn<=mTurns[axis]; turn++)
           {
           boolean allLayersLocked = true;
 
@@ -241,6 +246,38 @@ printMoves();
     return ret;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void fillOutScramble(int[] scramble, int moveIndex)
+    {
+    for(int axis=0; axis<3; axis++)
+      {
+      int size = mTurns[axis]*mSize[axis];
+
+      if( moveIndex<size )
+        {
+        scramble[0] = axis;
+        scramble[1] = moveIndex % mSize[axis];
+
+        if( mTurns[axis]==3 )
+          {
+          switch(moveIndex/mSize[axis])
+            {
+            case 0: scramble[2] =-1; break;
+            case 1: scramble[2] = 2; break;
+            case 2: scramble[2] = 1; break;
+            }
+          }
+        else scramble[2] = 1;
+        return;
+        }
+
+      moveIndex -= size;
+      }
+
+    android.util.Log.e("D", "ERROR in fillOutScramble moveIndex="+moveIndex);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void printMoves()
