Project

General

Profile

« Previous | Next » 

Revision 13fd91e7

Added by Leszek Koltunski about 1 year ago

'Clever' pyraminx scrambling done.

View differences:

src/main/java/org/distorted/objectlib/tablebases/TablebasesPyraminx.java
114 114
    move[2] = (twist==2 ? -1:twist);
115 115
    }
116 116

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

  
119
  private void includeTip(int[] move, int[] extra, int index)
120
    {
121
    move[1] = 6;
122
    extra[index] += (move[2]==1 ? 2:1);
123
    }
124

  
117 125
///////////////////////////////////////////////////////////////////////////////////////////////////
118 126

  
119 127
  private boolean failedInsertingTipMove(int[][] moves, int[] extra, int extraIndex, int axis)
120 128
    {
121 129
    int numAxis = 0;
122 130
    boolean ret = true;
131
    extra[extraIndex]+=3; // make sure extra is positive
123 132

  
124 133
    for( int[] move : moves )
125 134
      {
126 135
      if( move[0]==axis )
127 136
        {
128 137
        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;
138
        if( (numAxis==1 && (move[2]-extra[extraIndex])%3==0 ) || numAxis>=2 ) ret=false;
133 139
        }
134 140
      }
135 141

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

  
138 142
    int currAx = 0;
139 143
    int numMoves = moves.length;
140 144
    int foreIndex=-1;
......
146 150

  
147 151
      if( move[0]==axis )
148 152
        {
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

  
153
             if( currAx <  numAxis-2 ) includeTip(move,extra,extraIndex);
154
        else if( currAx == numAxis-2 ) foreIndex = index;
155
        else if( currAx == numAxis-1 ) lastIndex = index;
157 156
        currAx++;
158 157
        }
159 158
      }
......
167 166

  
168 167
      if( extra[extraIndex]==1 )
169 168
        {
170
        if( foreAngle==1 )
171
          {
172
          moves[foreIndex][1] = 6;
173
          extra[extraIndex]++;
174
          }
169
        if( foreAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
175 170
        else
176 171
          {
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
            }
172
          includeTip(moves[lastIndex],extra,extraIndex);
173
          if( lastAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
188 174
          }
189 175
        }
190 176
      else if( extra[extraIndex]==2 )
191 177
        {
192
        if( foreAngle==-1 )
193
          {
194
          moves[foreIndex][1] = 6;
195
          extra[extraIndex]+=2;
196
          }
178
        if( foreAngle==-1 ) includeTip(moves[foreIndex],extra,extraIndex);
197 179
        else
198 180
          {
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
            }
181
          includeTip(moves[lastIndex],extra,extraIndex);
182
          if( lastAngle==1 ) includeTip(moves[foreIndex],extra,extraIndex);
210 183
          }
211 184
        }
212 185
      }
......
214 187
      {
215 188
      int lastAngle = moves[lastIndex][2];
216 189

  
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
        }
190
      if( (extra[extraIndex]-lastAngle)%3 ==0 )
191
        includeTip(moves[lastIndex],extra,extraIndex);
233 192
      }
234 193

  
235 194
    extra[extraIndex] = (extra[extraIndex]%3);
......
250 209
    if( failedInsertingTipMove(moves,extra,2,3) && extra[2]!=0 ) lenExtra++;
251 210
    if( failedInsertingTipMove(moves,extra,3,2) && extra[3]!=0 ) lenExtra++;
252 211

  
253
android.util.Log.e("D", "lenExtra="+lenExtra);
254

  
255 212
    if( lenExtra>0 )
256 213
      {
257 214
      int[][] extraMoves = new int[lenExtra][3];
......
269 226
      if( len>0 ) System.arraycopy(moves, 0, totalMoves, 0, len);
270 227
      System.arraycopy(extraMoves, 0, totalMoves, len, lenExtra);
271 228

  
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 229
      return totalMoves;
276 230
      }
277 231

  

Also available in: Unified diff