Project

General

Profile

« Previous | Next » 

Revision 6d637f71

Added by Leszek Koltunski about 1 year ago

Move corner orientation from SolverPyraminx to TablebasesPyraminx (we'll need it for better-looking tablebases scrambling)

View differences:

src/main/java/org/distorted/objectlib/tablebases/TablebaseHelpers.java
72 72
    for(int i=0; i<num; i++)
73 73
      {
74 74
      int next = rnd.nextInt(size-1);
75
      int[][] moves = tb.solution(next);
75
      int[][] moves = tb.solution(next,null);
76 76
      String moveSeq = print(moves);
77 77
      android.util.Log.e("D", (moves==null ? 0 : moves.length)+" Trying "+next+" : "+moveSeq);
78 78
      }
src/main/java/org/distorted/objectlib/tablebases/TablebasesAbstract.java
377 377

  
378 378
///////////////////////////////////////////////////////////////////////////////////////////////////
379 379

  
380
  public int[][] solution(int index)
380
  int[][] extraInfo(int[][] moves, int[] extra)
381
    {
382
    return moves;
383
    }
384

  
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

  
387
  public int[][] solution(int index, int[] extra)
381 388
    {
382 389
    if( !mInitialized ) return null;
383 390

  
......
445 452
        }
446 453
      }
447 454

  
448
    return convertMoves(moves);
455
    int[][] ret = convertMoves(moves);
456
    return extraInfo(ret,extra);
449 457
    }
450 458

  
451 459
///////////////////////////////////////////////////////////////////////////////////////////////////
......
458 466
    int scraLen = scramble.length;
459 467
    if( depth>mMinScramble ) depth = mMinScramble;
460 468

  
469
    int[] cornerTwist = new int[4];
470
    for(int i=0; i<4; i++) cornerTwist[i] = (rnd.nextInt(3)-1);
471

  
461 472
    while( solDepth<depth )
462 473
      {
463 474
      int randomPosition = rnd.nextInt(mSize-1);
464
      int[][] sol = solution(randomPosition);
475
      int[][] sol = solution(randomPosition,cornerTwist);
465 476
      solDepth = sol.length;
466 477

  
467 478
      if( solDepth>=depth )
src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
105 105

  
106 106
///////////////////////////////////////////////////////////////////////////////////////////////////
107 107
// specifically for the tablebase
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  private void addMove(int[] move, int axis, int twist)
111
    {
112
    move[0] = axis;
113
    move[1] = (1<<2);
114
    move[2] = (twist==2 ? -1:twist);
115
    }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
  private int[][] constructTipMoves(int[] twist)
120
    {
121
    int total = 0;
122

  
123
    for(int i=0; i<4; i++)
124
      if( twist[i]!=0 ) total++;
125

  
126
    if( total>0 )
127
      {
128
      int[][] moves = new int[total][3];
129

  
130
      int index=0;
131
      if( twist[0]!=0 ) { addMove(moves[index],1,twist[0]); index++; }
132
      if( twist[1]!=0 ) { addMove(moves[index],0,twist[1]); index++; }
133
      if( twist[2]!=0 ) { addMove(moves[index],3,twist[2]); index++; }
134
      if( twist[3]!=0 ) { addMove(moves[index],2,twist[3]);          }
135

  
136
      return moves;
137
      }
138

  
139
    return null;
140
    }
141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
// extra = cornerTips
144

  
145
  @Override
146
  int[][] extraInfo(int[][] moves, int[] extra)
147
    {
148
    int[][] tipMoves = constructTipMoves(extra);
149

  
150
    int len1 = (   moves==null ? 0:   moves.length);
151
    int len2 = (tipMoves==null ? 0:tipMoves.length);
152

  
153
    int[][] ret = new int[len1+len2][3];
154

  
155
    if( len1>0 ) System.arraycopy(   moves, 0, ret,    0, len1);
156
    if( len2>0 ) System.arraycopy(tipMoves, 0, ret, len1, len2);
157

  
158
    return ret;
159
    }
160

  
108 161
///////////////////////////////////////////////////////////////////////////////////////////////////
109 162

  
110 163
  int getSize()
......
114 167

  
115 168
///////////////////////////////////////////////////////////////////////////////////////////////////
116 169

  
117
 int getMinScramble()
170
  int getMinScramble()
118 171
    {
119 172
    return 9;
120 173
    }

Also available in: Unified diff