commit 2d697abd3b371a831ab04c9c80a22d45999c394b
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Mar 22 00:12:39 2023 +0100

    Progess with Skewb solver.

diff --git a/src/main/java/org/distorted/objectlib/tablebases/TBSkewb.java b/src/main/java/org/distorted/objectlib/tablebases/TBSkewb.java
index c75b9345..be978dfc 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TBSkewb.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TBSkewb.java
@@ -20,6 +20,8 @@ import org.distorted.objectlib.R;
 
 public class TBSkewb extends TablebasesAbstract
 {
+  private static final int[][] freeIndex = { {1,3,2},{0,2,3},{3,1,0},{2,0,1} };
+
   private static final int[][][] centerQuats =
     {
         { {0,10},{9,11},{1,7},{4,6},{2,5},{3,8} },
@@ -59,7 +61,7 @@ public class TBSkewb extends TablebasesAbstract
 
   public TBSkewb(Resources res)
     {
-    super(res, R.raw.pyra_3_tablebase);
+    super(res, R.raw.skew_2_tablebase);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -156,11 +158,11 @@ public class TBSkewb extends TablebasesAbstract
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public static int computeLocation(int quat)
+  public static int computeLocation(int index, int quat)
     {
     for(int i=0; i<4; i++)
       {
-      int[] q = freeQuats[0][i];
+      int[] q = freeQuats[index][i];
       if( quat==q[0] || quat==q[1] || quat==q[2] ) return i;
       }
 
@@ -231,7 +233,7 @@ public class TBSkewb extends TablebasesAbstract
       {
       output[i] = -1;
       int[][] c = centerQuats[i];
-      int q = quats[i];
+      int q = quats[8+i];
 
       for(int j=0; j<6; j++)
         if( c[j][0]==q || c[j][1]==q )
@@ -250,25 +252,39 @@ public class TBSkewb extends TablebasesAbstract
     {
     for(int i=0; i<6; i++)
       {
-      quats[i] = centerQuats[i][perm[i]][0];
+      quats[8+i] = centerQuats[i][perm[i]][0];
       }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int freeIndex(int taken, int seq)
+  private void fillUpToEvenPerm(int[] perm)
     {
-    return seq + (seq>=taken ? 1:0);
+    int min, max;
+
+         if( perm[0]!=0 && perm[1]!=0 ) min=0;
+    else if( perm[0]!=1 && perm[1]!=1 ) min=1;
+    else                                min=2;
+
+         if( perm[0]!=3 && perm[1]!=3 ) max=3;
+    else if( perm[0]!=2 && perm[1]!=2 ) max=2;
+    else                                max=1;
+
+    int diff = perm[1]-perm[0];
+
+    if( diff==-2 || diff==1 || diff==3 ) { perm[2]=min; perm[3]=max; }
+    else                                 { perm[2]=max; perm[3]=min; }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int[] getQuats(int index)
     {
+    int[] locationFree = new int[4];
     int center_perm_num = (index%360);
     index /= 360;
     int totalTwist = (index%2187);
-    int locationOfFree0 = (index/2187);
+    locationFree[0] = (index/2187);
 
     int[] quats = new int[14];
     int[] center_perm = new int[6];
@@ -286,19 +302,22 @@ public class TBSkewb extends TablebasesAbstract
     int total = twist[1]+twist[2]+twist[4];
     twist[7] = ((6-total)%3);
 
-    int locationOfFree1 = freeIndex(locationOfFree0,0);
-    int locationOfFree2 = freeIndex(locationOfFree0,1);
-    int locationOfFree3 = freeIndex(locationOfFree0,2);
+    int sumFixedTwists = ((twist[0]+twist[3]+twist[5]+twist[6])%3);
+    locationFree[1] = freeIndex[locationFree[0]][sumFixedTwists];
+    fillUpToEvenPerm(locationFree);
 
     quats[0] = fixedQuats[0][twist[0]];
     quats[3] = fixedQuats[1][twist[3]];
     quats[5] = fixedQuats[2][twist[5]];
     quats[6] = fixedQuats[3][twist[6]];
 
-    quats[1] = freeQuats[0][locationOfFree0][twist[1]];
-    quats[2] = freeQuats[1][locationOfFree1][twist[2]];
-    quats[4] = freeQuats[2][locationOfFree2][twist[4]];
-    quats[7] = freeQuats[3][locationOfFree3][twist[7]];
+    quats[1] = freeQuats[0][locationFree[0]][twist[1]];
+    quats[2] = freeQuats[1][locationFree[1]][twist[2]];
+    quats[4] = freeQuats[2][locationFree[2]][twist[4]];
+    quats[7] = freeQuats[3][locationFree[3]][twist[7]];
+
+//android.util.Log.e("D", "QUATS center_perm: "+center_perm_num+" totalTwist="+totalTwist+" locationOfFree0="+locationOfFree0);
+//android.util.Log.e("D", "QUATS t0="+twist[0]+" t1="+twist[1]+" t2="+twist[2]+" t3="+twist[3]+" t4="+twist[4]+" t5="+twist[5]+" t6="+twist[6]+" t7="+twist[7]);
 
     return quats;
     }
@@ -312,7 +331,10 @@ public class TBSkewb extends TablebasesAbstract
     int[] twist = new int[8];
     computeCornerTwists(twist,quats);
     int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6])))));
-    int locationOfFree0 = computeLocation(quats[1]);
+    int locationOfFree0 = computeLocation(0,quats[1]);
+
+//android.util.Log.e("D", "INDEX center_perm: "+center_perm_num+" totalTwist="+totalTwist+" locationOfFree0="+locationOfFree0);
+//android.util.Log.e("D", "INDEX t0="+twist[0]+" t1="+twist[1]+" t2="+twist[2]+" t3="+twist[3]+" t4="+twist[4]+" t5="+twist[5]+" t6="+twist[6]+" t7="+twist[7]);
 
     return center_perm_num+ 360*(totalTwist + 2187*locationOfFree0);
     }
diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
index ddb0095c..62be437b 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
@@ -587,4 +587,35 @@ public abstract class TablebasesAbstract
         android.util.Log.e("D", "numbers: " + sb);
         }
       }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private void printQuats(int[] quats)
+      {
+      StringBuilder sb = new StringBuilder();
+      for(int q : quats )
+        {
+        sb.append(' ');
+        sb.append(q);
+        }
+      android.util.Log.e("D", "quats: "+sb);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void test()
+      {
+      int[] q1 = {1,1,1,0,1,0,0,0, 1,0,1,0,1,0 };
+      int index1 = getIndex(q1);
+      android.util.Log.e("D", "index1: "+index1);
+
+      int[] q2 = getQuats(index1);
+      printQuats(q2);
+/*
+      int[] q2 = {0,0,3,0,4,0,0,0, 0,0,0,0,0,0 };
+      int index2 = getIndex(q2);
+      android.util.Log.e("D", "index2: "+index2);
+
+ */
+      }
 }
diff --git a/src/main/res/raw/skew_2_tablebase.db b/src/main/res/raw/skew_2_tablebase.db
new file mode 100644
index 00000000..c9286b7e
Binary files /dev/null and b/src/main/res/raw/skew_2_tablebase.db differ
