commit b8dab9fd6950c35ccfe6e81b21d65f993afc5492
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Feb 28 13:37:34 2023 +0100

    Pyraminx solver: add tips.

diff --git a/src/main/java/org/distorted/solvers/SolverPyraminx.java b/src/main/java/org/distorted/solvers/SolverPyraminx.java
index ba81d0ef..af58ea66 100644
--- a/src/main/java/org/distorted/solvers/SolverPyraminx.java
+++ b/src/main/java/org/distorted/solvers/SolverPyraminx.java
@@ -52,7 +52,8 @@ public class SolverPyraminx extends SolverTablebase
           {3,2},{1,3},{0,3},{2,1},{2,0},{1,0}  // order of those pairs determines edge twist
       };
 
-  TablebasesAbstract mSolver;
+  private TablebasesAbstract mSolver;
+  private int[] mCornerTwist;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -326,8 +327,8 @@ public class SolverPyraminx extends SolverTablebase
     int[][] corners = new int[4][3];
     int[][] edges   = new int[6][2];
     int[][] vertices= new int[4][3];
-    int[] corner_twist = new int[4];
     int[] vertex_twist = new int[4];
+    mCornerTwist = new int[4];
 
     getCorners(object,corners);
     getVertices(object,vertices);
@@ -350,8 +351,8 @@ public class SolverPyraminx extends SolverTablebase
 
     for(int i=0; i<4; i++)
       {
-      corner_twist[i] = computePieceTwist(i,corners[i],faces1);
-      if( corner_twist[i]<0 ) return ERROR_CORNERS_CANNOT;
+      mCornerTwist[i] = computePieceTwist(i,corners[i],faces1);
+      if( mCornerTwist[i]<0 ) return ERROR_CORNERS_CANNOT;
       }
 
     for(int i=0; i<4; i++)
@@ -498,6 +499,40 @@ public class SolverPyraminx extends SolverTablebase
     return null;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void addMove(int[] move, int axis, int twist)
+    {
+    move[0] = axis;
+    move[1] = (1<<2);
+    move[2] = (twist==2 ? -1:twist);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int[][] constructTipMoves(int[] twist)
+    {
+    int total = 0;
+
+    for(int i=0; i<4; i++)
+      if( twist[i]!=0 ) total++;
+
+    if( total>0 )
+      {
+      int[][] moves = new int[total][3];
+
+      int index=0;
+      if( twist[0]!=0 ) { addMove(moves[index],1,twist[0]); index++; }
+      if( twist[1]!=0 ) { addMove(moves[index],0,twist[1]); index++; }
+      if( twist[2]!=0 ) { addMove(moves[index],3,twist[2]); index++; }
+      if( twist[3]!=0 ) { addMove(moves[index],2,twist[3]);          }
+
+      return moves;
+      }
+
+    return null;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int[][] solution(int index, Resources res)
@@ -507,7 +542,20 @@ public class SolverPyraminx extends SolverTablebase
       mSolver = ImplementedTablebasesList.createPacked(res,ObjectType.PYRA_3);
       }
 
-    return mSolver!=null ? mSolver.solution(index) : null;
+    int[][] moves1 = mSolver!=null ? mSolver.solution(index) : null;
+    int[][] moves2 = constructTipMoves(mCornerTwist);
+
+    int len1 = (moves1==null ? 0:moves1.length);
+    int len2 = (moves2==null ? 0:moves2.length);
+
+    int[][] moves = new int[len1+len2][];
+
+android.util.Log.e("D", "len1="+len1+" len2="+len2);
+
+    if( len1>0 ) System.arraycopy(moves1, 0, moves,    0, len1);
+    if( len2>0 ) System.arraycopy(moves2, 0, moves, len1, len2);
+
+    return moves;
     }
 }  
 
