commit f2d04089c314db17c5cebec6b5e2023dde1bdf0f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Jan 31 16:22:57 2021 +0100

    Improve the way we scramble the Kilo and Megaminx.

diff --git a/src/main/java/org/distorted/objects/TwistyMinx.java b/src/main/java/org/distorted/objects/TwistyMinx.java
index d1c7f2bd..6166e0fd 100644
--- a/src/main/java/org/distorted/objects/TwistyMinx.java
+++ b/src/main/java/org/distorted/objects/TwistyMinx.java
@@ -198,6 +198,16 @@ abstract class TwistyMinx extends TwistyObject
         36, 34, 56, 32, 43, 21, 48, 28, 42, 23
       };
 
+  static final boolean[][] OPPOSITE_ROWS =
+      {
+          {false,  true, false,  true, false, false},
+          { true, false, false,  true,  true,  true},
+          {false, false, false,  true, false,  true},
+          { true,  true,  true, false, false,  true},
+          {false,  true, false, false, false,  true},
+          {false,  true,  true,  true,  true, false}
+      };
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   TwistyMinx(int numLayers, int realSize, Static4D quat, DistortedTexture texture, MeshSquare mesh,
@@ -298,14 +308,26 @@ abstract class TwistyMinx extends TwistyObject
 
   public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
     {
-    float rowFloat = rnd.nextFloat();
+    if( oldRotAxis<0 )
+      {
+      float rowFloat = rnd.nextFloat();
 
-    for(int row=0; row<mRowChances.length; row++)
+      for(int row=0; row<mRowChances.length; row++)
+        {
+        if( rowFloat<=mRowChances[row] ) return row;
+        }
+
+      return 0;
+      }
+    else
       {
-      if( rowFloat<=mRowChances[row] ) return row;
+      int size = mRowChances.length;
+      int num = (size-1)/2;
+      int row = rnd.nextInt(num);
+      boolean opposite = OPPOSITE_ROWS[oldRotAxis][newRotAxis];
+      boolean low = opposite^(oldRow<num);
+      return low ? row : size-1-row;
       }
-
-    return 0;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
