Project

General

Profile

« Previous | Next » 

Revision 6a64512e

Added by Leszek Koltunski about 1 year ago

Skewb solver: corrections for error detection.

View differences:

src/main/java/org/distorted/solvers/SolverSkewb.java
68 68

  
69 69
///////////////////////////////////////////////////////////////////////////////////////////////////
70 70

  
71
  private void getCenters(TwistyObject object, int[] centers)
71
  private int getCenters(TwistyObject object, int[] output)
72 72
    {
73
    final int[] face_colors = {4,5,2,3,0,1};
74
    int[] tmp = new int[6];
73
    final int[] map = {4,5,2,3,0,1};
74
    int[] inverted_perm = new int[6];
75
    boolean[] present = new boolean[6];
75 76

  
76 77
    for(int i=0; i<6; i++)
77 78
      {
78 79
      int color = object.getCubitFaceStickerIndex(i+8,0) - 6;
79
      tmp[i] = face_colors[color];
80
      present[color] = true;
81
      inverted_perm[i] = map[mFaceColors[color]];
80 82
      }
81 83

  
82
    TablebaseHelpers.invertPermutation(tmp,centers);
84
    if( !present[0] ) return ERROR_CENTER_0_MISSING;
85
    if( !present[1] ) return ERROR_CENTER_1_MISSING;
86
    if( !present[2] ) return ERROR_CENTER_2_MISSING;
87
    if( !present[3] ) return ERROR_CENTER_3_MISSING;
88
    if( !present[4] ) return ERROR_CENTER_4_MISSING;
89
    if( !present[5] ) return ERROR_CENTER_5_MISSING;
90

  
91
    TablebaseHelpers.invertPermutation(inverted_perm,output);
92
    return 0;
83 93
    }
84 94

  
85 95
///////////////////////////////////////////////////////////////////////////////////////////////////
......
104 114

  
105 115
  private int computeFaceColors(int[][] corners, int[] output)
106 116
    {
107
    final int[][] map = { {0,3},{5,6},{0,5},{6,3},{0,6},{3,5} };
117
    final int[][] corner_indices = { {0,3},{5,6},{0,5},{6,3},{0,6},{3,5} };
108 118

  
109 119
    for(int i=0; i<6; i++)
110 120
      {
111
      int c1 = map[i][0];
112
      int c2 = map[i][1];
121
      int c1 = corner_indices[i][0];
122
      int c2 = corner_indices[i][1];
113 123
      output[i] = commonCornerColor(corners[c1],corners[c2]);
114 124
      if( output[i]<0 ) return ERROR_CORNERS_CANNOT;
115 125
      }
......
119 129

  
120 130
///////////////////////////////////////////////////////////////////////////////////////////////////
121 131

  
122
  private boolean cornerIs(int[] corner, int c0, int c1, int c2)
132
  private boolean cornerIs(int[] corner, int f0, int f1, int f2)
123 133
    {
134
    int c0 = mFaceColors[f0];
135
    int c1 = mFaceColors[f1];
136
    int c2 = mFaceColors[f2];
137

  
124 138
    return ( (corner[0]==c0 && corner[1]==c1 && corner[2]==c2 ) ||
125 139
             (corner[1]==c0 && corner[2]==c1 && corner[0]==c2 ) ||
126 140
             (corner[2]==c0 && corner[0]==c1 && corner[1]==c2 )  );
......
156 170
    return 0;
157 171
    }
158 172

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
  private int checkAllCentersPresent(int[] centers)
162
    {
163
    boolean[] present = new boolean[6];
164
    for(int i=0; i<6; i++) present[centers[i]]= true;
165

  
166
    if( !present[0] ) return ERROR_CENTER_4_MISSING;
167
    if( !present[1] ) return ERROR_CENTER_5_MISSING;
168
    if( !present[2] ) return ERROR_CENTER_2_MISSING;
169
    if( !present[3] ) return ERROR_CENTER_3_MISSING;
170
    if( !present[4] ) return ERROR_CENTER_0_MISSING;
171
    if( !present[5] ) return ERROR_CENTER_1_MISSING;
172

  
173
    return 0;
174
    }
175

  
176 173
///////////////////////////////////////////////////////////////////////////////////////////////////
177 174

  
178 175
  private int retFreeCornerPermutation(int[] perm, int[][] corners)
......
223 220

  
224 221
  private void computeCornerQuats(int[] quats, int[][] corners, int[] perm)
225 222
    {
226
    final int[] map = { 4,2,3,5,1,5,4,1 };
223
    final int[] zeroeth_face_map = { 4,2,3,5,1,5,4,1 };
227 224
    int[] twist = new int[8];
228 225

  
229 226
    for(int i=0; i<8; i++)
230 227
      {
231
      int color = mFaceColors[map[i]];
228
      int color = mFaceColors[zeroeth_face_map[i]];
232 229
      int[] c = corners[retCornerPerm(i,perm)];
233 230

  
234 231
           if( c[0]==color ) twist[i] = 0;
......
257 254
    int result2 = checkAllCornersPresent(corners);
258 255
    if( result2<0 ) return result2;
259 256

  
260
    getCenters(object,centers);
261
    int result3 = checkAllCentersPresent(centers);
257
    int result3 = getCenters(object,centers);
262 258
    if( result3<0 ) return result3;
263 259

  
264 260
    if( !TablebaseHelpers.permutationIsEven(centers) ) return ERROR_TWO_CENTERS;

Also available in: Unified diff