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/TwistyPyraminx.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
public class TwistyPyraminx extends TwistyObject
......
51 49
           COLOR_BLUE  , COLOR_RED
52 50
         };
53 51

  
54
  private int mCurrState;
55
  private int mIndexExcluded;
56 52
  private ScrambleState[] mStates;
57
  private int[][] mScrambleTable;
58
  private int[] mNumOccurences;
59 53
  private int[] mBasicAngle;
60 54
  private Static4D[] mQuats;
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.PYRA, res, scrWidth);
63
    }
69 64

  
70
    initializeScrambleStates(size);
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

  
67
  ScrambleState[] getScrambleStates()
68
    {
69
    if( mStates==null )
70
      {
71
      int numLayers = getNumLayers();
72
      initializeScrambleStates(numLayers);
73
      }
74

  
75
    return mStates;
71 76
    }
72 77

  
73 78
///////////////////////////////////////////////////////////////////////////////////////////////////
......
382 387
    }
383 388

  
384 389
///////////////////////////////////////////////////////////////////////////////////////////////////
385

  
386
  private void initializeScrambling()
387
    {
388
    int numLayers = getNumLayers();
389

  
390
    if( mScrambleTable ==null )
391
      {
392
      mScrambleTable = new int[NUM_AXIS][numLayers];
393
      }
394
    if( mNumOccurences ==null )
395
      {
396
      int max=0;
397

  
398
      for (ScrambleState mState : mStates)
399
        {
400
        int tmp = mState.getTotal(-1);
401
        if (max < tmp) max = tmp;
402
        }
403

  
404
      mNumOccurences = new int[max];
405
      }
406

  
407
    for(int i=0; i<NUM_AXIS; i++)
408
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
409
    }
410

  
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
// PUBLIC API
413

  
414
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
415
    {
416
    if( curr==0 )
417
      {
418
      mCurrState     = 0;
419
      mIndexExcluded =-1;
420
      initializeScrambling();
421
      }
422

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

  
425
    scramble[curr][0] = info[0];
426
    scramble[curr][1] = info[1];
427
    scramble[curr][2] = info[2];
428

  
429
    mCurrState     = info[3];
430
    mIndexExcluded = info[0];
431
    }
432

  
433
///////////////////////////////////////////////////////////////////////////////////////////////////
390
// public API
434 391

  
435 392
  public Static3D[] getRotationAxis()
436 393
    {

Also available in: Unified diff