commit caccea6eed354b60906f8f376677009921b6b447
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Aug 31 01:12:21 2021 +0200

    Convert the Cubes of all sizes to the new, unified scrambling method.

diff --git a/src/main/java/org/distorted/objects/TwistyCube.java b/src/main/java/org/distorted/objects/TwistyCube.java
index 4f51eaa8..ea6d4c41 100644
--- a/src/main/java/org/distorted/objects/TwistyCube.java
+++ b/src/main/java/org/distorted/objects/TwistyCube.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;
@@ -128,12 +129,61 @@ class TwistyCube extends TwistyObject
     mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke );
     }
 
+  private int mCurrState;
+  private int mIndexExcluded;
+  private final ScrambleStateGraph[] mStates;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyCube(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.CUBE, res, scrWidth);
+
+    int[][] m = new int[16][];
+    for(int i=1; i<16; i++) m[i] = createEdges(size,i);
+
+    mStates = new ScrambleStateGraph[]  // built so that all 3 axes must be present in every 4 consecutive moves
+      {
+      new ScrambleStateGraph( new int[][] { m[ 1], m[ 2], m[ 3] } ),  // 0
+      new ScrambleStateGraph( new int[][] {  null, m[ 4], m[ 5] } ),  // x
+      new ScrambleStateGraph( new int[][] { m[ 6],  null, m[ 7] } ),  // y
+      new ScrambleStateGraph( new int[][] { m[ 8], m[ 8],  null } ),  // z
+      new ScrambleStateGraph( new int[][] { m[10],  null, m[ 7] } ),  // xy
+      new ScrambleStateGraph( new int[][] { m[11], m[ 9],  null } ),  // xz
+      new ScrambleStateGraph( new int[][] {  null, m[12], m[ 5] } ),  // yx
+      new ScrambleStateGraph( new int[][] { m[ 8], m[13],  null } ),  // yz
+      new ScrambleStateGraph( new int[][] {  null, m[ 4], m[14] } ),  // zx
+      new ScrambleStateGraph( new int[][] { m[ 6],  null, m[15] } ),  // zy
+      new ScrambleStateGraph( new int[][] {  null,  null, m[ 5] } ),  // xyx
+      new ScrambleStateGraph( new int[][] {  null, m[ 4],  null } ),  // xzx
+      new ScrambleStateGraph( new int[][] {  null,  null, m[ 7] } ),  // yxy
+      new ScrambleStateGraph( new int[][] { m[ 6],  null,  null } ),  // yzy
+      new ScrambleStateGraph( new int[][] {  null, m[ 9],  null } ),  // zxz
+      new ScrambleStateGraph( new int[][] { m[ 8],  null,  null } ),  // zyz
+      };
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int[] createEdges(int size, int vertex)
+    {
+    int[] ret = new int[9*size];
+
+    for(int l=0; l<size; l++)
+      {
+      ret[9*l  ] = l;
+      ret[9*l+1] =-1;
+      ret[9*l+2] = vertex;
+      ret[9*l+3] = l;
+      ret[9*l+4] = 1;
+      ret[9*l+5] = vertex;
+      ret[9*l+6] = l;
+      ret[9*l+7] = 2;
+      ret[9*l+8] = vertex;
+      }
+
+    return ret;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -322,53 +372,24 @@ class TwistyCube 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);
-
-      // All three axis must be present among every four consecutive rotations.
-      // Otherwise in case of odd-sized cubes we can get four consecutive rotations
-      // that collapse to a NOP
-      // (X,midLayer,180)->(Y,midLayer,180)->(X,midLayer,180)->(Y,midLayer,180) = NOP
-      if( curr>=3 && scramble[curr-1][0]==scramble[curr-3][0] )
-        {
-        for( int ax=0; ax<NUM_AXIS; ax++)
-          {
-          if( scramble[curr-1][0]!=ax && scramble[curr-2][0]!=ax )
-            {
-            scramble[curr][0] = ax;
-            break;
-            }
-          }
-        }
+      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(4) )
-      {
-      case 0: scramble[curr][2] = -2; break;
-      case 1: scramble[curr][2] = -1; break;
-      case 2: scramble[curr][2] =  1; break;
-      case 3: scramble[curr][2] =  2; break;
-      }
+    mCurrState     = info[3];
+    mIndexExcluded = info[0];
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/TwistyDino4.java b/src/main/java/org/distorted/objects/TwistyDino4.java
index 74bc327e..9114084a 100644
--- a/src/main/java/org/distorted/objects/TwistyDino4.java
+++ b/src/main/java/org/distorted/objects/TwistyDino4.java
@@ -28,8 +28,6 @@ import org.distorted.library.mesh.MeshSquare;
 import org.distorted.library.type.Static4D;
 import org.distorted.main.R;
 
-import java.util.Random;
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public class TwistyDino4 extends TwistyDino
