commit 74cc695a843444290b4a422fc6ac70010f6d0e11
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Feb 28 13:13:48 2023 +0100

    Pyraminx solver: tablebase working now (tipless, tips to be added in the SolverPyraminx class)

diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java b/src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java
index 63af7dac..cc3cdc01 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java
@@ -9,10 +9,77 @@
 
 package org.distorted.objectlib.tablebases;
 
+import java.util.Random;
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 public class TablebaseHelpers
 {
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static String print(int[][] move)
+    {
+    StringBuilder sb = new StringBuilder();
+
+    if( move==null )
+      {
+      return ("move NULL!!");
+      }
+
+    for (int[] ints : move)
+      {
+      sb.append(' ');
+      sb.append('(');
+      sb.append(ints[0]);
+      sb.append(' ');
+      sb.append(ints[1]);
+      sb.append(' ');
+      sb.append(ints[2]);
+      sb.append(')');
+      }
+
+    return sb.toString();
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void test(TablebasesAbstract tb)
+    {
+    int size = tb.getSize();
+
+    for(int i=0; i<size; i++)
+      {
+      boolean success = tb.test(i);
+
+      if( (!success && i>0) || (success && i==0) )
+        {
+        android.util.Log.e("D", "--------> FAILED: "+i);
+        break;
+        }
+
+      if( (i%1000)==0 )   android.util.Log.e("D", "trying "+i);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void test2(TablebasesAbstract tb, int num)
+    {
+    Random rnd = new Random();
+    int size = tb.getSize();
+
+    for(int i=0; i<num; i++)
+      {
+      int next = rnd.nextInt(size-1);
+      int[][] moves = tb.solution(next);
+      String moveSeq = print(moves);
+      android.util.Log.e("D", (moves==null ? 0 : moves.length)+" Trying "+next+" : "+moveSeq);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
   private static int swaps(int val, int[] buffer, int len)
     {
     int ret = 0;
diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
index 3d6177f3..5257c174 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
@@ -436,7 +436,7 @@ public abstract class TablebasesAbstract
 
       if( !found )
         {
-        android.util.Log.e("D", "solution error: no move found!");
+        android.util.Log.e("D", "----> solution error: no move found!");
         return null;
         }
       }
@@ -517,4 +517,56 @@ public abstract class TablebasesAbstract
 
     return moves;
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public boolean test(int index)
+    {
+    if( !mInitialized ) return false;
+
+    int[] data = new int[4];
+    byte level = mTablebase.retrievePacked(index);
+    int[] quats = getQuats(index);
+    int numQuats = quats.length;
+    int[] tmpQuats = new int[numQuats];
+
+    data[0]=0;
+    data[1]=0;
+    data[2]=1;
+    data[3]=1;
+
+    for(int ax=0; ax<mNumAxis; ax++)
+      for(int cubit=0; cubit<mNumCubits; cubit++)
+        mRotRow[cubit][ax] = computeRow(mPosition[cubit],quats[cubit],ax);
+
+    for(int s=0; s<mScalingFactor; s++)
+      {
+      int ax    = data[0];
+      int layer = data[1];
+      int quat  = data[3];
+
+      if( mRotatable[ax][layer] )
+        {
+        int bitLayer = (1<<layer);
+        System.arraycopy(quats, 0, tmpQuats, 0, numQuats);
+
+        for(int cubit=0; cubit<mNumCubits; cubit++)
+          if( mRotRow[cubit][ax]==bitLayer )
+            {
+            int currQuat = tmpQuats[cubit];
+            int newQuat = getMultQuat(quat,currQuat);
+            tmpQuats[cubit] = newQuat;
+            }
+
+        int childIndex = getIndex(tmpQuats);
+        byte newLevel = mTablebase.retrievePacked(childIndex);
+
+        if( ((newLevel-level+1)%3) == 0 ) return true;
+        }
+
+      getNextAxisLayerAngleQuat(data);
+      }
+
+    return false;
+    }
 }
diff --git a/src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java b/src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
index d89053ed..dbe7337b 100644
--- a/src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
+++ b/src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
@@ -15,6 +15,7 @@ import static org.distorted.objectlib.main.TwistyObject.SQ6;
 import android.content.res.Resources;
 
 import org.distorted.library.type.Static3D;
+import org.distorted.objectlib.R;
 import org.distorted.objectlib.objects.TwistyPyraminx;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -42,7 +43,7 @@ public class TablebasesPyraminx extends TablebasesAbstract
 
   public TablebasesPyraminx(Resources res)
     {
-    super(res,org.distorted.objectlib.R.raw.pduo_2_tablebase);
+    super(res, R.raw.pyra_3_tablebase);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -71,20 +72,12 @@ public class TablebasesPyraminx extends TablebasesAbstract
              {-0.5f, SQ2/4, 0.0f},
              { 0.5f, SQ2/4, 0.0f},
 
+             { 0.0f,-SQ2/2, 0.0f},   // index=0 has the quats already set up so that
+             { 0.0f,-SQ2/2, 0.0f},   // all the edges fall into right spots, so here
+             { 0.0f,-SQ2/2, 0.0f},   // they need to be all in one place
              { 0.0f,-SQ2/2, 0.0f},
              { 0.0f,-SQ2/2, 0.0f},
              { 0.0f,-SQ2/2, 0.0f},
-             { 0.0f,-SQ2/2, 0.0f},
-             { 0.0f,-SQ2/2, 0.0f},
-             { 0.0f,-SQ2/2, 0.0f},
-
-             /*
-             { 0.5f,  0.0f,-0.5f},
-             { 0.5f,  0.0f, 0.5f},
-             {-0.5f,  0.0f,-0.5f},
-             {-0.5f,  0.0f, 0.5f},
-             { 0.0f, SQ2/2, 0.0f},
-              */
          };
     }
 
diff --git a/src/main/res/raw/pyra_3_tablebase.db b/src/main/res/raw/pyra_3_tablebase.db
new file mode 100644
index 00000000..31a8427f
Binary files /dev/null and b/src/main/res/raw/pyra_3_tablebase.db differ
