Project

General

Profile

« Previous | Next » 

Revision 20df890a

Added by Leszek Koltunski about 1 year ago

First version of 'clever' pyraminx tablebase scrambling (with layers 2 & 3 combined if possible)
Still incorrect.

View differences:

src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
110 110
  private void addMove(int[] move, int axis, int twist)
111 111
    {
112 112
    move[0] = axis;
113
    move[1] = (1<<2);
113
    move[1] = 4;
114 114
    move[2] = (twist==2 ? -1:twist);
115 115
    }
116 116

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

  
119
  private int[][] constructTipMoves(int[] twist)
119
  private boolean failedInsertingTipMove(int[][] moves, int[] extra, int extraIndex, int axis)
120 120
    {
121
    int total = 0;
121
    int numAxis = 0;
122
    boolean ret = true;
122 123

  
123
    for(int i=0; i<4; i++)
124
      if( twist[i]!=0 ) total++;
124
    for( int[] move : moves )
125
      {
126
      if( move[0]==axis )
127
        {
128
        numAxis++;
129

  
130
android.util.Log.e("D", "sameAxis, numAxis="+numAxis+" "+move[2]+" "+extra[extraIndex]);
131

  
132
        if( (numAxis==1 && move[2]==extra[extraIndex]) || numAxis>=2 ) ret=false;
133
        }
134
      }
135

  
136
android.util.Log.e("D", "failedInsertingTipMove "+axis+" : "+ret);
137

  
138
    int currAx = 0;
139
    int numMoves = moves.length;
140
    int foreIndex=-1;
141
    int lastIndex = -1;
125 142

  
126
    if( total>0 )
143
    for( int index=0; index<numMoves; index++ )
127 144
      {
128
      int[][] moves = new int[total][3];
145
      int[] move = moves[index];
129 146

  
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]);          }
147
      if( move[0]==axis )
148
        {
149
        if (currAx < numAxis-2 )
150
          {
151
          move[1] = 6;
152
          extra[extraIndex] += (move[2]==1 ? 1:2);
153
          }
154
        if( currAx == numAxis-2 ) foreIndex = index;
155
        if( currAx == numAxis-1 ) lastIndex = index;
156

  
157
        currAx++;
158
        }
159
      }
160

  
161
    extra[extraIndex] = (extra[extraIndex]%3);
162

  
163
    if( foreIndex>=0 )
164
      {
165
      int foreAngle = moves[foreIndex][2];
166
      int lastAngle = moves[lastIndex][2];
135 167

  
136
      return moves;
168
      if( extra[extraIndex]==1 )
169
        {
170
        if( foreAngle==1 )
171
          {
172
          moves[foreIndex][1] = 6;
173
          extra[extraIndex]++;
174
          }
175
        else
176
          {
177
          if( lastAngle==1 )
178
            {
179
            moves[lastIndex][1] = 6;
180
            extra[extraIndex]++;
181
            }
182
          else
183
            {
184
            moves[foreIndex][1] = 6;
185
            moves[lastIndex][1] = 6;
186
            extra[extraIndex]+=2;
187
            }
188
          }
189
        }
190
      else if( extra[extraIndex]==2 )
191
        {
192
        if( foreAngle==-1 )
193
          {
194
          moves[foreIndex][1] = 6;
195
          extra[extraIndex]+=2;
196
          }
197
        else
198
          {
199
          if( lastAngle==-1 )
200
            {
201
            moves[lastIndex][1] = 6;
202
            extra[extraIndex]+=2;
203
            }
204
          else
205
            {
206
            moves[foreIndex][1] = 6;
207
            moves[lastIndex][1] = 6;
208
            extra[extraIndex]++;
209
            }
210
          }
211
        }
137 212
      }
213
    else if( lastIndex>=0 )
214
      {
215
      int lastAngle = moves[lastIndex][2];
138 216

  
139
    return null;
217
      if( extra[extraIndex]==1 )
218
        {
219
        if( lastAngle==1 )
220
          {
221
          moves[lastIndex][1] = 6;
222
          extra[extraIndex]++;
223
          }
224
        }
225
      else if( extra[extraIndex]==2 )
226
        {
227
        if( lastAngle==-1 )
228
          {
229
          moves[lastIndex][1] = 6;
230
          extra[extraIndex]+=2;
231
          }
232
        }
233
      }
234

  
235
    extra[extraIndex] = (extra[extraIndex]%3);
236

  
237
    return ret;
140 238
    }
141 239

  
142 240
///////////////////////////////////////////////////////////////////////////////////////////////////
......
145 243
  @Override
146 244
  int[][] extraInfo(int[][] moves, int[] extra)
147 245
    {
148
    int[][] tipMoves = constructTipMoves(extra);
246
    int lenExtra = 0;
149 247

  
150
    int len1 = (   moves==null ? 0:   moves.length);
151
    int len2 = (tipMoves==null ? 0:tipMoves.length);
248
    if( failedInsertingTipMove(moves,extra,0,1) && extra[0]!=0 ) lenExtra++;
249
    if( failedInsertingTipMove(moves,extra,1,0) && extra[1]!=0 ) lenExtra++;
250
    if( failedInsertingTipMove(moves,extra,2,3) && extra[2]!=0 ) lenExtra++;
251
    if( failedInsertingTipMove(moves,extra,3,2) && extra[3]!=0 ) lenExtra++;
152 252

  
153
    int[][] ret = new int[len1+len2][3];
253
android.util.Log.e("D", "lenExtra="+lenExtra);
154 254

  
155
    if( len1>0 ) System.arraycopy(   moves, 0, ret,    0, len1);
156
    if( len2>0 ) System.arraycopy(tipMoves, 0, ret, len1, len2);
255
    if( lenExtra>0 )
256
      {
257
      int[][] extraMoves = new int[lenExtra][3];
157 258

  
158
    return ret;
259
      int index=0;
260
      if( extra[0]!=0 ) { addMove(extraMoves[index],1,extra[0]); index++; }
261
      if( extra[1]!=0 ) { addMove(extraMoves[index],0,extra[1]); index++; }
262
      if( extra[2]!=0 ) { addMove(extraMoves[index],3,extra[2]); index++; }
263
      if( extra[3]!=0 ) { addMove(extraMoves[index],2,extra[3]);          }
264

  
265
      int len = moves.length;
266
      int totalLen = len+lenExtra;
267
      int[][] totalMoves = new int[totalLen][];
268

  
269
      if( len>0 ) System.arraycopy(moves, 0, totalMoves, 0, len);
270
      System.arraycopy(extraMoves, 0, totalMoves, len, lenExtra);
271

  
272
for(int i=0; i<totalLen; i++)
273
  android.util.Log.e("D", totalMoves[i][0]+" "+totalMoves[i][1]+" "+totalMoves[i][2]);
274

  
275
      return totalMoves;
276
      }
277

  
278
    return moves;
159 279
    }
160 280

  
161 281
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff