Project

General

Profile

« Previous | Next » 

Revision 2d697abd

Added by Leszek Koltunski about 1 year ago

Progess with Skewb solver.

View differences:

src/main/java/org/distorted/objectlib/tablebases/TBSkewb.java
20 20

  
21 21
public class TBSkewb extends TablebasesAbstract
22 22
{
23
  private static final int[][] freeIndex = { {1,3,2},{0,2,3},{3,1,0},{2,0,1} };
24

  
23 25
  private static final int[][][] centerQuats =
24 26
    {
25 27
        { {0,10},{9,11},{1,7},{4,6},{2,5},{3,8} },
......
59 61

  
60 62
  public TBSkewb(Resources res)
61 63
    {
62
    super(res, R.raw.pyra_3_tablebase);
64
    super(res, R.raw.skew_2_tablebase);
63 65
    }
64 66

  
65 67
///////////////////////////////////////////////////////////////////////////////////////////////////
......
156 158

  
157 159
///////////////////////////////////////////////////////////////////////////////////////////////////
158 160

  
159
  public static int computeLocation(int quat)
161
  public static int computeLocation(int index, int quat)
160 162
    {
161 163
    for(int i=0; i<4; i++)
162 164
      {
163
      int[] q = freeQuats[0][i];
165
      int[] q = freeQuats[index][i];
164 166
      if( quat==q[0] || quat==q[1] || quat==q[2] ) return i;
165 167
      }
166 168

  
......
231 233
      {
232 234
      output[i] = -1;
233 235
      int[][] c = centerQuats[i];
234
      int q = quats[i];
236
      int q = quats[8+i];
235 237

  
236 238
      for(int j=0; j<6; j++)
237 239
        if( c[j][0]==q || c[j][1]==q )
......
250 252
    {
251 253
    for(int i=0; i<6; i++)
252 254
      {
253
      quats[i] = centerQuats[i][perm[i]][0];
255
      quats[8+i] = centerQuats[i][perm[i]][0];
254 256
      }
255 257
    }
256 258

  
257 259
///////////////////////////////////////////////////////////////////////////////////////////////////
258 260

  
259
  private int freeIndex(int taken, int seq)
261
  private void fillUpToEvenPerm(int[] perm)
260 262
    {
261
    return seq + (seq>=taken ? 1:0);
263
    int min, max;
264

  
265
         if( perm[0]!=0 && perm[1]!=0 ) min=0;
266
    else if( perm[0]!=1 && perm[1]!=1 ) min=1;
267
    else                                min=2;
268

  
269
         if( perm[0]!=3 && perm[1]!=3 ) max=3;
270
    else if( perm[0]!=2 && perm[1]!=2 ) max=2;
271
    else                                max=1;
272

  
273
    int diff = perm[1]-perm[0];
274

  
275
    if( diff==-2 || diff==1 || diff==3 ) { perm[2]=min; perm[3]=max; }
276
    else                                 { perm[2]=max; perm[3]=min; }
262 277
    }
263 278

  
264 279
///////////////////////////////////////////////////////////////////////////////////////////////////
265 280

  
266 281
  public int[] getQuats(int index)
267 282
    {
283
    int[] locationFree = new int[4];
268 284
    int center_perm_num = (index%360);
269 285
    index /= 360;
270 286
    int totalTwist = (index%2187);
271
    int locationOfFree0 = (index/2187);
287
    locationFree[0] = (index/2187);
272 288

  
273 289
    int[] quats = new int[14];
274 290
    int[] center_perm = new int[6];
......
286 302
    int total = twist[1]+twist[2]+twist[4];
287 303
    twist[7] = ((6-total)%3);
288 304

  
289
    int locationOfFree1 = freeIndex(locationOfFree0,0);
290
    int locationOfFree2 = freeIndex(locationOfFree0,1);
291
    int locationOfFree3 = freeIndex(locationOfFree0,2);
305
    int sumFixedTwists = ((twist[0]+twist[3]+twist[5]+twist[6])%3);
306
    locationFree[1] = freeIndex[locationFree[0]][sumFixedTwists];
307
    fillUpToEvenPerm(locationFree);
292 308

  
293 309
    quats[0] = fixedQuats[0][twist[0]];
294 310
    quats[3] = fixedQuats[1][twist[3]];
295 311
    quats[5] = fixedQuats[2][twist[5]];
296 312
    quats[6] = fixedQuats[3][twist[6]];
297 313

  
298
    quats[1] = freeQuats[0][locationOfFree0][twist[1]];
299
    quats[2] = freeQuats[1][locationOfFree1][twist[2]];
300
    quats[4] = freeQuats[2][locationOfFree2][twist[4]];
301
    quats[7] = freeQuats[3][locationOfFree3][twist[7]];
314
    quats[1] = freeQuats[0][locationFree[0]][twist[1]];
315
    quats[2] = freeQuats[1][locationFree[1]][twist[2]];
316
    quats[4] = freeQuats[2][locationFree[2]][twist[4]];
317
    quats[7] = freeQuats[3][locationFree[3]][twist[7]];
318

  
319
//android.util.Log.e("D", "QUATS center_perm: "+center_perm_num+" totalTwist="+totalTwist+" locationOfFree0="+locationOfFree0);
320
//android.util.Log.e("D", "QUATS t0="+twist[0]+" t1="+twist[1]+" t2="+twist[2]+" t3="+twist[3]+" t4="+twist[4]+" t5="+twist[5]+" t6="+twist[6]+" t7="+twist[7]);
302 321

  
303 322
    return quats;
304 323
    }
......
312 331
    int[] twist = new int[8];
313 332
    computeCornerTwists(twist,quats);
314 333
    int totalTwist = twist[0]+ 3*(twist[1]+ 3*(twist[2]+ 3*(twist[3]+ 3*(twist[4]+ 3*(twist[5]+ 3*twist[6])))));
315
    int locationOfFree0 = computeLocation(quats[1]);
334
    int locationOfFree0 = computeLocation(0,quats[1]);
335

  
336
//android.util.Log.e("D", "INDEX center_perm: "+center_perm_num+" totalTwist="+totalTwist+" locationOfFree0="+locationOfFree0);
337
//android.util.Log.e("D", "INDEX t0="+twist[0]+" t1="+twist[1]+" t2="+twist[2]+" t3="+twist[3]+" t4="+twist[4]+" t5="+twist[5]+" t6="+twist[6]+" t7="+twist[7]);
316 338

  
317 339
    return center_perm_num+ 360*(totalTwist + 2187*locationOfFree0);
318 340
    }
src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
587 587
        android.util.Log.e("D", "numbers: " + sb);
588 588
        }
589 589
      }
590

  
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592

  
593
    private void printQuats(int[] quats)
594
      {
595
      StringBuilder sb = new StringBuilder();
596
      for(int q : quats )
597
        {
598
        sb.append(' ');
599
        sb.append(q);
600
        }
601
      android.util.Log.e("D", "quats: "+sb);
602
      }
603

  
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605

  
606
    public void test()
607
      {
608
      int[] q1 = {1,1,1,0,1,0,0,0, 1,0,1,0,1,0 };
609
      int index1 = getIndex(q1);
610
      android.util.Log.e("D", "index1: "+index1);
611

  
612
      int[] q2 = getQuats(index1);
613
      printQuats(q2);
614
/*
615
      int[] q2 = {0,0,3,0,4,0,0,0, 0,0,0,0,0,0 };
616
      int index2 = getIndex(q2);
617
      android.util.Log.e("D", "index2: "+index2);
618

  
619
 */
620
      }
590 621
}

Also available in: Unified diff