Project

General

Profile

« Previous | Next » 

Revision 91792184

Added by Leszek Koltunski over 2 years ago

Make object scrambling abstract (well, almost - with exception of Square-1 - this theoretically could also be done the generic way, but this would require almost 20000 'ScrambleStates')

View differences:

src/main/java/org/distorted/objects/TwistyCube.java
31 31
import org.distorted.library.type.Static4D;
32 32
import org.distorted.main.R;
33 33

  
34
import java.util.Random;
35

  
36 34
///////////////////////////////////////////////////////////////////////////////////////////////////
37 35

  
38 36
class TwistyCube extends TwistyObject
......
51 49
           COLOR_RED   , COLOR_ORANGE
52 50
         };
53 51

  
54
  private int mCurrState;
55
  private int mIndexExcluded;
56
  private final ScrambleState[] mStates;
57
  private int[][] mScrambleTable;
58
  private int[] mNumOccurences;
52
  private ScrambleState[] mStates;
59 53
  private Static4D[] mQuats;
60 54
  private int[] mBasicAngle;
61 55
  private ObjectSticker[] mStickers;
......
66 60
             DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
67 61
    {
68 62
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.CUBE, res, scrWidth);
63
    }
69 64

  
70
    int[][] m = new int[16][];
71
    for(int i=1; i<16; i++) m[i] = createEdges(size,i);
65
///////////////////////////////////////////////////////////////////////////////////////////////////
72 66

  
73
    mStates = new ScrambleState[]  // built so that all 3 axes must be present in every 4 consecutive moves
67
  ScrambleState[] getScrambleStates()
68
    {
69
    if( mStates==null )
74 70
      {
75
      new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  // 0
76
      new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  // x
77
      new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  // y
78
      new ScrambleState( new int[][] { m[ 8], m[ 8],  null } ),  // z
79
      new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  // xy
80
      new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  // xz
81
      new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  // yx
82
      new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  // yz
83
      new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  // zx
84
      new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  // zy
85
      new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // xyx
86
      new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // xzx
87
      new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // yxy
88
      new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // yzy
89
      new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // zxz
90
      new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // zyz
91
      };
71
      int size = getNumLayers();
72
      int[][] m = new int[16][];
73
      for(int i=1; i<16; i++) m[i] = createEdges(size,i);
74

  
75
      mStates = new ScrambleState[]
76
        {
77
        new ScrambleState( new int[][] { m[ 1], m[ 2], m[ 3] } ),  // 0
78
        new ScrambleState( new int[][] {  null, m[ 4], m[ 5] } ),  // x
79
        new ScrambleState( new int[][] { m[ 6],  null, m[ 7] } ),  // y
80
        new ScrambleState( new int[][] { m[ 8], m[ 8],  null } ),  // z
81
        new ScrambleState( new int[][] { m[10],  null, m[ 7] } ),  // xy
82
        new ScrambleState( new int[][] { m[11], m[ 9],  null } ),  // xz
83
        new ScrambleState( new int[][] {  null, m[12], m[ 5] } ),  // yx
84
        new ScrambleState( new int[][] { m[ 8], m[13],  null } ),  // yz
85
        new ScrambleState( new int[][] {  null, m[ 4], m[14] } ),  // zx
86
        new ScrambleState( new int[][] { m[ 6],  null, m[15] } ),  // zy
87
        new ScrambleState( new int[][] {  null,  null, m[ 5] } ),  // xyx
88
        new ScrambleState( new int[][] {  null, m[ 4],  null } ),  // xzx
89
        new ScrambleState( new int[][] {  null,  null, m[ 7] } ),  // yxy
90
        new ScrambleState( new int[][] { m[ 6],  null,  null } ),  // yzy
91
        new ScrambleState( new int[][] {  null, m[ 9],  null } ),  // zxz
92
        new ScrambleState( new int[][] { m[ 8],  null,  null } ),  // zyz
93
        };
94
      }
95

  
96
    return mStates;
92 97
    }
93 98

  
94 99
///////////////////////////////////////////////////////////////////////////////////////////////////
......
368 373
    return mBasicAngle;
369 374
    }
370 375

  
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

  
373
  private void initializeScrambling()
374
    {
375
    int numLayers = getNumLayers();
376

  
377
    if( mScrambleTable ==null )
378
      {
379
      mScrambleTable = new int[NUM_AXIS][numLayers];
380
      }
381
    if( mNumOccurences ==null )
382
      {
383
      int max=0;
384

  
385
      for (ScrambleState mState : mStates)
386
        {
387
        int tmp = mState.getTotal(-1);
388
        if (max < tmp) max = tmp;
389
        }
390

  
391
      mNumOccurences = new int[max];
392
      }
393

  
394
    for(int i=0; i<NUM_AXIS; i++)
395
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
396
    }
397

  
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399

  
400
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
401
    {
402
    if( curr==0 )
403
      {
404
      mCurrState     = 0;
405
      mIndexExcluded =-1;
406
      initializeScrambling();
407
      }
408

  
409
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
410

  
411
    scramble[curr][0] = info[0];
412
    scramble[curr][1] = info[1];
413
    scramble[curr][2] = info[2];
414

  
415
    mCurrState     = info[3];
416
    mIndexExcluded = info[0];
417
    }
418

  
419 376
///////////////////////////////////////////////////////////////////////////////////////////////////
420 377

  
421 378
  public int getObjectName(int numLayers)

Also available in: Unified diff