commit 45dc5cd71db2deb6246636ff567f67d45b67517f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Apr 20 16:50:32 2023 +0200

    CU_323 solver: corrections.

diff --git a/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java b/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
index 8ea584c2..51d36987 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TBCuboid323.java
@@ -14,7 +14,7 @@ import org.distorted.objectlib.helpers.OperatingSystemInterface;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public class TBCuboid323 extends TablebasesAbstract
+public class TBCuboid323 extends TablebasesPruning
 {
   private static final int[][] CORNER_MAP = new int[][]
       {
@@ -40,6 +40,7 @@ public class TBCuboid323 extends TablebasesAbstract
       };
 
   private static boolean mUpper;
+  private int[][] mAngles;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -133,16 +134,21 @@ public class TBCuboid323 extends TablebasesAbstract
 
   public TBCuboid323(OperatingSystemInterface os)
     {
-    super(os,org.distorted.objectlib.R.raw.cu_232_tablebase);
+    super(os,null,null);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   int[][] getBasicAngles()
     {
-    int[] tmp2 = {2,2,2};
-    int[] tmp4 = {4,4};
-    return new int[][] { tmp2,tmp4,tmp2 };
+    if( mAngles==null )
+      {
+      int[] tmp2 = {2,2,2};
+      int[] tmp4 = {4,4};
+      return new int[][] { tmp2,tmp4,tmp2 };
+      }
+
+    return mAngles;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -202,6 +208,30 @@ public class TBCuboid323 extends TablebasesAbstract
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // specifically for the tablebase
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// we can never really move the fixed front edge, because if we do so, we would also rotate the
+// rotation axis themselves! (see getIndex() where the cubit quats are normalized)
+// Fixed front edge is either edge1 or edge3, depending on value of mUpper
+// (mUpper==true --> fixed==3, else fixed==1)
+//
+
+  @Override
+  int[] newMove(int axis, int layer, int angle)
+    {
+    //if( axis==0 && layer==2 ) return new int[] { axis, 3, angle==1 ? 1:-1};
+    //if( axis==3 && layer==0 ) return new int[] { axis, 6, angle==1 ? 1:-1};
+
+    if( axis==1 )
+      {
+
+      }
+
+    int maxAngle = mAngles[axis][layer];
+    angle = maxAngle-angle;
+    if( angle> 0.5f*maxAngle ) angle -= maxAngle;
+    return new int[] { axis, (1<<layer), angle };
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // 8!*8!/4 --> https://www.jaapsch.net/puzzles/domino.htm
 
@@ -217,6 +247,34 @@ public class TBCuboid323 extends TablebasesAbstract
     return 13;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int[] getMidPruningLevels()
+    {
+    return new int[] {6,7};
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int[] getHighPruningLevels()
+    {
+    return new int[] {17,18};
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getGodsNumber()
+    {
+    return 18;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean moveCanProceed(int lastA, int lastR, int currA, int currR)
+    {
+    return (lastA!=currA) || (lastR!=currR);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private int findIndex(int[] table, int value)
@@ -231,15 +289,33 @@ public class TBCuboid323 extends TablebasesAbstract
 
   private boolean isFrontEdgeInItsPlace(int[] perm)
     {
-    return perm[mUpper ? 3 : 1]==0;
+    int index = mUpper?3:1;
+    return perm[index]==index;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void correctQuats(int[] quats)
+    {
+    int mult=0, index = mUpper? 11:9;
+
+    switch(quats[index])
+      {
+      case 0: case 5: return;
+      case 4: case 7: mult=2; break;
+      case 1: case 3: mult=3; break;
+      case 2: case 6: mult=4; break;
+      }
+
+    for(int i=0; i<16; i++) quats[i] = getMultQuat(mult,quats[i]);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int[] getQuats(int index)
     {
-    int cornerPermNum = index%20160;
-    index /= 20160;
+    int cornerPermNum = index%40320;
+    index /= 40320;
     boolean inPlace = ((index%2)==0);
     int edgePermNum = index/2;
 
@@ -272,6 +348,8 @@ public class TBCuboid323 extends TablebasesAbstract
     int[] corner_perm = new int[8];
     int[] edge_perm8  = new int[8];
 
+    correctQuats(quats);
+
     for(int i=0; i<8; i++)
       {
       corner_perm[i] = findIndex( CORNER_MAP[i], quats[i  ]);
@@ -284,7 +362,7 @@ public class TBCuboid323 extends TablebasesAbstract
     int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm7);
     boolean inPlace = isFrontEdgeInItsPlace(edge_perm8);
 
-    return corner_perm_num + 20160*( (inPlace?0:1) + 2*edge_perm_num);
+    return corner_perm_num + 40320*( (inPlace?0:1) + 2*edge_perm_num);
     }
 }  
 
diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
index 9a6c34bf..34969a79 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
@@ -374,11 +374,11 @@ public abstract class TablebasesAbstract
     {
     for(int[] move : moves )
       {
-      int[] newMove = newMove(move[0],move[1],move[2]);
+      int[] m = newMove(move[0],move[1],move[2]);
 
-      move[0] = newMove[0];
-      move[1] = newMove[1];
-      move[2] = newMove[2];
+      move[0] = m[0];
+      move[1] = m[1];
+      move[2] = m[2];
       }
     }
 
@@ -395,7 +395,7 @@ public abstract class TablebasesAbstract
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int[][] convertMoves(ArrayList<int[]> moves)
+  private int[][] convertMovesFromArray(ArrayList<int[]> moves)
     {
     int len = moves.size();
     int[][] ret = new int[len][];
@@ -506,7 +506,7 @@ public abstract class TablebasesAbstract
         }
       }
 
-    int[][] ret = convertMoves(moves);
+    int[][] ret = convertMovesFromArray(moves);
     return extraInfo(ret,extra);
     }
 
