Project

General

Profile

« Previous | Next » 

Revision eb316dea

Added by Leszek Koltunski over 1 year ago

CU_323 solver: new schema.

View differences:

src/main/java/org/distorted/solvers/SolverCuboid323.java
11 11

  
12 12
import android.content.res.Resources;
13 13

  
14
import org.distorted.library.type.Static3D;
15
import org.distorted.library.type.Static4D;
16 14
import org.distorted.main.R;
17 15
import org.distorted.objectlib.helpers.OperatingSystemInterface;
18
import org.distorted.objectlib.helpers.QuatGroupGenerator;
19 16
import org.distorted.objectlib.main.ObjectSignatures;
20 17
import org.distorted.objectlib.main.TwistyObject;
21 18
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
......
36 33
  TablebasesAbstract mSolver;
37 34
  private final int[] mFaceColors;
38 35
  private int mErrorColor1, mErrorColor2, mErrorColor3;
39
  private Static4D[] mQuats;
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
  private void initializeQuats()
44
    {
45
    int[] tmp2 = {2,2,2};
46
    int[] tmp4 = {4,4};
47
    int[][] angles = new int[][] { tmp2,tmp4,tmp2 };
48
    Static3D[] axis = new Static3D[] { new Static3D(1,0,0), new Static3D(0,1,0), new Static3D(0,0,1) };
49
    mQuats = QuatGroupGenerator.computeGroup(axis,angles);
50
    }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
  private int mulQuat(int q1, int q2)
55
    {
56
    if( mQuats==null ) initializeQuats();
57
    return TablebasesAbstract.mulQuat(q1,q2,mQuats);
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  private void rotatePermutations(int[] corner, int[] edge8, int quat)
63
    {
64
    int[] quats = TBCuboid323.quatsFromPermutations(corner,edge8);
65
    int num = quats.length;
66

  
67
    for( int i=0; i<num; i++ ) quats[i] = mulQuat(quat,quats[i]);
68

  
69
    TBCuboid323.cornerFromQuats(corner,quats);
70
    TBCuboid323.edgeFromQuats(edge8,quats);
71
    }
72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
// when we input the position, edge1 can be anywhere. We need to rotate the permutations so that
75
// edge1 is always in the front (i.e. so that edge[1] is 1 or 3)
76

  
77
  private void normalizePermutations(int[] corner, int[] edge8)
78
    {
79
    switch(edge8[1])
80
      {
81
      case 0: case 2: rotatePermutations(corner,edge8,3);
82
                      break;
83
      case 4: case 5: rotatePermutations(corner,edge8,4);
84
                      break;
85
      case 6: case 7: rotatePermutations(corner,edge8,2);
86
                      break;
87
      }
88
    }
89 36

  
90 37
///////////////////////////////////////////////////////////////////////////////////////////////////
91 38

  
......
220 167

  
221 168
  private int computeFaceColors(int[][] corners, int[][] edges, int[] centers)
222 169
    {
223
    mFaceColors[2] = centers[0];
224
    mFaceColors[3] = centers[1];
170
    mFaceColors[4] = edges[1][0];
171
    mFaceColors[3] = edges[1][1];
225 172

  
226
    if( edges[1][1]==mFaceColors[2] || edges[1][1]==mFaceColors[3] )
227
      {
228
      mFaceColors[4] = edges[1][0];
229
      }
173
         if( centers[0]!=mFaceColors[3] ) mFaceColors[2] = centers[0];
174
    else if( centers[1]!=mFaceColors[3] ) mFaceColors[2] = centers[1];
230 175
    else return ERROR_CORNERS_CANNOT;
231 176

  
232 177
    mFaceColors[0] = findCorner(corners,mFaceColors[4],mFaceColors[2]);
......
337 282
    int result2 = retEdgePermutation(edge_perm8,edges);
338 283
    if( result2<0 ) return result2;
339 284

  
340
    TablebaseHelpers.displayTable(corner_perm, "CORNER PERM (before norm)");
341
    TablebaseHelpers.displayTable(edge_perm8, "EDGE PERM8 (before norm)");
342

  
343
    normalizePermutations(corner_perm,edge_perm8);
344

  
345
    TablebaseHelpers.displayTable(corner_perm, "CORNER PERM (after norm)");
346
    TablebaseHelpers.displayTable(edge_perm8, "EDGE PERM8 (after norm)");
347

  
348 285
    int[] edge_perm7 = TBCuboid323.edgePermTo7(edge_perm8);
349 286

  
350
TablebaseHelpers.displayTable(edge_perm7, "EDGE PERM7");
287
    TablebaseHelpers.displayTable(corner_perm, "CORNER PERM");
288
    TablebaseHelpers.displayTable(edge_perm8, "EDGE PERM8");
289
    TablebaseHelpers.displayTable(edge_perm7, "EDGE PERM7");
351 290

  
352 291
    int corner_perm_num = TablebaseHelpers.computePermutationNum(corner_perm);
353 292
    int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm7);
354
    boolean inPlace = TBCuboid323.isFrontEdgeInItsPlace(edge_perm8);
355

  
356
android.util.Log.e("D", "corner_perm_num: "+corner_perm_num+" edge_perm_num: "+edge_perm_num+" inPlace: "+inPlace);
357
android.util.Log.e("D", "index="+(corner_perm_num + 40320*( (inPlace?0:1) + 2*edge_perm_num)));
293
    int centersInPlace = (centers[0]==mFaceColors[2]) ? 0 : 1;
358 294

  
359
    TBCuboid323.initialize();
295
android.util.Log.e("D", "corner_perm_num: "+corner_perm_num+" edge_perm_num: "+edge_perm_num+" inPlace: "+centersInPlace);
296
android.util.Log.e("D", "index="+(corner_perm_num + 40320*( centersInPlace + 2*edge_perm_num)));
360 297

  
361
    return corner_perm_num + 40320*( (inPlace?0:1) + 2*edge_perm_num);
298
    return corner_perm_num + 40320*( centersInPlace + 2*edge_perm_num);
362 299
    }
363 300

  
364 301
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff