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/TwistyIvy.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 TwistyIvy extends TwistyObject
......
58 56
  private static final int  IVY_N = 8;
59 57
  private static final int FACES_PER_CUBIT =6;
60 58

  
61
  private int mCurrState;
62
  private int mIndexExcluded;
63
  private final ScrambleState[] mStates;
64
  private int[][] mScrambleTable;
65
  private int[] mNumOccurences;
59
  private ScrambleState[] mStates;
66 60
  private int[] mBasicAngle;
67 61
  private Static4D[] mQuats;
68 62
  private int[][] mFaceMap;
......
83 77
      };
84 78
    }
85 79

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

  
82
  ScrambleState[] getScrambleStates()
83
    {
84
    if( mStates==null )
85
      {
86
      int[] tmp = {0,-1,0, 0,1,0, 1,-1,0, 1,1,0 };
87

  
88
      mStates = new ScrambleState[]
89
        {
90
        new ScrambleState( new int[][] {tmp,tmp,tmp,tmp} )
91
        };
92
      }
93

  
94
    return mStates;
95
    }
96

  
86 97
///////////////////////////////////////////////////////////////////////////////////////////////////
87 98

  
88 99
  private void initializeQuats()
......
447 458
    return 2.0f;
448 459
    }
449 460

  
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

  
452
  private void initializeScrambling()
453
    {
454
    int numLayers = getNumLayers();
455

  
456
    if( mScrambleTable ==null )
457
      {
458
      mScrambleTable = new int[NUM_AXIS][numLayers];
459
      }
460
    if( mNumOccurences ==null )
461
      {
462
      int max=0;
463

  
464
      for (ScrambleState mState : mStates)
465
        {
466
        int tmp = mState.getTotal(-1);
467
        if (max < tmp) max = tmp;
468
        }
469

  
470
      mNumOccurences = new int[max];
471
      }
472

  
473
    for(int i=0; i<NUM_AXIS; i++)
474
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
475
    }
476

  
477 461
///////////////////////////////////////////////////////////////////////////////////////////////////
478 462
// PUBLIC API
479 463

  
480
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
481
    {
482
    if( curr==0 )
483
      {
484
      mCurrState     = 0;
485
      mIndexExcluded =-1;
486
      initializeScrambling();
487
      }
488

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

  
491
    scramble[curr][0] = info[0];
492
    scramble[curr][1] = info[1];
493
    scramble[curr][2] = info[2];
494

  
495
    mCurrState     = info[3];
496
    mIndexExcluded = info[0];
497
    }
498

  
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500

  
501 464
  public Static3D[] getRotationAxis()
502 465
    {
503 466
    return ROT_AXIS;

Also available in: Unified diff