Project

General

Profile

« Previous | Next » 

Revision b8dab9fd

Added by Leszek Koltunski almost 2 years ago

Pyraminx solver: add tips.

View differences:

src/main/java/org/distorted/solvers/SolverPyraminx.java
52 52
          {3,2},{1,3},{0,3},{2,1},{2,0},{1,0}  // order of those pairs determines edge twist
53 53
      };
54 54

  
55
  TablebasesAbstract mSolver;
55
  private TablebasesAbstract mSolver;
56
  private int[] mCornerTwist;
56 57

  
57 58
///////////////////////////////////////////////////////////////////////////////////////////////////
58 59

  
......
326 327
    int[][] corners = new int[4][3];
327 328
    int[][] edges   = new int[6][2];
328 329
    int[][] vertices= new int[4][3];
329
    int[] corner_twist = new int[4];
330 330
    int[] vertex_twist = new int[4];
331
    mCornerTwist = new int[4];
331 332

  
332 333
    getCorners(object,corners);
333 334
    getVertices(object,vertices);
......
350 351

  
351 352
    for(int i=0; i<4; i++)
352 353
      {
353
      corner_twist[i] = computePieceTwist(i,corners[i],faces1);
354
      if( corner_twist[i]<0 ) return ERROR_CORNERS_CANNOT;
354
      mCornerTwist[i] = computePieceTwist(i,corners[i],faces1);
355
      if( mCornerTwist[i]<0 ) return ERROR_CORNERS_CANNOT;
355 356
      }
356 357

  
357 358
    for(int i=0; i<4; i++)
......
498 499
    return null;
499 500
    }
500 501

  
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

  
504
  private void addMove(int[] move, int axis, int twist)
505
    {
506
    move[0] = axis;
507
    move[1] = (1<<2);
508
    move[2] = (twist==2 ? -1:twist);
509
    }
510

  
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

  
513
  private int[][] constructTipMoves(int[] twist)
514
    {
515
    int total = 0;
516

  
517
    for(int i=0; i<4; i++)
518
      if( twist[i]!=0 ) total++;
519

  
520
    if( total>0 )
521
      {
522
      int[][] moves = new int[total][3];
523

  
524
      int index=0;
525
      if( twist[0]!=0 ) { addMove(moves[index],1,twist[0]); index++; }
526
      if( twist[1]!=0 ) { addMove(moves[index],0,twist[1]); index++; }
527
      if( twist[2]!=0 ) { addMove(moves[index],3,twist[2]); index++; }
528
      if( twist[3]!=0 ) { addMove(moves[index],2,twist[3]);          }
529

  
530
      return moves;
531
      }
532

  
533
    return null;
534
    }
535

  
501 536
///////////////////////////////////////////////////////////////////////////////////////////////////
502 537

  
503 538
  public int[][] solution(int index, Resources res)
......
507 542
      mSolver = ImplementedTablebasesList.createPacked(res,ObjectType.PYRA_3);
508 543
      }
509 544

  
510
    return mSolver!=null ? mSolver.solution(index) : null;
545
    int[][] moves1 = mSolver!=null ? mSolver.solution(index) : null;
546
    int[][] moves2 = constructTipMoves(mCornerTwist);
547

  
548
    int len1 = (moves1==null ? 0:moves1.length);
549
    int len2 = (moves2==null ? 0:moves2.length);
550

  
551
    int[][] moves = new int[len1+len2][];
552

  
553
android.util.Log.e("D", "len1="+len1+" len2="+len2);
554

  
555
    if( len1>0 ) System.arraycopy(moves1, 0, moves,    0, len1);
556
    if( len2>0 ) System.arraycopy(moves2, 0, moves, len1, len2);
557

  
558
    return moves;
511 559
    }
512 560
}  
513 561

  

Also available in: Unified diff