commit 01b2ef5a11c6fd457d8bcaf08a973ffddba0d92f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Aug 30 19:33:17 2021 +0200

    Convert Skewbs & Rex Cube to the new, unified scrambling method.

diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
index c453e866..76101fdb 100644
--- a/src/main/java/org/distorted/objects/TwistyRex.java
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -23,6 +23,7 @@ import android.content.res.Resources;
 
 import org.distorted.helpers.ObjectShape;
 import org.distorted.helpers.ObjectSticker;
+import org.distorted.helpers.ScrambleStateGraph;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
@@ -152,12 +153,23 @@ public class TwistyRex extends TwistyObject
       }
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleStateGraph[] mStates;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
     {
     super(size, size, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
+
+    int[] tmp = {0,-1,0, 0,1,0, 2,-1,0, 2,1,0 };
+
+    mStates = new ScrambleStateGraph[]
+      {
+      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
+      };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -481,25 +493,24 @@ public class TwistyRex extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
+  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
     {
     if( curr==0 )
       {
-      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
-      }
-    else
-      {
-      int newVector = rnd.nextInt(NUM_AXIS -1);
-      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
+      mCurrState     = 0;
+      mIndexExcluded =-1;
       }
 
-    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : 2;
+    int total = mStates[mCurrState].getTotal(mIndexExcluded);
+    int random= rnd.nextInt(total);
+    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
 
-    switch( rnd.nextInt(2) )
-      {
-      case 0: scramble[curr][2] = -1; break;
-      case 1: scramble[curr][2] =  1; break;
-      }
+    scramble[curr][0] = info[0];
+    scramble[curr][1] = info[1];
+    scramble[curr][2] = info[2];
+
+    mCurrState     = info[3];
+    mIndexExcluded = info[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/TwistySkewb.java b/src/main/java/org/distorted/objects/TwistySkewb.java
index 26c0c5ce..9bcdb908 100644
--- a/src/main/java/org/distorted/objects/TwistySkewb.java
+++ b/src/main/java/org/distorted/objects/TwistySkewb.java
@@ -23,6 +23,7 @@ import android.content.res.Resources;
 
 import org.distorted.helpers.ObjectShape;
 import org.distorted.helpers.ObjectSticker;
+import org.distorted.helpers.ScrambleStateGraph;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
@@ -189,12 +190,23 @@ public class TwistySkewb extends TwistyObject
       }
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleStateGraph[] mStates;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistySkewb(int size, Static4D quat, DistortedTexture texture,
               MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
     {
     super(size, 2*size-2, quat, texture, mesh, effects, moves, ObjectList.SKEW, res, scrWidth);
+
+    int[] tmp = {0,-1,0, 0,1,0, size-1,-1,0, size-1,1,0 };
+
+    mStates = new ScrambleStateGraph[]
+      {
+      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
+      };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -599,25 +611,24 @@ public class TwistySkewb extends TwistyObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
+  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
     {
     if( curr==0 )
       {
-      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
-      }
-    else
-      {
-      int newVector = rnd.nextInt(NUM_AXIS-1);
-      scramble[curr][0] = (newVector>=scramble[curr-1][0] ? newVector+1 : newVector);
+      mCurrState     = 0;
+      mIndexExcluded =-1;
       }
 
-    scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0 : getNumLayers()-1;
+    int total = mStates[mCurrState].getTotal(mIndexExcluded);
+    int random= rnd.nextInt(total);
+    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
 
-    switch( rnd.nextInt(2) )
-      {
-      case 0: scramble[curr][2] = -1; break;
-      case 1: scramble[curr][2] =  1; break;
-      }
+    scramble[curr][0] = info[0];
+    scramble[curr][1] = info[1];
+    scramble[curr][2] = info[2];
+
+    mCurrState     = info[3];
+    mIndexExcluded = info[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
