Project

General

Profile

« Previous | Next » 

Revision 673c1a11

Added by Leszek Koltunski over 1 year ago

CU_323 solver: progress

View differences:

src/main/java/org/distorted/solvers/SolverCuboid323.java
16 16
import org.distorted.objectlib.main.ObjectSignatures;
17 17
import org.distorted.objectlib.main.TwistyObject;
18 18
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
19
import org.distorted.objectlib.tablebases.TablebaseHelpers;
19 20
import org.distorted.objectlib.tablebases.TablebasesAbstract;
20 21

  
21 22
///////////////////////////////////////////////////////////////////////////////////////////////////
......
34 35
  private boolean mUpper;
35 36

  
36 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
// if mUpper==true, then the edge3 is the 'half-fixed' front edge. Remove it from the permutation.
39
// Otherwise edge1 is the one; remove it.
37 40

  
38
  private int edgeIs(int[] edge, int i0, int i1)
39
    {
40
    int c0 = mFaceColors[i0];
41
    int c1 = mFaceColors[i1];
42

  
43
    if( edge[0]==c0 && edge[1]==c1 ) return 0;
44
    if( edge[0]==c1 && edge[1]==c0 ) return 1;
45
    return 2;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  private int retEdgePermutation(int[] output, int[][] edges)
41
  private int[] correctEdgePerm(int[] perm)
51 42
    {
52
    for(int i=0; i<4; i++) output[i] = -1;
43
    int val;
44
    int[] ret = new int[7];
53 45

  
54
    for(int i=0; i<4; i++)
46
    if( mUpper )
55 47
      {
56
      int edge0 = edgeIs(edges[i],1,5);
57
           if( edge0==0 ) output[0]=i;
58
      else if( edge0==1 ) return ERROR_EDGE_TWISTED;
59

  
60
      int edge1 = edgeIs(edges[i],1,4);
61
           if( edge1==0 ) output[1]=i;
62
      else if( edge1==1 ) return ERROR_EDGE_TWISTED;
63

  
64
      int edge2 = edgeIs(edges[i],0,5);
65
           if( edge2==0 ) output[2]=i;
66
      else if( edge2==1 ) return ERROR_EDGE_TWISTED;
67

  
68
      int edge3 = edgeIs(edges[i],0,4);
69
           if( edge3==0 ) output[3]=i;
70
      else if( edge3==1 ) return ERROR_EDGE_TWISTED;
48
      ret[0] = perm[0];
49
      ret[1] = perm[1];
50
      ret[2] = perm[2];
51
      ret[3] = perm[4];
52
      ret[4] = perm[5];
53
      ret[5] = perm[6];
54
      ret[6] = perm[7];
55

  
56
      val = perm[3];
71 57
      }
72
/*
73
    if( output[0]==-1 ) return ERROR_EDGE_15_MISSING;
74
    if( output[1]==-1 ) return ERROR_EDGE_14_MISSING;
75
    if( output[2]==-1 ) return ERROR_EDGE_05_MISSING;
76
    if( output[3]==-1 ) return ERROR_EDGE_04_MISSING;
77
*/
78
    return 0;
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  private int cornerIs(int[] corner, int i0, int i1, int i2)
84
    {
85
    int c0 = mFaceColors[i0];
86
    int c1 = mFaceColors[i1];
87
    int c2 = mFaceColors[i2];
88

  
89
    if( corner[0]==c0 && corner[1]==c1 && corner[2]==c2 ) return 0;
90

  
91
    if( corner[0]==c0 && corner[1]==c2 && corner[2]==c1 ||
92
        corner[0]==c1 && corner[1]==c0 && corner[2]==c2 ||
93
        corner[0]==c1 && corner[1]==c2 && corner[2]==c0 ||
94
        corner[0]==c2 && corner[1]==c0 && corner[2]==c1 ||
95
        corner[0]==c2 && corner[1]==c1 && corner[2]==c0  ) return 1;
96

  
97
    return 2;
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  private int retCornerPermutation(int[] output, int[][] corners)
103
    {
104
    for(int i=0; i<8; i++) output[i] = -1;
105

  
106
    for(int i=0; i<8; i++)
58
    else
107 59
      {
108
      int corner7 = cornerIs(corners[i],2,4,0);
109
           if( corner7==0 ) output[7]=i;
110
      else if( corner7==1 ) return ERROR_CORNER_TWISTED;
111

  
112
      int corner6 = cornerIs(corners[i],2,0,5);
113
           if( corner6==0 ) output[6]=i;
114
      else if( corner6==1 ) return ERROR_CORNER_TWISTED;
115

  
116
      int corner5 = cornerIs(corners[i],3,0,4);
117
           if( corner5==0 ) output[5]=i;
118
      else if( corner5==1 ) return ERROR_CORNER_TWISTED;
119

  
120
      int corner4 = cornerIs(corners[i],3,5,0);
121
           if( corner4==0 ) output[4]=i;
122
      else if( corner4==1 ) return ERROR_CORNER_TWISTED;
123

  
124
      int corner3 = cornerIs(corners[i],2,1,4);
125
           if( corner3==0 ) output[3]=i;
126
      else if( corner3==1 ) return ERROR_CORNER_TWISTED;
127

  
128
      int corner2 = cornerIs(corners[i],2,5,1);
129
           if( corner2==0 ) output[2]=i;
130
      else if( corner2==1 ) return ERROR_CORNER_TWISTED;
60
      ret[0] = perm[0];
61
      ret[1] = perm[2];
62
      ret[2] = perm[3];
63
      ret[3] = perm[4];
64
      ret[4] = perm[5];
65
      ret[5] = perm[6];
66
      ret[6] = perm[7];
67

  
68
      val = perm[1];
69
      }
131 70

  
132
      int corner1 = cornerIs(corners[i],3,4,1);
133
           if( corner1==0 ) output[1]=i;
134
      else if( corner1==1 ) return ERROR_CORNER_TWISTED;
71
    for(int i=0; i<7; i++)
72
      if( ret[i]>val ) ret[i]--;
135 73

  
136
      int corner0 = cornerIs(corners[i],3,1,5);
137
           if( corner0==0 ) output[0]=i;
138
      else if( corner0==1 ) return ERROR_CORNER_TWISTED;
139
      }
140
/*
141
    if( output[0]==-1 ) return ERROR_CORNER_135_MISSING;
142
    if( output[1]==-1 ) return ERROR_CORNER_134_MISSING;
143
    if( output[2]==-1 ) return ERROR_CORNER_125_MISSING;
144
    if( output[3]==-1 ) return ERROR_CORNER_124_MISSING;
145
    if( output[4]==-1 ) return ERROR_CORNER_035_MISSING;
146
    if( output[5]==-1 ) return ERROR_CORNER_034_MISSING;
147
    if( output[6]==-1 ) return ERROR_CORNER_025_MISSING;
148
    if( output[7]==-1 ) return ERROR_CORNER_024_MISSING;
149
*/
150
    return 0;
74
    return ret;
151 75
    }
152 76

  
153 77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// 0 or 1, depending on if the 'half-fixed' front edge is in its place or not.
79
// if the 'half-fixed' edge is the upped front one ( i.e. mUpper==true) than it can be in its
80
// place or not; if mUpper==false it always must be in its place.
154 81

  
155
  private int[] correctEdgePerm(int[] perm)
82
  private boolean isFrontEdgeInItsPlace(int[][] edges)
156 83
    {
157
    int[] ret = new int[3];
158

  
159
    ret[0] = perm[0];
160
    ret[1] = perm[2];
161
    ret[2] = perm[3];
162

  
163
    if( ret[0]>1 ) ret[0]--;
164
    if( ret[1]>1 ) ret[1]--;
165
    if( ret[2]>1 ) ret[2]--;
166

  
167
    return ret;
84
    return (!mUpper || edges[3][1]==mFaceColors[2]);
168 85
    }
169 86

  
170 87
///////////////////////////////////////////////////////////////////////////////////////////////////
......
217 134
    int c0 = mFaceColors[f0];
218 135
    int c1 = mFaceColors[f1];
219 136

  
220
    for(int[] edge : edges)
137
    for(int i=0; i<8; i++ )
221 138
      {
222
      if( edge[0]==c0 && edge[1]==c1 )
223
        return 0;
139
      int[] edge = edges[i];
140

  
141
      if( edge[0]==c0 && edge[1]==c1 ) return i;
224 142
      if( edge[0]==c1 && edge[1]==c0 )
225 143
        {
226 144
        mErrorColor1 = c0;
......
242 160
    int c1 = mFaceColors[f1];
243 161
    int c2 = mFaceColors[f2];
244 162

  
245
    for(int[] corner : corners )
163
    for(int i=0; i<8; i++)
246 164
      {
247
      if(  corner[0]==c0 && corner[1]==c1 && corner[2]==c2 ) return 0;
165
      int[] corner = corners[i];
166

  
167
      if(  corner[0]==c0 && corner[1]==c1 && corner[2]==c2 ) return i;
248 168
      if( (corner[0]==c1 && corner[1]==c2 && corner[2]==c0 ) ||
249 169
          (corner[0]==c2 && corner[1]==c0 && corner[2]==c1 )  )
250 170
        {
......
263 183

  
264 184
////////////////////////////////////////////////////////////////////////////////////////
265 185

  
266
  private int checkAllEdgesPresent(int[][] edges)
186
  private int retEdgePermutation(int[] output, int[][] edges)
267 187
    {
268
    int result;
269

  
270
    result = edgePresent(edges,0,2);
271
    if( result<0 ) return result;
272
    result = edgePresent(edges,1,2);
273
    if( result<0 ) return result;
274
    result = edgePresent(edges,4,2);
275
    if( result<0 ) return result;
276
    result = edgePresent(edges,5,2);
277
    if( result<0 ) return result;
278
    result = edgePresent(edges,0,3);
279
    if( result<0 ) return result;
280
    result = edgePresent(edges,1,3);
281
    if( result<0 ) return result;
282
    result = edgePresent(edges,4,3);
283
    if( result<0 ) return result;
284
    result = edgePresent(edges,5,3);
285
    if( result<0 ) return result;
188
    int[][] e = { {5,3}, {4,3}, {5,2}, {4,2}, {1,3}, {1,2}, {0,3}, {0,2} };
189

  
190
    for(int i=0; i<8; i++)
191
      {
192
      int[] ee = e[i];
193
      output[i] = edgePresent(edges,ee[0],ee[1]);
194
      if( output[i]<0 ) return output[i];
195
      }
286 196

  
287 197
    return 0;
288 198
    }
289 199

  
290 200
////////////////////////////////////////////////////////////////////////////////////////
291 201

  
292
  private int checkAllCornersPresent(int[][] corners)
202
  private int retCornerPermutation(int[] output, int[][] corners)
293 203
    {
294
    int result;
295

  
296
    result = cornerPresent(corners,0,4,2);
297
    if( result<0 ) return result;
298
    result = cornerPresent(corners,5,0,2);
299
    if( result<0 ) return result;
300
    result = cornerPresent(corners,1,5,2);
301
    if( result<0 ) return result;
302
    result = cornerPresent(corners,4,1,2);
303
    if( result<0 ) return result;
304
    result = cornerPresent(corners,4,0,3);
305
    if( result<0 ) return result;
306
    result = cornerPresent(corners,0,5,3);
307
    if( result<0 ) return result;
308
    result = cornerPresent(corners,5,1,3);
309
    if( result<0 ) return result;
310
    result = cornerPresent(corners,1,4,3);
311
    if( result<0 ) return result;
204
    int[][] c = { {5,1,3}, {1,4,3}, {1,5,2}, {4,1,2}, {0,5,3}, {4,0,3}, {5,0,2}, {0,4,2} };
205

  
206
    for(int i=0; i<8; i++)
207
      {
208
      int[] cc = c[i];
209
      output[i] = cornerPresent(corners,cc[0],cc[1],cc[2]);
210
      if( output[i]<0 ) return output[i];
211
      }
312 212

  
313 213
    return 0;
314 214
    }
......
428 328
    getCenters(object,centers);
429 329

  
430 330
for(int i=0; i<8; i++) android.util.Log.e("D", "corner: "+i+" : "+corners[i][0]+" "+corners[i][1]+" "+corners[i][2]);
331
for(int i=0; i<8; i++) android.util.Log.e("D", "edge: "+i+" : "+edges[i][0]+" "+edges[i][1]);
431 332

  
432 333
    int result0 = computeFaceColors(corners, edges, centers);
433 334
    if( result0<0 ) return result0;
434 335

  
435
    int result1 = checkAllEdgesPresent(edges);
336
    int[] corner_perm = new int[8];
337
    int result1 = retCornerPermutation(corner_perm,corners);
436 338
    if( result1<0 ) return result1;
437 339

  
438
    int result2 = checkAllCornersPresent(corners);
439
    if( result2<0 ) return result2;
440

  
441 340
android.util.Log.e("D", "upper: "+mUpper);
442 341
for(int i=0; i<6; i++) android.util.Log.e("D", "face color: "+mFaceColors[i]);
443
/*
444
    int[] corner_perm = new int[8];
445
    int result1 = retCornerPermutation(corner_perm,corners);
446
    if( result1<0 ) return result1;
447 342

  
448 343
    int[] edge_perm = new int[8];
449 344
    int result2 = retEdgePermutation(edge_perm,edges);
450 345
    if( result2<0 ) return result2;
451 346

  
452
    int[] edge_perm2 = correctEdgePerm(edge_perm); // edge1 is fixed!
347
    TablebaseHelpers.displayTable(corner_perm, "CORNER PERM");
348
    TablebaseHelpers.displayTable(edge_perm, "EDGE PERM");
349

  
350
    int[] edge_perm2 = correctEdgePerm(edge_perm); // edge1 (lower) or edge3 (upper) is fixed!
453 351

  
454 352
    int corner_perm_num = TablebaseHelpers.computePermutationNum(corner_perm);
455 353
    int edge_perm_num = TablebaseHelpers.computePermutationNum(edge_perm2);
354
    boolean inPlace = isFrontEdgeInItsPlace(edges);
456 355

  
457
    return edge_perm_num + 6*corner_perm_num;
356
android.util.Log.e("D", "corner_perm_num: "+corner_perm_num+" edge_perm_num: "+edge_perm_num+" inPlace: "+inPlace);
458 357

  
459
 */
460
    return 0;
358
    return corner_perm_num + 20160*( (inPlace?0:1) + 2*edge_perm_num);
461 359
    }
462 360

  
463 361
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff