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/TwistySquare2.java
30 30
import org.distorted.library.type.Static4D;
31 31
import org.distorted.main.R;
32 32

  
33
import java.util.Random;
34

  
35 33
///////////////////////////////////////////////////////////////////////////////////////////////////
36 34

  
37 35
class TwistySquare2 extends TwistySquare
38 36
{
39 37
  private static final int NUM_STICKERS = 6;
40 38

  
41
  private int mCurrState;
42
  private int mIndexExcluded;
43
  private final ScrambleState[] mStates;
44
  private int[][] mScrambleTable;
45
  private int[] mNumOccurences;
39
  private ScrambleState[] mStates;
46 40
  private int[] mQuatNumber;
47 41
  private float[][] mCenters;
48 42
  private int[][] mStickerColor;
......
55 49
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
56 50
    {
57 51
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
52
    }
58 53

  
59
    int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
60
    int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
61
    int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
62
    int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
63
    int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
54
///////////////////////////////////////////////////////////////////////////////////////////////////
64 55

  
65
    mStates = new ScrambleState[]
56
  ScrambleState[] getScrambleStates()
57
    {
58
    if( mStates==null )
66 59
      {
67
      new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
68
      new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
69
      new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
70
      new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
71
      new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
72
      };
60
      int[] SL_6 = new int[] { 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1, 0,1,1, 1,1,1};
61
      int[] SL_1 = new int[] { 0,1,1, 1,1,1 };
62
      int[] LO_2 = new int[] { 0,-5,2, 0,-4,2, 0,-3,2, 0,-2,2, 0,-1,2, 0,1,2, 0,2,2, 0,3,2, 0,4,2, 0,5,2, 0,5,2 };
63
      int[] LO_3 = new int[] { 0,-5,3, 0,-4,3, 0,-3,3, 0,-2,3, 0,-1,3, 0,1,3, 0,2,3, 0,3,3, 0,4,3, 0,5,3, 0,5,3 };
64
      int[] LO_4 = new int[] { 0,-5,4, 0,-4,4, 0,-3,4, 0,-2,4, 0,-1,4, 0,1,4, 0,2,4, 0,3,4, 0,4,4, 0,5,4, 0,5,4 };
65

  
66
      mStates = new ScrambleState[]
67
        {
68
        new ScrambleState( new int[][] { LO_2, SL_6, LO_3 } ),  // 0
69
        new ScrambleState( new int[][] { LO_2, null, LO_3 } ),  // SL
70
        new ScrambleState( new int[][] { null, SL_1, LO_4 } ),  // LO
71
        new ScrambleState( new int[][] { LO_4, SL_1, null } ),  // UP
72
        new ScrambleState( new int[][] { null, SL_1, null } ),  // UL
73
        };
74
      }
75

  
76
    return mStates;
73 77
    }
74 78

  
75 79
///////////////////////////////////////////////////////////////////////////////////////////////////
......
367 371
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
368 372
    }
369 373

  
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

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

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

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

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

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

  
397 374
///////////////////////////////////////////////////////////////////////////////////////////////////
398 375
// PUBLIC API
399 376

  
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
///////////////////////////////////////////////////////////////////////////////////////////////////
420

  
421 377
  public int getObjectName(int numLayers)
422 378
    {
423 379
    return R.string.squa2;

Also available in: Unified diff