commit cda32fc19974f5428851c358133654579abefa65
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Aug 31 18:12:51 2021 +0200

    Convert the Redi to the new scrambling paradigm.

diff --git a/src/main/java/org/distorted/helpers/ScrambleState.java b/src/main/java/org/distorted/helpers/ScrambleState.java
index dc396c98..6a9da810 100644
--- a/src/main/java/org/distorted/helpers/ScrambleState.java
+++ b/src/main/java/org/distorted/helpers/ScrambleState.java
@@ -138,18 +138,4 @@ public class ScrambleState
     {
     return ( indexExcluded>=0 && indexExcluded<mNumAxis ) ? mTotal-mNum[indexExcluded] : mTotal;
     }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public int[] getInfo(int num, int indexExcluded)
-    {
-    int index = getIndex(num,indexExcluded);
-
-    mTmp[0] = mInfo[LEN*index  ];   // axis
-    mTmp[1] = mInfo[LEN*index+1];   // row
-    mTmp[2] = mInfo[LEN*index+2];   // angle
-    mTmp[3] = mInfo[LEN*index+3];   // next state
-
-    return mTmp;
-    }
 }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/objects/TwistyRedi.java b/src/main/java/org/distorted/objects/TwistyRedi.java
index 3b4db123..0b213eb9 100644
--- a/src/main/java/org/distorted/objects/TwistyRedi.java
+++ b/src/main/java/org/distorted/objects/TwistyRedi.java
@@ -23,6 +23,7 @@ import android.content.res.Resources;
 
 import org.distorted.helpers.ObjectShape;
 import org.distorted.helpers.ObjectSticker;
+import org.distorted.helpers.ScrambleState;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshSquare;
@@ -185,10 +186,6 @@ public class TwistyRedi extends TwistyObject
              { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
           };
 
-  private static int[][] mScrambleTable;
-  private static int[] mPossibleAxis, mPossibleLayers;
-  private static int[] mNumOccurences;
-
   private static final ObjectSticker[] mStickers;
 
   static
@@ -205,12 +202,31 @@ public class TwistyRedi extends TwistyObject
       }
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleState[] mStates;
+  private int[][] mScrambleTable;
+  private int[] mNumOccurences;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyRedi(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.REDI, res, scrWidth);
+
+    mStates = new ScrambleState[]
+      {
+      new ScrambleState( new int[][] { {0,1,1,0,-1,1, 2,1,2,2,-1,2},{0,1,3,0,-1,3, 2,1,4,2,-1,4},{0,1,5,0,-1,5, 2,1,6,2,-1,6},{0,1,7,0,-1,7, 2,1,8,2,-1,8} } ),
+      new ScrambleState( new int[][] { {                          },{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
+      new ScrambleState( new int[][] { {                          },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
+      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{                          },{              2,1,6,2,-1,6},{0,1,7,0,-1,7              } } ),
+      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{                          },{0,1,5,0,-1,5,             },{              2,1,8,2,-1,8} } ),
+      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{                          },{0,1,7,0,-1,7              } } ),
+      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{                          },{              2,1,8,2,-1,8} } ),
+      new ScrambleState( new int[][] { {              2,1,2,2,-1,2},{0,1,3,0,-1,3              },{0,1,5,0,-1,5,             },{                          } } ),
+      new ScrambleState( new int[][] { {0,1,1,0,-1,1              },{              2,1,4,2,-1,4},{              2,1,6,2,-1,6},{                          } } ),
+      };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -388,109 +404,67 @@ public class TwistyRedi extends TwistyObject
     return 2.0f;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// PUBLIC API
-
-  public Static3D[] getRotationAxis()
-    {
-    return ROT_AXIS;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public int[] getBasicAngle()
+  private void initializeScrambling()
     {
-    return BASIC_ANGLE;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
+    int numLayers = getNumLayers();
 
-  private void initializeScrambleTable(int[] first)
-    {
-    if( mScrambleTable ==null ) mScrambleTable = new int[NUM_AXIS][2];
-    if( mPossibleAxis  ==null ) mPossibleAxis  = new int[NUM_AXIS-1];
-    if( mPossibleLayers==null ) mPossibleLayers= new int[NUM_AXIS-1];
-    if( mNumOccurences ==null ) mNumOccurences = new int[NUM_AXIS-1];
+    if( mScrambleTable ==null )
+      {
+      mScrambleTable = new int[NUM_AXIS][numLayers];
+      }
+    if( mNumOccurences ==null )
+      {
+      int max=0;
 
-    for(int i=0; i<NUM_AXIS; i++)
-      for(int j=0; j<2; j++)
+      for (ScrambleState mState : mStates)
         {
-        mScrambleTable[i][j] = 0;
+        int tmp = mState.getTotal(-1);
+        if (max < tmp) max = tmp;
         }
 
-    mScrambleTable[first[0]][first[1]/2] = 1;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
+      mNumOccurences = new int[max];
+      }
 
-  private boolean areOpposite(int oldAxis, int newAxis, int oldRow, int nom)
-    {
-    return (oldAxis+newAxis==3)^(oldRow<nom);
+    for(int i=0; i<NUM_AXIS; i++)
+      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
 
-  private int retNewRotationIndex(Random rnd, int nom, int[] oldRot)
+  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
     {
-    int index=0, max=0;
-
-    for(int ax=0; ax<NUM_AXIS; ax++)
+    if( curr==0 )
       {
-      if( ax!=oldRot[0] )
-        {
-        mPossibleAxis[index] = ax;
-        mPossibleLayers[index] = areOpposite(oldRot[0],ax,oldRot[1],nom) ? 0:1;
-        int tmp = mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]];
-        if( tmp>max ) max=tmp;
-        index++;
-        }
+      mCurrState     = 0;
+      mIndexExcluded =-1;
+      initializeScrambling();
       }
 
-    for(int ax=0; ax<NUM_AXIS-1; ax++)
-      {
-      int value = mScrambleTable[mPossibleAxis[ax]][mPossibleLayers[ax]];
-      mNumOccurences[ax] = max - value + (ax==0 ? 0 : mNumOccurences[ax-1]);
-      }
+    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
 
-    float random= rnd.nextFloat()*mNumOccurences[NUM_AXIS-2];
+    scramble[curr][0] = info[0];
+    scramble[curr][1] = info[1];
+    scramble[curr][2] = info[2];
 
-    for(int ax=0; ax<NUM_AXIS-1; ax++)
-      {
-      if( random <= mNumOccurences[ax] )
-        {
-        index=ax;
-        break;
-        }
-      }
+    mCurrState     = info[3];
+    mIndexExcluded = info[0];
+    }
 
-    mScrambleTable[mPossibleAxis[index]][mPossibleLayers[index]]++;
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    return index;
+  public Static3D[] getRotationAxis()
+    {
+    return ROT_AXIS;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// PUBLIC API
 
-  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
+  public int[] getBasicAngle()
     {
-    if( curr==0 )
-      {
-      scramble[curr][0] = rnd.nextInt(NUM_AXIS);
-      scramble[curr][1] = rnd.nextFloat()<=0.5f ? 0:2;
-      initializeScrambleTable(scramble[curr]);
-      }
-    else
-      {
-      int index = retNewRotationIndex(rnd,1,scramble[curr-1]);
-      scramble[curr][0] = mPossibleAxis[index];
-      scramble[curr][1] = 2*mPossibleLayers[index];
-      }
-
-    switch( rnd.nextInt(2) )
-      {
-      case 0: scramble[curr][2] = -1; break;
-      case 1: scramble[curr][2] =  1; break;
-      }
+    return BASIC_ANGLE;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
