commit 202b167ec7d295fa4d95883cafbd64ddbf344a7c
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue Feb 28 14:36:38 2023 +0100

    Pyraminx solver: bugfix.

diff --git a/src/main/java/org/distorted/solvers/SolverPyraminx.java b/src/main/java/org/distorted/solvers/SolverPyraminx.java
index af58ea66..83e5c785 100644
--- a/src/main/java/org/distorted/solvers/SolverPyraminx.java
+++ b/src/main/java/org/distorted/solvers/SolverPyraminx.java
@@ -42,15 +42,9 @@ public class SolverPyraminx extends SolverTablebase
 
   private static final int ERROR_CORNERS_CANNOT   = -15;
   private static final int ERROR_VERTICES_CANNOT  = -16;
-  private static final int ERROR_CORNER_TWISTED   = -17;
-  private static final int ERROR_EDGE_TWISTED     = -18;
-  private static final int ERROR_C_V_DONT_MATCH   = -19;
-  private static final int ERROR_TWO_EDGES        = -20;
-
-  private static final int[][] edgeColors = new int[][]
-      {
-          {3,2},{1,3},{0,3},{2,1},{2,0},{1,0}  // order of those pairs determines edge twist
-      };
+  private static final int ERROR_EDGE_TWISTED     = -17;
+  private static final int ERROR_C_V_DONT_MATCH   = -18;
+  private static final int ERROR_TWO_EDGES        = -19;
 
   private TablebasesAbstract mSolver;
   private int[] mCornerTwist;
@@ -127,7 +121,7 @@ public class SolverPyraminx extends SolverTablebase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int checkAllEdgesPresent(int[][] edges)
+  private int checkAllEdgesPresent(int[][] edges, int[][] edgeColors)
     {
     boolean[] present = new boolean[6];
     for(int i=0; i<6; i++) present[i] = false;
@@ -234,7 +228,7 @@ public class SolverPyraminx extends SolverTablebase
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int[] computeEdgeQuats(int[][] edges)
+  private int[] computeEdgeQuats(int[][] edges, int[][] edgeColors)
     {
     int[] quats = new int[6];
 
@@ -320,6 +314,27 @@ public class SolverPyraminx extends SolverTablebase
     edges[5][1] = object.getCubitFaceStickerIndex(12,0); // G
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int[][] computeEdgeColors(int[] faceColor)
+    {
+    // The first pair being (2,3) means 'the first edge's first face is on the tetrahedron
+    // face which oppeses corner number 2, and its second face on tetra face which opposes
+    // corner number 3'
+    // Order of those pairs determines edge twist.
+
+    final int[][] edgeColorIndices = new int[][] { {2,3},{0,2},{1,2},{3,0},{3,1},{0,1}  };
+    int[][] ret = new int[6][2];
+
+    for(int i=0; i<6; i++)
+      {
+      ret[i][0] = faceColor[edgeColorIndices[i][0]];
+      ret[i][1] = faceColor[edgeColorIndices[i][1]];
+      }
+
+    return ret;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public int tablebaseIndex(TwistyObject object)
@@ -332,7 +347,6 @@ public class SolverPyraminx extends SolverTablebase
 
     getCorners(object,corners);
     getVertices(object,vertices);
-    getEdges(object,edges);
 
     int result1 = checkAllCornersPresent(corners);
     if( result1<0 ) return result1;
@@ -340,13 +354,16 @@ public class SolverPyraminx extends SolverTablebase
     int result2 = checkAllVerticesPresent(vertices);
     if( result2<0 ) return result2;
 
-    int result3 = checkAllEdgesPresent(edges);
-    if( result3<0 ) return result3;
-
     int[] faces1 = computeFaceColors(corners);
     int[] faces2 = computeFaceColors(vertices);
 
-    int result4 = checkAgreement(faces1,faces2);
+    int result3 = checkAgreement(faces1,faces2);
+    if( result3<0 ) return result3;
+
+    int[][] edgeColors = computeEdgeColors(faces1);
+
+    getEdges(object,edges);
+    int result4 = checkAllEdgesPresent(edges,edgeColors);
     if( result4<0 ) return result4;
 
     for(int i=0; i<4; i++)
@@ -361,7 +378,7 @@ public class SolverPyraminx extends SolverTablebase
       if( vertex_twist[i]<0 ) return ERROR_VERTICES_CANNOT;
       }
 
-    int[] quats = computeEdgeQuats(edges);
+    int[] quats = computeEdgeQuats(edges,edgeColors);
     int[] permutation = new int[6];
     TablebasesPyraminx.getEdgePermutation(permutation,quats,0);
     boolean even = TablebaseHelpers.permutationIsEven(permutation);
@@ -488,7 +505,6 @@ public class SolverPyraminx extends SolverTablebase
       case ERROR_EDGE_YB_MISSING   : return edgeError(res,2,1);
       case ERROR_EDGE_GB_MISSING   : return edgeError(res,2,0);
       case ERROR_EDGE_GY_MISSING   : return edgeError(res,1,0);
-      case ERROR_CORNER_TWISTED    : return res.getString(R.string.solver_generic_corner_twist);
       case ERROR_EDGE_TWISTED      : return res.getString(R.string.solver_generic_edge_twist);
       case ERROR_CORNERS_CANNOT    : return res.getString(R.string.solver_generic_corners_cannot);
       case ERROR_VERTICES_CANNOT   : return res.getString(R.string.solver_generic_vertices_cannot);
@@ -548,9 +564,7 @@ public class SolverPyraminx extends SolverTablebase
     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);
+    int[][] moves = new int[len1+len2][3];
 
     if( len1>0 ) System.arraycopy(moves1, 0, moves,    0, len1);
     if( len2>0 ) System.arraycopy(moves2, 0, moves, len1, len2);
