commit 486b3417db3b8ecc315ab95701b0746aa7759115
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Aug 30 22:21:14 2021 +0200

    Convert the Diamonds & the Helicopter to the new, unified scrambling method.

diff --git a/src/main/java/org/distorted/objects/TwistyDiamond.java b/src/main/java/org/distorted/objects/TwistyDiamond.java
index 7e081ee2..3d488a1f 100644
--- a/src/main/java/org/distorted/objects/TwistyDiamond.java
+++ b/src/main/java/org/distorted/objects/TwistyDiamond.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;
@@ -135,12 +136,30 @@ public class TwistyDiamond extends TwistyObject
     mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleStateGraph[] mStates;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyDiamond(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.DIAM, res, scrWidth);
+
+    int[] tmp = new int[3*2*size];
+
+    for(int i=0; i<2*size; i++)
+      {
+      tmp[3*i  ] = (i<size) ?  i:i-size;
+      tmp[3*i+1] = (i%2==0) ? -1:1;
+      tmp[3*i+2] = 0;
+      }
+
+    mStates = new ScrambleStateGraph[]
+      {
+      new ScrambleStateGraph( new int[][] {tmp,tmp,tmp,tmp} )
+      };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -515,35 +534,24 @@ public class TwistyDiamond 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;
       }
 
-    float rowFloat = rnd.nextFloat();
-    int numLayers = getNumLayers();
+    int total = mStates[mCurrState].getTotal(mIndexExcluded);
+    int random= rnd.nextInt(total);
+    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
 
-    for(int row=0; row<numLayers; row++)
-      {
-      if( rowFloat*numLayers <= row+1 )
-        {
-        scramble[curr][1] = row;
-        break;
-        }
-      }
+    scramble[curr][0] = info[0];
+    scramble[curr][1] = info[1];
+    scramble[curr][2] = info[2];
 
-    switch( rnd.nextInt(2) )
-      {
-      case 0: scramble[curr][2] = -1; break;
-      case 1: scramble[curr][2] =  1; break;
-      }
+    mCurrState     = info[3];
+    mIndexExcluded = info[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/TwistyHelicopter.java b/src/main/java/org/distorted/objects/TwistyHelicopter.java
index a238c72a..0e0bf77e 100644
--- a/src/main/java/org/distorted/objects/TwistyHelicopter.java
+++ b/src/main/java/org/distorted/objects/TwistyHelicopter.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;
@@ -235,12 +236,33 @@ public class TwistyHelicopter extends TwistyObject
     mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleStateGraph[] mStates;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyHelicopter(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.HELI, res, scrWidth);
+
+    mStates = new ScrambleStateGraph[]
+      {
+      new ScrambleStateGraph( new int[][] { {0,1,1,2,1,2},{0,1,3,2,1,4},{0,1,5,2,1,6},{0,1,7,2,1,8},{0,1,9,2,1,10},{0,1,11,2,1,12} } ),
+      new ScrambleStateGraph( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{      2,1,10},{       2,1,12} } ),
+      new ScrambleStateGraph( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{0,1,9       },{0,1,11       } } ),
+      new ScrambleStateGraph( new int[][] { {           },{           },{0,1,5      },{0,1,7      },{0,1,9       },{0,1,11       } } ),
+      new ScrambleStateGraph( new int[][] { {           },{           },{      2,1,6},{      2,1,8},{      2,1,10},{       2,1,12} } ),
+      new ScrambleStateGraph( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{0,1,9       },{       2,1,12} } ),
+      new ScrambleStateGraph( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{      2,1,10},{0,1,11       } } ),
+      new ScrambleStateGraph( new int[][] { {0,1,1      },{0,1,3      },{           },{           },{      2,1,10},{0,1,11       } } ),
+      new ScrambleStateGraph( new int[][] { {      2,1,2},{      2,1,4},{           },{           },{0,1,9       },{       2,1,12} } ),
+      new ScrambleStateGraph( new int[][] { {      2,1,2},{0,1,3      },{0,1,5      },{      2,1,8},{            },{             } } ),
+      new ScrambleStateGraph( new int[][] { {0,1,1      },{      2,1,4},{      2,1,6},{0,1,7      },{            },{             } } ),
+      new ScrambleStateGraph( new int[][] { {      2,1,2},{0,1,3      },{      2,1,6},{0,1,7      },{            },{             } } ),
+      new ScrambleStateGraph( new int[][] { {0,1,1      },{      2,1,4},{0,1,5      },{      2,1,8},{            },{             } } ),
+      };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -409,36 +431,24 @@ public class TwistyHelicopter 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 -2);
-
-      switch(scramble[curr-1][0])
-        {
-        case  0:
-        case  1: scramble[curr][0] = newVector+2;
-                 break;
-        case  2:
-        case  3: scramble[curr][0] = (newVector==0 || newVector==1) ? newVector:newVector+2;
-                 break;
-        default: scramble[curr][0] = newVector;
-                 break;
-        }
+      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];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
