Project

General

Profile

« Previous | Next » 

Revision 338e42aa

Added by Leszek Koltunski about 2 years ago

Fixes for scrambling locally-produced bandaged cuboid.
Still does not work completely.

View differences:

src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java
206 206
        if( getBit(index)!=0 )
207 207
          {
208 208
          float[] touch = getCubitTouchOfIndex(index);
209
          if( belongsToTheLeft(touch,axis,layer) ) return false;
209
          if( belongsLeft(touch,axis,layer) ) return false;
210 210
          }
211 211

  
212 212
    return true;
......
223 223
      float[][] cyc = mAllCycles[i];
224 224
      float[] p0 = cyc[0];
225 225
      float[] p1 = cyc[1];
226
      float[] p2 = cyc[2];
226 227

  
227
      if( (belongsToTheLeft(p0,axis,layer) && belongsToTheLeft(p1,axis,layer)) ||
228
          (belongsToTheCent(p0,axis,layer) && belongsToTheCent(p1,axis,layer))  )
228
      if( (belongsLeft(p0,axis,layer) && belongsLeft(p1,axis,layer) && belongsLeft(p2,axis,layer)) ||
229
          (belongsCent(p0,axis,layer) && belongsCent(p1,axis,layer) && belongsCent(p2,axis,layer))  )
229 230
        {
230 231
        ret.cycle(turn,cyc);
231 232
        }
......
234 235
    return ret;
235 236
    }
236 237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
  private boolean belongsLeft(float[] point, int axis, int layer)
241
    {
242
    return 2*point[axis]+mLayer[axis] == 2*layer;
243
    }
244

  
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

  
247
  private boolean belongsCent(float[] point, int axis, int layer)
248
    {
249
    return 2*point[axis]+mLayer[axis] == 2*layer+1;
250
    }
251

  
237 252
///////////////////////////////////////////////////////////////////////////////////////////////////
238 253

  
239 254
  private void cycle(int turn, float[][] cyc)
......
456 471
    return -1;
457 472
    }
458 473

  
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

  
461
  private boolean belongsToTheLeft(float[] point, int axis, int layer)
462
    {
463
    return 2*point[axis]+mLayer[axis] == 2*layer;
464
    }
465

  
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467

  
468
  private boolean belongsToTheCent(float[] point, int axis, int layer)
469
    {
470
    return 2*point[axis]+mLayer[axis] == 2*layer+1;
471
    }
472

  
473 474
///////////////////////////////////////////////////////////////////////////////////////////////////
474 475

  
475 476
  private int getIndexOfCubitTouch(float x, float y, float z)
src/main/java/org/distorted/objectlib/scrambling/ObjectScrambler.java
56 56
  // type=2 , i.e. locally created bandaged cuboids
57 57
  private static ObjectSignature mSignature;
58 58
  private ArrayList<ScrambleStateBandagedCuboid> mBandagedStates;
59
  private int[] mSize, mTurns;
60 59

  
61 60
///////////////////////////////////////////////////////////////////////////////////////////////////
62 61

  
......
73 72
      mCornerQuat = new int[8];
74 73
      mLastRot = LAST_SL;
75 74
      }
76
    if( mType==2 )
77
      {
78
      mSize = new int[3];
79
      mTurns= new int[3];
80

  
81
      mSize[0] = (mNumLayers[0]>1 ? mNumLayers[0] : 0);
82
      mSize[1] = (mNumLayers[1]>1 ? mNumLayers[1] : 0);
83
      mSize[2] = (mNumLayers[2]>1 ? mNumLayers[2] : 0);
84

  
85
      mTurns[0] = mNumLayers[1]==mNumLayers[2] ? 3:1;
86
      mTurns[1] = mNumLayers[0]==mNumLayers[2] ? 3:1;
87
      mTurns[2] = mNumLayers[0]==mNumLayers[1] ? 3:1;
88
      }
89 75
    }
90 76

  
91 77
///////////////////////////////////////////////////////////////////////////////////////////////////
......
421 407
      }
422 408
    }
423 409

  
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
// TYPE 2
426

  
427
  private void fillOutScramble(int[] scramble, int moveIndex)
428
    {
429
    for(int axis=0; axis<3; axis++)
430
      {
431
      int size = mTurns[axis]*mSize[axis];
432

  
433
      if( moveIndex<size )
434
        {
435
        scramble[0] = axis;
436
        scramble[1] = moveIndex/mTurns[axis];
437

  
438
        if( mTurns[axis]==3 )
439
          {
440
          switch(moveIndex%3)
441
            {
442
            case 0: scramble[2] = -1; break;
443
            case 1: scramble[2] =  2; break;
444
            case 2: scramble[2] =  1; break;
445
            }
446
          }
447
        else scramble[2] =  1;
448
        return;
449
        }
450

  
451
      moveIndex -= size;
452
      }
453

  
454
    android.util.Log.e("D", "ERROR in fillOutScramble moveIndex="+moveIndex);
455
    }
456

  
457 410
///////////////////////////////////////////////////////////////////////////////////////////////////
458 411
// TYPE 2
459 412

  
......
480 433
      int randMove = rnd.nextInt(numMoves);
481 434
      int moveIndex = currState.getNthMove(randMove,indexExcluded);
482 435
      mSignature = currState.getMove(moveIndex);
483
      fillOutScramble(scramble[curr],moveIndex);
436
      currState.fillOutScramble(scramble[curr],moveIndex);
484 437
      }
485 438

  
486 439
    ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
......
519 472
    int randMove = rnd.nextInt(numMoves);
520 473
    int moveIndex = currState.getNthMove(randMove,indexExcluded);
521 474
    mSignature = currState.getMove(moveIndex);
522
    fillOutScramble(scramble[curr],moveIndex);
475
    currState.fillOutScramble(scramble[curr],moveIndex);
523 476

  
524 477
    ScrambleStateBandagedCuboid nextState = new ScrambleStateBandagedCuboid(mNumLayers[0], mNumLayers[1], mNumLayers[2], mSignature);
525 478
    mBandagedStates.add(nextState);
src/main/java/org/distorted/objectlib/scrambling/ScrambleStateBandagedCuboid.java
35 35

  
36 36
  private final ObjectSignature[] mMoves;
37 37
  private final ObjectSignature mSignature;
38
  private final int[] mLayer, mTurns;
38
  private final int[] mLayer, mTurns, mSize;
39 39
  private final int mNumMoves;
40 40
  private final int mStartX, mStartY, mStartZ;
41 41
  private final boolean[][] mIsUnblocked;
......
46 46
    {
47 47
    mLayer = new int[3];
48 48
    mTurns = new int[3];
49
    mSize  = new int[3];
49 50

  
50 51
    mIsUnblocked = new boolean[3][MAX_SUPPORTED_SIZE];
51 52

  
......
57 58
    mTurns[1] = mLayer[0]==mLayer[2] ? 3:1;
58 59
    mTurns[2] = mLayer[0]==mLayer[1] ? 3:1;
59 60

  
60
    int xMoves = mLayer[0]>1 ? mTurns[0]*mLayer[0] : 0;
61
    int yMoves = mLayer[1]>1 ? mTurns[1]*mLayer[1] : 0;
62
    int zMoves = mLayer[2]>1 ? mTurns[2]*mLayer[2] : 0;
61
    mSize[0] = (mLayer[0]>1 ? mLayer[0] : 0);
62
    mSize[1] = (mLayer[1]>1 ? mLayer[1] : 0);
63
    mSize[2] = (mLayer[2]>1 ? mLayer[2] : 0);
64

  
65
    int xMoves = mTurns[0]*mSize[0];
66
    int yMoves = mTurns[1]*mSize[1];
67
    int zMoves = mTurns[2]*mSize[2];
63 68

  
64 69
    mNumMoves = xMoves + yMoves + zMoves;
65 70

  
......
210 215
      for(int layer=0; layer<mLayer[axis]; layer++)
211 216
        {
212 217
        mIsUnblocked[axis][layer] = mSignature.isUnblockedFromLeft(axis,layer);
213
        android.util.Log.e("D", "unblocked from left: axis="+axis+" layer="+layer+" val="+mIsUnblocked[axis][layer]);
218
        //android.util.Log.e("D", "unblocked from left: axis="+axis+" layer="+layer+" val="+mIsUnblocked[axis][layer]);
214 219
        }
215 220

  
216 221
    for(int axis=0; axis<3; axis++)
217 222
      if( mLayer[axis]>1 )
218
        for(int turn=0; turn<mTurns[axis]; turn++)
223
        for(int turn=1; turn<=mTurns[axis]; turn++)
219 224
          {
220 225
          boolean allLayersLocked = true;
221 226

  
......
241 246
    return ret;
242 247
    }
243 248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
  public void fillOutScramble(int[] scramble, int moveIndex)
252
    {
253
    for(int axis=0; axis<3; axis++)
254
      {
255
      int size = mTurns[axis]*mSize[axis];
256

  
257
      if( moveIndex<size )
258
        {
259
        scramble[0] = axis;
260
        scramble[1] = moveIndex % mSize[axis];
261

  
262
        if( mTurns[axis]==3 )
263
          {
264
          switch(moveIndex/mSize[axis])
265
            {
266
            case 0: scramble[2] =-1; break;
267
            case 1: scramble[2] = 2; break;
268
            case 2: scramble[2] = 1; break;
269
            }
270
          }
271
        else scramble[2] = 1;
272
        return;
273
        }
274

  
275
      moveIndex -= size;
276
      }
277

  
278
    android.util.Log.e("D", "ERROR in fillOutScramble moveIndex="+moveIndex);
279
    }
280

  
244 281
///////////////////////////////////////////////////////////////////////////////////////////////////
245 282

  
246 283
  private void printMoves()

Also available in: Unified diff