Project

General

Profile

« Previous | Next » 

Revision 62c08ea7

Added by Leszek Koltunski over 1 year ago

Progress with Skewb Diamond solver.

View differences:

src/main/java/org/distorted/solvers/SolverSkewbDiamond.java
14 14
import org.distorted.objectlib.main.ObjectType;
15 15
import org.distorted.objectlib.main.TwistyObject;
16 16
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
17
import org.distorted.objectlib.tablebases.TablebaseHelpers;
17 18
import org.distorted.objectlib.tablebases.TablebasesAbstract;
18 19

  
19 20
///////////////////////////////////////////////////////////////////////////////////////////////////
......
39 40
  private static final int ERROR_TWO_CORNERS      = -15;
40 41
  private static final int ERROR_TWO_CENTERS      = -16;
41 42
  private static final int ERROR_CORNER_TWIST     = -17;
43
  private static final int ERROR_CORNERS_CANNOT   = -18;
42 44

  
43 45
  private TablebasesAbstract mSolver;
44 46

  
......
49 51
    super(res,object);
50 52
    }
51 53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
  private int[] getCornersPermutation(int[] colors, int[][] corners)
57
    {
58

  
59
    }
60

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

  
63
  private int[] getCornersTwist(int[] colors, int[][] corners)
64
    {
65

  
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  private int[] getFreeCentersPermutation(int[] colors, int[] centers)
71
    {
72

  
73
    }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  private int getTotalTwist(int[] twist)
78
    {
79
    int total = 0;
80

  
81
    for(int i=0; i<6; i++)
82
      {
83
      int t= twist[i];
84
      if( t==1 || t==3 ) return -1;
85
      if( t==2 ) total++;
86
      total *= 2;
87
      }
88

  
89
    return total;
90
    }
91

  
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

  
94
  private int figureOutColor(int[][] corners, int c1, int c2)
95
    {
96
    for(int i=0; i<6; i++)
97
      {
98
      int[] cor = corners[i];
99

  
100
      if( cor[0]==c1 && cor[2]==c2 ) return cor[1];
101
      if( cor[1]==c1 && cor[3]==c2 ) return cor[2];
102
      if( cor[2]==c1 && cor[0]==c2 ) return cor[3];
103
      if( cor[3]==c1 && cor[1]==c2 ) return cor[0];
104
      }
105

  
106
    return -1;
107
    }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
// We only move the UR, UR, DR & DB faces --> those centers are fixed and determine the colors of
111
// the faces.
112

  
113
  private int figureOutFaceColors(int[] output, int[] centers, int[][] corners)
114
    {
115
    output[1] = centers[1];
116
    output[3] = centers[3];
117
    output[4] = centers[4];
118
    output[6] = centers[6];
119

  
120
    int color01 = figureOutColor(corners,output[4],output[1]);
121
    if( color01<0 ) return ERROR_CORNER_FR_MISSING;
122
    int color02 = figureOutColor(corners,output[3],output[4]);
123
    if( color02<0 ) return ERROR_CORNER_FL_MISSING;
124
    int color03 = figureOutColor(corners,output[1],output[3]);
125
    if( color03<0 ) return ERROR_CORNER_TO_MISSING;
126
    if( color01!=color02 || color01!=color03 ) return ERROR_CORNERS_CANNOT;
127
    output[0] = color01;
128

  
129
    int color21 = figureOutColor(corners,output[1],output[6]);
130
    if( color21<0 ) return ERROR_CORNER_BR_MISSING;
131
    int color22 = figureOutColor(corners,output[6],output[3]);
132
    if( color22<0 ) return ERROR_CORNER_BL_MISSING;
133
    int color23 = figureOutColor(corners,output[3],output[1]);
134
    if( color23<0 ) return ERROR_CORNER_TO_MISSING;
135
    if( color21!=color22 || color21!=color23 ) return ERROR_CORNERS_CANNOT;
136
    output[2] = color21;
137

  
138
    int color51 = figureOutColor(corners,output[1],output[4]);
139
    if( color51<0 ) return ERROR_CORNER_FR_MISSING;
140
    int color52 = figureOutColor(corners,output[6],output[1]);
141
    if( color52<0 ) return ERROR_CORNER_BR_MISSING;
142
    int color53 = figureOutColor(corners,output[4],output[6]);
143
    if( color53<0 ) return ERROR_CORNER_BO_MISSING;
144
    if( color51!=color52 || color51!=color53 ) return ERROR_CORNERS_CANNOT;
145
    output[5] = color51;
146

  
147
    int color71 = figureOutColor(corners,output[3],output[6]);
148
    if( color71<0 ) return ERROR_CORNER_BL_MISSING;
149
    int color72 = figureOutColor(corners,output[4],output[3]);
150
    if( color72<0 ) return ERROR_CORNER_FL_MISSING;
151
    int color73 = figureOutColor(corners,output[6],output[4]);
152
    if( color73<0 ) return ERROR_CORNER_BO_MISSING;
153
    if( color71!=color72 || color71!=color73 ) return ERROR_CORNERS_CANNOT;
154
    output[7] = color71;
155

  
156
    return 0;
157
    }
158

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

  
161
  private int checkAllColorsDifferent(int[] colors)
162
    {
163
    for(int i=0; i<8; i++)
164
      {
165
      boolean present = false;
166

  
167
      for(int j=0; j<8; j++)
168
        if( colors[j]==i )
169
          {
170
          present=true;
171
          break;
172
          }
173

  
174
      if( !present ) return ERROR_CORNERS_CANNOT;
175
      }
176

  
177
    return 0;
178
    }
179

  
52 180
///////////////////////////////////////////////////////////////////////////////////////////////////
53 181

  
54 182
  private int checkAllCentersPresent(int[] centers)
55 183
    {
184
    for(int i=0; i<8; i++)
185
      {
186
      boolean present = false;
187

  
188
      for(int j=0; j<8; j++)
189
        if( centers[j]==i )
190
          {
191
          present=true;
192
          break;
193
          }
194

  
195
      if( !present )
196
        {
197
        switch(i)
198
          {
199
          case 0: return ERROR_CENTER_0_MISSING;
200
          case 1: return ERROR_CENTER_1_MISSING;
201
          case 2: return ERROR_CENTER_2_MISSING;
202
          case 3: return ERROR_CENTER_3_MISSING;
203
          case 4: return ERROR_CENTER_4_MISSING;
204
          case 5: return ERROR_CENTER_5_MISSING;
205
          case 6: return ERROR_CENTER_6_MISSING;
206
          case 7: return ERROR_CENTER_7_MISSING;
207
          }
208
        }
209
      }
210

  
56 211
    return 0;
57 212
    }
58 213

  
......
95 250

  
96 251
  private void getCenters(TwistyObject object, int[] centers)
97 252
    {
98
    centers[0] = object.getCubitFaceStickerIndex( 6,0); // UR
99
    centers[1] = object.getCubitFaceStickerIndex( 8,0); // UL
100
    centers[2] = object.getCubitFaceStickerIndex(11,0); // DB
101
    centers[3] = object.getCubitFaceStickerIndex(13,0); // DF
102
    centers[4] = object.getCubitFaceStickerIndex( 9,0); // UF
103
    centers[5] = object.getCubitFaceStickerIndex( 7,0); // UB
104
    centers[6] = object.getCubitFaceStickerIndex(12,0); // DL
105
    centers[7] = object.getCubitFaceStickerIndex(10,1); // DR
253
    centers[0] = object.getCubitFaceStickerIndex( 9,0); // UF
254
    centers[1] = object.getCubitFaceStickerIndex( 6,0); // UR
255
    centers[2] = object.getCubitFaceStickerIndex( 7,0); // UB
256
    centers[3] = object.getCubitFaceStickerIndex( 8,0); // UL
257
    centers[4] = object.getCubitFaceStickerIndex(13,0); // DF
258
    centers[5] = object.getCubitFaceStickerIndex(10,1); // DR
259
    centers[6] = object.getCubitFaceStickerIndex(11,0); // DB
260
    centers[7] = object.getCubitFaceStickerIndex(12,0); // DL
106 261
    }
107 262

  
108 263
///////////////////////////////////////////////////////////////////////////////////////////////////
......
111 266
    {
112 267
    int[][] corners = new int[6][4];
113 268
    int[] centers = new int[8];
269
    int[] face_colors = new int[8];
114 270

  
115 271
    getCorners(object,corners);
116 272
    getCenters(object,centers);
......
118 274
    int result1 = checkAllCentersPresent(centers);
119 275
    if( result1<0 ) return result1;
120 276

  
121
    return 0;
277
    int result2 = figureOutFaceColors(face_colors,centers,corners);
278
    if( result2<0 ) return result2;
279

  
280
    int result3 = checkAllColorsDifferent(face_colors);
281
    if( result3<0 ) return result3;
282

  
283
    int[] corners_perm = getCornersPermutation(face_colors, corners);
284
    boolean even1 = TablebaseHelpers.permutationIsEven(corners_perm);
285
    if( !even1 ) return ERROR_TWO_CORNERS;
286

  
287
    int[] free_centers_perm = getFreeCentersPermutation(face_colors, centers);
288
    boolean even2 = TablebaseHelpers.permutationIsEven(free_centers_perm);
289
    if( !even2 ) return ERROR_TWO_CENTERS;
290

  
291
    int[] corners_twist = getCornersTwist(face_colors, corners);
292
    int totalTwist = getTotalTwist(corners_twist);
293
    if( totalTwist<0 ) return ERROR_CORNER_TWIST;
294

  
295
    int corners_perm_num = TablebaseHelpers.computeEvenPermutationNum(corners_perm);
296
    int centers_perm_num = TablebaseHelpers.computeEvenPermutationNum(free_centers_perm);
297

  
298
    return centers_perm_num + 12*(totalTwist + 128*corners_perm_num);
122 299
    }
123 300

  
124 301
///////////////////////////////////////////////////////////////////////////////////////////////////
......
127 304
    {
128 305
    switch(index)
129 306
      {
130
  /*
131
 private static final int ERROR_CORNER_FR_MISSING = -1;
132
  private static final int ERROR_CORNER_BR_MISSING = -2;
133
  private static final int ERROR_CORNER_BL_MISSING = -3;
134
  private static final int ERROR_CORNER_FL_MISSING = -4;
135
  private static final int ERROR_CORNER_TO_MISSING = -5;
136
  private static final int ERROR_CORNER_BO_MISSING = -6;
137

  
138
  private static final int ERROR_CENTER_0_MISSING = -7;
139
  private static final int ERROR_CENTER_1_MISSING = -8;
140
  private static final int ERROR_CENTER_2_MISSING = -9;
141
  private static final int ERROR_CENTER_3_MISSING = -10;
142
  private static final int ERROR_CENTER_4_MISSING = -11;
143
  private static final int ERROR_CENTER_5_MISSING = -12;
144
  private static final int ERROR_CENTER_6_MISSING = -13;
145
  private static final int ERROR_CENTER_7_MISSING = -14;
146

  
147
  private static final int ERROR_TWO_CORNERS      = -15;
148
  private static final int ERROR_TWO_CENTERS      = -16;
149
  private static final int ERROR_CORNER_TWIST     = -17;
150

  
151
   */
307
      case ERROR_CORNER_FR_MISSING:
308
      case ERROR_CORNER_BR_MISSING:
309
      case ERROR_CORNER_BL_MISSING:
310
      case ERROR_CORNER_FL_MISSING:
311
      case ERROR_CORNER_TO_MISSING:
312
      case ERROR_CORNER_BO_MISSING:
313

  
314
      case ERROR_CENTER_0_MISSING :
315
      case ERROR_CENTER_1_MISSING :
316
      case ERROR_CENTER_2_MISSING :
317
      case ERROR_CENTER_3_MISSING :
318
      case ERROR_CENTER_4_MISSING :
319
      case ERROR_CENTER_5_MISSING :
320
      case ERROR_CENTER_6_MISSING :
321
      case ERROR_CENTER_7_MISSING :
322

  
323
      case ERROR_TWO_CORNERS      :
324
      case ERROR_TWO_CENTERS      :
325
      case ERROR_CORNER_TWIST     :
326
      case ERROR_CORNERS_CANNOT   :
152 327
      }
153 328

  
154 329
    return null;

Also available in: Unified diff