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/TwistyUltimate.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
import static org.distorted.objects.TwistyMinx.MINX_DBLUE;
37 35
import static org.distorted.objects.TwistyMinx.MINX_DGREEN;
38 36
import static org.distorted.objects.TwistyMinx.MINX_DRED;
......
73 71
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
74 72
         };
75 73

  
76
  private int mCurrState;
77
  private int mIndexExcluded;
78
  private final ScrambleState[] mStates;
79
  private int[][] mScrambleTable;
80
  private int[] mNumOccurences;
74
  private ScrambleState[] mStates;
81 75
  private int[] mBasicAngle;
82 76
  private Static4D[] mQuats;
83 77
  private int[][] mFaceMap;
......
91 85
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
92 86
    {
93 87
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.ULTI, res, scrWidth);
88
    }
94 89

  
95
    int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
90
///////////////////////////////////////////////////////////////////////////////////////////////////
96 91

  
97
    mStates = new ScrambleState[]
92
  ScrambleState[] getScrambleStates()
93
    {
94
    if( mStates==null )
98 95
      {
99
      new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
100
      };
96
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
97

  
98
      mStates = new ScrambleState[]
99
        {
100
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
101
        };
102
      }
103

  
104
    return mStates;
101 105
    }
102 106

  
103 107
///////////////////////////////////////////////////////////////////////////////////////////////////
......
421 425
    return 0.67f;
422 426
    }
423 427

  
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425

  
426
  private void initializeScrambling()
427
    {
428
    int numLayers = getNumLayers();
429

  
430
    if( mScrambleTable ==null )
431
      {
432
      mScrambleTable = new int[NUM_AXIS][numLayers];
433
      }
434
    if( mNumOccurences ==null )
435
      {
436
      int max=0;
437

  
438
      for (ScrambleState mState : mStates)
439
        {
440
        int tmp = mState.getTotal(-1);
441
        if (max < tmp) max = tmp;
442
        }
443

  
444
      mNumOccurences = new int[max];
445
      }
446

  
447
    for(int i=0; i<NUM_AXIS; i++)
448
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
449
    }
450

  
451 428
///////////////////////////////////////////////////////////////////////////////////////////////////
452 429
// PUBLIC API
453 430

  
454
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
455
    {
456
    if( curr==0 )
457
      {
458
      mCurrState     = 0;
459
      mIndexExcluded =-1;
460
      initializeScrambling();
461
      }
462

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

  
465
    scramble[curr][0] = info[0];
466
    scramble[curr][1] = info[1];
467
    scramble[curr][2] = info[2];
468

  
469
    mCurrState     = info[3];
470
    mIndexExcluded = info[0];
471
    }
472

  
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474

  
475 431
  public Static3D[] getRotationAxis()
476 432
    {
477 433
    return ROT_AXIS;

Also available in: Unified diff