Project

General

Profile

« Previous | Next » 

Revision b4f45fdc

Added by Leszek Koltunski about 1 year ago

Skewb solver: full TB version works now.

View differences:

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

  
10 10
package org.distorted.solvers;
11 11

  
12
import static org.distorted.objectlib.tablebases.TBSkewb.FREE;
13

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

  
14 16
import org.distorted.main.R;
......
68 70

  
69 71
  private void getCenters(TwistyObject object, int[] centers)
70 72
    {
71
    int[] map = {12,13,10,11,8,9};
73
    final int[] face_colors = {4,5,2,3,0,1};
74
    int[] tmp = new int[6];
72 75

  
73 76
    for(int i=0; i<6; i++)
74
      centers[i] = object.getCubitFaceStickerIndex(map[i],0) - 6;
77
      {
78
      int color = object.getCubitFaceStickerIndex(i+8,0) - 6;
79
      tmp[i] = face_colors[color];
80
      }
81

  
82
    TablebaseHelpers.invertPermutation(tmp,centers);
75 83
    }
76 84

  
77 85
///////////////////////////////////////////////////////////////////////////////////////////////////
......
166 174
    }
167 175

  
168 176
///////////////////////////////////////////////////////////////////////////////////////////////////
169
// free corners: 1,2,4,7
170 177

  
171 178
  private int retFreeCornerPermutation(int[] perm, int[][] corners)
172 179
    {
173
    int[] map = {1,2,4,7};
174

  
175 180
    perm[0] = -1;
176 181
    perm[1] = -1;
177 182
    perm[2] = -1;
......
179 184

  
180 185
    for(int i=0; i<4; i++)
181 186
      {
182
      int[] cor = corners[map[i]];
187
      int[] cor = corners[FREE[i]];
183 188

  
184 189
      if( cornerIs(cor,2,5,0) ) perm[0] = i;
185 190
      if( cornerIs(cor,3,4,0) ) perm[1] = i;
......
199 204

  
200 205
  private int retCornerPerm(int index, int[] perm)
201 206
    {
202
    int[] free = {1,2,4,7};
203

  
204 207
    switch(index)
205 208
      {
206 209
      case 0: return 0;
207
      case 1: return free[perm[0]];
208
      case 2: return free[perm[1]];
210
      case 1: return FREE[perm[0]];
211
      case 2: return FREE[perm[1]];
209 212
      case 3: return 3;
210
      case 4: return free[perm[2]];
213
      case 4: return FREE[perm[2]];
211 214
      case 5: return 5;
212 215
      case 6: return 6;
213
      case 7: return free[perm[3]];
216
      case 7: return FREE[perm[3]];
214 217
      }
215 218

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

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

  
231
           if( c[0]==color ) twists[i] = 0;
232
      else if( c[1]==color ) twists[i] = 1;
233
      else                   twists[i] = 2;
234
           if( c[0]==color ) twist[i] = 0;
235
      else if( c[1]==color ) twist[i] = 1;
236
      else                   twist[i] = 2;
234 237
      }
235 238

  
236
    TBSkewb.fillInQuats(quats,perm,twists);
239
    TBSkewb.fillInQuats(quats,perm,twist);
237 240
    }
238 241

  
239 242
///////////////////////////////////////////////////////////////////////////////////////////////////
......
257 260
    getCenters(object,centers);
258 261
    int result3 = checkAllCentersPresent(centers);
259 262
    if( result3<0 ) return result3;
260
/*
261
for(int i=0; i<8; i++)
262
  for(int j=0; j<3; j++) android.util.Log.e("D", "corner "+i+" face "+j+" : "+corners[i][j]);
263 263

  
264
for(int i=0; i<6; i++) android.util.Log.e("D", "center "+i+" : "+centers[i]);
265
for(int i=0; i<6; i++) android.util.Log.e("D", "face "+i+" : "+mFaceColors[i]);
266
*/
267 264
    if( !TablebaseHelpers.permutationIsEven(centers) ) return ERROR_TWO_CENTERS;
268 265
    int center_perm_num = TablebaseHelpers.computeEvenPermutationNum(centers);
269 266

  
......
272 269

  
273 270
    computeCornerQuats(quats,corners,freePerm);
274 271
    TBSkewb.computeCornerTwists(twist,quats);
275
/*
276
for(int i=0; i<4; i++) android.util.Log.e("D", "perm "+i+" : "+freePerm[i]);
277
for(int i=0; i<8; i++) android.util.Log.e("D", "quat "+i+" : "+quats[i]);
278
for(int i=0; i<8; i++) android.util.Log.e("D", "twist "+i+" : "+twist[i]);
279
*/
280
    int total = twist[1]+twist[2]+twist[4]+twist[7];
272

  
273
    int total = 0;
274
    for(int i=0; i<4; i++) total += twist[FREE[i]];
281 275
    if( (total%3)!=0 ) return ERROR_CORNER_TWISTED;
282 276
    int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6])))));
283 277

  
......
399 393
    if( mSolver==null )
400 394
      {
401 395
      mSolver = ImplementedTablebasesList.createPacked(res,ObjectSignatures.SKEW_2);
402
/*
403
      if( mSolver!=null )
404
        {
405
        mSolver.createTablebase(-1);
406
        mSolver.pack();
407
       //mSolver.test();
408
        }
409

  
410
 */
411 396
      }
412 397

  
413 398
    return mSolver!=null ? mSolver.solution(index,null) : null;

Also available in: Unified diff